Back to index

texmacs  1.0.7.15
extend_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : extend_widget.cpp
00004 * DESCRIPTION: Size extension to the maximum size of a list of widgets
00005 * COPYRIGHT  : (C) 2010  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/attribute_widget.hpp"
00014 #include "Widkit/layout.hpp"
00015 
00016 /******************************************************************************
00017 * Balloon widgets
00018 ******************************************************************************/
00019 
00020 class extend_widget_rep: public attribute_widget_rep {
00021   array<wk_widget> ws;
00022 public:
00023   extend_widget_rep (wk_widget w, array<wk_widget> ws);
00024   operator tree ();
00025   void handle_get_size (get_size_event ev);
00026   void handle_position (position_event ev);
00027   bool handle (event ev);
00028 };
00029 
00030 /******************************************************************************
00031 * Implementation of balloon widgets
00032 ******************************************************************************/
00033 
00034 extend_widget_rep::extend_widget_rep (wk_widget w, array<wk_widget> ws2):
00035   attribute_widget_rep (1, south_west), ws (ws2)
00036 {
00037   a[0]= w;
00038 }
00039 
00040 extend_widget_rep::operator tree () {
00041   int i;
00042   tree t (TUPLE, N(ws)+2);
00043   t[0]= "extend";
00044   t[1]= (tree) a[0];
00045   for (i=0; i<N(ws); i++) t[i+2]= (tree) ws[i];
00046   return t;
00047 }
00048 
00049 void
00050 extend_widget_rep::handle_get_size (get_size_event ev) {
00051   SI w= ev->w, h= ev->h;
00052   a[0] << get_size (w, h, ev->mode);
00053   for (int i=0; i<N(ws); i++) {
00054     SI ww= ev->w, hh= ev->h;
00055     ws[i] << get_size (ww, hh, ev->mode);
00056     w= max (w, ww);
00057     h= max (h, hh);
00058   }
00059   ev->w= w;
00060   ev->h= h;
00061 }
00062 
00063 void
00064 extend_widget_rep::handle_position (position_event ev) {
00065   (event) ev;
00066   SI ww= w, hh= h;
00067   a[0] << get_size (ww, hh, 0);
00068   SI x= (w - ww) >> 1;
00069   abs_round (x);
00070   a[0] << emit_position (x, 0, ww, hh, south_west);
00071 }
00072 
00073 bool
00074 extend_widget_rep::handle (event ev) {
00075   switch (ev->type) {
00076   case MOUSE_EVENT:
00077   case GET_SIZE_EVENT:
00078   case SET_WIDGET_EVENT:
00079   case ATTACH_WINDOW_EVENT:
00080   case POSITION_EVENT:
00081   case UPDATE_EVENT:
00082   case INVALIDATE_EVENT:
00083   case REPAINT_EVENT:
00084   case FIND_CHILD_EVENT:
00085     return attribute_widget_rep::handle (ev);
00086   default:
00087     a[0] << ev;
00088     return true;
00089   }
00090 }
00091 
00092 /******************************************************************************
00093 * exported routines
00094 ******************************************************************************/
00095 
00096 wk_widget
00097 extend (wk_widget w, array<wk_widget> a) {
00098   return tm_new<extend_widget_rep> (w, a);
00099 }