9
0
Fork 0

Add argument to window callbacks

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1366 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-12-01 13:22:34 +00:00
parent c38eb80e47
commit ed9ff70f02
10 changed files with 104 additions and 48 deletions

View File

@ -84,20 +84,22 @@ enum exitcode_e
****************************************************************************/ ****************************************************************************/
static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more); boolean morem, FAR void *arg);
static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more); boolean more, FAR void *arg);
static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds); FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds); FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
#ifdef CONFIG_NX_MOUSE #ifdef CONFIG_NX_MOUSE
static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons); ubyte buttons, FAR void *arg);
static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons); ubyte buttons, FAR void *arg);
#endif #endif
#ifdef CONFIG_NX_KBD #ifdef CONFIG_NX_KBD
static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch); static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch);
@ -163,10 +165,10 @@ static nxgl_mxpixel_t g_color2[CONFIG_NX_NPLANES];
****************************************************************************/ ****************************************************************************/
static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more) boolean more, FAR void *arg)
{ {
message("nxeg_redraw1: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s arg=%p\n",
hwnd, (int)arg, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "TRUE" : "FALSE"); more ? "TRUE" : "FALSE");
nx_fill(hwnd, rect, g_color1); nx_fill(hwnd, rect, g_color1);
@ -177,12 +179,13 @@ static void nxeg_redraw1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
****************************************************************************/ ****************************************************************************/
static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more) boolean more, FAR void *arg)
{ {
message("nxeg_redraw2: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n", message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s arg=%p\n",
hwnd, (int)arg, hwnd,
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
more ? "TRUE" : "FALSE"); more ? "TRUE" : "FALSE",
arg);
nx_fill(hwnd, rect, g_color2); nx_fill(hwnd, rect, g_color2);
} }
@ -192,12 +195,13 @@ static void nxeg_redraw2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds) FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{ {
/* Report the position */ /* Report the position */
message("nxeg_position1: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", message("nxeg_position%d: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
hwnd, arg, hwnd,
size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y, size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y,
pos->x, pos->y, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
@ -223,12 +227,13 @@ static void nxeg_position1(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds) FAR const struct nxgl_rect_s *bounds,
FAR void *arg)
{ {
/* Report the position */ /* Report the position */
message("nxeg_position2: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n", message("nxeg_position%d: hwnd=%p size={(%d,%d),(%d,%d)} pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
hwnd, arg, hwnd,
size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y, size->pt1.x, size->pt1.y, size->pt2.x, size->pt2.y,
pos->x, pos->y, pos->x, pos->y,
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y); bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
@ -240,10 +245,10 @@ static void nxeg_position2(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
#ifdef CONFIG_NX_MOUSE #ifdef CONFIG_NX_MOUSE
static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons) ubyte buttons, FAR void *arg)
{ {
message("nxeg_mousein1: hwnd=%p pos=(%d,%d) button=%02x\n", message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
hwnd, pos->x, pos->y, buttons); arg, hwnd, pos->x, pos->y, buttons);
} }
#endif #endif
@ -253,7 +258,7 @@ static void nxeg_mousein1(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
#ifdef CONFIG_NX_MOUSE #ifdef CONFIG_NX_MOUSE
static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, static void nxeg_mousein2(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons) ubyte buttons, FAR void *arg)
{ {
message("nxeg_mousein2: hwnd=%p pos=(%d,%d) button=%02x\n", message("nxeg_mousein2: hwnd=%p pos=(%d,%d) button=%02x\n",
hwnd, pos->x, pos->y, buttons); hwnd, pos->x, pos->y, buttons);
@ -546,7 +551,7 @@ int user_start(int argc, char *argv[])
/* Create window #1 */ /* Create window #1 */
message("user_start: Create window #1\n"); message("user_start: Create window #1\n");
hwnd1 = nx_openwindow(g_hnx, &g_nxcb1); hwnd1 = nx_openwindow(g_hnx, &g_nxcb1, (FAR void *)2);
message("user_start: hwnd1=%p\n", hwnd1); message("user_start: hwnd1=%p\n", hwnd1);
if (!hwnd1) if (!hwnd1)
@ -580,8 +585,18 @@ int user_start(int argc, char *argv[])
goto errout_with_hwnd1; goto errout_with_hwnd1;
} }
pt.x = g_xres / 4; /* Sleep a bit -- both so that we can see the result of the above operations
pt.y = g_yres / 4; * but also, in the multi-user case, so that the server can get a chance to
* actually do them!
*/
message("user_start: Sleeping\n\n");
sleep(1);
/* Set the position of window #1 */
pt.x = g_xres / 8;
pt.y = g_yres / 8;
message("user_start: Set hwnd1 postion to (%d,%d)\n", pt.x, pt.y); message("user_start: Set hwnd1 postion to (%d,%d)\n", pt.x, pt.y);
ret = nx_setposition(hwnd1, &pt); ret = nx_setposition(hwnd1, &pt);
@ -592,18 +607,15 @@ int user_start(int argc, char *argv[])
goto errout_with_hwnd1; goto errout_with_hwnd1;
} }
/* Sleep a bit -- both so that we can see the result of the above operations /* Sleep a bit */
* but also, in the multi-user case, so that the server can get a chance to
* actually do them!
*/
message("user_start: Sleeping\n\n"); message("user_start: Sleeping\n\n");
sleep(2); sleep(2);
/* Create window #2 */ /* Create window #2 */
message("user_start: Create window #1\n"); message("user_start: Create window #2\n");
hwnd2 = nx_openwindow(g_hnx, &g_nxcb2); hwnd2 = nx_openwindow(g_hnx, &g_nxcb2, (FAR void *)2);
message("user_start: hwnd2=%p\n", hwnd2); message("user_start: hwnd2=%p\n", hwnd2);
if (!hwnd2) if (!hwnd2)
@ -613,6 +625,11 @@ int user_start(int argc, char *argv[])
goto errout_with_hwnd1; goto errout_with_hwnd1;
} }
/* Sleep a bit */
message("user_start: Sleeping\n\n");
sleep(1);
/* Set the size of the window 2 == size of window 1*/ /* Set the size of the window 2 == size of window 1*/
message("user_start: Set hwnd2 size to (%d,%d)\n", rect.pt2.x, rect.pt2.y); message("user_start: Set hwnd2 size to (%d,%d)\n", rect.pt2.x, rect.pt2.y);
@ -624,6 +641,13 @@ int user_start(int argc, char *argv[])
goto errout_with_hwnd2; goto errout_with_hwnd2;
} }
/* Sleep a bit */
message("user_start: Sleeping\n\n");
sleep(1);
/* Set the position of window #2 */
pt.x = g_xres - rect.pt2.x - pt.x; pt.x = g_xres - rect.pt2.x - pt.x;
pt.y = g_yres - rect.pt2.y - pt.y; pt.y = g_yres - rect.pt2.y - pt.y;
@ -654,6 +678,22 @@ int user_start(int argc, char *argv[])
/* Sleep a bit */ /* Sleep a bit */
message("user_start: Sleeping\n\n");
sleep(1);
/* Lower window 1 */
message("user_start: Raise window #2\n");
ret = nx_raise(hwnd2);
if (ret < 0)
{
message("user_start: nx_raise failed: %d\n", errno);
g_exitcode = NXEXIT_NXSETPOSITION;
goto errout_with_hwnd2;
}
/* Sleep a bit */
message("user_start: Sleeping\n\n"); message("user_start: Sleeping\n\n");
sleep(2); sleep(2);

