Squashed commit of the following:

apps/graphics/twm4nx:  Remove Icon Windows; replace with IconWidgets that are draw on the background.
    apps/graphics/twm4nx:  Add CIconWidget event generation.
    apps/graphics/twm4nx:  Add event handling logic to CIconWidget.
This commit is contained in:
Gregory Nutt 2019-04-28 09:24:05 -06:00
parent 07b6eb555c
commit e742f97674
11 changed files with 642 additions and 822 deletions

View File

@ -55,8 +55,8 @@ STACKSIZE = $(CONFIG_TWM4NX_STACKSIZE)
ASRCS =
CSRCS =
CXXSRCS = cbackground.cxx cfonts.cxx cicon.cxx ciconmgr.cxx
CXXSRCS += ciconwidget.cxx ciconwin.cxx cinput.cxx cmenus.cxx
CXXSRCS += cresize.cxx cwindow.cxx cwindowevent.cxx cwindowfactory.cxx
CXXSRCS += ciconwidget.cxx cinput.cxx cmenus.cxx cresize.cxx
CXXSRCS += cwindow.cxx cwindowevent.cxx cwindowfactory.cxx
CXXSRCS += twm4nx_cursor.cxx
MAINSRC = ctwm4nx.cxx

View File

@ -179,7 +179,7 @@ void CIcon::place(FAR CWindow *cwin, FAR const struct nxgl_point_s *pos,
for (FAR struct SIconRegion *ir = m_regionHead; ir; ir = ir->flink)
{
struct nxgl_size_s iconWindowSize;
cwin->getIconWindowSize(&iconWindowSize);
cwin->getIconWidgetSize(iconWindowSize);
struct nxgl_size_s tmpsize;
tmpsize.w = roundUp(iconWindowSize.w, ir->step.x);
@ -225,7 +225,7 @@ void CIcon::place(FAR CWindow *cwin, FAR const struct nxgl_point_s *pos,
ie->cwin = cwin;
struct nxgl_size_s iconWindowSize;
cwin->getIconWindowSize(&iconWindowSize);
cwin->getIconWidgetSize(iconWindowSize);
final->x = ie->pos.x + (ie->size.w - iconWindowSize.w) / 2;
final->y = ie->pos.y + (ie->size.h - iconWindowSize.h) / 2;
@ -255,15 +255,8 @@ void CIcon::up(FAR CWindow *cwin)
if (cwin->hasIconMoved())
{
struct nxgl_size_s oldsize;
if (!cwin->getIconWindowSize(&oldsize))
{
return;
}
if (!cwin->getIconWindowPosition(&oldpos))
{
return;
}
cwin->getIconWidgetSize(oldsize);
cwin->getIconWidgetPosition(oldpos);
newpos.x = oldpos.x + ((int)oldsize.w) / 2;
newpos.y = oldpos.y + ((int)oldsize.h) / 2;
@ -293,7 +286,7 @@ void CIcon::up(FAR CWindow *cwin)
if (newpos.x != oldpos.x || newpos.y != oldpos.y)
{
(void)cwin->getIconWindowPosition(&newpos);
cwin->getIconWidgetPosition(newpos);
cwin->setIconMoved(false); // since we've restored it
}
}

View File

@ -41,18 +41,24 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <cstdint>
#include <cstdbool>
#include <cfcntl>
#include <cerrno>
#include <mqueue.h>
#include <nuttx/nx/nxglib.h>
#include "graphics/nxwidgets/cgraphicsport.hxx"
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
#include "graphics/nxwidgets/crlepalettebitmap.hxx"
#include "graphics/nxwidgets/ibitmap.hxx"
#include "graphics/twm4nx/twm4nx_config.hxx"
#include "graphics/twm4nx/ctwm4nx.hxx"
#include "graphics/twm4nx/cfonts.hxx"
#include "graphics/twm4nx/ciconwidget.hxx"
#include "graphics/twm4nx/twm4nx_widgetevents.hxx"
#include "graphics/twm4nx/twm4nx_cursor.hxx"
/////////////////////////////////////////////////////////////////////////////
// CIconWidget Definitions
@ -78,31 +84,59 @@ CIconWidget::CIconWidget(FAR CTwm4Nx *twm4nx,
FAR NXWidgets::CWidgetStyle *style)
: CNxWidget(widgetControl, x, y, 0, 0, WIDGET_BORDERLESS, style)
{
m_twm4nx = twm4nx;
m_widgetControl = widgetControl;
m_twm4nx = twm4nx; // Save the Twm4Nx session instance
m_widgetControl = widgetControl; // Save the widget control instance
m_eventq = (mqd_t)-1; // No widget message queue yet
// Configure the widget
m_flags.borderless = true;
m_flags.borderless = true; // The widget is borless (and transparent)
}
/**
* Destructor.
*/
CIconWidget::~CIconWidget(void)
{
// Close the NxWidget event message queue
if (m_eventq != (mqd_t)-1)
{
(void)mq_close(m_eventq);
m_eventq = (mqd_t)-1;
}
}
/**
* Perform widget initialization that could fail and so it not appropriate
* for the constructor
*
* @param cbitmp The bitmap image representing the icon
* @param ibitmap The bitmap image representing the icon
* @param title The icon title string
* @return True is returned if the widget is successfully initialized.
*/
bool CIconWidget::initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
FAR NXWidgets::CNxString &title)
bool CIconWidget::initialize(FAR NXWidgets::IBitmap *ibitmap,
FAR const NXWidgets::CNxString &title)
{
// Open a message queue to send fully digested NxWidget events.
FAR const char *mqname = m_twm4nx->getEventQueueName();
m_eventq = mq_open(mqname, O_WRONLY | O_NONBLOCK);
if (m_eventq == (mqd_t)-1)
{
gerr("ERROR: Failed open message queue '%s': %d\n",
mqname, errno);
return false;
}
// Get the size of the Icon bitmap
struct nxgl_size_s iconImageSize;
iconImageSize.w = cbitmap->getWidth();
iconImageSize.h = cbitmap->getHeight();
iconImageSize.w = ibitmap->getWidth();
iconImageSize.h = ibitmap->getHeight();
// Get the size of the Icon name
@ -140,7 +174,7 @@ bool CIconWidget::initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
FAR NXWidgets::CImage *image =
new NXWidgets::CImage(m_widgetControl, iconImagePos.x,
iconImagePos.y, iconImageSize.w, iconImageSize.h,
cbitmap, m_style);
ibitmap, m_style);
if (image == (FAR NXWidgets::CImage *)0)
{
gerr("ERROR: Failed to create image\n");
@ -208,6 +242,145 @@ void CIconWidget::getPreferredDimensions(NXWidgets::CRect &rect) const
rect.setHeight(widgetSize.h);
}
/**
* Handle ICONWIDGET events.
*
* @param eventmsg. The received NxWidget ICON event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWidget::event(FAR struct SEventMsg *eventmsg)
{
bool success = true;
switch (eventmsg->eventID)
{
case EVENT_ICONWIDGET_GRAB: /* Left click on icon. Start drag */
success = iconGrab(eventmsg);
break;
case EVENT_ICONWIDGET_DRAG: /* Mouse movement while clicked */
success = iconDrag(eventmsg);
break;
case EVENT_ICONWIDGET_UNGRAB: /* Left click release while dragging. */
success = iconUngrab(eventmsg);
break;
default:
success = false;
break;
}
return success;
}
/**
* After the widget has been grabbed, it may be dragged then dropped,
* or it may be simply "un-grabbed". Both cases are handled here.
*
* NOTE: Unlike the other event handlers, this does NOT override any
* virtual event handling methods. It just combines some common event-
* handling logic.
*
* @param e The event data.
*/
void CIconWidget::handleUngrabEvent(const NXWidgets::CWidgetEventArgs &e)
{
// Exit the dragging state
m_drag = false;
// Generate the un-grab event
struct SEventMsg msg;
msg.eventID = EVENT_ICONWIDGET_UNGRAB;
msg.pos.x = e.getX();
msg.pos.y = e.getY();
msg.delta.x = 0;
msg.delta.y = 0;
msg.context = EVENT_CONTEXT_ICON;
msg.handler = (FAR CTwm4NxEvent *)0;
msg.obj = (FAR void *)this;
// NOTE that we cannot block because we are on the same thread
// as the message reader. If the event queue becomes full then
// we have no other option but to lose events.
//
// I suppose we could recurse and call Twm4Nx::dispatchEvent at
// the risk of runaway stack usage.
int ret = mq_send(m_eventq, (FAR const char *)&msg,
sizeof(struct SEventMsg), 100);
if (ret < 0)
{
gerr("ERROR: mq_send failed: %d\n", ret);
}
}
/**
* Override the mouse button drag event.
*
* @param e The event data.
*/
void CIconWidget::handleDragEvent(const NXWidgets::CWidgetEventArgs &e)
{
// We don't care which widget is being dragged, only that we are in the
// dragging state.
if (m_drag)
{
// Generate the event
struct SEventMsg msg;
msg.eventID = EVENT_ICONWIDGET_DRAG;
msg.pos.x = e.getX();
msg.pos.y = e.getY();
msg.delta.x = e.getVX();
msg.delta.y = e.getVY();
msg.context = EVENT_CONTEXT_ICON;
msg.handler = (FAR CTwm4NxEvent *)0;
msg.obj = (FAR void *)this;
// NOTE that we cannot block because we are on the same thread
// as the message reader. If the event queue becomes full then
// we have no other option but to lose events.
//
// I suppose we could recurse and call Twm4Nx::dispatchEvent at
// the risk of runaway stack usage.
int ret = mq_send(m_eventq, (FAR const char *)&msg,
sizeof(struct SEventMsg), 100);
if (ret < 0)
{
gerr("ERROR: mq_send failed: %d\n", ret);
}
}
}
/**
* Override a drop event, triggered when the widget has been dragged-
* and-dropped.
*
* @param e The event data.
*/
void CIconWidget::handleDropEvent(const NXWidgets::CWidgetEventArgs &e)
{
// When the Drop Event is received, both isClicked and isBeingDragged()
// will return false. No checks are performed.
if (m_drag)
{
// Yes.. handle the drop event
handleUngrabEvent(e);
}
}
/**
* Handle a mouse click event.
*
@ -216,29 +389,58 @@ void CIconWidget::getPreferredDimensions(NXWidgets::CRect &rect) const
void CIconWidget::handleClickEvent(const NXWidgets::CWidgetEventArgs &e)
{
m_widgetEventHandlers->raiseClickEvent(e.getX(), e.getY());
// We don't care which component of the icon widget was clicked only that
// we are not currently being dragged
if (!m_drag)
{
// Generate the event
struct SEventMsg msg;
msg.eventID = EVENT_ICONWIDGET_GRAB;
msg.pos.x = e.getX();
msg.pos.y = e.getY();
msg.delta.x = 0;
msg.delta.y = 0;
msg.context = EVENT_CONTEXT_ICON;
msg.handler = (FAR CTwm4NxEvent *)0;
msg.obj = (FAR void *)this;
// NOTE that we cannot block because we are on the same thread
// as the message reader. If the event queue becomes full then
// we have no other option but to lose events.
//
// I suppose we could recurse and call Twm4Nx::dispatchEvent at
// the risk of runaway stack usage.
int ret = mq_send(m_eventq, (FAR const char *)&msg,
sizeof(struct SEventMsg), 100);
if (ret < 0)
{
gerr("ERROR: mq_send failed: %d\n", ret);
}
}
}
/**
* Handle a mouse double-click event.
* Override the virtual CWidgetEventHandler::handleReleaseEvent. This
* event will fire when the widget is released. isClicked() will
* return false for the widget.
*
* @param e The event data.
*/
void CIconWidget::handleDoubleClickEvent(const NXWidgets::CWidgetEventArgs &e)
{
m_widgetEventHandlers->raiseDoubleClickEvent(e.getX(), e.getY());
}
/**
* Handle a mouse button release event that occurred within the bounds of
* the source widget.
* @param e The event data.
*/
void CIconWidget::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
{
m_widgetEventHandlers->raiseReleaseEvent(e.getX(), e.getY());
// Handle the case where a release event was received, but the
// window was not dragged.
if (m_drag)
{
// Handle the non-drag drop event
handleUngrabEvent(e);
}
}
/**
@ -250,17 +452,130 @@ void CIconWidget::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
void CIconWidget::handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e)
{
// Child raised a release outside event, but we need to raise a different
// event if the release occurred within the bounds of this parent widget
// Handle the case where a release event was received, but the
// window was not dragged.
if (checkCollision(e.getX(), e.getY()))
if (m_drag)
{
m_widgetEventHandlers->raiseReleaseEvent(e.getX(), e.getY());
// Handle the non-drag drop event
handleUngrabEvent(e);
}
else
}
/**
* Handle the EVENT_ICONWIDGET_GRAB event. That corresponds to a left
* mouse click on the icon widtet
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWidget::iconGrab(FAR struct SEventMsg *eventmsg)
{
// Indicate that dragging has started.
m_drag = false;
// Get the icon position.
struct nxgl_point_s widgetPos;
getPos(widgetPos);
// Determine the relative position of the icon and the mouse
m_dragOffset.x = widgetPos.x - eventmsg->pos.x;
m_dragOffset.y = widgetPos.y - eventmsg->pos.y;
// Select the grab cursor image
m_twm4nx->setCursorImage(&CONFIG_TWM4NX_GBCURSOR_IMAGE);
// Remember the grab cursor size
m_dragCSize.w = CONFIG_TWM4NX_GBCURSOR_IMAGE.size.w;
m_dragCSize.h = CONFIG_TWM4NX_GBCURSOR_IMAGE.size.h;
return true;
}
/**
* Handle the EVENT_ICONWIDGET_DRAG event. That corresponds to a mouse
* movement when the icon is in a grabbed state.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWidget::iconDrag(FAR struct SEventMsg *eventmsg)
{
if (m_drag)
{
m_widgetEventHandlers->raiseReleaseOutsideEvent(e.getX(), e.getY());
// Calculate the new icon position
struct nxgl_point_s newpos;
newpos.x = eventmsg->pos.x + m_dragOffset.x;
newpos.y = eventmsg->pos.y + m_dragOffset.y;
// Keep the icon on the display (at least enough of it so that we
// can still grab it)
struct nxgl_size_s displaySize;
m_twm4nx->getDisplaySize(&displaySize);
if (newpos.x < 0)
{
newpos.x = 0;
}
else if (newpos.x + m_dragCSize.w > displaySize.w)
{
newpos.x = displaySize.w - m_dragCSize.w;
}
if (newpos.y < 0)
{
newpos.y = 0;
}
else if (newpos.y + m_dragCSize.h > displaySize.h)
{
newpos.y = displaySize.h - m_dragCSize.h;
}
// Set the new window position
return moveTo(newpos.x, newpos.y);
}
return false;
}
/**
* Handle the EVENT_ICONWIDGET_UNGRAB event. The corresponds to a mouse
* left button release while in the grabbed state.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWidget::iconUngrab(FAR struct SEventMsg *eventmsg)
{
// One last position update
if (!iconDrag(eventmsg))
{
return false;
}
// Indicate no longer dragging
m_drag = false;
// Restore the normal cursor image
m_twm4nx->setCursorImage(&CONFIG_TWM4NX_CURSOR_IMAGE);
return false;
}
/**

View File

@ -1,386 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// apps/graphics/twm4nx/src/ciconwin.cxx
// Icon Windows
//
// Copyright (C) 2019 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Largely an original work but derives from TWM 1.0.10 in many ways:
//
// Copyright 1989,1998 The Open Group
//
// Please refer to apps/twm4nx/COPYING for detailed copyright information.
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include "graphics/nxwidgets/cnxwindow.hxx"
#include "graphics/nxwidgets/crlepalettebitmap.hxx"
#include "graphics/twm4nx/twm4nx_config.hxx"
#include "graphics/twm4nx/ctwm4nx.hxx"
#include "graphics/twm4nx/cfonts.hxx"
#include "graphics/twm4nx/cmenus.hxx"
#include "graphics/twm4nx/cwindow.hxx"
#include "graphics/twm4nx/cwindowevent.hxx"
#include "graphics/twm4nx/cicon.hxx"
#include "graphics/twm4nx/ciconwin.hxx"
#include "graphics/twm4nx/ctwm4nxevent.hxx"
#include "graphics/twm4nx/twm4nx_widgetevents.hxx"
#include "graphics/twm4nx/twm4nx_cursor.hxx"
/////////////////////////////////////////////////////////////////////////////
// CTwm4Nx Implementation
/////////////////////////////////////////////////////////////////////////////
using namespace Twm4Nx;
/**
* CIconWin Constructor
*/
CIconWin::CIconWin(CTwm4Nx *twm4nx)
{
m_twm4nx = twm4nx; // Cached the Twm4Nx session
m_nxwin = (FAR NXWidgets::CNxWindow *)0; // The cursor "raw" window
// Dragging
m_drag = false; // No drag in progress
m_dragOffset.x = 0; // Offset from mouse to window origin
m_dragOffset.y = 0;
m_dragCSize.w = 0; // The grab cursor size
m_dragCSize.h = 0;
}
/**
* CIconWin Destructor
*/
CIconWin::~CIconWin(void)
{
cleanup();
}
/**
* Create the icon window
*
* @param parent The parent window
* @param sbitmap The Icon image
* @param pos The default position
*/
bool CIconWin::initialize(FAR CWindow *parent,
FAR const NXWidgets::SRlePaletteBitmap *sbitmap,
FAR const struct nxgl_point_s *pos)
{
struct nxgl_point_s final;
// Get the size of the Icon Image
struct nxgl_size_s iconImageSize;
iconImageSize.h = sbitmap->height;
iconImageSize.w = sbitmap->height;
// Get the size of the Icon name
FAR CFonts *fonts = m_twm4nx->getFonts();
FAR NXWidgets::CNxFont *iconFont = fonts->getIconFont();
FAR const char *iconName = parent->getWindowName();
struct nxgl_size_s iconWindowSize;
iconWindowSize.w = iconFont->getStringWidth(iconName);
iconWindowSize.w += 6;
// Handle the case where the name string is wider than the icon
struct nxgl_point_s iconWindowPos;
if (iconWindowSize.w < iconImageSize.w)
{
// Center
iconWindowPos.x = (iconImageSize.w - iconWindowSize.w) / 2;
iconWindowPos.x += 3;
iconWindowSize.w = iconImageSize.w;
}
else
{
iconWindowPos.x = 3;
}
iconWindowPos.y = iconImageSize.h + iconFont->getHeight();
iconWindowSize.h = iconImageSize.h + iconFont->getHeight() + 4;
// Create the icon window
// 1. Get the server instance. m_twm4nx inherits from NXWidgets::CNXServer
// so we all ready have the server instance.
// 2. Create the style, using the selected colors (REVISIT)
// 3. Create a Widget control instance for the window using the default
// style for now. CWindowEvent derives from CWidgetControl.
FAR CWindowEvent *control = new CWindowEvent(m_twm4nx);
// 4. Create the icon window
m_nxwin = m_twm4nx->createRawWindow(control);
if (m_nxwin == (FAR NXWidgets::CNxWindow *)0)
{
delete control;
return false;
}
// 5. Open and initialize the icon window
bool success = m_nxwin->open();
if (!success)
{
delete m_nxwin;
m_nxwin = (FAR NXWidgets::CNxWindow *)0;
return false;
}
// 6. Set the initial window size
if (!m_nxwin->setSize(&iconWindowSize))
{
delete m_nxwin;
m_nxwin = (FAR NXWidgets::CNxWindow *)0;
return false;
}
// 7. Set the initial window position
if (!m_nxwin->setPosition(&iconWindowPos))
{
delete m_nxwin;
m_nxwin = (FAR NXWidgets::CNxWindow *)0;
return false;
}
// We need to figure out where to put the icon window now, because getting
// here means that we am going to make the icon visible.
FAR CIcon *cicon = m_twm4nx->getIcon();
cicon->place(parent, pos, &final);
struct nxgl_size_s displaySize;
m_twm4nx->getDisplaySize(&displaySize);
if (final.x > displaySize.w)
{
final.x = displaySize.w - iconWindowSize.w;
}
if (final.y > displaySize.h)
{
final.y = displaySize.h - iconImageSize.h - iconFont->getHeight() - 4;
}
(void)m_nxwin->setPosition(&final);
return true;
}
/**
* Handle ICON events.
*
* @param eventmsg. The received NxWidget ICON event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWin::event(FAR struct SEventMsg *eventmsg)
{
bool success = true;
switch (eventmsg->eventID)
{
case EVENT_ICONWIN_GRAB: /* Left click on icon. Start drag */
success = iconGrab(eventmsg);
break;
case EVENT_ICONWIN_DRAG: /* Mouse movement while clicked */
success = iconDrag(eventmsg);
break;
case EVENT_ICONWIN_UNGRAB: /* Left click release while dragging. */
success = iconUngrab(eventmsg);
break;
default:
success = false;
break;
}
return success;
}
/**
* Handle the ICON_GRAB event. That corresponds to a left
* mouse click on the icon
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWin::iconGrab(FAR struct SEventMsg *eventmsg)
{
// Promote the icon to a modal window
m_nxwin->modal(true);
// Indicate that dragging has started.
m_drag = false;
// Get the icon position.
struct nxgl_point_s framePos;
m_nxwin->getPosition(&framePos);
// Determine the relative position of the icon and the mouse
m_dragOffset.x = framePos.x - eventmsg->pos.x;
m_dragOffset.y = framePos.y - eventmsg->pos.y;
// Select the grab cursor image
m_twm4nx->setCursorImage(&CONFIG_TWM4NX_GBCURSOR_IMAGE);
// Remember the grab cursor size
m_dragCSize.w = CONFIG_TWM4NX_GBCURSOR_IMAGE.size.w;
m_dragCSize.h = CONFIG_TWM4NX_GBCURSOR_IMAGE.size.h;
return true;
}
/**
* Handle the ICON_DRAG event. That corresponds to a mouse
* movement when the icon is in a grabbed state.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWin::iconDrag(FAR struct SEventMsg *eventmsg)
{
if (m_drag)
{
// Calculate the new icon position
struct nxgl_point_s newpos;
newpos.x = eventmsg->pos.x + m_dragOffset.x;
newpos.y = eventmsg->pos.y + m_dragOffset.y;
// Keep the icon on the display (at least enough of it so that we
// can still grab it)
struct nxgl_size_s displaySize;
m_twm4nx->getDisplaySize(&displaySize);
if (newpos.x < 0)
{
newpos.x = 0;
}
else if (newpos.x + m_dragCSize.w > displaySize.w)
{
newpos.x = displaySize.w - m_dragCSize.w;
}
if (newpos.y < 0)
{
newpos.y = 0;
}
else if (newpos.y + m_dragCSize.h > displaySize.h)
{
newpos.y = displaySize.h - m_dragCSize.h;
}
// Set the new window position
return m_nxwin->setPosition(&newpos);
}
return false;
}
/**
* Handle the ICON_UNGRAB event. The corresponds to a mouse
* left button release while in the grabbed
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool CIconWin::iconUngrab(FAR struct SEventMsg *eventmsg)
{
// One last position update
if (!iconDrag(eventmsg))
{
return false;
}
// Indicate no longer dragging
m_drag = false;
// No long modal
m_nxwin->modal(false);
// Restore the normal cursor image
m_twm4nx->setCursorImage(&CONFIG_TWM4NX_CURSOR_IMAGE);
return false;
}
/**
* Cleanup on failure or as part of the destructor
*/
void CIconWin::cleanup(void)
{
// Close windows
if (m_nxwin != (FAR NXWidgets::CNxWindow *)0)
{
delete m_nxwin;
m_nxwin = (FAR NXWidgets::CNxWindow *)0;
}
}

