r878: This is Cinelerra 2.1.
[cinelerra_cv/ct.git] / guicast / bctextbox.h
blob60f8059b3edd9793045a8a870acca9b2edaf6471
1 #ifndef BCTEXTBOX_H
2 #define BCTEXTBOX_H
4 #include "bclistbox.h"
5 #include "bcsubwindow.h"
6 #include "bctumble.h"
7 #include "fonts.h"
8 #include "bctimer.inc"
10 #define BCCURSORW 2
14 class BC_TextBox : public BC_SubWindow
16 public:
17 BC_TextBox(int x,
18 int y,
19 int w,
20 int rows,
21 char *text,
22 int has_border = 1,
23 int font = MEDIUMFONT);
24 BC_TextBox(int x,
25 int y,
26 int w,
27 int rows,
28 int64_t text,
29 int has_border = 1,
30 int font = MEDIUMFONT);
31 BC_TextBox(int x,
32 int y,
33 int w,
34 int rows,
35 int text,
36 int has_border = 1,
37 int font = MEDIUMFONT);
38 BC_TextBox(int x,
39 int y,
40 int w,
41 int rows,
42 float text,
43 int has_border = 1,
44 int font = MEDIUMFONT,
45 int precision = 4);
46 virtual ~BC_TextBox();
48 // Whenever the contents of the text change
49 virtual int handle_event() { return 0; };
50 // Whenever the position of the text changes
51 virtual int motion_event() { return 0; };
52 void set_selection(int char1, int char2, int ibeam);
53 int update(char *text);
54 int update(int64_t value);
55 int update(float value);
56 void disable();
57 void enable();
58 int get_enabled();
60 int initialize();
62 int focus_in_event();
63 int focus_out_event();
64 int cursor_enter_event();
65 int cursor_leave_event();
66 int cursor_motion_event();
67 virtual int button_press_event();
68 int button_release_event();
69 int repeat_event(int64_t repeat_id);
70 int keypress_event();
71 int activate();
72 int deactivate();
73 char* get_text();
74 int get_text_rows();
75 // Set top left of text view
76 void set_text_row(int row);
77 int get_text_row();
78 int reposition_window(int x, int y, int w = -1, int rows = -1);
79 int uses_text();
80 static int calculate_h(BC_WindowBase *gui, int font, int has_border, int rows);
81 static int calculate_row_h(int rows, BC_WindowBase *parent_window, int has_border = 1, int font = MEDIUMFONT);
82 static int pixels_to_rows(BC_WindowBase *window, int font, int pixels);
83 void set_precision(int precision);
84 // Whether to draw every time there is a keypress or rely on user to
85 // follow up every keypress with an update().
86 void set_keypress_draw(int value);
87 int get_ibeam_letter();
88 void set_ibeam_letter(int number, int redraw = 1);
89 // Used for custom formatting text boxes
90 int get_last_keypress();
91 // Table of separators to skip. Used by time textboxes
92 // The separator format is "0000:0000". Things not alnum are considered
93 // separators. The alnums are replaced by user text.
94 void set_separators(char *separators);
96 // 1 - selects text, -1 - deselects, 0 - do nothing
97 // in all cases it returns text_selected after the operation
98 int select_whole_text(int select);
99 void cycle_textboxes(int amout);
101 private:
102 int reset_parameters(int rows, int has_border, int font);
103 void draw();
104 void draw_border();
105 void draw_cursor();
106 void copy_selection(int clipboard_num);
107 void paste_selection(int clipboard_num);
108 void delete_selection(int letter1, int letter2, int text_len);
109 void insert_text(char *string);
110 // Reformat text according to separators.
111 // ibeam_left causes the ibeam to move left.
112 void do_separators(int ibeam_left);
113 void get_ibeam_position(int &x, int &y);
114 void find_ibeam(int dispatch_event);
115 void select_word(int &letter1, int &letter2, int ibeam_letter);
116 int get_cursor_letter(int cursor_x, int cursor_y);
117 int get_row_h(int rows);
118 void default_keypress(int &dispatch_event, int &result);
121 // Top left of text relative to window
122 int text_x, text_y;
123 // Top left of cursor relative to text
124 int ibeam_x, ibeam_y;
126 int ibeam_letter;
127 int highlight_letter1, highlight_letter2;
128 int highlight_letter3, highlight_letter4;
129 int text_x1, text_start, text_end, text_selected, word_selected;
130 int text_ascent, text_descent, text_height;
131 int left_margin, right_margin, top_margin, bottom_margin;
132 int has_border;
133 int font;
134 int rows;
135 int highlighted;
136 int high_color, back_color;
137 int background_color;
138 char text[BCTEXTLEN], text_row[BCTEXTLEN], temp_string[2];
139 int active;
140 int enabled;
141 int precision;
142 int keypress_draw;
143 // Cause the repeater to skip a cursor refresh if a certain event happened
144 // within a certain time of the last repeat event
145 Timer *skip_cursor;
146 // Used for custom formatting text boxes
147 int last_keypress;
148 char *separators;
153 class BC_ScrollTextBoxText;
154 class BC_ScrollTextBoxYScroll;
157 class BC_ScrollTextBox
159 public:
160 BC_ScrollTextBox(BC_WindowBase *parent_window,
161 int x,
162 int y,
163 int w,
164 int rows,
165 char *default_text);
166 virtual ~BC_ScrollTextBox();
167 void create_objects();
168 virtual int handle_event();
170 char* get_text();
171 void update(char *text);
172 void reposition_window(int x, int y, int w, int rows);
173 int get_x();
174 int get_y();
175 int get_w();
176 // Visible rows for resizing
177 int get_rows();
179 friend class BC_ScrollTextBoxText;
180 friend class BC_ScrollTextBoxYScroll;
182 private:
183 BC_ScrollTextBoxText *text;
184 BC_ScrollTextBoxYScroll *yscroll;
185 BC_WindowBase *parent_window;
186 char *default_text;
187 int x, y, w, rows;
190 class BC_ScrollTextBoxText : public BC_TextBox
192 public:
193 BC_ScrollTextBoxText(BC_ScrollTextBox *gui);
194 virtual ~BC_ScrollTextBoxText();
195 int handle_event();
196 int motion_event();
197 BC_ScrollTextBox *gui;
200 class BC_ScrollTextBoxYScroll : public BC_ScrollBar
202 public:
203 BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui);
204 virtual ~BC_ScrollTextBoxYScroll();
205 int handle_event();
206 BC_ScrollTextBox *gui;
212 class BC_PopupTextBoxText;
213 class BC_PopupTextBoxList;
215 class BC_PopupTextBox : public BC_RelocatableWidget
217 public:
218 BC_PopupTextBox(BC_WindowBase *parent_window,
219 ArrayList<BC_ListBoxItem*> *list_items,
220 char *default_text,
221 int x,
222 int y,
223 int text_w,
224 int list_h);
225 virtual ~BC_PopupTextBox();
226 int create_objects();
227 virtual int handle_event();
228 char* get_text();
229 int get_number();
230 int get_x();
231 int get_y();
232 int get_w();
233 int get_h();
234 void update(char *text);
235 void update_list(ArrayList<BC_ListBoxItem*> *data);
236 int reposition_widget(int x, int y, int w = -1, int h = -1);
237 void reposition_window(int x, int y);
239 friend class BC_PopupTextBoxText;
240 friend class BC_PopupTextBoxList;
242 private:
243 int x, y, text_w, list_h;
244 char *default_text;
245 ArrayList<BC_ListBoxItem*> *list_items;
246 BC_PopupTextBoxText *textbox;
247 BC_PopupTextBoxList *listbox;
248 BC_WindowBase *parent_window;
251 class BC_PopupTextBoxText : public BC_TextBox
253 public:
254 BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y);
255 virtual ~BC_PopupTextBoxText();
256 int handle_event();
257 BC_PopupTextBox *popup;
260 class BC_PopupTextBoxList : public BC_ListBox
262 public:
263 BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y);
264 int handle_event();
265 BC_PopupTextBox *popup;
269 class BC_TumbleTextBoxText;
270 class BC_TumbleTextBoxTumble;
272 class BC_TumbleTextBox : public BC_RelocatableWidget
274 public:
275 BC_TumbleTextBox(BC_WindowBase *parent_window,
276 int64_t default_value,
277 int64_t min,
278 int64_t max,
279 int x,
280 int y,
281 int text_w);
282 BC_TumbleTextBox(BC_WindowBase *parent_window,
283 int default_value,
284 int min,
285 int max,
286 int x,
287 int y,
288 int text_w);
289 BC_TumbleTextBox(BC_WindowBase *parent_window,
290 float default_value,
291 float min,
292 float max,
293 int x,
294 int y,
295 int text_w);
296 virtual ~BC_TumbleTextBox();
298 int create_objects();
299 void reset();
300 virtual int handle_event();
301 char* get_text();
302 int update(char *value);
303 int update(int64_t value);
304 int update(float value);
305 int get_x();
306 int get_y();
307 int get_w();
308 int get_h();
309 int reposition_widget(int x, int y, int w = -1, int h = -1);
310 void reposition_window(int x, int y);
311 void set_boundaries(int64_t min, int64_t max);
312 void set_boundaries(float min, float max);
313 void set_precision(int precision);
314 void set_increment(float value);
316 friend class BC_TumbleTextBoxText;
317 friend class BC_TumbleTextBoxTumble;
319 private:
320 int x, y, text_w;
321 int64_t default_value, min, max;
322 float default_value_f, min_f, max_f;
323 int use_float;
324 int precision;
325 float increment;
326 BC_TumbleTextBoxText *textbox;
327 BC_Tumbler *tumbler;
328 BC_WindowBase *parent_window;
331 class BC_TumbleTextBoxText : public BC_TextBox
333 public:
334 BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
335 int64_t default_value,
336 int64_t min,
337 int64_t max,
338 int x,
339 int y);
340 BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
341 float default_value,
342 float min,
343 float max,
344 int x,
345 int y);
346 BC_TumbleTextBoxText(BC_TumbleTextBox *popup, int x, int y);
347 virtual ~BC_TumbleTextBoxText();
348 int handle_event();
349 int button_press_event();
350 BC_TumbleTextBox *popup;
354 #endif