View File

@ -142,9 +142,14 @@ struct nxbe_window_s
FAR struct nxbe_window_s *above; /* The window "above" this window */ FAR struct nxbe_window_s *above; /* The window "above" this window */
FAR struct nxbe_window_s *below; /* The window "below this one */ FAR struct nxbe_window_s *below; /* The window "below this one */
/* Window geometry */
struct nxgl_rect_s bounds; /* The bounding rectangle of window */ struct nxgl_rect_s bounds; /* The bounding rectangle of window */
struct nxgl_point_s origin; /* The position of the top-left corner of the window */ struct nxgl_point_s origin; /* The position of the top-left corner of the window */
/* Client state information this is provide in window callbacks */
FAR void *arg;
}; };
/* Back-end state ***********************************************************/ /* Back-end state ***********************************************************/

View File

@ -193,7 +193,7 @@ int nx_eventhandler(NXHANDLE handle)
DEBUGASSERT(wnd); DEBUGASSERT(wnd);
if (wnd->cb->redraw) if (wnd->cb->redraw)
{ {
wnd->cb->redraw((NXWINDOW)wnd, &redraw->rect, redraw->more); wnd->cb->redraw((NXWINDOW)wnd, &redraw->rect, redraw->more, wnd->arg);
} }
} }
break; break;
@ -205,7 +205,7 @@ int nx_eventhandler(NXHANDLE handle)
DEBUGASSERT(wnd); DEBUGASSERT(wnd);
if (wnd->cb->position) if (wnd->cb->position)
{ {
wnd->cb->position((NXWINDOW)wnd, &postn->size, &postn->pos, &postn->bounds); wnd->cb->position((NXWINDOW)wnd, &postn->size, &postn->pos, &postn->bounds, wnd->arg);
} }
} }
break; break;
@ -218,7 +218,7 @@ int nx_eventhandler(NXHANDLE handle)
DEBUGASSERT(wnd); DEBUGASSERT(wnd);
if (wnd->cb->mousein) if (wnd->cb->mousein)
{ {
wnd->cb->mousein((NXWINDOW)wnd, &mouse->pos, mouse->buttons); wnd->cb->mousein((NXWINDOW)wnd, &mouse->pos, mouse->buttons, wnd->arg);
} }
} }
break; break;
@ -232,7 +232,7 @@ int nx_eventhandler(NXHANDLE handle)
DEBUGASSERT(wnd); DEBUGASSERT(wnd);
if (wnd->cb->kbdin) if (wnd->cb->kbdin)
{ {
wnd->cb->kbdin((NXWINDOW)wnd, kbd->nch, kbd->ch); wnd->cb->kbdin((NXWINDOW)wnd, kbd->nch, kbd->ch, wnd->arg);
} }
} }
break; break;