View File

@ -73,7 +73,7 @@
#include "graphics/twm4nx/cwindowevent.hxx"
#include "graphics/twm4nx/cinput.hxx"
#include "graphics/twm4nx/cicon.hxx"
#include "graphics/twm4nx/ciconwin.hxx"
#include "graphics/twm4nx/ciconwidget.hxx"
#include "graphics/twm4nx/ciconmgr.hxx"
#include "graphics/twm4nx/cmenus.hxx"
#include "graphics/twm4nx/cresize.hxx"
@ -417,27 +417,27 @@ bool CTwm4Nx::dispatchEvent(FAR struct SEventMsg *eventmsg)
bool ret = false;
switch (recipient)
{
case EVENT_RECIPIENT_MSG: // NX message event
case EVENT_RECIPIENT_MSG: // NX message event
ret = CWindowEvent::event(eventmsg);
break;
case EVENT_RECIPIENT_SYSTEM: // Twm4Nx system event
case EVENT_RECIPIENT_SYSTEM: // Twm4Nx system event
ret = systemEvent(eventmsg);
break;
case EVENT_RECIPIENT_ICONWIN: // Icon window event
case EVENT_RECIPIENT_ICONWIDGET: // Icon widget event
{
FAR CIconWin *iconWin = (FAR CIconWin *)eventmsg->obj;
DEBUGASSERT(iconWin != (FAR CIconWin *)0);
ret = iconWin->event(eventmsg);
FAR CIconWidget *iconWidget = (FAR CIconWidget *)eventmsg->obj;
DEBUGASSERT(iconWidget != (FAR CIconWidget *)0);
ret = iconWidget->event(eventmsg);
}
break;
case EVENT_RECIPIENT_ICONMGR: // Icon Manager event
case EVENT_RECIPIENT_ICONMGR: // Icon Manager event
ret = m_iconmgr->event(eventmsg);
break;
case EVENT_RECIPIENT_MENU: // Menu related event
case EVENT_RECIPIENT_MENU: // Menu related event
{
FAR CMenus *menus = (FAR CMenus *)eventmsg->obj;
DEBUGASSERT(menus != (FAR CMenus *)0);
@ -445,17 +445,17 @@ bool CTwm4Nx::dispatchEvent(FAR struct SEventMsg *eventmsg)
}
break;
case EVENT_RECIPIENT_WINDOW: // Window related event
case EVENT_RECIPIENT_TOOLBAR: // Toolbar related event
case EVENT_RECIPIENT_BORDER: // Window border related event
case EVENT_RECIPIENT_WINDOW: // Window related event
case EVENT_RECIPIENT_TOOLBAR: // Toolbar related event
case EVENT_RECIPIENT_BORDER: // Window border related event
ret = m_factory->event(eventmsg);
break;
case EVENT_RECIPIENT_RESIZE: // Wind0w resize event
case EVENT_RECIPIENT_RESIZE: // Wind0w resize event
ret = m_resize->event(eventmsg);
break;
case EVENT_RECIPIENT_APP: // Application menu event
case EVENT_RECIPIENT_APP: // Application menu event
{
// Application events are unique in that they do not have any
// fixed, a priori endpoint. Rather, the endpoint must be
@ -466,7 +466,7 @@ bool CTwm4Nx::dispatchEvent(FAR struct SEventMsg *eventmsg)
}
break;
case EVENT_RECIPIENT_MASK: // Used to isolate recipient
case EVENT_RECIPIENT_MASK: // Used to isolate recipient
default:
break;
}

