Back to index

texmacs  1.0.7.15
glue_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : glue_widget.cpp
00004 * DESCRIPTION: Widgets for filling up space between a group of widgets.
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 "gui.hpp"
00013 #include "window.hpp"
00014 #include "Widkit/layout.hpp"
00015 #include "Widkit/basic_widget.hpp"
00016 
00017 /******************************************************************************
00018 * Glue widgets
00019 ******************************************************************************/
00020 
00021 class glue_widget_rep: public basic_widget_rep {
00022   tree col;           // color or empty string for default background
00023   bool hflag, vflag;  // may be extended horizontally resp. vertically
00024   SI   minw, minh;    // minimal width and height in pixels
00025 
00026 public:
00027   glue_widget_rep (bool hflag, bool vflag, SI minw, SI minh);
00028   glue_widget_rep (tree col, bool hflag, bool vflag, SI minw, SI minh);
00029   operator tree ();
00030 
00031   void handle_get_size (get_size_event ev);
00032   void handle_repaint (repaint_event ev);
00033 };
00034 
00035 glue_widget_rep::glue_widget_rep (bool hflag2, bool vflag2, SI w2, SI h2):
00036   basic_widget_rep (),
00037   col (""), hflag (hflag2), vflag (vflag2), minw (w2), minh (h2) {}
00038 
00039 glue_widget_rep::glue_widget_rep (tree c2, bool hf2, bool vf2, SI w2, SI h2):
00040   basic_widget_rep (),
00041   col (c2), hflag (hf2), vflag (vf2), minw (w2), minh (h2) {}
00042 
00043 glue_widget_rep::operator tree () {
00044   return "glue";
00045 }
00046 
00047 void
00048 glue_widget_rep::handle_get_size (get_size_event ev) {
00049   if (ev->mode==0) {
00050     ev->w= minw;
00051     ev->h= minh;
00052     //if (!hflag) ev->w= minw;
00053     //if (!vflag) ev->h= minh;
00054   }
00055   if (ev->mode==-1) {
00056     ev->w= minw;
00057     ev->h= minh;
00058   }
00059   if (ev->mode==1) {
00060     gui_maximal_extents (ev->w, ev->h);
00061     if (!hflag) ev->w= minw;
00062     if (!vflag) ev->h= minh;
00063   }
00064 }
00065 
00066 void
00067 glue_widget_rep::handle_repaint (repaint_event ev) {
00068   renderer ren= win->get_renderer ();
00069   if (col == "")
00070     layout_default (ren, ev->x1, ev->y1, ev->x2, ev->y2);
00071   else {
00072     if (is_atomic (col)) {
00073       color c= named_color (col->label);
00074       ren->set_background (c);
00075       ren->set_color (c);
00076       ren->fill (ev->x1, ev->y1, ev->x2, ev->y2);
00077     }
00078     else {
00079       ren->set_shrinking_factor (5);
00080       int old_a;
00081       tree old_bg= ren->get_background_pattern (old_a);
00082       ren->set_background_pattern (col);
00083       ren->clear_pattern (5*ev->x1, 5*ev->y1, 5*ev->x2, 5*ev->y2);
00084       ren->set_background_pattern (old_bg, old_a);
00085       ren->set_shrinking_factor (1);
00086     }
00087   }
00088 }
00089 
00090 /******************************************************************************
00091 * Interface
00092 ******************************************************************************/
00093 
00094 wk_widget
00095 glue_wk_widget (bool hflag, bool vflag, SI minw, SI minh) {
00096   return tm_new<glue_widget_rep> (hflag, vflag, minw, minh);
00097 }
00098 
00099 wk_widget
00100 glue_wk_widget (tree col, bool hflag, bool vflag, SI minw, SI minh) {
00101   return tm_new<glue_widget_rep> (col, hflag, vflag, minw, minh);
00102 }