mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-10-10 23:40:12 +00:00
apps/graphics/twm4nx: Finsh menu-related event handling. Extended menu handling. Allow external application event handling using a new base class (CTwm4NxEvent).
This commit is contained in:
parent
ba58654955
commit
c144919a4e
15 changed files with 353 additions and 71 deletions
|
|
@ -67,6 +67,7 @@ namespace NXWidgets
|
|||
namespace Twm4Nx
|
||||
{
|
||||
class CTwm4Nx; // Forward reference
|
||||
|
||||
/**
|
||||
* Background management
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -47,8 +47,12 @@
|
|||
// Included Files
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <mqueue.h>
|
||||
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
#include "graphics/twm4nx/cwindow.hxx"
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation Classes
|
||||
|
|
@ -58,6 +62,7 @@ namespace NXWidgets
|
|||
{
|
||||
class CNxTkWindow; // Forward reference
|
||||
class CButtonArray; // Forward reference
|
||||
class CWidgetEventHandler; // Forward reference
|
||||
class CWidgetEventArgs; // Forward reference
|
||||
struct SRlePaletteBitmap; // Forward reference
|
||||
}
|
||||
|
|
@ -68,7 +73,7 @@ namespace Twm4Nx
|
|||
{
|
||||
FAR struct SWindowEntry *flink;
|
||||
FAR struct SWindowEntry *blink;
|
||||
FAR CWindow *cwin; // Used only for the window name
|
||||
FAR CWindow *cwin;
|
||||
FAR CIconMgr *iconmgr;
|
||||
nxgl_point_s pos;
|
||||
nxgl_size_s size;
|
||||
|
|
@ -78,11 +83,12 @@ namespace Twm4Nx
|
|||
bool down;
|
||||
};
|
||||
|
||||
class CIconMgr : protected NXWidgets::CWidgetEventHandler
|
||||
class CIconMgr : protected NXWidgets::CWidgetEventHandler, public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
|
||||
FAR CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
|
||||
mqd_t m_eventq; /**< NxWidget event message queue */
|
||||
FAR struct SWindowEntry *m_head; /**< Head of the window list */
|
||||
FAR struct SWindowEntry *m_tail; /**< Tail of the window list */
|
||||
FAR struct SWindowEntry *m_active; /**< The active entry */
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@
|
|||
|
||||
#include "graphics/nxwidgets/cnxwindow.hxx"
|
||||
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -69,7 +71,7 @@ namespace Twm4Nx
|
|||
* The CIconWin represents on icon window
|
||||
*/
|
||||
|
||||
class CIconWin
|
||||
class CIconWin : public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -48,11 +48,13 @@
|
|||
// Included Files
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "mqueue.h"
|
||||
#include <mqueue.h>
|
||||
|
||||
#include "graphics/nxwidgets/cwidgeteventhandler.hxx"
|
||||
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
|
||||
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Pre-processor Definitions
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -83,6 +85,8 @@ namespace NXWidgets
|
|||
{
|
||||
class CNxTkWindow; // Forward reference
|
||||
class CListBox; // Forward reference
|
||||
class CWidgetEventArgs; // Forward reference
|
||||
class CWidgetEventArgs; // Forward reference
|
||||
}
|
||||
|
||||
namespace Twm4Nx
|
||||
|
|
@ -97,18 +101,17 @@ namespace Twm4Nx
|
|||
FAR struct SMenuItem *blink; /**< Backward link previous menu item */
|
||||
FAR CMenus *subMenu; /**< Menu root of a pull right menu */
|
||||
FAR char *text; /**< The text string for the menu item */
|
||||
FAR const char *action; /**< Action to be performed */
|
||||
short index; /**< Index of this menu item */
|
||||
short func; /**< Built-in function */
|
||||
FAR CTwm4NxEvent *handler; /**< Application event handler */
|
||||
uint16_t index; /**< Index of this menu item */
|
||||
uint16_t event; /**< Menu selection event */
|
||||
};
|
||||
|
||||
class CMenus: protected NXWidgets::CWidgetEventHandler
|
||||
class CMenus : protected NXWidgets::CWidgetEventHandler, public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
|
||||
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
|
||||
mqd_t m_eventq; /**< NxWidget event message queue */
|
||||
FAR struct SFuncKey *m_funcKeyHead; /**< Head of function key list */
|
||||
FAR NXWidgets::CNxTkWindow *m_menuWindow; /**< The menu window */
|
||||
FAR CMenus *m_popUpMenu; /**< Pop-up menu */
|
||||
FAR NXWidgets::CListBox *m_menuListBox; /**< The menu list box */
|
||||
|
|
@ -230,6 +233,15 @@ namespace Twm4Nx
|
|||
|
||||
bool popUpMenu(FAR struct nxgl_point_s *pos);
|
||||
|
||||
/**
|
||||
* Override the virtual value change event. This will get events
|
||||
* when there is a change in the list box selection.
|
||||
*
|
||||
* @param e The event data.
|
||||
*/
|
||||
|
||||
void handleValueChangeEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||
|
||||
/**
|
||||
* Cleanup or initialization error or on deconstruction.
|
||||
*/
|
||||
|
|
@ -265,14 +277,14 @@ namespace Twm4Nx
|
|||
* Add an item to a root menu
|
||||
*
|
||||
* \param text The text to appear in the menu
|
||||
* \param action The string to possibly execute
|
||||
* \param subMenu The menu root if it is a pull-right entry
|
||||
* \param func The numeric function
|
||||
* \param handler The application event handler. Should be NULL unless
|
||||
* the event recipient is EVENT_RECIPIENT_APP
|
||||
* \param event The event to generate on menu item selection
|
||||
*/
|
||||
|
||||
bool addMenuItem(FAR const char *text,
|
||||
FAR const char *action,
|
||||
FAR CMenus *subMenu, int func);
|
||||
bool addMenuItem(FAR const char *text, FAR CMenus *subMenu,
|
||||
FAR CTwm4NxEvent *handler, uint16_t event);
|
||||
|
||||
/**
|
||||
* Handle MENU events.
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@
|
|||
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation Classes
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -63,10 +65,10 @@ namespace NXWidgets
|
|||
|
||||
namespace Twm4Nx
|
||||
{
|
||||
class CWindow; // Forward referernce
|
||||
struct SEventMsg; // Forward referernce
|
||||
class CWindow; // Forward reference
|
||||
struct SEventMsg; // Forward reference
|
||||
|
||||
class CResize
|
||||
class CResize : protected NXWidgets::CWidgetEventHandler, public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
|
||||
|
|
|
|||
91
include/graphics/twm4nx/ctwm4nxevent.hxx
Normal file
91
include/graphics/twm4nx/ctwm4nxevent.hxx
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
// apps/graphics/twm4nx/include/ctwmnxevent.hxx
|
||||
// Twm4Nx Event handler base class
|
||||
//
|
||||
// Copyright (C) 2019 Gregory Nutt. All rights reserved.
|
||||
// Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in
|
||||
// the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// 3. Neither the name NuttX nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software
|
||||
// without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __APPS_INCLUDE_GRAPHICS_TWM4NX_CTWM4NXEVNT_HXX
|
||||
#define __APPS_INCLUDE_GRAPHICS_TWM4NX_CTWM4NXEVNT_HXX
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <cstdbool>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation Class Definition
|
||||
****************************************************************************/
|
||||
|
||||
namespace Twm4Nx
|
||||
{
|
||||
/**
|
||||
* Twm4Nx Event Handler base class
|
||||
*/
|
||||
|
||||
class CTwm4NxEvent
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* A virtual destructor is required in order to override the INxWindow
|
||||
* destructor. We do this because if we delete INxWindow, we want the
|
||||
* destructor of the class that inherits from INxWindow to run, not this
|
||||
* one.
|
||||
*/
|
||||
|
||||
virtual ~CTwm4NxEvent(void)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Twm4Nx events.
|
||||
*
|
||||
* @param eventmsg. The received NxWidget WINDOW event message.
|
||||
* @return True if the message was properly handled. false is
|
||||
* return on any failure.
|
||||
*/
|
||||
|
||||
virtual bool event(FAR struct SEventMsg *eventmsg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CTWM4NXEVNT_HXX
|
||||
|
|
@ -57,6 +57,7 @@
|
|||
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
|
||||
|
||||
#include "graphics/twm4nx/ciconwin.hxx"
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Pre-processor Definitions
|
||||
|
|
@ -102,7 +103,7 @@ namespace Twm4Nx
|
|||
// The CWindow class implements a standard, framed window with a toolbar
|
||||
// containing the standard buttons and the window title.
|
||||
|
||||
class CWindow : protected NXWidgets::CWidgetEventHandler
|
||||
class CWindow : protected NXWidgets::CWidgetEventHandler, public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
|
||||
|
|
@ -330,6 +331,16 @@ namespace Twm4Nx
|
|||
FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
|
||||
bool isIconMgr, FAR CIconMgr *iconMgr, bool noToolbar);
|
||||
|
||||
/**
|
||||
* Get the widget control instance needed to support application drawing
|
||||
* into the window.
|
||||
*/
|
||||
|
||||
inline FAR NXWidgets::CWidgetControl *getWidgetControl()
|
||||
{
|
||||
return m_nxWin->getWidgetControl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the window
|
||||
*/
|
||||
|
|
@ -612,7 +623,7 @@ namespace Twm4Nx
|
|||
}
|
||||
|
||||
/**
|
||||
* Handle WINDOW events.
|
||||
* Handle Twm4Nx events.
|
||||
*
|
||||
* @param eventmsg. The received NxWidget WINDOW event message.
|
||||
* @return True if the message was properly handled. false is
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#include <cstdbool>
|
||||
|
||||
#include "graphics/twm4nx/cwindow.hxx"
|
||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation Classes
|
||||
|
|
@ -85,7 +86,7 @@ namespace Twm4Nx
|
|||
* things that are common to all windows.
|
||||
*/
|
||||
|
||||
class CWindowFactory
|
||||
class CWindowFactory: public CTwm4NxEvent
|
||||
{
|
||||
private:
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ namespace Twm4Nx
|
|||
{
|
||||
class CWindow; // Forward reference
|
||||
class CWindowEvent; // Forward reference
|
||||
class CTwm4NxEvent; // Forward reference
|
||||
class CTwm4Nx; // Forward reference
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -89,6 +90,7 @@ namespace Twm4Nx
|
|||
EVENT_RECIPIENT_TOOLBAR = 0x6000, /**< Toolbar related event */
|
||||
EVENT_RECIPIENT_BORDER = 0x7000, /**< Window border related event */
|
||||
EVENT_RECIPIENT_RESIZE = 0x8000, /**< Window resize event */
|
||||
EVENT_RECIPIENT_APP = 0x9000, /**< App received event via CTwn4NxEvent */
|
||||
EVENT_RECIPIENT_MASK = 0xf000, /**< Used to isolate recipient */
|
||||
};
|
||||
|
||||
|
|
@ -104,8 +106,9 @@ namespace Twm4Nx
|
|||
|
||||
// Recipient == SYSTEM
|
||||
|
||||
EVENT_SYSTEM_ERROR = 0x1000, /**< Report system error */
|
||||
EVENT_SYSTEM_EXIT = 0x1001, /**< Terminate the Twm4Nx session */
|
||||
EVENT_SYSTEM_NOP = 0x1000, /**< Null event */
|
||||
EVENT_SYSTEM_ERROR = 0x1001, /**< Report system error */
|
||||
EVENT_SYSTEM_EXIT = 0x1002, /**< Terminate the Twm4Nx session */
|
||||
|
||||
// Recipient == ICONWIN
|
||||
|
||||
|
|
@ -131,8 +134,8 @@ namespace Twm4Nx
|
|||
EVENT_WINDOW_UNFOCUS = 0x5001, /**< Exit modal state */
|
||||
EVENT_WINDOW_RAISE = 0x5002, /**< Raise window to the top of the heirarchy */
|
||||
EVENT_WINDOW_LOWER = 0x5003, /**< Lower window to the bottom of the heirarchy */
|
||||
EVENT_WINDOW_DRAG = 0x5004, /**< Drag window */
|
||||
EVENT_WINDOW_POPUP = 0x5005, /**< De-iconify and raise window */
|
||||
EVENT_WINDOW_DEICONIFY = 0x5004, /**< De-iconify and raise window */
|
||||
EVENT_WINDOW_DRAG = 0x5005, /**< Drag window */
|
||||
EVENT_WINDOW_DELETE = 0x5006, /**< Delete window */
|
||||
|
||||
// Recipient == TOOLBAR
|
||||
|
|
@ -156,6 +159,11 @@ namespace Twm4Nx
|
|||
EVENT_RESIZE_RIGHTZOOM = 0x8005, /**< Zoom right only */
|
||||
EVENT_RESIZE_TOPZOOM = 0x8006, /**< Zoom top only */
|
||||
EVENT_RESIZE_BOTTOMZOOM = 0x8007, /**< Zoom bottom only */
|
||||
|
||||
// Recipient == ICONWIN
|
||||
// All application defined events must (1) use recepient == EVENT_RECIPIENT_APP,
|
||||
// and (2) provide an instance of CTwm4NxEvent in the SEventMsg structure.
|
||||
|
||||
};
|
||||
|
||||
// Contexts for button press events
|
||||
|
|
@ -183,6 +191,7 @@ namespace Twm4Nx
|
|||
struct nxgl_point_s pos; /**< X/Y position */
|
||||
struct nxgl_point_s delta; /**< X/Y change (for dragging only) */
|
||||
uint8_t context; /**< Button press context */
|
||||
FAR CTwm4NxEvent *handler; /**< App event handler (APP recipient only) */
|
||||
FAR void *obj; /**< Window object (CWindow or CIconWin) */
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue