X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbctextbox.C;h=2a34c18096952024b3c7c5fa9eb1a40a8432843c;hb=d348518c261d543e12282d516768d4f446434a42;hp=bd43f1cdf31b0bb4c63c45a3f797807d74286f44;hpb=a07e46d684a8aff4b56566b010b697ba9891872d;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/guicast/bctextbox.C b/cinelerra-5.1/guicast/bctextbox.C index bd43f1cd..2a34c180 100644 --- a/cinelerra-5.1/guicast/bctextbox.C +++ b/cinelerra-5.1/guicast/bctextbox.C @@ -24,11 +24,12 @@ #include "bcsignals.h" #include "bctextbox.h" #include "clip.h" -#include "colors.h" +#include "bccolors.h" #include #include "cursors.h" #include "filesystem.h" #include "keys.h" +#include "language.h" #include #include "bctimer.h" #include "vframe.h" @@ -133,6 +134,7 @@ BC_TextBox::~BC_TextBox() delete suggestions_popup; suggestions->remove_all_objects(); delete suggestions; + delete menu; delete [] wtext; if( size > 0 ) delete [] text; @@ -175,7 +177,9 @@ int BC_TextBox::reset_parameters(int rows, int has_border, int font, int size) separators = 0; xscroll = 0; yscroll = 0; + menu = 0; dirty = 1; + selection_active = 0; return 0; } @@ -187,8 +191,9 @@ int BC_TextBox::tstrlen() int BC_TextBox::tstrcmp(const char *cp) { - if( !tsize ) return strcmp(text, cp); - return strncmp(text, cp, tsize); + const char *tp = get_text(); + if( !tsize ) return strcmp(tp, cp); + return strncmp(tp, cp, tsize); } char *BC_TextBox::tstrcpy(const char *cp) @@ -246,6 +251,7 @@ int BC_TextBox::text_update(const wchar_t *wcp, int wsz, char *tcp, int tsz) int BC_TextBox::initialize() { + if (!skip_cursor) skip_cursor = new Timer; skip_cursor->update(); @@ -287,6 +293,10 @@ int BC_TextBox::initialize() draw(0); set_cursor(IBEAM_CURSOR, 0, 0); show_window(0); + + add_subwindow(menu = new BC_TextMenu(this)); + menu->create_objects(); + return 0; } @@ -392,9 +402,9 @@ void BC_TextBox::set_suggestions(ArrayList *suggestions, int column) // Show the highlighted text if( suggestions->size() == 1 ) { highlight_letter1 = wtext_update(); - text_update(wtext,wlen, text,tsize); + int len = text_update(wtext,wlen, text,tsize); char *current_suggestion = suggestions->get(0); - int col = highlight_letter1 - suggestion_column; + int col = len - suggestion_column; if( col < 0 ) col = 0; char *cur = current_suggestion + col; tstrcat(cur); @@ -673,6 +683,8 @@ void BC_TextBox::draw(int flush) highlight_letter1 <= row_end ) { int color = active && enabled && get_has_focus() ? resources->text_highlight : + selection_active ? + resources->text_selected_highlight : resources->text_inactive_highlight; if( unicode_active >= 0 ) color ^= LTBLUE; @@ -697,7 +709,7 @@ void BC_TextBox::draw(int flush) int len = row_end - row_begin; if( len > 0 ) { set_color(enabled ? resources->text_default : DMGREY); - draw_wtext(text_x, k + text_ascent, wtext_row, len, 0); + draw_single_text(1, font, text_x, k + text_ascent, wtext_row, len); } // Get ibeam location @@ -776,12 +788,10 @@ int BC_TextBox::button_press_event() const int debug = 0; if(!enabled) return 0; - if(get_buttonpress() != WHEEL_UP && - get_buttonpress() != WHEEL_DOWN && - get_buttonpress() != LEFT_BUTTON && - get_buttonpress() != MIDDLE_BUTTON) return 0; - - +// if(get_buttonpress() != WHEEL_UP && +// get_buttonpress() != WHEEL_DOWN && +// get_buttonpress() != LEFT_BUTTON && +// get_buttonpress() != MIDDLE_BUTTON) return 0; if(debug) printf("BC_TextBox::button_press_event %d\n", __LINE__); @@ -819,6 +829,11 @@ int BC_TextBox::button_press_event() update_scroll = 1; } else + if(get_buttonpress() == RIGHT_BUTTON) + { + menu->activate_menu(); + } + else { cursor_letter = get_cursor_letter(top_level->cursor_x, top_level->cursor_y); @@ -1605,29 +1620,15 @@ int BC_TextBox::keypress_event() if( ctrl_down() ) { switch( get_keypress() ) { case 'c': case 'C': { - if(highlight_letter1 != highlight_letter2) { - copy_selection(SECONDARY_SELECTION); - result = 1; - } + result = copy(0); break; } case 'v': case 'V': { - paste_selection(SECONDARY_SELECTION); - find_ibeam(1); - if(keypress_draw) draw(1); + result = paste(0); dispatch_event = 1; - result = 1; break; } case 'x': case 'X': { - if(highlight_letter1 != highlight_letter2) { - copy_selection(SECONDARY_SELECTION); - delete_selection(highlight_letter1, highlight_letter2, wtext_len); - highlight_letter2 = ibeam_letter = highlight_letter1; - } - - find_ibeam(1); - if(keypress_draw) draw(1); + result = cut(0); dispatch_event = 1; - result = 1; break; } case 'u': case 'U': { if( shift_down() ) { @@ -1658,6 +1659,53 @@ int BC_TextBox::keypress_event() } +int BC_TextBox::cut(int do_update) +{ + if( highlight_letter1 != highlight_letter2 ) { + int wtext_len = wtext_update(); + copy_selection(SECONDARY_SELECTION); + delete_selection(highlight_letter1, highlight_letter2, wtext_len); + highlight_letter2 = ibeam_letter = highlight_letter1; + } + + find_ibeam(1); + if( keypress_draw ) + draw(1); + + if( do_update ) { + skip_cursor->update(); + handle_event(); + } + return 1; +} + +int BC_TextBox::copy(int do_update) +{ + int result = 0; + if( highlight_letter1 != highlight_letter2 ) { + copy_selection(SECONDARY_SELECTION); + result = 1; + if( do_update ) { + skip_cursor->update(); + } + } + return result; +} + +int BC_TextBox::paste(int do_update) +{ + paste_selection(SECONDARY_SELECTION); + find_ibeam(1); + if( keypress_draw ) + draw(1); + if( do_update ) { + skip_cursor->update(); + handle_event(); + } + return 1; +} + + int BC_TextBox::uses_text() { return 1; @@ -2007,21 +2055,30 @@ void BC_TextBox::copy_selection(int clipboard_num) //printf(" BC_TextBox::copy_selection %d %d %d\n",highlight_letter1, highlight_letter2, clip_len); char ctext[4*clip_len+4]; clip_len = text_update(&wtext[highlight_letter1],clip_len, ctext,4*clip_len+4); - get_clipboard()->to_clipboard(ctext, clip_len, clipboard_num); + to_clipboard(ctext, clip_len, clipboard_num); + selection_active = 1; } +int BC_TextBox::selection_clear_event() +{ + if( !is_event_win() ) return 0; + selection_active = 0; + draw(1); + return 1; +} void BC_TextBox::paste_selection(int clipboard_num) { - int len = get_clipboard()->clipboard_len(clipboard_num); + int len = clipboard_len(clipboard_num); if( len > 0 ) { char cstring[len]; wchar_t wstring[len]; - get_clipboard()->from_clipboard(cstring, len, clipboard_num); --len; + from_clipboard(cstring, len, clipboard_num); --len; //printf("BC_TextBox::paste_selection %d '%*.*s'\n",len,len,len,cstring); len = BC_Resources::encode(BC_Resources::encoding, BC_Resources::wide_encoding, cstring,len, (char *)wstring,(len+1)*sizeof(wchar_t)) / sizeof(wchar_t); insert_text(wstring, len); + last_keypress = 0; } } @@ -2313,10 +2370,9 @@ void BC_ScrollTextBox::update_scrollbars() int xpos = get_x_pos(); if( xpos != xscroll->get_value() ) xscroll->update_value(xpos); - int xlength = text_width + view_w/4; - if( xlength != xscroll->get_length() || + if( text_width != xscroll->get_length() || view_w != xscroll->get_handlelength() ) - xscroll->update_length(xlength, xpos, view_w, 0); + xscroll->update_length(text_width, xpos, view_w, 0); } if( yscroll ) { yscroll->reposition_window(x + w - yscroll->get_span(), y, text->get_h()); @@ -2342,8 +2398,9 @@ int BC_ScrollTextBoxText::motion_event() } BC_ScrollTextBoxXScroll::BC_ScrollTextBoxXScroll(BC_ScrollTextBox *gui) - : BC_ScrollBar(gui->x, gui->y + gui->text->get_h(), SCROLL_HORIZ, gui->text->get_w(), - gui->text->get_text_width(MEDIUMFONT, gui->get_wtext()), 0, gui->w) + : BC_ScrollBar(gui->x, gui->y + gui->text->get_h(), SCROLL_HORIZ + SCROLL_STRETCH, + gui->text->get_w(), gui->text->get_text_width(MEDIUMFONT, gui->get_wtext()), + 0, gui->w) { this->gui = gui; } @@ -2359,8 +2416,8 @@ int BC_ScrollTextBoxXScroll::handle_event() } BC_ScrollTextBoxYScroll::BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui) - : BC_ScrollBar(gui->x + gui->text->get_w(), gui->y, SCROLL_VERT, gui->text->get_h(), - gui->text->get_text_rows(), 0, gui->rows) + : BC_ScrollBar(gui->x + gui->text->get_w(), gui->y, SCROLL_VERT, + gui->text->get_h(), gui->text->get_text_rows(), 0, gui->rows) { this->gui = gui; } @@ -2561,8 +2618,8 @@ BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup, } BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup, - float default_value, int x, int y) - : BC_TextBox(x, y, popup->text_w, 1, default_value) + float default_value, int x, int y, int precision) + : BC_TextBox(x, y, popup->text_w, 1, default_value, 1, MEDIUMFONT, precision) { this->popup = popup; } @@ -2587,19 +2644,10 @@ int BC_TumbleTextBoxText::handle_event() int BC_TumbleTextBoxText::button_press_event() { - if(is_event_win()) - { - if(get_buttonpress() < 4) return BC_TextBox::button_press_event(); - - if(get_buttonpress() == 4) - { - popup->tumbler->handle_up_event(); - } - else - if(get_buttonpress() == 5) - { - popup->tumbler->handle_down_event(); - } + if( get_enabled() && is_event_win() ) { + if( get_buttonpress() < 4 ) return BC_TextBox::button_press_event(); + if( get_buttonpress() == 4 ) popup->tumbler->handle_up_event(); + else if( get_buttonpress() == 5 ) popup->tumbler->handle_down_event(); return 1; } return 0; @@ -2714,31 +2762,17 @@ int BC_TumbleTextBox::create_objects() { int x = this->x, y = this->y; - if(use_float) - { - parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this, - default_value_f, x, y)); - textbox->set_precision(precision); - } - else - parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this, - default_value, x, y)); + textbox = use_float ? + new BC_TumbleTextBoxText(this, default_value_f, x, y, precision) : + new BC_TumbleTextBoxText(this, default_value, x, y); + parent_window->add_subwindow(textbox); x += textbox->get_w(); - if(use_float) - parent_window->add_subwindow(tumbler = new BC_FTumbler(textbox, - min_f, - max_f, - x, - y)); - else - parent_window->add_subwindow(tumbler = new BC_ITumbler(textbox, - min, - max, - x, - y)); - + tumbler = use_float ? + (BC_Tumbler *)new BC_FTumbler(textbox, min_f, max_f, x, y) : + (BC_Tumbler *)new BC_ITumbler(textbox, min, max, x, y); + parent_window->add_subwindow(tumbler); tumbler->set_increment(increment); return 0; } @@ -2855,6 +2889,66 @@ void BC_TumbleTextBox::set_boundaries(float min, float max) tumbler->set_boundaries(min, max); } + + +BC_TextMenu::BC_TextMenu(BC_TextBox *textbox) + : BC_PopupMenu(0, 0, 0, "", 0) +{ + this->textbox = textbox; +} + +BC_TextMenu::~BC_TextMenu() +{ +} + +void BC_TextMenu::create_objects() +{ + add_item(new BC_TextMenuCut(this)); + add_item(new BC_TextMenuCopy(this)); + add_item(new BC_TextMenuPaste(this)); +} + + +BC_TextMenuCut::BC_TextMenuCut(BC_TextMenu *menu) + : BC_MenuItem(_("Cut")) +{ + this->menu = menu; +} + +int BC_TextMenuCut::handle_event() +{ + menu->textbox->cut(1); + + return 0; +} + + +BC_TextMenuCopy::BC_TextMenuCopy(BC_TextMenu *menu) + : BC_MenuItem(_("Copy")) +{ + this->menu = menu; +} + +int BC_TextMenuCopy::handle_event() +{ + menu->textbox->copy(1); + return 0; +} + + +BC_TextMenuPaste::BC_TextMenuPaste(BC_TextMenu *menu) + : BC_MenuItem(_("Paste")) +{ + this->menu = menu; +} + +int BC_TextMenuPaste::handle_event() +{ + menu->textbox->paste(1); + return 0; +} + + void BC_TumbleTextBox::set_tooltip(const char *text) { textbox->set_tooltip(text);