Back to index

texmacs  1.0.7.15
basic_event.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : basic_event.cpp
00004 * DESCRIPTION: The most common events
00005 * COPYRIGHT  : (C) 1999  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 "window.hpp"
00013 #include "Widkit/Event/basic_event.hpp"
00014 
00015 /******************************************************************************
00016 * Attribute events
00017 ******************************************************************************/
00018 
00019 get_size_event_rep::get_size_event_rep (SI& w2, SI& h2, int m):
00020   event_rep (GET_SIZE_EVENT), w (w2), h (h2), mode (m) {}
00021 get_size_event_rep::operator tree () {
00022   if (mode==-1) return "get_min_size_event";
00023   if (mode== 0) return "get_size_event";
00024   else          return "get_max_size_event"; }
00025 event get_size (SI& w, SI& h, int mode) {
00026   return tm_new<get_size_event_rep> (w, h, mode); }
00027 
00028 get_widget_event_rep::get_widget_event_rep (string ww, wk_widget& w2):
00029   event_rep (GET_WIDGET_EVENT), which (ww), w (w2) {}
00030 get_widget_event_rep::operator tree () {
00031   return tree (TUPLE, "get_widget_event", which); }
00032 event get_widget (string which, wk_widget& w) {
00033   return tm_new<get_widget_event_rep> (which, w); }
00034 
00035 set_widget_event_rep::set_widget_event_rep (string ww, wk_widget w2):
00036   event_rep (SET_WIDGET_EVENT), which (ww), w (w2) {}
00037 set_widget_event_rep::operator tree () {
00038   return tree (TUPLE, "set_widget_event", which); }
00039 event set_widget (string which, wk_widget w) {
00040   return tm_new<set_widget_event_rep> (which, w); }
00041 
00042 /******************************************************************************
00043 * Structure events
00044 ******************************************************************************/
00045 
00046 attach_window_event_rep::attach_window_event_rep (window win2):
00047   event_rep (ATTACH_WINDOW_EVENT), win (win2) {}
00048 attach_window_event_rep::operator tree () { return "attach_window_event"; }
00049 event emit_attach_window (window win) {
00050   return tm_new<attach_window_event_rep> (win); }
00051 
00052 position_event_rep::position_event_rep ():
00053   event_rep (POSITION_EVENT), flag (true),
00054   ox (0), oy (0), w (0), h (0), grav (north_west) {}
00055 position_event_rep::position_event_rep (SI a, SI b, SI c, SI d, gravity grav2):
00056   event_rep (POSITION_EVENT), flag (false),
00057   ox (a), oy (b), w (c), h (d), grav (grav2) {}
00058 position_event_rep::operator tree () {
00059   if (flag) return "reposition";
00060   return tree (TUPLE, "position_event", as_tree (grav),
00061               tree (TUPLE, as_string (ox/PIXEL), as_string (oy/PIXEL)),
00062               tree (TUPLE, as_string (w /PIXEL), as_string (h /PIXEL))); }
00063 event emit_reposition () {
00064   return tm_new<position_event_rep> (); }
00065 event emit_position (SI ox, SI oy, SI w, SI h, gravity grav) {
00066   return tm_new<position_event_rep> (ox, oy, w, h, grav); }
00067 
00068 move_event_rep::move_event_rep ():
00069   event_rep (MOVE_EVENT) {}
00070 move_event_rep::operator tree () { return "move_event"; }
00071 event emit_move () {
00072   return tm_new<move_event_rep> (); }
00073 
00074 resize_event_rep::resize_event_rep ():
00075   event_rep (RESIZE_EVENT) {}
00076 resize_event_rep::operator tree () { return "resize_event"; }
00077 event emit_resize () {
00078   return tm_new<resize_event_rep> (); }
00079 
00080 destroy_event_rep::destroy_event_rep ():
00081   event_rep (DESTROY_EVENT) {}
00082 destroy_event_rep::operator tree () { return "destroy_event"; }
00083 event emit_destroy () {
00084   return tm_new<destroy_event_rep> (); }
00085 
00086 /******************************************************************************
00087 * Input events
00088 ******************************************************************************/
00089 
00090 keypress_event_rep::keypress_event_rep (string key2, time_t t2):
00091   event_rep (KEYPRESS_EVENT), key (key2), t (t2) {}
00092 keypress_event_rep::operator tree () {
00093   return tree (TUPLE, "keypress_event", key); }
00094 event emit_keypress (string key, time_t t) {
00095   return tm_new<keypress_event_rep> (key, t); }
00096 event emit_keypress (keypress_event ev, string key) {
00097   return tm_new<keypress_event_rep> (key, ev->t); }
00098 
00099 keyboard_focus_event_rep::keyboard_focus_event_rep (bool io, time_t t2):
00100   event_rep (KEYBOARD_FOCUS_EVENT), flag (io), t (t2) {}
00101 keyboard_focus_event_rep::operator tree () {
00102   return tree (TUPLE, "keyboard_focus_event", (char*) (flag? "in": "out")); }
00103 event emit_keyboard_focus (bool in_out_flag, time_t t) {
00104   return tm_new<keyboard_focus_event_rep> (in_out_flag, t); }
00105 
00106 mouse_event_rep::mouse_event_rep (string type2, SI x2, SI y2,
00107   int mods2, time_t t2): event_rep (MOUSE_EVENT),
00108     type (type2), x (x2), y (y2), mods (mods2), t (t2) {}
00109 mouse_event_rep::operator tree () {
00110   return tree (TUPLE, "mouse_event", type,
00111               tree (TUPLE, as_string (x/PIXEL), as_string (y/PIXEL))); }
00112 bool
00113 mouse_event_rep::pressed (string s) {
00114   if (s == "left") return (mods&1) != 0;
00115   if (s == "middle") return (mods&2) != 0;
00116   if (s == "right") return (mods&4) != 0;
00117   if (s == "extra1") return (mods&8) != 0;
00118   if (s == "extra2") return (mods&16) != 0;
00119   return false; }
00120 event emit_mouse (string type, SI x, SI y, int mods, time_t t) {
00121   return tm_new<mouse_event_rep> (type, x, y, mods, t); }
00122 event emit_mouse (mouse_event ev, string type, SI x, SI y) {
00123   return tm_new<mouse_event_rep> (type, x, y, ev->mods, ev->t); }
00124 
00125 alarm_event_rep::alarm_event_rep (string message2, time_t t2):
00126   event_rep (ALARM_EVENT), message (message2), t (t2) {}
00127 alarm_event_rep::operator tree () {
00128   return tree (TUPLE, "alarm_event", message); }
00129 event emit_alarm (string message, time_t t) {
00130   return tm_new<alarm_event_rep> (message, t); }
00131 
00132 /******************************************************************************
00133 * Output events
00134 ******************************************************************************/
00135 
00136 clear_event_rep::clear_event_rep (SI x1b, SI y1b, SI x2b, SI y2b):
00137   event_rep (CLEAR_EVENT), x1 (x1b), y1 (y1b), x2 (x2b), y2 (y2b) {}
00138 clear_event_rep::operator tree () {
00139   return tree (TUPLE, "clear event",
00140               tree (TUPLE, as_string (x1/PIXEL), as_string (y1/PIXEL)),
00141               tree (TUPLE, as_string (x2/PIXEL), as_string (y2/PIXEL))); }
00142 event emit_clear (SI x1, SI y1, SI x2, SI y2) {
00143   return tm_new<clear_event_rep> (x1, y1, x2, y2); }
00144 
00145 repaint_event_rep::repaint_event_rep (SI x1b, SI y1b, SI x2b, SI y2b, bool& b):
00146   event_rep (REPAINT_EVENT), x1 (x1b), y1 (y1b), x2 (x2b), y2 (y2b), stop(b) {}
00147 repaint_event_rep::operator tree () {
00148   return tree (TUPLE, "repaint event",
00149               tree (TUPLE, as_string (x1/PIXEL), as_string (y1/PIXEL)),
00150               tree (TUPLE, as_string (x2/PIXEL), as_string (y2/PIXEL))); }
00151 event emit_repaint (SI x1, SI y1, SI x2, SI y2, bool& stop) {
00152   return tm_new<repaint_event_rep> (x1, y1, x2, y2, stop); }
00153 
00154 /******************************************************************************
00155 * Request some action
00156 ******************************************************************************/
00157 
00158 update_event_rep::update_event_rep ():
00159   event_rep (UPDATE_EVENT) {}
00160 update_event_rep::operator tree () { return "update_event"; }
00161 event emit_update () {
00162   return tm_new<update_event_rep> (); }
00163 
00164 refresh_event_rep::refresh_event_rep ():
00165   event_rep (REFRESH_EVENT) {}
00166 refresh_event_rep::operator tree () { return "refresh_event"; }
00167 event emit_refresh () {
00168   return tm_new<refresh_event_rep> (); }
00169 
00170 invalidate_event_rep::invalidate_event_rep ():
00171   event_rep (INVALIDATE_EVENT), all_flag (true),
00172   x1 (0), y1 (0), x2 (0), y2 (0) {}
00173 invalidate_event_rep::invalidate_event_rep (SI x1b, SI y1b, SI x2b, SI y2b):
00174   event_rep (INVALIDATE_EVENT), all_flag (false),
00175   x1 (x1b), y1 (y1b), x2 (x2b), y2 (y2b) {}
00176 invalidate_event_rep::operator tree () {
00177   if (all_flag) return "invalidate_event";
00178   else return tree (TUPLE, "invalidate_event",
00179                   tree (TUPLE, as_string (x1/PIXEL),as_string (y1/PIXEL)),
00180                   tree (TUPLE, as_string (x2/PIXEL),as_string (y2/PIXEL))); }
00181 event emit_invalidate_all () {
00182   return tm_new<invalidate_event_rep> (); }
00183 event emit_invalidate (SI x1, SI y1, SI x2, SI y2) {
00184   return tm_new<invalidate_event_rep> (x1, y1, x2, y2); }
00185 
00186 keyboard_grab_event_rep::keyboard_grab_event_rep (bool io, time_t t2):
00187   event_rep (KEYBOARD_GRAB_EVENT), flag (io), t (t2) {}
00188 keyboard_grab_event_rep::operator tree () {
00189   return tree (TUPLE, "keyboard_grab_event", (char*) (flag? "in": "out")); }
00190 event emit_keyboard_grab (bool in_out_flag, time_t t) {
00191   return tm_new<keyboard_grab_event_rep> (in_out_flag, t); }
00192 
00193 mouse_grab_event_rep::mouse_grab_event_rep (bool io, time_t t2):
00194   event_rep (MOUSE_GRAB_EVENT), flag (io), t (t2) {}
00195 mouse_grab_event_rep::operator tree () {
00196   return tree (TUPLE, "mouse_grab_event", (char*) (flag? "in": "out")); }
00197 event emit_mouse_grab (bool in_out_flag, time_t t) {
00198   return tm_new<mouse_grab_event_rep> (in_out_flag, t); }
00199 
00200 request_alarm_event_rep::request_alarm_event_rep (event ev2, time_t delay2):
00201   event_rep (REQUEST_ALARM_EVENT), ev (ev2), delay (delay2) {}
00202 request_alarm_event_rep::operator tree () {
00203   return tree (TUPLE, "request_alarm_event",
00204               (tree) ev, as_string ((int) delay)); }
00205 event emit_request_alarm (event ev, time_t delay) {
00206   return tm_new<request_alarm_event_rep> (ev, delay); }
00207 
00208 /******************************************************************************
00209 * Miscellaneous events
00210 ******************************************************************************/
00211 
00212 find_child_event_rep::find_child_event_rep (SI x2, SI y2, int& which2):
00213   event_rep (FIND_CHILD_EVENT), x (x2), y (y2), which (which2) {}
00214 find_child_event_rep::operator tree () {
00215   return tree (TUPLE, "find_child_event",
00216               tree (TUPLE, as_string (x/PIXEL), as_string (y/PIXEL))); }
00217 event emit_find_child (SI x, SI y, int& which) {
00218   return tm_new<find_child_event_rep> (x, y, which); }
00219 
00220 /******************************************************************************
00221 * Output routines for the gravity class
00222 ******************************************************************************/
00223 
00224 tm_ostream&
00225 operator << (tm_ostream& out, gravity grav) {
00226   return out << as_tree (grav);
00227 }
00228 
00229 tree
00230 as_tree (gravity grav) {
00231   switch (grav) {
00232   case north_west: return "north west";
00233   case north     : return "north";
00234   case north_east: return "north east";
00235   case west      : return "west";
00236   case center    : return "center";
00237   case east      : return "east";
00238   case south_west: return "south west";
00239   case south     : return "south";
00240   case south_east: return "south east";
00241   }
00242   FAILED ("unknown gravity");
00243   return "";
00244 }