From a63f8bb684d01a23bfe1ee85b1d7faf983b9d1ea Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 28 Feb 2013 18:48:11 +0000 Subject: NxWidgets/NxWM updates from Petteri Aimonen (Patches 0007-0013) git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5689 42af7a65-404d-4744-a932-0658087f49c3 --- NxWidgets/libnxwidgets/include/cimage.hxx | 8 ++- NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx | 71 +++++++++++++++++------ NxWidgets/libnxwidgets/src/cimage.cxx | 27 +++++---- NxWidgets/libnxwidgets/src/cmultilinetextbox.cxx | 4 +- NxWidgets/libnxwidgets/src/cnxtimer.cxx | 8 +-- NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx | 46 ++++++++++----- 6 files changed, 115 insertions(+), 49 deletions(-) (limited to 'NxWidgets/libnxwidgets') diff --git a/NxWidgets/libnxwidgets/include/cimage.hxx b/NxWidgets/libnxwidgets/include/cimage.hxx index 6093c5f33..438ea7267 100644 --- a/NxWidgets/libnxwidgets/include/cimage.hxx +++ b/NxWidgets/libnxwidgets/include/cimage.hxx @@ -1,7 +1,7 @@ /**************************************************************************** * NxWidgets/libnxwidgets/include/cimage.hxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -207,6 +207,12 @@ namespace NXWidgets inline FAR IBitmap *getBitmap() const { return m_bitmap; } + /** + * Set the bitmap that this image contains. + */ + + inline void setBitmap(FAR IBitmap *bitmap) { m_bitmap = bitmap; } + /** * Insert the dimensions that this widget wants to have into the rect * passed in as a parameter. All coordinates are relative to the diff --git a/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx index e709271a0..f0afe2c47 100644 --- a/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx +++ b/NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx @@ -1,7 +1,7 @@ /**************************************************************************** * NxWidgets/libnxwidgets/include/cwidgetcontrol.hxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,11 +39,12 @@ /**************************************************************************** * Included Files ****************************************************************************/ - + #include #include #include +#include #include #include @@ -203,6 +204,7 @@ namespace NXWidgets struct nxgl_rect_s m_bounds; /**< Size of the display */ #ifdef CONFIG_NX_MULTIUSER sem_t m_geoSem; /**< Posted when geometry is valid */ + sem_t m_boundsSem; /**< Posted when bounds are valid */ #endif CWindowEventHandlerList m_eventHandlers; /**< List of event handlers. */ @@ -228,7 +230,7 @@ namespace NXWidgets * @param startTime A time in the past from which to compute the elapsed time. * @return The elapsed time since startTime */ - + uint32_t elapsedTime(FAR const struct timespec *startTime); /** @@ -256,7 +258,7 @@ namespace NXWidgets /** * Delete any widgets in the deletion queue. */ - + void processDeleteQueue(void); /** @@ -324,6 +326,37 @@ namespace NXWidgets giveGeoSem(); } + /** + * Take the bounds semaphore (handling signal interruptions) + */ + +#ifdef CONFIG_NX_MULTIUSER + void takeBoundsSem(void); +#else + inline void takeBoundsSem(void) {} +#endif + + /** + * Give the bounds semaphore + */ + + inline void giveBoundsSem(void) + { +#ifdef CONFIG_NX_MULTIUSER + sem_post(&m_boundsSem); +#endif + } + + /** + * Wait for bounds data + */ + + inline void waitBoundsData(void) + { + takeBoundsSem(); + giveBoundsSem(); + } + /** * Clear all mouse events */ @@ -345,7 +378,7 @@ namespace NXWidgets /** * Destructor. */ - + virtual ~CWidgetControl(void); /** @@ -407,7 +440,7 @@ namespace NXWidgets * all widgets in the window. * @return True means some interesting event occurred */ - + bool pollEvents(CNxWidget *widget = (CNxWidget *)NULL); /** @@ -425,7 +458,7 @@ namespace NXWidgets * * @param widget The widget to be controlled. */ - + inline void addControlledWidget(CNxWidget* widget) { m_widgets.push_back(widget); @@ -438,7 +471,7 @@ namespace NXWidgets */ void removeControlledWidget(CNxWidget* widget); - + /** * Get the number of controlled widgets. * @@ -456,7 +489,7 @@ namespace NXWidgets * * @param widget The widget to add to the delete queue. */ - + void addToDeleteQueue(CNxWidget *widget); /** @@ -469,7 +502,7 @@ namespace NXWidgets void setClickedWidget(CNxWidget *widget); /** - * Get the clicked widget pointer. + * Get the clicked widget pointer. * * @return Pointer to the clicked widget. */ @@ -502,7 +535,7 @@ namespace NXWidgets } /** - * Get the focused widget pointer. + * Get the focused widget pointer. * * @return Pointer to the focused widget. */ @@ -513,7 +546,7 @@ namespace NXWidgets } /** - * Check for the occurrence of a double click. + * Check for the occurrence of a double click. * * @return Pointer to the clicked widget. */ @@ -582,7 +615,7 @@ namespace NXWidgets * @param pos The (x,y) position of the mouse. * @param buttons See NX_MOUSE_* definitions. */ - + void newMouseEvent(FAR const struct nxgl_point_s *pos, uint8_t buttons); /** @@ -624,7 +657,7 @@ namespace NXWidgets * * @param cursorControl The cursor control code received. */ - + void newCursorControlEvent(ECursorControl cursorControl); /** @@ -639,21 +672,21 @@ namespace NXWidgets } /** - * Get the window bounding box in physical display coordinated. This - * method may need to wait until geometry data is available. + * Get the window bounding box in physical display coordinates. This + * method may need to wait until bounds data is available. * * @return This function returns the window handle. */ inline CRect getWindowBoundingBox(void) { - waitGeoData(); + waitBoundsData(); return CRect(&m_bounds); } inline void getWindowBoundingBox(FAR struct nxgl_rect_s *bounds) { - waitGeoData(); + waitBoundsData(); nxgl_rectcopy(bounds, &m_bounds); } @@ -759,7 +792,7 @@ namespace NXWidgets inline void removeWindowEventHandler(CWindowEventHandler *eventHandler) { - m_eventHandlers.removeWindowEventHandler(eventHandler); + m_eventHandlers.removeWindowEventHandler(eventHandler); } }; } diff --git a/NxWidgets/libnxwidgets/src/cimage.cxx b/NxWidgets/libnxwidgets/src/cimage.cxx index 30bf7e78b..9b3137129 100644 --- a/NxWidgets/libnxwidgets/src/cimage.cxx +++ b/NxWidgets/libnxwidgets/src/cimage.cxx @@ -1,7 +1,7 @@ /**************************************************************************** * NxWidgets/libnxwidgets/include/cimage.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -88,7 +88,7 @@ /**************************************************************************** * Pre-Processor Definitions ****************************************************************************/ - + /**************************************************************************** * Method Implementations ****************************************************************************/ @@ -163,6 +163,13 @@ void CImage::getPreferredDimensions(CRect &rect) const void CImage::drawContents(CGraphicsPort *port) { + if (!m_bitmap) + { + // No image to draw + + return; + } + // Get the the drawable region CRect rect; @@ -187,11 +194,11 @@ void CImage::drawContents(CGraphicsPort *port) m_bitmap->setSelected(isClicked() || m_highlighted); // This is the number of rows that we can draw at the top of the display - + nxgl_coord_t nTopRows = m_bitmap->getHeight() - m_origin.y; if (nTopRows > rect.getHeight()) { - nTopRows = rect.getHeight(); + nTopRows = rect.getHeight(); } else if (nTopRows < 0) { @@ -214,7 +221,7 @@ void CImage::drawContents(CGraphicsPort *port) // the display nxgl_coord_t nLeftPixels = m_bitmap->getWidth() - m_origin.x; - + // This is the number of rows that we have to pad on the right if the display // width is wider than the image width @@ -257,7 +264,7 @@ void CImage::drawContents(CGraphicsPort *port) // Replace any transparent pixels with the background color. // Then we can use the faster opaque drawBitmap() function. - + ptr = buffer; for (int i = 0; i < nLeftPixels; i++, ptr++) { @@ -337,12 +344,12 @@ void CImage::drawBorder(CGraphicsPort *port) { return; } - + // Work out which colors to use nxgl_coord_t color1; nxgl_coord_t color2; - + if (isClicked()) { // Bevelled into the screen @@ -357,7 +364,7 @@ void CImage::drawBorder(CGraphicsPort *port) color1 = getShineEdgeColor(); color2 = getShadowEdgeColor(); } - + port->drawBevelledRect(getX(), getY(), getWidth(), getHeight(), color1, color2); } @@ -389,7 +396,7 @@ void CImage::onClick(nxgl_coord_t x, nxgl_coord_t y) } /** - * Raises an action. + * Raises an action. * * @param x The x coordinate of the mouse. * @param y The y coordinate of the mouse. diff --git a/NxWidgets/libnxwidgets/src/cmultilinetextbox.cxx b/NxWidgets/libnxwidgets/src/cmultilinetextbox.cxx index 94caac5fd..df060f037 100644 --- a/NxWidgets/libnxwidgets/src/cmultilinetextbox.cxx +++ b/NxWidgets/libnxwidgets/src/cmultilinetextbox.cxx @@ -1261,8 +1261,8 @@ void CMultiLineTextBox::drawRow(CGraphicsPort *port, int row) uint8_t rowLength = m_text->getLineTrimmedLength(row); struct nxgl_point_s pos; - pos.x = getRowX(row) + m_canvasX; - pos.y = getRowY(row) + m_canvasY; + pos.x = getRowX(row) + m_canvasX + rect.getX(); + pos.y = getRowY(row) + m_canvasY + rect.getY(); // Determine the background and text color diff --git a/NxWidgets/libnxwidgets/src/cnxtimer.cxx b/NxWidgets/libnxwidgets/src/cnxtimer.cxx index d663df036..d67cee6e8 100644 --- a/NxWidgets/libnxwidgets/src/cnxtimer.cxx +++ b/NxWidgets/libnxwidgets/src/cnxtimer.cxx @@ -193,16 +193,16 @@ void CNxTimer::workQueueCallback(FAR void *arg) This->m_isRunning = false; - // Raise the action event. - - This->m_widgetEventHandlers->raiseActionEvent(); - // Restart the timer if this is a repeating timer if (This->m_isRepeater) { This->start(); } + + // Raise the action event. + + This->m_widgetEventHandlers->raiseActionEvent(); } diff --git a/NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx b/NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx index 644abd714..2cb1a930d 100644 --- a/NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx +++ b/NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx @@ -1,7 +1,7 @@ /**************************************************************************** * NxWidgets/libnxwidgets/src/cwidgetcontrol.cxx * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -117,6 +117,7 @@ CWidgetControl::CWidgetControl(FAR const CWidgetStyle *style) sem_init(&m_waitSem, 0, 0); #endif #ifdef CONFIG_NX_MULTIUSER + sem_init(&m_boundsSem, 0, 0); sem_init(&m_geoSem, 0, 0); #endif @@ -135,12 +136,11 @@ CWidgetControl::CWidgetControl(FAR const CWidgetStyle *style) copyWidgetStyle(&m_style, style); } } - /** * Destructor. */ - + CWidgetControl::~CWidgetControl(void) { // Notify any external waiters... this should not happen because it @@ -235,7 +235,7 @@ void CWidgetControl::postWindowEvent(void) * all widgets in the window. * @return True means some interesting event occurred */ - + bool CWidgetControl::pollEvents(CNxWidget *widget) { // Delete any queued widgets @@ -299,7 +299,7 @@ void CWidgetControl::removeControlledWidget(CNxWidget *widget) * * @param widget The widget to add to the delete queue. */ - + void CWidgetControl::addToDeleteQueue(CNxWidget *widget) { // Add the widget to the delete queue @@ -330,7 +330,7 @@ void CWidgetControl::setClickedWidget(CNxWidget *widget) m_clickedWidget->release(m_clickedWidget->getX() - 10, 0); } - + // Update the pointer m_clickedWidget = widget; @@ -394,18 +394,19 @@ void CWidgetControl::geometryEvent(NXHANDLE hWindow, if (!m_hWindow) { // Save one-time server specific information - + m_hWindow = hWindow; nxgl_rectcopy(&m_bounds, bounds); + giveBoundsSem(); } // In the normal start up sequence, the window is created with zero size // at position 0,0. The safe thing to do is to set the position (still // with size 0, then then set the size. Assuming that is what is being // done, we will not report that we have valid geometry until the size - // becomes nonzero. + // becomes nonzero (or actually over 1). - if (!m_haveGeometry && size->h > 0 && size->w > 0) + if (!m_haveGeometry && size->h > 1 && size->w > 1) { // Wake up any threads waiting for initial position information. // REVISIT: If the window is moved or repositioned, then the @@ -619,7 +620,7 @@ void CWidgetControl::newKeyboardEvent(uint8_t nCh, FAR const uint8_t *pStr) * * @param cursorControl The cursor control code received. */ - + void CWidgetControl::newCursorControlEvent(ECursorControl cursorControl) { // Append the new cursor control @@ -688,7 +689,7 @@ void CWidgetControl::copyWidgetStyle(CWidgetStyle *dest, const CWidgetStyle *src * @param tp A time in the past from which to compute the elapsed time. * @return The elapsed time since tp */ - + uint32_t CWidgetControl::elapsedTime(FAR const struct timespec *startTime) { struct timespec endTime; @@ -701,7 +702,7 @@ uint32_t CWidgetControl::elapsedTime(FAR const struct timespec *startTime) uint32_t seconds = endTime.tv_sec - startTime->tv_sec; // Get the elapsed nanoseconds, borrowing from the seconds if necessary - + int32_t endNanoSeconds = endTime.tv_nsec; if (startTime->tv_nsec > endNanoSeconds) { @@ -767,7 +768,7 @@ void CWidgetControl::handleLeftClick(nxgl_coord_t x, nxgl_coord_t y, CNxWidget * /** * Delete any widgets in the deletion queue. */ - + void CWidgetControl::processDeleteQueue(void) { int i = 0; @@ -916,6 +917,25 @@ void CWidgetControl::takeGeoSem(void) } #endif +/** + * Take the bounds semaphore (handling signal interruptions) + */ + +#ifdef CONFIG_NX_MULTIUSER +void CWidgetControl::takeBoundsSem(void) +{ + // Take the bounds semaphore. Retry is an error occurs (only if + // the error is due to a signal interruption). + + int ret; + do + { + ret = sem_wait(&m_boundsSem); + } + while (ret < 0 && errno == EINTR); +} +#endif + /** * Clear all mouse events */ -- cgit v1.2.3