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