1 | // Aseprite UI Library |
2 | // Copyright (C) 2018-2021 Igara Studio S.A. |
3 | // Copyright (C) 2001-2018 David Capello |
4 | // |
5 | // This file is released under the terms of the MIT license. |
6 | // Read LICENSE.txt for more information. |
7 | |
8 | #ifdef HAVE_CONFIG_H |
9 | #include "config.h" |
10 | #endif |
11 | |
12 | #include "ui/message.h" |
13 | |
14 | #include "base/memory.h" |
15 | #include "os/system.h" |
16 | #include "ui/display.h" |
17 | #include "ui/widget.h" |
18 | |
19 | #include <cstring> |
20 | |
21 | namespace ui { |
22 | |
23 | Message::Message(MessageType type, KeyModifiers modifiers) |
24 | : m_type(type) |
25 | , m_flags(0) |
26 | , m_display(nullptr) |
27 | , m_recipient(nullptr) |
28 | , m_commonAncestor(nullptr) |
29 | { |
30 | if (modifiers == kKeyUninitializedModifier && os::instance()) |
31 | m_modifiers = os::instance()->keyModifiers(); |
32 | else |
33 | m_modifiers = modifiers; |
34 | } |
35 | |
36 | Message::~Message() |
37 | { |
38 | } |
39 | |
40 | void Message::setDisplay(Display* display) |
41 | { |
42 | m_display = display; |
43 | } |
44 | |
45 | void Message::setRecipient(Widget* widget) |
46 | { |
47 | ASSERT(m_recipient == nullptr); |
48 | ASSERT_VALID_WIDGET(widget); |
49 | m_recipient = widget; |
50 | } |
51 | |
52 | void Message::removeRecipient(Widget* widget) |
53 | { |
54 | if (m_recipient == widget) |
55 | m_recipient = nullptr; |
56 | } |
57 | |
58 | KeyMessage::KeyMessage(MessageType type, |
59 | KeyScancode scancode, |
60 | KeyModifiers modifiers, |
61 | int unicodeChar, int repeat) |
62 | : Message(type, modifiers) |
63 | , m_scancode(scancode) |
64 | , m_unicodeChar(unicodeChar) |
65 | , m_repeat(repeat) |
66 | , m_isDead(false) |
67 | { |
68 | setPropagateToParent(true); |
69 | } |
70 | |
71 | gfx::Point MouseMessage::positionForDisplay(Display* anotherDisplay) const |
72 | { |
73 | if (display() == anotherDisplay) { |
74 | return position(); // There is no need for transformation |
75 | } |
76 | else { |
77 | ASSERT(anotherDisplay); |
78 | ASSERT(anotherDisplay->nativeWindow()); |
79 | return anotherDisplay->nativeWindow()->pointFromScreen(screenPosition()); |
80 | } |
81 | } |
82 | |
83 | gfx::Point MouseMessage::screenPosition() const |
84 | { |
85 | return display()->nativeWindow()->pointToScreen(position()); |
86 | } |
87 | |
88 | } // namespace ui |
89 | |