Back to index

texmacs  1.0.7.15
widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : widget.cpp
00004 * DESCRIPTION: 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 #include "gui.hpp"
00013 #include "message.hpp"
00014 #include "font.hpp"
00015 #include "window.hpp"
00016 
00017 /******************************************************************************
00018 * slot names, useful for debugging
00019 ******************************************************************************/
00020 
00021 const char * 
00022 slot_name (const slot s) { 
00023   const char * slot_names[]= {
00024     "SLOT_IDENTIFIER",
00025     "SLOT_WINDOW",
00026     "SLOT_RENDERER",
00027     "SLOT_VISIBILITY",
00028     "SLOT_FULL_SCREEN",
00029     "SLOT_NAME",
00030     "SLOT_SIZE",
00031     "SLOT_POSITION",
00032     "SLOT_UPDATE",
00033     "SLOT_REFRESH",
00034     "SLOT_KEYBOARD",
00035     "SLOT_KEYBOARD_FOCUS",
00036     "SLOT_MOUSE",
00037     "SLOT_MOUSE_GRAB",
00038     "SLOT_MOUSE_POINTER",
00039     "SLOT_INVALIDATE",
00040     "SLOT_INVALIDATE_ALL",
00041     "SLOT_REPAINT",
00042     "SLOT_DELAYED_MESSAGE",
00043     "SLOT_DESTROY",
00044     
00045     "SLOT_SHRINKING_FACTOR",
00046     "SLOT_EXTENTS",
00047     "SLOT_VISIBLE_PART",
00048     "SLOT_SCROLLBARS_VISIBILITY",
00049     "SLOT_SCROLL_POSITION",
00050     "SLOT_CANVAS",
00051     "SLOT_SCROLLABLE",
00052     "SLOT_CURSOR",
00053     
00054     "SLOT_HEADER_VISIBILITY",
00055     "SLOT_MAIN_MENU",
00056     "SLOT_MAIN_ICONS_VISIBILITY",
00057     "SLOT_MAIN_ICONS",
00058     "SLOT_MODE_ICONS_VISIBILITY",
00059     "SLOT_MODE_ICONS",
00060     "SLOT_FOCUS_ICONS_VISIBILITY",
00061     "SLOT_FOCUS_ICONS",
00062     "SLOT_USER_ICONS_VISIBILITY",
00063     "SLOT_USER_ICONS",
00064     "SLOT_FOOTER_VISIBILITY",
00065     "SLOT_LEFT_FOOTER",
00066     "SLOT_RIGHT_FOOTER",
00067     "SLOT_INTERACTIVE_MODE",
00068     "SLOT_INTERACTIVE_PROMPT",
00069     "SLOT_INTERACTIVE_INPUT",
00070     
00071     "SLOT_FORM_FIELD",
00072     "SLOT_STRING_INPUT",
00073     "SLOT_INPUT_TYPE",
00074     "SLOT_INPUT_PROPOSAL",
00075     "SLOT_FILE",
00076     "SLOT_DIRECTORY"
00077   };
00078   
00079   return slot_names[s.sid]; 
00080 }
00081 
00082 /******************************************************************************
00083 * The abstract widget_connection class
00084 ******************************************************************************/
00085 
00086 class widget_connection_rep: public concrete_struct {
00087 public:
00088   widget_rep* w1;  // widget which triggers the signal
00089   slot s1;         // corresponding slot
00090   widget_rep* w2;  // widget which receives the signal
00091   slot s2;         // corresponding slot
00092 
00093 public:
00094   inline widget_connection_rep (widget_rep* w1b, slot s1b,
00095                             widget_rep* w2b, slot s2b):
00096     w1 (w1b), s1 (s1b), w2 (w2b), s2 (s2b) {}
00097 
00098   friend class widget_connection;
00099 };
00100 
00101 class widget_connection {
00102 public:
00103 CONCRETE(widget_connection);
00104   inline widget_connection (widget_rep* w1, slot s1,
00105                          widget_rep* w2, slot s2):
00106     rep (tm_new<widget_connection_rep> (w1, s1, w2, s2)) {}
00107   inline bool operator == (widget_connection con) {
00108     return rep->w1 == con->w1 && rep->s1 == con->s1 &&
00109            rep->w2 == con->w2 && rep->s2 == con->s2; }
00110   inline bool operator != (widget_connection con) {
00111     return rep->w1 != con->w1 || rep->s1 != con->s1 ||
00112            rep->w2 != con->w2 || rep->s2 != con->s2; }
00113 };
00114 CONCRETE_CODE(widget_connection);
00115 
00116 /******************************************************************************
00117 * Managing connections
00118 ******************************************************************************/
00119 
00120 inline void
00121 insert (list<widget_connection>& l, widget_connection con) {
00122   l= list<widget_connection> (con, l);
00123 }
00124 
00125 void
00126 remove (list<widget_connection>& l, widget_connection con) {
00127   ASSERT (!is_nil (l), "removal not succeeded");
00128   if (l->item == con) l= l->next;
00129   else remove (l->next, con);
00130 }
00131 
00132 widget_rep::widget_rep () {}
00133 
00134 widget_rep::~widget_rep () {
00135   list<widget_connection> l= in;
00136   while (!is_nil (l)) {
00137     remove (l->item->w1->out, l->item);
00138     l= l->next;
00139   }
00140   l= out;
00141   while (!is_nil (l)) {
00142     remove (l->item->w2->in, l->item);
00143     l= l->next;
00144   }
00145   in = list<widget_connection> ();
00146   out= list<widget_connection> ();
00147 }
00148 
00149 void
00150 widget_rep::connect (slot s, widget w2, slot s2) {
00151   widget_connection con (this, s, w2.rep, s2);
00152   insert (out, con);
00153   insert (w2->in, con);
00154 }
00155 
00156 void
00157 widget_rep::deconnect (slot s, widget w2, slot s2) {
00158   widget_connection con (this, s, w2.rep, s2);
00159   remove (out, con);
00160   remove (w2->in, con);
00161 }
00162 
00163 /******************************************************************************
00164 * Message passing
00165 ******************************************************************************/
00166 
00167 void
00168 widget_rep::send (slot s, blackbox val) {
00169   (void) s; (void) val;
00170   FAILED ("no default implementation");
00171 }
00172 
00173 blackbox
00174 widget_rep::query (slot s, int type_id) {
00175   (void) s; (void) type_id;
00176   FAILED ("no default implementation");
00177   return blackbox ();
00178 }
00179 
00180 widget
00181 widget_rep::read (slot s, blackbox index) {
00182   (void) s; (void) index;
00183   FAILED ("no default implementation");
00184   return widget ();
00185 }
00186 
00187 void
00188 widget_rep::write (slot s, blackbox index, widget w) {
00189   (void) s; (void) index; (void) w;
00190   FAILED ("no default implementation");
00191 }
00192 
00193 void
00194 widget_rep::notify (slot s, blackbox new_val) {
00195   list<widget_connection> l= out;
00196   while (!is_nil (l)) {
00197     l->item->w2->send (s, new_val);
00198     l= l->next;
00199   }  
00200 }
00201 
00202 /******************************************************************************
00203 * Miscellaneous
00204 ******************************************************************************/
00205 
00206 tm_ostream&
00207 widget_rep::print (tm_ostream& out) {
00208   return out << "widget";
00209 }
00210 
00211 font
00212 get_default_styled_font (int style) {
00213   bool tt  = (style & WIDGET_STYLE_MONOSPACED) != 0;
00214   bool mini= (style & WIDGET_STYLE_MINI) != 0;
00215   bool bold= (style & WIDGET_STYLE_BOLD) != 0;
00216   return get_default_font (tt, mini, bold);
00217 }
00218 
00219 bool use_side_tools= false;