2012-03-22 22:22:59 +01:00
|
|
|
/****************************************************************************
|
2018-09-17 01:23:45 +02:00
|
|
|
* apps/include/graphics/nxwidgets/cwidgetcontrol.hxx
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
2021-06-11 08:28:21 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-17 01:23:45 +02:00
|
|
|
#ifndef __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETCONTROLT_HXX
|
|
|
|
#define __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETCONTROLT_HXX
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2013-02-28 19:48:11 +01:00
|
|
|
#include <stdlib.h>
|
2012-03-22 22:22:59 +01:00
|
|
|
#include <semaphore.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2018-09-17 01:23:45 +02:00
|
|
|
#include "graphics/nxwidgets/nxconfig.hxx"
|
|
|
|
#include "graphics/nxwidgets/cgraphicsport.hxx"
|
|
|
|
#include "graphics/nxwidgets/cnxwidget.hxx"
|
|
|
|
#include "graphics/nxwidgets/crect.hxx"
|
|
|
|
#include "graphics/nxwidgets/cwidgetstyle.hxx"
|
|
|
|
#include "graphics/nxwidgets/cwindoweventhandler.hxx"
|
|
|
|
#include "graphics/nxwidgets/cwindoweventhandlerlist.hxx"
|
|
|
|
#include "graphics/nxwidgets/tnxarray.hxx"
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Implementation Classes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
|
|
|
namespace NXWidgets
|
|
|
|
{
|
|
|
|
class INxWindow;
|
|
|
|
class CNxWidget;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class providing a top-level widget and an interface to the CWidgetControl
|
|
|
|
* widget hierarchy.
|
|
|
|
*
|
|
|
|
* There are three instances that represent an NX window from the
|
|
|
|
* perspective of NXWidgets.
|
|
|
|
*
|
|
|
|
* - There is one widget control instance per NX window,
|
|
|
|
* - One CCallback instance per window,
|
|
|
|
* - One window instance.
|
|
|
|
*
|
|
|
|
* There a various kinds of of window instances, but each inherits
|
|
|
|
* (1) CCallback and dispatches the Windows callbacks and (2) INxWindow
|
|
|
|
* that describes the common window behavior.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CWidgetControl
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Structure holding the status of the Mouse or Touchscreen. There must
|
|
|
|
* be one instance of this structure per window instance. The
|
|
|
|
* content of this structure is update by the CGraphicsPort on each
|
|
|
|
* NX mouse callback
|
|
|
|
*/
|
|
|
|
|
2014-07-17 03:20:44 +02:00
|
|
|
#ifdef CONFIG_NX_XYINPUT
|
|
|
|
struct SXYInput
|
2012-03-22 22:22:59 +01:00
|
|
|
{
|
2014-07-17 03:20:44 +02:00
|
|
|
// A touchscreen has no buttons. However, the convention is that
|
|
|
|
// touchscreen contacts are reported with the LEFT button pressed.
|
|
|
|
// The loss of contct is reported with no buttons pressed.
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
#if 0 // Center and right buttons are not used
|
2014-07-17 03:20:44 +02:00
|
|
|
// But only a mouse has center and right buttons
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
uint16_t leftPressed : 1; /**< Left button pressed (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint16_t centerPressed : 1; /**< Center button pressed (not
|
|
|
|
used with touchscreen) */
|
|
|
|
uint16_t rightPressed : 1; /**< Right button pressed (not
|
|
|
|
used with touchscreen) */
|
|
|
|
uint16_t leftHeld : 1; /**< Left button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint16_t centerHeld : 1; /**< Center button held down
|
|
|
|
(not used with touchscreen) */
|
|
|
|
uint16_t rightHeld : 1; /**< Right button held down
|
|
|
|
(not used with touchscreen) */
|
|
|
|
uint16_t leftDrag : 1; /**< Left button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint16_t centerDrag : 1; /**< Center button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint16_t rightDrag : 1; /**< Right button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint16_t leftReleased : 1; /**< Left button release (or
|
|
|
|
loss of touchscreen contact) */
|
|
|
|
uint16_t centerReleased : 1; /**< Center button release (or
|
|
|
|
loss of touchscreen contact) */
|
|
|
|
uint16_t rightReleased : 1; /**< Right button release (or
|
|
|
|
loss of touchscreen contact) */
|
|
|
|
uint16_t doubleClick : 1; /**< Left button double click */
|
|
|
|
uint16_t unused : 3; /**< Padding bits */
|
|
|
|
#else
|
|
|
|
uint8_t leftPressed : 1; /**< Left button pressed (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint8_t leftHeld : 1; /**< Left button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint8_t leftDrag : 1; /**< Left button held down (or
|
|
|
|
touchscreen contact) */
|
|
|
|
uint8_t leftReleased : 1; /**< Left button release (or
|
|
|
|
loss of touchscreen contact) */
|
|
|
|
uint8_t doubleClick : 1; /**< Left button double click */
|
|
|
|
uint8_t unused : 3; /**< Padding bits */
|
|
|
|
#endif
|
2014-07-17 03:20:44 +02:00
|
|
|
|
|
|
|
// These are attributes common to both touchscreen and mouse input devices
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
nxgl_coord_t x; /**< Current X coordinate of
|
|
|
|
the mouse/touch */
|
|
|
|
nxgl_coord_t y; /**< Current Y coordinate of
|
|
|
|
the mouse/touch */
|
|
|
|
nxgl_coord_t lastX; /**< X coordinate of the mouse
|
|
|
|
at the previous poll */
|
|
|
|
nxgl_coord_t lastY; /**< Y coordinate of the mouse
|
|
|
|
at the previous poll */
|
|
|
|
struct timespec leftPressTime; /**< Time the left button was
|
|
|
|
pressed */
|
|
|
|
struct timespec leftReleaseTime; /**< Time the left button was
|
|
|
|
released */
|
|
|
|
};
|
2014-07-17 03:20:44 +02:00
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* State data
|
|
|
|
*/
|
|
|
|
|
|
|
|
CGraphicsPort *m_port; /**< The graphics port
|
|
|
|
that is used for
|
|
|
|
drawing on this window */
|
|
|
|
TNxArray<CNxWidget*> m_deleteQueue; /**< Array of widgets
|
|
|
|
awaiting deletion. */
|
|
|
|
TNxArray<CNxWidget*> m_widgets; /**< List of controlled
|
|
|
|
widgets. */
|
2019-05-01 19:11:43 +02:00
|
|
|
volatile bool m_haveGeometry; /**< True: indicates that we
|
2012-05-07 23:25:24 +02:00
|
|
|
have valid geometry data. */
|
2012-05-09 21:31:48 +02:00
|
|
|
#ifdef CONFIG_NXWIDGET_EVENTWAIT
|
2019-05-01 19:11:43 +02:00
|
|
|
bool m_waiting; /**< True: External logic waiting for
|
2012-05-09 21:31:48 +02:00
|
|
|
window event */
|
|
|
|
sem_t m_waitSem; /**< External loops waits for
|
2012-03-22 22:22:59 +01:00
|
|
|
events on this semaphore */
|
2012-05-09 21:31:48 +02:00
|
|
|
#endif
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* I/O
|
|
|
|
*/
|
|
|
|
|
2014-07-17 03:20:44 +02:00
|
|
|
#ifdef CONFIG_NX_XYINPUT
|
|
|
|
struct SXYInput m_xyinput; /**< Current XY input
|
2012-03-22 22:22:59 +01:00
|
|
|
device state */
|
2014-07-17 03:20:44 +02:00
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
CNxWidget *m_clickedWidget; /**< Pointer to the widget
|
|
|
|
that is clicked. */
|
|
|
|
CNxWidget *m_focusedWidget; /**< Pointer to the widget
|
|
|
|
that received keyboard
|
|
|
|
input. */
|
|
|
|
uint8_t m_kbdbuf[CONFIG_NXWIDGETS_KBDBUFFER_SIZE];
|
|
|
|
uint8_t m_nCh; /**< Number of buffered
|
|
|
|
keyboard characters */
|
|
|
|
uint8_t m_controls[CONFIG_NXWIDGETS_CURSORCONTROL_SIZE];
|
|
|
|
uint8_t m_nCc; /**< Number of buffered
|
|
|
|
cursor controls */
|
|
|
|
/**
|
|
|
|
* The following were picked off from the position callback.
|
|
|
|
*/
|
|
|
|
|
|
|
|
NXHANDLE m_hWindow; /**< Handle to the NX window */
|
|
|
|
struct nxgl_size_s m_size; /**< Size of the window */
|
|
|
|
struct nxgl_point_s m_pos; /**< Position in display space */
|
|
|
|
struct nxgl_rect_s m_bounds; /**< Size of the display */
|
2012-05-02 16:38:54 +02:00
|
|
|
sem_t m_geoSem; /**< Posted when geometry is valid */
|
2013-02-28 19:48:11 +01:00
|
|
|
sem_t m_boundsSem; /**< Posted when bounds are valid */
|
2012-05-09 21:31:48 +02:00
|
|
|
CWindowEventHandlerList m_eventHandlers; /**< List of event handlers. */
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Style
|
|
|
|
*/
|
|
|
|
|
|
|
|
CWidgetStyle m_style; /**< Default style used by all
|
|
|
|
widgets in the window. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a widget style
|
|
|
|
*
|
|
|
|
* @param dest The destination style
|
|
|
|
* @param src The source to use
|
|
|
|
*/
|
|
|
|
|
|
|
|
void copyWidgetStyle(CWidgetStyle *dest, const CWidgetStyle *src);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the elapsed time in millisconds
|
|
|
|
*
|
|
|
|
* @param startTime A time in the past from which to compute the elapsed time.
|
|
|
|
* @return The elapsed time since startTime
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
uint32_t elapsedTime(FAR const struct timespec *startTime);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pass clicks to the widget hierarchy. Closes the context menu if
|
|
|
|
* the clicked widget is not the context menu. If a single widget
|
2012-05-09 21:31:48 +02:00
|
|
|
* is supplied, only that widget is sent the click.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @param x Click xcoordinate.
|
|
|
|
* @param y Click ycoordinate.
|
2012-05-09 21:31:48 +02:00
|
|
|
* @param widget. Specific widget to poll. Use NULL to run the
|
|
|
|
* all widgets in the window.
|
2019-05-08 23:28:06 +02:00
|
|
|
* @return True means an interesting mouse event occurred
|
2012-03-22 22:22:59 +01:00
|
|
|
*/
|
|
|
|
|
2019-05-08 23:28:06 +02:00
|
|
|
bool handleLeftClick(nxgl_coord_t x, nxgl_coord_t y, CNxWidget *widget);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the index of the specified controlled widget.
|
|
|
|
*
|
|
|
|
* @param widget The widget to get the index of.
|
|
|
|
* @return The index of the widget. -1 if the widget is not found.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const int getWidgetIndex(const CNxWidget *widget) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete any widgets in the deletion queue.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
void processDeleteQueue(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process mouse/touchscreen events and send throughout the hierarchy.
|
|
|
|
*
|
2012-05-09 21:31:48 +02:00
|
|
|
* @param widget. Specific widget to poll. Use NULL to run the
|
|
|
|
* all widgets in the window.
|
2012-03-22 22:22:59 +01:00
|
|
|
* @return True means a mouse event occurred
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool pollMouseEvents(CNxWidget* widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process keypad events and send throughout the hierarchy.
|
|
|
|
*
|
|
|
|
* @return True means a keyboard event occurred
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool pollKeyboardEvents(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process cursor control events and send throughout the hierarchy.
|
|
|
|
*
|
|
|
|
* @return True means a cursor control event was processes
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool pollCursorControlEvents(void);
|
|
|
|
|
2019-05-02 22:41:53 +02:00
|
|
|
#ifdef CONFIG_NXWIDGET_EVENTWAIT
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
2012-05-09 21:31:48 +02:00
|
|
|
* Wake up and external logic that is waiting for a window event.
|
2012-03-22 22:22:59 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-09 21:31:48 +02:00
|
|
|
void postWindowEvent(void);
|
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
2012-05-02 00:31:26 +02:00
|
|
|
/**
|
|
|
|
* Take the geometry semaphore (handling signal interruptions)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void takeGeoSem(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Give the geometry semaphore
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void giveGeoSem(void)
|
|
|
|
{
|
2012-05-02 16:38:54 +02:00
|
|
|
sem_post(&m_geoSem);
|
2012-05-02 00:31:26 +02:00
|
|
|
}
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
/**
|
2020-02-23 05:51:44 +01:00
|
|
|
* Check if geometry data is available. If not, [re-]request the
|
|
|
|
* geometry data and wait for it to become valid.
|
2019-05-01 19:11:43 +02:00
|
|
|
* CAREFUL: This assumes that if we already have geometry data, then
|
|
|
|
* it is valid. This might not be true if the size position was
|
|
|
|
* recently changed.
|
2012-05-07 17:05:07 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-01 19:11:43 +02:00
|
|
|
void waitGeoData(void);
|
2012-05-07 17:05:07 +02:00
|
|
|
|
2013-02-28 19:48:11 +01:00
|
|
|
/**
|
|
|
|
* Take the bounds semaphore (handling signal interruptions)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void takeBoundsSem(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Give the bounds semaphore
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void giveBoundsSem(void)
|
|
|
|
{
|
|
|
|
sem_post(&m_boundsSem);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wait for bounds data
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void waitBoundsData(void)
|
|
|
|
{
|
|
|
|
takeBoundsSem();
|
|
|
|
giveBoundsSem();
|
|
|
|
}
|
|
|
|
|
2014-07-17 03:20:44 +02:00
|
|
|
#ifdef CONFIG_NX_XYINPUT
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* Clear all mouse events
|
|
|
|
*/
|
|
|
|
|
|
|
|
void clearMouseEvents(void);
|
2014-07-17 03:20:44 +02:00
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param style The default style that all widgets on this display
|
|
|
|
* should use. If this is not specified, the widget will use the
|
|
|
|
* values stored in the defaultCWidgetStyle object.
|
|
|
|
*/
|
|
|
|
|
2022-10-15 19:55:16 +02:00
|
|
|
CWidgetControl(FAR const CWidgetStyle *style = NULL);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-05-17 00:43:40 +02:00
|
|
|
virtual ~CWidgetControl(void);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
2019-05-02 22:41:53 +02:00
|
|
|
#ifdef CONFIG_NXWIDGET_EVENTWAIT
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
2012-05-09 21:31:48 +02:00
|
|
|
* Wait for an interesting window event to occur (like a mouse or keyboard event)
|
|
|
|
* Caller's should exercise care to assure that the test for waiting and this
|
|
|
|
* call are "atomic" .. perhaps by locking the scheduler like:
|
|
|
|
*
|
|
|
|
* sched_lock();
|
|
|
|
* <check for events>
|
|
|
|
* if (<no interesting events>)
|
|
|
|
* {
|
|
|
|
* window->waitForWindowEvent();
|
|
|
|
* }
|
|
|
|
* sched_unlock();
|
2012-03-22 22:22:59 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-09 21:31:48 +02:00
|
|
|
void waitForWindowEvent(void);
|
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
2019-05-02 22:41:53 +02:00
|
|
|
#ifdef CONFIG_NXWIDGET_EVENTWAIT
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
2012-05-09 21:31:48 +02:00
|
|
|
* Is external logic awaiting for a window event?
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
2012-05-09 21:31:48 +02:00
|
|
|
* @return True if the widget if external logic is waiting.
|
2012-03-22 22:22:59 +01:00
|
|
|
*/
|
|
|
|
|
2012-05-09 21:31:48 +02:00
|
|
|
inline const bool isWaiting(void) const
|
2012-03-22 22:22:59 +01:00
|
|
|
{
|
2012-05-09 21:31:48 +02:00
|
|
|
return m_waiting;
|
2012-03-22 22:22:59 +01:00
|
|
|
}
|
2012-05-09 21:31:48 +02:00
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run all code that needs to take place on a periodic basis.
|
2012-05-09 21:31:48 +02:00
|
|
|
* This method normally called externally... either periodically
|
|
|
|
* or when a window event is detected. If CONFIG_NXWIDGET_EVENTWAIT
|
|
|
|
* is defined, then external logic want call waitWindow event and
|
2020-02-22 19:52:12 +01:00
|
|
|
* when awakened, they should call this function. As an example:
|
2012-05-09 21:31:48 +02:00
|
|
|
*
|
|
|
|
* for (;;)
|
|
|
|
* {
|
|
|
|
* sched_lock(); // Make the sequence atomic
|
|
|
|
* if (!window->pollEvents(0))
|
|
|
|
* {
|
|
|
|
* window->waitWindowEvent();
|
|
|
|
* }
|
|
|
|
* sched_unlock();
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* This method is just a wrapper simply calls the followi.
|
|
|
|
*
|
|
|
|
* processDeleteQueue()
|
|
|
|
* pollMouseEvents(widget)
|
|
|
|
* pollKeyboardEvents()
|
|
|
|
* pollCursorControlEvents()
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
wm4Nx is a port of twm, Tab Window Manager (or Tom's Window Manager)
version 1.0.10 to NuttX NX windows server. No, a port is not the right
word. It is a re-design of TWM from the inside out to work with the NuttX
NX server. The name Twm4Nx reflects this legacy. But Twm4Nx is more a
homage to TWM than a port of TWM.
The original TWM was based on X11 which provides a rich set of features.
TWM provided titlebars, shaped windows, several forms of icon management,
user-defined macro functions, click-to-type and pointer-driven keyboard
focus, graphic contexts, and user-specified key and pointer button bindings,
etc.
Twm4Nx, on the other hand is based on the NuttX NX server which provides
comparatively minimal support. Additional drawing support comes from
the NuttX NxWidgets library (which necessitated the change to C++).
Twm4Nx is greatly stripped down and targeted on small embedded systems
with minimal resources. For example, no assumption is made about the
availability of a file system; no .twmrc file is used. Bitmaps are not
used (other than for fonts).
The TWM license is, I believe compatible with the BSD license used by NuttX.
The origin TWM license required notice of copyrights within each file and
a full copy of the original license which you can find in the COPYING file.
within this directory.
STATUS:
This port was brutal. Much TWM logic was removed because it depending on X11 features (or just because I could not understand how to use it). The logic is partial. A lot more needs to be done to have a complete system (hence, it is marked EXPERIMENTAL). The kinds of things that need to done are:
1. Update some logic that is only fragmentary for how like resizing, and menus.
2. Integrate NxWidgets into the windows: The resize menu needs a CLabel, the menus are CListBox'es, but not completely integrated, the Icon Manager needs to be a button array.
3. Resit Icons. They are windows now, but need to be compound widgets lying on the background.
4. Widget events are only partially integrated. A lot more needs to be done. A partial change to thoe event system that hints at the redesign is in place but it is far from complete.
2019-04-26 00:54:17 +02:00
|
|
|
* @param widget. Specific widget to poll. Use NULL to run through
|
|
|
|
* of the widgets in the window.
|
2012-03-22 22:22:59 +01:00
|
|
|
* @return True means some interesting event occurred
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2022-10-15 19:55:16 +02:00
|
|
|
bool pollEvents(CNxWidget *widget = NULL);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Swaps the depth of the supplied widget.
|
|
|
|
* This function presumes that all child widgets are screens.
|
|
|
|
*
|
|
|
|
* @param widget The widget to be depth-swapped.
|
|
|
|
* @return True if the depth swap occurred.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool swapWidgetDepth(CNxWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add another widget to be managed by this control instance
|
|
|
|
*
|
|
|
|
* @param widget The widget to be controlled.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
inline void addControlledWidget(CNxWidget* widget)
|
|
|
|
{
|
|
|
|
m_widgets.push_back(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a controlled widget
|
|
|
|
*
|
|
|
|
* @param widget The widget to be removed
|
|
|
|
*/
|
|
|
|
|
|
|
|
void removeControlledWidget(CNxWidget* widget);
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* Get the number of controlled widgets.
|
|
|
|
*
|
|
|
|
* @return The number of child widgets belonging to this widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline const int getControlledWidgetCount(void) const
|
|
|
|
{
|
|
|
|
return m_widgets.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a widget to the list of widgets to be deleted.
|
|
|
|
* Must never be called by anything other than the framework itself.
|
|
|
|
*
|
|
|
|
* @param widget The widget to add to the delete queue.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
void addToDeleteQueue(CNxWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the clicked widget pointer. Note that this should not be
|
|
|
|
* called by code other than within the CWidgetControl library itself.
|
|
|
|
*
|
|
|
|
* @param widget The new clicked widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setClickedWidget(CNxWidget *widget);
|
|
|
|
|
|
|
|
/**
|
2013-02-28 19:48:11 +01:00
|
|
|
* Get the clicked widget pointer.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return Pointer to the clicked widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline CNxWidget *getClickedWidget(void)
|
|
|
|
{
|
|
|
|
return m_clickedWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the focused widget that will receive keyboard input.
|
|
|
|
*
|
|
|
|
* @param widget The new focused widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void setFocusedWidget(CNxWidget *widget);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset the focused widget so that it will no longer receive keyboard input.
|
|
|
|
*
|
|
|
|
* @param widget The new focused widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void clearFocusedWidget(CNxWidget *widget)
|
|
|
|
{
|
|
|
|
if (widget == m_focusedWidget)
|
|
|
|
{
|
2022-10-15 19:55:16 +02:00
|
|
|
m_focusedWidget = NULL;
|
2012-03-22 22:22:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-28 19:48:11 +01:00
|
|
|
* Get the focused widget pointer.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return Pointer to the focused widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline CNxWidget *getFocusedWidget(void)
|
|
|
|
{
|
|
|
|
return m_focusedWidget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-28 19:48:11 +01:00
|
|
|
* Check for the occurrence of a double click.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return Pointer to the clicked widget.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline bool doubleClick(void)
|
|
|
|
{
|
2020-04-20 06:14:57 +02:00
|
|
|
#ifdef CONFIG_NX_XYINPUT
|
2014-07-17 03:20:44 +02:00
|
|
|
return (bool)m_xyinput.doubleClick;
|
2020-04-20 06:14:57 +02:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the default widget style for this window.
|
|
|
|
*
|
2012-05-13 16:36:59 +02:00
|
|
|
* @param style. The location to return the widget's style
|
2012-03-22 22:22:59 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
inline void getWidgetStyle(CWidgetStyle *style)
|
|
|
|
{
|
|
|
|
copyWidgetStyle(style, &m_style);
|
|
|
|
}
|
|
|
|
|
2012-05-13 16:36:59 +02:00
|
|
|
/**
|
|
|
|
* Set the default widget style for this window.
|
|
|
|
*
|
|
|
|
* @param style. The new widget style to copy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void setWidgetStyle(const CWidgetStyle *style)
|
|
|
|
{
|
|
|
|
copyWidgetStyle(&m_style, style);
|
|
|
|
}
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* These remaining methods are used by the CCallback instance to
|
|
|
|
* provide notifications of certain events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event will occur when the position or size of the underlying
|
|
|
|
* window occurs.
|
|
|
|
*
|
|
|
|
* @param hWindow The window handle that should be used to communicate
|
|
|
|
* with the window
|
|
|
|
* @param pos The position of the window in the physical device space.
|
|
|
|
* @param size The size of the window.
|
|
|
|
* @param bounds The size of the underlying display (pixels x rows)
|
|
|
|
*/
|
|
|
|
|
|
|
|
void geometryEvent(NXHANDLE hWindow,
|
|
|
|
const struct nxgl_size_s *size,
|
|
|
|
const struct nxgl_point_s *pos,
|
|
|
|
const struct nxgl_rect_s *bounds);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event will occur when the a portion of the window that was
|
|
|
|
* previously obscured is now exposed.
|
|
|
|
*
|
|
|
|
* @param nxRect The region in the window that must be redrawn.
|
|
|
|
* @param more True means that more re-draw requests will follow
|
|
|
|
*/
|
|
|
|
|
|
|
|
void redrawEvent(FAR const struct nxgl_rect_s *nxRect, bool more);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This event means that new mouse data is available for the window.
|
|
|
|
*
|
2012-05-07 17:05:07 +02:00
|
|
|
* @param pos The (x,y) position of the mouse.
|
2012-03-22 22:22:59 +01:00
|
|
|
* @param buttons See NX_MOUSE_* definitions.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
void newMouseEvent(FAR const struct nxgl_point_s *pos, uint8_t buttons);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
2019-05-02 22:41:53 +02:00
|
|
|
#ifdef CONFIG_NX_KBD
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* This event means that keyboard/keypad data is available for the window.
|
|
|
|
*
|
|
|
|
* @param nCh The number of characters that are available in pStr[].
|
|
|
|
* @param pStr The array of characters.
|
|
|
|
*/
|
2012-05-09 21:31:48 +02:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
void newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr);
|
2012-05-09 21:31:48 +02:00
|
|
|
#endif
|
2012-03-22 22:22:59 +01:00
|
|
|
|
2012-05-18 00:16:02 +02:00
|
|
|
/**
|
|
|
|
* This event is the response from nx_block (or nxtk_block). Those
|
|
|
|
* blocking interfaces are used to assure that no further messages are
|
|
|
|
* directed to the window. Receipt of the blocked callback signifies
|
|
|
|
* that (1) there are no further pending events and (2) that the
|
|
|
|
* window is now 'defunct' and will receive no further events.
|
|
|
|
*
|
|
|
|
* This event supports coordinated destruction of a window in multi-
|
|
|
|
* user mode. In multi-use mode, the client window logic must stay
|
|
|
|
* intact until all of the queued callbacks are processed. Then the
|
|
|
|
* window may be safely closed. Closing the window prior with pending
|
|
|
|
* callbacks can lead to bad behavior when the callback is executed.
|
|
|
|
*
|
2012-05-19 03:01:00 +02:00
|
|
|
* @param arg - User provided argument (see nx_block or nxtk_block)
|
2012-05-18 00:16:02 +02:00
|
|
|
*/
|
|
|
|
|
2012-05-19 03:01:00 +02:00
|
|
|
inline void windowBlocked(FAR void *arg)
|
2012-05-18 00:16:02 +02:00
|
|
|
{
|
2012-05-19 03:01:00 +02:00
|
|
|
m_eventHandlers.raiseBlockedEvent(arg);
|
2012-05-18 00:16:02 +02:00
|
|
|
}
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
/**
|
|
|
|
* This event means that cursor control data is available for the window.
|
|
|
|
*
|
|
|
|
* @param cursorControl The cursor control code received.
|
|
|
|
*/
|
2013-02-28 19:48:11 +01:00
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
void newCursorControlEvent(ECursorControl cursorControl);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the window handle reported on the first position callback.
|
|
|
|
*
|
|
|
|
* @return This function returns the window handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline NXHANDLE getWindowHandle(void)
|
|
|
|
{
|
2019-05-01 20:19:14 +02:00
|
|
|
// Verify that we have the window handle
|
|
|
|
|
|
|
|
if (m_hWindow == (NXHANDLE)0)
|
|
|
|
{
|
|
|
|
// The window handle is saved at the same time as the bounds
|
|
|
|
|
|
|
|
waitBoundsData();
|
|
|
|
}
|
|
|
|
|
2012-03-22 22:22:59 +01:00
|
|
|
return m_hWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-02-28 19:48:11 +01:00
|
|
|
* Get the window bounding box in physical display coordinates. This
|
|
|
|
* method may need to wait until bounds data is available.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return This function returns the window handle.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline CRect getWindowBoundingBox(void)
|
|
|
|
{
|
2013-02-28 19:48:11 +01:00
|
|
|
waitBoundsData();
|
2012-05-07 17:05:07 +02:00
|
|
|
return CRect(&m_bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void getWindowBoundingBox(FAR struct nxgl_rect_s *bounds)
|
|
|
|
{
|
2013-02-28 19:48:11 +01:00
|
|
|
waitBoundsData();
|
2012-05-07 17:05:07 +02:00
|
|
|
nxgl_rectcopy(bounds, &m_bounds);
|
2012-03-22 22:22:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-07 17:05:07 +02:00
|
|
|
* Get the position of the window (as reported by the last NX callback). This
|
|
|
|
* method may need to wait until geometry data is available.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return The position.
|
|
|
|
*/
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
inline bool getWindowPosition(FAR struct nxgl_point_s *pos)
|
2012-03-22 22:22:59 +01:00
|
|
|
{
|
2019-05-01 19:11:43 +02:00
|
|
|
// Check if we already have geometry data available. CAREFUL: This
|
|
|
|
// might refer to OLD geometry data if the position was recently
|
|
|
|
// changed!
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
waitGeoData();
|
|
|
|
pos->x = m_pos.x;
|
2012-05-07 20:19:17 +02:00
|
|
|
pos->y = m_pos.y;
|
2012-03-22 22:22:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-07 17:05:07 +02:00
|
|
|
* Get the size of the window (as reported by the last NX callback). This
|
|
|
|
* method may need to wait until geometry data is available.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return The size.
|
|
|
|
*/
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
inline bool getWindowSize(FAR struct nxgl_size_s *size)
|
2012-03-22 22:22:59 +01:00
|
|
|
{
|
2019-05-01 19:11:43 +02:00
|
|
|
// Check if we already have geometry data available. CAREFUL: This
|
|
|
|
// might refer to OLD geometry data if the position was recently
|
|
|
|
// changed!
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
waitGeoData();
|
|
|
|
size->h = m_size.h;
|
|
|
|
size->w = m_size.w;
|
2012-03-22 22:22:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-07 17:05:07 +02:00
|
|
|
* Get the width of the window (as reported by the last NX callback). This
|
|
|
|
* method may need to wait until geometry data is available.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return The size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline nxgl_coord_t getWindowWidth(void)
|
|
|
|
{
|
2019-05-01 19:11:43 +02:00
|
|
|
// Check if we already have geometry data available. CAREFUL: This
|
|
|
|
// might refer to OLD geometry data if the position was recently
|
|
|
|
// changed!
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
waitGeoData();
|
2012-03-22 22:22:59 +01:00
|
|
|
return m_size.w;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-07 17:05:07 +02:00
|
|
|
* Get the height of the window (as reported by the last NX callback). This
|
|
|
|
* method may need to wait until geometry data is available.
|
2012-03-22 22:22:59 +01:00
|
|
|
*
|
|
|
|
* @return The size.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline nxgl_coord_t getWindowHeight(void)
|
|
|
|
{
|
2019-05-01 19:11:43 +02:00
|
|
|
// Check if we already have geometry data available. CAREFUL: This
|
|
|
|
// might refer to OLD geometry data if the position was recently
|
|
|
|
// changed!
|
|
|
|
|
2012-05-07 17:05:07 +02:00
|
|
|
waitGeoData();
|
2012-03-22 22:22:59 +01:00
|
|
|
return m_size.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The creation sequence is:
|
|
|
|
*
|
|
|
|
* 1) Create a dumb CWigetControl instance
|
|
|
|
* 2) Pass the dumb CWidgetControl instance to the window constructor
|
|
|
|
* that inherits from INxWindow.
|
|
|
|
* 3) The call this method with the static_cast to INxWindow to,
|
|
|
|
* finally, create the CGraphicsPort for this window.
|
|
|
|
* 4) After that, the fully smartend CWidgetControl instance can
|
|
|
|
* be used to generate additional widgets.
|
|
|
|
*
|
|
|
|
* @param window The instance of INxWindow needed to construct the
|
|
|
|
* CGraphicsPort instance
|
|
|
|
*/
|
|
|
|
|
2012-05-07 23:25:24 +02:00
|
|
|
bool createGraphicsPort(INxWindow *window);
|
2012-03-22 22:22:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the CGraphicsPort instance for drawing on this window
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline CGraphicsPort *getGraphicsPort(void)
|
|
|
|
{
|
|
|
|
return m_port;
|
|
|
|
}
|
2012-05-09 21:31:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a window event handler. The window handler will receive
|
|
|
|
* notification all NX events received by this window\.
|
|
|
|
*
|
|
|
|
* @param eventHandler A pointer to the event handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void addWindowEventHandler(CWindowEventHandler *eventHandler)
|
|
|
|
{
|
|
|
|
m_eventHandlers.addWindowEventHandler(eventHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a window event handler.
|
|
|
|
*
|
|
|
|
* @param eventHandler A pointer to the event handler to remove.
|
|
|
|
*/
|
|
|
|
|
|
|
|
inline void removeWindowEventHandler(CWindowEventHandler *eventHandler)
|
|
|
|
{
|
2013-02-28 19:48:11 +01:00
|
|
|
m_eventHandlers.removeWindowEventHandler(eventHandler);
|
2012-05-09 21:31:48 +02:00
|
|
|
}
|
2012-03-22 22:22:59 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
2018-09-17 01:23:45 +02:00
|
|
|
#endif // __APPS_INCLUDE_GRAPHICS_NXWIDGETS_CWIDGETCONTROLT_HXX
|