Algorithmic Solutions > LEDA > LEDA Guide > GraphWin > Customizing the Interactive Interface > Call-Back Functions

GraphWin Call-Back Functions

What is a Call-Back Function?

Call-Back or Handler functions can be used to associate arbitrary functionality with the edit operations of the interactive interface of GraphWin. For complete examples of how to use Call-Back functions see Online Demos of Graph Algorithms and A Recipe for Online Demos of Network Algorithms.

For every edit operation two handlers can be defined

  • pre-handler: This handler is called immediately before the corresponding edit operation. A pre-handler returns a bool which tells GraphWin whether to execute the corresponding edit operation or not. This provides a simple way of disallowing edit operations under certain conditions.
  • post-handler: This handler is called at the end of the corresponding edit operation.
A third handler can be defined for move operations of nodes and edge sliders
  • move-handler: This handler is called for all intermediate positions

The null-handler (NULL) can be used to remove the pre- or post-handler from an edit operation.

Simple Example Call-Back Functions

New-Node and New-Edge Operations

The following operation sets the pre-handler of the new-node operation to f, i.e., f(gw,p) is called before a node is created at position p.
    void gw.set_new_node_handler(bool (*f)(GraphWin&,const point&));
The function
    void gw.set_new_node_handler(void (*f)(GraphWin&,node));
sets the post-handler of the new-node operation to f, i.e., f(gw,v) is called after a new node v has been created.
    void gw.set_new_edge_handler(bool (*f)(GraphWin&,node,node));
sets the pre-handler of the new-edge operation to f, i.e., f(gw,v,w) is called before a new edge (v,w) is created. The function
    void gw.set_new_edge_handler(void (*f)(GraphWin&,edge));
sets the post-handler of the new-edge operation to f, i.e., f(gw,e) is called after a new edge e has been created.

Del-Node and Del-Edge Operations

The following operation sets the pre-handler of the del-node operation to f, i.e., f(gw,v) is called before a node is deleted.
    void gw.set_del_node_handler(bool (*f)(GraphWin&,node));
The function
    void gw.set_del_node_handler(void (*f)(GraphWin&));
sets the post-handler of the del-node operation to f, i.e., f(gw) is called after a node has been deleted.
    void gw.set_del_edge_handler(bool (*f)(GraphWin&,node,node));
sets the pre-handler of the del-edge operation to f, i.e., f(gw,e) is called before an edge e is deleted. The function
    void gw.set_del_edge_handler(void (*f)(GraphWin&));
sets the post-handler of the del-edge operation to f, i.e., f(gw) is called after an edge e has been deleted.

Init-Graph Operations

The following operation sets the pre-handler of the init-graph operation to f, i.e., f(gw) is called every time before a global update of the graph, e.g., in a clear, generate, or load operation.
    void gw.set_init_graph_handler(bool (*f)(GraphWin&));
The function
    void gw.set_init_graph_handler(void (*f)(GraphWin&));
sets the post-handler of the init-graph operation to f, i.e., f(gw) is called after each global update of the graph.

Move-Handler

Node moving and edge slider moving operations may have three different handlers. The first is called before moving starts, the second is called for every intermediate position, and the third one is called at the final position of the node after the moving has been finished. The handlers are set by
    void gw.set_start_move_node_handler
                      (bool (*f)(GraphWin&,node));
    void gw.set_move_node_handler
                      (bool (*f)(GraphWin&,node,const point&));
    void gw.set_end_move_node_handler
                      (void (*f)(GraphWin&,node));

    void gw.set_start_edge_slider_handler
                      (bool (*f)(GraphWin&,edge,double),int i);
    void gw.set_edge_slider_handler
                      (bool (*f)(GraphWin&,edge,double),int i);
    void gw.set_end_edge_slider_handler
                      (void (*f)(GraphWin&,edge,double),int i);
Each edge has three sliders associated with it. The integer argument i in the last three functions selects the slider, i=0,1,2.

See also:

Customizing the Interactive Interface

GraphWin

Interactive Interface

A Recipe for Online Demos of Graph Algorithms

A Recipe for Online Demos of Network Algorithms


Windows and Panels


Graph Data Types

Graphs


Manual Pages:

Manual Page GraphWin




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH