Back to index

texmacs  1.0.7.15
text_widget.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003 * MODULE     : text_widget.cpp
00004 * DESCRIPTION: Text widgets for output only
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 "analyze.hpp"
00013 #include "font.hpp"
00014 #include "window.hpp"
00015 #include "Widkit/basic_widget.hpp"
00016 #include "Widkit/layout.hpp"
00017 #include "dictionary.hpp"
00018 
00019 /******************************************************************************
00020 * Text widgets
00021 ******************************************************************************/
00022 
00023 class text_widget_rep: public basic_widget_rep {
00024   string  original, s;
00025   int     style;
00026   color   col;
00027   bool    transparent;
00028   bool    tt;
00029   metric  ex;
00030   int     dw, dh;
00031 
00032 public:
00033   text_widget_rep (string s, int style, color col,
00034                  bool trans, bool tt, int dw, int dh);
00035   operator tree ();
00036 
00037   void handle_get_size (get_size_event ev);
00038   void handle_repaint (repaint_event ev);
00039 };
00040 
00041 text_widget_rep::text_widget_rep (
00042   string s2, int st2, color c2,
00043   bool t2, bool tt2, int dw2, int dh2):
00044     basic_widget_rep (south_west),
00045     original (s2), s (s2), style (st2), col (c2),
00046     transparent (t2), tt (tt2),
00047     dw (dw2+2*PIXEL), dh (dh2+2*PIXEL)
00048 {
00049   if (tt) style= style | WIDGET_STYLE_MONOSPACED;
00050 }
00051 
00052 text_widget_rep::operator tree () {
00053   return tree (TUPLE, "text", s);
00054 }
00055 
00056 void
00057 text_widget_rep::handle_get_size (get_size_event ev) {
00058   s= tm_var_encode (original);
00059   font fn= get_default_styled_font (style);
00060   fn->var_get_extents (s, ex);
00061   ev->w = ((ex->x2- ex->x1+ 2)/3)+ 2*dw;
00062   ev->h = ((fn->y2- fn->y1+ 2)/3)+ 2*dh;
00063   abs_round (ev->w, ev->h);
00064 }
00065 
00066 void
00067 text_widget_rep::handle_repaint (repaint_event ev) { (void) ev;
00068   renderer ren= win->get_renderer ();
00069   if (!transparent) layout_default (ren, 0, 0, w, h);
00070   ren->set_color (col);
00071   font fn= get_default_styled_font (style);
00072   ren->set_shrinking_factor (3);
00073   fn ->var_draw (ren, s, 3*dw- ex->x1, 3*dh- fn->y1);
00074   ren->set_shrinking_factor (1);
00075 }
00076 
00077 /******************************************************************************
00078 * Interface
00079 ******************************************************************************/
00080 
00081 wk_widget
00082 text_wk_widget (string s, int style, bool tsp) {
00083   return tm_new<text_widget_rep> (s, style, black, tsp, false, 3*PIXEL, 0);
00084 }
00085 
00086 wk_widget
00087 menu_text_wk_widget (string s, int style, color col, bool tsp, bool tt) {
00088   return tm_new<text_widget_rep> (s, style, col, tsp, tt, 3*PIXEL, 0);
00089 }