home *** CD-ROM | disk | FTP | other *** search
- /* File: _WimpCol.c
- * Purpose: Supplies functionality for a PopUp
- * Author: © Copyright 1993 Jason Williams
- * All rights reserved
- */
-
- #include "DeskLib:GFX.h"
- #include "DeskLib:WimpSWIs.h"
- #include "DeskLib:Template.h"
-
- #include "Server.h"
-
-
- typedef struct
- {
- char colour;
- } wimpcol_data;
-
-
- /* First of all, we define a handler_info structure for our PopUp handler
- * which describes it to the manager. This is referenced externally
- * by the server to find the procedure to call with events for any PopUp
- * of this type, etc.
- * (We also prototype the handler function so we can reference it here)
- */
-
- static int Handler_WimpColour(int, ctrl_block *, void *, event_pollblock *);
-
- handler_info HandlerInfo_WimpColour =
- {
- "WimpColour", /* PopUp type/name string */
- 0x00000001, /* Flag word */
- Handler_WimpColour, /* Handler procedure */
- 4 /* Instantiation workspace size */
- };
-
-
- static char invertcolour[] = {7,7,7,7, 0,0,0,0, 0,7,7,0, 7,0,7,7};
-
- /* The Handler_ function referenced in the above info struct will handle all
- * calls from the server during normal operation...
- */
-
- static BOOL Handler_WimpColour(int reasoncode, ctrl_block *ctrl,
- void *privateworkspace, event_pollblock *event)
- {
- switch(reasoncode)
- {
- case REASON_OPEN:
- {
- window_handle windowhandle;
- window_block *window;
- wimpcol_data *info;
-
- /* Find the template. NOTE that if you provide a STATIC popup, you
- * MUST support multiple instantiations, so MUST use Template_Clone()
- * Also note that if bringing up a MENU LEAF window, we must clone
- * our template data into the RMA so the WIMP does not crash! ;-(
- */
- window = Template_Find("WimpColour"); /* Has NO indirected data */
- if (window == NULL) break;
-
- /* Create the window, and fill in it's icons with the data given
- * to us in the pollblock. (DATA_BASE is defined above)
- */
- window->colours[windowcol_WORKBACK] = colour_TRANSPARENT;
- window->flags.data.closeicon = (ctrl->appflags & APPFLAGS_ISLEAF) == 0;
- Wimp_CreateWindow(window, &windowhandle);
-
- info = (wimpcol_data *) (((int)event) + POPUP_DATA_OFFSET);
- if (info->colour >= 0 && info->colour <= 15)
- ((char *)privateworkspace)[0] = info->colour;
-
- ctrl->pollmask.value = ~( (1 << event_CLOSE) |
- (1 << event_REDRAW) |
- (1 << event_CLICK) );
- ctrl->basewindow = windowhandle; /* Let server know windowhandle */
- }
- return(TRUE);
-
-
- case REASON_CLOSE: /* Quietly kill our window */
- Wimp_DeleteWindow(ctrl->basewindow);
- return(TRUE);
-
-
- case REASON_EVENT: /* Handle a WIMP Event */
- switch(event->type)
- {
- case event_REDRAW:
- if (event->data.openblock.window == ctrl->basewindow)
- {
- window_redrawblock r;
- window_state wstate;
- int gridsize, x, y, x0, y0;
- BOOL more;
-
- Wimp_GetWindowState(ctrl->basewindow, &wstate);
- x0 = wstate.openblock.screenrect.min.x;
- y0 = wstate.openblock.screenrect.min.y;
- gridsize = (wstate.openblock.screenrect.max.x - x0) >> 2;
-
- r.window = ctrl->basewindow;
- Wimp_RedrawWindow(&r, &more);
- while (more)
- {
- for (x = 0; x < 4; x++)
- for (y = 0; y < 4; y++)
- {
- Wimp_SetColour(x + ((3-y) << 2));
- GFX_RectangleFill(x0 + (x * gridsize), y0 + (y * gridsize),
- gridsize-1, gridsize-1);
- }
-
- x = ((char *)privateworkspace)[0];
- Wimp_SetColour(invertcolour[x]);
- y = 3 - ((x >> 2) & 3);
- x &= 3;
- GFX_CircleFill(x0 + x * gridsize + (gridsize >> 1),
- y0 + y * gridsize + (gridsize >> 1),
- gridsize >> 2);
-
- Wimp_GetRectangle(&r, &more);
- }
- return(TRUE);
- }
- break;
-
-
- case event_CLOSE:
- if (event->data.openblock.window == ctrl->basewindow)
- {
- /* *ONLY* if this is our window, we kill the current menu, kill
- * our window, and return TRUE to indicate that we have processed
- * the event (so no other handlers should get it)
- */
- Wimp_CreateMenu((menu_block *) -1, 0, 0);
- Wimp_DeleteWindow(ctrl->basewindow);
- KillMe(); /* Inform server that we have closed ourselves */
- return(TRUE);
- }
- break;
-
-
- case event_CLICK:
- if (event->data.mouse.window == ctrl->basewindow)
- {
- window_state wstate;
- int gridsize, x, y;
-
- Wimp_GetWindowState(ctrl->basewindow, &wstate);
- x = wstate.openblock.screenrect.min.x;
- y = wstate.openblock.screenrect.min.y;
- gridsize = (wstate.openblock.screenrect.max.x - x) >> 2;
-
- x = ((event->data.mouse.pos.x - x) / gridsize) & 3;
- y = ((event->data.mouse.pos.y - y) / gridsize) & 3;
-
- x += ((3 - y) << 2);
- if (x != ((char *)privateworkspace)[0]) /* If new colour picked */
- {
- if (!event->data.mouse.button.data.select)
- {
- window_redrawblock r;
-
- ((char *)privateworkspace)[0] = x; /* Force window redraw */
- r.window = ctrl->basewindow;
- r.rect.min.x = r.rect.min.y = -1024;
- r.rect.max.x = r.rect.max.y = 1024;
- Wimp_ForceRedraw(&r);
- }
-
- ((char *)event)[0] = x; /* tell the client of the change */
- SendState(event, 1);
- }
-
- if (event->data.mouse.button.data.select)
- {
- Wimp_CreateMenu((menu_block *) -1, 0, 0); /* Kill menu/window */
- Wimp_DeleteWindow(ctrl->basewindow); /* If hit with select*/
- KillMe(); /* Inform server that we have closed ourselves */
- }
- return(TRUE);
- }
- break;
- }
- break;
- }
-
- return(FALSE); /* If we didn't handle this call, we MUST return 0 */
- }
-
-