prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / guicast / bctextbox.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BCTEXTBOX_H
23 #define BCTEXTBOX_H
24
25 #include "bclistbox.h"
26 #include "bcsubwindow.h"
27 #include "bctumble.h"
28 #include "fonts.h"
29 #include "bctextbox.inc"
30 #include "bctimer.inc"
31
32 #define BCCURSORW 2
33
34
35
36
37 class BC_TextBoxSuggestions;
38 class BC_ScrollTextBoxYScroll;
39
40
41 class BC_TextBox : public BC_SubWindow
42 {
43         char *text;
44         wchar_t *wtext;
45 public:
46         BC_TextBox(int x, int y, int w, int rows, int size, char *text,
47                 int has_border=1, int font=MEDIUMFONT);
48         BC_TextBox(int x, int y, int w, int rows, int size, wchar_t *wtext,
49                 int has_border=1, int font=MEDIUMFONT);
50         BC_TextBox(int x, int y, int w, int rows, const char *text,
51                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
52         BC_TextBox(int x, int y, int w, int rows, const wchar_t *wtext,
53                 int has_border=1, int font=MEDIUMFONT, int is_utf8=1);
54         BC_TextBox(int x, int y, int w, int rows, int64_t text,
55                 int has_border=1, int font=MEDIUMFONT);
56         BC_TextBox(int x, int y, int w, int rows, float text,
57                 int has_border=1, int font=MEDIUMFONT, int precision=4);
58         BC_TextBox(int x, int y, int w, int rows,
59                 int text, int has_border=1, int font=MEDIUMFONT);
60         virtual ~BC_TextBox();
61
62
63         friend class BC_TextBoxSuggestions;
64
65
66 // Whenever the contents of the text change
67         virtual int handle_event() { return 0; };
68 // Whenever the position of the text changes
69         virtual int motion_event() { return 0; };
70         void set_selection(int char1, int char2, int ibeam);
71         int update(const char *text);
72         int update(const wchar_t *wtext);
73         int update(int64_t value);
74         int update(float value);
75         void disable();
76         void enable();
77         int get_enabled();
78         int get_rows();
79
80         int initialize();
81
82         int focus_in_event();
83         int focus_out_event();
84         int cursor_enter_event();
85         int cursor_leave_event();
86         int cursor_motion_event();
87         virtual int button_press_event();
88         int button_release_event();
89         int repeat_event(int64_t repeat_id);
90         int keypress_event();
91         int activate();
92         int deactivate();
93         const char* get_text();
94         const wchar_t* get_wtext();
95         const char* get_utf8text();
96         void set_text(char *text, int isz);
97         int get_text_rows();
98 // Set top left of text view
99         void set_text_row(int row);
100         int get_text_row();
101         int reposition_window(int x, int y, int w = -1, int rows = -1);
102         int uses_text();
103 #ifdef X_HAVE_UTF8_STRING
104         int utf8seek(int i, int reverse);
105 #endif
106         static int calculate_h(BC_WindowBase *gui, int font, int has_border, int rows);
107         static int calculate_row_h(int rows, BC_WindowBase *parent_window, int has_border = 1, int font = MEDIUMFONT);
108         static int pixels_to_rows(BC_WindowBase *window, int font, int pixels);
109         void set_precision(int precision);
110 // Whether to draw every time there is a keypress or rely on user to
111 // follow up every keypress with an update().
112         void set_keypress_draw(int value);
113         int get_ibeam_letter();
114         void set_ibeam_letter(int number, int redraw = 1);
115 // Used for custom formatting text boxes
116         int get_last_keypress();
117 // Table of separators to skip.  Used by time textboxes
118 // The separator format is "0000:0000".  Things not alnum are considered
119 // separators.  The alnums are replaced by user text.
120         void set_separators(const char *separators);
121
122 // 1 - selects text, -1 - deselects, 0 - do nothing
123 // in all cases it returns text_selected after the operation
124         int select_whole_text(int select);
125         void cycle_textboxes(int amout);
126
127 // Compute suggestions for a path
128 // If entries is null, just search absolute paths
129         int calculate_suggestions(ArrayList<BC_ListBoxItem*> *entries);
130
131
132 // User computes suggestions after handle_event.
133 // The array is copied to a local variable.
134 // A highlighted extension is added if 1 suggestion or a popup appears
135 // if multiple suggestions.
136 // column - starting column to replace
137         void set_suggestions(ArrayList<char*> *suggestions, int column);
138         BC_ScrollTextBoxYScroll *yscroll;
139
140 private:
141         int reset_parameters(int rows, int has_border, int font, int size);
142         void draw(int flush);
143         void draw_border();
144         void draw_cursor();
145         void copy_selection(int clipboard_num);
146         void paste_selection(int clipboard_num);
147         void delete_selection(int letter1, int letter2, int text_len);
148         void insert_text(const wchar_t *wcp, int len=-1);
149 // Reformat text according to separators.
150 // ibeam_left causes the ibeam to move left.
151         int is_separator(const char *txt, int i);
152         void do_separators(int ibeam_left);
153         void get_ibeam_position(int &x, int &y);
154         void find_ibeam(int dispatch_event);
155         void select_word(int &letter1, int &letter2, int ibeam_letter);
156         void select_line(int &letter1, int &letter2, int ibeam_letter);
157         int get_cursor_letter(int cursor_x, int cursor_y);
158         int get_cursor_letter2(int cursor_x, int cursor_y);
159         int get_row_h(int rows);
160         void default_keypress(int &dispatch_event, int &result);
161         int tstrlen();
162         int tstrcmp(const char *cp);
163         char *tstrcpy(const char *cp);
164         char *tstrcat(const char *cp);
165         int text_update(const wchar_t *wcp, int wsz, char *tcp, int tsz);
166         int wtext_update();
167
168 // Top left of text relative to window
169         int text_x, text_y;
170 // Top left of cursor relative to text
171         int ibeam_x, ibeam_y;
172
173         int ibeam_letter;
174         int highlight_letter1, highlight_letter2;
175         int highlight_letter3, highlight_letter4;
176         int text_x1, text_start, text_end;
177         int text_selected, word_selected, line_selected;
178         int text_ascent, text_descent, text_height;
179         int left_margin, right_margin, top_margin, bottom_margin;
180         int has_border;
181         int font;
182         int rows;
183         int highlighted;
184         int high_color, back_color;
185         int background_color;
186         int size, tsize, dirty;
187         int wlen, wsize, *positions, plen;
188         char temp_string[KEYPRESSLEN];
189         int is_utf8;
190         int active;
191         int enabled;
192         int precision;
193         int keypress_draw;
194 // Cause the repeater to skip a cursor refresh if a certain event happened
195 // within a certain time of the last repeat event
196         Timer *skip_cursor;
197 // Used for custom formatting text boxes
198         int last_keypress;
199         const char *separators;
200         ArrayList<BC_ListBoxItem*> *suggestions;
201         BC_TextBoxSuggestions *suggestions_popup;
202         int suggestion_column;
203 };
204
205
206
207 class BC_TextBoxSuggestions : public BC_ListBox
208 {
209 public:
210         BC_TextBoxSuggestions(BC_TextBox *text_box, int x, int y);
211         virtual ~BC_TextBoxSuggestions();
212
213         int selection_changed();
214         int handle_event();
215
216
217         BC_TextBox *text_box;
218 };
219
220
221
222 class BC_ScrollTextBoxText;
223 class BC_ScrollTextBoxYScroll;
224
225
226 class BC_ScrollTextBox
227 {
228 public:
229         BC_ScrollTextBox(BC_WindowBase *parent_window,
230                 int x, int y, int w, int rows,
231                 const char *default_text, int default_size=BCTEXTLEN);
232         BC_ScrollTextBox(BC_WindowBase *parent_window,
233                 int x, int y, int w, int rows,
234                 const wchar_t *default_wtext, int default_size=BCTEXTLEN);
235         virtual ~BC_ScrollTextBox();
236         void create_objects();
237         virtual int handle_event();
238
239         const char* get_text();
240         const wchar_t* get_wtext();
241         void set_text(char *text, int isz);
242         int set_text_row(int n);
243         void update(const char *text);
244         void update(const wchar_t *wtext);
245         void set_selection(int char1, int char2, int ibeam);
246         void reposition_window(int x, int y, int w, int rows);
247         int get_x();
248         int get_y();
249         int get_w();
250         int get_h();
251 // Visible rows for resizing
252         int get_rows();
253
254         friend class BC_ScrollTextBoxText;
255         friend class BC_ScrollTextBoxYScroll;
256
257 private:
258         BC_ScrollTextBoxText *text;
259         BC_ScrollTextBoxYScroll *yscroll;
260         BC_WindowBase *parent_window;
261         const char *default_text;
262         const wchar_t *default_wtext;
263         int default_size;
264         int x, y, w, rows;
265 };
266
267 class BC_ScrollTextBoxText : public BC_TextBox
268 {
269 public:
270         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const char *text);
271         BC_ScrollTextBoxText(BC_ScrollTextBox *gui, const wchar_t *wtext);
272         virtual ~BC_ScrollTextBoxText();
273         int handle_event();
274         int motion_event();
275         BC_ScrollTextBox *gui;
276 };
277
278 class BC_ScrollTextBoxYScroll : public BC_ScrollBar
279 {
280 public:
281         BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui);
282         virtual ~BC_ScrollTextBoxYScroll();
283         int handle_event();
284         BC_ScrollTextBox *gui;
285 };
286
287
288
289
290 class BC_PopupTextBoxText;
291 class BC_PopupTextBoxList;
292
293 class BC_PopupTextBox
294 {
295 public:
296         BC_PopupTextBox(BC_WindowBase *parent_window,
297                 ArrayList<BC_ListBoxItem*> *list_items,
298                 const char *default_text, int x, int y,
299                 int text_w, int list_h, int list_format = LISTBOX_TEXT);
300         virtual ~BC_PopupTextBox();
301         int create_objects();
302         virtual int handle_event();
303         const char* get_text();
304         const wchar_t* get_wtext();
305         int get_number();
306         int get_x();
307         int get_y();
308         int get_w();
309         int get_h();
310         void update(const char *text);
311         void update_list(ArrayList<BC_ListBoxItem*> *data);
312         void reposition_window(int x, int y);
313
314         friend class BC_PopupTextBoxText;
315         friend class BC_PopupTextBoxList;
316
317 private:
318         int x, y, text_w, list_h;
319         int list_format;
320         const char *default_text;
321         const wchar_t *default_wtext;
322         ArrayList<BC_ListBoxItem*> *list_items;
323         BC_PopupTextBoxText *textbox;
324         BC_PopupTextBoxList *listbox;
325         BC_WindowBase *parent_window;
326 };
327
328 class BC_PopupTextBoxText : public BC_TextBox
329 {
330 public:
331         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const char *text);
332         BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y, const wchar_t *wtext);
333         virtual ~BC_PopupTextBoxText();
334         int handle_event();
335         BC_PopupTextBox *popup;
336 };
337
338 class BC_PopupTextBoxList : public BC_ListBox
339 {
340 public:
341         BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y);
342         int handle_event();
343         BC_PopupTextBox *popup;
344 };
345
346
347 class BC_TumbleTextBoxText;
348 class BC_TumbleTextBoxTumble;
349
350 class BC_TumbleTextBox
351 {
352 public:
353         BC_TumbleTextBox(BC_WindowBase *parent_window,
354                 int64_t default_value,
355                 int64_t min,
356                 int64_t max,
357                 int x,
358                 int y,
359                 int text_w);
360         BC_TumbleTextBox(BC_WindowBase *parent_window,
361                 int default_value,
362                 int min,
363                 int max,
364                 int x,
365                 int y,
366                 int text_w);
367         BC_TumbleTextBox(BC_WindowBase *parent_window,
368                 float default_value,
369                 float min,
370                 float max,
371                 int x,
372                 int y,
373                 int text_w);
374         virtual ~BC_TumbleTextBox();
375
376         int create_objects();
377         void reset();
378         virtual int handle_event();
379         const char* get_text();
380         const wchar_t* get_wtext();
381         BC_TextBox* get_textbox();
382         int update(const char *value);
383         int update(int64_t value);
384         int update(float value);
385         int get_x();
386         int get_y();
387         int get_w();
388         int get_h();
389         void disable();
390         void enable();
391         int get_enabled();
392         void reposition_window(int x, int y);
393         void set_boundaries(int64_t min, int64_t max);
394         void set_boundaries(float min, float max);
395         void set_precision(int precision);
396         void set_increment(float value);
397
398         friend class BC_TumbleTextBoxText;
399         friend class BC_TumbleTextBoxTumble;
400
401 private:
402         int x, y, text_w;
403         int64_t default_value, min, max;
404         float default_value_f, min_f, max_f;
405         int use_float;
406         int precision;
407         float increment;
408         BC_TumbleTextBoxText *textbox;
409         BC_Tumbler *tumbler;
410         BC_WindowBase *parent_window;
411 };
412
413 class BC_TumbleTextBoxText : public BC_TextBox
414 {
415 public:
416         BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
417                 int64_t default_value,
418                 int64_t min,
419                 int64_t max,
420                 int x,
421                 int y);
422         BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
423                 float default_value,
424                 float min,
425                 float max,
426                 int x,
427                 int y);
428         BC_TumbleTextBoxText(BC_TumbleTextBox *popup, int x, int y);
429         virtual ~BC_TumbleTextBoxText();
430         int handle_event();
431         int button_press_event();
432         BC_TumbleTextBox *popup;
433 };
434
435
436 #endif