summaryrefslogtreecommitdiff
path: root/nuttx/graphics/nxsu
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-01 13:26:23 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-12-01 13:26:23 +0000
commited6a78372c4c7dde448e92d21f74f3defee35fed (patch)
tree5d9877c26c969f35782f57582e42c58df413a6d0 /nuttx/graphics/nxsu
parentad2faab27444c4f2e24e5bcde65898036a86767b (diff)
downloadnuttx-ed6a78372c4c7dde448e92d21f74f3defee35fed.tar.gz
nuttx-ed6a78372c4c7dde448e92d21f74f3defee35fed.tar.bz2
nuttx-ed6a78372c4c7dde448e92d21f74f3defee35fed.zip
Add nx_constructwindow
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1367 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/graphics/nxsu')
-rw-r--r--nuttx/graphics/nxsu/Make.defs2
-rw-r--r--nuttx/graphics/nxsu/nx_openwindow.c38
-rw-r--r--nuttx/graphics/nxsu/nxfe.h33
-rw-r--r--nuttx/graphics/nxsu/nxsu_constructwindow.c151
4 files changed, 197 insertions, 27 deletions
diff --git a/nuttx/graphics/nxsu/Make.defs b/nuttx/graphics/nxsu/Make.defs
index 5a4c74bb3..af525bea9 100644
--- a/nuttx/graphics/nxsu/Make.defs
+++ b/nuttx/graphics/nxsu/Make.defs
@@ -39,5 +39,5 @@ NXAPI_CSRCS = nx_bitmap.c nx_close.c nx_closewindow.c nx_fill.c \
nx_kbdin.c nx_lower.c nx_mousein.c nx_move.c nx_open.c \
nx_openwindow.c nx_raise.c nx_releasebkgd.c nx_requestbkgd.c \
nx_setsize.c nx_setbgcolor.c nx_setposition.c
-NXSU_CSRCS = nxsu_redrawreq.c nxsu_reportposition.c
+NXSU_CSRCS = nxsu_constructwindow.c nxsu_redrawreq.c nxsu_reportposition.c
NX_CSRCS = $(NXAPI_CSRCS) $(NXSU_CSRCS)
diff --git a/nuttx/graphics/nxsu/nx_openwindow.c b/nuttx/graphics/nxsu/nx_openwindow.c
index 005d907fd..2d73feaef 100644
--- a/nuttx/graphics/nxsu/nx_openwindow.c
+++ b/nuttx/graphics/nxsu/nx_openwindow.c
@@ -80,6 +80,7 @@
* Input Parameters:
* handle - The handle returned by nx_connect
* cb - Callbacks used to process windo events
+ * arg - User provided value that will be returned with NX callbacks.
*
* Return:
* Success: A non-NULL handle used with subsequent NX accesses
@@ -87,14 +88,14 @@
*
****************************************************************************/
-NXWINDOW nx_openwindow(NXHANDLE handle, FAR const struct nx_callback_s *cb)
+NXWINDOW nx_openwindow(NXHANDLE handle, FAR const struct nx_callback_s *cb,
+ FAR void *arg)
{
- FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle;
- FAR struct nxbe_state_s *be = &fe->be;
FAR struct nxbe_window_s *wnd;
+ int ret;
#ifdef CONFIG_DEBUG
- if (!fe || !cb)
+ if (!handle || !cb)
{
errno = EINVAL;
return NULL;
@@ -110,30 +111,15 @@ NXWINDOW nx_openwindow(NXHANDLE handle, FAR const struct nx_callback_s *cb)
return NULL;
}
- /* Initialize the window structure */
+ /* Then let nxfe_constructwindow do the rest */
- wnd->be = be;
- wnd->cb = cb;
-
- /* Insert the new window at the top on the display. topwind is
- * never NULL (it may point only at the background window, however)
- */
-
- wnd->above = NULL;
- wnd->below = be->topwnd;
-
- be->topwnd->above = wnd;
- be->topwnd = wnd;
-
- /* Report the initialize size/position of the window */
-
- nxfe_reportposition((NXWINDOW)wnd);
-
- /* Provide the initial mouse settings */
+ ret = nxfe_constructwindow(handle, wnd, cb, arg);
+ if (ret < 0)
+ {
+ /* An error occurred, the window has been freed */
-#ifdef CONFIG_NX_MOUSE
- nxsu_mousereport(wnd);
-#endif
+ return NULL;
+ }
/* Return the initialized window reference */
diff --git a/nuttx/graphics/nxsu/nxfe.h b/nuttx/graphics/nxsu/nxfe.h
index f0cc076a7..7fd65f2f3 100644
--- a/nuttx/graphics/nxsu/nxfe.h
+++ b/nuttx/graphics/nxsu/nxfe.h
@@ -95,6 +95,39 @@ EXTERN const struct nx_callback_s g_bkgdcb;
****************************************************************************/
/****************************************************************************
+ * Name: nxfe_constructwindow
+ *
+ * Description:
+ * This function is the same a nx_openwindow EXCEPT that the client provides
+ * the window structure instance. nx_constructwindow will initialize the
+ * the pre-allocated window structure for use by NX. This function is
+ * provided in addition to nx_open window in order to support a kind of
+ * inheritance: The caller's window structure may include extensions that
+ * are not visible to NX.
+ *
+ * NOTE: wnd must have been allocated using malloc() (or related allocators)
+ * Once provided to nxfe_constructwindow() that memory is owned and managed
+ * by NX. On certain error conditions or when the window is closed, NX will
+ * free() the the window.
+ *
+ * Input Parameters:
+ * handle - The handle returned by nx_connect
+ * wnd - The pre-allocated window structure.
+ * cb - Callbacks used to process window events
+ * arg - User provided value that will be returned with NX callbacks.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately. In the
+ * case of ERROR, NX will have dealloated the pre-allocated window.
+ *
+ ****************************************************************************/
+
+EXTERN int nxfe_constructwindow(NXHANDLE handle,
+ FAR struct nxbe_window_s *wnd,
+ FAR const struct nx_callback_s *cb,
+ FAR void *arg);
+
+/****************************************************************************
* Name: nxfe_redrawreq
*
* Descripton:
diff --git a/nuttx/graphics/nxsu/nxsu_constructwindow.c b/nuttx/graphics/nxsu/nxsu_constructwindow.c
new file mode 100644
index 000000000..e41071b26
--- /dev/null
+++ b/nuttx/graphics/nxsu/nxsu_constructwindow.c
@@ -0,0 +1,151 @@
+/****************************************************************************
+ * graphics/nxsu/nx_openwindow.c
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <debug.h>
+
+#include <nuttx/nx.h>
+#include "nxfe.h"
+
+/****************************************************************************
+ * Pre-Processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: nxfe_constructwindow
+ *
+ * Description:
+ * This function is the same a nx_openwindow EXCEPT that the client provides
+ * the window structure instance. nx_constructwindow will initialize the
+ * the pre-allocated window structure for use by NX. This function is
+ * provided in addition to nx_open window in order to support a kind of
+ * inheritance: The caller's window structure may include extensions that
+ * are not visible to NX.
+ *
+ * NOTE: wnd must have been allocated using malloc() (or related allocators)
+ * Once provided to nxfe_constructwindow() that memory is owned and managed
+ * by NX. On certain error conditions or when the window is closed, NX will
+ * free() the the window.
+ *
+ * Input Parameters:
+ * handle - The handle returned by nx_connect
+ * wnd - The pre-allocated window structure.
+ * cb - Callbacks used to process window events
+ * arg - User provided value that will be returned with NX callbacks.
+ *
+ * Return:
+ * OK on success; ERROR on failure with errno set appropriately. In the
+ * case of ERROR, NX will have dealloated the pre-allocated window.
+ *
+ ****************************************************************************/
+
+int nxfe_constructwindow(NXHANDLE handle, FAR struct nxbe_window_s *wnd,
+ FAR const struct nx_callback_s *cb, FAR void *arg)
+{
+ FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle;
+ FAR struct nxbe_state_s *be = &fe->be;
+
+#ifdef CONFIG_DEBUG
+ if (!wnd)
+ {
+ errno = EINVAL;
+ return ERROR;
+ }
+
+ if (!fe || !cb)
+ {
+ free(wnd);
+ errno = EINVAL;
+ return ERROR;
+ }
+#endif
+
+ /* Initialize the window structure */
+
+ wnd->be = be;
+ wnd->cb = cb;
+ wnd->arg = arg;
+
+ /* Insert the new window at the top on the display. topwind is
+ * never NULL (it may point only at the background window, however)
+ */
+
+ wnd->above = NULL;
+ wnd->below = be->topwnd;
+
+ be->topwnd->above = wnd;
+ be->topwnd = wnd;
+
+ /* Report the initialize size/position of the window */
+
+ nxfe_reportposition((NXWINDOW)wnd);
+
+ /* Provide the initial mouse settings */
+
+#ifdef CONFIG_NX_MOUSE
+ nxsu_mousereport(wnd);
+#endif
+
+ return OK;
+}
+