View File

@ -93,7 +93,7 @@ int nx_kbdchin(NXHANDLE handle, ubyte ch)
if (wnd->cb->kbdin) if (wnd->cb->kbdin)
{ {
wnd->kbdin(wnd, 1, &ch); wnd->cb->kbdin(wnd, 1, &ch, wnd->arg);
} }
} }

View File

@ -92,7 +92,7 @@ int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch)
if (wnd->cb->kbdin) if (wnd->cb->kbdin)
{ {
wnd->cb->kbdin(wnd, kbd->nch, kbd->ch); wnd->cb->kbdin(wnd, kbd->nch, kbd->ch, wnd->arg);
} }
} }

View File

@ -107,7 +107,7 @@ void nxsu_mousereport(struct nxbe_window_s *wnd)
if (win->cb->mousein) if (win->cb->mousein)
{ {
win->cb->mousein((NXWINDOW)wnd, &g_mpos, g_mbutton); win->cb->mousein((NXWINDOW)wnd, &g_mpos, g_mbutton, wnd->arg);
} }
} }

View File

@ -61,7 +61,8 @@
****************************************************************************/ ****************************************************************************/
static void nxsu_bkgdredraw(NXWINDOW hwnd, static void nxsu_bkgdredraw(NXWINDOW hwnd,
FAR const struct nxgl_rect_s *rect, boolean more); FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg);
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@ -92,7 +93,8 @@ const struct nx_callback_s g_bkgdcb =
****************************************************************************/ ****************************************************************************/
static void nxsu_bkgdredraw(NXWINDOW hwnd, static void nxsu_bkgdredraw(NXWINDOW hwnd,
FAR const struct nxgl_rect_s *rect, boolean more) FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg)
{ {
FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd;
FAR struct nxbe_state_s *be = wnd->be; FAR struct nxbe_state_s *be = wnd->be;

View File

@ -97,7 +97,7 @@ void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, FAR const struct nxgl_rect_s
/* And request the redraw */ /* And request the redraw */
wnd->cb->redraw((NXWINDOW)wnd, &relrect, FALSE); wnd->cb->redraw((NXWINDOW)wnd, &relrect, FALSE, wnd->arg);
} }
} }

View File

