PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/TeXmacs-1.0.7.11-src/src/Texmacs/Window/tm_button.cpp

#
C++ | 174 lines | 134 code | 19 blank | 21 comment | 17 complexity | d35a02c89fe17ea89b6ec6cd69ac1a6c MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, MPL-2.0-no-copyleft-exception
  1. /******************************************************************************
  2. * MODULE : tm_button.cpp
  3. * DESCRIPTION: Text widgets for output only
  4. * COPYRIGHT : (C) 1999 Joris van der Hoeven
  5. *******************************************************************************
  6. * This software falls under the GNU general public license version 3 or later.
  7. * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
  8. * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
  9. ******************************************************************************/
  10. #include "boxes.hpp"
  11. #include "Boxes/construct.hpp"
  12. #include "font.hpp"
  13. #include "tm_frame.hpp"
  14. #include "message.hpp"
  15. #ifdef AQUATEXMACS
  16. #include "Cocoa/aqua_simple_widget.h"
  17. #else
  18. #ifdef QTTEXMACS
  19. #include "Qt/qt_simple_widget.hpp"
  20. #else
  21. #include "Widkit/simple_wk_widget.hpp"
  22. #endif
  23. #endif
  24. /******************************************************************************
  25. * Text widgets
  26. ******************************************************************************/
  27. class box_widget_rep: public simple_widget_rep {
  28. box b;
  29. bool transparent;
  30. SI X1, Y1, X2, Y2;
  31. int dw, dh;
  32. public:
  33. box_widget_rep (box b, bool trans, int dw, int dh);
  34. operator tree ();
  35. void handle_get_size_hint (SI& w, SI& h);
  36. void handle_repaint (SI x1, SI y1, SI x2, SI y2);
  37. };
  38. box_widget_rep::box_widget_rep (
  39. box b2, bool trans2, int dw2, int dh2):
  40. simple_widget_rep (), b (b2),
  41. transparent (trans2), dw (dw2+2*PIXEL), dh (dh2+2*PIXEL) {}
  42. box_widget_rep::operator tree () {
  43. return tree (TUPLE, "box", (tree) b);
  44. }
  45. #define SHRINK 6
  46. void
  47. box_widget_rep::handle_get_size_hint (SI& w, SI& h) {
  48. X1= b->x1; Y1= b->y1;
  49. X2= b->x2; Y2= b->y2;
  50. w = ((X2- X1+ SHRINK- 1)/SHRINK)+ 2*dw;
  51. h = ((Y2- Y1+ SHRINK- 1)/SHRINK)+ 2*dh;
  52. abs_round (w, h);
  53. }
  54. void
  55. box_widget_rep::handle_repaint (SI x1, SI y1, SI x2, SI y2) {
  56. (void) x1; (void) y1; (void) x2; (void) y2;
  57. renderer ren= get_renderer (this);
  58. #if defined (QTTEXMACS) || defined(AQUATEXMACS)
  59. SI w,h;
  60. handle_get_size_hint (w,h);
  61. #endif
  62. if (!transparent) {
  63. ren->set_background (light_grey);
  64. ren->set_color (light_grey);
  65. ren->fill (0, -h, w, 0);
  66. }
  67. ren->set_shrinking_factor (SHRINK);
  68. rectangles l (rectangle (0, 0, w, h));
  69. SI x= ((SHRINK*w-b->w())>>1) - b->x1;
  70. SI y= ((SHRINK*h-b->h())>>1) - b->y1 - SHRINK*h;
  71. b->redraw (ren, path(), l, x, y);
  72. ren->set_shrinking_factor (1);
  73. }
  74. /******************************************************************************
  75. * Interface
  76. ******************************************************************************/
  77. widget
  78. box_widget (box b, bool tr) {
  79. return widget (tm_new<box_widget_rep> (b, tr, 3*PIXEL, 3*PIXEL));
  80. }
  81. widget
  82. box_widget (scheme_tree p, string s, color col, bool trans, bool ink) {
  83. string family = "roman";
  84. string fn_class= "mr";
  85. string series = "medium";
  86. string shape = "normal";
  87. int sz = 10;
  88. int dpi = 600;
  89. int n = arity (p);
  90. if ((n >= 1) && is_atomic (p[0])) family = as_string (p[0]);
  91. if ((n >= 2) && is_atomic (p[1])) fn_class= as_string (p[1]);
  92. if ((n >= 3) && is_atomic (p[2])) series = as_string (p[2]);
  93. if ((n >= 4) && is_atomic (p[3])) shape = as_string (p[3]);
  94. if ((n >= 5) && is_atomic (p[4])) sz = as_int (p[4]);
  95. if ((n >= 6) && is_atomic (p[5])) dpi = as_int (p[5]);
  96. font fn= find_font (family, fn_class, series, shape, sz, dpi);
  97. box b = text_box (decorate (), 0, s, fn, col);
  98. if (ink) b= resize_box (decorate (), b, b->x3, b->y3, b->x4, b->y4, true);
  99. return box_widget (b, trans);
  100. }
  101. /******************************************************************************
  102. * Getting extents of a typesetted tree
  103. * Application: get window size for widget tree
  104. ******************************************************************************/
  105. #include "gui.hpp"
  106. #include "drd_std.hpp"
  107. #include "drd_info.hpp"
  108. #include "convert.hpp"
  109. #include "formatter.hpp"
  110. #include "Format/format.hpp"
  111. void use_modules (tree t);
  112. edit_env
  113. get_init_environment (tree doc, drd_info& drd) {
  114. hashmap<string,tree> h1 (UNINIT), h2 (UNINIT), h3 (UNINIT), h4 (UNINIT);
  115. edit_env env (drd, "none", h1, h2, h3, h4);
  116. env->write_default_env ();
  117. bool ok;
  118. tree t, style= extract (doc, "style");
  119. hashmap<string,tree> H;
  120. get_server () -> style_get_cache (style, H, t, ok);
  121. if (ok) {
  122. env->patch_env (H);
  123. ok= drd->set_locals (t);
  124. drd->set_environment (H);
  125. }
  126. if (!ok) {
  127. ASSERT (is_tuple (style), "tuple expected as style");
  128. tree t (USE_PACKAGE, A (style));
  129. env->exec (t);
  130. env->read_env (H);
  131. drd->heuristic_init (H);
  132. }
  133. use_modules (env->read (THE_MODULES));
  134. // FIXME: extract (doc, "init")
  135. // env->write (PAGE_TYPE, "a5");
  136. env->update ();
  137. return env;
  138. }
  139. tree
  140. tree_extents (tree doc) {
  141. drd_info drd ("none", std_drd);
  142. edit_env env= get_init_environment (doc, drd);
  143. tree t= extract (doc, "body");
  144. lazy lz= make_lazy (env, t, path ());
  145. format vf= make_query_vstream_width (array<line_item>(), array<line_item>());
  146. format rf= lz->query (LAZY_BOX, vf);
  147. SI w= ((format_vstream) rf)->width;
  148. box b= (box) lz->produce (LAZY_BOX, make_format_width (w));
  149. SI h= b->h ();
  150. w += env->get_length (PAGE_SCREEN_LEFT);
  151. w += env->get_length (PAGE_SCREEN_RIGHT);
  152. h += env->get_length (PAGE_SCREEN_TOP);
  153. h += env->get_length (PAGE_SCREEN_BOT);
  154. return tuple (as_tree ((w / (5*PIXEL)) + 1), as_tree ((h / (5*PIXEL)) + 1));
  155. }