summaryrefslogtreecommitdiff
path: root/NxWidgets
diff options
context:
space:
mode:
Diffstat (limited to 'NxWidgets')
-rw-r--r--NxWidgets/nxwm/include/capplicationwindow.hxx34
-rw-r--r--NxWidgets/nxwm/include/nxwmconfig.hxx28
-rw-r--r--NxWidgets/nxwm/src/capplicationwindow.cxx233
3 files changed, 277 insertions, 18 deletions
diff --git a/NxWidgets/nxwm/include/capplicationwindow.hxx b/NxWidgets/nxwm/include/capplicationwindow.hxx
index 6f802ebe5..607538e12 100644
--- a/NxWidgets/nxwm/include/capplicationwindow.hxx
+++ b/NxWidgets/nxwm/include/capplicationwindow.hxx
@@ -88,11 +88,24 @@ namespace NxWM
class CApplicationWindow : public INxApplication
{
protected:
- NxWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */
- NxWidgets::CNxToolbar *m_toolbar; /**< The toolbar */
- NxWidgets::CImage *m_minimize; /**< The minimize icon */
- NxWidgets::CImage *m_close; /**< The close icon */
- IApplicationCallback *m_callback; /**< Toolbar action callbacks */
+ NxWidgets::CNxTkWindow *m_window; /**< The framed window used by the application */
+ NxWidgets::CNxToolbar *m_toolbar; /**< The toolbar */
+ NxWidgets::CImage *m_minimizeImage; /**< The minimize icon */
+ NxWidgets::CImage *m_stopImage; /**< The close icon */
+ NxWidgets::CLabel *m_windowLabel; /**< The window title */
+ NxWidgets::CRlePaletteBitmap *m_minimizeBitmap; /**< The minimize icon bitmap */
+ NxWidgets::CRlePaletteBitmap *m_stopBitmap; /**< The stop icon bitmap */
+ NxWidgets::CRlePaletteBitmap *m_minimizeBitmap; /**< The minimize icon bitmap */
+ NxWidgets::CNxFont *m_windowFont; /**< The font used to rend the window label */
+ IApplicationCallback *m_callback; /**< Toolbar action callbacks */
+
+ /**
+ * Configure the standard application toolbar
+ *
+ * @return True if the toolcar was successfully initialized.
+ */
+
+ bool configureToolbar(void);
/**
* CNxApplicationWindow Destructor
@@ -132,6 +145,17 @@ namespace NxWM
}
/**
+ * Set the window label
+ *
+ * @param appname. The name of the application to place on the window
+ */
+
+ inline void setWindowLabel(NxWidgets::CNxString &appname)
+ {
+ m_windowLabel->setText(appname);
+ }
+
+ /**
* Register to receive callbacks when toolbar icons are selected
*/
diff --git a/NxWidgets/nxwm/include/nxwmconfig.hxx b/NxWidgets/nxwm/include/nxwmconfig.hxx
index e5a85ac5a..1400d41a4 100644
--- a/NxWidgets/nxwm/include/nxwmconfig.hxx
+++ b/NxWidgets/nxwm/include/nxwmconfig.hxx
@@ -56,13 +56,21 @@
# warning "NX multi-user support is required (CONFIG_NX_MULTIUSER)"
#endif
+/**
+ * Default font ID
+ */
+
+#ifndef CONFIG_NXWM_DEFAULT_FONTID
+# define CONFIG_NXWM_DEFAULT_FONTID NXFONT_DEFAULT
+#endif
+
/* Colors *******************************************************************/
/**
* Normal background color
*/
#ifndef CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR
-# define CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR CONFIG_NXWIDGETS_DEFAULT_BACKGROUNDCOLOR
+# define CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR CONFIG_NXWM_DEFAULT_BACKGROUNDCOLOR
#endif
/**
@@ -70,7 +78,7 @@
*/
#ifndef CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR
-# define CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR CONFIG_NXWIDGETS_DEFAULT_SELECTEDBACKGROUNDCOLOR
+# define CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR CONFIG_NXWM_DEFAULT_SELECTEDBACKGROUNDCOLOR
#endif
/**
@@ -89,6 +97,22 @@
# define CONFIG_NXWM_DEFAULT_SELECTEDFOREGROUNDCOLOR MKRGB(248,248,248)
#endif
+/**
+ * The default font color
+ */
+
+#ifndef CONFIG_NXWM_DEFAULT_FONTCOLOR
+# define CONFIG_NXWM_DEFAULT_FONTCOLOR MKRGB(255,255,255)
+#endif
+
+/**
+ * The transparent color
+ */
+
+#ifndef CONFIG_NXWM_TRANSPARENT_COLOR
+# define CONFIG_NXWM_TRANSPARENT_COLOR MKRGB(0,0,0)
+#endif
+
/* Task Bar Configuation ***************************************************/
/* At present, all icons are 25 pixels in "widgth" and, hence require a
* task bar of at least that size.
diff --git a/NxWidgets/nxwm/src/capplicationwindow.cxx b/NxWidgets/nxwm/src/capplicationwindow.cxx
index 0c5c9791f..6ffb1dd53 100644
--- a/NxWidgets/nxwm/src/capplicationwindow.cxx
+++ b/NxWidgets/nxwm/src/capplicationwindow.cxx
@@ -40,6 +40,7 @@
#include <nuttx/config.h>
#include "nxwmconfig.hxx"
+#include "nxwmglyphs.hxx"
#include "cappliationwinow.hxx"
/********************************************************************************************
@@ -61,11 +62,26 @@
CNxApplicationWindow::CNxApplicationWindow(NxWidgets::CNxTkWindow *window);
{
- m_window = (NxWidgets::CNxTkWindow *)0;
- m_toolbar = (NxWidgets::CNxToolbar *)0;
- m_minimize = (NxWidgets::CImage *)0;
- m_close = (NxWidgets::CImage *)0;
- m_callback = (IApplicationCallback *)0;
+ // Save the window for later use
+
+ m_window = window;
+
+ // These will be created with the open method is called
+
+ m_toolbar = (NxWidgets::CNxToolbar *)0;
+
+ m_minimizeImage = (NxWidgets::CImage *)0;
+ m_stopImage = (NxWidgets::CImage *)0;
+ m_windowLabel = (NxWidgets::CLabel *)0;
+
+ m_minimizeBitmap = (NxWidgets::CRlePaletteBitmap *)0;
+ m_stopBitmap = (NxWidgets::CRlePaletteBitmap *)0;
+
+ m_windowFont = (NxWidgets::CNxFont *)0;
+
+ // This will be initialized when the registerCallbacks() method is called
+
+ m_callback = (IApplicationCallback *)0;
}
/**
@@ -76,19 +92,39 @@ CNxApplicationWindow::~CNxApplicationWindow(void)
{
// Free the resources that we are responsible for
- if (m_toolbar)
+ if (m_minimizeImage)
{
- delete m_toolbar;
+ delete m_minimizeImage;
+ }
+
+ if (m_stopImage)
+ {
+ delete m_stopImage;
}
- if (m_minimize)
+ if (m_windowLabel)
{
- delete m_minimize;
+ delete m_windowLabel;
}
- if (m_close)
+ if (m_minimizeBitmap)
{
- delete m_close;
+ delete m_minimizeBitmap;
+ }
+
+ if (m_stopBitmap)
+ {
+ delete m_stopBitmap;
+ }
+
+ if (m_windowFont)
+ {
+ delete m_windowFont;
+ }
+
+ if (m_toolbar)
+ {
+ delete m_toolbar;
}
// We didn't create the window. That was done by the task bar,
@@ -109,7 +145,182 @@ CNxApplicationWindow::~CNxApplicationWindow(void)
bool CNxApplicationWindow::open(void)
{
+ /* Configure the toolbar */
+
+ if (!configureToolbar())
+ {
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Configure the standard application toolbar
+ *
+ * @return True if the toolcar was successfully initialized.
+ */
+
+bool configureToolbar(void)
+{
+ // Open the toolbar
+
+ m_toolbar = m_window->openToolbar();
+ if (!m_toolbar)
+ {
+ // We failed to open the toolbar
+
+ return false;
+ }
+
+ // Get the width of the display
+
+ struct nxgl_size_s windowSize;
+ if (!m_toolbar->getSize(&windowSize))
+ {
+ return false;
+ }
+
+ // Get the CWidgetControl associated with this window
+
+ 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
+
+ nxgl_point_t iconPos;
+ nxgl_size_t iconSize;
+
+ // 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 = windowSize.w - 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 CImage(control, iconPos.x, iconPos.y, iconSize.w, iconSize.h, m_stopBitmap);
+ if (!m_stopImage)
+ {
+ return false;
+ }
+
+ // Create MINIMIZE application bitmap container
+
+ m_minimizeBitmap = new NxWidgets::CRlePaletteBitmap(&g_minimizeBitmap);
+ if (!m_minimizeBitmap)
+ {
+ return false;
+ }
+
+ // Get the height and width of the stop bitmap
+
+ iconSize.w = m_minimizeBitmap->getWidth();
+ iconSize.h = m_minimizeBitmap->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_minimizeImage = new CImage(control, iconPos.x, iconPos.y, iconSize.w, iconSize.h, m_minimizeBitmap);
+ if (!m_minimizeImage)
+ {
+ return false;
+ }
+
+ // The rest of the toolbar will hold the left-justified application label
+ // Create the default font instance
+
+ m_windowFont = new CNxFont(CONFIG_NXWM_DEFAULT_FONTID,
+ CONFIG_NXWM_DEFAULT_FONTCOLOR,
+ CONFIG_NXWM_TRANSPARENT_COLOR);
+ if (!m_windowFont)
+ {
+ return false;
+ }
+ // Get the width of the display
+
+ struct nxgl_size_s windowSize;
+ if (!m_bgWindow->getSize(&windowSize))
+ {
+ printf("CLabelTest::createGraphics: Failed to get window size\n");
+ return (CLabel *)NULL;
+ }
+
+ // Get the height and width of the text display area
+
+ size.w = pos.x
+ size.h = windowSize.h;
+
+ pos.x = 0;
+ pos.y = 0;
+
+ // Now we have enough information to create the label
+
+ m_windowLabel = new CLabel(control, pos.x, pos.y, size.w, size.h, "");
+ if (!m_windowLabel)
+ {
+ return false;
+ }
+
+ // Configure the label
+ m_windowLabel->setBorderLess(true);
+ m_windowLabel->setTextAlignmentHoriz(NxWidgets::TEXT_ALIGNMENT_HORIZ_LEFT);
+ m_windowLabel->setTextAlignmentVert(NxWidgets::TEXT_ALIGNMENT_VERT_CENTER);
+ return true;
}