185 lines
6.7 KiB
C
185 lines
6.7 KiB
C
/* File: CPevents.c */
|
|
/* This module contains a function to handle the events from the CPWindow. */
|
|
|
|
/****************************************************************
|
|
Topograph - A function browser
|
|
Copyright (C) 1996 Marc Culler
|
|
|
|
culler@math.uic.edu
|
|
|
|
Department of Mathematics (M/C 249)
|
|
University of Illinois at Chicago
|
|
851 S. Morgan St.
|
|
Chicago, IL 60607-7045
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
******************************************************************/
|
|
|
|
#include "Topograph.h"
|
|
|
|
/* Defined in this module. */
|
|
BOOL processCPIDCMP(void);
|
|
|
|
/* Defined in Topograph.c */
|
|
extern struct CPMessage CPmsg;
|
|
|
|
/* Defined in UI.c */
|
|
extern struct Window *CPWindow;
|
|
extern struct Window *graphWindow;
|
|
extern struct Menu *CPMenu;
|
|
extern struct Gadget *CPGadgets[];
|
|
extern void stackScreens(void);
|
|
|
|
/* Defined in parseIO.c */
|
|
extern BPTR inputStream;
|
|
|
|
/* Defined in menus.c */
|
|
extern BOOL quit(void);
|
|
|
|
/* Defined in CP.c */
|
|
extern void CP_displayDomain(void);
|
|
extern void CP_displayExtrema(struct graph *);
|
|
|
|
/* Defined in graphtask.c */
|
|
extern struct graph *theGraph;
|
|
extern void graphMessage(int command);
|
|
|
|
BOOL processCPIDCMP(void){
|
|
BOOL doingFine = TRUE;
|
|
struct IntuiMessage *m;
|
|
struct IntuiMessage message;
|
|
struct MenuItem *item;
|
|
UWORD menuNumber;
|
|
BOOL (*menuFunction)(void);
|
|
void (*gadgetFunction)(UWORD code);
|
|
struct Gadget *gadget;
|
|
|
|
while(m = GT_GetIMsg(CPWindow->UserPort)){
|
|
|
|
message = *m;
|
|
GT_ReplyIMsg(m);
|
|
|
|
if (doingFine)
|
|
switch(message.Class){
|
|
case IDCMP_CLOSEWINDOW:
|
|
doingFine = quit();
|
|
break;
|
|
|
|
case IDCMP_GADGETUP:
|
|
/*
|
|
Call the function(s) pointed to by the UserData field(s).
|
|
If we had an active gadget, take care of it first.
|
|
The activeGadget is always a string gadget. Since the code
|
|
argument is ignored by them, we pass 0.
|
|
*/
|
|
gadget = (struct Gadget *)message.IAddress;
|
|
if (CPmsg.activeGadget != NULL && CPmsg.activeGadget != gadget){
|
|
gadgetFunction = (void (*)()) CPmsg.activeGadget->UserData;
|
|
if (gadgetFunction != NULL)(*gadgetFunction)(0);
|
|
}
|
|
gadgetFunction = (void (*)()) gadget->UserData;
|
|
if (gadgetFunction != NULL)(*gadgetFunction)(message.Code);
|
|
CPmsg.activeGadget = NULL;
|
|
break;
|
|
|
|
case IDCMP_GADGETDOWN:
|
|
gadget = (struct Gadget *)message.IAddress;
|
|
/*
|
|
One of the string gadgets has been activated. If we already
|
|
had an active string gadget, take care of it.
|
|
*/
|
|
if (CPmsg.activeGadget != NULL && CPmsg.activeGadget != gadget){
|
|
gadgetFunction = (void (*)()) CPmsg.activeGadget->UserData;
|
|
if (gadgetFunction != NULL)(*gadgetFunction)(0);
|
|
}
|
|
/*
|
|
The gadget might have been deactivated when the gadgetFunction
|
|
was called for the previous gadget, so ...
|
|
*/
|
|
ActivateGadget(gadget,CPWindow,NULL);
|
|
|
|
if (gadget->GadgetID == ASPECT ||
|
|
gadget->GadgetID == XMIN ||
|
|
gadget->GadgetID == XMAX ||
|
|
gadget->GadgetID == YMIN ||
|
|
gadget->GadgetID == YMAX ){
|
|
CPmsg.computeNewValues = YES;
|
|
OffGadget(CPGadgets[RESCALE],CPWindow,NULL);
|
|
}
|
|
|
|
CPmsg.activeGadget = gadget;
|
|
break;
|
|
|
|
case IDCMP_MENUPICK:
|
|
menuNumber = message.Code;
|
|
/*
|
|
The "while" is supposed to allow multiple selection, which
|
|
we probably will never get.
|
|
*/
|
|
while (menuNumber != MENUNULL && doingFine){
|
|
item = ItemAddress(CPMenu, menuNumber);
|
|
|
|
/*
|
|
Call the function pointed to by the UserData field.
|
|
*/
|
|
menuFunction = (BOOL (*)()) GTMENUITEM_USERDATA(item);
|
|
if (menuFunction != NULL) doingFine = (*menuFunction)();
|
|
menuNumber = item->NextSelect;
|
|
}
|
|
break;
|
|
|
|
case IDCMP_RAWKEY:
|
|
switch (message.Code){
|
|
case UPARROW:
|
|
graphMessage(UP_CMD);
|
|
break;
|
|
|
|
case DOWNARROW:
|
|
graphMessage(DOWN_CMD);
|
|
break;
|
|
|
|
case LEFTARROW:
|
|
graphMessage(LEFT_CMD);
|
|
break;
|
|
|
|
case RIGHTARROW:
|
|
graphMessage(RIGHT_CMD);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
CP_displayDomain();
|
|
CP_displayExtrema(theGraph);
|
|
break;
|
|
|
|
case IDCMP_INTUITICKS:
|
|
/*
|
|
If we hear a tick, check whether the pointer has moved into
|
|
the graphWindow; if so and if we don't have an active string
|
|
gadget then activate the graphWindow.
|
|
*/
|
|
if (CPWindow->MouseY > CPWindow->Height + 4 &&
|
|
CPmsg.activeGadget == NULL)
|
|
ActivateWindow(graphWindow);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return(doingFine);
|
|
}
|