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; | |
36 | import jexer.event.TResizeEvent; | |
37 | ||
38 | /** | |
39 | * TDesktop is a special-class window that is drawn underneath everything | |
92453213 KL |
40 | * else. Like a TWindow, it can contain widgets and perform "background" |
41 | * processing via onIdle(). But unlike a TWindow, it cannot be hidden, | |
42 | * moved, or resized. | |
43 | * | |
44 | * <p> | |
45 | * Events are passed to TDesktop as follows: | |
46 | * <ul> | |
47 | * <li>Mouse events are seen if they do not cover any other windows.</li> | |
48 | * <li>Keypress events are seen if no other windows are open.</li> | |
49 | * <li>Menu events are seen if no other windows are open.</li> | |
50 | * <li>Command events are seen if no other windows are open.</li> | |
51 | * <ul> | |
0ee88b6d KL |
52 | */ |
53 | public class TDesktop extends TWindow { | |
54 | ||
55 | /** | |
56 | * Public constructor. | |
57 | * | |
58 | * @param parent parent application | |
59 | */ | |
60 | public TDesktop(final TApplication parent) { | |
61 | ||
62 | super(parent, "", 0, 0, parent.getScreen().getWidth(), | |
63 | parent.getScreen().getHeight() - 1); | |
64 | ||
65 | setActive(false); | |
66 | } | |
67 | ||
68 | /** | |
69 | * The default TDesktop draws a hatch character across everything. | |
70 | */ | |
71 | @Override | |
72 | public void draw() { | |
73 | CellAttributes background = getTheme().getColor("tdesktop.background"); | |
74 | putAll(GraphicsChars.HATCH, background); | |
75 | } | |
76 | ||
92453213 KL |
77 | /** |
78 | * Hide window. This is a NOP for TDesktop. | |
79 | */ | |
80 | @Override | |
81 | public final void hide() {} | |
82 | ||
83 | /** | |
84 | * Show window. This is a NOP for TDesktop. | |
85 | */ | |
86 | @Override | |
87 | public final void show() {} | |
88 | ||
89 | /** | |
90 | * Called by hide(). This is a NOP for TDesktop. | |
91 | */ | |
92 | @Override | |
93 | public final void onHide() {} | |
94 | ||
95 | /** | |
96 | * Called by show(). This is a NOP for TDesktop. | |
97 | */ | |
98 | @Override | |
99 | public final void onShow() {} | |
100 | ||
101 | /** | |
102 | * Returns true if the mouse is currently on the close button. | |
103 | * | |
104 | * @return true if mouse is currently on the close button | |
105 | */ | |
106 | @Override | |
107 | protected final boolean mouseOnClose() { | |
108 | return false; | |
109 | } | |
110 | ||
111 | /** | |
112 | * Returns true if the mouse is currently on the maximize/restore button. | |
113 | * | |
114 | * @return true if the mouse is currently on the maximize/restore button | |
115 | */ | |
116 | @Override | |
117 | protected final boolean mouseOnMaximize() { | |
118 | return false; | |
119 | } | |
120 | ||
121 | /** | |
122 | * Returns true if the mouse is currently on the resizable lower right | |
123 | * corner. | |
124 | * | |
125 | * @return true if the mouse is currently on the resizable lower right | |
126 | * corner | |
127 | */ | |
128 | @Override | |
129 | protected final boolean mouseOnResize() { | |
130 | return false; | |
131 | } | |
132 | ||
0ee88b6d KL |
133 | /** |
134 | * Handle mouse button presses. | |
135 | * | |
136 | * @param mouse mouse button event | |
137 | */ | |
138 | @Override | |
139 | public void onMouseDown(final TMouseEvent mouse) { | |
140 | this.mouse = mouse; | |
141 | ||
142 | // Pass to children | |
143 | for (TWidget widget: getChildren()) { | |
144 | if (widget.mouseWouldHit(mouse)) { | |
145 | // Dispatch to this child, also activate it | |
146 | activate(widget); | |
147 | ||
148 | // Set x and y relative to the child's coordinates | |
149 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
150 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
151 | widget.handleEvent(mouse); | |
152 | return; | |
153 | } | |
154 | } | |
155 | } | |
156 | ||
157 | /** | |
158 | * Handle mouse button releases. | |
159 | * | |
160 | * @param mouse mouse button release event | |
161 | */ | |
162 | @Override | |
163 | public void onMouseUp(final TMouseEvent mouse) { | |
164 | this.mouse = mouse; | |
165 | ||
166 | // Pass to children | |
167 | for (TWidget widget: getChildren()) { | |
168 | if (widget.mouseWouldHit(mouse)) { | |
169 | // Dispatch to this child, also activate it | |
170 | activate(widget); | |
171 | ||
172 | // Set x and y relative to the child's coordinates | |
173 | mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX()); | |
174 | mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY()); | |
175 | widget.handleEvent(mouse); | |
176 | return; | |
177 | } | |
178 | } | |
179 | } | |
180 | ||
181 | /** | |
182 | * Handle mouse movements. | |
183 | * | |
184 | * @param mouse mouse motion event | |
185 | */ | |
186 | @Override | |
187 | public void onMouseMotion(final TMouseEvent mouse) { | |
188 | this.mouse = mouse; | |
189 | ||
190 | // Default: do nothing, pass to children instead | |
191 | super.onMouseMotion(mouse); | |
192 | } | |
193 | ||
194 | /** | |
195 | * Handle keystrokes. | |
196 | * | |
197 | * @param keypress keystroke event | |
198 | */ | |
199 | @Override | |
200 | public void onKeypress(final TKeypressEvent keypress) { | |
201 | // Default: do nothing, pass to children instead | |
202 | super.onKeypress(keypress); | |
203 | } | |
204 | ||
205 | /** | |
206 | * Handle posted menu events. | |
207 | * | |
208 | * @param menu menu event | |
209 | */ | |
210 | @Override | |
211 | public void onMenu(final TMenuEvent menu) { | |
212 | // Default: do nothing, pass to children instead | |
213 | super.onMenu(menu); | |
214 | } | |
215 | ||
216 | } |