Back to index

texmacs  1.0.7.15
balloon_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : balloon.cpp
00004 * DESCRIPTION: Balloon widgets for showing help
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/basic_widget.hpp"
00014 
00015 /******************************************************************************
00016 * Balloon widgets
00017 ******************************************************************************/
00018 
00019 class balloon_widget_rep: public basic_widget_rep {
00020   wk_widget balloon_wid;
00021 
00022 public:
00023   balloon_widget_rep (wk_widget w, wk_widget help);
00024   operator tree ();
00025 
00026   void balloon_handle_mouse (mouse_event ev);
00027   bool handle (event ev);
00028 };
00029 
00030 /******************************************************************************
00031 * Implementation of balloon widgets
00032 ******************************************************************************/
00033 
00034 balloon_widget_rep::balloon_widget_rep (wk_widget w, wk_widget help):
00035   basic_widget_rep (1)
00036 {
00037   a[0]       = w;
00038   balloon_wid= help;
00039 }
00040 
00041 balloon_widget_rep::operator tree () {
00042   return tree (TUPLE, "balloon", (tree) a[0], balloon_wid);
00043 }
00044 
00045 void
00046 balloon_widget_rep::balloon_handle_mouse (mouse_event ev) {
00047   if (/* (!ev->pressed ("left")) &&
00048         (!ev->pressed ("right")) && */
00049       ((ev->type == "enter") || (ev->type == "move"))) {
00050     SI x, y;
00051     win->get_position (x, y);
00052     SI xx= x+ ev->x+ 10*PIXEL;
00053     SI yy= y+ ev->y- 5*PIXEL;
00054     show_help_balloon (abstract (balloon_wid), xx, yy);
00055   }
00056 }
00057 
00058 bool
00059 balloon_widget_rep::handle (event ev) {
00060   switch (ev->type) {
00061   case MOUSE_EVENT: {
00062     mouse_event e (ev);
00063     balloon_handle_mouse (e);
00064   }
00065   case GET_SIZE_EVENT:
00066   case SET_WIDGET_EVENT:
00067   case ATTACH_WINDOW_EVENT:
00068   case POSITION_EVENT:
00069   case UPDATE_EVENT:
00070   case INVALIDATE_EVENT:
00071   case REPAINT_EVENT:
00072   case FIND_CHILD_EVENT:
00073     return basic_widget_rep::handle (ev);
00074   default:
00075     a[0] << ev;
00076     return true;
00077   }
00078 }
00079 
00080 /******************************************************************************
00081 * Balloon decoration
00082 ******************************************************************************/
00083 
00084 class balloon_decoration_widget_rep: public basic_widget_rep {
00085 public:
00086   balloon_decoration_widget_rep (wk_widget w);
00087   operator tree ();
00088 
00089   void handle_get_size (get_size_event ev);
00090   void handle_position (position_event ev);
00091   void handle_repaint (repaint_event ev);
00092 };
00093 
00094 /******************************************************************************
00095 * Implementation of balloon decoration widgets
00096 ******************************************************************************/
00097 
00098 balloon_decoration_widget_rep::balloon_decoration_widget_rep (wk_widget w):
00099   basic_widget_rep (1, south_west) { a[0]= w; }
00100 
00101 balloon_decoration_widget_rep::operator tree () {
00102   return tree (TUPLE, "balloon decoration", (tree) a[0]);
00103 }
00104 
00105 void
00106 balloon_decoration_widget_rep::handle_get_size (get_size_event ev) {
00107   basic_widget_rep::handle_get_size (ev);
00108   ev->w += 4*PIXEL;
00109   ev->h += 4*PIXEL;
00110 }
00111 
00112 void
00113 balloon_decoration_widget_rep::handle_position (position_event ev) {
00114   (void) ev;
00115   SI ww= w-4*PIXEL;
00116   SI hh= h-4*PIXEL;
00117   a[0] << emit_position (2*PIXEL, 2*PIXEL, ww, hh, south_west);
00118 }
00119 
00120 void
00121 balloon_decoration_widget_rep::handle_repaint (repaint_event ev) {
00122   (void) ev;
00123   renderer ren= win->get_renderer ();
00124   ren->set_background (rgb_color (255, 255, 160));
00125   ren->clear (0, 0, w, h);
00126   ren->set_color (black);
00127   ren->line (0, 0, w-PIXEL, 0);
00128   ren->line (0, h-PIXEL, w-PIXEL, h-PIXEL);
00129   ren->line (0, 0, 0, h);
00130   ren->line (w-PIXEL, 0, w-PIXEL, h-PIXEL);
00131 }
00132 
00133 /******************************************************************************
00134 * exported routines
00135 ******************************************************************************/
00136 
00137 wk_widget
00138 balloon_widget (wk_widget w, wk_widget help) {
00139   return tm_new<balloon_widget_rep> (w, tm_new<balloon_decoration_widget_rep> (help));
00140 }