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:
parent
07b6eb555c
commit
e742f97674
@ -55,8 +55,8 @@ STACKSIZE = $(CONFIG_TWM4NX_STACKSIZE)
|
|||||||
ASRCS =
|
ASRCS =
|
||||||
CSRCS =
|
CSRCS =
|
||||||
CXXSRCS = cbackground.cxx cfonts.cxx cicon.cxx ciconmgr.cxx
|
CXXSRCS = cbackground.cxx cfonts.cxx cicon.cxx ciconmgr.cxx
|
||||||
CXXSRCS += ciconwidget.cxx ciconwin.cxx cinput.cxx cmenus.cxx
|
CXXSRCS += ciconwidget.cxx cinput.cxx cmenus.cxx cresize.cxx
|
||||||
CXXSRCS += cresize.cxx cwindow.cxx cwindowevent.cxx cwindowfactory.cxx
|
CXXSRCS += cwindow.cxx cwindowevent.cxx cwindowfactory.cxx
|
||||||
CXXSRCS += twm4nx_cursor.cxx
|
CXXSRCS += twm4nx_cursor.cxx
|
||||||
MAINSRC = ctwm4nx.cxx
|
MAINSRC = ctwm4nx.cxx
|
||||||
|
|
||||||
|
@ -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)
|
for (FAR struct SIconRegion *ir = m_regionHead; ir; ir = ir->flink)
|
||||||
{
|
{
|
||||||
struct nxgl_size_s iconWindowSize;
|
struct nxgl_size_s iconWindowSize;
|
||||||
cwin->getIconWindowSize(&iconWindowSize);
|
cwin->getIconWidgetSize(iconWindowSize);
|
||||||
|
|
||||||
struct nxgl_size_s tmpsize;
|
struct nxgl_size_s tmpsize;
|
||||||
tmpsize.w = roundUp(iconWindowSize.w, ir->step.x);
|
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;
|
ie->cwin = cwin;
|
||||||
|
|
||||||
struct nxgl_size_s iconWindowSize;
|
struct nxgl_size_s iconWindowSize;
|
||||||
cwin->getIconWindowSize(&iconWindowSize);
|
cwin->getIconWidgetSize(iconWindowSize);
|
||||||
|
|
||||||
final->x = ie->pos.x + (ie->size.w - iconWindowSize.w) / 2;
|
final->x = ie->pos.x + (ie->size.w - iconWindowSize.w) / 2;
|
||||||
final->y = ie->pos.y + (ie->size.h - iconWindowSize.h) / 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())
|
if (cwin->hasIconMoved())
|
||||||
{
|
{
|
||||||
struct nxgl_size_s oldsize;
|
struct nxgl_size_s oldsize;
|
||||||
if (!cwin->getIconWindowSize(&oldsize))
|
cwin->getIconWidgetSize(oldsize);
|
||||||
{
|
cwin->getIconWidgetPosition(oldpos);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!cwin->getIconWindowPosition(&oldpos))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
newpos.x = oldpos.x + ((int)oldsize.w) / 2;
|
newpos.x = oldpos.x + ((int)oldsize.w) / 2;
|
||||||
newpos.y = oldpos.y + ((int)oldsize.h) / 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)
|
if (newpos.x != oldpos.x || newpos.y != oldpos.y)
|
||||||
{
|
{
|
||||||
(void)cwin->getIconWindowPosition(&newpos);
|
cwin->getIconWidgetPosition(newpos);
|
||||||
cwin->setIconMoved(false); // since we've restored it
|
cwin->setIconMoved(false); // since we've restored it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,18 +41,24 @@
|
|||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
#include <cstdint>
|
||||||
#include <stdbool.h>
|
#include <cstdbool>
|
||||||
|
#include <cfcntl>
|
||||||
|
#include <cerrno>
|
||||||
|
#include <mqueue.h>
|
||||||
|
|
||||||
#include <nuttx/nx/nxglib.h>
|
#include <nuttx/nx/nxglib.h>
|
||||||
|
|
||||||
#include "graphics/nxwidgets/cgraphicsport.hxx"
|
#include "graphics/nxwidgets/cgraphicsport.hxx"
|
||||||
#include "graphics/nxwidgets/cwidgeteventargs.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/ctwm4nx.hxx"
|
||||||
#include "graphics/twm4nx/cfonts.hxx"
|
#include "graphics/twm4nx/cfonts.hxx"
|
||||||
#include "graphics/twm4nx/ciconwidget.hxx"
|
#include "graphics/twm4nx/ciconwidget.hxx"
|
||||||
|
#include "graphics/twm4nx/twm4nx_widgetevents.hxx"
|
||||||
|
#include "graphics/twm4nx/twm4nx_cursor.hxx"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// CIconWidget Definitions
|
// CIconWidget Definitions
|
||||||
@ -78,31 +84,59 @@ CIconWidget::CIconWidget(FAR CTwm4Nx *twm4nx,
|
|||||||
FAR NXWidgets::CWidgetStyle *style)
|
FAR NXWidgets::CWidgetStyle *style)
|
||||||
: CNxWidget(widgetControl, x, y, 0, 0, WIDGET_BORDERLESS, style)
|
: CNxWidget(widgetControl, x, y, 0, 0, WIDGET_BORDERLESS, style)
|
||||||
{
|
{
|
||||||
m_twm4nx = twm4nx;
|
m_twm4nx = twm4nx; // Save the Twm4Nx session instance
|
||||||
m_widgetControl = widgetControl;
|
m_widgetControl = widgetControl; // Save the widget control instance
|
||||||
|
m_eventq = (mqd_t)-1; // No widget message queue yet
|
||||||
|
|
||||||
// Configure the widget
|
// 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
|
* Perform widget initialization that could fail and so it not appropriate
|
||||||
* for the constructor
|
* 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
|
* @param title The icon title string
|
||||||
* @return True is returned if the widget is successfully initialized.
|
* @return True is returned if the widget is successfully initialized.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool CIconWidget::initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
|
bool CIconWidget::initialize(FAR NXWidgets::IBitmap *ibitmap,
|
||||||
FAR NXWidgets::CNxString &title)
|
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
|
// Get the size of the Icon bitmap
|
||||||
|
|
||||||
struct nxgl_size_s iconImageSize;
|
struct nxgl_size_s iconImageSize;
|
||||||
iconImageSize.w = cbitmap->getWidth();
|
iconImageSize.w = ibitmap->getWidth();
|
||||||
iconImageSize.h = cbitmap->getHeight();
|
iconImageSize.h = ibitmap->getHeight();
|
||||||
|
|
||||||
// Get the size of the Icon name
|
// Get the size of the Icon name
|
||||||
|
|
||||||
@ -140,7 +174,7 @@ bool CIconWidget::initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
|
|||||||
FAR NXWidgets::CImage *image =
|
FAR NXWidgets::CImage *image =
|
||||||
new NXWidgets::CImage(m_widgetControl, iconImagePos.x,
|
new NXWidgets::CImage(m_widgetControl, iconImagePos.x,
|
||||||
iconImagePos.y, iconImageSize.w, iconImageSize.h,
|
iconImagePos.y, iconImageSize.w, iconImageSize.h,
|
||||||
cbitmap, m_style);
|
ibitmap, m_style);
|
||||||
if (image == (FAR NXWidgets::CImage *)0)
|
if (image == (FAR NXWidgets::CImage *)0)
|
||||||
{
|
{
|
||||||
gerr("ERROR: Failed to create image\n");
|
gerr("ERROR: Failed to create image\n");
|
||||||
@ -208,6 +242,145 @@ void CIconWidget::getPreferredDimensions(NXWidgets::CRect &rect) const
|
|||||||
rect.setHeight(widgetSize.h);
|
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.
|
* Handle a mouse click event.
|
||||||
*
|
*
|
||||||
@ -216,29 +389,58 @@ void CIconWidget::getPreferredDimensions(NXWidgets::CRect &rect) const
|
|||||||
|
|
||||||
void CIconWidget::handleClickEvent(const NXWidgets::CWidgetEventArgs &e)
|
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.
|
* @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)
|
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)
|
void CIconWidget::handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e)
|
||||||
{
|
{
|
||||||
// Child raised a release outside event, but we need to raise a different
|
// Handle the case where a release event was received, but the
|
||||||
// event if the release occurred within the bounds of this parent widget
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -73,7 +73,7 @@
|
|||||||
#include "graphics/twm4nx/cwindowevent.hxx"
|
#include "graphics/twm4nx/cwindowevent.hxx"
|
||||||
#include "graphics/twm4nx/cinput.hxx"
|
#include "graphics/twm4nx/cinput.hxx"
|
||||||
#include "graphics/twm4nx/cicon.hxx"
|
#include "graphics/twm4nx/cicon.hxx"
|
||||||
#include "graphics/twm4nx/ciconwin.hxx"
|
#include "graphics/twm4nx/ciconwidget.hxx"
|
||||||
#include "graphics/twm4nx/ciconmgr.hxx"
|
#include "graphics/twm4nx/ciconmgr.hxx"
|
||||||
#include "graphics/twm4nx/cmenus.hxx"
|
#include "graphics/twm4nx/cmenus.hxx"
|
||||||
#include "graphics/twm4nx/cresize.hxx"
|
#include "graphics/twm4nx/cresize.hxx"
|
||||||
@ -425,11 +425,11 @@ bool CTwm4Nx::dispatchEvent(FAR struct SEventMsg *eventmsg)
|
|||||||
ret = systemEvent(eventmsg);
|
ret = systemEvent(eventmsg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_RECIPIENT_ICONWIN: // Icon window event
|
case EVENT_RECIPIENT_ICONWIDGET: // Icon widget event
|
||||||
{
|
{
|
||||||
FAR CIconWin *iconWin = (FAR CIconWin *)eventmsg->obj;
|
FAR CIconWidget *iconWidget = (FAR CIconWidget *)eventmsg->obj;
|
||||||
DEBUGASSERT(iconWin != (FAR CIconWin *)0);
|
DEBUGASSERT(iconWidget != (FAR CIconWidget *)0);
|
||||||
ret = iconWin->event(eventmsg);
|
ret = iconWidget->event(eventmsg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@
|
|||||||
#include "graphics/twm4nx/ctwm4nx.hxx"
|
#include "graphics/twm4nx/ctwm4nx.hxx"
|
||||||
#include "graphics/twm4nx/cfonts.hxx"
|
#include "graphics/twm4nx/cfonts.hxx"
|
||||||
#include "graphics/twm4nx/cresize.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/ciconmgr.hxx"
|
||||||
#include "graphics/twm4nx/cwindowevent.hxx"
|
#include "graphics/twm4nx/cwindowevent.hxx"
|
||||||
#include "graphics/twm4nx/cwindow.hxx"
|
#include "graphics/twm4nx/cwindow.hxx"
|
||||||
@ -150,7 +151,8 @@ CWindow::CWindow(CTwm4Nx *twm4nx)
|
|||||||
|
|
||||||
// Icons/Icon Manager
|
// 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_iconMgr = (FAR CIconMgr *)0;
|
||||||
m_isIconMgr = false;
|
m_isIconMgr = false;
|
||||||
m_iconOn = 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);
|
m_iconBitMap = new NXWidgets::CRlePaletteBitmap(sbitmap);
|
||||||
if (m_iconWin == (FAR CIconWin *)0)
|
if (m_iconBitMap == (NXWidgets::CRlePaletteBitmap *)0)
|
||||||
{
|
{
|
||||||
gerr("ERROR: Failed to create the icon Window\n");
|
gerr("ERROR: Failed to create icon image\n");
|
||||||
cleanup();
|
cleanup();
|
||||||
return false;
|
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();
|
cleanup();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -461,7 +479,6 @@ void CWindow::iconify(void)
|
|||||||
|
|
||||||
m_iconified = true;
|
m_iconified = true;
|
||||||
m_nxWin->lower();
|
m_nxWin->lower();
|
||||||
m_iconWin->raise();
|
|
||||||
m_iconOn = true;
|
m_iconOn = true;
|
||||||
m_nxWin->synchronize();
|
m_nxWin->synchronize();
|
||||||
}
|
}
|
||||||
@ -476,7 +493,6 @@ void CWindow::deIconify(void)
|
|||||||
// Raise the main window and lower the icon window
|
// Raise the main window and lower the icon window
|
||||||
|
|
||||||
m_iconified = false;
|
m_iconified = false;
|
||||||
m_iconWin->lower();
|
|
||||||
m_nxWin->raise();
|
m_nxWin->raise();
|
||||||
m_iconOn = false;
|
m_iconOn = false;
|
||||||
m_nxWin->synchronize();
|
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.
|
* @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
|
// We are interested only the the press event on the title box and
|
||||||
// only if we are not already dragging the window
|
// 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)
|
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.
|
// window was not dragged.
|
||||||
|
|
||||||
if (m_drag && !m_tbTitle->isClicked())
|
if (m_drag && !m_tbTitle->isClicked())
|
||||||
{
|
{
|
||||||
// A click with no drag should raise the window.
|
// A click with no drag should raise the window.
|
||||||
|
|
||||||
m_iconWin->raise();
|
m_nxWin->raise();
|
||||||
|
|
||||||
// Handle the non-drag drop event
|
// Handle the non-drag drop event
|
||||||
|
|
||||||
@ -1383,7 +1399,7 @@ void CWindow::cleanup(void)
|
|||||||
m_tbTitle = (FAR NXWidgets::CLabel *)0;
|
m_tbTitle = (FAR NXWidgets::CLabel *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close windows
|
// Delete the window
|
||||||
|
|
||||||
if (m_nxWin != (FAR NXWidgets::CNxTkWindow *)0)
|
if (m_nxWin != (FAR NXWidgets::CNxTkWindow *)0)
|
||||||
{
|
{
|
||||||
@ -1391,10 +1407,18 @@ void CWindow::cleanup(void)
|
|||||||
m_nxWin = (FAR NXWidgets::CNxTkWindow *)0;
|
m_nxWin = (FAR NXWidgets::CNxTkWindow *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_iconWin != (FAR CIconWin *)0)
|
// Delete the Icon
|
||||||
|
|
||||||
|
if (m_iconWidget != (FAR CIconWidget *)0)
|
||||||
{
|
{
|
||||||
delete m_iconWin;
|
delete m_iconWidget;
|
||||||
m_iconWin = (FAR CIconWin *)0;
|
m_iconWidget = (FAR CIconWidget *)0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_iconBitMap != (FAR NXWidgets::CRlePaletteBitmap *)0)
|
||||||
|
{
|
||||||
|
delete m_iconBitMap;
|
||||||
|
m_iconBitMap = (FAR NXWidgets::CRlePaletteBitmap *)0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Free memory
|
// Free memory
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdbool>
|
#include <cstdbool>
|
||||||
|
#include <mqueue.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include <nuttx/nx/nxglib.h>
|
#include <nuttx/nx/nxglib.h>
|
||||||
@ -61,6 +62,7 @@
|
|||||||
|
|
||||||
namespace NXWidgets
|
namespace NXWidgets
|
||||||
{
|
{
|
||||||
|
class IBitmap; // Forward reference
|
||||||
class CNxWidget; // Forward reference
|
class CNxWidget; // Forward reference
|
||||||
class CWidgetStyle; // Forward reference
|
class CWidgetStyle; // Forward reference
|
||||||
class CWidgetControl; // Forward reference
|
class CWidgetControl; // Forward reference
|
||||||
@ -85,9 +87,107 @@ namespace Twm4Nx
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
FAR CTwm4Nx *m_twm4nx; /**< Cached Twm4Nx session */
|
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::CWidgetControl *m_widgetControl; /**< The controlling widget */
|
||||||
FAR NXWidgets::CWidgetStyle *m_style; /**< Widget style */
|
FAR NXWidgets::CWidgetStyle *m_style; /**< Widget style */
|
||||||
|
|
||||||
|
// 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 */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 handleUngrabEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override the mouse button drag event.
|
||||||
|
*
|
||||||
|
* @param e The event data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void handleDragEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override a drop event, triggered when the widget has been dragged-
|
||||||
|
* and-dropped.
|
||||||
|
*
|
||||||
|
* @param e The event data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void handleDropEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a mouse click event.
|
||||||
|
*
|
||||||
|
* @param e The event data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a mouse button release event that occurred outside the bounds of
|
||||||
|
* the source widget.
|
||||||
|
*
|
||||||
|
* @param e The event data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void handleReleaseOutsideEvent(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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool iconGrab(FAR struct SEventMsg *eventmsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 iconDrag(FAR struct SEventMsg *eventmsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 iconUngrab(FAR struct SEventMsg *eventmsg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw the area of this widget that falls within the clipping region.
|
* Draw the area of this widget that falls within the clipping region.
|
||||||
* Called by the redraw() function to draw all visible regions.
|
* Called by the redraw() function to draw all visible regions.
|
||||||
@ -95,7 +195,7 @@ namespace Twm4Nx
|
|||||||
* @see redraw()
|
* @see redraw()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual void drawContents(NXWidgets::CGraphicsPort* port);
|
void drawContents(NXWidgets::CGraphicsPort* port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy constructor is protected to prevent usage.
|
* Copy constructor is protected to prevent usage.
|
||||||
@ -129,21 +229,19 @@ namespace Twm4Nx
|
|||||||
* Destructor.
|
* Destructor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
~CIconWidget(void)
|
~CIconWidget(void);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform widget initialization that could fail and so it not appropriate
|
* Perform widget initialization that could fail and so it not appropriate
|
||||||
* for the constructor
|
* 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
|
* @param title The icon title string
|
||||||
* @return True is returned if the widget is successfully initialized.
|
* @return True is returned if the widget is successfully initialized.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool initialize(FAR NXWidgets::CRlePaletteBitmap *cbitmap,
|
bool initialize(FAR NXWidgets::IBitmap *ibitmap,
|
||||||
FAR NXWidgets::CNxString &title);
|
FAR const NXWidgets::CNxString &title);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the dimensions that this widget wants to have into the rect
|
* Insert the dimensions that this widget wants to have into the rect
|
||||||
@ -154,40 +252,17 @@ namespace Twm4Nx
|
|||||||
* @param rect Reference to a rect to populate with data.
|
* @param rect Reference to a rect to populate with data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual void getPreferredDimensions(NXWidgets::CRect &rect) const;
|
void getPreferredDimensions(NXWidgets::CRect &rect) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a mouse click event.
|
* Handle ICON WIDGET events.
|
||||||
*
|
*
|
||||||
* @param e The event data.
|
* @param eventmsg. The received NxWidget ICON event message.
|
||||||
|
* @return True if the message was properly handled. false is
|
||||||
|
* return on any failure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
virtual void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
|
bool event(FAR struct SEventMsg *eventmsg);
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a mouse double-click event.
|
|
||||||
*
|
|
||||||
* @param e The event data.
|
|
||||||
*/
|
|
||||||
|
|
||||||
virtual void handleDoubleClickEvent(const NXWidgets::CWidgetEventArgs &e);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a mouse button release event that occurred within the bounds of
|
|
||||||
* the source widget.
|
|
||||||
* @param e The event data.
|
|
||||||
*/
|
|
||||||
|
|
||||||
virtual void handleReleaseEvent(const NXWidgets::CWidgetEventArgs &e);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a mouse button release event that occurred outside the bounds of
|
|
||||||
* the source widget.
|
|
||||||
*
|
|
||||||
* @param e The event data.
|
|
||||||
*/
|
|
||||||
|
|
||||||
virtual void handleReleaseOutsideEvent(const NXWidgets::CWidgetEventArgs &e);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
|
@ -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.
|
* @return The contained instance of the Icon class for this session.
|
||||||
*/
|
*/
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <mqueue.h>
|
||||||
|
|
||||||
#include <nuttx/nx/nxglib.h>
|
#include <nuttx/nx/nxglib.h>
|
||||||
|
|
||||||
@ -56,7 +57,7 @@
|
|||||||
#include "graphics/nxwidgets/cwidgeteventhandler.hxx"
|
#include "graphics/nxwidgets/cwidgeteventhandler.hxx"
|
||||||
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
|
#include "graphics/nxwidgets/cwidgeteventargs.hxx"
|
||||||
|
|
||||||
#include "graphics/twm4nx/ciconwin.hxx"
|
#include "graphics/twm4nx/ciconwidget.hxx"
|
||||||
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
#include "graphics/twm4nx/ctwm4nxevent.hxx"
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
@ -94,7 +95,7 @@ namespace NXWidgets
|
|||||||
|
|
||||||
namespace Twm4Nx
|
namespace Twm4Nx
|
||||||
{
|
{
|
||||||
class CIconWin; // Forward reference
|
class CIconWidget; // Forward reference
|
||||||
class CIconMgr; // Forward reference
|
class CIconMgr; // Forward reference
|
||||||
class CWindow; // Forward reference
|
class CWindow; // Forward reference
|
||||||
struct SMenuRoot; // Forward reference
|
struct SMenuRoot; // Forward reference
|
||||||
@ -118,7 +119,9 @@ namespace Twm4Nx
|
|||||||
|
|
||||||
// Icon
|
// 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 */
|
FAR CIconMgr *m_iconMgr; /**< Pointer to it if this is an icon manager */
|
||||||
bool m_isIconMgr; /**< This is an icon manager window */
|
bool m_isIconMgr; /**< This is an icon manager window */
|
||||||
bool m_iconMoved; /**< User explicitly moved the icon. */
|
bool m_iconMoved; /**< User explicitly moved the icon. */
|
||||||
@ -228,12 +231,12 @@ namespace Twm4Nx
|
|||||||
void handleDropEvent(const NXWidgets::CWidgetEventArgs &e);
|
void handleDropEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a key press event.
|
* Handle a mouse click event.
|
||||||
*
|
*
|
||||||
* @param e The event data.
|
* @param e The event data.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void handleKeyPressEvent(const NXWidgets::CWidgetEventArgs &e);
|
void handleClickEvent(const NXWidgets::CWidgetEventArgs &e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the virtual CWidgetEventHandler::handleReleaseEvent. This
|
* Override the virtual CWidgetEventHandler::handleReleaseEvent. This
|
||||||
@ -559,9 +562,9 @@ namespace Twm4Nx
|
|||||||
* @param size Location to return the icon window size
|
* @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
|
* @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
|
* @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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,7 +83,7 @@ namespace Twm4Nx
|
|||||||
{
|
{
|
||||||
EVENT_RECIPIENT_MSG = 0x0000, /**< Twm4Nx messenging event */
|
EVENT_RECIPIENT_MSG = 0x0000, /**< Twm4Nx messenging event */
|
||||||
EVENT_RECIPIENT_SYSTEM = 0x1000, /**< Twm4Nx system event */
|
EVENT_RECIPIENT_SYSTEM = 0x1000, /**< Twm4Nx system event */
|
||||||
EVENT_RECIPIENT_ICONWIN = 0x2000, /**< Icon Window event */
|
EVENT_RECIPIENT_ICONWIDGET = 0x2000, /**< Icon Widget event */
|
||||||
EVENT_RECIPIENT_ICONMGR = 0x3000, /**< Icon Manager event */
|
EVENT_RECIPIENT_ICONMGR = 0x3000, /**< Icon Manager event */
|
||||||
EVENT_RECIPIENT_MENU = 0x4000, /**< Menu related event */
|
EVENT_RECIPIENT_MENU = 0x4000, /**< Menu related event */
|
||||||
EVENT_RECIPIENT_WINDOW = 0x5000, /**< Window related event */
|
EVENT_RECIPIENT_WINDOW = 0x5000, /**< Window related event */
|
||||||
@ -110,11 +110,11 @@ namespace Twm4Nx
|
|||||||
EVENT_SYSTEM_ERROR = 0x1001, /**< Report system error */
|
EVENT_SYSTEM_ERROR = 0x1001, /**< Report system error */
|
||||||
EVENT_SYSTEM_EXIT = 0x1002, /**< Terminate the Twm4Nx session */
|
EVENT_SYSTEM_EXIT = 0x1002, /**< Terminate the Twm4Nx session */
|
||||||
|
|
||||||
// Recipient == ICONWIN
|
// Recipient == ICONWIDGET
|
||||||
|
|
||||||
EVENT_ICONWIN_GRAB = 0x2000, /**< Click on toolbar title */
|
EVENT_ICONWIDGET_GRAB = 0x2000, /**< Click on toolbar title */
|
||||||
EVENT_ICONWIN_DRAG = 0x2001, /**< Drag window */
|
EVENT_ICONWIDGET_DRAG = 0x2001, /**< Drag window */
|
||||||
EVENT_ICONWIN_UNGRAB = 0x2002, /**< Release click on toolbar */
|
EVENT_ICONWIDGET_UNGRAB = 0x2002, /**< Release click on toolbar */
|
||||||
|
|
||||||
// Recipient == ICONMGR
|
// Recipient == ICONMGR
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ namespace Twm4Nx
|
|||||||
EVENT_RESIZE_TOPZOOM = 0x8006, /**< Zoom top only */
|
EVENT_RESIZE_TOPZOOM = 0x8006, /**< Zoom top only */
|
||||||
EVENT_RESIZE_BOTTOMZOOM = 0x8007, /**< Zoom bottom only */
|
EVENT_RESIZE_BOTTOMZOOM = 0x8007, /**< Zoom bottom only */
|
||||||
|
|
||||||
// Recipient == ICONWIN
|
// Recipient == APP
|
||||||
// All application defined events must (1) use recepient == EVENT_RECIPIENT_APP,
|
// All application defined events must (1) use recepient == EVENT_RECIPIENT_APP,
|
||||||
// and (2) provide an instance of CTwm4NxEvent in the SEventMsg structure.
|
// 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) */
|
struct nxgl_point_s delta; /**< X/Y change (for dragging only) */
|
||||||
uint8_t context; /**< Button press context */
|
uint8_t context; /**< Button press context */
|
||||||
FAR CTwm4NxEvent *handler; /**< App event handler (APP recipient only) */
|
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) */
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user