home *** CD-ROM | disk | FTP | other *** search
- /* File: _Magnify.c
- * Purpose: Supplies functionality for a PopUp
- * Author: © Copyright 1993 Jason Williams
- * All rights reserved
- */
-
- #include "DeskLib:WimpSWIs.h"
- #include "DeskLib:Icon.h"
- #include "DeskLib:Keycodes.h"
- #include "DeskLib:StringCR.h"
- #include "DeskLib:Template.h"
-
- #include "Server.h"
-
-
- typedef struct
- {
- int mul, div; /* Multiplier and divisor icon values */
- int minmul, maxmul; /* Minimum allowed fraction */
- int mindiv, maxdiv; /* Maximum allowed fraction */
- char windowname[12]; /* Title string for window */
-
- window_block *window; /* Internal use only */
- } magnify_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_Magnify(int, ctrl_block *, void *, event_pollblock *);
-
- handler_info HandlerInfo_Magnify =
- {
- "Magnify", /* PopUp type/name string */
- 0x00000003, /* Flag word (MENU/STATIC) */
- Handler_Magnify, /* Handler procedure */
- 44 /* Instantiation workspace size */
- };
-
-
- static void CheckMagDiv(magnify_data *ws)
- /* Ensures that the parameters mag/div give a value between min and max
- * If not, the value is truncated to min or max as appropriate
- */
- {
- if (ws->mul < ws->minmul) ws->mul = ws->minmul;
- if (ws->div < ws->mindiv) ws->div = ws->mindiv;
-
- if (ws->mul > ws->maxmul) ws->mul = ws->maxmul;
- if (ws->div > ws->maxdiv) ws->div = ws->maxdiv;
- }
-
-
-
- static void Add(window_handle window, magnify_data *ws,
- int *value, int increment)
- {
- int oldmul = ws->mul, olddiv = ws->div;
-
- *value += increment;
- CheckMagDiv(ws);
-
- if (oldmul != ws->mul)
- {
- Icon_SetInteger(window, 0, ws->mul); /* Set new value */
- Icon_SetCaret(window, 0); /* Ensure caret appears correctly */
- }
-
- if (olddiv != ws->div)
- {
- Icon_SetInteger(window, 1, ws->div);
- Icon_SetCaret(window, 1);
- }
-
- if (oldmul != ws->mul || olddiv != ws->div)
- SendState(ws, sizeof(magnify_data)); /* 'instant effect' update */
- }
-
-
- static void ReadIcons(magnify_data *ws, window_handle window)
- {
- ws->mul = Icon_GetInteger(window, 0);
- ws->div = Icon_GetInteger(window, 1);
- CheckMagDiv(ws);
- }
-
-
- /* The Handler_ function referenced in the above info struct will handle all
- * calls from the server during normal operation...
- */
-
- static BOOL Handler_Magnify(int reasoncode, ctrl_block *ctrl,
- void *privateworkspace, event_pollblock *event)
- {
- magnify_data *ws = privateworkspace;
-
- switch(reasoncode)
- {
- case REASON_OPEN:
- {
- window_handle windowhandle;
- window_block *window;
- magnify_data *info;
-
- info = (magnify_data *) (((int)event) + POPUP_DATA_OFFSET);
- *ws = *info; /* Copy the window settins into out workspace */
-
- /* 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! ;-(
- */
- if (ctrl->appflags & APPFLAGS_ISSTATIC)
- ws->window = window = Template_Clone("Magnify", 0);
- else
- {
- ws->window = NULL;
- if((ctrl->appflags & APPFLAGS_ISLEAF) == 0)
- window = Template_Find("Magnify");
- else
- {
- window = Template_RMAFind("Magnify");
- window->flags.data.closeicon = FALSE;
- /* (Remove the close icon. NOTE that this is a COPY of the window
- * so does not permanently remove the icon)
- */
- }
- }
-
- 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)
- */
- info->windowname[11] = 0;
- strcpycr(window->title.text,info->windowname); /* Set window name */
- Wimp_CreateWindow(window, &windowhandle);
-
- CheckMagDiv(ws);
- Icon_SetInteger(windowhandle, 0, ws->mul);
- Icon_SetInteger(windowhandle, 1, ws->div);
-
- if (ctrl->appflags & APPFLAGS_ISSTATIC)
- ShowStaticPopUp(windowhandle, ctrl->openx, ctrl->openy);
-
- ctrl->pollmask.value = ~( (1 << event_CLOSE) |
- (1 << event_CLICK) |
- (1 << event_KEY) );
- ctrl->basewindow = windowhandle; /* Let server know windowhandle */
- }
- return(TRUE);
-
-
- case REASON_CLOSE: /* Quietly close our window */
- Wimp_DeleteWindow(ctrl->basewindow);
- if (ws->window != NULL) /* If static, release memory */
- Template_Free(&ws->window); /* used by cloned template */
- return(TRUE);
-
-
- case REASON_EVENT: /* Handle a WIMP Event */
- switch(event->type)
- {
- 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);
- if (ws->window != NULL) /* If static, release memory */
- Template_Free(&ws->window); /* used by cloned template */
-
- KillMe(); /* Tell the PopUp manager that I have closed down */
- return(TRUE);
- }
- break;
-
- case event_CLICK:
- if (event->data.mouse.window == ctrl->basewindow)
- {
- switch(event->data.mouse.icon)
- {
- case 2: /* Mag up */
- Add(ctrl->basewindow, ws, &ws->mul, +1);
- break;
-
- case 3: /* Mag down */
- Add(ctrl->basewindow, ws, &ws->mul, -1);
- break;
-
- case 4: /* Div up */
- Add(ctrl->basewindow, ws, &ws->div, +1);
- break;
-
- case 5: /* Div down */
- Add(ctrl->basewindow, ws, &ws->div, -1);
- break;
- }
- return(TRUE);
- }
- break;
-
- case event_KEY:
- if (event->data.key.caret.window == ctrl->basewindow)
- {
- switch(event->data.key.code)
- {
- case keycode_TAB:
- case keycode_CURSORUP:
- case keycode_CURSORDOWN:
- ReadIcons(ws, ctrl->basewindow);
- if (event->data.key.caret.icon == 0)
- Icon_SetCaret(ctrl->basewindow, 1);
- else
- Icon_SetCaret(ctrl->basewindow, 0);
- break;
-
- case keycode_RETURN:
- ReadIcons(ws, ctrl->basewindow);
- if (event->data.key.caret.icon == 0)
- Icon_SetCaret(ctrl->basewindow, 1);
- else
- SendState(ws, sizeof(magnify_data));
- break;
-
- default:
- Wimp_ProcessKey(event->data.key.code);
- break;
- }
- return(TRUE);
- }
- break;
- }
- break;
- }
-
- return(FALSE); /* If we didn't handle this call, we MUST return 0 */
- }
-
-