home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.pollmenu
- *
- * HASWIN Graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * routine to perform the menu related reason code returns from
- * SWI(Wimp_Poll)
- */
- #include "c.poll_h"
-
- int haswin_poll_menu(int (*user)(int, buffer *), buffer *pbuf) {
-
- char menutitle[12], menustr[1024];
- icon *iptr;
- pointer *mouse;
- _kernel_swi_regs regs;
- buffer buff;
-
- if (!haswin_menu.actual) {
- haswin_internalerror("cannot find a menu to select from");
- return(HASWIN_FALSE);
- }
- mouse = haswin_getpointerinfo(0);
- strncpy(menutitle, (char *)haswin_menu.actual, 12);
- regs.r[1] = (int)haswin_menu.actual;
- regs.r[2] = (int)pbuf;
- regs.r[3] = (int)menustr;
- if (!haswin_swi(HASWIN_Decode_menu, ®s))
- return(HASWIN_FALSE);
-
- asciilen(menustr);
- if (haswin_menu.wfrom != 0) {
- /* this came from an icon on the menu bar or in a
- window, or just a window */
- pbuf->i[0] = (int)&haswin_menu;
- pbuf->i[2] = pbuf->i[5] = 0;
- pbuf->i[3] = haswin_menu.wfrom;
- pbuf->i[4] = haswin_menu.ifrom;
- if (!strncmp(menustr, "Quit", 4)) {
- /* inform the userpoll routine that we are about to QUIT */
- if ((user) && (!(*user)(HASWIN_POLL_poll_UQuit, pbuf)))
- return(HASWIN_FALSE);
- if ((haswin_menu.wfrom == -2) || (haswin_ok_cancel("Quit from an icon not on the menu bar ?") == HASWIN_OK))
- haswin_exit(HASWIN_FALSE);
- } else if (!strncmp(menustr, "Window.Open", 11)) {
- iptr = haswin_findiconhandle(haswin_findwindowhandle(haswin_menu.wfrom), haswin_menu.ifrom);
- if ((iptr) && (iptr->window)) {
- /* inform the userpoll routine that we are about to open a window */
- pbuf->i[6] = iptr->window->handle;
- if ((user) && (!(*user)(HASWIN_POLL_poll_Open, pbuf)))
- return(HASWIN_FALSE);
- haswin_reopenwindow(iptr->window);
- } else
- haswin_internalerror("This MENU has no window to open");
- } else if (!strncmp(menustr, "Window.Close", 12)) {
- iptr = haswin_findiconhandle(haswin_findwindowhandle(haswin_menu.wfrom), haswin_menu.ifrom);
- if ((iptr) && (iptr->window)) {
- pbuf->i[6] = iptr->window->handle;
- /* inform the userpoll routine that we are about to close a window */
- if ((user) && (!(*user)(HASWIN_POLL_poll_Close, pbuf)))
- return(HASWIN_FALSE);
- haswin_closewindow(iptr->window);
- } else
- haswin_internalerror("This MENU has no window to close");
- } else if (!strncmp(menustr, "Files.Load", 10)) {
- /*
- pretend that we have pressed the Load File window
- OK icon. Build the mouse pressed data block.
- */
- buff.i[0] = 0;
- buff.i[1] = 0;
- buff.i[2] = HASWIN_MOUSE_L;
- buff.i[3] = haswin_loadiconok->whandle;
- buff.i[4] = haswin_loadiconok->ihandle;
- filemousebutton(haswin_loadiconok, &buff);
- } else if (!strncmp(menustr, "Files.Save", 10)) {
- /*
- pretend that we have pressed the Save File window
- OK icon. Build the mouse pressed data block.
- */
- buff.i[0] = 0;
- buff.i[1] = 0;
- buff.i[2] = HASWIN_MOUSE_L;
- buff.i[3] = haswin_saveiconok->whandle;
- buff.i[4] = haswin_saveiconok->ihandle;
- filemousebutton(haswin_saveiconok, &buff);
- } else if (!strncmp(menustr, "Files.Options.Add", 17)) {
- haswin_fileoptions |= HASWIN_OPTIONS_ADD;
- } else if (!strncmp(menustr, "Files.Options.Replace", 21)) {
- haswin_fileoptions &= ~HASWIN_OPTIONS_ADD;
- } else if (!strncmp(menustr, "Help.Window", 11)) {
- haswin_reopenwindow(haswin_menu.whelp);
- } else if (!strncmp(menustr, "Help.Icon", 9)) {
- haswin_reopenwindow(haswin_menu.ihelp);
- } else if (!strncmp(menustr, "Help.Menu", 9)) {
- haswin_reopenwindow(haswin_menu.mhelp);
- } else if (haswin_menu.domenu) {
- (*haswin_menu.domenu)(menustr,&haswin_menu);
- } else {
- haswin_interrorprintf("Menu selection %s has no action", menustr);
- }
- } else {
- if (haswin_menu.domenu) {
- (*haswin_menu.domenu)(menustr,&haswin_menu);
- } else {
- haswin_interrorprintf("Menu selection %s has no action", menustr);
- }
- }
- if ((mouse->buttons&POINTER_MOUSEBUTTONS) == POINTER_MOUSE_R) {
- /* recreate menu because ADJUST button means don't close */
- /* inform the userpoll routine that a menu is about to be re-opened */
- if ((user) && (!(*user)(HASWIN_POLL_poll_Re_Menu, pbuf)))
- return(HASWIN_FALSE);
- /* call the menu creation routine in the menu block if it exists */
- if ((haswin_menu.makemenu) && (!(*haswin_menu.makemenu)(&haswin_menu)))
- return(HASWIN_FALSE);
- /* now we actually remake the menu */
- haswin_recreatemenu();
- }
- return(HASWIN_TRUE);
- }
-
-