NxWM: Fix detection of touch events in the tool bar; Start window should not have a stop icon
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4729 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
4b352d5052
commit
ad3d507223
@ -300,9 +300,11 @@ static bool createStartWindow(void)
|
||||
// in the start window.
|
||||
// 4. Call CTaskBar::startApplication (initially minimized) to start the start
|
||||
// window application.
|
||||
//
|
||||
// NOTE: that the start window should not have a stop button.
|
||||
|
||||
printf(MAIN_STRING "Opening the start window application window\n");
|
||||
NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow();
|
||||
NxWM::CApplicationWindow *window = g_nxwmtest.taskbar->openApplicationWindow(NxWM::CApplicationWindow::WINDOW_PERSISTENT);
|
||||
if (!window)
|
||||
{
|
||||
printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the start window\n");
|
||||
|
@ -112,7 +112,7 @@ namespace NXWidgets
|
||||
* @param widgetControl Controlling widget for this window.
|
||||
*/
|
||||
|
||||
CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl);
|
||||
CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
@ -143,10 +143,15 @@ namespace NXWidgets
|
||||
* the toolbar object AND calls the INxWindow::open() method to
|
||||
* create the toolbar. The toolbar is ready for use upon return.
|
||||
*
|
||||
* @param height. The height in rows of the tool bar
|
||||
* @param widgetControl. The controlling widget for this window. If
|
||||
* none is provided, then a new, vanilla CWidgetControl will be created
|
||||
* for the tool bar.
|
||||
* @return True if the toolbar was successfully created.
|
||||
*/
|
||||
|
||||
CNxToolbar *openToolbar(nxgl_coord_t height);
|
||||
CNxToolbar *openToolbar(nxgl_coord_t height,
|
||||
CWidgetControl *widgetControl = (CWidgetControl *)0);
|
||||
|
||||
/**
|
||||
* Detach the toolbar. This should *ONLY* be called by the toolbar
|
||||
|
@ -526,7 +526,7 @@ namespace NXWidgets
|
||||
/**
|
||||
* Get the default widget style for this window.
|
||||
*
|
||||
* @return Pointer to the clicked widget.
|
||||
* @param style. The location to return the widget's style
|
||||
*/
|
||||
|
||||
inline void getWidgetStyle(CWidgetStyle *style)
|
||||
@ -534,6 +534,17 @@ namespace NXWidgets
|
||||
copyWidgetStyle(style, &m_style);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* These remaining methods are used by the CCallback instance to
|
||||
* provide notifications of certain events.
|
||||
|
@ -66,13 +66,13 @@ using namespace NXWidgets;
|
||||
* @param widgetControl Controlling widget for this window.
|
||||
*/
|
||||
|
||||
CNxTkWindow::CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl)
|
||||
: CCallback(pWidgetControl)
|
||||
CNxTkWindow::CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl)
|
||||
: CCallback(widgetControl)
|
||||
{
|
||||
// Save construction values
|
||||
|
||||
m_hNxServer = hNxServer;
|
||||
m_widgetControl = pWidgetControl;
|
||||
m_widgetControl = widgetControl;
|
||||
|
||||
// Nullify uninitilized pointers
|
||||
|
||||
@ -138,14 +138,38 @@ CWidgetControl *CNxTkWindow::getWidgetControl(void) const
|
||||
* the toolbar object AND calls the INxWindow::open() method to
|
||||
* create the toolbar. The toolbar is ready for use upon return.
|
||||
*
|
||||
* @param height. The height in rows of the tool bar
|
||||
* @param widgetControl. The controlling widget for this window. If
|
||||
* none is provided, then a new, vanilla CWidgetControl will be created
|
||||
* for the tool bar.
|
||||
* @param height Height of the toolbar
|
||||
*/
|
||||
|
||||
CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
|
||||
CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height, CWidgetControl *widgetControl)
|
||||
{
|
||||
if (m_hNxTkWindow && !m_toolbar)
|
||||
{
|
||||
// Get current window style from the widget control
|
||||
// Create a new widget control if none was provided
|
||||
|
||||
CWidgetControl *allocControl = (CWidgetControl *)0;
|
||||
if (!widgetControl)
|
||||
{
|
||||
// NOTE: This constructor would accept the toolbar "style" as a argument.
|
||||
// However, we will explicitly set the style below to handle the case
|
||||
// where the user has provided a custom widget control
|
||||
|
||||
allocControl = new CWidgetControl();
|
||||
if (!allocControl)
|
||||
{
|
||||
return (CNxToolbar *)0;
|
||||
}
|
||||
|
||||
// Use the allocated widget control
|
||||
|
||||
widgetControl = allocControl;
|
||||
}
|
||||
|
||||
// Get current window style from the NXTK window's widget control
|
||||
|
||||
CWidgetStyle style;
|
||||
m_widgetControl->getWidgetStyle(&style);
|
||||
@ -155,9 +179,7 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
|
||||
style.colors.background = CONFIG_NXTK_BORDERCOLOR1;
|
||||
style.colors.selectedBackground = CONFIG_NXTK_BORDERCOLOR1;
|
||||
|
||||
// Create a new controlling widget for the window using these colors
|
||||
|
||||
CWidgetControl *widgetControl = new CWidgetControl(&style);
|
||||
widgetControl->setWidgetStyle(&style);
|
||||
|
||||
// And create the toolbar
|
||||
|
||||
@ -165,7 +187,10 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
|
||||
widgetControl, height);
|
||||
if (!m_toolbar)
|
||||
{
|
||||
delete widgetControl;
|
||||
if (allocControl)
|
||||
{
|
||||
delete allocControl;
|
||||
}
|
||||
return (CNxToolbar *)0;
|
||||
}
|
||||
|
||||
@ -177,7 +202,10 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
|
||||
// Failed to create the toolbar. Clean-up and return NULL
|
||||
|
||||
delete m_toolbar;
|
||||
delete widgetControl;
|
||||
if (allocControl)
|
||||
{
|
||||
delete allocControl;
|
||||
}
|
||||
return (CNxToolbar *)0;
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,16 @@ namespace NxWM
|
||||
class CApplicationWindow : public IApplicationWindow,
|
||||
private NXWidgets::CWidgetEventHandler
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Enumeration describing the bit settings for each window flag
|
||||
*/
|
||||
|
||||
enum EWindowFlags
|
||||
{
|
||||
WINDOW_PERSISTENT = 0x01 /**< Persistent windows have no stop button */
|
||||
};
|
||||
|
||||
protected:
|
||||
NXWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */
|
||||
NXWidgets::CNxToolbar *m_toolbar; /**< The toolbar */
|
||||
@ -83,6 +93,7 @@ namespace NxWM
|
||||
NXWidgets::CRlePaletteBitmap *m_stopBitmap; /**< The stop icon bitmap */
|
||||
NXWidgets::CNxFont *m_windowFont; /**< The font used to rend the window label */
|
||||
IApplicationCallback *m_callback; /**< Toolbar action callbacks */
|
||||
uint8_t m_flags; /**< Window flags */
|
||||
|
||||
/**
|
||||
* Handle a mouse button click event.
|
||||
@ -98,9 +109,10 @@ namespace NxWM
|
||||
* CApplicationWindow Constructor
|
||||
*
|
||||
* @param window. The window to be used by this application.
|
||||
* @param flags. Optional flags to control the window configuration (See EWindowFlags).
|
||||
*/
|
||||
|
||||
CApplicationWindow(NXWidgets::CNxTkWindow *window);
|
||||
CApplicationWindow(NXWidgets::CNxTkWindow *window, uint8_t flags = 0);
|
||||
|
||||
/**
|
||||
* CApplicationWindow Destructor
|
||||
@ -152,6 +164,18 @@ namespace NxWM
|
||||
|
||||
void registerCallbacks(IApplicationCallback *callback);
|
||||
|
||||
/**
|
||||
* Check if this window is configured for a persistent application (i.e.,
|
||||
* an application that has no STOP icon
|
||||
*
|
||||
* @return True if the window is configured for a persistent application.
|
||||
*/
|
||||
|
||||
inline bool isPersistent(void) const
|
||||
{
|
||||
return (m_flags & WINDOW_PERSISTENT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate a mouse click on the minimize icon. This inline method is only
|
||||
* used during automated testing of NxWM.
|
||||
|
@ -301,9 +301,11 @@ namespace NxWM
|
||||
*
|
||||
* 4. Call CTaskBar::startApplication start the application and bring its window to
|
||||
* the top.
|
||||
*
|
||||
* @param flags. CApplicationWindow flugs for window customization.
|
||||
*/
|
||||
|
||||
CApplicationWindow *openApplicationWindow(void);
|
||||
CApplicationWindow *openApplicationWindow(uint8_t flags = 0);
|
||||
|
||||
/**
|
||||
* Create a full screen application window. Creating a new full screen application
|
||||
|
@ -47,6 +47,7 @@
|
||||
|
||||
#include "nxwmconfig.hxx"
|
||||
#include "nxwmglyphs.hxx"
|
||||
#include "cwindowcontrol.hxx"
|
||||
#include "capplicationwindow.hxx"
|
||||
|
||||
/********************************************************************************************
|
||||
@ -63,13 +64,15 @@
|
||||
* CApplicationWindow Constructor
|
||||
*
|
||||
* @param taskbar. A pointer to the parent task bar instance.
|
||||
* @param flags. Optional flags to control the window configuration (See EWindowFlags).
|
||||
*/
|
||||
|
||||
CApplicationWindow::CApplicationWindow(NXWidgets::CNxTkWindow *window)
|
||||
CApplicationWindow::CApplicationWindow(NXWidgets::CNxTkWindow *window, uint8_t flags)
|
||||
{
|
||||
// Save the window for later use
|
||||
// Save the window and window flags for later use
|
||||
|
||||
m_window = window;
|
||||
m_flags = flags;
|
||||
|
||||
// These will be created with the open method is called
|
||||
|
||||
@ -150,9 +153,17 @@ CApplicationWindow::~CApplicationWindow(void)
|
||||
|
||||
bool CApplicationWindow::open(void)
|
||||
{
|
||||
// Create one of our special window controls for the tool bar
|
||||
|
||||
CWindowControl *control = new CWindowControl();
|
||||
if (!control)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Open the toolbar
|
||||
|
||||
m_toolbar = m_window->openToolbar(CONFIG_NXWM_TOOLBAR_HEIGHT);
|
||||
m_toolbar = m_window->openToolbar(CONFIG_NXWM_TOOLBAR_HEIGHT, control);
|
||||
if (!m_toolbar)
|
||||
{
|
||||
// We failed to open the toolbar
|
||||
@ -168,67 +179,67 @@ bool CApplicationWindow::open(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the CWidgetControl associated with the toolbar
|
||||
|
||||
NXWidgets::CWidgetControl *control = m_toolbar->getWidgetControl();
|
||||
if (!control)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create STOP bitmap container
|
||||
|
||||
m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&g_stopBitmap);
|
||||
if (!m_stopBitmap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the STOP application icon at the right of the toolbar
|
||||
// Start positioning icons from the right side of the tool bar
|
||||
|
||||
struct nxgl_point_s iconPos;
|
||||
struct nxgl_size_s iconSize;
|
||||
|
||||
// Get the height and width of the stop bitmap
|
||||
iconPos.x = windowSize.w;
|
||||
|
||||
iconSize.w = m_stopBitmap->getWidth();
|
||||
iconSize.h = m_stopBitmap->getHeight();
|
||||
// Create the STOP icon only if this is a non-persistent application
|
||||
|
||||
// The default CImage has borders enabled with thickness of the border
|
||||
// width. Add twice the thickness of the border to the width and height.
|
||||
// (We could let CImage do this for us by calling
|
||||
// CImage::getPreferredDimensions())
|
||||
|
||||
iconSize.w += 2 * 1;
|
||||
iconSize.h += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the image will position at the right of
|
||||
// the toolbar and centered vertically.
|
||||
|
||||
iconPos.x = windowSize.w - iconSize.w;
|
||||
|
||||
if (iconSize.h >= windowSize.h)
|
||||
if (!isPersistent())
|
||||
{
|
||||
iconPos.y = 0;
|
||||
// Create STOP bitmap container
|
||||
|
||||
m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&g_stopBitmap);
|
||||
if (!m_stopBitmap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the STOP application icon at the right of the toolbar
|
||||
// Get the height and width of the stop bitmap
|
||||
|
||||
iconSize.w = m_stopBitmap->getWidth();
|
||||
iconSize.h = m_stopBitmap->getHeight();
|
||||
|
||||
// The default CImage has borders enabled with thickness of the border
|
||||
// width. Add twice the thickness of the border to the width and height.
|
||||
// (We could let CImage do this for us by calling
|
||||
// CImage::getPreferredDimensions())
|
||||
|
||||
iconSize.w += 2 * 1;
|
||||
iconSize.h += 2 * 1;
|
||||
|
||||
// Pick an X/Y position such that the image will position at the right of
|
||||
// the toolbar and centered vertically.
|
||||
|
||||
iconPos.x -= iconSize.w;
|
||||
|
||||
if (iconSize.h >= windowSize.h)
|
||||
{
|
||||
iconPos.y = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iconPos.y = (windowSize.h - iconSize.h) >> 1;
|
||||
}
|
||||
|
||||
// Now we have enough information to create the image
|
||||
|
||||
m_stopImage = new NXWidgets::CImage(control, iconPos.x, iconPos.y, iconSize.w,
|
||||
iconSize.h, m_stopBitmap);
|
||||
if (!m_stopImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure 'this' to receive mouse click inputs from the image
|
||||
|
||||
m_stopImage->setBorderless(true);
|
||||
m_stopImage->addWidgetEventHandler(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
iconPos.y = (windowSize.h - iconSize.h) >> 1;
|
||||
}
|
||||
|
||||
// Now we have enough information to create the image
|
||||
|
||||
m_stopImage = new NXWidgets::CImage(control, iconPos.x, iconPos.y, iconSize.w,
|
||||
iconSize.h, m_stopBitmap);
|
||||
if (!m_stopImage)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Configure 'this' to receive mouse click inputs from the image
|
||||
|
||||
m_stopImage->setBorderless(true);
|
||||
m_stopImage->addWidgetEventHandler(this);
|
||||
|
||||
// Create MINIMIZE application bitmap container
|
||||
|
||||
@ -343,17 +354,23 @@ void CApplicationWindow::redraw(void)
|
||||
port->drawFilledRect(0, 0, windowSize.w, windowSize.h,
|
||||
CONFIG_NXTK_BORDERCOLOR1);
|
||||
|
||||
// Then draw the images
|
||||
// Then draw the stop image (which may not be present if this is a
|
||||
// "persistent" application)
|
||||
|
||||
m_stopImage->enableDrawing();
|
||||
m_stopImage->redraw();
|
||||
m_stopImage->setRaisesEvents(true);
|
||||
if (m_stopImage)
|
||||
{
|
||||
m_stopImage->enableDrawing();
|
||||
m_stopImage->redraw();
|
||||
m_stopImage->setRaisesEvents(true);
|
||||
}
|
||||
|
||||
// Draw the minimize image
|
||||
|
||||
m_minimizeImage->enableDrawing();
|
||||
m_minimizeImage->redraw();
|
||||
m_minimizeImage->setRaisesEvents(true);
|
||||
|
||||
// And draw the window label
|
||||
// And finally draw the window label
|
||||
|
||||
m_windowLabel->enableDrawing();
|
||||
m_windowLabel->redraw();
|
||||
@ -366,10 +383,16 @@ void CApplicationWindow::redraw(void)
|
||||
|
||||
void CApplicationWindow::hide(void)
|
||||
{
|
||||
// Disable the images
|
||||
// Disable the stop image (which may not be present if this is a
|
||||
// "persistent" application)
|
||||
|
||||
m_stopImage->disableDrawing();
|
||||
m_stopImage->setRaisesEvents(false);
|
||||
if (m_stopImage)
|
||||
{
|
||||
m_stopImage->disableDrawing();
|
||||
m_stopImage->setRaisesEvents(false);
|
||||
}
|
||||
|
||||
// Disable the minimize image
|
||||
|
||||
m_minimizeImage->disableDrawing();
|
||||
m_minimizeImage->setRaisesEvents(false);
|
||||
@ -428,7 +451,8 @@ void CApplicationWindow::clickMinimizeIcon(int index)
|
||||
|
||||
// And click the image at its center
|
||||
|
||||
m_minimizeImage->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1));
|
||||
m_minimizeImage->click(imagePos.x + (imageSize.w >> 1),
|
||||
imagePos.y + (imageSize.h >> 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -440,17 +464,23 @@ void CApplicationWindow::clickMinimizeIcon(int index)
|
||||
#if defined(CONFIG_NXWM_UNITTEST) && !defined(CONFIG_NXWM_TOUCHSCREEN)
|
||||
void CApplicationWindow::clickStopIcon(int index)
|
||||
{
|
||||
// Get the size and position of the widget
|
||||
// The stop icon will not be available for "persistent" applications
|
||||
|
||||
struct nxgl_size_s imageSize;
|
||||
m_stopImage->getSize(imageSize);
|
||||
if (m_stopImage)
|
||||
{
|
||||
// Get the size and position of the widget
|
||||
|
||||
struct nxgl_point_s imagePos;
|
||||
m_stopImage->getPos(imagePos);
|
||||
struct nxgl_size_s imageSize;
|
||||
m_stopImage->getSize(imageSize);
|
||||
|
||||
// And click the image at its center
|
||||
struct nxgl_point_s imagePos;
|
||||
m_stopImage->getPos(imagePos);
|
||||
|
||||
m_stopImage->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1));
|
||||
// And click the image at its center
|
||||
|
||||
m_stopImage->click(imagePos.x + (imageSize.w >> 1),
|
||||
imagePos.y + (imageSize.h >> 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -468,7 +498,7 @@ void CApplicationWindow::handleClickEvent(const NXWidgets::CWidgetEventArgs &e)
|
||||
{
|
||||
// Check the stop application image
|
||||
|
||||
if (m_stopImage->isClicked())
|
||||
if (m_stopImage && m_stopImage->isClicked())
|
||||
{
|
||||
// Notify the controlling logic that the application should be stopped
|
||||
|
||||
|
@ -264,9 +264,11 @@ bool CTaskbar::startWindowManager(void)
|
||||
*
|
||||
* 4. Call CTaskBar::startApplication start the application and bring its window to
|
||||
* the top.
|
||||
*
|
||||
* @param flags. CApplicationWindow flugs for window customization.
|
||||
*/
|
||||
|
||||
CApplicationWindow *CTaskbar::openApplicationWindow(void)
|
||||
CApplicationWindow *CTaskbar::openApplicationWindow(uint8_t flags)
|
||||
{
|
||||
// Get a framed window for the application
|
||||
|
||||
@ -282,7 +284,7 @@ CApplicationWindow *CTaskbar::openApplicationWindow(void)
|
||||
|
||||
// Use this window to instantiate the application window
|
||||
|
||||
CApplicationWindow *appWindow = new CApplicationWindow(window);
|
||||
CApplicationWindow *appWindow = new CApplicationWindow(window, flags);
|
||||
if (!appWindow)
|
||||
{
|
||||
delete window;
|
||||
|
Loading…
Reference in New Issue
Block a user