1 #include "bcclipboard.h"
2 #include "bclistboxitem.h"
3 #include "bcresources.h"
16 BC_TextBox::BC_TextBox(int x,
23 : BC_SubWindow(x, y, w, 0, -1)
26 reset_parameters(rows, has_border, font);
27 strcpy(this->text, text);
30 BC_TextBox::BC_TextBox(int x,
37 : BC_SubWindow(x, y, w, 0, -1)
40 reset_parameters(rows, has_border, font);
41 sprintf(this->text, "%lld", text);
44 BC_TextBox::BC_TextBox(int x,
51 : BC_SubWindow(x, y, w, 0, -1)
54 reset_parameters(rows, has_border, font);
55 sprintf(this->text, "%0.4f", text);
58 BC_TextBox::BC_TextBox(int x,
65 : BC_SubWindow(x, y, w, 0, -1)
68 reset_parameters(rows, has_border, font);
69 sprintf(this->text, "%d", text);
72 BC_TextBox::~BC_TextBox()
74 if(skip_cursor) delete skip_cursor;
77 int BC_TextBox::reset_parameters(int rows, int has_border, int font)
80 this->has_border = has_border;
84 highlight_letter1 = highlight_letter2 = 0;
85 highlight_letter3 = highlight_letter4 = 0;
88 text_selected = word_selected = 0;
94 skip_cursor = new Timer;
101 int BC_TextBox::initialize()
104 skip_cursor = new Timer;
105 skip_cursor->update();
107 text_ascent = get_text_ascent(font) + 1;
108 text_descent = get_text_descent(font) + 1;
109 text_height = text_ascent + text_descent;
110 ibeam_letter = strlen(text);
113 left_margin = right_margin = 4;
114 top_margin = bottom_margin = 2;
118 left_margin = right_margin = 2;
119 top_margin = bottom_margin = 0;
122 text_x = left_margin;
126 // Create the subwindow
127 BC_SubWindow::initialize();
132 high_color = LTYELLOW;
137 back_color = bg_color;
141 set_cursor(IBEAM_CURSOR);
145 void BC_TextBox::set_precision(int precision)
147 this->precision = precision;
150 int BC_TextBox::update(char *text)
152 //printf("BC_TextBox::update 1 %d %s %s\n", strcmp(text, this->text), text, this->text);
153 int text_len = strlen(text);
154 // Don't update if contents are the same
155 if(!strcmp(text, this->text)) return 0;
158 strcpy(this->text, text);
159 if(highlight_letter1 > text_len) highlight_letter1 = text_len;
160 if(highlight_letter2 > text_len) highlight_letter2 = text_len;
161 if(ibeam_letter > text_len) ibeam_letter = text_len;
166 int BC_TextBox::update(int64_t value)
168 char string[BCTEXTLEN];
169 sprintf(string, "%lld", value);
176 int BC_TextBox::update(float value)
178 char string[BCTEXTLEN];
179 sprintf(string, "%f", value);
180 char *ptr = strchr(string, '.');
182 if(ptr) ptr[precision + 1] = 0;
188 void BC_TextBox::disable()
193 if(active) top_level->deactivate();
198 void BC_TextBox::enable()
207 int BC_TextBox::get_enabled()
212 int BC_TextBox::pixels_to_rows(BC_WindowBase *window, int font, int pixels)
214 return (pixels - 4) /
215 (window->get_text_ascent(font) + 1 +
216 window->get_text_descent(font) + 1);
219 int BC_TextBox::calculate_row_h(int rows,
220 BC_WindowBase *parent_window,
225 (parent_window->get_text_ascent(font) + 1 +
226 parent_window->get_text_descent(font) + 1) +
227 (has_border ? 4 : 0);
230 char* BC_TextBox::get_text()
235 int BC_TextBox::get_text_rows()
237 int text_len = strlen(text);
239 for(int i = 0; i < text_len; i++)
241 if(text[i] == 0xa) result++;
247 int BC_TextBox::get_row_h(int rows)
249 return rows * text_height + top_margin + bottom_margin;
252 int BC_TextBox::reposition_window(int x, int y, int w, int rows)
255 if(w < 0) w = get_w();
258 new_h = get_row_h(rows);
267 // printf("BC_TextBox::reposition_window 1 %d %d %d %d %d %d %d %d\n",
268 // x, get_x(), y, get_y(), w, get_w(), new_h, get_h());
269 BC_WindowBase::reposition_window(x, y, w, new_h);
275 void BC_TextBox::draw_border()
278 set_color(background_color);
279 draw_box(0, 0, left_margin, get_h());
280 draw_box(get_w() - right_margin, 0, right_margin, get_h());
285 draw_3d_border(0, 0, w, h,
286 top_level->get_resources()->button_shadow,
287 top_level->get_resources()->button_uphighlighted,
288 top_level->get_resources()->button_highlighted,
289 top_level->get_resources()->button_light);
291 draw_3d_border(0, 0, w, h,
292 top_level->get_resources()->button_shadow,
294 top_level->get_resources()->button_up,
295 top_level->get_resources()->button_light);
299 void BC_TextBox::draw_cursor()
301 set_color(background_color);
304 draw_box(ibeam_x + text_x,
312 void BC_TextBox::draw()
314 int i, j, k, text_len;
315 int row_begin, row_end;
316 int highlight_x1, highlight_x2;
319 //printf("BC_TextBox::draw 1 %s\n", text);
323 background_color = WHITE;
329 background_color = high_color;
333 background_color = back_color;
337 set_color(background_color);
338 draw_box(0, 0, w, h);
340 // Draw text with selection
342 text_len = strlen(text);
343 //printf("BC_TextBox::draw 0 %s %d %d %d %d\n", text, text_y, text_len, get_w(), text_height);
345 for(i = 0, k = text_y; i < text_len && k < get_h(); k += text_height)
348 if(text[i] == '\n') i++;
350 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
352 text_row[j] = text[i];
357 //printf("BC_TextBox::draw 1 %d %d %c\n", row_begin, row_end, text_row[j - 1]);
359 if(k > -text_height + top_margin && k < get_h() - bottom_margin)
361 // Draw highlighted region of row
362 if(highlight_letter2 > highlight_letter1 &&
363 highlight_letter2 > row_begin && highlight_letter1 < row_end)
365 if(active && enabled && get_has_focus())
366 set_color(top_level->get_resources()->text_highlight);
370 if(highlight_letter1 >= row_begin && highlight_letter1 < row_end)
371 highlight_x1 = get_text_width(font, text_row, highlight_letter1 - row_begin);
375 if(highlight_letter2 > row_begin && highlight_letter2 <= row_end)
376 highlight_x2 = get_text_width(font, text_row, highlight_letter2 - row_begin);
378 highlight_x2 = get_w();
380 draw_box(highlight_x1 + text_x,
382 highlight_x2 - highlight_x1,
386 // Draw text over highlight
392 draw_text(text_x, k + text_ascent, text_row);
394 // Get ibeam location
395 if(ibeam_letter >= row_begin && ibeam_letter <= row_end)
398 ibeam_y = k - text_y;
399 ibeam_x = get_text_width(font, text_row, ibeam_letter - row_begin);
404 //printf("BC_TextBox::draw 3 %d\n", ibeam_y);
411 //printf("BC_TextBox::draw 4 %d\n", ibeam_y);
424 int BC_TextBox::focus_in_event()
430 int BC_TextBox::focus_out_event()
436 int BC_TextBox::cursor_enter_event()
438 if(top_level->event_win == win && enabled)
453 int BC_TextBox::cursor_leave_event()
466 int BC_TextBox::button_press_event()
468 if(get_buttonpress() > 2) return 0;
470 int cursor_letter = 0;
471 int text_len = strlen(text);
473 if(!enabled) return 0;
475 if(top_level->event_win == win)
480 top_level->deactivate();
484 cursor_letter = get_cursor_letter(top_level->cursor_x, top_level->cursor_y);
485 if(get_double_click())
488 select_word(highlight_letter1, highlight_letter2, cursor_letter);
489 highlight_letter3 = highlight_letter1;
490 highlight_letter4 = highlight_letter2;
491 ibeam_letter = highlight_letter2;
492 copy_selection(PRIMARY_SELECTION);
495 if(get_buttonpress() == 2)
497 highlight_letter3 = highlight_letter4 =
498 ibeam_letter = highlight_letter1 =
499 highlight_letter2 = cursor_letter;
500 paste_selection(PRIMARY_SELECTION);
505 highlight_letter3 = highlight_letter4 =
506 ibeam_letter = highlight_letter1 =
507 highlight_letter2 = cursor_letter;
510 if(ibeam_letter < 0) ibeam_letter = 0;
511 if(ibeam_letter > text_len) ibeam_letter = text_len;
518 top_level->deactivate();
524 int BC_TextBox::button_release_event()
529 if(text_selected || word_selected)
538 int BC_TextBox::cursor_motion_event()
540 int cursor_letter, text_len = strlen(text), letter1, letter2;
543 if(text_selected || word_selected)
545 cursor_letter = get_cursor_letter(top_level->cursor_x, top_level->cursor_y);
548 select_word(letter1, letter2, cursor_letter);
553 letter1 = letter2 = cursor_letter;
556 if(letter1 <= highlight_letter3)
558 highlight_letter1 = letter1;
559 highlight_letter2 = highlight_letter4;
560 ibeam_letter = letter1;
563 if(letter2 >= highlight_letter4)
565 highlight_letter2 = letter2;
566 highlight_letter1 = highlight_letter3;
567 ibeam_letter = letter2;
570 copy_selection(PRIMARY_SELECTION);
579 int BC_TextBox::activate()
581 top_level->active_subwindow = this;
584 top_level->set_repeat(top_level->get_resources()->blink_rate);
588 int BC_TextBox::deactivate()
591 top_level->unset_repeat(top_level->get_resources()->blink_rate);
596 int BC_TextBox::repeat_event(int64_t duration)
600 if(duration == top_level->get_resources()->tooltip_delay &&
601 tooltip_text[0] != 0 &&
609 if(duration == top_level->get_resources()->blink_rate &&
613 if(skip_cursor->get_difference() < duration)
615 // printf("BC_TextBox::repeat_event 1 %lld %lld\n",
616 // skip_cursor->get_difference(),
628 void BC_TextBox::default_keypress(int &dispatch_event, int &result)
630 if((top_level->get_keypress() == RETURN) ||
631 // (top_level->get_keypress() > 30 && top_level->get_keypress() < 127))
632 (top_level->get_keypress() > 30 && top_level->get_keypress() <= 255))
634 // Substitute UNIX linefeed
635 if(top_level->get_keypress() == RETURN)
636 temp_string[0] = 0xa;
638 temp_string[0] = top_level->get_keypress();
640 insert_text(temp_string);
648 int BC_TextBox::select_whole_text(int select)
652 highlight_letter1 = 0;
653 highlight_letter2 = strlen(text);
654 text_selected = word_selected = 0;
655 ibeam_letter = highlight_letter1;
657 if(keypress_draw) draw();
661 ibeam_letter = strlen(text);
662 highlight_letter1 = ibeam_letter;
663 highlight_letter2 = ibeam_letter;
664 text_selected = word_selected = 0;
666 if(keypress_draw) draw();
668 return highlight_letter2 - highlight_letter1;
671 void BC_TextBox::cycle_textboxes(int amout)
673 top_level->cycle_textboxes(amout);
676 int BC_TextBox::keypress_event()
678 // Result == 2 contents changed
679 // Result == 1 trapped keypress
680 // Result == 0 nothing
683 int dispatch_event = 0;
685 if(!active || !enabled) return 0;
687 text_len = strlen(text);
688 last_keypress = get_keypress();
689 switch(get_keypress())
692 top_level->deactivate();
699 top_level->deactivate();
705 default_keypress(dispatch_event, result);
708 // Handle like a default keypress
723 int old_ibeam_letter = ibeam_letter;
733 while(ibeam_letter > 0 && isalnum(text[ibeam_letter - 1]))
739 if(top_level->shift_down())
741 // Initialize highlighting
742 if(highlight_letter1 == highlight_letter2)
744 highlight_letter1 = ibeam_letter;
745 highlight_letter2 = old_ibeam_letter;
748 // Extend left highlight
749 if(highlight_letter1 == old_ibeam_letter)
751 highlight_letter1 = ibeam_letter;
754 // Shrink right highlight
755 if(highlight_letter2 == old_ibeam_letter)
757 highlight_letter2 = ibeam_letter;
762 highlight_letter1 = highlight_letter2 = ibeam_letter;
767 if(keypress_draw) draw();
773 if(ibeam_letter < text_len)
775 int old_ibeam_letter = ibeam_letter;
784 while(ibeam_letter < text_len && isalnum(text[ibeam_letter++]))
791 if(top_level->shift_down())
793 // Initialize highlighting
794 if(highlight_letter1 == highlight_letter2)
796 highlight_letter1 = old_ibeam_letter;
797 highlight_letter2 = ibeam_letter;
800 // Shrink left highlight
801 if(highlight_letter1 == old_ibeam_letter)
803 highlight_letter1 = ibeam_letter;
806 // Expand right highlight
807 if(highlight_letter2 == old_ibeam_letter)
809 highlight_letter2 = ibeam_letter;
814 highlight_letter1 = highlight_letter2 = ibeam_letter;
818 if(keypress_draw) draw();
826 //printf("BC_TextBox::keypress_event 1 %d %d %d\n", ibeam_x, ibeam_y, ibeam_letter);
827 int new_letter = get_cursor_letter(ibeam_x + text_x,
828 ibeam_y + text_y - text_height);
829 //printf("BC_TextBox::keypress_event 2 %d %d %d\n", ibeam_x, ibeam_y, new_letter);
832 if(top_level->shift_down())
834 // Initialize highlighting
835 if(highlight_letter1 == highlight_letter2)
837 highlight_letter1 = new_letter;
838 highlight_letter2 = ibeam_letter;
841 // Expand left highlight
842 if(highlight_letter1 == ibeam_letter)
844 highlight_letter1 = new_letter;
847 // Shrink right highlight
848 if(highlight_letter2 == ibeam_letter)
850 highlight_letter2 = new_letter;
854 highlight_letter1 = highlight_letter2 = new_letter;
856 if(highlight_letter1 > highlight_letter2)
858 int temp = highlight_letter1;
859 highlight_letter1 = highlight_letter2;
860 highlight_letter2 = temp;
862 ibeam_letter = new_letter;
865 if(keypress_draw) draw();
873 int new_letter = get_cursor_letter(ibeam_x + text_x,
874 ibeam_y + text_y - get_h());
877 if(top_level->shift_down())
879 // Initialize highlighting
880 if(highlight_letter1 == highlight_letter2)
882 highlight_letter1 = new_letter;
883 highlight_letter2 = ibeam_letter;
886 // Expand left highlight
887 if(highlight_letter1 == ibeam_letter)
889 highlight_letter1 = new_letter;
892 // Shrink right highlight
893 if(highlight_letter2 == ibeam_letter)
895 highlight_letter2 = new_letter;
899 highlight_letter1 = highlight_letter2 = new_letter;
901 if(highlight_letter1 > highlight_letter2)
903 int temp = highlight_letter1;
904 highlight_letter1 = highlight_letter2;
905 highlight_letter2 = temp;
907 ibeam_letter = new_letter;
910 if(keypress_draw) draw();
916 // if(ibeam_letter > 0)
919 int new_letter = get_cursor_letter(ibeam_x + text_x,
920 ibeam_y + text_y + text_height);
921 //printf("BC_TextBox::keypress_event 10 %d\n", new_letter);
923 if(top_level->shift_down())
925 // Initialize highlighting
926 if(highlight_letter1 == highlight_letter2)
928 highlight_letter1 = new_letter;
929 highlight_letter2 = ibeam_letter;
932 // Shrink left highlight
933 if(highlight_letter1 == ibeam_letter)
935 highlight_letter1 = new_letter;
938 // Expand right highlight
939 if(highlight_letter2 == ibeam_letter)
941 highlight_letter2 = new_letter;
945 highlight_letter1 = highlight_letter2 = new_letter;
947 if(highlight_letter1 > highlight_letter2)
949 int temp = highlight_letter1;
950 highlight_letter1 = highlight_letter2;
951 highlight_letter2 = temp;
953 ibeam_letter = new_letter;
956 if(keypress_draw) draw();
958 //printf("BC_TextBox::keypress_event 20 %d\n", ibeam_letter);
966 int new_letter = get_cursor_letter(ibeam_x + text_x,
967 ibeam_y + text_y + get_h());
968 //printf("BC_TextBox::keypress_event 10 %d\n", new_letter);
970 if(top_level->shift_down())
972 // Initialize highlighting
973 if(highlight_letter1 == highlight_letter2)
975 highlight_letter1 = new_letter;
976 highlight_letter2 = ibeam_letter;
979 // Shrink left highlight
980 if(highlight_letter1 == ibeam_letter)
982 highlight_letter1 = new_letter;
985 // Expand right highlight
986 if(highlight_letter2 == ibeam_letter)
988 highlight_letter2 = new_letter;
992 highlight_letter1 = highlight_letter2 = new_letter;
994 if(highlight_letter1 > highlight_letter2)
996 int temp = highlight_letter1;
997 highlight_letter1 = highlight_letter2;
998 highlight_letter2 = temp;
1000 ibeam_letter = new_letter;
1003 if(keypress_draw) draw();
1005 //printf("BC_TextBox::keypress_event 20 %d\n", ibeam_letter);
1012 int old_ibeam_letter = ibeam_letter;
1014 while(ibeam_letter < text_len && text[ibeam_letter] != '\n')
1017 if(top_level->shift_down())
1020 if(highlight_letter1 == highlight_letter2)
1022 highlight_letter2 = ibeam_letter;
1023 highlight_letter1 = old_ibeam_letter;
1027 if(highlight_letter1 == old_ibeam_letter)
1029 highlight_letter1 = highlight_letter2;
1030 highlight_letter2 = ibeam_letter;
1034 if(highlight_letter2 == old_ibeam_letter)
1036 highlight_letter2 = ibeam_letter;
1040 highlight_letter1 = highlight_letter2 = ibeam_letter;
1043 if(keypress_draw) draw();
1050 int old_ibeam_letter = ibeam_letter;
1052 while(ibeam_letter > 0 && text[ibeam_letter - 1] != '\n')
1055 if(top_level->shift_down())
1058 if(highlight_letter1 == highlight_letter2)
1060 highlight_letter2 = old_ibeam_letter;
1061 highlight_letter1 = ibeam_letter;
1065 if(highlight_letter1 == old_ibeam_letter)
1067 highlight_letter1 = ibeam_letter;
1071 if(highlight_letter2 == old_ibeam_letter)
1073 highlight_letter2 = highlight_letter1;
1074 highlight_letter1 = ibeam_letter;
1078 highlight_letter1 = highlight_letter2 = ibeam_letter;
1081 if(keypress_draw) draw();
1087 if(highlight_letter1 == highlight_letter2)
1089 if(ibeam_letter > 0)
1091 delete_selection(ibeam_letter - 1, ibeam_letter, text_len);
1097 delete_selection(highlight_letter1, highlight_letter2, text_len);
1098 highlight_letter2 = ibeam_letter = highlight_letter1;
1102 if(keypress_draw) draw();
1108 if(highlight_letter1 == highlight_letter2)
1110 if(ibeam_letter < text_len)
1112 delete_selection(ibeam_letter, ibeam_letter + 1, text_len);
1117 delete_selection(highlight_letter1, highlight_letter2, text_len);
1118 highlight_letter2 = ibeam_letter = highlight_letter1;
1122 if(keypress_draw) draw();
1132 if(get_keypress() == 'c' || get_keypress() == 'C')
1134 if(highlight_letter1 != highlight_letter2)
1136 copy_selection(SECONDARY_SELECTION);
1141 if(get_keypress() == 'v' || get_keypress() == 'V')
1143 paste_selection(SECONDARY_SELECTION);
1145 if(keypress_draw) draw();
1150 if(get_keypress() == 'x' || get_keypress() == 'X')
1152 if(highlight_letter1 != highlight_letter2)
1154 copy_selection(SECONDARY_SELECTION);
1155 delete_selection(highlight_letter1, highlight_letter2, text_len);
1156 highlight_letter2 = ibeam_letter = highlight_letter1;
1160 if(keypress_draw) draw();
1168 default_keypress(dispatch_event, result);
1172 if(dispatch_event) skip_cursor->update();
1173 if(dispatch_event) handle_event();
1174 //printf("BC_TextBox::keypress_event 100 %d\n", ibeam_letter);
1180 int BC_TextBox::uses_text()
1185 void BC_TextBox::delete_selection(int letter1, int letter2, int text_len)
1189 for(i = letter1, j = letter2; j < text_len; i++, j++)
1198 void BC_TextBox::insert_text(char *string)
1200 int i, j, text_len, string_len;
1202 string_len = strlen(string);
1203 text_len = strlen(text);
1204 if(highlight_letter1 < highlight_letter2)
1206 delete_selection(highlight_letter1, highlight_letter2, text_len);
1207 highlight_letter2 = ibeam_letter = highlight_letter1;
1210 text_len = strlen(text);
1212 for(i = text_len, j = text_len + string_len; i >= ibeam_letter; i--, j--)
1215 for(i = ibeam_letter, j = 0; j < string_len; j++, i++)
1216 text[i] = string[j];
1218 ibeam_letter += string_len;
1223 void BC_TextBox::do_separators(int ibeam_left)
1227 // Remove separators from text
1228 int text_len = strlen(text);
1229 int separator_len = strlen(separators);
1230 for(int i = 0; i < text_len; i++)
1232 if(!isalnum(text[i]))
1234 for(int j = i; j < text_len - 1; j++)
1235 text[j] = text[j + 1];
1236 if(!ibeam_left && i < ibeam_letter) ibeam_letter--;
1248 // Insert separators into text
1249 for(int i = 0; i < separator_len; i++)
1253 // Insert a separator
1254 if(!isalnum(separators[i]))
1256 for(int j = text_len; j >= i; j--)
1258 text[j + 1] = text[j];
1260 if(!ibeam_left && i < ibeam_letter) ibeam_letter++;
1262 text[i] = separators[i];
1268 text[i] = separators[i];
1273 text[separator_len] = 0;
1278 void BC_TextBox::get_ibeam_position(int &x, int &y)
1280 int i, j, k, row_begin, row_end, text_len;
1282 text_len = strlen(text);
1285 for(i = 0; i < text_len; )
1288 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
1290 text_row[j] = text[i];
1296 if(ibeam_letter >= row_begin && ibeam_letter <= row_end)
1298 x = get_text_width(font, text_row, ibeam_letter - row_begin);
1299 //printf("BC_TextBox::get_ibeam_position 9 %d %d\n", x, y);
1309 //printf("BC_TextBox::get_ibeam_position 10 %d %d\n", x, y);
1315 void BC_TextBox::set_text_row(int row)
1317 text_y = -(row * text_height) + top_margin;
1321 int BC_TextBox::get_text_row()
1323 return -(text_y - top_margin) / text_height;
1326 void BC_TextBox::find_ibeam(int dispatch_event)
1329 int old_x = text_x, old_y = text_y;
1331 get_ibeam_position(x, y);
1333 if(left_margin + text_x + x >= get_w() - right_margin - BCCURSORW)
1335 text_x = -(x - (get_w() - get_w() / 4)) + left_margin;
1336 if(text_x > left_margin) text_x = left_margin;
1339 if(left_margin + text_x + x < left_margin)
1341 text_x = -(x - (get_w() / 4)) + left_margin;
1342 if(text_x > left_margin) text_x = left_margin;
1345 while(y + text_y >= get_h() - text_height - bottom_margin)
1347 text_y -= text_height;
1348 // text_y = -(y - (get_h() / 2)) + top_margin;
1349 // if(text_y > top_margin) text_y = top_margin;
1352 while(y + text_y < top_margin)
1354 text_y += text_height;
1355 if(text_y > top_margin)
1357 text_y = top_margin;
1362 if(dispatch_event && (old_x != text_x || old_y != text_y)) motion_event();
1365 int BC_TextBox::get_cursor_letter(int cursor_x, int cursor_y)
1367 int i, j, k, l, row_begin, row_end, text_len, result = 0, done = 0;
1368 text_len = strlen(text);
1370 if(cursor_y < text_y)
1376 for(i = 0, k = text_y; i < text_len && !done; k += text_height)
1379 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
1381 text_row[j] = text[i];
1386 if(cursor_y >= k && cursor_y < k + text_height)
1388 for(j = 0; j <= row_end - row_begin && !done; j++)
1390 l = get_text_width(font, text_row, j) + text_x;
1393 result = row_begin + j - 1;
1403 if(text[i] == '\n') i++;
1405 if(i >= text_len && !done)
1410 if(result < 0) result = 0;
1411 if(result > text_len) result = text_len;
1415 void BC_TextBox::select_word(int &letter1, int &letter2, int ibeam_letter)
1417 int text_len = strlen(text);
1418 letter1 = letter2 = ibeam_letter;
1421 if(isalnum(text[letter1])) letter1--;
1422 }while(letter1 > 0 && isalnum(text[letter1]));
1423 if(!isalnum(text[letter1])) letter1++;
1427 if(isalnum(text[letter2])) letter2++;
1428 }while(letter2 < text_len && isalnum(text[letter2]));
1429 if(letter2 < text_len && text[letter2] == ' ') letter2++;
1431 if(letter1 < 0) letter1 = 0;
1432 if(letter2 < 0) letter2 = 0;
1433 if(letter1 > text_len) letter1 = text_len;
1434 if(letter2 > text_len) letter2 = text_len;
1437 void BC_TextBox::copy_selection(int clipboard_num)
1439 int text_len = strlen(text);
1441 if(highlight_letter1 >= text_len ||
1442 highlight_letter2 > text_len ||
1443 highlight_letter1 < 0 ||
1444 highlight_letter2 < 0 ||
1445 highlight_letter2 - highlight_letter1 <= 0) return;
1447 get_clipboard()->to_clipboard(&text[highlight_letter1],
1448 highlight_letter2 - highlight_letter1,
1452 void BC_TextBox::paste_selection(int clipboard_num)
1454 int len = get_clipboard()->clipboard_len(clipboard_num);
1457 char *string = new char[len + 1];
1458 get_clipboard()->from_clipboard(string, len, clipboard_num);
1459 insert_text(string);
1463 void BC_TextBox::set_keypress_draw(int value)
1465 keypress_draw = value;
1468 int BC_TextBox::get_last_keypress()
1470 return last_keypress;
1473 int BC_TextBox::get_ibeam_letter()
1475 return ibeam_letter;
1478 void BC_TextBox::set_ibeam_letter(int number, int redraw)
1480 this->ibeam_letter = number;
1487 void BC_TextBox::set_separators(char *separators)
1489 this->separators = separators;
1507 BC_ScrollTextBox::BC_ScrollTextBox(BC_WindowBase *parent_window,
1514 this->parent_window = parent_window;
1519 this->default_text = default_text;
1522 BC_ScrollTextBox::~BC_ScrollTextBox()
1532 void BC_ScrollTextBox::create_objects()
1534 // Must be created first
1535 parent_window->add_subwindow(text = new BC_ScrollTextBoxText(this));
1536 parent_window->add_subwindow(yscroll = new BC_ScrollTextBoxYScroll(this));
1539 int BC_ScrollTextBox::handle_event()
1544 int BC_ScrollTextBox::get_x()
1549 int BC_ScrollTextBox::get_y()
1554 int BC_ScrollTextBox::get_w()
1559 int BC_ScrollTextBox::get_rows()
1565 char* BC_ScrollTextBox::get_text()
1567 return text->get_text();
1570 void BC_ScrollTextBox::update(char *text)
1572 this->text->update(text);
1573 yscroll->update_length(this->text->get_text_rows(),
1574 this->text->get_text_row(),
1575 yscroll->get_handlelength());
1578 void BC_ScrollTextBox::reposition_window(int x, int y, int w, int rows)
1584 text->reposition_window(x,
1586 w - yscroll->get_span(),
1588 yscroll->reposition_window(x + w - yscroll->get_span(),
1590 BC_TextBox::calculate_row_h(rows,
1592 yscroll->update_length(text->get_text_rows(),
1593 text->get_text_row(),
1605 BC_ScrollTextBoxText::BC_ScrollTextBoxText(BC_ScrollTextBox *gui)
1606 : BC_TextBox(gui->x,
1608 gui->w - get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w(),
1615 BC_ScrollTextBoxText::~BC_ScrollTextBoxText()
1624 int BC_ScrollTextBoxText::handle_event()
1626 gui->yscroll->update_length(get_text_rows(),
1628 gui->yscroll->get_handlelength());
1629 return gui->handle_event();
1632 int BC_ScrollTextBoxText::motion_event()
1634 gui->yscroll->update_length(get_text_rows(),
1636 gui->yscroll->get_handlelength());
1641 BC_ScrollTextBoxYScroll::BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui)
1642 : BC_ScrollBar(gui->x +
1644 get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w(),
1647 BC_TextBox::calculate_row_h(gui->rows,
1648 gui->parent_window),
1649 gui->text->get_text_rows(),
1656 BC_ScrollTextBoxYScroll::~BC_ScrollTextBoxYScroll()
1660 int BC_ScrollTextBoxYScroll::handle_event()
1662 gui->text->set_text_row(get_position());
1675 BC_PopupTextBoxText::BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y)
1676 : BC_TextBox(x, y, popup->text_w, 1, popup->default_text)
1678 this->popup = popup;
1681 BC_PopupTextBoxText::~BC_PopupTextBoxText()
1692 int BC_PopupTextBoxText::handle_event()
1694 popup->handle_event();
1698 BC_PopupTextBoxList::BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y)
1701 popup->text_w + BC_WindowBase::get_resources()->listbox_button[0]->get_w(),
1711 this->popup = popup;
1713 int BC_PopupTextBoxList::handle_event()
1715 popup->textbox->update(get_selection(0, 0)->get_text());
1716 popup->handle_event();
1723 BC_PopupTextBox::BC_PopupTextBox(BC_WindowBase *parent_window,
1724 ArrayList<BC_ListBoxItem*> *list_items,
1733 this->list_h = list_h;
1734 this->default_text = default_text;
1735 this->text_w = text_w;
1736 this->parent_window = parent_window;
1737 this->list_items = list_items;
1740 BC_PopupTextBox::~BC_PopupTextBox()
1750 int BC_PopupTextBox::create_objects()
1752 int x = this->x, y = this->y;
1753 parent_window->add_subwindow(textbox = new BC_PopupTextBoxText(this, x, y));
1754 x += textbox->get_w();
1755 parent_window->add_subwindow(listbox = new BC_PopupTextBoxList(this, x, y));
1759 void BC_PopupTextBox::update(char *text)
1761 textbox->update(text);
1764 void BC_PopupTextBox::update_list(ArrayList<BC_ListBoxItem*> *data)
1766 listbox->update(data,
1773 char* BC_PopupTextBox::get_text()
1775 return textbox->get_text();
1778 int BC_PopupTextBox::get_number()
1780 return listbox->get_selection_number(0, 0);
1783 int BC_PopupTextBox::get_x()
1788 int BC_PopupTextBox::get_y()
1793 int BC_PopupTextBox::get_w()
1795 return textbox->get_w() + listbox->get_w();
1798 int BC_PopupTextBox::get_h()
1800 return textbox->get_h();
1803 int BC_PopupTextBox::handle_event()
1808 void BC_PopupTextBox::reposition_window(int x, int y)
1813 textbox->reposition_window(x1, y1);
1814 x1 += textbox->get_w();
1815 listbox->reposition_window(x1, y1);
1831 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
1832 int64_t default_value,
1843 this->popup = popup;
1846 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
1847 float default_value,
1858 this->popup = popup;
1861 BC_TumbleTextBoxText::~BC_TumbleTextBoxText()
1873 int BC_TumbleTextBoxText::handle_event()
1875 popup->handle_event();
1884 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
1885 int64_t default_value,
1897 this->default_value = default_value;
1898 this->text_w = text_w;
1899 this->parent_window = parent_window;
1905 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
1918 this->default_value = default_value;
1919 this->text_w = text_w;
1920 this->parent_window = parent_window;
1926 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
1927 float default_value_f,
1937 this->min_f = min_f;
1938 this->max_f = max_f;
1939 this->default_value_f = default_value_f;
1940 this->text_w = text_w;
1941 this->parent_window = parent_window;
1947 BC_TumbleTextBox::~BC_TumbleTextBox()
1949 // Recursive delete. Normally ~BC_TumbleTextBox is never called but textbox
1950 // is deleted anyway by the windowbase so textbox deletes this.
1951 if(tumbler) delete tumbler;
1953 // Don't delete text here if we were called by ~BC_TumbleTextBoxText
1962 void BC_TumbleTextBox::reset()
1969 void BC_TumbleTextBox::set_precision(int precision)
1971 this->precision = precision;
1974 void BC_TumbleTextBox::set_increment(float value)
1976 this->increment = value;
1977 if(tumbler) tumbler->set_increment(value);
1980 int BC_TumbleTextBox::create_objects()
1982 int x = this->x, y = this->y;
1986 parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
1992 textbox->set_precision(precision);
1995 parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
2002 x += textbox->get_w();
2005 parent_window->add_subwindow(tumbler = new BC_FTumbler(textbox,
2011 parent_window->add_subwindow(tumbler = new BC_ITumbler(textbox,
2017 tumbler->set_increment(increment);
2021 char* BC_TumbleTextBox::get_text()
2023 return textbox->get_text();
2026 int BC_TumbleTextBox::update(char *value)
2028 textbox->update(value);
2032 int BC_TumbleTextBox::update(int64_t value)
2034 textbox->update(value);
2038 int BC_TumbleTextBox::update(float value)
2040 textbox->update(value);
2045 int BC_TumbleTextBox::get_x()
2050 int BC_TumbleTextBox::get_y()
2055 int BC_TumbleTextBox::get_w()
2057 return textbox->get_w() + tumbler->get_w();
2060 int BC_TumbleTextBox::get_h()
2062 return textbox->get_h();
2065 int BC_TumbleTextBox::handle_event()
2070 void BC_TumbleTextBox::reposition_window(int x, int y)
2075 textbox->reposition_window(x,
2079 tumbler->reposition_window(x + textbox->get_w(),
2084 void BC_TumbleTextBox::set_boundaries(int64_t min, int64_t max)
2086 tumbler->set_boundaries(min, max);
2089 void BC_TumbleTextBox::set_boundaries(float min, float max)
2091 tumbler->set_boundaries(min, max);