From lechner Sat Nov 10 02:26:18 2001 Subject: bdeOOMenu2CanvasInterface.txt To: 01f522 Date: Sat, 10 Nov 2001 02:26:10 -0500 (EST) $CASE/01f522/bdeOOMenu2CanvasInterface.txt: This note contains more info on dobuttonevent's interface to *ops.cc files, using as an example the node_delete method in nodeops.cc.. Example Interface: buttonevent.cc/dobuttonevent calls nodeops.cc/node_delete:: ================================================ bde/src/buttonevent.cc contains one routine: void dobuttonevent(Widget, XtPointer, XEvent, Boolean) /* Description: * Dobuttonevent is a callback routine called by X to handle button * events. It divides up work and calls the appropriate functions. Practically all class*method state name combinations are handled here. See the various *ops.cc function calls from dobuttonevent cases. */ For example, both node-delete states call the same node_delete method: ---------------- case SDnode1: case SDnode2: // redefined by hcpatel & mmaliset node_delete(event, selected.getstate(), &(attr.node), button_op); break; ----------------- Notice that BOTH states of that machine call node_delete(...) in nodeops.cc. (Moving node methods there began the partitioning of bde methods into classes.) nodeops.cc dooes the switch(state) again, but now responds only to the SDnode1 and SDnode2 cases): Here is the beginning of nodeops.cc: ---------------------- //Name: nodeops.cc // // Description: // // This file contains all BDE code responsible for controlling node // operations. The code has been taken from the BDE 1.0 buttondown.cc, // buttonup.cc and buttonmoved.cc files. // // Routines :node_create();node_delete();node_move();position_text() // node_resize();node_fit_to_text(); ... ================================================ Here is the entire node_delete() method, with its two state case blocks: /************************************************************ * Name: * void node_delete(XButtonEvent*, int, node_attributes *, int) * . .. * A generic selction routine is used for selecting a Node which searches * the whole object list till it finds a Node. This routine implements the * improved state model suggested by Prof.Lechner. * Description: * This performs the node deletion operation. It does this based on the * button event and other variables passed in to it. (Note that attribute * is not actually used for the delete operation. We don't need to know * whether the node was a circle or rectangle to delete it.) * All code within this function was lifted from the button*.cc files. * button_op is one of: BUTTON_UP, BUTTON_DOWN, BUTTON_MOVED * Uses: * DCtoWC(), Ggroup class method select_HN(widget, int, int), * changeCanvasCursor(), changeAttribState(), docut() * Side effects: * NONE ****************************************************************** void node_delete (XButtonEvent *event, int state, /* Canvas State (eventually just NodeCreate)*/ node_attributes *attribute, /* circle, square, etc. */ int button_op /* BUTTON_UP, BUTTON_DOWN, BUTTON_MOVED */ ) { float sx, sy; static graphobject *selected_node = NULL; DCtoWC(event->x, event->y, &sx, &sy); switch (state) { /* Note that once the canvas state has been changed to be more meaningful, the following state case should eventually be replaced by a line of the form "case NodeDelete:" */ case SDnode1: switch (button_op) { case BUTTON_DOWN_EVENT: topobject->select_HN(canvas, (int)sx, (int)sy); selected_node = currentselection; if (currentselection != NULL) { selected.changeAttribState(SDnode2); changeCanvasCursor(pirate); } break; case BUTTON_UP_EVENT: break; case BUTTON_MOVED_EVENT: break; default: //add PostErrorMsg() to handle error message - phsia 12/8/95 PostErrorMsg(SDnode1); break; } break; case SDnode2: switch (button_op) { case BUTTON_DOWN_EVENT: topobject->select_HN(canvas, (int)sx, (int)sy); if(currentselection != NULL && selected_node == currentselection) { docut((Widget) 0,0,0); selected.changeAttribState(SDnode1); changeCanvasCursor(arrow); } else selected_node = currentselection; break; case BUTTON_UP_EVENT: break; case BUTTON_MOVED_EVENT: break; default: /* illegal value for button_op variable */ //add PostErrorMsg() to handle error message - phsia 12/8/95 PostErrorMsg(SDnode2); break; } break; default: /* illegal value for state variable */ fprintf(stderr, "Out of State in function node_delete.\n"); fprintf(stderr, "switch on state\n"); fprintf(stderr, "Report this to Professor Lechner.\n"); break; } } // end void node_delete() // (other methods follow in nodeops.cc)