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:
patacongo 2012-05-13 14:36:59 +00:00
parent 4b352d5052
commit ad3d507223
8 changed files with 195 additions and 91 deletions

View File

@ -300,9 +300,11 @@ static bool createStartWindow(void)
// in the start window. // in the start window.
// 4. Call CTaskBar::startApplication (initially minimized) to start the start // 4. Call CTaskBar::startApplication (initially minimized) to start the start
// window application. // window application.
//
// NOTE: that the start window should not have a stop button.
printf(MAIN_STRING "Opening the start window application window\n"); 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) if (!window)
{ {
printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the start window\n"); printf(MAIN_STRING "ERROR: Failed to create CApplicationWindow for the start window\n");

View File

@ -112,7 +112,7 @@ namespace NXWidgets
* @param widgetControl Controlling widget for this window. * @param widgetControl Controlling widget for this window.
*/ */
CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl); CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl);
/** /**
* Destructor. * Destructor.
@ -143,10 +143,15 @@ namespace NXWidgets
* the toolbar object AND calls the INxWindow::open() method to * the toolbar object AND calls the INxWindow::open() method to
* create the toolbar. The toolbar is ready for use upon return. * 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. * @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 * Detach the toolbar. This should *ONLY* be called by the toolbar

View File

@ -526,7 +526,7 @@ namespace NXWidgets
/** /**
* Get the default widget style for this window. * 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) inline void getWidgetStyle(CWidgetStyle *style)
@ -534,6 +534,17 @@ namespace NXWidgets
copyWidgetStyle(style, &m_style); 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 * These remaining methods are used by the CCallback instance to
* provide notifications of certain events. * provide notifications of certain events.

View File

@ -66,13 +66,13 @@ using namespace NXWidgets;
* @param widgetControl Controlling widget for this window. * @param widgetControl Controlling widget for this window.
*/ */
CNxTkWindow::CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *pWidgetControl) CNxTkWindow::CNxTkWindow(NXHANDLE hNxServer, CWidgetControl *widgetControl)
: CCallback(pWidgetControl) : CCallback(widgetControl)
{ {
// Save construction values // Save construction values
m_hNxServer = hNxServer; m_hNxServer = hNxServer;
m_widgetControl = pWidgetControl; m_widgetControl = widgetControl;
// Nullify uninitilized pointers // Nullify uninitilized pointers
@ -138,14 +138,38 @@ CWidgetControl *CNxTkWindow::getWidgetControl(void) const
* the toolbar object AND calls the INxWindow::open() method to * the toolbar object AND calls the INxWindow::open() method to
* create the toolbar. The toolbar is ready for use upon return. * 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 * @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) 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; CWidgetStyle style;
m_widgetControl->getWidgetStyle(&style); m_widgetControl->getWidgetStyle(&style);
@ -155,9 +179,7 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
style.colors.background = CONFIG_NXTK_BORDERCOLOR1; style.colors.background = CONFIG_NXTK_BORDERCOLOR1;
style.colors.selectedBackground = CONFIG_NXTK_BORDERCOLOR1; style.colors.selectedBackground = CONFIG_NXTK_BORDERCOLOR1;
// Create a new controlling widget for the window using these colors widgetControl->setWidgetStyle(&style);
CWidgetControl *widgetControl = new CWidgetControl(&style);
// And create the toolbar // And create the toolbar
@ -165,7 +187,10 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
widgetControl, height); widgetControl, height);
if (!m_toolbar) if (!m_toolbar)
{ {
delete widgetControl; if (allocControl)
{
delete allocControl;
}
return (CNxToolbar *)0; return (CNxToolbar *)0;
} }
@ -177,7 +202,10 @@ CNxToolbar *CNxTkWindow::openToolbar(nxgl_coord_t height)
// Failed to create the toolbar. Clean-up and return NULL // Failed to create the toolbar. Clean-up and return NULL
delete m_toolbar; delete m_toolbar;
delete widgetControl; if (allocControl)
{
delete allocControl;
}
return (CNxToolbar *)0; return (CNxToolbar *)0;
} }

View File

