summaryrefslogtreecommitdiff
path: root/NxWidgets/nxwm/src/capplicationwindow.cxx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-04-29 19:18:24 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-04-29 19:18:24 +0000
commitc38d91a6cda19491b56dfb2e298e28ea3de06086 (patch)
tree77b8442939f538486aaeaa6fd51c43c849a618ca /NxWidgets/nxwm/src/capplicationwindow.cxx
parent3906314011646470ede38d0c96157378d89c7568 (diff)
downloadpx4-nuttx-c38d91a6cda19491b56dfb2e298e28ea3de06086.tar.gz
px4-nuttx-c38d91a6cda19491b56dfb2e298e28ea3de06086.tar.bz2
px4-nuttx-c38d91a6cda19491b56dfb2e298e28ea3de06086.zip
NxWM update
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4675 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'NxWidgets/nxwm/src/capplicationwindow.cxx')
-rw-r--r--NxWidgets/nxwm/src/capplicationwindow.cxx233
1 files changed, 222 insertions, 11 deletions
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;
}