Commit | Line | Data |
---|---|---|
0ee88b6d KL |
1 | /* |
2 | * Jexer - Java Text User Interface | |
3 | * | |
4 | * The MIT License (MIT) | |
5 | * | |
6 | * Copyright (C) 2017 Kevin Lamonte | |
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 | ||
54 | /** | |
55 | * Public constructor. | |
56 | * | |
57 | * @param parent parent application | |
58 | */ | |
59 | public TDesktop(final TApplication parent) { | |
60 | ||
61 | super(parent, "", 0, 0, parent.getScreen().getWidth(), | |
62 | parent.getScreen().getHeight() - 1); | |
63 | ||
64 | setActive(false); | |
65 | } | |
66 | ||
67 | /** | |
68 | * The default TDesktop draws a hatch character across everything. | |
69 | */ | |
70 | @Override | |
71 | public void draw() { | |
72 | CellAttributes background = getTheme().getColor("tdesktop.background"); | |
73 | putAll(GraphicsChars.HATCH, background); | |
74 | } | |
75 | ||
92453213 KL |
76 | /** |
77 | * Hide window. This is a NOP for TDesktop. | |
78 | */ | |
79 | @Override | |
80 | public final void hide() {} | |
81 | ||
82 | /** | |
83 | * Show window. This is a NOP for TDesktop. | |
84 | */ | |
85 | @Override | |
86 | public final void show() {} | |
87 | ||
88 | /** | |
89 | * Called by hide(). This is a NOP for TDesktop. | |
90 | */ | |
91 | @Override | |
92 | public final void onHide() {} | |
93 | ||
94 | /** | |
95 | * Called by show(). This is a NOP for TDesktop. | |
96 | */ | |
97 | @Override | |
98 | public final void onShow() {} | |
99 | ||
100 | /** | |
101 | * Returns true if the mouse is currently on the close button. | |
102 | * | |
103 | * @return true if mouse is currently on the close button | |
104 | */ | |
105 | @Override | |
106 | protected final boolean mouseOnClose() { | |
107 | return false; | |
108 | } | |
109 | ||
110 | /** | |
111 | * Returns true if the mouse is currently on the maximize/restore button. | |
112 | * | |
113 | * @return true if the mouse is currently on the maximize/restore button | |
114 | */ | |
115 | @Override | |
116 | protected final boolean mouseOnMaximize() { | |
117 | return false; | |
118 | } | |
119 | ||
120 | /** | |
121 | * Returns true if the mouse is currently on the resizable lower right | |
122 | * corner. | |
123 | * | |
124 | * @return true if the mouse is currently on the resizable lower right | |
125 | * corner | |
126 | */ | |
127 | @Override | |
128 | protected final boolean mouseOnResize() { | |
129 | return false; | |
130 | } | |
131 | ||
0ee88b6d KL |
132 | /** |
133 | * Handle mouse button presses. | |
134 | * | |
135 | * @param mouse mouse button event | |
136 | */ | |
137 | @Override | |
138 | public void onMouseDown(final TMouseEvent mouse) { | |
139 | this.mouse = mouse; | |
140 | ||
141 | // Pass to children | |
142 | for (TWidget widget: getChildren()) { | |
143 | if (widget.mouseWouldHit(mouse)) { | |
144 | // Dispatch to this child, also activate it | |
145 | activate(widget); | |
146 | ||
147 | // Set x and y relative to the child's coordinates | |
148 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
149 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
150 | widget.handleEvent(mouse); | |
151 | return; | |
152 | } | |
153 | } | |
154 | } | |
155 | ||
156 | /** | |
157 | * Handle mouse button releases. | |
158 | * | |
159 | * @param mouse mouse button release event | |
160 | */ | |
161 | @Override | |
162 | public void onMouseUp(final TMouseEvent mouse) { | |
163 | this.mouse = mouse; | |
164 | ||
165 | // Pass to children | |
166 | for (TWidget widget: getChildren()) { | |
167 | if (widget.mouseWouldHit(mouse)) { | |
168 | // Dispatch to this child, also activate it | |
169 | activate(widget); | |
170 | ||
171 | // Set x and y relative to the child's coordinates | |
172 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
173 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
174 | widget.handleEvent(mouse); | |
175 | return; | |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | /** | |
181 | * Handle mouse movements. | |
182 | * | |
183 | * @param mouse mouse motion event | |
184 | */ | |
185 | @Override | |
186 | public void onMouseMotion(final TMouseEvent mouse) { | |
187 | this.mouse = mouse; | |
188 | ||
189 | // Default: do nothing, pass to children instead | |
190 | super.onMouseMotion(mouse); | |
191 | } | |
192 | ||
193 | /** | |
194 | * Handle keystrokes. | |
195 | * | |
196 | * @param keypress keystroke event | |
197 | */ | |
198 | @Override | |
199 | public void onKeypress(final TKeypressEvent keypress) { | |
200 | // Default: do nothing, pass to children instead | |
201 | super.onKeypress(keypress); | |
202 | } | |
203 | ||
204 | /** | |
205 | * Handle posted menu events. | |
206 | * | |
207 | * @param menu menu event | |
208 | */ | |
209 | @Override | |
210 | public void onMenu(final TMenuEvent menu) { | |
211 | // Default: do nothing, pass to children instead | |
212 | super.onMenu(menu); | |
213 | } | |
214 | ||
215 | } |