NXWidgets  1.19
ctaskbar.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/nxwm/include/cnxtaskbar.hxx
3  *
4  * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
5  * Author: Gregory Nutt <gnutt@nuttx.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  * 3. Neither the name NuttX, NxWidgets, nor the names of its contributors
18  * me be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  ****************************************************************************/
35 
36 #ifndef __NXWM_INCLUDE_CTASKBAR_HXX
37 #define __NXWM_INCLUDE_CTASKBAR_HXX
38 
39 /****************************************************************************
40  * Included Files
41  ****************************************************************************/
42 
43 #include <nuttx/config.h>
44 
45 #include "nxconfig.hxx"
46 #include "tnxarray.hxx"
47 #include "cnxwindow.hxx"
48 #include "cnxserver.hxx"
49 #include "cwidgeteventhandler.hxx"
50 #include "cwidgeteventargs.hxx"
51 
52 #include "nxwmconfig.hxx"
53 #include "nxwmglyphs.hxx"
54 
55 #include "capplicationwindow.hxx"
56 #include "cfullscreenwindow.hxx"
57 #include "iapplication.hxx"
58 
59 /****************************************************************************
60  * Pre-processor Definitions
61  ****************************************************************************/
62 
63 /****************************************************************************
64  * Implementation Class Definition
65  ****************************************************************************/
66 
67 #if defined(__cplusplus)
68 
69 namespace NxWM
70 {
71  /**
72  * This class describes the NX window manager's task bar. That task bar is,
73  * of course, used to dock active applications. But in NxWM, it is also
74  * the heart of the window manager: It inherits for CNxServer and, hence,
75  * represents the NX server itself. It also then serves as the NxWM
76  * window factory.
77  *
78  * Why do it this way? The only reason is so that if you have an instance
79  * of CTaskbar, you have everything you need to manage new applications.
80  * It might have been a better decision to separate the window factory into
81  * a separate class instead of making the task bar of such central importance
82  * (and I may still do that someday)
83  */
84 
87  {
88  protected:
89  /**
90  * This structure represents an application and its associated icon image
91  */
92 
93  struct STaskbarSlot
94  {
95  IApplication *app; /**< A reference to the application */
96  NXWidgets::CImage *image; /**< The icon image for the application */
97  };
98 
99  /**
100  * Taskbar state
101  */
102 
103  NXWidgets::CNxWindow *m_taskbar; /**< The task bar window */
104  NXWidgets::CNxWindow *m_background; /**< The background window */
105  NXWidgets::CImage *m_backImage; /**< The background image */
106  IApplication *m_topApp; /**< The top application in the hierarchy */
107  TNxArray<struct STaskbarSlot> m_slots; /**< List of application slots in the task bar */
108  bool m_started; /**< True if window manager has been started */
109 
110  /**
111  * Create a raw window.
112  *
113  * 1) Create a dumb NXWidgets::CWidgetControl instance (See not).
114  * 2) Pass the dumb NXWidgets::CWindowMessenger instance to the window constructor
115  * that inherits from INxWindow. This will "smarten" the NXWidgets::CWidgetControl
116  * instance with some window knowlede
117  * 3) Call the open() method on the window to display the window.
118  * 4) After that, the fully smartened NXWidgets::CWidgetControl instance can
119  * be used to generate additional widgets by passing it to the
120  * widget constructor
121  *
122  * NOTE: Actually, NxWM uses the CWindowMessenger class that inherits from
123  * CWidgetControl. That class just adds some unrelated messaging capability;
124  * It cohabitates with CWidgetControl only becuase it needs the CWidgetControl
125  * this point.
126  */
127 
129 
130  /**
131  * Create a framed application window
132  *
133  * This may be used to provide the window parater to the IApplication constructor
134  *
135  * @return A partially initialized application window instance.
136  */
137 
139 
140  /**
141  * Set size and position of a window in the application area.
142  *
143  * @param window. The window to be resized and repositioned
144  * @param fullscreen. True: Use full screen
145  */
146 
147  void setApplicationGeometry(NXWidgets::INxWindow *window, bool fullscreen);
148 
149  /**
150  * Create the task bar window.
151  *
152  * @return true on success
153  */
154 
155  virtual bool createTaskbarWindow(void);
156 
157  /**
158  * Create the background window.
159  *
160  * @return true on success
161  */
162 
163  virtual bool createBackgroundWindow(void);
164 
165  /**
166  * Create the background image.
167  *
168  * @return true on success
169  */
170 
171  virtual bool createBackgroundImage(void);
172 
173  /**
174  * (Re-)draw the task bar window.
175  *
176  * @return true on success
177  */
178 
179  virtual bool redrawTaskbarWindow(void);
180 
181  /**
182  * Redraw the window at the top of the heirarchy.
183  *
184  * @return true on success
185  */
186 
187  virtual bool redrawTopApplication(void);
188 
189  /**
190  * Raise the top window to the top of the NXheirarchy.
191  *
192  * @return true on success
193  */
194 
195  void raiseTopApplication(void);
196 
197  /**
198  * (Re-)draw the background window.
199  *
200  * @return true on success
201  */
202 
203  virtual bool redrawBackgroundWindow(void);
204 
205  /**
206  * Redraw the last application in the list of application maintained by
207  * the task bar.
208  *
209  * @param app. The new top application to draw
210  * @return true on success
211  */
212 
214 
215  /**
216  * The application window is hidden (either it is minimized or it is
217  * maximized, but not at the top of the hierarchy)
218  *
219  * @param app. The application to hide
220  */
221 
223 
224  /**
225  * Handle a widget action event. For CImage, this is a mouse button pre-release event.
226  *
227  * @param e The event data.
228  */
229 
231 
232  public:
233  /**
234  * CTaskbar Constructor
235  *
236  * @param hWnd - NX server handle
237  */
238 
239  CTaskbar(void);
240 
241  /**
242  * CTaskbar Destructor
243  */
244 
245  ~CTaskbar(void);
246 
247  /**
248  * Connect to the server
249  */
250 
251  bool connect(void);
252 
253  /**
254  * Disconnect from the server
255  */
256 
257  void disconnect(void);
258 
259  /**
260  * Initialize task bar. Task bar initialization is separate from
261  * object instantiation so that failures can be reported. The window
262  * manager start-up sequence is:
263  *
264  * 1. Create the CTaskbar instance,
265  * 2. Call the CTaskbar::connect() method to connect to the NX server (CTaskbar
266  * inherits the connect method from CNxServer),
267  * 3. Call the CTaskbar::initWindowManager() method to initialize the task bar.
268  * 4. Call CTaskBar::startApplication repeatedly to add applications to the task bar
269  * 5. Call CTaskBar::startWindowManager() to start the display with applications in place
270  *
271  * CTaskbar::initWindowManager() prepares the task bar to receive applications.
272  * CTaskBar::startWindowManager() brings the window manager up with those applications
273  * in place.
274  *
275  * @return True if the window was successfully initialized.
276  */
277 
278  bool initWindowManager(void);
279 
280  /**
281  * Start the window manager and present the initial displays. The window
282  * manager start-up sequence is:
283  *
284  * 1. Create the CTaskbar instance,
285  * 2. Call the CTaskbar::connect() method to connect to the NX server (CTaskbar
286  * inherits the connect method from CNxServer),
287  * 3. Call the CTaskbar::initWindowManager() method to initialize the task bar.
288  * 4. Call CTaskBar::startApplication repeatedly to add applications to the task bar
289  * 5. Call CTaskBar::startWindowManager to start the display with applications in place
290  *
291  * CTaskbar::initWindowManager() prepares the task bar to receive applications.
292  * CTaskBar::startWindowManager() brings the window manager up with those applications
293  * in place.
294  *
295  * CTaskBar::startWindowManager() will present the task bar and the background image.
296  * The The initial taskbar will contain only the start window icon.
297  *
298  * @return true on success
299  */
300 
301  bool startWindowManager(void);
302 
303  /**
304  * Create an normal application window. Creating a normal application in the
305  * start window requires three steps:
306  *
307  * 1. Call CTaskBar::openApplicationWindow to create a window for the application,
308  * 2. Instantiate the application, providing the window to the application's
309  * constructor,
310  * 3. Then call CStartWindow::addApplication to add the application to the
311  * start window.
312  *
313  * When the application is selected from the start window:
314  *
315  * 4. Call CTaskBar::startApplication start the application and bring its window to
316  * the top.
317  *
318  * @param flags. CApplicationWindow flugs for window customization.
319  */
320 
321  CApplicationWindow *openApplicationWindow(uint8_t flags = 0);
322 
323  /**
324  * Create a full screen application window. Creating a new full screen application
325  * requires three steps:
326  *
327  * 1. Call CTaskBar::FullScreenWindow to create a window for the application,
328  * 2. Instantiate the application, providing the window to the application's
329  * constructor,
330  * 3. Then call CStartWindow::addApplication to add the application to the
331  * start window.
332  *
333  * When the application is selected from the start window:
334  *
335  * 4. Call CTaskBar::startApplication start the application and bring its window to
336  * the top.
337  */
338 
340 
341  /**
342  * Start an application and add its icon to the taskbar. The applications's
343  * window is brought to the top. Creating a new application in the start
344  * window requires three steps:
345  *
346  * 1. Call CTaskBar::openApplicationWindow to create a window for the application,
347  * 2. Instantiate the application, providing the window to the application's
348  * constructor,
349  * 3. Then call CStartWindow::addApplication to add the application to the start window.
350  *
351  * When the application is selected from the start window:
352  *
353  * 4. Call CTaskBar::startApplication start the application and bring its window to
354  * the top.
355  *
356  * @param app. The new application to add to the task bar
357  * @param minimized. The new application starts in the minimized state
358  * @return true on success
359  */
360 
361  bool startApplication(IApplication *app, bool minimized);
362 
363  /**
364  * Move window to the top of the hierarchy and re-draw it. This method
365  * does nothing if the application is minimized.
366  *
367  * @param app. The new application to show
368  * @return true on success
369  */
370 
372 
373  /**
374  * Maximize an application by moving its window to the top of the hierarchy
375  * and re-drawing it. If the application was already maximized, then this
376  * method is equivalent to topApplication().
377  *
378  * @param app. The new application to add to the task bar
379  * @return true on success
380  */
381 
383 
384  /**
385  * Minimize an application by moving its window to the bottom of the
386  * and redrawing the next visible appliation.
387  *
388  * @param app. The new application to add to the task bar
389  * @return true on success
390  */
391 
393 
394  /**
395  * Destroy an application. Move its window to the bottom and remove its
396  * icon from the task bar.
397  *
398  * @param app. The new application to remove from the task bar
399  * @return true on success
400  */
401 
403 
404  /**
405  * Get the size of the physical display device as it is known to the task
406  * bar.
407  *
408  * @return The size of the display
409  */
410 
411  void getDisplaySize(FAR struct nxgl_size_s &size);
412 
413  /**
414  * Force a redraw of the taskbar and current application.
415  * This should only be necessary if the display loses state due to e.g. powerdown
416  * or other manual intervention.
417  */
418 
419  inline void redraw() { redrawTopApplication(); }
420 
421  /**
422  * Simulate a mouse click or release on the icon at index. This method
423  * is only available during automated testing of NxWM.
424  *
425  * @param index. Selects the icon in the start window
426  * @param click. True to click and false to release
427  */
428 
429 #if defined(CONFIG_NXWM_UNITTEST) && !defined(CONFIG_NXWM_TOUCHSCREEN)
430  void clickIcon(int index, bool click);
431 #endif
432  };
433 }
434 
435 #endif // __cplusplus
436 #endif // __NXWM_INCLUDE_CTASKBAR_HXX
void handleActionEvent(const NXWidgets::CWidgetEventArgs &e)
Definition: ctaskbar.cxx:1452
virtual bool redrawBackgroundWindow(void)
Definition: ctaskbar.cxx:1323
NXWidgets::CImage * image
Definition: ctaskbar.hxx:96
bool startWindowManager(void)
Definition: ctaskbar.cxx:250
bool topApplication(IApplication *app)
Definition: ctaskbar.cxx:586
void raiseTopApplication(void)
Definition: ctaskbar.cxx:1299
bool startApplication(IApplication *app, bool minimized)
Definition: ctaskbar.cxx:450
bool stopApplication(IApplication *app)
Definition: ctaskbar.cxx:667
bool redrawApplicationWindow(IApplication *app)
Definition: ctaskbar.cxx:1375
CApplicationWindow * openApplicationWindow(uint8_t flags=0)
Definition: ctaskbar.cxx:365
NXWidgets::CImage * m_backImage
Definition: ctaskbar.hxx:105
IApplication * m_topApp
Definition: ctaskbar.hxx:106
void hideApplicationWindow(IApplication *app)
Definition: ctaskbar.cxx:1415
void disconnect(void)
Definition: ctaskbar.cxx:118
virtual bool createBackgroundWindow(void)
Definition: ctaskbar.cxx:1014
NXWidgets::CNxWindow * m_background
Definition: ctaskbar.hxx:104
virtual bool redrawTopApplication(void)
Definition: ctaskbar.cxx:1255
bool minimizeApplication(IApplication *app)
Definition: ctaskbar.cxx:639
void getDisplaySize(FAR struct nxgl_size_s &size)
Definition: ctaskbar.cxx:733
virtual bool redrawTaskbarWindow(void)
Definition: ctaskbar.cxx:1113
NXWidgets::CNxWindow * openRawWindow(void)
Definition: ctaskbar.cxx:808
void clickIcon(int index, bool click)
Definition: ctaskbar.cxx:758
CFullScreenWindow * openFullScreenWindow(void)
Definition: ctaskbar.cxx:406
virtual bool createTaskbarWindow(void)
Definition: ctaskbar.cxx:950
virtual bool createBackgroundImage(void)
Definition: ctaskbar.cxx:1036
NXWidgets::CNxWindow * m_taskbar
Definition: ctaskbar.hxx:103
~CTaskbar(void)
Definition: ctaskbar.cxx:83
void setApplicationGeometry(NXWidgets::INxWindow *window, bool fullscreen)
Definition: ctaskbar.cxx:882
bool initWindowManager(void)
Definition: ctaskbar.cxx:206
TNxArray< struct STaskbarSlot > m_slots
Definition: ctaskbar.hxx:107
CTaskbar(void)
Definition: ctaskbar.cxx:70
bool connect(void)
Definition: ctaskbar.cxx:95
NXWidgets::CNxTkWindow * openFramedWindow(void)
Definition: ctaskbar.cxx:845
bool maximizeApplication(IApplication *app)
Definition: ctaskbar.cxx:620