@ -73,6 +73,16 @@ namespace NxWM
class CApplicationWindow : public IApplicationWindow, class CApplicationWindow : public IApplicationWindow,
private NXWidgets::CWidgetEventHandler 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: protected:
NXWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */ NXWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */
NXWidgets::CNxToolbar *m_toolbar; /**< The toolbar */ NXWidgets::CNxToolbar *m_toolbar; /**< The toolbar */
@ -83,6 +93,7 @@ namespace NxWM
NXWidgets::CRlePaletteBitmap *m_stopBitmap; /**< The stop icon bitmap */ NXWidgets::CRlePaletteBitmap *m_stopBitmap; /**< The stop icon bitmap */
NXWidgets::CNxFont *m_windowFont; /**< The font used to rend the window label */ NXWidgets::CNxFont *m_windowFont; /**< The font used to rend the window label */
IApplicationCallback *m_callback; /**< Toolbar action callbacks */ IApplicationCallback *m_callback; /**< Toolbar action callbacks */
uint8_t m_flags; /**< Window flags */
/** /**
* Handle a mouse button click event. * Handle a mouse button click event.
@ -98,9 +109,10 @@ namespace NxWM
* CApplicationWindow Constructor * CApplicationWindow Constructor
* *
* @param window. The window to be used by this application. * @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 * CApplicationWindow Destructor
@ -152,6 +164,18 @@ namespace NxWM
void registerCallbacks(IApplicationCallback *callback); 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 * Simulate a mouse click on the minimize icon. This inline method is only
* used during automated testing of NxWM. * used during automated testing of NxWM.

View File

@ -301,9 +301,11 @@ namespace NxWM
* *
* 4. Call CTaskBar::startApplication start the application and bring its window to * 4. Call CTaskBar::startApplication start the application and bring its window to
* the top. * 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 * Create a full screen application window. Creating a new full screen application

View File

@ -47,6 +47,7 @@
#include "nxwmconfig.hxx" #include "nxwmconfig.hxx"
#include "nxwmglyphs.hxx" #include "nxwmglyphs.hxx"
#include "cwindowcontrol.hxx"
#include "capplicationwindow.hxx" #include "capplicationwindow.hxx"
/******************************************************************************************** /********************************************************************************************
@ -63,13 +64,15 @@
* CApplicationWindow Constructor * CApplicationWindow Constructor
* *
* @param taskbar. A pointer to the parent task bar instance. * @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_window = window;
m_flags = flags;
// These will be created with the open method is called // These will be created with the open method is called
@ -150,9 +153,17 @@ CApplicationWindow::~CApplicationWindow(void)
bool CApplicationWindow::open(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 // 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) if (!m_toolbar)
{ {
// We failed to open the toolbar // We failed to open the toolbar
@ -168,14 +179,17 @@ bool CApplicationWindow::open(void)
return false; return false;
} }
// Get the CWidgetControl associated with the toolbar // Start positioning icons from the right side of the tool bar
NXWidgets::CWidgetControl *control = m_toolbar->getWidgetControl(); struct nxgl_point_s iconPos;
if (!control) struct nxgl_size_s iconSize;
iconPos.x = windowSize.w;
// Create the STOP icon only if this is a non-persistent application
if (!isPersistent())
{ {
return false;
}
// Create STOP bitmap container // Create STOP bitmap container
m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&g_stopBitmap); m_stopBitmap = new NXWidgets::CRlePaletteBitmap(&g_stopBitmap);
@ -185,10 +199,6 @@ bool CApplicationWindow::open(void)
} }
// Create the STOP application icon at the right of the toolbar // Create the STOP application icon at the right of the toolbar
struct nxgl_point_s iconPos;
struct nxgl_size_s iconSize;
// Get the height and width of the stop bitmap // Get the height and width of the stop bitmap
iconSize.w = m_stopBitmap->getWidth(); iconSize.w = m_stopBitmap->getWidth();
@ -205,7 +215,7 @@ bool CApplicationWindow::open(void)
// Pick an X/Y position such that the image will position at the right of // Pick an X/Y position such that the image will position at the right of
// the toolbar and centered vertically. // the toolbar and centered vertically.
iconPos.x = windowSize.w - iconSize.w; iconPos.x -= iconSize.w;
if (iconSize.h >= windowSize.h) if (iconSize.h >= windowSize.h)
{ {
@ -229,6 +239,7 @@ bool CApplicationWindow::open(void)
m_stopImage->setBorderless(true); m_stopImage->setBorderless(true);
m_stopImage->addWidgetEventHandler(this); m_stopImage->addWidgetEventHandler(this);
}
// Create MINIMIZE application bitmap container // Create MINIMIZE application bitmap container
@ -343,17 +354,23 @@ void CApplicationWindow::redraw(void)
port->drawFilledRect(0, 0, windowSize.w, windowSize.h, port->drawFilledRect(0, 0, windowSize.w, windowSize.h,
CONFIG_NXTK_BORDERCOLOR1); CONFIG_NXTK_BORDERCOLOR1);
// Then draw the images // Then draw the stop image (which may not be present if this is a
// "persistent" application)
if (m_stopImage)
{
m_stopImage->enableDrawing(); m_stopImage->enableDrawing();
m_stopImage->redraw(); m_stopImage->redraw();
m_stopImage->setRaisesEvents(true); m_stopImage->setRaisesEvents(true);
}
// Draw the minimize image
m_minimizeImage->enableDrawing(); m_minimizeImage->enableDrawing();
m_minimizeImage->redraw(); m_minimizeImage->redraw();
m_minimizeImage->setRaisesEvents(true); m_minimizeImage->setRaisesEvents(true);
// And draw the window label // And finally draw the window label
m_windowLabel->enableDrawing(); m_windowLabel->enableDrawing();
m_windowLabel->redraw(); m_windowLabel->redraw();
@ -366,10 +383,16 @@ void CApplicationWindow::redraw(void)
void CApplicationWindow::hide(void) void CApplicationWindow::hide(void)
{ {
// Disable the images // Disable the stop image (which may not be present if this is a
// "persistent" application)
if (m_stopImage)
{
m_stopImage->disableDrawing(); m_stopImage->disableDrawing();
m_stopImage->setRaisesEvents(false); m_stopImage->setRaisesEvents(false);
}
// Disable the minimize image
m_minimizeImage->disableDrawing(); m_minimizeImage->disableDrawing();
m_minimizeImage->setRaisesEvents(false); m_minimizeImage->setRaisesEvents(false);
@ -428,7 +451,8 @@ void CApplicationWindow::clickMinimizeIcon(int index)
// And click the image at its center // 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 #endif
@ -439,6 +463,10 @@ void CApplicationWindow::clickMinimizeIcon(int index)
#if defined(CONFIG_NXWM_UNITTEST) && !defined(CONFIG_NXWM_TOUCHSCREEN) #if defined(CONFIG_NXWM_UNITTEST) && !defined(CONFIG_NXWM_TOUCHSCREEN)
void CApplicationWindow::clickStopIcon(int index) void CApplicationWindow::clickStopIcon(int index)
{
// The stop icon will not be available for "persistent" applications
if (m_stopImage)
{ {
// Get the size and position of the widget // Get the size and position of the widget
@ -450,7 +478,9 @@ void CApplicationWindow::clickStopIcon(int index)
// And click the image at its center // And click the image at its center
m_stopImage->click(imagePos.x + (imageSize.w >> 1), imagePos.y + (imageSize.h >> 1)); m_stopImage->click(imagePos.x + (imageSize.w >> 1),
imagePos.y + (imageSize.h >> 1));
}
} }
#endif #endif
@ -468,7 +498,7 @@ void CApplicationWindow::handleClickEvent(const NXWidgets::CWidgetEventArgs &e)
{ {
// Check the stop application image // 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 // Notify the controlling logic that the application should be stopped

View File

@ -264,9 +264,11 @@ bool CTaskbar::startWindowManager(void)
* *
* 4. Call CTaskBar::startApplication start the application and bring its window to * 4. Call CTaskBar::startApplication start the application and bring its window to
* the top. * 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 // Get a framed window for the application
@ -282,7 +284,7 @@ CApplicationWindow *CTaskbar::openApplicationWindow(void)
// Use this window to instantiate the application window // Use this window to instantiate the application window
CApplicationWindow *appWindow = new CApplicationWindow(window); CApplicationWindow *appWindow = new CApplicationWindow(window, flags);
if (!appWindow) if (!appWindow)
{ {
delete window; delete window;