libt3widget
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
editwindow.h
1 /* Copyright (C) 2011-2013 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_WIDGET_EDITWINDOW_H
15 #define T3_WIDGET_EDITWINDOW_H
16 
17 namespace t3_widget {
18  class edit_window_t;
19 }; // namespace
20 
21 #include <t3widget/widgets/widget.h>
22 #include <t3widget/widgets/scrollbar.h>
23 #include <t3widget/widgets/listpane.h>
24 #include <t3widget/textbuffer.h>
25 #include <t3widget/key.h>
26 #include <t3widget/interfaces.h>
27 #include <t3widget/autocompleter.h>
28 
29 namespace t3_widget {
30 
31 class finder_t;
32 class wrap_info_t;
33 class goto_dialog_t;
34 class find_dialog_t;
35 class replace_buttons_dialog_t;
36 
38 class T3_WIDGET_API edit_window_t : public widget_t, public center_component_t, public container_t, public bad_draw_recheck_t {
39  private:
40  class T3_WIDGET_LOCAL autocomplete_panel_t;
41 
42  static goto_dialog_t *goto_dialog;
43  static sigc::connection goto_connection;
44  static find_dialog_t *global_find_dialog;
45  static sigc::connection global_find_dialog_connection;
46  static finder_t global_finder;
47  static replace_buttons_dialog_t *replace_buttons;
48  static sigc::connection replace_buttons_connection;
49  static sigc::connection init_connected;
50 
51  struct T3_WIDGET_LOCAL implementation_t {
52  cleanup_t3_window_ptr edit_window,
53  indicator_window;
54  cleanup_ptr<scrollbar_t>::t scrollbar;
55  int screen_pos;
56  int tabsize;
57  bool focus;
58  bool tab_spaces;
62  find_dialog_t *find_dialog;
63  finder_t *finder;
64  wrap_type_t wrap_type;
65  wrap_info_t *wrap_info;
70  text_coordinate_t top_left;
71  int ins_mode,
72  last_set_pos;
73  bool auto_indent;
74  bool indent_aware_home;
75  bool show_tabs;
77  cleanup_ptr<autocompleter_t>::t autocompleter;
78  cleanup_ptr<autocomplete_panel_t>::t autocomplete_panel;
80  int repaint_min,
81  repaint_max;
83  implementation_t(void) : tab_spaces(false), find_dialog(NULL), finder(NULL),
84  wrap_type(wrap_type_t::NONE), wrap_info(NULL), ins_mode(0), last_set_pos(0),
85  auto_indent(true), indent_aware_home(true), show_tabs(false), autocompleter(NULL),
86  autocomplete_panel(NULL), repaint_min(0), repaint_max(INT_MAX)
87  {}
88  };
89  pimpl_ptr<implementation_t>::t impl;
90 
92  static void init(bool _init);
94  static const char *ins_string[];
96  static bool (text_buffer_t::*proces_char[])(key_t);
97 
99  void repaint_screen(void);
101  void inc_x(void);
103  void next_word(void);
105  void dec_x(void);
107  void previous_word(void);
109  void inc_y(void);
111  void dec_y(void);
113  void pgdn(void);
115  void pgup(void);
117  void home_key(void);
119  void end_key(void);
121  void reset_selection(void);
123  void set_selection_mode(key_t key);
125  void delete_selection(void);
126 
128  void find_activated(find_action_t action, finder_t *finder);
130  void set_wrap_internal(wrap_type_t wrap);
131 
132  void scroll(int lines);
133  void scrollbar_clicked(scrollbar_t::step_t step);
134  void scrollbar_dragged(int start);
135  void autocomplete_activated(void);
136 
137  protected:
139  cleanup_t3_window_ptr info_window;
146  virtual void draw_info_window(void);
147 
154  void activate_autocomplete(bool autocomplete_single);
155 
157  text_coordinate_t xy_to_text_coordinate(int x, int y);
159  void ensure_cursor_on_screen(void);
164  void update_repaint_lines(int start, int end);
165  public:
166  class T3_WIDGET_API view_parameters_t;
167 
172  edit_window_t(text_buffer_t *_text = NULL, const view_parameters_t *params = NULL);
173  ~edit_window_t(void);
174  virtual bool process_key(key_t key);
175  virtual bool set_size(optint height, optint width);
176  virtual void update_contents(void);
177  virtual void set_focus(focus_t focus);
178  virtual void force_redraw(void);
179  virtual void bad_draw_recheck(void);
180 
181  virtual void set_child_focus(window_component_t *target);
182  virtual bool is_child(window_component_t *widget);
183  virtual bool process_mouse_event(mouse_event_t event);
184 
191  void set_text(text_buffer_t *_text, const view_parameters_t *params = NULL);
193  text_buffer_t *get_text(void) const;
195  void undo(void);
197  void redo(void);
202  void cut_copy(bool cut);
206  void paste(void);
208  void select_all(void);
210  void insert_special(void);
212  void indent_selection(void);
214  void unindent_selection(void);
216  void goto_line(int line);
217 
219  void goto_line(void);
221  void find_replace(bool replace);
225  void find_next(bool backward);
230  void set_find_dialog(find_dialog_t *_find_dialog);
236  void set_finder(finder_t *_finder);
237 
239  void set_tabsize(int _tabsize);
241  void set_wrap(wrap_type_t wrap);
243  void set_tab_spaces(bool _tab_spaces);
245  void set_auto_indent(bool _auto_indent);
247  void set_indent_aware_home(bool _indent_aware_home);
249  void set_show_tabs(bool _show_tabs);
250 
252  int get_tabsize(void);
254  wrap_type_t get_wrap(void);
256  bool get_tab_spaces(void);
258  bool get_auto_indent(void);
260  bool get_indent_aware_home(void);
262  bool get_show_tabs(void);
263 
265  view_parameters_t *save_view_parameters(void);
267  void save_view_parameters(view_parameters_t *params);
268 
270  void set_autocompleter(autocompleter_t *_autocompleter);
272  void autocomplete(void);
273 };
274 
275 class T3_WIDGET_API edit_window_t::view_parameters_t {
276  friend class edit_window_t;
277 
278  private:
279  text_coordinate_t top_left;
280  wrap_type_t wrap_type;
281  int tabsize;
282  bool tab_spaces;
283  int ins_mode, last_set_pos;
284  bool auto_indent;
285  bool indent_aware_home;
286  bool show_tabs;
287 
289  void apply_parameters(edit_window_t *view) const;
290 
291  public:
292  view_parameters_t(void);
293  void set_tabsize(int _tabsize);
294  void set_wrap(wrap_type_t _wrap_type);
295  void set_tab_spaces(bool _tab_spaces);
296  void set_auto_indent(bool _auto_indent);
297  void set_indent_aware_home(bool _indent_aware_home);
298  void set_show_tabs(bool _show_tabs);
299 };
300 
301 class T3_WIDGET_LOCAL edit_window_t::autocomplete_panel_t : public popup_t {
302  private:
303  list_pane_t *list_pane;
304  public:
306  virtual bool process_key(key_t key);
307  virtual void set_position(optint top, optint left);
308  virtual bool set_size(optint height, optint width);
309 
310  void set_completions(string_list_base_t *completions);
311  size_t get_selected_idx(void) const;
312  void connect_activate(const sigc::slot<void> &slot);
313 };
314 
315 }; // namespace
316 #endif