1 
2 /******************************************************************************
3 * MODULE     : qt_simple_widget.hpp
4 * DESCRIPTION: A widget containing a TeXmacs canvas.
5 * COPYRIGHT  : (C) 2008  Massimiliano Gubinelli
6 *******************************************************************************
7 * This software falls under the GNU general public license version 3 or later.
8 * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
9 * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
10 ******************************************************************************/
11 
12 #ifndef QT_SIMPLE_WIDGET_HPP
13 #define QT_SIMPLE_WIDGET_HPP
14 
15 #include "qt_widget.hpp"
16 #include "QTMScrollView.hpp"
17 #include "QTMWidget.hpp"
18 
19 /*! A widget containing a TeXmacs canvas.
20 
21  This canvas can be used both for input or output of typesetted documents.
22  Editors (editor_rep), output-only widgets (box_widget_rep) and
23  other classes are extensions to a "simple_widget", quite a misnomer...
24 
25  MEMORY POLICY: as usual, we give ownership of the QWidget to the caller of
26  as_qwidget(), which in our case will be one of qt_tm_widget_rep or
27  qt_tm_embedded_rep. These will embed our QWidget in a QLayout who will reparent
28  it to the QWidget using the layout (e.g. QTMWindow::centralWidget())
29   */
30 class qt_simple_widget_rep: public qt_widget_rep {
31 
32     // We keep a pointer to ourselves to avoid accidental deletion by our own
33     // QTMWidget, who keeps a smart pointer to us.
34     // (not sure whether this works/is necessary, though)
35   qt_widget self;
36 
37   typedef struct t_slot_entry {
38     int seq;
39     slot_id id;
40     blackbox val;
t_slot_entryqt_simple_widget_rep::t_slot_entry41     t_slot_entry() : seq(-1), id (slot_id__LAST), val (blackbox()) { }
t_slot_entryqt_simple_widget_rep::t_slot_entry42     t_slot_entry(const t_slot_entry& other)
43     : seq (other.seq), id (other.id), val (other.val) { };
operator <qt_simple_widget_rep::t_slot_entry44     bool operator< (const t_slot_entry& b) const { return this->seq < b.seq; }
45   } t_slot_entry;
46 
47   t_slot_entry sent_slots[slot_id__LAST];
48 
49   int sequencer;
50 
51 public:
52   qt_simple_widget_rep ();
53 
54   virtual bool is_editor_widget ();
55   virtual void handle_get_size_hint (SI& w, SI& h);
56   virtual void handle_notify_resize (SI w, SI h);
57   virtual void handle_keypress (string key, time_t t);
58   virtual void handle_keyboard_focus (bool has_focus, time_t t);
59   virtual void handle_mouse (string kind, SI x, SI y, int mods, time_t t);
60   virtual void handle_set_zoom_factor (double zoom);
61   virtual void handle_clear (SI x1, SI y1, SI x2, SI y2);
62   virtual void handle_repaint (renderer win, SI x1, SI y1, SI x2, SI y2);
63 
64     ////////////////////// Handling of TeXmacs' messages
65 
66   void save_send_slot (slot s, blackbox val);
67   void reapply_sent_slots();
68   virtual void      send (slot s, blackbox val);
69   virtual blackbox query (slot s, int type_id);
70   virtual widget    read (slot s, blackbox index);
71 
72     ////////////////////// Qt semantics of abstract texmacs widgets
73 
74   virtual QAction* as_qaction();
75   virtual QWidget* as_qwidget();
76 
canvas()77   QTMWidget*         canvas () { return qobject_cast<QTMWidget*> (qwid); }
scrollarea()78   QTMScrollView* scrollarea () { return qobject_cast<QTMScrollView*> (qwid); }
79 };
80 
concrete_simple_widget(qt_widget w)81 inline qt_simple_widget_rep* concrete_simple_widget (qt_widget w) {
82   return static_cast<qt_simple_widget_rep*>(w.rep);
83 }
84 
concrete_simple_widget(widget w)85 inline qt_simple_widget_rep* concrete_simple_widget (widget w) {
86   return static_cast<qt_simple_widget_rep*>(w.rep);
87 }
88 
89 // Export for TeXmacs' use
90 typedef qt_simple_widget_rep simple_widget_rep;
91 
92 #endif // defined QT_SIMPLE_WIDGET_HPP
93