#include "bcsignals.h"
#include "bctextbox.h"
#include "clip.h"
-#include "colors.h"
+#include "bccolors.h"
#include <ctype.h>
#include "cursors.h"
#include "filesystem.h"
#include "keys.h"
+#include "language.h"
#include <math.h>
#include "bctimer.h"
#include "vframe.h"
delete suggestions_popup;
suggestions->remove_all_objects();
delete suggestions;
+ delete menu;
delete [] wtext;
if( size > 0 )
delete [] text;
text_x = 0;
enabled = 1;
highlighted = 0;
+ back_color = -1;
+ high_color = -1;
precision = 4;
if (!skip_cursor)
skip_cursor = new Timer;
separators = 0;
xscroll = 0;
yscroll = 0;
+ menu = 0;
dirty = 1;
selection_active = 0;
return 0;
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)
int BC_TextBox::initialize()
{
+
if (!skip_cursor)
skip_cursor = new Timer;
skip_cursor->update();
BC_Resources *resources = get_resources();
if(has_border)
{
- back_color = resources->text_background;
- high_color = resources->text_background_hi;
+ if( back_color < 0 ) back_color = resources->text_background;
+ if( high_color < 0 ) high_color = resources->text_background_hi;
}
else
{
- high_color = resources->text_background_noborder_hi;
- back_color = bg_color;
+ if( back_color < 0 ) back_color = bg_color;
+ if( high_color < 0 ) high_color = resources->text_background_noborder_hi;
}
draw(0);
set_cursor(IBEAM_CURSOR, 0, 0);
show_window(0);
+
+ add_subwindow(menu = new BC_TextMenu(this));
+ menu->create_objects();
+
return 0;
}
// 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);
{
//printf("BC_TextBox::update 1 %d %s %s\n", tstrcmp(text), text, this->text);
// Don't update if contents are the same
- if(!tstrcmp(text)) return 0;
+ int bg_color = has_border || !highlighted ? back_color : high_color;
+ if( bg_color == background_color && !tstrcmp(text)) return 0;
tstrcpy(text);
int wtext_len = wtext_update();
if(highlight_letter1 > wtext_len) highlight_letter1 = wtext_len;
int BC_TextBox::get_text_y() { return text_y; }
void BC_TextBox::set_text_x(int v) { text_x = v; }
void BC_TextBox::set_text_y(int v) { text_y = v; }
+int BC_TextBox::get_back_color() { return back_color; }
+void BC_TextBox::set_back_color(int v) { back_color = v; }
int BC_TextBox::pixels_to_rows(BC_WindowBase *window, int font, int pixels)
{
//printf("BC_TextBox::draw %d %s\n", __LINE__, text);
// Background
- if(has_border)
- background_color = resources->text_background;
- else if(highlighted)
- background_color = high_color;
- else
- background_color = back_color;
+ background_color = has_border || !highlighted ? back_color : high_color;
set_color(background_color);
draw_box(0, 0, w, h);
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__);
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);
void BC_TextBox::default_keypress(int &dispatch_event, int &result)
{
int key = top_level->get_keypress(), len;
- if( (key == RETURN) || ( key >= 32 && key <= 255 ) ) {
+ if( (key == RETURN) || ( key >= 32 && key <= 255 ) ||
+ (key >= KP1 && key <= KP9) || key == KPINS ) {
wchar_t *wkeys = top_level->get_wkeystring(&len);
- if( key == RETURN ) { wkeys[0] = '\n'; wkeys[1] = 0; len = 1; }
+ switch( key ) {
+ case RETURN: key = '\n'; goto kpchr;
+ case KPINS: key = '0'; goto kpchr;
+ case KP1: case KP2: case KP3: case KP4: case KP5:
+ case KP6: case KP7: case KP8: case KP9:
+ key = key - KP1 + '1';
+ kpchr:
+ wkeys[0] = key; wkeys[1] = 0; len = 1;
+ break;
+ }
insert_text(wkeys, len);
find_ibeam(1);
draw(1);
result = 1;
wlen = 0;
break; }
+ case KPINS: last_keypress = KP1-'1'+'0'; // fall thru
+ case KP1: case KP2: case KP3: case KP4: case KP5:
+ case KP6: case KP7: case KP8: case KP9:
+ last_keypress = last_keypress-KP1 + '1';
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':
default: {
if( ctrl_down() ) {
- switch( get_keypress() ) {
+ switch( last_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() ) {
}
+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;
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;
}
}
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);