00001 #include "bcclipboard.h"
00002 #include "bclistboxitem.h"
00003 #include "bcresources.h"
00004 #include "bcsignals.h"
00005 #include "bctextbox.h"
00006 #include "clip.h"
00007 #include "colors.h"
00008 #include <ctype.h>
00009 #include "cursors.h"
00010 #include "keys.h"
00011 #include <math.h>
00012 #include "bctimer.h"
00013 #include "vframe.h"
00014
00015 #include <string.h>
00016
00017 #define VERTICAL_MARGIN 2
00018 #define VERTICAL_MARGIN_NOBORDER 0
00019 #define HORIZONTAL_MARGIN 4
00020 #define HORIZONTAL_MARGIN_NOBORDER 2
00021
00022 BC_TextBox::BC_TextBox(int x,
00023 int y,
00024 int w,
00025 int rows,
00026 char *text,
00027 int has_border,
00028 int font)
00029 : BC_SubWindow(x, y, w, 0, -1)
00030 {
00031 skip_cursor = 0;
00032 reset_parameters(rows, has_border, font);
00033 strcpy(this->text, text);
00034 }
00035
00036 BC_TextBox::BC_TextBox(int x,
00037 int y,
00038 int w,
00039 int rows,
00040 int64_t text,
00041 int has_border,
00042 int font)
00043 : BC_SubWindow(x, y, w, 0, -1)
00044 {
00045 skip_cursor = 0;
00046 reset_parameters(rows, has_border, font);
00047 sprintf(this->text, "%lld", text);
00048 }
00049
00050 BC_TextBox::BC_TextBox(int x,
00051 int y,
00052 int w,
00053 int rows,
00054 float text,
00055 int has_border,
00056 int font,
00057 int precision)
00058 : BC_SubWindow(x, y, w, 0, -1)
00059 {
00060 skip_cursor = 0;
00061 this->precision = precision;
00062 reset_parameters(rows, has_border, font);
00063 sprintf(this->text, "%0.*f", precision, text);
00064 }
00065
00066 BC_TextBox::BC_TextBox(int x,
00067 int y,
00068 int w,
00069 int rows,
00070 int text,
00071 int has_border,
00072 int font)
00073 : BC_SubWindow(x, y, w, 0, -1)
00074 {
00075 skip_cursor = 0;
00076 reset_parameters(rows, has_border, font);
00077 sprintf(this->text, "%d", text);
00078 }
00079
00080 BC_TextBox::~BC_TextBox()
00081 {
00082 if(skip_cursor) delete skip_cursor;
00083 }
00084
00085 int BC_TextBox::reset_parameters(int rows, int has_border, int font)
00086 {
00087 this->rows = rows;
00088 this->has_border = has_border;
00089 this->font = font;
00090 text_start = 0;
00091 text_end = 0;
00092 highlight_letter1 = highlight_letter2 = 0;
00093 highlight_letter3 = highlight_letter4 = 0;
00094 ibeam_letter = 0;
00095 active = 0;
00096 text_selected = word_selected = 0;
00097 text_x = 0;
00098 enabled = 1;
00099 highlighted = 0;
00100 precision = 4;
00101 if (!skip_cursor)
00102 skip_cursor = new Timer;
00103 keypress_draw = 1;
00104 last_keypress = 0;
00105 separators = 0;
00106 return 0;
00107 }
00108
00109 int BC_TextBox::initialize()
00110 {
00111 if (!skip_cursor)
00112 skip_cursor = new Timer;
00113 skip_cursor->update();
00114
00115 text_ascent = get_text_ascent(font) + 1;
00116 text_descent = get_text_descent(font) + 1;
00117 text_height = text_ascent + text_descent;
00118 ibeam_letter = strlen(text);
00119 if(has_border)
00120 {
00121 left_margin = right_margin = HORIZONTAL_MARGIN;
00122 top_margin = bottom_margin = VERTICAL_MARGIN;
00123 }
00124 else
00125 {
00126 left_margin = right_margin = HORIZONTAL_MARGIN_NOBORDER;
00127 top_margin = bottom_margin = VERTICAL_MARGIN_NOBORDER;
00128 }
00129 h = get_row_h(rows);
00130 text_x = left_margin;
00131 text_y = top_margin;
00132 find_ibeam(0);
00133
00134
00135 BC_SubWindow::initialize();
00136
00137 BC_Resources *resources = get_resources();
00138 if(has_border)
00139 {
00140 back_color = resources->text_background;
00141 high_color = resources->text_background_hi;
00142 }
00143 else
00144 {
00145 high_color = resources->text_background_noborder_hi;
00146 back_color = bg_color;
00147 }
00148
00149 draw();
00150 set_cursor(IBEAM_CURSOR);
00151 return 0;
00152 }
00153
00154 int BC_TextBox::calculate_h(BC_WindowBase *gui,
00155 int font,
00156 int has_border,
00157 int rows)
00158 {
00159 return rows * (gui->get_text_ascent(font) + 1 +
00160 gui->get_text_descent(font) + 1) +
00161 2 * (has_border ? VERTICAL_MARGIN : VERTICAL_MARGIN_NOBORDER);
00162 }
00163
00164 void BC_TextBox::set_precision(int precision)
00165 {
00166 this->precision = precision;
00167 }
00168
00169 void BC_TextBox::set_selection(int char1, int char2, int ibeam)
00170 {
00171 highlight_letter1 = char1;
00172 highlight_letter2 = char2;
00173 ibeam_letter = ibeam;
00174 draw();
00175 }
00176
00177 int BC_TextBox::update(char *text)
00178 {
00179
00180 int text_len = strlen(text);
00181
00182 if(!strcmp(text, this->text)) return 0;
00183
00184
00185 strcpy(this->text, text);
00186 if(highlight_letter1 > text_len) highlight_letter1 = text_len;
00187 if(highlight_letter2 > text_len) highlight_letter2 = text_len;
00188 if(ibeam_letter > text_len) ibeam_letter = text_len;
00189 draw();
00190 return 0;
00191 }
00192
00193 int BC_TextBox::update(int64_t value)
00194 {
00195 char string[BCTEXTLEN];
00196 sprintf(string, "%lld", value);
00197
00198
00199 update(string);
00200 return 0;
00201 }
00202
00203 int BC_TextBox::update(float value)
00204 {
00205 char string[BCTEXTLEN];
00206 sprintf(string, "%0.*f", precision, value);
00207
00208 update(string);
00209 return 0;
00210 }
00211
00212 void BC_TextBox::disable()
00213 {
00214 if(enabled)
00215 {
00216 enabled = 0;
00217 if(top_level)
00218 {
00219 if(active) top_level->deactivate();
00220 draw();
00221 }
00222 }
00223 }
00224
00225 void BC_TextBox::enable()
00226 {
00227 if(!enabled)
00228 {
00229 enabled = 1;
00230 if(top_level)
00231 {
00232 draw();
00233 }
00234 }
00235 }
00236
00237 int BC_TextBox::get_enabled()
00238 {
00239 return enabled;
00240 }
00241
00242 int BC_TextBox::pixels_to_rows(BC_WindowBase *window, int font, int pixels)
00243 {
00244 return (pixels - 4) /
00245 (window->get_text_ascent(font) + 1 +
00246 window->get_text_descent(font) + 1);
00247 }
00248
00249 int BC_TextBox::calculate_row_h(int rows,
00250 BC_WindowBase *parent_window,
00251 int has_border,
00252 int font)
00253 {
00254 return rows *
00255 (parent_window->get_text_ascent(font) + 1 +
00256 parent_window->get_text_descent(font) + 1) +
00257 (has_border ? 4 : 0);
00258 }
00259
00260 char* BC_TextBox::get_text()
00261 {
00262 return text;
00263 }
00264
00265 int BC_TextBox::get_text_rows()
00266 {
00267 int text_len = strlen(text);
00268 int result = 1;
00269 for(int i = 0; i < text_len; i++)
00270 {
00271 if(text[i] == 0xa) result++;
00272 }
00273 return result;
00274 }
00275
00276
00277 int BC_TextBox::get_row_h(int rows)
00278 {
00279 return rows * text_height + top_margin + bottom_margin;
00280 }
00281
00282 int BC_TextBox::reposition_window(int x, int y, int w, int rows)
00283 {
00284 int new_h = get_h();
00285 if(w < 0) w = get_w();
00286 if(rows != -1)
00287 {
00288 new_h = get_row_h(rows);
00289 this->rows = rows;
00290 }
00291
00292 if(x != get_x() ||
00293 y != get_y() ||
00294 w != get_w() ||
00295 new_h != get_h())
00296 {
00297
00298
00299 BC_WindowBase::reposition_window(x, y, w, new_h);
00300 draw();
00301 }
00302 return 0;
00303 }
00304
00305 void BC_TextBox::draw_border()
00306 {
00307 BC_Resources *resources = get_resources();
00308
00309 set_color(background_color);
00310 draw_box(0, 0, left_margin, get_h());
00311 draw_box(get_w() - right_margin, 0, right_margin, get_h());
00312
00313 if(has_border)
00314 {
00315 if(highlighted)
00316 draw_3d_border(0, 0, w, h,
00317 resources->button_shadow,
00318 resources->button_uphighlighted,
00319 resources->button_highlighted,
00320 resources->button_light);
00321 else
00322 draw_3d_border(0, 0, w, h,
00323 resources->text_border1,
00324 resources->text_border2,
00325 resources->text_border3,
00326 resources->text_border4);
00327 }
00328 }
00329
00330 void BC_TextBox::draw_cursor()
00331 {
00332
00333 set_color(WHITE);
00334 set_inverse();
00335
00336 draw_box(ibeam_x + text_x,
00337 ibeam_y + text_y,
00338 BCCURSORW,
00339 text_height);
00340 set_opaque();
00341 }
00342
00343
00344 void BC_TextBox::draw()
00345 {
00346 int i, j, k, text_len;
00347 int row_begin, row_end;
00348 int highlight_x1, highlight_x2;
00349 int need_ibeam = 1;
00350 BC_Resources *resources = get_resources();
00351
00352
00353
00354 if(has_border)
00355 {
00356 background_color = resources->text_background;
00357 }
00358 else
00359 {
00360 if(highlighted)
00361 {
00362 background_color = high_color;
00363 }
00364 else
00365 {
00366 background_color = back_color;
00367 }
00368 }
00369
00370 set_color(background_color);
00371 draw_box(0, 0, w, h);
00372
00373
00374 set_font(font);
00375 text_len = strlen(text);
00376
00377
00378 for(i = 0, k = text_y; i < text_len && k < get_h(); k += text_height)
00379 {
00380
00381 if(text[i] == '\n') i++;
00382 row_begin = i;
00383 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
00384 {
00385 text_row[j] = text[i];
00386 }
00387 row_end = i;
00388 text_row[j] = 0;
00389
00390
00391
00392 if(k > -text_height + top_margin && k < get_h() - bottom_margin)
00393 {
00394
00395 if(highlight_letter2 > highlight_letter1 &&
00396 highlight_letter2 > row_begin && highlight_letter1 < row_end)
00397 {
00398 if(active && enabled && get_has_focus())
00399 set_color(resources->text_highlight);
00400 else
00401 set_color(resources->text_inactive_highlight);
00402
00403 if(highlight_letter1 >= row_begin && highlight_letter1 < row_end)
00404 highlight_x1 = get_text_width(font, text_row, highlight_letter1 - row_begin);
00405 else
00406 highlight_x1 = 0;
00407
00408 if(highlight_letter2 > row_begin && highlight_letter2 <= row_end)
00409 highlight_x2 = get_text_width(font, text_row, highlight_letter2 - row_begin);
00410 else
00411 highlight_x2 = get_w();
00412
00413 draw_box(highlight_x1 + text_x,
00414 k,
00415 highlight_x2 - highlight_x1,
00416 text_height);
00417 }
00418
00419
00420 if(enabled)
00421 set_color(resources->text_default);
00422 else
00423 set_color(MEGREY);
00424
00425 draw_text(text_x, k + text_ascent, text_row);
00426
00427
00428 if(ibeam_letter >= row_begin && ibeam_letter <= row_end)
00429 {
00430 need_ibeam = 0;
00431 ibeam_y = k - text_y;
00432 ibeam_x = get_text_width(font, text_row, ibeam_letter - row_begin);
00433 }
00434 }
00435 }
00436
00437
00438 if(need_ibeam)
00439 {
00440 ibeam_x = 0;
00441 ibeam_y = 0;
00442 }
00443
00444
00445
00446 if (active)
00447 draw_cursor();
00448
00449
00450 draw_border();
00451 flash();
00452 flush();
00453 }
00454
00455 int BC_TextBox::focus_in_event()
00456 {
00457 draw();
00458 return 1;
00459 }
00460
00461 int BC_TextBox::focus_out_event()
00462 {
00463 draw();
00464 return 1;
00465 }
00466
00467 int BC_TextBox::cursor_enter_event()
00468 {
00469 if(top_level->event_win == win && enabled)
00470 {
00471 tooltip_done = 0;
00472
00473 if(!highlighted)
00474 {
00475 highlighted = 1;
00476 draw_border();
00477 flash();
00478 flush();
00479 }
00480 }
00481 return 0;
00482 }
00483
00484 int BC_TextBox::cursor_leave_event()
00485 {
00486 if(highlighted)
00487 {
00488 highlighted = 0;
00489 draw_border();
00490 hide_tooltip();
00491 flash();
00492 flush();
00493 }
00494 return 0;
00495 }
00496
00497 int BC_TextBox::button_press_event()
00498 {
00499 if(get_buttonpress() > 2) return 0;
00500
00501 int cursor_letter = 0;
00502 int text_len = strlen(text);
00503
00504 if(!enabled) return 0;
00505
00506 if(top_level->event_win == win)
00507 {
00508 if(!active)
00509 {
00510 hide_tooltip();
00511 top_level->deactivate();
00512 activate();
00513 }
00514
00515 cursor_letter = get_cursor_letter(top_level->cursor_x, top_level->cursor_y);
00516 if(get_double_click())
00517 {
00518 word_selected = 1;
00519 select_word(highlight_letter1, highlight_letter2, cursor_letter);
00520 highlight_letter3 = highlight_letter1;
00521 highlight_letter4 = highlight_letter2;
00522 ibeam_letter = highlight_letter2;
00523 copy_selection(PRIMARY_SELECTION);
00524 }
00525 else
00526 if(get_buttonpress() == 2)
00527 {
00528 highlight_letter3 = highlight_letter4 =
00529 ibeam_letter = highlight_letter1 =
00530 highlight_letter2 = cursor_letter;
00531 paste_selection(PRIMARY_SELECTION);
00532 }
00533 else
00534 {
00535 text_selected = 1;
00536 highlight_letter3 = highlight_letter4 =
00537 ibeam_letter = highlight_letter1 =
00538 highlight_letter2 = cursor_letter;
00539 }
00540
00541 if(ibeam_letter < 0) ibeam_letter = 0;
00542 if(ibeam_letter > text_len) ibeam_letter = text_len;
00543 draw();
00544 return 1;
00545 }
00546 else
00547 if(active)
00548 {
00549 top_level->deactivate();
00550 }
00551
00552 return 0;
00553 }
00554
00555 int BC_TextBox::button_release_event()
00556 {
00557 if(active)
00558 {
00559 hide_tooltip();
00560 if(text_selected || word_selected)
00561 {
00562 text_selected = 0;
00563 word_selected = 0;
00564 }
00565 }
00566 return 0;
00567 }
00568
00569 int BC_TextBox::cursor_motion_event()
00570 {
00571 int cursor_letter, text_len = strlen(text), letter1, letter2;
00572 if(active)
00573 {
00574 if(text_selected || word_selected)
00575 {
00576 cursor_letter = get_cursor_letter(top_level->cursor_x, top_level->cursor_y);
00577 if(word_selected)
00578 {
00579 select_word(letter1, letter2, cursor_letter);
00580 }
00581 else
00582 if(text_selected)
00583 {
00584 letter1 = letter2 = cursor_letter;
00585 }
00586
00587 if(letter1 <= highlight_letter3)
00588 {
00589 highlight_letter1 = letter1;
00590 highlight_letter2 = highlight_letter4;
00591 ibeam_letter = letter1;
00592 }
00593 else
00594 if(letter2 >= highlight_letter4)
00595 {
00596 highlight_letter2 = letter2;
00597 highlight_letter1 = highlight_letter3;
00598 ibeam_letter = letter2;
00599 }
00600
00601 copy_selection(PRIMARY_SELECTION);
00602 find_ibeam(1);
00603 draw();
00604 return 1;
00605 }
00606 }
00607 return 0;
00608 }
00609
00610 int BC_TextBox::activate()
00611 {
00612 top_level->active_subwindow = this;
00613 active = 1;
00614 draw();
00615 top_level->set_repeat(top_level->get_resources()->blink_rate);
00616 return 0;
00617 }
00618
00619 int BC_TextBox::deactivate()
00620 {
00621 active = 0;
00622 top_level->unset_repeat(top_level->get_resources()->blink_rate);
00623 draw();
00624 return 0;
00625 }
00626
00627 int BC_TextBox::repeat_event(int64_t duration)
00628 {
00629 int result = 0;
00630
00631 if(duration == top_level->get_resources()->tooltip_delay &&
00632 tooltip_text[0] != 0 &&
00633 highlighted)
00634 {
00635 show_tooltip();
00636 tooltip_done = 1;
00637 result = 1;
00638 }
00639
00640 if(duration == top_level->get_resources()->blink_rate &&
00641 active &&
00642 get_has_focus())
00643 {
00644 if(skip_cursor->get_difference() < duration)
00645 {
00646
00647
00648
00649 return 1;
00650 }
00651 draw_cursor();
00652 flash();
00653 flush();
00654 result = 1;
00655 }
00656 return result;
00657 }
00658
00659 void BC_TextBox::default_keypress(int &dispatch_event, int &result)
00660 {
00661 if((top_level->get_keypress() == RETURN) ||
00662
00663 (top_level->get_keypress() > 30 && top_level->get_keypress() <= 255))
00664 {
00665
00666 if(top_level->get_keypress() == RETURN)
00667 temp_string[0] = 0xa;
00668 else
00669 temp_string[0] = top_level->get_keypress();
00670 temp_string[1] = 0;
00671 insert_text(temp_string);
00672 find_ibeam(1);
00673 draw();
00674 dispatch_event = 1;
00675 result = 1;
00676 }
00677 }
00678
00679 int BC_TextBox::select_whole_text(int select)
00680 {
00681 if (select == 1)
00682 {
00683 highlight_letter1 = 0;
00684 highlight_letter2 = strlen(text);
00685 text_selected = word_selected = 0;
00686 ibeam_letter = highlight_letter1;
00687 find_ibeam(1);
00688 if(keypress_draw) draw();
00689 } else
00690 if (select == -1)
00691 {
00692 ibeam_letter = strlen(text);
00693 highlight_letter1 = ibeam_letter;
00694 highlight_letter2 = ibeam_letter;
00695 text_selected = word_selected = 0;
00696 find_ibeam(1);
00697 if(keypress_draw) draw();
00698 }
00699 return highlight_letter2 - highlight_letter1;
00700 }
00701
00702 void BC_TextBox::cycle_textboxes(int amout)
00703 {
00704 top_level->cycle_textboxes(amout);
00705 }
00706
00707 int BC_TextBox::keypress_event()
00708 {
00709
00710
00711
00712 int result = 0;
00713 int text_len;
00714 int dispatch_event = 0;
00715
00716 if(!active || !enabled) return 0;
00717
00718 text_len = strlen(text);
00719 last_keypress = get_keypress();
00720 switch(get_keypress())
00721 {
00722 case ESC:
00723 top_level->deactivate();
00724 result = 0;
00725 break;
00726
00727 case RETURN:
00728 if(rows == 1)
00729 {
00730 top_level->deactivate();
00731 dispatch_event = 1;
00732 result = 0;
00733 }
00734 else
00735 {
00736 default_keypress(dispatch_event, result);
00737 }
00738 break;
00739
00740
00741 case TAB:
00742 cycle_textboxes(1);
00743 result = 1;
00744 break;
00745
00746 case LEFTTAB:
00747 cycle_textboxes(-1);
00748 result = 1;
00749 break;
00750
00751 case LEFT:
00752 if(ibeam_letter > 0)
00753 {
00754 int old_ibeam_letter = ibeam_letter;
00755
00756 if(!ctrl_down())
00757 {
00758 ibeam_letter--;
00759 }
00760 else
00761
00762 {
00763 ibeam_letter--;
00764 while(ibeam_letter > 0 && isalnum(text[ibeam_letter - 1]))
00765 ibeam_letter--;
00766 }
00767
00768
00769
00770 if(top_level->shift_down())
00771 {
00772
00773 if(highlight_letter1 == highlight_letter2)
00774 {
00775 highlight_letter1 = ibeam_letter;
00776 highlight_letter2 = old_ibeam_letter;
00777 }
00778 else
00779
00780 if(highlight_letter1 == old_ibeam_letter)
00781 {
00782 highlight_letter1 = ibeam_letter;
00783 }
00784 else
00785
00786 if(highlight_letter2 == old_ibeam_letter)
00787 {
00788 highlight_letter2 = ibeam_letter;
00789 }
00790 }
00791 else
00792 {
00793 highlight_letter1 = highlight_letter2 = ibeam_letter;
00794 }
00795
00796
00797 find_ibeam(1);
00798 if(keypress_draw) draw();
00799 }
00800 result = 1;
00801 break;
00802
00803 case RIGHT:
00804 if(ibeam_letter < text_len)
00805 {
00806 int old_ibeam_letter = ibeam_letter;
00807
00808 if(!ctrl_down())
00809 {
00810 ibeam_letter++;
00811 }
00812 else
00813
00814 {
00815 while(ibeam_letter < text_len && isalnum(text[ibeam_letter++]))
00816 ;
00817 }
00818
00819
00820
00821
00822 if(top_level->shift_down())
00823 {
00824
00825 if(highlight_letter1 == highlight_letter2)
00826 {
00827 highlight_letter1 = old_ibeam_letter;
00828 highlight_letter2 = ibeam_letter;
00829 }
00830 else
00831
00832 if(highlight_letter1 == old_ibeam_letter)
00833 {
00834 highlight_letter1 = ibeam_letter;
00835 }
00836 else
00837
00838 if(highlight_letter2 == old_ibeam_letter)
00839 {
00840 highlight_letter2 = ibeam_letter;
00841 }
00842 }
00843 else
00844 {
00845 highlight_letter1 = highlight_letter2 = ibeam_letter;
00846 }
00847
00848 find_ibeam(1);
00849 if(keypress_draw) draw();
00850 }
00851 result = 1;
00852 break;
00853
00854 case UP:
00855 if(ibeam_letter > 0)
00856 {
00857
00858 int new_letter = get_cursor_letter(ibeam_x + text_x,
00859 ibeam_y + text_y - text_height);
00860
00861
00862
00863 if(top_level->shift_down())
00864 {
00865
00866 if(highlight_letter1 == highlight_letter2)
00867 {
00868 highlight_letter1 = new_letter;
00869 highlight_letter2 = ibeam_letter;
00870 }
00871 else
00872
00873 if(highlight_letter1 == ibeam_letter)
00874 {
00875 highlight_letter1 = new_letter;
00876 }
00877 else
00878
00879 if(highlight_letter2 == ibeam_letter)
00880 {
00881 highlight_letter2 = new_letter;
00882 }
00883 }
00884 else
00885 highlight_letter1 = highlight_letter2 = new_letter;
00886
00887 if(highlight_letter1 > highlight_letter2)
00888 {
00889 int temp = highlight_letter1;
00890 highlight_letter1 = highlight_letter2;
00891 highlight_letter2 = temp;
00892 }
00893 ibeam_letter = new_letter;
00894
00895 find_ibeam(1);
00896 if(keypress_draw) draw();
00897 }
00898 result = 1;
00899 break;
00900
00901 case PGUP:
00902 if(ibeam_letter > 0)
00903 {
00904 int new_letter = get_cursor_letter(ibeam_x + text_x,
00905 ibeam_y + text_y - get_h());
00906
00907
00908 if(top_level->shift_down())
00909 {
00910
00911 if(highlight_letter1 == highlight_letter2)
00912 {
00913 highlight_letter1 = new_letter;
00914 highlight_letter2 = ibeam_letter;
00915 }
00916 else
00917
00918 if(highlight_letter1 == ibeam_letter)
00919 {
00920 highlight_letter1 = new_letter;
00921 }
00922 else
00923
00924 if(highlight_letter2 == ibeam_letter)
00925 {
00926 highlight_letter2 = new_letter;
00927 }
00928 }
00929 else
00930 highlight_letter1 = highlight_letter2 = new_letter;
00931
00932 if(highlight_letter1 > highlight_letter2)
00933 {
00934 int temp = highlight_letter1;
00935 highlight_letter1 = highlight_letter2;
00936 highlight_letter2 = temp;
00937 }
00938 ibeam_letter = new_letter;
00939
00940 find_ibeam(1);
00941 if(keypress_draw) draw();
00942 }
00943 result = 1;
00944 break;
00945
00946 case DOWN:
00947
00948 {
00949
00950 int new_letter = get_cursor_letter(ibeam_x + text_x,
00951 ibeam_y + text_y + text_height);
00952
00953
00954 if(top_level->shift_down())
00955 {
00956
00957 if(highlight_letter1 == highlight_letter2)
00958 {
00959 highlight_letter1 = new_letter;
00960 highlight_letter2 = ibeam_letter;
00961 }
00962 else
00963
00964 if(highlight_letter1 == ibeam_letter)
00965 {
00966 highlight_letter1 = new_letter;
00967 }
00968 else
00969
00970 if(highlight_letter2 == ibeam_letter)
00971 {
00972 highlight_letter2 = new_letter;
00973 }
00974 }
00975 else
00976 highlight_letter1 = highlight_letter2 = new_letter;
00977
00978 if(highlight_letter1 > highlight_letter2)
00979 {
00980 int temp = highlight_letter1;
00981 highlight_letter1 = highlight_letter2;
00982 highlight_letter2 = temp;
00983 }
00984 ibeam_letter = new_letter;
00985
00986 find_ibeam(1);
00987 if(keypress_draw) draw();
00988
00989
00990 }
00991 result = 1;
00992 break;
00993
00994 case PGDN:
00995 {
00996
00997 int new_letter = get_cursor_letter(ibeam_x + text_x,
00998 ibeam_y + text_y + get_h());
00999
01000
01001 if(top_level->shift_down())
01002 {
01003
01004 if(highlight_letter1 == highlight_letter2)
01005 {
01006 highlight_letter1 = new_letter;
01007 highlight_letter2 = ibeam_letter;
01008 }
01009 else
01010
01011 if(highlight_letter1 == ibeam_letter)
01012 {
01013 highlight_letter1 = new_letter;
01014 }
01015 else
01016
01017 if(highlight_letter2 == ibeam_letter)
01018 {
01019 highlight_letter2 = new_letter;
01020 }
01021 }
01022 else
01023 highlight_letter1 = highlight_letter2 = new_letter;
01024
01025 if(highlight_letter1 > highlight_letter2)
01026 {
01027 int temp = highlight_letter1;
01028 highlight_letter1 = highlight_letter2;
01029 highlight_letter2 = temp;
01030 }
01031 ibeam_letter = new_letter;
01032
01033 find_ibeam(1);
01034 if(keypress_draw) draw();
01035
01036
01037 }
01038 result = 1;
01039 break;
01040
01041 case END:
01042 {
01043 int old_ibeam_letter = ibeam_letter;
01044
01045 while(ibeam_letter < text_len && text[ibeam_letter] != '\n')
01046 ibeam_letter++;
01047
01048 if(top_level->shift_down())
01049 {
01050
01051 if(highlight_letter1 == highlight_letter2)
01052 {
01053 highlight_letter2 = ibeam_letter;
01054 highlight_letter1 = old_ibeam_letter;
01055 }
01056 else
01057
01058 if(highlight_letter1 == old_ibeam_letter)
01059 {
01060 highlight_letter1 = highlight_letter2;
01061 highlight_letter2 = ibeam_letter;
01062 }
01063 else
01064
01065 if(highlight_letter2 == old_ibeam_letter)
01066 {
01067 highlight_letter2 = ibeam_letter;
01068 }
01069 }
01070 else
01071 highlight_letter1 = highlight_letter2 = ibeam_letter;
01072
01073 find_ibeam(1);
01074 if(keypress_draw) draw();
01075 result = 1;
01076 break;
01077 }
01078
01079 case HOME:
01080 {
01081 int old_ibeam_letter = ibeam_letter;
01082
01083 while(ibeam_letter > 0 && text[ibeam_letter - 1] != '\n')
01084 ibeam_letter--;
01085
01086 if(top_level->shift_down())
01087 {
01088
01089 if(highlight_letter1 == highlight_letter2)
01090 {
01091 highlight_letter2 = old_ibeam_letter;
01092 highlight_letter1 = ibeam_letter;
01093 }
01094 else
01095
01096 if(highlight_letter1 == old_ibeam_letter)
01097 {
01098 highlight_letter1 = ibeam_letter;
01099 }
01100 else
01101
01102 if(highlight_letter2 == old_ibeam_letter)
01103 {
01104 highlight_letter2 = highlight_letter1;
01105 highlight_letter1 = ibeam_letter;
01106 }
01107 }
01108 else
01109 highlight_letter1 = highlight_letter2 = ibeam_letter;
01110
01111 find_ibeam(1);
01112 if(keypress_draw) draw();
01113 result = 1;
01114 break;
01115 }
01116
01117 case BACKSPACE:
01118 if(highlight_letter1 == highlight_letter2)
01119 {
01120 if(ibeam_letter > 0)
01121 {
01122 delete_selection(ibeam_letter - 1, ibeam_letter, text_len);
01123 ibeam_letter--;
01124 }
01125 }
01126 else
01127 {
01128 delete_selection(highlight_letter1, highlight_letter2, text_len);
01129 highlight_letter2 = ibeam_letter = highlight_letter1;
01130 }
01131
01132 find_ibeam(1);
01133 if(keypress_draw) draw();
01134 dispatch_event = 1;
01135 result = 1;
01136 break;
01137
01138 case DELETE:
01139 if(highlight_letter1 == highlight_letter2)
01140 {
01141 if(ibeam_letter < text_len)
01142 {
01143 delete_selection(ibeam_letter, ibeam_letter + 1, text_len);
01144 }
01145 }
01146 else
01147 {
01148 delete_selection(highlight_letter1, highlight_letter2, text_len);
01149 highlight_letter2 = ibeam_letter = highlight_letter1;
01150 }
01151
01152 find_ibeam(1);
01153 if(keypress_draw) draw();
01154 dispatch_event = 1;
01155 result = 1;
01156 break;
01157
01158
01159
01160 default:
01161 if(ctrl_down())
01162 {
01163 if(get_keypress() == 'c' || get_keypress() == 'C')
01164 {
01165 if(highlight_letter1 != highlight_letter2)
01166 {
01167 copy_selection(SECONDARY_SELECTION);
01168 result = 1;
01169 }
01170 }
01171 else
01172 if(get_keypress() == 'v' || get_keypress() == 'V')
01173 {
01174 paste_selection(SECONDARY_SELECTION);
01175 find_ibeam(1);
01176 if(keypress_draw) draw();
01177 dispatch_event = 1;
01178 result = 1;
01179 }
01180 else
01181 if(get_keypress() == 'x' || get_keypress() == 'X')
01182 {
01183 if(highlight_letter1 != highlight_letter2)
01184 {
01185 copy_selection(SECONDARY_SELECTION);
01186 delete_selection(highlight_letter1, highlight_letter2, text_len);
01187 highlight_letter2 = ibeam_letter = highlight_letter1;
01188 }
01189
01190 find_ibeam(1);
01191 if(keypress_draw) draw();
01192 dispatch_event = 1;
01193 result = 1;
01194 }
01195
01196 break;
01197 }
01198
01199 default_keypress(dispatch_event, result);
01200 break;
01201 }
01202
01203 if(dispatch_event) skip_cursor->update();
01204 if(dispatch_event) handle_event();
01205
01206 return result;
01207 }
01208
01209
01210
01211 int BC_TextBox::uses_text()
01212 {
01213 return 1;
01214 }
01215
01216 void BC_TextBox::delete_selection(int letter1, int letter2, int text_len)
01217 {
01218 int i, j;
01219
01220 for(i = letter1, j = letter2; j < text_len; i++, j++)
01221 {
01222 text[i] = text[j];
01223 }
01224 text[i] = 0;
01225
01226 do_separators(1);
01227 }
01228
01229 void BC_TextBox::insert_text(char *string)
01230 {
01231 int i, j, text_len, string_len;
01232
01233 string_len = strlen(string);
01234 text_len = strlen(text);
01235 if(highlight_letter1 < highlight_letter2)
01236 {
01237 delete_selection(highlight_letter1, highlight_letter2, text_len);
01238 highlight_letter2 = ibeam_letter = highlight_letter1;
01239 }
01240
01241 text_len = strlen(text);
01242
01243 for(i = text_len, j = text_len + string_len; i >= ibeam_letter; i--, j--)
01244 text[j] = text[i];
01245
01246 for(i = ibeam_letter, j = 0; j < string_len; j++, i++)
01247 text[i] = string[j];
01248
01249 ibeam_letter += string_len;
01250
01251 do_separators(0);
01252 }
01253
01254 void BC_TextBox::do_separators(int ibeam_left)
01255 {
01256 if(separators)
01257 {
01258
01259 int text_len = strlen(text);
01260 int separator_len = strlen(separators);
01261 for(int i = 0; i < text_len; i++)
01262 {
01263 if(!isalnum(text[i]))
01264 {
01265 for(int j = i; j < text_len - 1; j++)
01266 text[j] = text[j + 1];
01267 if(!ibeam_left && i < ibeam_letter) ibeam_letter--;
01268 text_len--;
01269 i--;
01270 }
01271 }
01272 text[text_len] = 0;
01273
01274
01275
01276
01277
01278
01279
01280 for(int i = 0; i < separator_len; i++)
01281 {
01282 if(i < text_len)
01283 {
01284
01285 if(!isalnum(separators[i]))
01286 {
01287 for(int j = text_len; j >= i; j--)
01288 {
01289 text[j + 1] = text[j];
01290 }
01291 if(!ibeam_left && i < ibeam_letter) ibeam_letter++;
01292 text_len++;
01293 text[i] = separators[i];
01294 }
01295 }
01296 else
01297 if(i >= text_len)
01298 {
01299 text[i] = separators[i];
01300 }
01301 }
01302
01303
01304 text[separator_len] = 0;
01305 }
01306
01307 }
01308
01309 void BC_TextBox::get_ibeam_position(int &x, int &y)
01310 {
01311 int i, j, k, row_begin, row_end, text_len;
01312
01313 text_len = strlen(text);
01314 y = 0;
01315 x = 0;
01316 for(i = 0; i < text_len; )
01317 {
01318 row_begin = i;
01319 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
01320 {
01321 text_row[j] = text[i];
01322 }
01323
01324 row_end = i;
01325 text_row[j] = 0;
01326
01327 if(ibeam_letter >= row_begin && ibeam_letter <= row_end)
01328 {
01329 x = get_text_width(font, text_row, ibeam_letter - row_begin);
01330
01331 return;
01332 }
01333
01334 if(text[i] == '\n')
01335 {
01336 i++;
01337 y += text_height;
01338 }
01339 }
01340
01341
01342 x = 0;
01343 return;
01344 }
01345
01346 void BC_TextBox::set_text_row(int row)
01347 {
01348 text_y = -(row * text_height) + top_margin;
01349 draw();
01350 }
01351
01352 int BC_TextBox::get_text_row()
01353 {
01354 return -(text_y - top_margin) / text_height;
01355 }
01356
01357 void BC_TextBox::find_ibeam(int dispatch_event)
01358 {
01359 int x, y;
01360 int old_x = text_x, old_y = text_y;
01361
01362 get_ibeam_position(x, y);
01363
01364 if(left_margin + text_x + x >= get_w() - right_margin - BCCURSORW)
01365 {
01366 text_x = -(x - (get_w() - get_w() / 4)) + left_margin;
01367 if(text_x > left_margin) text_x = left_margin;
01368 }
01369 else
01370 if(left_margin + text_x + x < left_margin)
01371 {
01372 text_x = -(x - (get_w() / 4)) + left_margin;
01373 if(text_x > left_margin) text_x = left_margin;
01374 }
01375
01376 while(y + text_y >= get_h() - text_height - bottom_margin)
01377 {
01378 text_y -= text_height;
01379
01380
01381 }
01382
01383 while(y + text_y < top_margin)
01384 {
01385 text_y += text_height;
01386 if(text_y > top_margin)
01387 {
01388 text_y = top_margin;
01389 break;
01390 }
01391 }
01392
01393 if(dispatch_event && (old_x != text_x || old_y != text_y)) motion_event();
01394 }
01395
01396 int BC_TextBox::get_cursor_letter(int cursor_x, int cursor_y)
01397 {
01398 int i, j, k, l, row_begin, row_end, text_len, result = 0, done = 0;
01399 text_len = strlen(text);
01400
01401 if(cursor_y < text_y)
01402 {
01403 result = 0;
01404 done = 1;
01405 }
01406
01407 for(i = 0, k = text_y; i < text_len && !done; k += text_height)
01408 {
01409 row_begin = i;
01410 for(j = 0; text[i] != '\n' && i < text_len; j++, i++)
01411 {
01412 text_row[j] = text[i];
01413 }
01414 row_end = i;
01415 text_row[j] = 0;
01416
01417 if(cursor_y >= k && cursor_y < k + text_height)
01418 {
01419 for(j = 0; j <= row_end - row_begin && !done; j++)
01420 {
01421 l = get_text_width(font, text_row, j) + text_x;
01422 if(l > cursor_x)
01423 {
01424 result = row_begin + j - 1;
01425 done = 1;
01426 }
01427 }
01428 if(!done)
01429 {
01430 result = row_end;
01431 done = 1;
01432 }
01433 }
01434 if(text[i] == '\n') i++;
01435
01436 if(i >= text_len && !done)
01437 {
01438 result = text_len;
01439 }
01440 }
01441 if(result < 0) result = 0;
01442 if(result > text_len) result = text_len;
01443 return result;
01444 }
01445
01446 void BC_TextBox::select_word(int &letter1, int &letter2, int ibeam_letter)
01447 {
01448 int text_len = strlen(text);
01449 letter1 = letter2 = ibeam_letter;
01450 do
01451 {
01452 if(isalnum(text[letter1])) letter1--;
01453 }while(letter1 > 0 && isalnum(text[letter1]));
01454 if(!isalnum(text[letter1])) letter1++;
01455
01456 do
01457 {
01458 if(isalnum(text[letter2])) letter2++;
01459 }while(letter2 < text_len && isalnum(text[letter2]));
01460 if(letter2 < text_len && text[letter2] == ' ') letter2++;
01461
01462 if(letter1 < 0) letter1 = 0;
01463 if(letter2 < 0) letter2 = 0;
01464 if(letter1 > text_len) letter1 = text_len;
01465 if(letter2 > text_len) letter2 = text_len;
01466 }
01467
01468 void BC_TextBox::copy_selection(int clipboard_num)
01469 {
01470 int text_len = strlen(text);
01471
01472 if(highlight_letter1 >= text_len ||
01473 highlight_letter2 > text_len ||
01474 highlight_letter1 < 0 ||
01475 highlight_letter2 < 0 ||
01476 highlight_letter2 - highlight_letter1 <= 0) return;
01477
01478 get_clipboard()->to_clipboard(&text[highlight_letter1],
01479 highlight_letter2 - highlight_letter1,
01480 clipboard_num);
01481 }
01482
01483 void BC_TextBox::paste_selection(int clipboard_num)
01484 {
01485 int len = get_clipboard()->clipboard_len(clipboard_num);
01486 if(len)
01487 {
01488 char *string = new char[len + 1];
01489 get_clipboard()->from_clipboard(string, len, clipboard_num);
01490 insert_text(string);
01491 }
01492 }
01493
01494 void BC_TextBox::set_keypress_draw(int value)
01495 {
01496 keypress_draw = value;
01497 }
01498
01499 int BC_TextBox::get_last_keypress()
01500 {
01501 return last_keypress;
01502 }
01503
01504 int BC_TextBox::get_ibeam_letter()
01505 {
01506 return ibeam_letter;
01507 }
01508
01509 void BC_TextBox::set_ibeam_letter(int number, int redraw)
01510 {
01511 this->ibeam_letter = number;
01512 if(redraw)
01513 {
01514 draw();
01515 }
01516 }
01517
01518 void BC_TextBox::set_separators(char *separators)
01519 {
01520 this->separators = separators;
01521 }
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538 BC_ScrollTextBox::BC_ScrollTextBox(BC_WindowBase *parent_window,
01539 int x,
01540 int y,
01541 int w,
01542 int rows,
01543 char *default_text)
01544 {
01545 this->parent_window = parent_window;
01546 this->x = x;
01547 this->y = y;
01548 this->w = w;
01549 this->rows = rows;
01550 this->default_text = default_text;
01551 }
01552
01553 BC_ScrollTextBox::~BC_ScrollTextBox()
01554 {
01555 delete yscroll;
01556 if(text)
01557 {
01558 text->gui = 0;
01559 delete text;
01560 }
01561 }
01562
01563 void BC_ScrollTextBox::create_objects()
01564 {
01565
01566 parent_window->add_subwindow(text = new BC_ScrollTextBoxText(this));
01567 parent_window->add_subwindow(yscroll = new BC_ScrollTextBoxYScroll(this));
01568 }
01569
01570 int BC_ScrollTextBox::handle_event()
01571 {
01572 return 1;
01573 }
01574
01575 int BC_ScrollTextBox::get_x()
01576 {
01577 return x;
01578 }
01579
01580 int BC_ScrollTextBox::get_y()
01581 {
01582 return y;
01583 }
01584
01585 int BC_ScrollTextBox::get_w()
01586 {
01587 return w;
01588 }
01589
01590 int BC_ScrollTextBox::get_rows()
01591 {
01592 return rows;
01593 }
01594
01595
01596 char* BC_ScrollTextBox::get_text()
01597 {
01598 return text->get_text();
01599 }
01600
01601 void BC_ScrollTextBox::update(char *text)
01602 {
01603 this->text->update(text);
01604 yscroll->update_length(this->text->get_text_rows(),
01605 this->text->get_text_row(),
01606 yscroll->get_handlelength());
01607 }
01608
01609 void BC_ScrollTextBox::reposition_window(int x, int y, int w, int rows)
01610 {
01611 this->x = x;
01612 this->y = y;
01613 this->w = w;
01614 this->rows = rows;
01615 text->reposition_window(x,
01616 y,
01617 w - yscroll->get_span(),
01618 rows);
01619 yscroll->reposition_window(x + w - yscroll->get_span(),
01620 y,
01621 BC_TextBox::calculate_row_h(rows,
01622 parent_window));
01623 yscroll->update_length(text->get_text_rows(),
01624 text->get_text_row(),
01625 rows);
01626 }
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636 BC_ScrollTextBoxText::BC_ScrollTextBoxText(BC_ScrollTextBox *gui)
01637 : BC_TextBox(gui->x,
01638 gui->y,
01639 gui->w - get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w(),
01640 gui->rows,
01641 gui->default_text)
01642 {
01643 this->gui = gui;
01644 }
01645
01646 BC_ScrollTextBoxText::~BC_ScrollTextBoxText()
01647 {
01648 if(gui)
01649 {
01650 gui->text = 0;
01651 delete gui;
01652 }
01653 }
01654
01655 int BC_ScrollTextBoxText::handle_event()
01656 {
01657 gui->yscroll->update_length(get_text_rows(),
01658 get_text_row(),
01659 gui->yscroll->get_handlelength());
01660 return gui->handle_event();
01661 }
01662
01663 int BC_ScrollTextBoxText::motion_event()
01664 {
01665 gui->yscroll->update_length(get_text_rows(),
01666 get_text_row(),
01667 gui->yscroll->get_handlelength());
01668 return 1;
01669 }
01670
01671
01672 BC_ScrollTextBoxYScroll::BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui)
01673 : BC_ScrollBar(gui->x +
01674 gui->w -
01675 get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w(),
01676 gui->y,
01677 SCROLL_VERT,
01678 BC_TextBox::calculate_row_h(gui->rows,
01679 gui->parent_window),
01680 gui->text->get_text_rows(),
01681 0,
01682 gui->rows)
01683 {
01684 this->gui = gui;
01685 }
01686
01687 BC_ScrollTextBoxYScroll::~BC_ScrollTextBoxYScroll()
01688 {
01689 }
01690
01691 int BC_ScrollTextBoxYScroll::handle_event()
01692 {
01693 gui->text->set_text_row(get_position());
01694 return 1;
01695 }
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706 BC_PopupTextBoxText::BC_PopupTextBoxText(BC_PopupTextBox *popup, int x, int y)
01707 : BC_TextBox(x, y, popup->text_w, 1, popup->default_text)
01708 {
01709 this->popup = popup;
01710 }
01711
01712 BC_PopupTextBoxText::~BC_PopupTextBoxText()
01713 {
01714 if(popup)
01715 {
01716 popup->textbox = 0;
01717 delete popup;
01718 popup = 0;
01719 }
01720 }
01721
01722
01723 int BC_PopupTextBoxText::handle_event()
01724 {
01725 popup->handle_event();
01726 return 1;
01727 }
01728
01729 BC_PopupTextBoxList::BC_PopupTextBoxList(BC_PopupTextBox *popup, int x, int y)
01730 : BC_ListBox(x,
01731 y,
01732 popup->text_w + BC_WindowBase::get_resources()->listbox_button[0]->get_w(),
01733 popup->list_h,
01734 LISTBOX_TEXT,
01735 popup->list_items,
01736 0,
01737 0,
01738 1,
01739 0,
01740 1)
01741 {
01742 this->popup = popup;
01743 }
01744 int BC_PopupTextBoxList::handle_event()
01745 {
01746 BC_ListBoxItem *item = get_selection(0, 0);
01747 if(item)
01748 {
01749 popup->textbox->update(item->get_text());
01750 popup->handle_event();
01751 }
01752 return 1;
01753 }
01754
01755
01756
01757
01758 BC_PopupTextBox::BC_PopupTextBox(BC_WindowBase *parent_window,
01759 ArrayList<BC_ListBoxItem*> *list_items,
01760 char *default_text,
01761 int x,
01762 int y,
01763 int text_w,
01764 int list_h)
01765 {
01766 this->x = x;
01767 this->y = y;
01768 this->list_h = list_h;
01769 this->default_text = default_text;
01770 this->text_w = text_w;
01771 this->parent_window = parent_window;
01772 this->list_items = list_items;
01773 }
01774
01775 BC_PopupTextBox::~BC_PopupTextBox()
01776 {
01777 delete listbox;
01778 if(textbox)
01779 {
01780 textbox->popup = 0;
01781 delete textbox;
01782 }
01783 }
01784
01785 int BC_PopupTextBox::create_objects()
01786 {
01787 int x = this->x, y = this->y;
01788 parent_window->add_subwindow(textbox = new BC_PopupTextBoxText(this, x, y));
01789 x += textbox->get_w();
01790 parent_window->add_subwindow(listbox = new BC_PopupTextBoxList(this, x, y));
01791 return 0;
01792 }
01793
01794 void BC_PopupTextBox::update(char *text)
01795 {
01796 textbox->update(text);
01797 }
01798
01799 void BC_PopupTextBox::update_list(ArrayList<BC_ListBoxItem*> *data)
01800 {
01801 listbox->update(data,
01802 0,
01803 0,
01804 1);
01805 }
01806
01807
01808 char* BC_PopupTextBox::get_text()
01809 {
01810 return textbox->get_text();
01811 }
01812
01813 int BC_PopupTextBox::get_number()
01814 {
01815 return listbox->get_selection_number(0, 0);
01816 }
01817
01818 int BC_PopupTextBox::get_x()
01819 {
01820 return x;
01821 }
01822
01823 int BC_PopupTextBox::get_y()
01824 {
01825 return y;
01826 }
01827
01828 int BC_PopupTextBox::get_w()
01829 {
01830 return textbox->get_w() + listbox->get_w();
01831 }
01832
01833 int BC_PopupTextBox::get_h()
01834 {
01835 return textbox->get_h();
01836 }
01837
01838 int BC_PopupTextBox::handle_event()
01839 {
01840 return 1;
01841 }
01842
01843 int BC_PopupTextBox::reposition_widget(int x, int y, int w, int h) {
01844 reposition_window(x, y);
01845 return(0);
01846 }
01847
01848 void BC_PopupTextBox::reposition_window(int x, int y)
01849 {
01850 this->x = x;
01851 this->y = y;
01852 int x1 = x, y1 = y;
01853 textbox->reposition_window(x1, y1);
01854 x1 += textbox->get_w();
01855 listbox->reposition_window(x1, y1);
01856 }
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
01872 int64_t default_value,
01873 int64_t min,
01874 int64_t max,
01875 int x,
01876 int y)
01877 : BC_TextBox(x,
01878 y,
01879 popup->text_w,
01880 1,
01881 default_value)
01882 {
01883 this->popup = popup;
01884 }
01885
01886 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
01887 float default_value,
01888 float min,
01889 float max,
01890 int x,
01891 int y)
01892 : BC_TextBox(x,
01893 y,
01894 popup->text_w,
01895 1,
01896 default_value)
01897 {
01898 this->popup = popup;
01899 }
01900
01901 BC_TumbleTextBoxText::~BC_TumbleTextBoxText()
01902 {
01903 if(popup)
01904 {
01905 popup->textbox = 0;
01906 delete popup;
01907 popup = 0;
01908 }
01909 }
01910
01911
01912
01913 int BC_TumbleTextBoxText::handle_event()
01914 {
01915 popup->handle_event();
01916 return 1;
01917 }
01918
01919 int BC_TumbleTextBoxText::button_press_event()
01920 {
01921 if(is_event_win())
01922 {
01923 if(get_buttonpress() < 4) return BC_TextBox::button_press_event();
01924 if(get_buttonpress() == 4)
01925 {
01926 popup->tumbler->handle_up_event();
01927 }
01928 else
01929 if(get_buttonpress() == 5)
01930 {
01931 popup->tumbler->handle_down_event();
01932 }
01933 return 1;
01934 }
01935 return 0;
01936 }
01937
01938
01939
01940
01941 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
01942 int64_t default_value,
01943 int64_t min,
01944 int64_t max,
01945 int x,
01946 int y,
01947 int text_w)
01948 {
01949 reset();
01950 this->x = x;
01951 this->y = y;
01952 this->min = min;
01953 this->max = max;
01954 this->default_value = default_value;
01955 this->text_w = text_w;
01956 this->parent_window = parent_window;
01957 use_float = 0;
01958 precision = 4;
01959 increment = 1;
01960 log_floatincrement = 0;
01961 }
01962
01963 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
01964 int default_value,
01965 int min,
01966 int max,
01967 int x,
01968 int y,
01969 int text_w)
01970 {
01971 reset();
01972 this->x = x;
01973 this->y = y;
01974 this->min = min;
01975 this->max = max;
01976 this->default_value = default_value;
01977 this->text_w = text_w;
01978 this->parent_window = parent_window;
01979 use_float = 0;
01980 precision = 4;
01981 increment = 1;
01982 log_floatincrement = 0;
01983 }
01984
01985 BC_TumbleTextBox::BC_TumbleTextBox(BC_WindowBase *parent_window,
01986 float default_value_f,
01987 float min_f,
01988 float max_f,
01989 int x,
01990 int y,
01991 int text_w)
01992 {
01993 reset();
01994 this->x = x;
01995 this->y = y;
01996 this->min_f = min_f;
01997 this->max_f = max_f;
01998 this->default_value_f = default_value_f;
01999 this->text_w = text_w;
02000 this->parent_window = parent_window;
02001 use_float = 1;
02002 precision = 4;
02003 increment = 1;
02004 log_floatincrement = 0;
02005 }
02006
02007 BC_TumbleTextBox::~BC_TumbleTextBox()
02008 {
02009
02010
02011 if(tumbler) delete tumbler;
02012 tumbler = 0;
02013
02014 if(textbox)
02015 {
02016 textbox->popup = 0;
02017 delete textbox;
02018 }
02019 textbox = 0;
02020 }
02021
02022 void BC_TumbleTextBox::reset()
02023 {
02024 textbox = 0;
02025 tumbler = 0;
02026 increment = 1.0;
02027 log_floatincrement = 0;
02028 }
02029
02030 void BC_TumbleTextBox::set_precision(int precision)
02031 {
02032 this->precision = precision;
02033 }
02034
02035 void BC_TumbleTextBox::set_increment(float value)
02036 {
02037 this->increment = value;
02038 if(tumbler) tumbler->set_increment(value);
02039 }
02040
02041 void BC_TumbleTextBox::set_log_floatincrement(int value)
02042 {
02043 this->log_floatincrement = value;
02044 if(tumbler) tumbler->set_log_floatincrement(value);
02045 }
02046
02047 int BC_TumbleTextBox::create_objects()
02048 {
02049 int x = this->x, y = this->y;
02050
02051 if(use_float)
02052 {
02053 parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
02054 default_value_f,
02055 min_f,
02056 max_f,
02057 x,
02058 y));
02059 textbox->set_precision(precision);
02060 }
02061 else
02062 parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
02063 default_value,
02064 min,
02065 max,
02066 x,
02067 y));
02068
02069 x += textbox->get_w();
02070
02071 if(use_float)
02072 parent_window->add_subwindow(tumbler = new BC_FTumbler(textbox,
02073 min_f,
02074 max_f,
02075 x,
02076 y));
02077 else
02078 parent_window->add_subwindow(tumbler = new BC_ITumbler(textbox,
02079 min,
02080 max,
02081 x,
02082 y));
02083
02084 tumbler->set_increment(increment);
02085 tumbler->set_log_floatincrement(log_floatincrement);
02086 return 0;
02087 }
02088
02089 char* BC_TumbleTextBox::get_text()
02090 {
02091 return textbox->get_text();
02092 }
02093
02094 int BC_TumbleTextBox::update(char *value)
02095 {
02096 textbox->update(value);
02097 return 0;
02098 }
02099
02100 int BC_TumbleTextBox::update(int64_t value)
02101 {
02102 textbox->update(value);
02103 return 0;
02104 }
02105
02106 int BC_TumbleTextBox::update(float value)
02107 {
02108 textbox->update(value);
02109 return 0;
02110 }
02111
02112
02113 int BC_TumbleTextBox::get_x()
02114 {
02115 return x;
02116 }
02117
02118 int BC_TumbleTextBox::get_y()
02119 {
02120 return y;
02121 }
02122
02123 int BC_TumbleTextBox::get_w()
02124 {
02125 return textbox->get_w() + tumbler->get_w();
02126 }
02127
02128 int BC_TumbleTextBox::get_h()
02129 {
02130 return textbox->get_h();
02131 }
02132
02133 int BC_TumbleTextBox::handle_event()
02134 {
02135 return 1;
02136 }
02137
02138 int BC_TumbleTextBox::reposition_widget(int x, int y, int w, int h) {
02139 reposition_window(x, y);
02140 return(0);
02141 }
02142
02143 void BC_TumbleTextBox::reposition_window(int x, int y)
02144 {
02145 this->x = x;
02146 this->y = y;
02147
02148 textbox->reposition_window(x,
02149 y,
02150 text_w,
02151 1);
02152 tumbler->reposition_window(x + textbox->get_w(),
02153 y);
02154 }
02155
02156
02157 void BC_TumbleTextBox::set_boundaries(int64_t min, int64_t max)
02158 {
02159 tumbler->set_boundaries(min, max);
02160 }
02161
02162 void BC_TumbleTextBox::set_boundaries(float min, float max)
02163 {
02164 tumbler->set_boundaries(min, max);
02165 }