Squashed commit of the following:

apps/graphics/twm4nx:  This resolves the problems noted in the previous commit comments.  Window events are now communicated properly to the appliation-specific event handler.  Menus now seem to be receiving events and working well.

    apps/graphics/twm4nx:  Revamp application event handler.  Better design but still crashes when a main menu entry is clicked.

    apps/graphics/twm4nx:  First cut at application window event distribution.  Has some issues.  Not ready for prime time.

    apps/graphics/twm4nx:  Add more controls for the events that will be generated on basic window redraw, mouse/keyboard input, and keyboard input.

    apps/graphpics/twm4nx:  Add a 'Desktop' item to the main menu that will iconify all windows and menus and just show the open desktop.
This commit is contained in:
Gregory Nutt 2019-05-10 15:22:27 -06:00
parent 28b4be1913
commit dbb5211060
15 changed files with 544 additions and 176 deletions

View file

@ -184,8 +184,7 @@ namespace Twm4Nx
void handleActionEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Return the name of the application. This is the string that will
* appear in the Main Menu item. This overrides the method from
* Return the Main Menu item string. This overrides the method from
* IApplication
*
* @param name The name of the application.
@ -197,10 +196,7 @@ namespace Twm4Nx
}
/**
* Return any submenu item associated with the menu entry. If a non-
* null value is returned, then this sub-menu will be brought up when
* the menu entry is selected. Otherwise, the start() method will be
* called. These two behaviors are mutually exlusive. This overrides
* There is no sub-menu for this Main Menu item. This overrides
* the method from IApplication.
*
* @return This implementation will always return a null value.
@ -212,13 +208,8 @@ namespace Twm4Nx
}
/**
* This is the application start up function. This function will be
* called when its menu entry has been selected in order to start the
* application. This function will not be called in this implementation
*
* @param twm4nx The Twm4Nx session object. Use with care! The CTwm4Nx
* logic runs on a different thread and some of the methods of the
* class may not be thread safe.
* There is no application start-up function. This function will not
* be called in this implementation
*/
inline void start(FAR CTwm4Nx *twm4nx)
@ -226,10 +217,7 @@ namespace Twm4Nx
}
/**
* External applications may provide their own event handler that runs
* when the the menu item is selection. If so, then this method will
* return the instance of CTwm4NxEvent that will handle the event. This
* method always returns NULL in this case.
* There is no custom event handler. We use the common event handler.
*
* @return. null is always returned in this impementation.
*/
@ -240,10 +228,10 @@ namespace Twm4Nx
}
/**
* Get the Twm4Nx event that will be generated when the menu item is
* selected.
* Return the Twm4Nx event that will be generated when the Main Menu
* item is selected.
*
* @return. This function returns .
* @return. This function always returns EVENT_ICONMGR_DEICONIFY.
*/
inline uint16_t getEvent(void)

View file

