Commit | Line | Data |
---|---|---|
0ee88b6d KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * The MIT License (MIT) | |
5 | * | |
a69ed767 | 6 | * Copyright (C) 2019 Kevin Lamonte |
0ee88b6d KL |
7 | * |
8 | * Permission is hereby granted, free of charge, to any person obtaining a | |
9 | * copy of this software and associated documentation files (the "Software"), | |
10 | * to deal in the Software without restriction, including without limitation | |
11 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
12 | * and/or sell copies of the Software, and to permit persons to whom the | |
13 | * Software is furnished to do so, subject to the following conditions: | |
14 | * | |
15 | * The above copyright notice and this permission notice shall be included in | |
16 | * all copies or substantial portions of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
23 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | |
24 | * DEALINGS IN THE SOFTWARE. | |
25 | * | |
26 | * @author Kevin Lamonte [kevin.lamonte@gmail.com] | |
27 | * @version 1 | |
28 | */ | |
29 | package jexer; | |
30 | ||
31 | import jexer.bits.CellAttributes; | |
32 | import jexer.bits.GraphicsChars; | |
33 | import jexer.event.TKeypressEvent; | |
34 | import jexer.event.TMenuEvent; | |
35 | import jexer.event.TMouseEvent; | |
0ee88b6d KL |
36 | |
37 | /** | |
38 | * TDesktop is a special-class window that is drawn underneath everything | |
92453213 KL |
39 | * else. Like a TWindow, it can contain widgets and perform "background" |
40 | * processing via onIdle(). But unlike a TWindow, it cannot be hidden, | |
41 | * moved, or resized. | |
42 | * | |
43 | * <p> | |
44 | * Events are passed to TDesktop as follows: | |
45 | * <ul> | |
46 | * <li>Mouse events are seen if they do not cover any other windows.</li> | |
47 | * <li>Keypress events are seen if no other windows are open.</li> | |
48 | * <li>Menu events are seen if no other windows are open.</li> | |
49 | * <li>Command events are seen if no other windows are open.</li> | |
43ad7b6c | 50 | * </ul> |
0ee88b6d KL |
51 | */ |
52 | public class TDesktop extends TWindow { | |
53 | ||
615a0d99 KL |
54 | // ------------------------------------------------------------------------ |
55 | // Constructors ----------------------------------------------------------- | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
0ee88b6d KL |
58 | /** |
59 | * Public constructor. | |
60 | * | |
61 | * @param parent parent application | |
62 | */ | |
63 | public TDesktop(final TApplication parent) { | |
0ee88b6d | 64 | super(parent, "", 0, 0, parent.getScreen().getWidth(), |
2bb26984 | 65 | parent.getDesktopBottom() - parent.getDesktopTop()); |
0ee88b6d KL |
66 | |
67 | setActive(false); | |
68 | } | |
69 | ||
615a0d99 KL |
70 | // ------------------------------------------------------------------------ |
71 | // TWindow ---------------------------------------------------------------- | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
0ee88b6d KL |
74 | /** |
75 | * The default TDesktop draws a hatch character across everything. | |
76 | */ | |
77 | @Override | |
78 | public void draw() { | |
79 | CellAttributes background = getTheme().getColor("tdesktop.background"); | |
80 | putAll(GraphicsChars.HATCH, background); | |
81 | } | |
82 | ||
92453213 KL |
83 | /** |
84 | * Hide window. This is a NOP for TDesktop. | |
85 | */ | |
86 | @Override | |
87 | public final void hide() {} | |
88 | ||
89 | /** | |
90 | * Show window. This is a NOP for TDesktop. | |
91 | */ | |
92 | @Override | |
93 | public final void show() {} | |
94 | ||
95 | /** | |
96 | * Called by hide(). This is a NOP for TDesktop. | |
97 | */ | |
98 | @Override | |
99 | public final void onHide() {} | |
100 | ||
101 | /** | |
102 | * Called by show(). This is a NOP for TDesktop. | |
103 | */ | |
104 | @Override | |
105 | public final void onShow() {} | |
106 | ||
107 | /** | |
108 | * Returns true if the mouse is currently on the close button. | |
109 | * | |
110 | * @return true if mouse is currently on the close button | |
111 | */ | |
112 | @Override | |
113 | protected final boolean mouseOnClose() { | |
114 | return false; | |
115 | } | |
116 | ||
117 | /** | |
118 | * Returns true if the mouse is currently on the maximize/restore button. | |
119 | * | |
120 | * @return true if the mouse is currently on the maximize/restore button | |
121 | */ | |
122 | @Override | |
123 | protected final boolean mouseOnMaximize() { | |
124 | return false; | |
125 | } | |
126 | ||
127 | /** | |
128 | * Returns true if the mouse is currently on the resizable lower right | |
129 | * corner. | |
130 | * | |
131 | * @return true if the mouse is currently on the resizable lower right | |
132 | * corner | |
133 | */ | |
134 | @Override | |
135 | protected final boolean mouseOnResize() { | |
136 | return false; | |
137 | } | |
138 | ||
0ee88b6d KL |
139 | /** |
140 | * Handle mouse button presses. | |
141 | * | |
142 | * @param mouse mouse button event | |
143 | */ | |
144 | @Override | |
145 | public void onMouseDown(final TMouseEvent mouse) { | |
146 | this.mouse = mouse; | |
147 | ||
148 | // Pass to children | |
149 | for (TWidget widget: getChildren()) { | |
150 | if (widget.mouseWouldHit(mouse)) { | |
151 | // Dispatch to this child, also activate it | |
152 | activate(widget); | |
153 | ||
154 | // Set x and y relative to the child's coordinates | |
155 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
156 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
157 | widget.handleEvent(mouse); | |
158 | return; | |
159 | } | |
160 | } | |
161 | } | |
162 | ||
163 | /** | |
164 | * Handle mouse button releases. | |
165 | * | |
166 | * @param mouse mouse button release event | |
167 | */ | |
168 | @Override | |
169 | public void onMouseUp(final TMouseEvent mouse) { | |
170 | this.mouse = mouse; | |
171 | ||
172 | // Pass to children | |
173 | for (TWidget widget: getChildren()) { | |
174 | if (widget.mouseWouldHit(mouse)) { | |
175 | // Dispatch to this child, also activate it | |
176 | activate(widget); | |
177 | ||
178 | // Set x and y relative to the child's coordinates | |
179 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
180 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
181 | widget.handleEvent(mouse); | |
182 | return; | |
183 | } | |
184 | } | |
185 | } | |
186 | ||
187 | /** | |
188 | * Handle mouse movements. | |
189 | * | |
190 | * @param mouse mouse motion event | |
191 | */ | |
192 | @Override | |
193 | public void onMouseMotion(final TMouseEvent mouse) { | |
194 | this.mouse = mouse; | |
195 | ||
196 | // Default: do nothing, pass to children instead | |
197 | super.onMouseMotion(mouse); | |
198 | } | |
199 | ||
200 | /** | |
201 | * Handle keystrokes. | |
202 | * | |
203 | * @param keypress keystroke event | |
204 | */ | |
205 | @Override | |
206 | public void onKeypress(final TKeypressEvent keypress) { | |
207 | // Default: do nothing, pass to children instead | |
208 | super.onKeypress(keypress); | |
209 | } | |
210 | ||
211 | /** | |
212 | * Handle posted menu events. | |
213 | * | |
214 | * @param menu menu event | |
215 | */ | |
216 | @Override | |
217 | public void onMenu(final TMenuEvent menu) { | |
218 | // Default: do nothing, pass to children instead | |
219 | super.onMenu(menu); | |
220 | } | |
221 | ||
222 | } |