1 
2 /******************************************************************************
3 * MODULE     : edit_interface.hpp
4 * DESCRIPTION: the interface for TeXmacs
5 * COPYRIGHT  : (C) 1999  Joris van der Hoeven
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 EDIT_INTERFACE_H
13 #define EDIT_INTERFACE_H
14 #include "editor.hpp"
15 #include "timer.hpp"
16 #include "widget.hpp"
17 
18 #define INPUT_NORMAL      0
19 #define INPUT_SEARCH      1
20 #define INPUT_REPLACE     2
21 #define INPUT_SPELL       3
22 #define INPUT_COMPLETE    4
23 
24 string MODE_LANGUAGE (string mode);
25 
26 class edit_interface_rep: virtual public editor_rep {
27 protected:
28   int           env_change;    // which things have been changed ?
29   time_t        last_change;   // time of last processed change
30   time_t        last_update;   // time of last update of menu, icons and footer
31   bool          do_animate;    // are we in an animation ?
32   time_t        next_animate;  // time for next animation
33   bool          full_screen;   // full screen mode ?
34   bool          got_focus;     // do we have keyboard focus ?
35   string        sh_s;          // current string for shortcuts
36   double        sh_mark;       // 0 or mark for undoing shortcut
37   string        pre_edit_s;    // pre-edit string
38   double        pre_edit_mark; // 0 or mark for undoing pre-edit
39   widget        popup_win;     // the current popup window
40   tree          message_l;     // a left message to display
41   tree          message_r;     // a right message to display
42   tree          last_l;        // last displayed left message
43   tree          last_r;        // last displayed right message
44   double        zoomf;         // the current zoom factor
45   double        magf;          // the current magnification factor
46   SI            pixel;         // current size of a pixel on the screen
47   rectangles    copy_always;   // for wiping out cursor
48   int           input_mode;    // INPUT_NORMAL, INPUT_SEARCH, INPUT_REPLACE
49 
50 protected:
51   SI            last_x, last_y;
52   time_t        last_t;
53   SI            start_x, start_y;
54   SI            end_x, end_y;
55   bool          table_selection;
56   int           mouse_adjusting;  // mask with active key modifiers upon click
57   rectangles    selection_rects;
58   array<rectangles> alt_selection_rects;
59   rectangles    env_rects;
60   rectangles    foc_rects;
61   rectangles    sem_rects;
62   bool          sem_correct;
63   cursor        oc;
64   bool          temp_invalid_cursor;
65   array<string> completions;
66   string        completion_prefix;
67   int           completion_pos;
68   renderer      shadow;
69   SI            vx1, vy1, vx2, vy2;
70   rectangles    stored_rects;
71   renderer      stored;
72   rectangles    locus_new_rects;
73   rectangles    locus_rects;
74   list<string>  mouse_ids;
75   list<string>  focus_ids;
76   int           cur_sb, cur_wb;
77   SI            cur_wx, cur_wy;
78 
79 public:
80   edit_interface_rep ();
81   ~edit_interface_rep ();
82   operator tree ();
83   void suspend ();
84   void resume ();
85   void keyboard_focus_on (string field);
86   void get_size (SI& wx, SI& wy);
87 
88   /* routines for dealing with shrinked coordinates */
89   int  get_pixel_size ();
90   SI   get_visible_width ();
91   SI   get_visible_height ();
92   SI   get_window_width ();
93   SI   get_window_height ();
94   void set_zoom_factor (double zoom);
95   void invalidate (SI x1, SI y1, SI x2, SI y2);
96   void invalidate (rectangles rs);
97   void invalidate_all ();
98   void update_visible ();
99   void scroll_to (SI x, SI y1);
100   void set_extents (SI x1, SI y1, SI x2, SI y2);
101 
102   /* repainting the window */
103   void draw_text (renderer ren, rectangles& l);
104   void draw_surround (renderer ren, rectangle r);
105   void draw_context (renderer ren, rectangle r);
106   void draw_env (renderer ren);
107   void draw_cursor (renderer ren);
108   void draw_selection (renderer ren, rectangle r);
109   void draw_graphics (renderer ren);
110   void draw_pre (renderer win, renderer ren, rectangle r);
111   void draw_post (renderer win, renderer ren, rectangle r);
112   void draw_with_shadow (renderer win, rectangle r);
113   void draw_with_stored (renderer win, rectangle r);
114 
115   /* handle changes */
116   void notify_change (int changed);
117   bool has_changed (int question);
118   int  idle_time (int event_type= ANY_EVENT);
119   int  change_time ();
120   void apply_changes ();
121   void animate ();
122 
123   /* miscellaneous */
124   void compute_env_rects (path p, rectangles& rs, bool recurse);
125   void cursor_visible ();
126   void selection_visible ();
127   void full_screen_mode (bool flag);
128   void before_menu_action ();
129   void after_menu_action ();
130   void cancel_menu_action ();
131   cursor search_cursor (path p);
132   selection search_selection (path start, path end);
133   rectangle get_window_extents ();
134 
135   /* keyboard handling */
136   int  get_input_mode ();
137   void set_input_mode (int mode);
138   void set_input_normal ();
139   bool in_normal_mode ();
140   bool in_search_mode ();
141   bool in_replace_mode ();
142   bool in_spell_mode ();
143   bool kbd_get_command (string which, string& help, command& cmd);
144   void interrupt_shortcut ();
145   bool try_shortcut (string comb);
146   tree kbd (string s);
147   tree kbd_shortcut (string s);
148   void key_press (string key);
149   void emulate_keyboard (string keys, string action= "");
150   bool complete_try ();
151   void complete_message ();
152   void complete_start (string prefix, array<string> compls);
153   bool complete_keypress (string key);
154   string session_complete_command (tree t);
155   void custom_complete (tree t);
156 
157   /* mouse handling */
158   void mouse_any (string s, SI x, SI y, int mods, time_t t);
159   void mouse_click (SI x, SI y);
160   bool mouse_extra_click (SI x, SI y);
161   void mouse_drag (SI x, SI y);
162   void mouse_select (SI x, SI y, int mods, bool drag);
163   void mouse_paste (SI x, SI y);
164   void mouse_adjust (SI x, SI y, int mods);
165   void mouse_adjust_selection (SI x, SI y, int mods);
166   void mouse_scroll (SI x, SI y, bool up);
167   cursor get_cursor ();
168   array<SI> get_mouse_position ();
169   void set_pointer (string name);
170   void set_pointer (string curs_name, string mask_name);
171   void update_mouse_loci ();
172   void update_focus_loci ();
173 
174   /* the footer */
175   tree compute_text_footer (tree st);
176   tree compute_operation_footer (tree st);
177   tree compute_compound_footer (tree t, path p);
178   bool set_latex_footer (tree st);
179   bool set_hybrid_footer (tree st);
180   void set_left_footer (tree l);
181   void append_left_footer (tree& l, string env_var);
182   void set_left_footer ();
183   void set_right_footer (tree r);
184   void set_right_footer ();
185   void set_footer ();
186   void set_message (tree l, tree r= "", bool temp= false);
187   void recall_message ();
188 
189   /* event handlers */
190   bool is_editor_widget ();
191   void handle_get_size_hint (SI& w, SI& h);
192   void handle_notify_resize (SI w, SI h);
193   void handle_keypress (string key, time_t t);
194   void handle_keyboard_focus (bool has_focus, time_t t);
195   void handle_mouse (string kind, SI x, SI y, int mods, time_t t);
196   void handle_set_zoom_factor (double zoomf);
197   void handle_clear (renderer win, SI x1, SI y1, SI x2, SI y2);
198   void handle_repaint (renderer win, SI x1, SI y1, SI x2, SI y2);
199 
200   friend class interactive_command_rep;
201   friend class tm_window_rep;
202 };
203 
204 #endif // defined EDIT_INTERFACE_H
205