Back to index

texmacs  1.0.7.15
window_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : window_widget.cpp
00004 * DESCRIPTION: Window 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 "window.hpp"
00013 #include "message.hpp"
00014 #include "Widkit/wk_widget.hpp"
00015 #include "Widkit/Event/basic_event.hpp"
00016 
00017 /******************************************************************************
00018 * Window widgets
00019 ******************************************************************************/
00020 
00021 class window_widget_rep: public wk_widget_rep {
00022   command quit;
00023 public:
00024   window_widget_rep (array<wk_widget> a, array<string> name, command quit2):
00025     wk_widget_rep (a, name, north_west), quit (quit2) {}
00026   operator tree () { return tree (TUPLE, "window", (tree) a[0]); }
00027   bool is_window_widget () { return true; }
00028   bool handle (event ev);
00029 };
00030 
00031 bool
00032 window_widget_rep::handle (event ev) {
00033   if (ev->type == ATTACH_WINDOW_EVENT)
00034     win= ((attach_window_event) ev)->win;
00035   if (ev->type == DESTROY_EVENT && !is_nil (quit))
00036     quit ();
00037   return a[0] -> handle (ev);
00038 }
00039 
00040 wk_widget
00041 window_widget (wk_widget w, command quit) {
00042   array<wk_widget> a (1);
00043   a[0]= w;
00044   array<string> name (1);
00045   name[0]= "window";
00046   return tm_new<window_widget_rep> (a, name, quit);
00047 }
00048 
00049 /******************************************************************************
00050 * Interface
00051 ******************************************************************************/
00052 
00053 wk_widget
00054 plain_window_widget (wk_widget wid, string s, command quit) {
00055   SI W, H;
00056   gui_root_extents (W, H);
00057   SI min_w= 0, min_h= 0, def_w= W, def_h= H, max_w= W, max_h= H;
00058   wid << get_size (min_w, min_h, -1);
00059   wid << get_size (def_w, def_h, 0);
00060   wid << get_size (max_w, max_h, 1);
00061   wid= window_widget (wid, quit);
00062   (void) plain_window (abstract (wid), s,
00063                      min_w, min_h, def_w, def_h, max_w, max_h);
00064   return wid;
00065 }
00066 
00067 wk_widget
00068 popup_window_widget (wk_widget wid, string s) {
00069   SI W, H;
00070   gui_root_extents (W, H);
00071   SI min_w= 0, min_h= 0, def_w= W, def_h= H, max_w= W, max_h= H;
00072   wid << get_size (min_w, min_h, -1);
00073   wid << get_size (def_w, def_h, 0);
00074   wid << get_size (max_w, max_h, 1);
00075   wid= window_widget (wid, command ());
00076   (void) popup_window (abstract (wid), s,
00077                      min_w, min_h, def_w, def_h, max_w, max_h);
00078   return wid;
00079 }
00080 
00081 void
00082 destroy_window_widget (wk_widget w) {
00083   ASSERT (w->is_window_widget (), "not a window widget");
00084   tm_delete (w->win);
00085 }
00086 
00087 void
00088 refresh_size (widget wid, bool exact) {
00089   window win= concrete (wid) -> win;
00090   SI old_w, old_h;
00091   win->get_size (old_w, old_h);
00092   SI def_w= old_w, def_h= old_h;
00093   SI min_w= old_w, min_h= old_h;
00094   SI max_w= old_w, max_h= old_h;
00095   concrete (wid) << get_size (def_w, def_h, 0);
00096   concrete (wid) << get_size (min_w, min_h, -1);
00097   concrete (wid) << get_size (max_w, max_h, 1);
00098   win->set_size_limits (min_w, min_h, max_w, max_h);
00099   SI new_w= min (max (old_w, min_w), max_w);
00100   SI new_h= min (max (old_h, min_h), max_h);
00101   if (exact) { new_w= def_w; new_h= def_h; }
00102   if (new_w != old_w || new_h != old_h) {
00103     concrete (wid) << emit_position (0, 0, new_w, new_h);
00104     win->set_size (new_w, new_h);
00105   }
00106 }