@ -102,6 +102,6 @@ void nxfe_reportposition(FAR struct nxbe_window_s *wnd)
/* And provide this to the client */ /* And provide this to the client */
wnd->cb->position(wnd, &rect, &wnd->origin, &be->bkgd.bounds); wnd->cb->position(wnd, &rect, &wnd->origin, &be->bkgd.bounds, wnd->arg);
} }
} }

View File

@ -101,13 +101,15 @@ struct nx_callback_s
* rect - The rectangle that needs to be re-drawn (in window relative * rect - The rectangle that needs to be re-drawn (in window relative
* coordinates * coordinates
* more - TRUE: More re-draw requests will follow * more - TRUE: More re-draw requests will follow
* arg - User provided argument (see nx_openwindow, nx_constructwindow)
* *
* Returned Value: * Returned Value:
* None * None
* *
**************************************************************************/ **************************************************************************/
void (*redraw)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, boolean more); void (*redraw)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
boolean more, FAR void *arg);
/************************************************************************** /**************************************************************************
* Name: position * Name: position
@ -123,6 +125,7 @@ struct nx_callback_s
* the overalll display * the overalll display
* bounds - The bounding rectangle that the describes the entire * bounds - The bounding rectangle that the describes the entire
* display * display
* arg - User provided argument (see nx_openwindow, nx_constructwindow)
* *
* Returned Value: * Returned Value:
* None * None
@ -131,7 +134,8 @@ struct nx_callback_s
void (*position)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size, void (*position)(NXWINDOW hwnd, FAR const struct nxgl_rect_s *size,
FAR const struct nxgl_point_s *pos, FAR const struct nxgl_point_s *pos,
FAR const struct nxgl_rect_s *bounds); FAR const struct nxgl_rect_s *bounds,
FAR void *arg);
/************************************************************************** /**************************************************************************
* Name: mousein * Name: mousein
@ -143,6 +147,7 @@ struct nx_callback_s
* hwnd - Window handle * hwnd - Window handle
* pos - The (x,y) position of the mouse * pos - The (x,y) position of the mouse
* buttons - See NX_MOUSE_* definitions * buttons - See NX_MOUSE_* definitions
* arg - User provided argument (see nx_openwindow, nx_constructwindow)
* *
* Returned Value: * Returned Value:
* None * None
@ -150,7 +155,8 @@ struct nx_callback_s
**************************************************************************/ **************************************************************************/
#ifdef CONFIG_NX_MOUSE #ifdef CONFIG_NX_MOUSE
void (*mousein)(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, ubyte buttons); void (*mousein)(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
ubyte buttons, FAR void *arg);
#endif #endif
/************************************************************************** /**************************************************************************
@ -163,6 +169,7 @@ struct nx_callback_s
* hwnd - Window handle * hwnd - Window handle
* nch - The number of characters that are available in ch[] * nch - The number of characters that are available in ch[]
* ch - The array of characters * ch - The array of characters
* arg - User provided argument (see nx_openwindow, nx_constructwindow)
* *
* Returned Value: * Returned Value:
* None * None
@ -170,7 +177,7 @@ struct nx_callback_s
**************************************************************************/ **************************************************************************/
#ifdef CONFIG_NX_KBD #ifdef CONFIG_NX_KBD
void (*kbdin)(NXWINDOW hwnd, ubyte nch, const ubyte *ch); void (*kbdin)(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg);
#endif #endif
}; };
@ -390,6 +397,7 @@ EXTERN int nx_eventnotify(NXHANDLE handle, int signo);
* Input Parameters: * Input Parameters:
* handle - The handle returned by nx_connect * handle - The handle returned by nx_connect
* cb - Callbacks used to process window events * cb - Callbacks used to process window events
* arg - User provided value that will be returned with NX callbacks.
* *
* Return: * Return:
* Success: A non-NULL handle used with subsequent NX accesses * Success: A non-NULL handle used with subsequent NX accesses
@ -398,7 +406,8 @@ EXTERN int nx_eventnotify(NXHANDLE handle, int signo);
****************************************************************************/ ****************************************************************************/
EXTERN NXWINDOW nx_openwindow(NXHANDLE handle, EXTERN NXWINDOW nx_openwindow(NXHANDLE handle,
FAR const struct nx_callback_s *cb); FAR const struct nx_callback_s *cb,
FAR void *arg);
/**************************************************************************** /****************************************************************************
* Name: nx_closewindow * Name: nx_closewindow