@ -115,19 +115,19 @@
namespace NXWidgets
{
class CNxString; // Forward reference
class CImage; // Forward reference
class CLabel; // Forward reference
struct SRlePaletteBitmap; // Forward reference
class CNxString; // Forward reference
class CImage; // Forward reference
class CLabel; // Forward reference
struct SRlePaletteBitmap; // Forward reference
}
namespace Twm4Nx
{
class CIconWidget; // Forward reference
class CIconMgr; // Forward reference
class CWindow; // Forward reference
struct SMenuRoot; // Forward reference
struct SMenuItem; // Forward reference
class CIconWidget; // Forward reference
class CIconMgr; // Forward reference
class CWindow; // Forward reference
struct SMenuRoot; // Forward reference
struct SMenuItem; // Forward reference
// The CWindow class implements a standard, framed window with a toolbar
// containing the standard buttons and the window title.
@ -137,35 +137,40 @@ namespace Twm4Nx
public CTwm4NxEvent
{
private:
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
mqd_t m_eventq; /**< NxWidget event message queue */
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
mqd_t m_eventq; /**< NxWidget event message queue */
// Primary Window
NXWidgets::CNxString m_name; /**< Name of the window */
FAR NXWidgets::CNxTkWindow *m_nxWin; /**< The contained NX primary window */
nxgl_coord_t m_minWidth; /**< The minimum width of the window */
uint16_t m_zoom; /**< Window zoom: ZOOM_NONE or EVENT_RESIZE_* */
bool m_modal; /**< Window zoom: ZOOM_NONE or EVENT_RESIZE_* */
NXWidgets::CNxString m_name; /**< Name of the window */
FAR NXWidgets::CNxTkWindow *m_nxWin; /**< The contained NX primary window */
FAR CWindowEvent *m_windowEvent; /**< Cached window event reference */
FAR void *m_eventObj; /**< Object reference that accompanies events */
nxgl_coord_t m_minWidth; /**< The minimum width of the window */
uint16_t m_redrawEvent; /**< Redraw event ID */
uint16_t m_mouseEvent; /**< Mouse/touchscreen event ID */
uint16_t m_kbdEvent; /**< Keyboard event ID */
uint16_t m_zoom; /**< Window zoom: ZOOM_NONE or EVENT_RESIZE_* */
bool m_modal; /**< Window zoom: ZOOM_NONE or EVENT_RESIZE_* */
// Icon
FAR NXWidgets::CRlePaletteBitmap *m_iconBitMap; /**< The icon image */
FAR CIconWidget *m_iconWidget; /**< The icon widget */
FAR CIconMgr *m_iconMgr; /**< Pointer to it if this is an icon manager */
bool m_iconMoved; /**< User explicitly moved the icon. */
bool m_iconOn; /**< Icon is visible. */
bool m_iconified; /**< Is the window an icon now ? */
FAR CIconWidget *m_iconWidget; /**< The icon widget */
FAR CIconMgr *m_iconMgr; /**< Pointer to it if this is an icon manager */
bool m_iconMoved; /**< User explicitly moved the icon. */
bool m_iconOn; /**< Icon is visible. */
bool m_iconified; /**< Is the window an icon now ? */
// Toolbar
FAR NXWidgets::CNxToolbar *m_toolbar; /**< The tool bar sub-window */
FAR NXWidgets::CLabel *m_tbTitle; /**< Toolbar title widget */
nxgl_coord_t m_tbHeight; /**< Height of the toolbar */
nxgl_coord_t m_tbLeftX; /**< Rightmost position of left buttons */
nxgl_coord_t m_tbRightX; /**< Leftmost position of right buttons */
uint8_t m_tbFlags; /**< Toolbar button customizations */
FAR NXWidgets::CNxToolbar *m_toolbar; /**< The tool bar sub-window */
FAR NXWidgets::CLabel *m_tbTitle; /**< Toolbar title widget */
nxgl_coord_t m_tbHeight; /**< Height of the toolbar */
nxgl_coord_t m_tbLeftX; /**< Rightmost position of left buttons */
nxgl_coord_t m_tbRightX; /**< Leftmost position of right buttons */
uint8_t m_tbFlags; /**< Toolbar button customizations */
// List of all toolbar button images
@ -173,14 +178,19 @@ namespace Twm4Nx
// Dragging
struct nxgl_point_s m_dragPos; /**< Last reported mouse position */
struct nxgl_size_s m_dragCSize; /**< The grab cursor size */
bool m_dragging; /**< True: Drag in-progress */
volatile bool m_clicked; /**< True: Mouse left button is clicked */
struct nxgl_point_s m_dragPos; /**< Last reported mouse position */
struct nxgl_size_s m_dragCSize; /**< The grab cursor size */
bool m_dragging; /**< True: Drag in-progress */
volatile bool m_clicked; /**< True: Mouse left button is clicked */
/**
* Create the main window
*
* Initially, the application window will generate no window-related events
* (redraw, mouse/touchscreen, keyboard input, etc.). After creating the
* window, the user may call the configureEvents() method to select the
* eventIDs of the events to be generated.
*
* @param winsize The initial window size
* @param winpos The initial window position
* @param flags Toolbar customizations see WFLAGS_NO_* definitions
@ -391,6 +401,10 @@ namespace Twm4Nx
/**
* CWindow Initializer (unlike the constructor, this may fail)
*
* The window is initialized with all application events disabled.
* The CWindows::configureEvents() method may be called as a second
* initialization step in order to enable application events.
*
* @param name The the name of the window (and its icon)
* @param pos The initial position of the window
* @param size The initial size of the window
@ -407,6 +421,24 @@ namespace Twm4Nx
FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
FAR CIconMgr *iconMgr, uint8_t flags);
/**
* Configure application window events.
*
* @param obj An object reference that will be provided with the event
* to assist in handling the event. This may be NULL is not needed
* @param redrawEvent The event to send on window redraw events. This
* may be EVENT_SYSTEM_NOP to ignore all rdraw events.
* @param mouseEvent The event to send on mouse/touchscreen input
* events. This may be EVENT_SYSTEM_NOP to ignore all mouse/
* touchscreen input events.
* @param kbdEvent The event to send on keyboard input events. This
* may be EVENT_SYSTEM_NOP to ignore all keyboard input events.
* @return True is returned on success
*/
bool configureEvents(FAR void *obj, uint16_t redrawEvent,
uint16_t mouseEvent, uint16_t kbdEvent);
/**
* Synchronize the window with the NX server. This function will delay
* until the the NX server has caught up with all of the queued requests.

View file

@ -142,7 +142,9 @@ namespace Twm4Nx
FAR CTwm4Nx *m_twm4nx; /**< Cached instance of CTwm4Nx */
mqd_t m_eventq; /**< NxWidget event message queue */
FAR void *m_object; /**< Window object (context specific) */
bool m_isBackground; /**< True if this serves the background window */
uint16_t m_redrawEvent; /**< Redraw event ID */
uint16_t m_mouseEvent; /**< Mouse/touchscreen event ID */
uint16_t m_kbdEvent; /**< Keyboard event ID */
// Dragging
@ -192,14 +194,21 @@ namespace Twm4Nx
*
* @param twm4nx The Twm4Nx session instance.
* @param obj Contextual object (Usually 'this' of instantiator)
* @param isBackground True is this for the background window.
* @param redrawEvent The event to send on window redraw events. This
* may be EVENT_SYSTEM_NOP to ignore all rdraw events.
* @param mouseEvent The event to send on mouse/touchscreen input
* events. This may be EVENT_SYSTEM_NOP to ignore all mouse/
* touchscreen input events.
* @param kbdEvent The event to send on keyboard input events. This
* may be EVENT_SYSTEM_NOP to ignore all keyboard input events.
* @param style The default style that all widgets on this display
* should use. If this is not specified, the widget will use the
* values stored in the defaultCWidgetStyle object.
*/
CWindowEvent(FAR CTwm4Nx *twm4nx, FAR void *obj,
bool isBackground = false,
uint16_t redrawEvent, uint16_t mouseEvent,
uint16_t kbdEvent,
FAR const NXWidgets::CWidgetStyle *style =
(const NXWidgets::CWidgetStyle *)NULL);
@ -225,6 +234,32 @@ namespace Twm4Nx
m_dragHandler = dragHandler;
m_dragArg = arg;
}
/**
* Modify event handlers.
*
* One use for this is by the window drag logic to temporarily capture
* application mouse/touchscreen inputs to handle cases where the drag
* position enters the application window area.
*
* @param redrawEvent The event to send on window redraw events. This
* may be EVENT_SYSTEM_NOP to ignore all rdraw events.
* @param mouseEvent The event to send on mouse/touchscreen input
* events. This may be EVENT_SYSTEM_NOP to ignore all mouse/
* touchscreen input events.
* @param kbdEvent The event to send on keyboard input events. This
* may be EVENT_SYSTEM_NOP to ignore all keyboard input events.
*/
inline bool configureEvents(FAR void *obj, uint16_t redrawEvent,
uint16_t mouseEvent, uint16_t kbdEvent)
{
m_object = obj; // Event object reference
m_redrawEvent = redrawEvent; // Redraw event ID
m_mouseEvent = mouseEvent; // Mouse/touchscreen event ID
m_kbdEvent = kbdEvent; // Keyboard event ID
return true;
}
};
}

