titler rework, some code cleanup and fixes
[goodguy/history.git] / cinelerra-5.1 / guicast / bctextbox.C
index cecd249294da015d75bae7a3209d6ca782fc629a..e8cb09ced1fc35afb853cea90382e99766229cd8 100644 (file)
@@ -161,6 +161,7 @@ int BC_TextBox::reset_parameters(int rows, int has_border, int font, int size)
        text_selected = 0;
        word_selected = 0;
        line_selected = 0;
+       unicode_active = -1;
        text_x = 0;
        enabled = 1;
        highlighted = 0;
@@ -313,143 +314,91 @@ void BC_TextBox::set_precision(int precision)
 }
 
 // Compute suggestions for a path
-int BC_TextBox::calculate_suggestions(ArrayList<BC_ListBoxItem*> *entries)
+int BC_TextBox::calculate_suggestions(ArrayList<BC_ListBoxItem*> *entries, const char *filter)
 {
 // Let user delete suggestion
-       if(get_last_keypress() != BACKSPACE)
-       {
-
+       if(get_last_keypress() != BACKSPACE) {
 // Compute suggestions
                FileSystem fs;
                ArrayList<char*> suggestions;
                const char *current_text = get_text();
-
+               int suggestion_column = 0;
+               char dirname[BCTEXTLEN];  dirname[0] = 0;
+               if( current_text[0] == '/' || current_text[0] == '~' )
+                       strncpy(dirname, current_text, sizeof(dirname));
+               else if( !entries )
+                       getcwd(dirname, sizeof(dirname));
 // If directory, tabulate it
-               if(current_text[0] == '/' ||
-                       current_text[0] == '~')
-               {
-//printf("BC_TextBox::calculate_suggestions %d\n", __LINE__);
-                       char string[BCTEXTLEN];
-                       strncpy(string, current_text, sizeof(string));
-                       char *ptr = strrchr(string, '/');
-                       if(!ptr) ptr = strrchr(string, '~');
-
-//printf("BC_TextBox::calculate_suggestions %d\n", __LINE__);
-                       *(ptr + 1) = 0;
-                       int suggestion_column = ptr + 1 - string;
-
-                       fs.set_filter(get_resources()->filebox_filter);
-//                     fs.set_sort_order(filebox->sort_order);
-//                     fs.set_sort_field(filebox->column_type[filebox->sort_column]);
-
-
-//printf("BC_TextBox::calculate_suggestions %d %c %s\n", __LINE__, *ptr, string);
-                       if(current_text[0] == '~' && *ptr != '/')
-                       {
-                               fs.update("/home");
-                       }
-                       else
-                       {
-                               fs.parse_tildas(string);
-                               fs.update(string);
+               if( dirname[0] ) {
+                       if( filter ) fs.set_filter(filter);
+                       char *prefix, *cp;
+                       strncpy(dirname, current_text, sizeof(dirname));
+                       if( (cp=strrchr(dirname, '/')) ||
+                           (cp=strrchr(dirname, '~')) ) *++cp = 0;
+                       fs.parse_tildas(dirname);
+                       fs.update(dirname);
+                       cp = (char *)current_text;
+                       if( (prefix=strrchr(cp, '/')) ||
+                           (prefix=strrchr(cp, '~')) ) ++prefix;
+                       suggestion_column = !prefix ? 0 : prefix - cp;
+                       int prefix_len = prefix ? strlen(prefix) : 0;
+// only include items where the filename matches the basename prefix
+                       for(int i = 0; i < fs.total_files(); i++) {
+                               char *current_name = fs.get_entry(i)->name;
+                               if( prefix_len>0 && strncmp(prefix, current_name, prefix_len) ) continue;
+                               suggestions.append(current_name);
                        }
-//printf("BC_TextBox::calculate_suggestions %d %d\n", __LINE__, fs.total_files());
-
-
-// Accept only entries with matching trailing characters
-                       ptr = strrchr((char*)current_text, '/');
-                       if(!ptr) ptr = strrchr((char*)current_text, '~');
-                       if(ptr) ptr++;
-//printf("BC_TextBox::calculate_suggestions %d %s %p\n", __LINE__, current_text, ptr);
-
-
-                       if(ptr && *ptr)
-                       {
-                               for(int i = 0; i < fs.total_files(); i++)
-                               {
-                                       char *current_name = fs.get_entry(i)->name;
-                                       if(!strncmp(ptr, current_name, strlen(ptr)))
-                                       {
-                                               suggestions.append(current_name);
-       //printf("BC_TextBox::calculate_suggestions %d %s\n", __LINE__, current_name);
-                                       }
-                               }
-                       }
-                       else
-       // Accept all entries
-                       for(int i = 0; i < fs.total_files(); i++)
-                       {
-       //printf("BC_TextBox::calculate_suggestions %d %s\n", __LINE__, fs.get_entry(i)->name);
-                               suggestions.append(fs.get_entry(i)->name);
-                       }
-//printf("BC_TextBox::calculate_suggestions %d\n", __LINE__);
-
-// Add 1 to column to keep /
-                       set_suggestions(&suggestions, suggestion_column);
-//printf("BC_TextBox::calculate_suggestions %d\n", __LINE__);
                }
-               else
-// Get entries from current listbox with matching trailing characters
-               if(entries)
-               {
-// printf("BC_TextBox::calculate_suggestions %d %d\n",
-// __LINE__,
-// entries->size());
-                       for(int i = 0; i < entries->size(); i++)
-                       {
+               else if(entries) {
+                       char *prefix = (char *)current_text;
+                       int prefix_len = strlen(prefix);
+                       for(int i = 0; i < entries->size(); i++) {
                                char *current_name = entries->get(i)->get_text();
-
-//printf("BC_TextBox::calculate_suggestions %d %s %s\n", __LINE__, current_text, current_name);
-                               if(!strncmp(current_text, current_name, strlen(current_text)))
-                               {
-                                       suggestions.append(current_name);
-                               }
+                               if( prefix_len>0 && strncmp(prefix, current_name, prefix_len) ) continue;
+                               suggestions.append(current_name);
                        }
-
-                       set_suggestions(&suggestions, 0);
                }
+               set_suggestions(&suggestions, suggestion_column);
        }
 
        return 1;
 }
 
+void BC_TextBox::no_suggestions()
+{
+       if( suggestions_popup ) {
+               delete suggestions_popup;
+               suggestions_popup = 0;
+               activate();
+       }
+}
+
 void BC_TextBox::set_suggestions(ArrayList<char*> *suggestions, int column)
 {
 // Copy the array
        this->suggestions->remove_all_objects();
        this->suggestion_column = column;
 
-       if(suggestions)
-       {
-               for(int i = 0; i < suggestions->size(); i++)
-               {
+       if(suggestions) {
+               for(int i = 0; i < suggestions->size(); i++) {
                        this->suggestions->append(new BC_ListBoxItem(suggestions->get(i)));
                }
 
 // Show the popup without taking focus
-               if(suggestions->size() > 1)
-               {
-                       if(!suggestions_popup)
-                       {
-
-                               get_parent()->add_subwindow(suggestions_popup =
-                                       new BC_TextBoxSuggestions(this, x, y));
+               if( suggestions->size() > 1 ) {
+                       if( !suggestions_popup ) {
+                               suggestions_popup = new BC_TextBoxSuggestions(this, x, y);
+                               get_parent()->add_subwindow(suggestions_popup);
                                suggestions_popup->set_is_suggestions(1);
-                               suggestions_popup->activate(0);
                        }
-                       else
-                       {
-                               suggestions_popup->update(this->suggestions,
-                                       0,
-                                       0,
-                                       1);
-                               suggestions_popup->activate(0);
+                       else {
+                               suggestions_popup->update(this->suggestions, 0, 0, 1);
                        }
+                       suggestions_popup->activate(0);
                }
                else
 // Show the highlighted text
-               if(suggestions->size() == 1)
-               {
+               if( suggestions->size() == 1 ) {
                        highlight_letter1 = wtext_update();
                        text_update(wtext,wlen, text,tsize);
                        char *current_suggestion = suggestions->get(0);
@@ -457,22 +406,18 @@ void BC_TextBox::set_suggestions(ArrayList<char*> *suggestions, int column)
                        if( col < 0 ) col = 0;
                        char *cur = current_suggestion + col;
                        tstrcat(cur);
+                       draw(0);  // update positions
                        highlight_letter2 = wtext_update();
 //printf("BC_TextBox::set_suggestions %d %d\n", __LINE__, suggestion_column);
 
                        draw(1);
-
-                       delete suggestions_popup;
-                       suggestions_popup = 0;
+                       no_suggestions();
                }
        }
 
 // Clear the popup
-       if(!suggestions || !this->suggestions->size())
-       {
-               delete suggestions_popup;
-               suggestions_popup = 0;
-       }
+       if( !suggestions || !this->suggestions->size() )
+               no_suggestions();
 }
 
 void BC_TextBox::wset_selection(int char1, int char2, int ibeam)
@@ -553,10 +498,8 @@ void BC_TextBox::disable()
 {
        if(enabled) {
                enabled = 0;
-               if(top_level) {
-                       if(active) top_level->deactivate();
-                       draw(1);
-               }
+               deactivate();
+               draw(1);
        }
 }
 
@@ -733,14 +676,15 @@ void BC_TextBox::draw(int flush)
 
                if(k > top_margin-text_height && k < get_h()-bottom_margin) {
 // Draw highlighted region of row
-                       if(highlight_letter2 > highlight_letter1 &&
-                               highlight_letter2 > row_begin &&
-                               highlight_letter1 <= row_end) {
-                               if(active && enabled && get_has_focus())
-                                       set_color(resources->text_highlight);
-                               else
-                                       set_color(resources->text_inactive_highlight);
-
+                       if( highlight_letter2 > highlight_letter1 &&
+                           highlight_letter2 > row_begin &&
+                           highlight_letter1 <= row_end ) {
+                               int color = active && enabled && get_has_focus() ?
+                                       resources->text_highlight :
+                                       resources->text_inactive_highlight;
+                               if( unicode_active >= 0 )
+                                       color ^= LTBLUE;
+                               set_color(color);
                                if(highlight_letter1 >= row_begin &&
                                        highlight_letter1 <= row_end)
                                        highlight_x1 = positions[highlight_letter1];
@@ -764,6 +708,8 @@ void BC_TextBox::draw(int flush)
                                draw_wtext(text_x, k + text_ascent, wtext_row, len,
                                        0, &positions[wtext_row - wtext]);
                        }
+                       else
+                               positions[wtext_row - wtext] = 0;
 
 // Get ibeam location
                        if(ibeam_letter >= row_begin && ibeam_letter <= row_end) {
@@ -776,14 +722,8 @@ void BC_TextBox::draw(int flush)
 
 //printf("BC_TextBox::draw 3 %d\n", ibeam_y);
        if(need_ibeam) {
-               if( wtext_len == 0 ) {
-                       ibeam_x = 0;
-                       ibeam_y = 0;
-               }
-               else {
-                       ibeam_x = -1;
-                       ibeam_y = -1;
-               }
+//             ibeam_x = ibeam_y = !wtext_len ? 0 : -1;
+               ibeam_x = 0;  ibeam_y = k - text_y;
        }
 
 //printf("BC_TextBox::draw 4 %d\n", ibeam_y);
@@ -810,10 +750,14 @@ int BC_TextBox::focus_out_event()
 
 int BC_TextBox::cursor_enter_event()
 {
-       if(top_level->event_win == win && enabled)
+       if( top_level->event_win == win && enabled &&
+           !(top_level->get_resources()->textbox_focus_policy & CLICK_ACTIVATE) )
        {
                tooltip_done = 0;
-
+               if( !active ) {
+                       top_level->deactivate();
+                       activate();
+               }
                if(!highlighted)
                {
                        highlighted = 1;
@@ -829,10 +773,13 @@ int BC_TextBox::cursor_leave_event()
        if(highlighted)
        {
                highlighted = 0;
-               draw_border();
                hide_tooltip();
+               draw_border();
                flash(1);
        }
+       if( !suggestions_popup &&
+           !(top_level->get_resources()->textbox_focus_policy & CLICK_DEACTIVATE) )
+               deactivate();
        return 0;
 }
 
@@ -950,28 +897,15 @@ int BC_TextBox::button_press_event()
                return 1;
        }
        else
-       if(active && (!yscroll || !yscroll->is_event_win()))
-       {
-//printf("BC_TextBox::button_press_event %d\n", __LINE__);
-// Suggestion popup is not active but must be deactivated.
-               if(suggestions_popup)
-               {
-                       return 0;
-// printf("BC_TextBox::button_press_event %d\n", __LINE__);
-// // Pass event to suggestions popup
-//                     if(!suggestions_popup->button_press_event())
-//                     {
-// printf("BC_TextBox::button_press_event %d\n", __LINE__);
-//                             top_level->deactivate();
-//                     }
-               }
-               else
-               {
-                       top_level->deactivate();
+       if( active ) {
+               if( suggestions_popup && (!yscroll || !yscroll->is_event_win())) {
+                       if( suggestions_popup->button_press_event() )
+                               return suggestions_popup->handle_event();
                }
+               else if( (top_level->get_resources()->textbox_focus_policy & CLICK_DEACTIVATE) )
+                       deactivate();
        }
 
-
        return 0;
 }
 
@@ -1049,27 +983,23 @@ int BC_TextBox::cursor_motion_event()
 
 int BC_TextBox::activate()
 {
-       top_level->active_subwindow = this;
-       active = 1;
+       if( !active ) {
+               active = 1;
+               top_level->set_active_subwindow(this);
+               top_level->set_repeat(top_level->get_resources()->blink_rate);
+       }
        draw(1);
-       top_level->set_repeat(top_level->get_resources()->blink_rate);
        return 0;
 }
 
 int BC_TextBox::deactivate()
 {
-//printf("BC_TextBox::deactivate %d suggestions_popup=%p\n", __LINE__, suggestions_popup);
-       active = 0;
-       top_level->unset_repeat(top_level->get_resources()->blink_rate);
-       if(suggestions_popup)
-       {
-// Must deactivate instead of delete since this is called from BC_ListBox::button_press_event
-//             suggestions_popup->deactivate();
-
-               delete suggestions_popup;
-               suggestions_popup = 0;
+       if( active ) {
+               active = 0;
+               text_selected = word_selected = line_selected = 0;
+               top_level->set_active_subwindow(0);
+               top_level->unset_repeat(top_level->get_resources()->blink_rate);
        }
-
        draw(1);
        return 0;
 }
@@ -1195,16 +1125,11 @@ int BC_TextBox::repeat_event(int64_t duration)
 
 void BC_TextBox::default_keypress(int &dispatch_event, int &result)
 {
-    if((top_level->get_keypress() == RETURN) ||
-        (top_level->get_keypress() > 30 && top_level->get_keypress() <= 255))
-       {
-               int len;
-               wchar_t *temp_string = top_level->get_wkeystring(&len);
-               if(top_level->get_keypress() == RETURN) {
-                       temp_string[0] = '\n';  temp_string[1] = 0;
-                       len = 1;
-               }
-               insert_text(temp_string, len);
+       int key = top_level->get_keypress(), len;
+       if( (key == RETURN) || ( key >= 32 && key <= 255 ) ) {
+               wchar_t *wkeys = top_level->get_wkeystring(&len);
+               if( key == RETURN ) { wkeys[0] = '\n';  wkeys[1] = 0;  len = 1; }
+               insert_text(wkeys, len);
                find_ibeam(1);
                draw(1);
                dispatch_event = 1;
@@ -1224,99 +1149,140 @@ int BC_TextBox::keypress_event()
 
        int wtext_len = wtext_update();
        last_keypress = get_keypress();
+
+       if( unicode_active >= 0 ) {
+               wchar_t wch = 0;
+               int wlen =  -1;
+               switch( last_keypress ) {
+//unicode active acitons
+               case RETURN: {
+                       for( int i=highlight_letter1+1; i<highlight_letter2; ++i ) {
+                               int ch = nib(wtext[i]);
+                               if( ch < 0 ) return 1;
+                               wch = (wch<<4) + ch;
+                       }
+                       if( wch ) {
+                               dispatch_event = 1;
+                               unicode_active = -1;
+                               result = 1;
+                               wlen = 1;
+                               break;
+                       } } // fall through
+               case ESC: {
+                       unicode_active = -1;
+                       result = 1;
+                       wlen = 0;
+                       break; }
+               case BACKSPACE: {
+                       if(ibeam_letter > 0) {
+                               delete_selection(ibeam_letter - 1, ibeam_letter, wtext_len);
+                               highlight_letter2 = --ibeam_letter;
+                               if( highlight_letter1 >= highlight_letter2 )
+                                       unicode_active = -1;
+                       }
+                       result = 1;
+                       wlen = 0;
+                       break; }
+               case '0': case '1': case '2': case '3': case '4':
+               case '5': case '6': case '7': case '8': case '9':
+               case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
+               case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': {
+                       int n = nib(last_keypress);
+                       wch = n < 10 ? '0'+n : 'A'+n-10;
+                       result = 1;
+                       wlen = 1;
+                       break; }
+//normal actions
+               case TAB:
+               case LEFTTAB:
+                       break;
+//ignored actions
+               default:
+                       result = 1;
+                       break;
+               }
+               if( wlen >= 0 ) {
+                       insert_text(&wch, wlen);
+                       find_ibeam(1);
+                       if( unicode_active >= 0 )
+                               highlight_letter2 = ibeam_letter;
+                       else
+                               highlight_letter1 = highlight_letter2 = 0;
+                       draw(1);
+               }
+       }
+
+       if( !result ) {
 //printf("BC_TextBox::keypress_event %d %x\n", __LINE__, last_keypress)
-       switch(last_keypress)
-       {
-               case ESC:
+               switch(last_keypress) {
+               case ESC: {
 // Deactivate the suggestions
-                       if(suggestions && suggestions_popup)
-                       {
-                               delete suggestions_popup;
-                               suggestions_popup = 0;
+                       if( suggestions_popup ) {
+                               no_suggestions();
                                result = 1;
                        }
-                       else
-                       {
+                       else {
                                top_level->deactivate();
                                result = 0;
                        }
-                       break;
-
-
-
+                       break; }
 
-
-               case RETURN:
-                       if(rows == 1)
-                       {
+               case RETURN: {
+                       if( rows == 1 ) {
+                               highlight_letter1 = highlight_letter2 = 0;
+                               ibeam_letter = wtext_update();
                                top_level->deactivate();
                                dispatch_event = 1;
                                result = 0;
                        }
-                       else
-                       {
+                       else {
                                default_keypress(dispatch_event, result);
                        }
-                       break;
-
-
+                       break; }
 
 
 // Handle like a default keypress
-               case TAB:
+               case TAB: {
                        top_level->cycle_textboxes(1);
                        result = 1;
-                       break;
+                       break; }
 
-
-
-               case LEFTTAB:
+               case LEFTTAB: {
                        top_level->cycle_textboxes(-1);
                        result = 1;
-                       break;
+                       break; }
 
-               case LEFT:
-                       if(ibeam_letter > 0)
-                       {
+               case LEFT: {
+                       if(ibeam_letter > 0) {
                                int old_ibeam_letter = ibeam_letter;
 // Single character
-                               if(!ctrl_down())
-                               {
+                               if(!ctrl_down()) {
                                        ibeam_letter--;
                                }
-                               else
+                               else {
 // Word
-                               {
                                        ibeam_letter--;
                                        while(ibeam_letter > 0 && isalnum(wtext[ibeam_letter - 1]))
                                                ibeam_letter--;
                                }
 
-
 // Extend selection
-                               if(top_level->shift_down())
-                               {
+                               if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
+                                       if(highlight_letter1 == highlight_letter2) {
                                                highlight_letter1 = ibeam_letter;
                                                highlight_letter2 = old_ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter1 == old_ibeam_letter) {
 // Extend left highlight
-                                       if(highlight_letter1 == old_ibeam_letter)
-                                       {
                                                highlight_letter1 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter2 == old_ibeam_letter) {
 // Shrink right highlight
-                                       if(highlight_letter2 == old_ibeam_letter)
-                                       {
                                                highlight_letter2 = ibeam_letter;
                                        }
                                }
-                               else
-                               {
+                               else {
                                        highlight_letter1 = highlight_letter2 = ibeam_letter;
                                }
 
@@ -1325,50 +1291,39 @@ int BC_TextBox::keypress_event()
                                if(keypress_draw) draw(1);
                        }
                        result = 1;
-                       break;
+                       break; }
 
-               case RIGHT:
-                       if(ibeam_letter < wtext_len)
-                       {
+               case RIGHT: {
+                       if(ibeam_letter < wtext_len) {
                                int old_ibeam_letter = ibeam_letter;
 // Single character
-                               if(!ctrl_down())
-                               {
+                               if(!ctrl_down()) {
                                        ibeam_letter++;
                                }
-                               else
+                               else {
 // Word
-                               {
-                                       while(ibeam_letter < wtext_len && isalnum(wtext[ibeam_letter++]))
-                                               ;
+                                       while(ibeam_letter < wtext_len && isalnum(wtext[ibeam_letter++]));
                                }
 
 
 
 // Extend selection
-                               if(top_level->shift_down())
-                               {
+                               if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
+                                       if(highlight_letter1 == highlight_letter2) {
                                                highlight_letter1 = old_ibeam_letter;
                                                highlight_letter2 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter1 == old_ibeam_letter) {
 // Shrink left highlight
-                                       if(highlight_letter1 == old_ibeam_letter)
-                                       {
                                                highlight_letter1 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter2 == old_ibeam_letter) {
 // Expand right highlight
-                                       if(highlight_letter2 == old_ibeam_letter)
-                                       {
                                                highlight_letter2 = ibeam_letter;
                                        }
                                }
-                               else
-                               {
+                               else {
                                        highlight_letter1 = highlight_letter2 = ibeam_letter;
                                }
 
@@ -1376,52 +1331,42 @@ int BC_TextBox::keypress_event()
                                if(keypress_draw) draw(1);
                        }
                        result = 1;
-                       break;
+                       break; }
 
-               case UP:
-                       if(suggestions && suggestions_popup)
-                       {
+               case UP: {
+                       if( suggestions && suggestions_popup ) {
 // Pass to suggestions popup
 //printf("BC_TextBox::keypress_event %d\n", __LINE__);
                                suggestions_popup->activate(1);
                                suggestions_popup->keypress_event();
                                result = 1;
                        }
-                       else
-                       if(ibeam_letter > 0)
-                       {
+                       else if(ibeam_letter > 0) {
 //printf("BC_TextBox::keypress_event 1 %d %d %d\n", ibeam_x, ibeam_y, ibeam_letter);
                                int new_letter = get_cursor_letter2(ibeam_x + text_x,
                                        ibeam_y + text_y - text_height);
 //printf("BC_TextBox::keypress_event 2 %d %d %d\n", ibeam_x, ibeam_y, new_letter);
 
 // Extend selection
-                               if(top_level->shift_down())
-                               {
+                               if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
+                                       if(highlight_letter1 == highlight_letter2) {
                                                highlight_letter1 = new_letter;
                                                highlight_letter2 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter1 == ibeam_letter) {
 // Expand left highlight
-                                       if(highlight_letter1 == ibeam_letter)
-                                       {
                                                highlight_letter1 = new_letter;
                                        }
-                                       else
+                                       else if(highlight_letter2 == ibeam_letter) {
 // Shrink right highlight
-                                       if(highlight_letter2 == ibeam_letter)
-                                       {
                                                highlight_letter2 = new_letter;
                                        }
                                }
                                else
                                        highlight_letter1 = highlight_letter2 = new_letter;
 
-                               if(highlight_letter1 > highlight_letter2)
-                               {
+                               if(highlight_letter1 > highlight_letter2) {
                                        int temp = highlight_letter1;
                                        highlight_letter1 = highlight_letter2;
                                        highlight_letter2 = temp;
@@ -1432,41 +1377,33 @@ int BC_TextBox::keypress_event()
                                if(keypress_draw) draw(1);
                        }
                        result = 1;
-                       break;
+                       break; }
 
-               case PGUP:
-                       if(ibeam_letter > 0)
-                       {
+               case PGUP: {
+                       if(ibeam_letter > 0) {
                                int new_letter = get_cursor_letter2(ibeam_x + text_x,
                                        ibeam_y + text_y - get_h());
 
 // Extend selection
-                               if(top_level->shift_down())
-                               {
+                               if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
+                                       if(highlight_letter1 == highlight_letter2) {
                                                highlight_letter1 = new_letter;
                                                highlight_letter2 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter1 == ibeam_letter) {
 // Expand left highlight
-                                       if(highlight_letter1 == ibeam_letter)
-                                       {
                                                highlight_letter1 = new_letter;
                                        }
-                                       else
+                                       else if(highlight_letter2 == ibeam_letter) {
 // Shrink right highlight
-                                       if(highlight_letter2 == ibeam_letter)
-                                       {
                                                highlight_letter2 = new_letter;
                                        }
                                }
                                else
                                        highlight_letter1 = highlight_letter2 = new_letter;
 
-                               if(highlight_letter1 > highlight_letter2)
-                               {
+                               if(highlight_letter1 > highlight_letter2) {
                                        int temp = highlight_letter1;
                                        highlight_letter1 = highlight_letter2;
                                        highlight_letter2 = temp;
@@ -1477,15 +1414,14 @@ int BC_TextBox::keypress_event()
                                if(keypress_draw) draw(1);
                        }
                        result = 1;
-                       break;
+                       break; }
 
-               case DOWN:
+               case DOWN: {
 // printf("BC_TextBox::keypress_event %d %p %p\n",
 // __LINE__,
 // suggestions,
 // suggestions_popup);
-                       if(suggestions && suggestions_popup)
-                       {
+                       if( suggestions && suggestions_popup ) {
 // Pass to suggestions popup
                                suggestions_popup->activate(1);
                                suggestions_popup->keypress_event();
@@ -1499,32 +1435,25 @@ int BC_TextBox::keypress_event()
                                        ibeam_y + text_y + text_height);
 //printf("BC_TextBox::keypress_event 10 %d\n", new_letter);
 
-                               if(top_level->shift_down())
-                               {
+                               if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
+                                       if(highlight_letter1 == highlight_letter2) {
                                                highlight_letter1 = new_letter;
                                                highlight_letter2 = ibeam_letter;
                                        }
-                                       else
+                                       else if(highlight_letter1 == ibeam_letter) {
 // Shrink left highlight
-                                       if(highlight_letter1 == ibeam_letter)
-                                       {
                                                highlight_letter1 = new_letter;
                                        }
-                                       else
+                                       else if(highlight_letter2 == ibeam_letter) {
 // Expand right highlight
-                                       if(highlight_letter2 == ibeam_letter)
-                                       {
                                                highlight_letter2 = new_letter;
                                        }
                                }
                                else
                                        highlight_letter1 = highlight_letter2 = new_letter;
 
-                               if(highlight_letter1 > highlight_letter2)
-                               {
+                               if(highlight_letter1 > highlight_letter2) {
                                        int temp = highlight_letter1;
                                        highlight_letter1 = highlight_letter2;
                                        highlight_letter2 = temp;
@@ -1537,84 +1466,67 @@ int BC_TextBox::keypress_event()
 //printf("BC_TextBox::keypress_event 20 %d\n", ibeam_letter);
                        }
                        result = 1;
-                       break;
+                       break; }
 
-               case PGDN:
-                       {
+               case PGDN: {
 // Extend selection
-                               int new_letter = get_cursor_letter2(ibeam_x + text_x,
-                                       ibeam_y + text_y + get_h());
+                       int new_letter = get_cursor_letter2(ibeam_x + text_x,
+                               ibeam_y + text_y + get_h());
 //printf("BC_TextBox::keypress_event 10 %d\n", new_letter);
 
-                               if(top_level->shift_down())
-                               {
+                       if(top_level->shift_down()) {
 // Initialize highlighting
-                                       if(highlight_letter1 == highlight_letter2)
-                                       {
-                                               highlight_letter1 = new_letter;
-                                               highlight_letter2 = ibeam_letter;
-                                       }
-                                       else
+                               if(highlight_letter1 == highlight_letter2) {
+                                       highlight_letter1 = new_letter;
+                                       highlight_letter2 = ibeam_letter;
+                               }
+                               else if(highlight_letter1 == ibeam_letter) {
 // Shrink left highlight
-                                       if(highlight_letter1 == ibeam_letter)
-                                       {
-                                               highlight_letter1 = new_letter;
-                                       }
-                                       else
+                                       highlight_letter1 = new_letter;
+                               }
+                               else if(highlight_letter2 == ibeam_letter) {
 // Expand right highlight
-                                       if(highlight_letter2 == ibeam_letter)
-                                       {
-                                               highlight_letter2 = new_letter;
-                                       }
+                                       highlight_letter2 = new_letter;
                                }
-                               else
-                                       highlight_letter1 = highlight_letter2 = new_letter;
+                       }
+                       else
+                               highlight_letter1 = highlight_letter2 = new_letter;
 
-                               if(highlight_letter1 > highlight_letter2)
-                               {
-                                       int temp = highlight_letter1;
-                                       highlight_letter1 = highlight_letter2;
-                                       highlight_letter2 = temp;
-                               }
-                               ibeam_letter = new_letter;
+                       if(highlight_letter1 > highlight_letter2) {
+                               int temp = highlight_letter1;
+                               highlight_letter1 = highlight_letter2;
+                               highlight_letter2 = temp;
+                       }
+                       ibeam_letter = new_letter;
 
-                               find_ibeam(1);
-                               if(keypress_draw) draw(1);
+                       find_ibeam(1);
+                       if(keypress_draw) draw(1);
 
 //printf("BC_TextBox::keypress_event 20 %d\n", ibeam_letter);
-                       }
                        result = 1;
-                       break;
+                       break; }
 
-               case END:
-               {
-                       delete suggestions_popup;
-                       suggestions_popup = 0;
+               case END: {
+                       no_suggestions();
 
                        int old_ibeam_letter = ibeam_letter;
 
                        while(ibeam_letter < wtext_len && wtext[ibeam_letter] != '\n')
                                ibeam_letter++;
 
-                       if(top_level->shift_down())
-                       {
+                       if(top_level->shift_down()) {
 // Begin selection
-                               if(highlight_letter1 == highlight_letter2)
-                               {
+                               if(highlight_letter1 == highlight_letter2) {
                                        highlight_letter2 = ibeam_letter;
                                        highlight_letter1 = old_ibeam_letter;
                                }
-                               else
+                               else if(highlight_letter1 == old_ibeam_letter) {
 // Shrink selection
-                               if(highlight_letter1 == old_ibeam_letter)
-                               {
                                        highlight_letter1 = highlight_letter2;
                                        highlight_letter2 = ibeam_letter;
                                }
-                               else
+                               else if(highlight_letter2 == old_ibeam_letter) {
 // Extend selection
-                               if(highlight_letter2 == old_ibeam_letter)
-                               {
                                        highlight_letter2 = ibeam_letter;
                                }
                        }
@@ -1624,13 +1536,10 @@ int BC_TextBox::keypress_event()
                        find_ibeam(1);
                        if(keypress_draw) draw(1);
                        result = 1;
-                       break;
-               }
+                       break; }
 
-               case HOME:
-               {
-                       delete suggestions_popup;
-                       suggestions_popup = 0;
+               case HOME: {
+                       no_suggestions();
 
                        int old_ibeam_letter = ibeam_letter;
 
@@ -1665,26 +1574,18 @@ int BC_TextBox::keypress_event()
                        find_ibeam(1);
                        if(keypress_draw) draw(1);
                        result = 1;
-                       break;
-               }
+                       break; }
 
-       case BACKSPACE:
-                       if(suggestions_popup)
-                       {
-                               delete suggestions_popup;
-                               suggestions_popup = 0;
-                       }
+               case BACKSPACE: {
+                       no_suggestions();
 
-                       if(highlight_letter1 == highlight_letter2)
-                       {
-                               if(ibeam_letter > 0)
-                               {
+                       if(highlight_letter1 == highlight_letter2) {
+                               if(ibeam_letter > 0) {
                                        delete_selection(ibeam_letter - 1, ibeam_letter, wtext_len);
                                        ibeam_letter--;
                                }
                        }
-                       else
-                       {
+                       else {
                                delete_selection(highlight_letter1, highlight_letter2, wtext_len);
                                highlight_letter2 = ibeam_letter = highlight_letter1;
                        }
@@ -1693,19 +1594,16 @@ int BC_TextBox::keypress_event()
                        if(keypress_draw) draw(1);
                        dispatch_event = 1;
                        result = 1;
-               break;
+                       break; }
 
-               case DELETE:
+               case DELETE: {
 //printf("BC_TextBox::keypress_event %d\n", __LINE__);
-                       if(highlight_letter1 == highlight_letter2)
-                       {
-                               if(ibeam_letter < wtext_len)
-                               {
+                       if(highlight_letter1 == highlight_letter2) {
+                               if(ibeam_letter < wtext_len) {
                                        delete_selection(ibeam_letter, ibeam_letter + 1, wtext_len);
                                }
                        }
-                       else
-                       {
+                       else {
                                delete_selection(highlight_letter1, highlight_letter2, wtext_len);
                                highlight_letter2 = ibeam_letter = highlight_letter1;
                        }
@@ -1714,35 +1612,26 @@ int BC_TextBox::keypress_event()
                        if(keypress_draw) draw(1);
                        dispatch_event = 1;
                        result = 1;
-                       break;
-
+                       break; }
 
-
-               default:
-                       if(ctrl_down())
-                       {
-                               if(get_keypress() == 'c' || get_keypress() == 'C')
-                               {
-                                       if(highlight_letter1 != highlight_letter2)
-                                       {
+               default: {
+                       if( ctrl_down() ) {
+                               switch( get_keypress() ) {
+                               case 'c': case 'C': {
+                                       if(highlight_letter1 != highlight_letter2) {
                                                copy_selection(SECONDARY_SELECTION);
                                                result = 1;
                                        }
-                               }
-                               else
-                               if(get_keypress() == 'v' || get_keypress() == 'V')
-                               {
+                                       break; }
+                               case 'v': case 'V': {
                                        paste_selection(SECONDARY_SELECTION);
                                        find_ibeam(1);
                                        if(keypress_draw) draw(1);
                                        dispatch_event = 1;
                                        result = 1;
-                               }
-                               else
-                               if(get_keypress() == 'x' || get_keypress() == 'X')
-                               {
-                                       if(highlight_letter1 != highlight_letter2)
-                                       {
+                                       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;
@@ -1752,23 +1641,36 @@ int BC_TextBox::keypress_event()
                                        if(keypress_draw) draw(1);
                                        dispatch_event = 1;
                                        result = 1;
+                                       break; }
+                               case 'u': case 'U': {
+                                       if( shift_down() ) {
+                                               unicode_active = ibeam_letter;
+                                               wchar_t wkey = 'U';
+                                               insert_text(&wkey, 1);
+                                               find_ibeam(1);
+                                               highlight_letter1 = unicode_active;
+                                               highlight_letter2 = ibeam_letter;
+                                               draw(1);
+                                               result = 1;
+                                       }
+                                       break; }
                                }
-
                                break;
                        }
 
                        default_keypress(dispatch_event, result);
-                       break;
+                       break; }
+               }
        }
 
        if(result) skip_cursor->update();
        if(dispatch_event && handle_event())
                result = 1;
+
        return result;
 }
 
 
-
 int BC_TextBox::uses_text()
 {
        return 1;
@@ -1791,14 +1693,12 @@ void BC_TextBox::insert_text(const wchar_t *wcp, int len)
 {
        if( len < 0 ) len = wcslen(wcp);
        int wtext_len = wtext_update();
-       if(highlight_letter1 < highlight_letter2)
-       {
+       if( unicode_active < 0 && highlight_letter1 < highlight_letter2 ) {
                delete_selection(highlight_letter1, highlight_letter2, wtext_len);
                highlight_letter2 = ibeam_letter = highlight_letter1;
                wtext_len = wtext_update();
        }
 
-
        int i, j;
        for(i=wtext_len-1, j=wtext_len+len-1; i>=ibeam_letter; i--, j--) {
                if( j >= wsize ) continue;
@@ -1873,9 +1773,8 @@ void BC_TextBox::get_ibeam_position(int &x, int &y)
 {
        int i, row_begin, row_end;
        int wtext_len = wtext_update();
+       x = y = 0;
 
-       y = 0;
-       x = 0;
        for( i=0; i<wtext_len; ) {
                row_begin = i;
                for(; i<wtext_len && wtext[i]!='\n'; i++);
@@ -1975,15 +1874,15 @@ int BC_TextBox::get_cursor_letter(int cursor_x, int cursor_y)
                        first_visible_row = 1;
                        got_visible_row = 1;
                }
-               
-               if( (k+text_height >= get_h() - bottom_margin || 
-                       (row_end >= wtext_len && k < get_h() - bottom_margin && 
+
+               if( (k+text_height >= get_h() - bottom_margin ||
+                       (row_end >= wtext_len && k < get_h() - bottom_margin &&
                                k + text_height > 0)) )
                        last_visible_row = 1;
 
 // Cursor is inside vertical range of row
-               if((cursor_y >= top_margin && 
-                       cursor_y < get_h() - bottom_margin && 
+               if((cursor_y >= top_margin &&
+                       cursor_y < get_h() - bottom_margin &&
                        cursor_y >= k && cursor_y < k + text_height) ||
 // Cursor is above 1st row
                        (cursor_y < k + text_height && first_visible_row) ||
@@ -1996,7 +1895,7 @@ int BC_TextBox::get_cursor_letter(int cursor_x, int cursor_y)
                                if((column2 + column1) / 2 >= cursor_x) {
                                        result = j - 1;
                                        done = 1;
-// printf("BC_TextBox::get_cursor_letter %d %d %d %d\n", 
+// printf("BC_TextBox::get_cursor_letter %d %d %d %d\n",
 // __LINE__, result, first_visible_row, last_visible_row);
                                }
                                column1 = column2;
@@ -2020,7 +1919,7 @@ int BC_TextBox::get_cursor_letter(int cursor_x, int cursor_y)
        }
 
 
-// printf("BC_TextBox::get_cursor_letter %d cursor_y=%d k=%d h=%d %d %d\n", 
+// printf("BC_TextBox::get_cursor_letter %d cursor_y=%d k=%d h=%d %d %d\n",
 //  __LINE__, cursor_y, k, get_h(), first_visible_row, last_visible_row);
        if(result < 0) result = 0;
        if(result > wtext_len) {
@@ -2065,7 +1964,7 @@ int BC_TextBox::get_cursor_letter2(int cursor_x, int cursor_y)
                        }
                }
                if(wtext[i] == '\n') i++;
-               
+
                if(i >= wtext_len && !done) {
                        result = wtext_len;
                }
@@ -2085,11 +1984,8 @@ void BC_TextBox::select_word(int &letter1, int &letter2, int ibeam_letter)
        if( letter1 > wtext_len ) letter1 = wtext_len;
        if( letter2 > wtext_len ) letter2 = wtext_len;
        if( !wtext_len ) return;
-
-       while( letter1 > 0 && iswalnum(wtext[letter1]) ) --letter1;
-       if( letter1 < wtext_len && iswspace(wtext[letter1]) ) ++letter1;
-
-       while( letter2 < wtext_len && iswalnum(wtext[letter2]) ) ++letter2;
+       for( int i=letter1; i>=0 && iswalnum(wtext[i]); --i ) letter1 = i;
+       for( int i=letter2; i<wtext_len && iswalnum(wtext[i]); ) letter2 = ++i;
        if( letter2 < wtext_len && wtext[letter2] == ' ' ) ++letter2;
 }
 
@@ -2097,26 +1993,14 @@ void BC_TextBox::select_word(int &letter1, int &letter2, int ibeam_letter)
 void BC_TextBox::select_line(int &letter1, int &letter2, int ibeam_letter)
 {
        int wtext_len = wtext_update();
-       if(!wtext_len) return;
-
        letter1 = letter2 = ibeam_letter;
-
-// Rewind to previous linefeed
-       do {
-               if( wtext[letter1] != '\n' ) letter1--;
-       } while( letter1 > 0 && wtext[letter1] != '\n' );
-       if( wtext[letter1] == '\n' ) letter1++;
-
-// Advance to next linefeed
-       do {
-               if( wtext[letter2] != '\n' ) letter2++;
-       } while( letter2 < wtext_len && wtext[letter2] != '\n' );
-       if( letter2 < wtext_len && wtext[letter2] == '\n') letter2++;
-
-       if(letter1 < 0) letter1 = 0;
-       if(letter2 < 0) letter2 = 0;
-       if(letter1 > wtext_len) letter1 = wtext_len;
-       if(letter2 > wtext_len) letter2 = wtext_len;
+       if( letter1 < 0 ) letter1 = 0;
+       if( letter2 < 0 ) letter2 = 0;
+       if( letter1 > wtext_len ) letter1 = wtext_len;
+       if( letter2 > wtext_len ) letter2 = wtext_len;
+       if( !wtext_len ) return;
+       for( int i=letter1; i>=0 && wtext[i]!='\n'; --i ) letter1 = i;
+       for( int i=letter2; i<wtext_len && wtext[i]!='\n'; ) letter2 = ++i;
 }
 
 void BC_TextBox::copy_selection(int clipboard_num)
@@ -2189,20 +2073,9 @@ int BC_TextBox::get_rows()
 
 
 
-BC_TextBoxSuggestions::BC_TextBoxSuggestions(BC_TextBox *text_box,
-       int x,
-       int y)
- : BC_ListBox(x,
-       y,
-       text_box->get_w(),
-       200,
-       LISTBOX_TEXT,
-       text_box->suggestions,
-       0,
-       0,
-       1,
-       0,
-       1)
+BC_TextBoxSuggestions::BC_TextBoxSuggestions(BC_TextBox *text_box, int x, int y)
+ : BC_ListBox(x, y, text_box->get_w(), 200, LISTBOX_TEXT,
+       text_box->suggestions, 0, 0, 1, 0, 1)
 {
        this->text_box = text_box;
        set_use_button(0);
@@ -2213,35 +2086,6 @@ BC_TextBoxSuggestions::~BC_TextBoxSuggestions()
 {
 }
 
-int BC_TextBoxSuggestions::selection_changed()
-{
-#if 0
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-       BC_ListBoxItem *item = get_selection(0, 0);
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-
-       if(item)
-       {
-               char *current_suggestion = item->get_text();
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-//             int text_box_len = strlen(text_box->text);
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-               strcpy(text_box->text + text_box->suggestion_column, current_suggestion);
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-               *(text_box->text + text_box->suggestion_column + strlen(current_suggestion)) = 0;
-
-//printf("BC_TextBoxSuggestions::selection_changed %d\n", __LINE__);
-               text_box->draw(1);
-               text_box->handle_event();
-       }
-
-       return 1;
-#else
-       return 0;
-#endif
-}
-
-
 int BC_TextBoxSuggestions::handle_event()
 {
        char *current_suggestion = 0;
@@ -2262,8 +2106,8 @@ int BC_TextBoxSuggestions::handle_event()
 
 
 //printf("BC_TextBoxSuggestions::handle_event %d\n", __LINE__);
-       text_box->highlight_letter1 = 
-               text_box->highlight_letter2 = 
+       text_box->highlight_letter1 =
+               text_box->highlight_letter2 =
                text_box->ibeam_letter = text_box->tstrlen();
        text_box->wtext_update();
        text_box->draw(1);
@@ -2319,49 +2163,21 @@ void BC_ScrollTextBox::create_objects()
        parent_window->add_subwindow(yscroll = new BC_ScrollTextBoxYScroll(this));
        text->yscroll = yscroll;
        yscroll->bound_to = text;
-
-}
-
-int BC_ScrollTextBox::handle_event()
-{
-       return 1;
-}
-
-int BC_ScrollTextBox::get_x()
-{
-       return x;
-}
-
-int BC_ScrollTextBox::get_y()
-{
-       return y;
-}
-
-int BC_ScrollTextBox::get_w()
-{
-       return w;
-}
-
-int BC_ScrollTextBox::get_h()
-{
-       return this->text->get_h();
+       set_text_row(0);
 }
 
-int BC_ScrollTextBox::get_rows()
-{
-       return rows;
-}
-
-
-const char* BC_ScrollTextBox::get_text()
-{
-       return text->get_text();
-}
+int BC_ScrollTextBox::handle_event() { return 1; }
+int BC_ScrollTextBox::button_press_event() { return text->BC_TextBox::button_press_event(); }
+int BC_ScrollTextBox::button_release_event() { return text->BC_TextBox::button_release_event(); }
+int BC_ScrollTextBox::get_buttonpress() { return text->BC_TextBox::get_buttonpress(); };
+int BC_ScrollTextBox::get_x() { return x; }
+int BC_ScrollTextBox::get_y() { return y; }
+int BC_ScrollTextBox::get_w() { return w; }
+int BC_ScrollTextBox::get_h() { return text->get_h(); }
+int BC_ScrollTextBox::get_rows() { return rows; }
 
-const wchar_t* BC_ScrollTextBox::get_wtext()
-{
-       return text->get_wtext();
-}
+const char* BC_ScrollTextBox::get_text() { return text->get_text(); }
+const wchar_t* BC_ScrollTextBox::get_wtext() { return text->get_wtext(); }
 
 void BC_ScrollTextBox::set_text(char *text, int isz)
 {
@@ -2428,6 +2244,11 @@ void BC_ScrollTextBox::wset_selection(int char1, int char2, int ibeam)
        this->text->wset_selection(char1, char2, ibeam);
 }
 
+int BC_ScrollTextBox::get_ibeam_letter()
+{
+       return this->text->get_ibeam_letter();
+}
+
 
 
 
@@ -2477,7 +2298,6 @@ int BC_ScrollTextBoxText::motion_event()
        return 1;
 }
 
-
 BC_ScrollTextBoxYScroll::BC_ScrollTextBoxYScroll(BC_ScrollTextBox *gui)
  : BC_ScrollBar(gui->x +
                        gui->w -
@@ -2680,22 +2500,14 @@ void BC_PopupTextBox::reposition_window(int x, int y)
 
 
 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
-       int64_t default_value,
-       int64_t min,
-       int64_t max,
-       int x,
-       int y)
+       int64_t default_value, int x, int y)
  : BC_TextBox(x, y, popup->text_w, 1, default_value)
 {
        this->popup = popup;
 }
 
 BC_TumbleTextBoxText::BC_TumbleTextBoxText(BC_TumbleTextBox *popup,
-       float default_value,
-       float min,
-       float max,
-       int x,
-       int y)
+       float default_value, int x, int y)
  : BC_TextBox(x, y, popup->text_w, 1, default_value)
 {
        this->popup = popup;
@@ -2851,20 +2663,12 @@ int BC_TumbleTextBox::create_objects()
        if(use_float)
        {
                parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
-                       default_value_f,
-                       min_f,
-                       max_f,
-                       x,
-                       y));
+                       default_value_f, x, y));
                textbox->set_precision(precision);
        }
        else
                parent_window->add_subwindow(textbox = new BC_TumbleTextBoxText(this,
-                       default_value,
-                       min,
-                       max,
-                       x,
-                       y));
+                       default_value, x, y));
 
        x += textbox->get_w();
 
@@ -2939,17 +2743,23 @@ int BC_TumbleTextBox::get_h()
        return textbox->get_h();
 }
 
-void BC_TumbleTextBox::disable()
+void BC_TumbleTextBox::disable(int hide_text)
 {
+       if( hide_text && !textbox->is_hidden() )
+               textbox->hide_window(0);
+       if( !tumbler->is_hidden() )
+               tumbler->hide_window(0);
        if( !get_enabled() ) return;
-       tumbler->hide_window(0);
        return textbox->disable();
 }
 
 void BC_TumbleTextBox::enable()
 {
+       if( textbox->is_hidden() )
+               textbox->show_window(0);
+       if( tumbler->is_hidden() )
+               tumbler->show_window(0);
        if( get_enabled() ) return;
-       tumbler->show_window(0);
        return textbox->enable();
 }