View File

@ -71,7 +71,8 @@
#include "graphics/twm4nx/ctwm4nx.hxx"
#include "graphics/twm4nx/cfonts.hxx"
#include "graphics/twm4nx/cresize.hxx"
#include "graphics/twm4nx/ciconwin.hxx"
#include "graphics/twm4nx/cbackground.hxx"
#include "graphics/twm4nx/ciconwidget.hxx"
#include "graphics/twm4nx/ciconmgr.hxx"
#include "graphics/twm4nx/cwindowevent.hxx"
#include "graphics/twm4nx/cwindow.hxx"
@ -150,7 +151,8 @@ CWindow::CWindow(CTwm4Nx *twm4nx)
// Icons/Icon Manager
m_iconWin = (FAR CIconWin *)0;
m_iconBitMap = (FAR NXWidgets::CRlePaletteBitmap *)0;
m_iconWidget = (FAR CIconWidget *)0;
m_iconMgr = (FAR CIconMgr *)0;
m_isIconMgr = false;
m_iconOn = false;
@ -299,19 +301,35 @@ bool CWindow::initialize(FAR const char *name,
}
}
// Create and initialize the icon window
// Create the icon image instance
m_iconWin = new CIconWin(m_twm4nx);
if (m_iconWin == (FAR CIconWin *)0)
m_iconBitMap = new NXWidgets::CRlePaletteBitmap(sbitmap);
if (m_iconBitMap == (NXWidgets::CRlePaletteBitmap *)0)
{
gerr("ERROR: Failed to create the icon Window\n");
gerr("ERROR: Failed to create icon image\n");
cleanup();
return false;
}
if (!m_iconWin->initialize(this, sbitmap, pos))
// Get the widget control instance from the background. This is needed
// to force the icon widgets to be draw on the background
FAR CBackground *background = m_twm4nx->getBackground();
FAR NXWidgets::CWidgetControl *control = background->getWidgetControl();
// Create and initialize the icon widget
m_iconWidget = new CIconWidget(m_twm4nx, control, pos->x, pos->y);
if (m_iconWidget == (FAR CIconWidget *)0)
{
gerr("ERROR: Failed to initialize the icon Window\n");
gerr("ERROR: Failed to create the icon widget\n");
cleanup();
return false;
}
if (!m_iconWidget->initialize(m_iconBitMap, m_name))
{
gerr("ERROR: Failed to initialize the icon widget\n");
cleanup();
return false;
}
@ -461,7 +479,6 @@ void CWindow::iconify(void)
m_iconified = true;
m_nxWin->lower();
m_iconWin->raise();
m_iconOn = true;
m_nxWin->synchronize();
}
@ -476,7 +493,6 @@ void CWindow::deIconify(void)
// Raise the main window and lower the icon window
m_iconified = false;
m_iconWin->lower();
m_nxWin->raise();
m_iconOn = false;
m_nxWin->synchronize();
@ -1112,12 +1128,12 @@ void CWindow::handleDropEvent(const NXWidgets::CWidgetEventArgs &e)
}
/**
* Handle a key press event.
* Handle a mouse click event.
*
* @param e The event data.
*/
void CWindow::handleKeyPressEvent(const NXWidgets::CWidgetEventArgs &e)
void CWindow::handleClickEvent(const NXWidgets::CWidgetEventArgs &e)
{
// We are interested only the the press event on the title box and
// only if we are not already dragging the window
@ -1162,14 +1178,14 @@ void CWindow::handleKeyPressEvent(const NXWidgets::CWidgetEventArgs &e)
void CWindow::handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e)
{
// Handle the case where a click event was received, but the
// Handle the case where a release event was received, but the
// window was not dragged.
if (m_drag && !m_tbTitle->isClicked())
{
// A click with no drag should raise the window.
m_iconWin->raise();
m_nxWin->raise();
// Handle the non-drag drop event
@ -1383,7 +1399,7 @@ void CWindow::cleanup(void)
m_tbTitle = (FAR NXWidgets::CLabel *)0;
}
// Close windows
// Delete the window
if (m_nxWin != (FAR NXWidgets::CNxTkWindow *)0)
{
@ -1391,10 +1407,18 @@ void CWindow::cleanup(void)
m_nxWin = (FAR NXWidgets::CNxTkWindow *)0;
}
if (m_iconWin != (FAR CIconWin *)0)
// Delete the Icon
if (m_iconWidget != (FAR CIconWidget *)0)
{
delete m_iconWin;
m_iconWin = (FAR CIconWin *)0;
delete m_iconWidget;
m_iconWidget = (FAR CIconWidget *)0;
}
if (m_iconBitMap != (FAR NXWidgets::CRlePaletteBitmap *)0)
{
delete m_iconBitMap;
m_iconBitMap = (FAR NXWidgets::CRlePaletteBitmap *)0;
}
// Free memory

View File

@ -45,6 +45,7 @@
#include <cstdint>
#include <cstdbool>
#include <mqueue.h>
#include <debug.h>
#include <nuttx/nx/nxglib.h>
@ -61,6 +62,7 @@
namespace NXWidgets
{
class IBitmap; // Forward reference
class CNxWidget; // Forward reference
class CWidgetStyle; // Forward reference
class CWidgetControl; // Forward reference
@ -85,109 +87,182 @@ namespace Twm4Nx
{
protected:
FAR CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
mqd_t m_eventq; /**< NxWidget event message queue */
FAR NXWidgets::CWidgetControl *m_widgetControl; /**< The controlling widget */
FAR NXWidgets::CWidgetStyle *m_style; /**< Widget style */
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
* @param port The NXWidgets::CGraphicsPort to draw to.
* @see redraw()
*/
// Dragging
virtual void drawContents(NXWidgets::CGraphicsPort* port);
struct nxgl_point_s m_dragPos; /**< Last mouse position */
struct nxgl_point_s m_dragOffset; /**< Offset from mouse to window origin */
struct nxgl_size_s m_dragCSize; /**< The grab cursor size */
bool m_drag; /**< Drag in-progress */
/**
* Copy constructor is protected to prevent usage.
*/
/**
* After the widget has been grabbed, it may be dragged then dropped,
* or it may be simply "un-grabbed". Both cases are handled here.
*
* NOTE: Unlike the other event handlers, this does NOT override any
* virtual event handling methods. It just combines some common event-
* handling logic.
*
* @param e The event data.
*/
inline CIconWidget(const CIconWidget &radioButtonGroup) :
CNxWidget(radioButtonGroup) { }
void handleUngrabEvent(const NXWidgets::CWidgetEventArgs &e);
public:
/**
* Override the mouse button drag event.
*
* @param e The event data.
*/
/**
* Constructor. Note that the group determines its width and height
* from the position and dimensions of its children.
*
* @param twm4nx The Twm4Nx session object
* @param widgetControl The controlling widget for the display.
* @param x The x coordinate of the group.
* @param y The y coordinate of the group.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
void handleDragEvent(const NXWidgets::CWidgetEventArgs &e);
CIconWidget(FAR CTwm4Nx *twm4nx,
FAR NXWidgets::CWidgetControl *widgetControl,
nxgl_coord_t x, nxgl_coord_t y,
FAR NXWidgets::CWidgetStyle *style =
(FAR NXWidgets::CWidgetStyle *)0);
/**
* Override a drop event, triggered when the widget has been dragged-
* and-dropped.
*
* @param e The event data.
*/
/**
* Destructor.
*/
void handleDropEvent(const NXWidgets::CWidgetEventArgs &e);
~CIconWidget(void)
{
}
/**
* Handle a mouse click event.
*
* @param e The event data.
*/
/**
* Perform widget initialization that could fail and so it not appropriate
* for the constructor
*
* @param cbitmp The bitmap image representing the icon
* @param title The icon title string
* @return True is returned if the widget is successfully initialized.
*/
void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
bool initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
FAR NXWidgets::CNxString &title);
/**
* Override the virtual CWidgetEventHandler::handleReleaseEvent. This
* event will fire when the widget is released. isClicked() will
* return false for the widget.
*
* @param e The event data.
*/
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent. Value is based on the length of the largest string
* in the set of options.
*
* @param rect Reference to a rect to populate with data.
*/
void handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e);
virtual void getPreferredDimensions(NXWidgets::CRect &rect) const;
/**
* Handle a mouse button release event that occurred outside the bounds of
* the source widget.
*
* @param e The event data.
*/
/**
* Handle a mouse click event.
*
* @param e The event data.
*/
void handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e);
virtual void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Handle the EVENT_ICONWIDGET_GRAB event. That corresponds to a left
* mouse click on the icon widget.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
/**
* Handle a mouse double-click event.
*
* @param e The event data.
*/
bool iconGrab(FAR struct SEventMsg *eventmsg);
virtual void handleDoubleClickEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Handle the EVENT_ICONWIDGET_DRAG event. That corresponds to a mouse
* movement when the icon is in a grabbed state.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
/**
* Handle a mouse button release event that occurred within the bounds of
* the source widget.
* @param e The event data.
*/
bool iconDrag(FAR struct SEventMsg *eventmsg);
virtual void handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Handle the EVENT_ICONWIDGET_UNGRAB event. The corresponds to a mouse
* left button release while in the grabbed state
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
/**
* Handle a mouse button release event that occurred outside the bounds of
* the source widget.
*
* @param e The event data.
*/
bool iconUngrab(FAR struct SEventMsg *eventmsg);
virtual void handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Draw the area of this widget that falls within the clipping region.
* Called by the redraw() function to draw all visible regions.
* @param port The NXWidgets::CGraphicsPort to draw to.
* @see redraw()
*/
void drawContents(NXWidgets::CGraphicsPort* port);
/**
* Copy constructor is protected to prevent usage.
*/
inline CIconWidget(const CIconWidget &radioButtonGroup) :
CNxWidget(radioButtonGroup) { }
public:
/**
* Constructor. Note that the group determines its width and height
* from the position and dimensions of its children.
*
* @param twm4nx The Twm4Nx session object
* @param widgetControl The controlling widget for the display.
* @param x The x coordinate of the group.
* @param y The y coordinate of the group.
* @param style The style that the button should use. If this is not
* specified, the button will use the global default widget
* style.
*/
CIconWidget(FAR CTwm4Nx *twm4nx,
FAR NXWidgets::CWidgetControl *widgetControl,
nxgl_coord_t x, nxgl_coord_t y,
FAR NXWidgets::CWidgetStyle *style =
(FAR NXWidgets::CWidgetStyle *)0);
/**
* Destructor.
*/
~CIconWidget(void);
/**
* Perform widget initialization that could fail and so it not appropriate
* for the constructor
*
* @param ibitmap The bitmap image representing the icon
* @param title The icon title string
* @return True is returned if the widget is successfully initialized.
*/
bool initialize(FAR NXWidgets::IBitmap *ibitmap,
FAR const NXWidgets::CNxString &title);
/**
* Insert the dimensions that this widget wants to have into the rect
* passed in as a parameter. All coordinates are relative to the
* widget's parent. Value is based on the length of the largest string
* in the set of options.
*
* @param rect Reference to a rect to populate with data.
*/
void getPreferredDimensions(NXWidgets::CRect &rect) const;
/**
* Handle ICON WIDGET events.
*
* @param eventmsg. The received NxWidget ICON event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool event(FAR struct SEventMsg *eventmsg);
};
}

View File

@ -1,216 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// apps/graphics/twm4nx/include/ciconwin.hxx
// Icon Windows
//
// Copyright (C) 2019 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org>
//
// Largely an original work but derives from TWM 1.0.10 in many ways:
//
// Copyright 1989,1998 The Open Group
//
// Please refer to apps/twm4nx/COPYING for detailed copyright information.
//
// 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_CICONWIN_HXX
#define __APPS_INCLUDE_GRAPHICS_TWM4NX_CICONWIN_HXX
/////////////////////////////////////////////////////////////////////////////
// Included Files
/////////////////////////////////////////////////////////////////////////////
#include <nuttx/config.h>
#include "graphics/nxwidgets/cnxwindow.hxx"
#include "graphics/twm4nx/ctwm4nxevent.hxx"
/////////////////////////////////////////////////////////////////////////////
// Implementation Classes
/////////////////////////////////////////////////////////////////////////////
namespace NXWidgets
{
struct SRlePaletteBitmap; // Forward reference
}
namespace Twm4Nx
{
class CTwm4Nx; // Forward reference
class CWindow; // Forward reference
/**
* The CIconWin represents on icon window
*/
class CIconWin : public CTwm4NxEvent
{
private:
FAR CTwm4Nx *m_twm4nx; /**< The Twm4Nx session */
FAR NXWidgets::CNxWindow *m_nxwin; /**< The cursor "raw" window */
// Dragging
struct nxgl_point_s m_dragPos; /**< Last mouse position */
struct nxgl_point_s m_dragOffset; /**< Offset from mouse to window origin */
struct nxgl_size_s m_dragCSize; /**< The grab cursor size */
bool m_drag; /**< Drag in-progress */
/**
* Handle the ICON_GRAB event. That corresponds to a left
* mouse click on the icon
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool iconGrab(FAR struct SEventMsg *eventmsg);
/**
* Handle the ICON_DRAG event. That corresponds to a mouse
* movement when the icon is in a grabbed state.
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool iconDrag(FAR struct SEventMsg *eventmsg);
/**
* Handle the ICON_UNGRAB event. The corresponds to a mouse
* left button release while in the grabbed
*
* @param eventmsg. The received NxWidget event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool iconUngrab(FAR struct SEventMsg *eventmsg);
/**
* Cleanup on failure or as part of the destructor
*/
void cleanup(void);
public:
/**
* CIconWin Constructor
*/
CIconWin(CTwm4Nx *twm4nx);
/**
* CIconWin Destructor
*/
~CIconWin(void);
/**
* Initialize the icon window
*
* @param parent The parent window
* @param sbitmap The Icon bitmap image
* @param pos The default position
*/
bool initialize(FAR CWindow *parent,
FAR const struct NXWidgets::SRlePaletteBitmap *sbitmap,
FAR const struct nxgl_point_s *pos);
/**
* Get the size of the icon window on the background
*
* @param size The location to return the size of the icon window
*/
inline bool getSize(FAR struct nxgl_size_s *size)
{
return m_nxwin->getSize(size);
}
/**
* Get the icon window position on the background
*
* @param size The location to return the position of the icon window
*/
inline bool getPosition(FAR struct nxgl_point_s *pos)
{
return m_nxwin->getPosition(pos);
}
/**
* Set the icon window position on the background
*
* @param size The new position of the icon window
*/
inline bool setPosition(FAR const struct nxgl_point_s *pos)
{
return m_nxwin->setPosition(pos);
}
/**
* Raise the icon window.
*/
inline void raise(void)
{
m_nxwin->raise();
}
/**
* Lower the icon window.
*/
inline void lower(void)
{
m_nxwin->lower();
}
/**
* Handle ICON WINDOW events.
*
* @param eventmsg. The received NxWidget ICON event message.
* @return True if the message was properly handled. false is
* return on any failure.
*/
bool event(FAR struct SEventMsg *eventmsg);
};
}
#endif // __APPS_INCLUDE_GRAPHICS_TWM4NX_CICONWIN_HXX

