Back to index

texmacs  1.0.7.15
widget.hpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : widget.hpp
00004 * DESCRIPTION: Definition of abstract widgets
00005 * COPYRIGHT  : (C) 2007  Joris van der Hoeven
00006 *******************************************************************************
00007 * This software falls under the GNU general public license version 3 or later.
00008 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
00009 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
00010 ******************************************************************************/
00011 
00012 #ifndef WIDGET_H
00013 #define WIDGET_H
00014 #include "list.hpp"
00015 #include "tree.hpp"
00016 #include "blackbox.hpp"
00017 #include "command.hpp"
00018 #include "timer.hpp"
00019 #define PIXEL 256
00020 
00021 class window_rep;
00022 typedef window_rep* window;
00023 typedef unsigned int color;
00024 class url;
00025 class widget;
00026 class slot;
00027 class widget_connection;
00028 template<class T> class promise;
00029 
00030 /******************************************************************************
00031 * The abstract widget class
00032 ******************************************************************************/
00033 
00034 class widget_rep: public abstract_struct {
00035 protected:
00036   list<widget_connection> in;
00037   list<widget_connection> out;
00038 
00039 public:
00040   widget_rep ();
00041   virtual ~widget_rep ();
00042   virtual tm_ostream& print (tm_ostream& out);
00043 
00044   virtual void send (slot s, blackbox val);
00045     // send a message val to the slot s
00046   virtual blackbox query (slot s, int type_id);
00047     // obtain information of a given type from the slot s
00048   virtual widget read (slot s, blackbox index);
00049     // abstract read access (of type s) of a subwidget at position index
00050   virtual void write (slot s, blackbox index, widget w);
00051     // abstract write access (of type s) of a subwidget at position index
00052   virtual void notify (slot s, blackbox new_val);
00053     // notification of a change on a slot s which contains a state variable
00054   virtual void connect (slot s, widget w2, slot s2);
00055     // connect a state slot s to another slot s2 of another widget w2
00056   virtual void deconnect (slot s, widget w2, slot s2);
00057     // deconnect a state slot s from another slot s2 of another widget w2
00058 
00059   friend class widget;
00060 };
00061 
00062 class widget {
00063 public:
00064 ABSTRACT_NULL(widget);
00065   inline bool operator == (widget w) { return rep == w.rep; }
00066   inline bool operator != (widget w) { return rep != w.rep; }
00067 };
00068 ABSTRACT_NULL_CODE(widget);
00069 
00070 inline tm_ostream&
00071 operator << (tm_ostream& out, widget w) {
00072   if (is_nil (w)) return out << "nil";
00073   else return w->print (out);
00074 }
00075 
00076 extern bool use_side_tools;
00077 
00078 /******************************************************************************
00079 * Widget style parameters
00080 ******************************************************************************/
00081 
00082 #define WIDGET_STYLE_MINI                1
00083   // use smaller text font inside widget
00084 #define WIDGET_STYLE_MONOSPACED          2
00085   // use monospaced font inside widget
00086 #define WIDGET_STYLE_GREY                4
00087   // use grey text font
00088 #define WIDGET_STYLE_PRESSED             8
00089   // indicate that a button is currently pressed
00090 #define WIDGET_STYLE_INERT              16
00091   // only render but don't associate any action to widget
00092 #define WIDGET_STYLE_BUTTON             32
00093   // indicate that a button should explicitly rendered as a button
00094 #define WIDGET_STYLE_CENTERED           64
00095   // use centered text
00096 #define WIDGET_STYLE_BOLD              128
00097   // use bold text
00098 
00099 /******************************************************************************
00100 * Window widgets
00101 ******************************************************************************/
00102 
00103 widget plain_window_widget (widget w, string s, command quit= command ());
00104   // creates a decorated window with name s and contents w
00105 widget popup_window_widget (widget w, string s);
00106   // creates an undecorated window with name s and contents w
00107 void   destroy_window_widget (widget w);
00108   // destroys a window as created by the above routines
00109 
00110 /******************************************************************************
00111 * Top-level widgets, typically given as an argument to plain_window_widget
00112 * See also message.hpp for specific messages for these widgets
00113 ******************************************************************************/
00114 
00115 widget texmacs_widget (int mask, command quit);
00116   // the main TeXmacs widget and a command which is called on exit
00117   // the mask variable indicates whether the menu, icon bars, status bar, etc.
00118   // are visible or not
00119 widget file_chooser_widget (command cmd, string type, bool save);
00120   // file chooser widget for files of a given 'type';
00121   // for files of type "image", the widget includes a previsualizer for images
00122   // 'save' indicates whether we intend to save the file
00123 widget printer_widget (command cmd, url ps_pdf_file);
00124   // widget for printing a file, offering a way for selecting a page range,
00125   // changing the paper type and orientation, previewing, etc.;
00126   // the command cmd is called on exit
00127 widget color_picker_widget (command cmd, bool bg, array<tree> proposals);
00128   // widgets for selecting a color, a pattern or a background image,
00129   // encoded by a tree. On input, we give a list of recently used proposals
00130   // on termination the command is called with the selected color as argument
00131   // the bg flag specifies whether we are picking a background color or fill
00132 widget inputs_list_widget (command call_back, array<string> prompts);
00133   // a dialogue widget with Ok and Cancel buttons and a series of textual
00134   // input widgets with specified prompts
00135 widget popup_widget (widget w);
00136   // a widget container which results w to be unmapped as soon as
00137   // the pointer quits the widget
00138 
00139 /******************************************************************************
00140 * Widgets for the construction of menus
00141 ******************************************************************************/
00142 
00143 widget horizontal_menu (array<widget> a);
00144   // a horizontal menu made up of the widgets in a
00145 widget vertical_menu (array<widget> a);
00146   // a vertical menu made up of the widgets in a
00147 widget tile_menu (array<widget> a, int cols);
00148   // a menu rendered as a table of cols columns wide & made up of widgets in a
00149 widget minibar_menu (array<widget> a);
00150   // a small minibar, which can for instance occur inside another iconbar
00151 widget menu_separator (bool vertical);
00152   // a horizontal or vertical menu separator
00153 widget menu_group (string name, int style);
00154   // a menu group of a given style; the name should be greyed and centered
00155 
00156 widget pulldown_button (widget w, promise<widget> pw);
00157   // a button w with a lazy pulldown menu pw
00158 widget pullright_button (widget w, promise<widget> pw);
00159   // a button w with a lazy pullright menu pw
00160 widget menu_button (widget w, command cmd,
00161                   string pre= "", string ks= "", int style= 0);
00162   // a command button with an optional prefix (o, * or v) and
00163   // keyboard shortcut; if ok does not hold, then the button is greyed
00164   // for pressed styles, the button is displayed as a pressed button
00165 widget balloon_widget (widget w, widget help);
00166   // given a button widget w, specify a help balloon which should be displayed
00167   // when the user leaves the mouse pointer on the button for a small while
00168 
00169 widget text_widget (string s, int style, color col, bool tsp= true);
00170   // a text widget with a given style, color and transparency
00171 widget xpm_widget (url file_name);
00172   // a widget with an X pixmap icon
00173 widget input_text_widget (command call_back, string type, array<string> def,
00174                        int style= 0, string width= "1w");
00175   // a textual input widget for input of a given type and a list of suggested
00176   // default inputs (the first one should be displayed, if there is one)
00177   // an optional width may be specified for the input field
00178   // the width is specified in TeXmacs length format with units em, px or w
00179 widget enum_widget (command cb, array<string> vals, string val,
00180                     int st= 0, string w= "1w");
00181   // select a value from a list of possible values
00182 widget choice_widget (command cb, array<string> vals, string val);
00183   // select a value from a long list of possible values
00184 widget choice_widget (command cb, array<string> vals, array<string> mc);
00185   // select multiple values from a long list
00186 
00187 /******************************************************************************
00188 * Other widgets
00189 ******************************************************************************/
00190 
00191 widget empty_widget ();
00192   // an empty widget of size zero
00193 widget glue_widget (bool hx=true, bool vx=true, SI w=0, SI h=0);
00194   // an empty widget of minimal width w and height h and which is horizontally
00195   // resp. vertically extensible if hx resp. vx is true
00196 widget glue_widget (tree col, bool hx=true, bool vx=true, SI w=0, SI h=0);
00197   // a colored variant of the above widget, with colors as in the color picker
00198 widget horizontal_list (array<widget> a);
00199   // a horizontal list made up of the widgets in a
00200 widget vertical_list (array<widget> a);
00201   // a vertical list made up of the widgets in a
00202 widget aligned_widget (array<widget> lhs, array<widget> rhs,
00203                        SI hsep= 3*PIXEL, SI vsep= 3*PIXEL,
00204                        SI lpad= 0, SI rpad= 0);
00205   // a table with two columns, the first one being right aligned and
00206   // the second one being left aligned
00207 widget tabs_widget (array<widget> tabs, array<widget> bodies);
00208   // a tab bar where one and only of the bodies can be selected
00209 widget wrapped_widget (widget w, command quit);
00210   // copy of w, but with a separate reference counter,
00211   // and with a command to be called upon destruction
00212 widget user_canvas_widget (widget wid, int style= 0);
00213   // a widget whose contents can be scrolled
00214   // if the size of the inner contents exceed the specified size
00215 widget resize_widget (widget w, int style, string w1, string h1,
00216                       string w2, string h2, string w3, string h3);
00217   // resize the widget w to be of minimal size (w1, h1),
00218   // of default size (w2, h2) and of maximal size (w3, h3)
00219 widget hsplit_widget (widget l, widget r);
00220   // two horizontally juxtaposed widgets l and r with an ajustable border
00221 widget vsplit_widget (widget t, widget b);
00222   // two vertically juxtaposed widgets t and b with an ajustable border
00223 widget extend (widget w, array<widget> a);
00224   // extend the size of w to the maximum of the sizes of
00225   // the widgets in the list a
00226 widget toggle_widget (command cmd, bool on= false, int style= 0);
00227   // an input toggle
00228 widget wait_widget (SI width, SI height, string message);
00229   // a widget of a specified width and height, displaying a wait message
00230   // this widget is only needed when using the X11 plugin
00231 widget ink_widget (command cb);
00232   // widget for inking a sketch. The input may later be passed to
00233   // an external program for handwriting recognition,
00234   // using the callback routine
00235 widget refresh_widget (string tmwid);
00236   // a widget which is automatically constructed from the a dynamic
00237   // scheme widget tmwid. When receiving the send_refresh event,
00238   // the contents should also be updated dynamically by reevaluating
00239   // the scheme widget
00240 
00241 /******************************************************************************
00242 * Besides the widget constructors, any GUI implementation should also provide
00243 * a simple_widget_rep class with the following virtual methods:
00244 ******************************************************************************/
00245 
00246 // void simple_widget_rep::handle_get_size_hint (SI& w, SI& h);
00247 //   propose a size for the widget
00248 // void simple_widget_rep::handle_notify_resize (SI w, SI h);
00249 //   issued when the size of the widget has changed
00250 // void simple_widget_rep::handle_keypress (string key, time_t t);
00251 //   issed when a key is pressed
00252 // void simple_widget_rep::handle_keyboard_focus (bool new_focus, time_t t);
00253 //   issued when the keyboard focus of the widget has changed
00254 // void simple_widget_rep::handle_mouse
00255 //        (string kind, SI x, SI y, int mods, time_t t);
00256 //   a mouse event of a given kind at position (x, y) and time t
00257 //   mods contains the active keyboard modifiers at time t
00258 // void simple_widget_rep::handle_set_shrinking_factor (int sf);
00259 //   set the shrinking factor for painting
00260 // void simple_widget_rep::handle_clear (SI x1, SI y1, SI x2, SI y2);
00261 //   clear the widget to the background color
00262 //   this event may for instance occur when scrolling
00263 // void simple_widget_rep::handle_repaint (SI x1, SI y1, SI x2, SI y2);
00264 //   repaint the region (x1, y1, x2, y2)
00265 
00266 #endif // defined WIDGET_H