NXWidgets  1.19
cstartwindow.hxx
Go to the documentation of this file.
1 /****************************************************************************
2  * NxWidgets/nxwm/include/cnxstart.hxx
3  *
4  * Copyright (C) 2012 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 __INCLUDE_CSTARTWINDOW_NXX
37 #define __INCLUDE_CSTARTWINDOW_NXX
38 
39 /****************************************************************************
40  * Included Files
41  ****************************************************************************/
42 
43 #include <nuttx/config.h>
44 
45 #include <debug.h>
46 
47 #include "tnxarray.hxx"
48 
49 #include "iapplication.hxx"
50 #include "capplicationwindow.hxx"
51 
52 /****************************************************************************
53  * Pre-Processor Definitions
54  ****************************************************************************/
55 
56 /****************************************************************************
57  * Abstract Base Classes
58  ****************************************************************************/
59 
60 #if defined(__cplusplus)
61 
62 namespace NxWM
63 {
64  /**
65  * Forward references
66  */
67 
68  class CTaskbar;
69 
70  /**
71  * Start window message opcodes and format
72  */
73 
75  {
76  MSGID_POSITIONAL_CHANGE = 1, /**< Change in window positional data (not used) */
77  MSGID_REDRAW_REQUEST, /**< Request to redraw a portion of the window (not used) */
78  MSGID_MOUSE_INPUT, /**< New mouse input is available */
79  MSGID_KEYBOARD_INPUT, /**< New keyboard input is available */
80  MSGID_DESTROY_APP /**< Destroy the application */
81  };
82 
84  {
85  enum EStartWindowMessageOpcodes msgId; /**< The message opcode */
86  FAR void *instance; /**< Object instance. */
87  };
88 
89  /**
90  * The well-known name for the Start Window's message queue.
91  */
92 
93  extern FAR const char *g_startWindowMqName;
94 
95  /**
96  * This class is the the start window application.
97  */
98 
99  class CStartWindow : public IApplication,
100  protected IApplicationCallback,
102  {
103  protected:
104  /**
105  * This structure represents an application and its associated icon image
106  */
107 
109  {
110  IApplicationFactory *app; /**< A reference to the icon */
111  NXWidgets::CImage *image; /**< The icon image that goes with the application */
112  };
113 
114  /**
115  * CStartWindow state data
116  */
117 
118  CTaskbar *m_taskbar; /**< Reference to the "parent" taskbar */
119  CApplicationWindow *m_window; /**< Reference to the application window */
120  TNxArray<struct SStartWindowSlot> m_slots; /**< List of apps in the start window */
121  struct nxgl_size_s m_iconSize; /**< A box big enough to hold the largest icon */
122 
123  /**
124  * This is the start window task. This function receives window events from
125  * the NX listener threads indirectly through this sequence:
126  *
127  * 1. The NX listener thread receives a windows event. The NX listener thread
128  * which is part of CTaskBar and was created when NX server connection was
129  * established). This event may be a positional change notification, a
130  * redraw request, or mouse or keyboard input.
131  * 2. The NX listener thread handles the message by calling nx_eventhandler().
132  * nx_eventhandler() dispatches the message by calling a method in the
133  * NXWidgets::CCallback instance associated with the window.
134  * NXWidgets::CCallback is a part of the CWidgetControl.
135  * 3. NXWidgets::CCallback calls into NXWidgets::CWidgetControl to process
136  * the event.
137  * 4. NXWidgets::CWidgetControl records the new state data and raises a
138  * window event.
139  * 5. NXWidgets::CWindowEventHandlerList will give the event to
140  * NxWM::CWindowMessenger.
141  * 6. NxWM::CWindowMessenger will send the a message on a well-known message
142  * queue.
143  * 7. This CStartWindow::startWindow task will receive and process that
144  * message.
145  */
146 
147  static int startWindow(int argc, char *argv[]);
148 
149  /**
150  * Called when the window minimize button is pressed.
151  */
152 
153  void minimize(void);
154 
155  /**
156  * Called when the window close button is pressed.
157  */
158 
159  void close(void);
160 
161  /**
162  * Calculate the icon bounding box
163  */
164 
165  void getIconBounds(void);
166 
167  /**
168  * Stop all applications
169  */
170 
171  void removeAllApplications(void);
172 
173  /**
174  * Handle a widget action event. For CButtonArray, this is a mouse
175  * button pre-release event.
176  *
177  * @param e The event data.
178  */
179 
180  void handleActionEvent(const NXWidgets::CWidgetEventArgs &e);
181 
182  public:
183 
184  /**
185  * CStartWindow Constructor
186  *
187  * @param taskbar. A pointer to the parent task bar instance
188  * @param window. The window to be used by this application.
189  */
190 
191  CStartWindow(CTaskbar *taskbar, CApplicationWindow *window);
192 
193  /**
194  * CStartWindow Constructor
195  */
196 
197  ~CStartWindow(void);
198 
199  /**
200  * Each implementation of IApplication must provide a method to recover
201  * the contained CApplicationWindow instance.
202  */
203 
204  IApplicationWindow *getWindow(void) const;
205 
206  /**
207  * Get the icon associated with the application
208  *
209  * @return An instance if IBitmap that may be used to rend the
210  * application's icon. This is an new IBitmap instance that must
211  * be deleted by the caller when it is no long needed.
212  */
213 
214  NXWidgets::IBitmap *getIcon(void);
215 
216  /**
217  * Get the name string associated with the application
218  *
219  * @return A copy if CNxString that contains the name of the application.
220  */
221 
222  NXWidgets::CNxString getName(void);
223 
224  /**
225  * Start the application.
226  *
227  * @return True if the application was successfully started.
228  */
229 
230  bool run(void);
231 
232  /**
233  * Stop the application.
234  */
235 
236  void stop(void);
237 
238  /**
239  * Destroy the application and free all of its resources. This method
240  * will initiate blocking of messages from the NX server. The server
241  * will flush the window message queue and reply with the blocked
242  * message. When the block message is received by CWindowMessenger,
243  * it will send the destroy message to the start window task which
244  * will, finally, safely delete the application.
245  */
246 
247  void destroy(void);
248 
249  /**
250  * The application window is hidden (either it is minimized or it is
251  * maximized, but not at the top of the hierarchy)
252  */
253 
254  void hide(void);
255 
256  /**
257  * Redraw the entire window. The application has been maximized or
258  * otherwise moved to the top of the hiearchy. This method is call from
259  * CTaskbar when the application window must be displayed
260  */
261 
262  void redraw(void);
263 
264  /**
265  * Report of this is a "normal" window or a full screen window. The
266  * primary purpose of this method is so that window manager will know
267  * whether or not it show draw the task bar.
268  *
269  * @return True if this is a full screen window.
270  */
271 
272  bool isFullScreen(void) const;
273 
274  /**
275  * Add the application to the start window. The general sequence for
276  * setting up the start window is:
277  *
278  * 1. Call IAppicationFactory::create to a new instance of the application
279  * 2. Call CStartWindow::addApplication to add the application to the
280  * start window.
281  *
282  * @param app. The new application to add to the start window
283  * @return true on success
284  */
285 
286  bool addApplication(IApplicationFactory *app);
287 
288  /**
289  * Simulate a mouse click or release on the icon at index. This method
290  * is only available during automated testing of NxWM.
291  *
292  * @param index. Selects the icon in the start window
293  * @param click. True to click and false to release
294  */
295 
296 #if defined(CONFIG_NXWM_UNITTEST) && !defined(CONFIG_NXWM_TOUCHSCREEN)
297  void clickIcon(int index, bool click);
298 #endif
299  };
300 }
301 
302 #endif // __cplusplus
303 
304 #endif // __INCLUDE_CSTARTWINDOW_NXX
CApplicationWindow * m_window
EStartWindowMessageOpcodes
TNxArray< struct SStartWindowSlot > m_slots
enum EStartWindowMessageOpcodes msgId
FAR const char * g_startWindowMqName