View File

@ -237,7 +237,19 @@ namespace Twm4Nx
}
/**
* Return the session's Icon instance.
* Return the session's CBackground instance.
*
* @return The contained instance of the CBackground class for this
* session.
*/
inline FAR CBackground *getBackground(void)
{
return m_background;
}
/**
* Return the session's CIcon instance.
*
* @return The contained instance of the Icon class for this session.
*/

View File

@ -49,6 +49,7 @@
/////////////////////////////////////////////////////////////////////////////
#include <cstdint>
#include <mqueue.h>
#include <nuttx/nx/nxglib.h>
@ -56,7 +57,7 @@
#include "graphics/nxwidgets/cwidgeteventhandler.hxx"
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
#include "graphics/twm4nx/ciconwin.hxx"
#include "graphics/twm4nx/ciconwidget.hxx"
#include "graphics/twm4nx/ctwm4nxevent.hxx"
/////////////////////////////////////////////////////////////////////////////
@ -94,7 +95,7 @@ namespace NXWidgets
namespace Twm4Nx
{
class CIconWin; // Forward reference
class CIconWidget; // Forward reference
class CIconMgr; // Forward reference
class CWindow; // Forward reference
struct SMenuRoot; // Forward reference
@ -118,7 +119,9 @@ namespace Twm4Nx
// Icon
FAR CIconWin *m_iconWin; /**< The icon window */
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_isIconMgr; /**< This is an icon manager window */
bool m_iconMoved; /**< User explicitly moved the icon. */
@ -228,12 +231,12 @@ namespace Twm4Nx
void handleDropEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Handle a key press event.
* Handle a mouse click event.
*
* @param e The event data.
*/
void handleKeyPressEvent(const NXWidgets::CWidgetEventArgs &e);
void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
/**
* Override the virtual CWidgetEventHandler::handleReleaseEvent. This
@ -559,9 +562,9 @@ namespace Twm4Nx
* @param size Location to return the icon window size
*/
inline bool getIconWindowSize(FAR struct nxgl_size_s *size)
inline void getIconWidgetSize(FAR struct nxgl_size_s &size)
{
return m_iconWin->getSize(size);
m_iconWidget->getSize(size);
}
/**
@ -572,9 +575,9 @@ namespace Twm4Nx
* @param pos Location to return the icon window position
*/
inline bool getIconWindowPosition(FAR struct nxgl_point_s *pos)
inline void getIconWidgetPosition(FAR struct nxgl_point_s &pos)
{
return m_iconWin->getPosition(pos);
m_iconWidget->getPos(pos);
}
/**
@ -585,9 +588,9 @@ namespace Twm4Nx
* @param pos The new location of the icon window
*/
inline bool setIconWindowPosition(FAR const struct nxgl_point_s *pos)
inline bool setIconWindowPosition(FAR const struct nxgl_point_s &pos)
{
return m_iconWin->setPosition(pos);
return m_iconWidget->resize(pos.x, pos.y);
}
/**

View File

@ -81,17 +81,17 @@ namespace Twm4Nx
enum EEventRecipient
{
EVENT_RECIPIENT_MSG = 0x0000, /**< Twm4Nx messenging event */
EVENT_RECIPIENT_SYSTEM = 0x1000, /**< Twm4Nx system event */
EVENT_RECIPIENT_ICONWIN = 0x2000, /**< Icon Window event */
EVENT_RECIPIENT_ICONMGR = 0x3000, /**< Icon Manager event */
EVENT_RECIPIENT_MENU = 0x4000, /**< Menu related event */
EVENT_RECIPIENT_WINDOW = 0x5000, /**< Window related event */
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 */
EVENT_RECIPIENT_MSG = 0x0000, /**< Twm4Nx messenging event */
EVENT_RECIPIENT_SYSTEM = 0x1000, /**< Twm4Nx system event */
EVENT_RECIPIENT_ICONWIDGET = 0x2000, /**< Icon Widget event */
EVENT_RECIPIENT_ICONMGR = 0x3000, /**< Icon Manager event */
EVENT_RECIPIENT_MENU = 0x4000, /**< Menu related event */
EVENT_RECIPIENT_WINDOW = 0x5000, /**< Window related event */
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 */
};
/**
@ -102,65 +102,65 @@ namespace Twm4Nx
{
// Recipient == MSG
EVENT_MSG_POLL = 0x0000, /**< Poll widgets for events */
EVENT_MSG_POLL = 0x0000, /**< Poll widgets for events */
// Recipient == SYSTEM
EVENT_SYSTEM_NOP = 0x1000, /**< Null event */
EVENT_SYSTEM_ERROR = 0x1001, /**< Report system error */
EVENT_SYSTEM_EXIT = 0x1002, /**< 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
// Recipient == ICONWIDGET
EVENT_ICONWIN_GRAB = 0x2000, /**< Click on toolbar title */
EVENT_ICONWIN_DRAG = 0x2001, /**< Drag window */
EVENT_ICONWIN_UNGRAB = 0x2002, /**< Release click on toolbar */
EVENT_ICONWIDGET_GRAB = 0x2000, /**< Click on toolbar title */
EVENT_ICONWIDGET_DRAG = 0x2001, /**< Drag window */
EVENT_ICONWIDGET_UNGRAB = 0x2002, /**< Release click on toolbar */
// Recipient == ICONMGR
// Recipient == MENU
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_FUNCTION = 0x4005, /**< Perform function on unknown menu */
EVENT_MENU_TITLE = 0x4006, /**< REVISIT: Really an action not an event */
EVENT_MENU_ROOT = 0x4007, /**< REVISIT: Popup root menu */
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_FUNCTION = 0x4005, /**< Perform function on unknown menu */
EVENT_MENU_TITLE = 0x4006, /**< REVISIT: Really an action not an event */
EVENT_MENU_ROOT = 0x4007, /**< REVISIT: Popup root menu */
// Recipient == WINDOW
EVENT_WINDOW_FOCUS = 0x5000, /**< Enter modal state */
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_DEICONIFY = 0x5004, /**< De-iconify and raise window */
EVENT_WINDOW_DRAG = 0x5005, /**< Drag window */
EVENT_WINDOW_DELETE = 0x5006, /**< Delete window */
EVENT_WINDOW_FOCUS = 0x5000, /**< Enter modal state */
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_DEICONIFY = 0x5004, /**< De-iconify and raise window */
EVENT_WINDOW_DRAG = 0x5005, /**< Drag window */
EVENT_WINDOW_DELETE = 0x5006, /**< Delete window */
// Recipient == TOOLBAR
EVENT_TOOLBAR_GRAB = 0x6000, /**< Click on title widget */
EVENT_TOOLBAR_UNGRAB = 0x6001, /**< Release click on title widget */
EVENT_TOOLBAR_MENU = 0x6002, /**< Toolbar menu button released */
EVENT_TOOLBAR_MINIMIZE = 0x6003, /**< Toolbar minimize button released */
EVENT_TOOLBAR_RESIZE = 0x6004, /**< Toolbar resize button released */
EVENT_TOOLBAR_TERMINATE = 0x6005, /**< Toolbar delete button released */
EVENT_TOOLBAR_GRAB = 0x6000, /**< Click on title widget */
EVENT_TOOLBAR_UNGRAB = 0x6001, /**< Release click on title widget */
EVENT_TOOLBAR_MENU = 0x6002, /**< Toolbar menu button released */
EVENT_TOOLBAR_MINIMIZE = 0x6003, /**< Toolbar minimize button released */
EVENT_TOOLBAR_RESIZE = 0x6004, /**< Toolbar resize button released */
EVENT_TOOLBAR_TERMINATE = 0x6005, /**< Toolbar delete button released */
// Recipient == BORDER
// Recipient == RESIZE
EVENT_RESIZE_START = 0x8000, /**< Start window resize */
EVENT_RESIZE_VERTZOOM = 0x8001, /**< Zoom vertically only */
EVENT_RESIZE_HORIZOOM = 0x8002, /**< Zoom horizontally only */
EVENT_RESIZE_FULLZOOM = 0x8003, /**< Zoom both vertically and horizontally */
EVENT_RESIZE_LEFTZOOM = 0x8004, /**< Zoom left only */
EVENT_RESIZE_RIGHTZOOM = 0x8005, /**< Zoom right only */
EVENT_RESIZE_TOPZOOM = 0x8006, /**< Zoom top only */
EVENT_RESIZE_BOTTOMZOOM = 0x8007, /**< Zoom bottom only */
EVENT_RESIZE_START = 0x8000, /**< Start window resize */
EVENT_RESIZE_VERTZOOM = 0x8001, /**< Zoom vertically only */
EVENT_RESIZE_HORIZOOM = 0x8002, /**< Zoom horizontally only */
EVENT_RESIZE_FULLZOOM = 0x8003, /**< Zoom both vertically and horizontally */
EVENT_RESIZE_LEFTZOOM = 0x8004, /**< Zoom left only */
EVENT_RESIZE_RIGHTZOOM = 0x8005, /**< Zoom right only */
EVENT_RESIZE_TOPZOOM = 0x8006, /**< Zoom top only */
EVENT_RESIZE_BOTTOMZOOM = 0x8007, /**< Zoom bottom only */
// Recipient == ICONWIN
// Recipient == APP
// All application defined events must (1) use recepient == EVENT_RECIPIENT_APP,
// and (2) provide an instance of CTwm4NxEvent in the SEventMsg structure.
@ -192,7 +192,7 @@ namespace Twm4Nx
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) */
FAR void *obj; /**< Window object (CWindow or CIconWidget) */
};
/**