View file

@ -53,6 +53,7 @@
#include "graphics/twm4nx/cwindow.hxx"
#include "graphics/twm4nx/ctwm4nxevent.hxx"
#include "graphics/twm4nx/iapplication.hxx"
/////////////////////////////////////////////////////////////////////////////
// Implementation Classes
@ -81,6 +82,72 @@ namespace Twm4Nx
FAR CWindow *cwin; /**< Window object payload */
};
/**
* This class is a simple implement of the interface to the Main Menu that
* provides the Desktop Main Menu entry.
*/
class CDesktopItem : public IApplication
{
public:
/**
* Return the Main Menu item string. This overrides the method from
* IApplication
*
* @param name The name of the application.
*/
inline const NXWidgets::CNxString getName(void)
{
return NXWidgets::CNxString("Desktop");
}
/**
* There is no sub-menu for this Main Menu item. This overrides
* the method from IApplication.
*
* @return This implementation will always return a null value.
*/
inline FAR CMenus *getSubMenu(void)
{
return (FAR CMenus *)0;
}
/**
* There is no application start-up function. This function will not
* be called in this implementation
*/
inline void start(FAR CTwm4Nx *twm4nx)
{
}
/**
* There is no custom event handler. We use the common event handler.
*
* @return. null is always returned in this impementation.
*/
inline FAR CTwm4NxEvent *getEventHandler(void)
{
return (FAR CTwm4NxEvent *)0;
}
/**
* Return the Twm4Nx event that will be generated when the Main Menu
* item is selected.
*
* @return. This function always returns EVENT_WINDOW_DESKTOP.
*/
inline uint16_t getEvent(void)
{
return EVENT_WINDOW_DESKTOP;
}
};
/**
* The CWindowFactory class creates new window instances and manages some
* things that are common to all windows.
@ -90,9 +157,10 @@ namespace Twm4Nx
{
private:
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
struct nxgl_point_s m_winpos; /**< Position of next window created */
FAR struct SWindow *m_windowHead; /**< List of all windows on the display */
CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
struct nxgl_point_s m_winpos; /**< Position of next window created */
FAR struct SWindow *m_windowHead; /**< List of windows on the display */
CDesktopItem m_desktopItem; /**< For the "Desktop" Main Menu item */
/**
* Add a window container to the window list.
@ -120,6 +188,15 @@ namespace Twm4Nx
FAR struct SWindow *findWindow(FAR CWindow *cwin);
/**
* This is the function that responds to the EVENT_WINDOW_DESKTOP. It
* iconifies all windows so that the desktop is visible.
*
* @return True is returned if the operation was successful.
*/
bool showDesktop(void);
public:
/**
@ -136,9 +213,23 @@ namespace Twm4Nx
~CWindowFactory(void);
/**
* Add Icon Manager menu items to the Main menu. This is really part
* of the instance initialization, but cannot be executed until the
* Main Menu logic is ready.
*
* @return True on success
*/
bool addMenuItems(void);
/**
* Create a new window and add it to the window list.
*
* The window is initialized with all application events disabled.
* The CWindows::configureEvents() method may be called as a second
* initialization step in order to enable application events.
*
* @param name The window name
* @param sbitmap The Icon bitmap
* @param iconMgr Pointer to icon manager instance

View file

@ -110,9 +110,8 @@ namespace Twm4Nx
// Recipient == BACKGOUND
EVENT_BACKGROUND_XYINPUT = 0x1000, /**< Poll window for widget mouse/touch events */
EVENT_BACKGROUND_KBDINPUT = 0x1001, /**< Poll window for widget keyboard events */
EVENT_BACKGROUND_REDRAW = 0x1002, /**< Redraw the background */
EVENT_BACKGROUND_XYINPUT = 0x1000, /**< Poll for widget mouse/touch events */
EVENT_BACKGROUND_REDRAW = 0x1001, /**< Redraw the background */
// Recipient == ICONWIDGET
@ -122,16 +121,18 @@ namespace Twm4Nx
// Recipient == ICONMGR
EVENT_ICONMGR_DEICONIFY = 0x3000, /**< De-iconify or raise the Icon Manager */
EVENT_ICONMGR_XYINPUT = 0x3000, /**< Poll for widget mouse/touch events */
EVENT_ICONMGR_DEICONIFY = 0x3001, /**< De-iconify or raise the Icon Manager */
// Recipient == MENU
EVENT_MENU_IDENTIFY = 0x4000, /**< Describe the window */
EVENT_MENU_VERSION = 0x4001, /**< Show the Twm4Nx version */
EVENT_MENU_ICONIFY = 0x4002, /**< Tool bar minimize button pressed */
EVENT_MENU_DEICONIFY = 0x4003, /**< Window icon pressed */
EVENT_MENU_SUBMENU = 0x4004, /**< Sub-menu selected */
EVENT_MENU_FUNCTION = 0x4005, /**< Perform function on unknown menu */
EVENT_MENU_XYINPUT = 0x4000, /**< Poll for widget mouse/touch events */
EVENT_MENU_IDENTIFY = 0x4001, /**< Describe the window */
EVENT_MENU_VERSION = 0x4002, /**< Show the Twm4Nx version */
EVENT_MENU_ICONIFY = 0x4003, /**< Tool bar minimize button pressed */
EVENT_MENU_DEICONIFY = 0x4004, /**< Window icon pressed */
EVENT_MENU_SUBMENU = 0x4005, /**< Sub-menu selected */
EVENT_MENU_FUNCTION = 0x4006, /**< Perform function on unknown menu */
// Recipient == MAINMENU
@ -139,37 +140,38 @@ namespace Twm4Nx
// Recipient == WINDOW
EVENT_WINDOW_XYINPUT = 0x6000, /**< Poll window for widget mouse/touch events */
EVENT_WINDOW_KBDINPUT = 0x6001, /**< Poll window for widget keyboard events */
EVENT_WINDOW_FOCUS = 0x6002, /**< Enter modal state */
EVENT_WINDOW_UNFOCUS = 0x6003, /**< Exit modal state */
EVENT_WINDOW_RAISE = 0x6004, /**< Raise window to the top of the heirarchy */
EVENT_WINDOW_LOWER = 0x6005, /**< Lower window to the bottom of the heirarchy */
EVENT_WINDOW_DEICONIFY = 0x6006, /**< De-iconify and raise window */
EVENT_WINDOW_DRAG = 0x6007, /**< Drag window */
EVENT_WINDOW_DELETE = 0x6008, /**< Delete window */
EVENT_WINDOW_FOCUS = 0x6000, /**< Enter modal state */
EVENT_WINDOW_UNFOCUS = 0x6001, /**< Exit modal state */
EVENT_WINDOW_RAISE = 0x6002, /**< Raise window to the top of the heirarchy */
EVENT_WINDOW_LOWER = 0x6003, /**< Lower window to the bottom of the heirarchy */
EVENT_WINDOW_DEICONIFY = 0x6004, /**< De-iconify and raise window */
EVENT_WINDOW_DRAG = 0x6005, /**< Drag window */
EVENT_WINDOW_DELETE = 0x6006, /**< Delete window */
EVENT_WINDOW_DESKTOP = 0x6007, /**< Show the desktop */
// Recipient == TOOLBAR
EVENT_TOOLBAR_GRAB = 0x7000, /**< Click on title widget */
EVENT_TOOLBAR_UNGRAB = 0x7001, /**< Release click on title widget */
EVENT_TOOLBAR_MENU = 0x7002, /**< Toolbar menu button released */
EVENT_TOOLBAR_MINIMIZE = 0x7003, /**< Toolbar minimize button released */
EVENT_TOOLBAR_RESIZE = 0x7004, /**< Toolbar resize button released */
EVENT_TOOLBAR_TERMINATE = 0x7005, /**< Toolbar delete button released */
EVENT_TOOLBAR_XYINPUT = 0x7000, /**< Poll for widget mouse/touch events */
EVENT_TOOLBAR_GRAB = 0x7001, /**< Click on title widget */
EVENT_TOOLBAR_UNGRAB = 0x7002, /**< Release click on title widget */
EVENT_TOOLBAR_MENU = 0x7003, /**< Toolbar menu button released */
EVENT_TOOLBAR_MINIMIZE = 0x7004, /**< Toolbar minimize button released */
EVENT_TOOLBAR_RESIZE = 0x7005, /**< Toolbar resize button released */
EVENT_TOOLBAR_TERMINATE = 0x7006, /**< Toolbar delete button released */
// Recipient == BORDER
// Recipient == RESIZE
EVENT_RESIZE_START = 0x9000, /**< Start window resize */
EVENT_RESIZE_VERTZOOM = 0x9001, /**< Zoom vertically only */
EVENT_RESIZE_HORIZOOM = 0x9002, /**< Zoom horizontally only */
EVENT_RESIZE_FULLZOOM = 0x9003, /**< Zoom both vertically and horizontally */
EVENT_RESIZE_LEFTZOOM = 0x9004, /**< Zoom left only */
EVENT_RESIZE_RIGHTZOOM = 0x9005, /**< Zoom right only */
EVENT_RESIZE_TOPZOOM = 0x9006, /**< Zoom top only */
EVENT_RESIZE_BOTTOMZOOM = 0x9007, /**< Zoom bottom only */
EVENT_RESIZE_XYINPUT = 0x9000, /**< Poll for widget mouse/touch events */
EVENT_RESIZE_START = 0x9001, /**< Start window resize */
EVENT_RESIZE_VERTZOOM = 0x9002, /**< Zoom vertically only */
EVENT_RESIZE_HORIZOOM = 0x9003, /**< Zoom horizontally only */
EVENT_RESIZE_FULLZOOM = 0x9004, /**< Zoom both vertically and horizontally */
EVENT_RESIZE_LEFTZOOM = 0x9005, /**< Zoom left only */
EVENT_RESIZE_RIGHTZOOM = 0x9006, /**< Zoom right only */
EVENT_RESIZE_TOPZOOM = 0x9007, /**< Zoom top only */
EVENT_RESIZE_BOTTOMZOOM = 0x9008, /**< Zoom bottom only */
// Recipient == APP
// All application defined events must (1) use recepient == EVENT_RECIPIENT_APP,
@ -194,16 +196,17 @@ namespace Twm4Nx
/**
* This type represents a generic messages, particularly button press
* or released events.
* or release events.
*/
struct SEventMsg
{
uint16_t eventID; /**< Encoded event ID */
FAR void *obj; /**< Context specific reference */
struct nxgl_point_s pos; /**< X/Y position */
uint8_t context; /**< Button press context */
FAR CTwm4NxEvent *handler; /**< App event handler (APP recipient only) */
FAR void *obj; /**< Window object (CWindow or CIconWidget) */
};
/**
@ -213,32 +216,37 @@ namespace Twm4Nx
struct SRedrawEventMsg
{
uint16_t eventID; /**< Encoded event ID */
FAR void *obj; /**< Context specific reference */
struct nxgl_rect_s rect; /**< Region to be redrawn */
bool more; /**< True: More redraw requests will follow */
};
/**
* This message for is used with CWindowEVent mouse/keyboard input events
* This message form is used with CWindowEVent mouse/touchscreen
* input events
*/
struct SXyInputEventMsg
{
uint16_t eventID; /**< Encoded event ID */
FAR void *obj; /**< Context specific reference */
struct nxgl_point_s pos; /**< X/Y position */
uint8_t buttons; /**< Bit set of button presses */
FAR void *obj; /**< Context specific reference */
};
/**
* This is the alternative form of the message used by
* CWindowEvent for blocked and keyboard input messages
* This message form of the message used by CWindowEvent for blocked and
* keyboard input messages
*/
struct SNxEventMsg
{
uint16_t eventID; /**< Encoded event ID */
FAR CWindowEvent *instance; /**< X/Y position */
FAR void *obj; /**< Context specific reference */
FAR CWindowEvent *instance; /**< X/Y position */
};
}