/* * SPL - The SPL Programming Language * Copyright (C) 2004, 2005 Clifford Wolf * * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * mod_wsf_graph.spl: A WSF Component for viewing and editing graphs */ /** * A module which implemnts a WSF Component for displaying and editing * graphs. */ load "wsf"; /** * A WSF Component for displaying and editing graphs. * * In order for this component to work properly, the browser must have support * for iframes and must allow javascripts to modify the DOM tree. This is the * case with most of todays graphical web browsers. * * For various technical reasons, the graph editor itself is displayed in an * iframe. This object creates an extra SPL task for this iframe. * * The constructor is passed a function which returns a list of node objects * which must implement the [[WsfGraphNode]] interface. If there is any * outside change of what that function would return, the 'dirty' attribute * of the WsfGraph instance must be set to '1'. * * This object is derived from [[wsf:WsfComponent]]. */ object WsfGraph WsfComponent { /** * The function which returns the node list. This is set by the * constructor to its first argument. */ var get_list; /** * The (relative or absolute) URL to the directory in which the images * used by this component can be found. * * This are the files 'images/wsf_graph_*' in the SPL sources. */ var ibase; /** * Per default, nodes can be moved to any position. It is possible to * use a raster to align the nodes. If you want that, set this variable * to the size of the raster (e.g. 10 is a good value). */ var raster; /** * Additional HTML text to be inserted in the HTML header of the iframe. */ var iframe_header; /** * Additional HTML text to be inserted at the end of the HTML text in the * iframe. */ var iframe_footer; /** * Additional attributes to be added in the \n'; } /** * Overloaded [[wsf:WsfComponent.main()]]. */ method main() { task_co_return(); if (declared cgi.param.n) { var i = cgi.param.n; var list = get_list(); if (declared cgi.param.sx) scroll_x = cgi.param.sx; if (declared cgi.param.sy) scroll_y = cgi.param.sy; if (declared cgi.param.x and declared cgi.param.y and declared list[i].set_xy) list[i].set_xy(cgi.param.x, cgi.param.y); if (declared cgi.param.t and declared list[i].set_link) list[i].set_link(cgi.param.t); } } /** * Overloaded [[wsf:WsfComponent.destroy()]]. */ method destroy() { task_kill("${id}_iframe"); return *WsfComponent.destroy(); } /** * The Constructor. * * The parameters are copied to the [[.get_list]] and [[.ibase]] * variables. * * The first parameter must be a function pointer. This function, when * called, must return an array of objects implementing the * [[WsfGraphNode]] interface. This objects describe the entire graph * and also provide callbacks to react on user events. */ method init(_get_list, _ibase) { *WsfComponent.init(); get_list = _get_list; ibase = _ibase; task_create("${id}_iframe", "while (1) { iframe_main(); task_pause(); }", this); task_public("${id}_iframe"); return this; } } /** * The node objects used by [[WsfGraph]] must implement this interface. * Some of the methods in this interface are optional. */ // interface WsfGraphNode // { /** * This method returns the position and size of the node in pixel. * The return value must be a hash with the keys 'x' and 'y' for * the x- and y-coordinate of the left upper corner (0,0 is the * left upper corner of the drawing area) and 'w' and 'h' for the * width and height. */ // method get_xywh() /** * When a node is moved or clicked, this callback is called. The new * x- and y-coordinates are passed as parameters. */ // method set_xy(x, y) /** * This method returns an array with the IDs of the nodes this node * has connections to. The IDs must correspond with the keys in the * array returned by [[WsfGraph.get_list]]. */ // method get_links() /** * This callback is called when one of the connections of the node * are clicked. The ID (see [[.get_links]]) of the target node of the * connection is passed as parameter. * * This method is optional. [[WsfGraph]] will not try to call it when * is is not declared. */ // method set_link(trg) /** * This method must return the background color for this node. The * return value is a string in the usual HTML color '#RRGGBB' format. * * This method is optional. [[WsfGraph]] will not try to call it when * it is not declared. */ // method get_color() /** * This method must return the HTML content for this node. Usually * this is just a label text, but it can any HTML code. * * This method is optional. [[WsfGraph]] will not try to call it when * it is not declared. */ // method get_html() // }