From b2cffc688ea7abbddabc9ed23deea1921f59ac9d Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Sun, 6 Dec 2009 22:21:55 +0000 Subject: Moved OS X code base to the more moder Cocoa toolkit thanks to the awesome work of Manolo Gouy (STR #2221). This is a big one! I tested all test applications under 32-bit autoconf and Xcode, and a few apps under 64bit intel. No PPC testing was done. Please verify this patch if you have the machine! git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6951 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Input.cxx | 606 +++++++++++++++++++++++++++---------------------------- 1 file changed, 303 insertions(+), 303 deletions(-) (limited to 'src/Fl_Input.cxx') diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index 67b5f2357..92d3e1d36 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -82,18 +82,18 @@ static const char *legal_fp_chars = ".eE+-"; #endif int Fl_Input::handle_key() { - + char ascii = Fl::event_text()[0]; - + int repeat_num=1; - + int del; if (Fl::compose(del)) { - + // Insert characters into numeric fields after checking for legality: if (input_type() == FL_FLOAT_INPUT || input_type() == FL_INT_INPUT) { Fl::compose_reset(); // ignore any foreign letters... - + // initialize the list of legal characters inside a floating point number #ifdef HAVE_LOCALECONV if (!legal_fp_chars) { @@ -108,7 +108,7 @@ int Fl_Input::handle_key() { // the following line is not a true memory leak because the array is only // allocated once if required, and automatically freed when the program quits char *chars = (char*)malloc(len+1); - legal_fp_chars = chars; + legal_fp_chars = chars; strcpy(chars, standard_fp_chars); if (lc) { if (lc->decimal_point) strcat(chars, lc->decimal_point); @@ -118,7 +118,7 @@ int Fl_Input::handle_key() { } } #endif // HAVE_LOCALECONV - + // find the insert position int ip = position()='A'&& ascii<='F' || ascii>='a'&& ascii<='f')) || input_type()==FL_FLOAT_INPUT && ascii && strchr(legal_fp_chars, ascii)) { - if (readonly()) fl_beep(); - else replace(position(), mark(), &ascii, 1); + if (readonly()) fl_beep(); + else replace(position(), mark(), &ascii, 1); } return 1; } - + if (del || Fl::event_length()) { if (readonly()) fl_beep(); else replace(position(), del ? position()-del : mark(), - Fl::event_text(), Fl::event_length()); + Fl::event_text(), Fl::event_length()); } return 1; } - + unsigned int mods = Fl::event_state() & (FL_META|FL_CTRL|FL_ALT); switch (Fl::event_key()) { - case FL_Insert: - if (Fl::event_state() & FL_CTRL) ascii = ctrl('C'); - else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V'); - break; - case FL_Delete: + case FL_Insert: + if (Fl::event_state() & FL_CTRL) ascii = ctrl('C'); + else if (Fl::event_state() & FL_SHIFT) ascii = ctrl('V'); + break; + case FL_Delete: #ifdef __APPLE__ - if (mods==0 || mods==FL_CTRL) { // delete next char - ascii = ctrl('D'); - } else if (mods==FL_ALT) { // delete next word - if (mark() != position()) return cut(); - cut(position(), word_end(position())); - return 1; - } else if (mods==FL_META) { // delete to the end of the line - if (mark() != position()) return cut(); - cut(position(), line_end(position())); - return 1; - } else return 1; + if (mods==0 || mods==FL_CTRL) { // delete next char + ascii = ctrl('D'); + } else if (mods==FL_ALT) { // delete next word + if (mark() != position()) return cut(); + cut(position(), word_end(position())); + return 1; + } else if (mods==FL_META) { // delete to the end of the line + if (mark() != position()) return cut(); + cut(position(), line_end(position())); + return 1; + } else return 1; #else - if (mods==0) { - ascii = ctrl('D'); - } else if (mods==FL_SHIFT) { - ascii = ctrl('X'); - } else return 1; + if (mods==0) { + ascii = ctrl('D'); + } else if (mods==FL_SHIFT) { + ascii = ctrl('X'); + } else return 1; #endif - break; - case FL_Left: + break; + case FL_Left: #ifdef __APPLE__ - if (mods==0) { // char left - ascii = ctrl('B'); - } else if (mods==FL_ALT) { // word left - shift_position(word_start(position())); - return 1; - } else if (mods==FL_CTRL || mods==FL_META) { // start of line - shift_position(line_start(position())); - return 1; - } else return 1; + if (mods==0) { // char left + ascii = ctrl('B'); + } else if (mods==FL_ALT) { // word left + shift_position(word_start(position())); + return 1; + } else if (mods==FL_CTRL || mods==FL_META) { // start of line + shift_position(line_start(position())); + return 1; + } else return 1; #else - if (mods==0) { // char left - ascii = ctrl('B'); - } else if (mods==FL_CTRL) { // word left - shift_position(word_start(position())); - return 1; - } else return 1; + if (mods==0) { // char left + ascii = ctrl('B'); + } else if (mods==FL_CTRL) { // word left + shift_position(word_start(position())); + return 1; + } else return 1; #endif - break; - case FL_Right: + break; + case FL_Right: #ifdef __APPLE__ - if (mods==0) { // char right - ascii = ctrl('F'); - } else if (mods==FL_ALT) { // word right - shift_position(word_end(position())); - return 1; - } else if (mods==FL_CTRL || mods==FL_META) { // end of line - shift_position(line_end(position())); - return 1; - } else return 1; + if (mods==0) { // char right + ascii = ctrl('F'); + } else if (mods==FL_ALT) { // word right + shift_position(word_end(position())); + return 1; + } else if (mods==FL_CTRL || mods==FL_META) { // end of line + shift_position(line_end(position())); + return 1; + } else return 1; #else - if (mods==0) { // char right - ascii = ctrl('F'); - } else if (mods==FL_CTRL) { // word right - shift_position(word_end(position())); - return 1; - } else return 1; + if (mods==0) { // char right + ascii = ctrl('F'); + } else if (mods==FL_CTRL) { // word right + shift_position(word_end(position())); + return 1; + } else return 1; #endif // __APPLE__ - break; - case FL_Page_Up: + break; + case FL_Page_Up: #ifdef __APPLE__ - if (mods==0) { // scroll text one page - // OS X scrolls the view, but does not move the cursor - // Fl_Input has no scroll control, so instead we move the cursor by one page - repeat_num = linesPerPage(); - ascii = ctrl('P'); - } else if (mods==FL_ALT) { // move cursor one page - repeat_num = linesPerPage(); - ascii = ctrl('P'); - } else return 1; - break; -#else + if (mods==0) { // scroll text one page + // OS X scrolls the view, but does not move the cursor + // Fl_Input has no scroll control, so instead we move the cursor by one page + repeat_num = linesPerPage(); + ascii = ctrl('P'); + } else if (mods==FL_ALT) { // move cursor one page repeat_num = linesPerPage(); - // fall through + ascii = ctrl('P'); + } else return 1; + break; +#else + repeat_num = linesPerPage(); + // fall through #endif - case FL_Up: + case FL_Up: #ifdef __APPLE__ - if (mods==0) { // line up - ascii = ctrl('P'); - } else if (mods==FL_CTRL) { // scroll text down one page - // OS X scrolls the view, but does not move the cursor - // Fl_Input has no scroll control, so instead we move the cursor by one page - repeat_num = linesPerPage(); - ascii = ctrl('P'); - } else if (mods==FL_ALT) { // line start and up - if (line_start(position())==position() && position()>0) - return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE; - else - return shift_position(line_start(position())) + NORMAL_INPUT_MOVE; - } else if (mods==FL_META) { // start of document - shift_position(0); - return 1; - } else return 1; + if (mods==0) { // line up + ascii = ctrl('P'); + } else if (mods==FL_CTRL) { // scroll text down one page + // OS X scrolls the view, but does not move the cursor + // Fl_Input has no scroll control, so instead we move the cursor by one page + repeat_num = linesPerPage(); + ascii = ctrl('P'); + } else if (mods==FL_ALT) { // line start and up + if (line_start(position())==position() && position()>0) + return shift_position(line_start(position()-1)) + NORMAL_INPUT_MOVE; + else + return shift_position(line_start(position())) + NORMAL_INPUT_MOVE; + } else if (mods==FL_META) { // start of document + shift_position(0); + return 1; + } else return 1; #else - if (mods==0) { // line up - ascii = ctrl('P'); - } else if (mods==FL_CTRL) { // scroll text down one line - // Fl_Input has no scroll control, so instead we move the cursor by one page - ascii = ctrl('P'); - } else return 1; + if (mods==0) { // line up + ascii = ctrl('P'); + } else if (mods==FL_CTRL) { // scroll text down one line + // Fl_Input has no scroll control, so instead we move the cursor by one page + ascii = ctrl('P'); + } else return 1; #endif - break; - case FL_Page_Down: + break; + case FL_Page_Down: #ifdef __APPLE__ - if (mods==0) { // scroll text one page - // OS X scrolls the view, but does not move the cursor - // Fl_Input has no scroll control, so instead we move the cursor by one page - repeat_num = linesPerPage(); - ascii = ctrl('N'); - } else if (mods==FL_ALT) { // move cursor one page - repeat_num = linesPerPage(); - ascii = ctrl('N'); - } else return 1; - break; -#else + if (mods==0) { // scroll text one page + // OS X scrolls the view, but does not move the cursor + // Fl_Input has no scroll control, so instead we move the cursor by one page + repeat_num = linesPerPage(); + ascii = ctrl('N'); + } else if (mods==FL_ALT) { // move cursor one page repeat_num = linesPerPage(); - // fall through + ascii = ctrl('N'); + } else return 1; + break; +#else + repeat_num = linesPerPage(); + // fall through #endif - case FL_Down: + case FL_Down: #ifdef __APPLE__ - if (mods==0) { // line down - ascii = ctrl('N'); - } else if (mods==FL_CTRL) { - // OS X scrolls the view, but does not move the cursor - // Fl_Input has no scroll control, so instead we move the cursor by one page - repeat_num = linesPerPage(); - ascii = ctrl('N'); - } else if (mods==FL_ALT) { // line end and down - if (line_end(position())==position() && position()=size()) return 0; - i = line_end(position()); - if (i == position() && i < size()) i++; - cut(position(), i); - return copy_cuts(); - case ctrl('N'): // go down one line - i = position(); - if (line_end(i) >= size()) return NORMAL_INPUT_MOVE; - while (repeat_num--) { - i = line_end(i); - if (i >= size()) break; - i++; - } - shift_up_down_position(i); + } + if (mark() != position()) return cut(); + else return cut(1); + case ctrl('E'): // go to the end of the line + return shift_position(line_end(position())) + NORMAL_INPUT_MOVE; + case ctrl('F'): // go to the next character + return shift_position(position()+1) + NORMAL_INPUT_MOVE; + case ctrl('H'): // cut the previous character + if (readonly()) { + fl_beep(); return 1; - case ctrl('P'): // go up one line - i = position(); - if (!line_start(i)) return NORMAL_INPUT_MOVE; - while(repeat_num--) { - i = line_start(i); - if (!i) break; - i--; - } - shift_up_down_position(line_start(i)); + } + if (mark() != position()) cut(); + else cut(-1); + return 1; + case ctrl('K'): // cut to the end of the line + if (readonly()) { + fl_beep(); return 1; - case ctrl('U'): // clear the whole document? - if (readonly()) { - fl_beep(); - return 1; - } - return cut(0, size()); - case ctrl('V'): // paste text - case ctrl('Y'): - if (readonly()) { - fl_beep(); - return 1; - } - Fl::paste(*this, 1); + } + if (position()>=size()) return 0; + i = line_end(position()); + if (i == position() && i < size()) i++; + cut(position(), i); + return copy_cuts(); + case ctrl('N'): // go down one line + i = position(); + if (line_end(i) >= size()) return NORMAL_INPUT_MOVE; + while (repeat_num--) { + i = line_end(i); + if (i >= size()) break; + i++; + } + shift_up_down_position(i); + return 1; + case ctrl('P'): // go up one line + i = position(); + if (!line_start(i)) return NORMAL_INPUT_MOVE; + while(repeat_num--) { + i = line_start(i); + if (!i) break; + i--; + } + shift_up_down_position(line_start(i)); + return 1; + case ctrl('U'): // clear the whole document? + if (readonly()) { + fl_beep(); return 1; - case ctrl('X'): // cut the selected text - case ctrl('W'): - if (readonly()) { - fl_beep(); - return 1; - } - copy(1); - return cut(); - case ctrl('Z'): // undo - case ctrl('_'): - if (readonly()) { - fl_beep(); - return 1; - } - return undo(); - case ctrl('I'): // insert literal - case ctrl('J'): - case ctrl('L'): - case ctrl('M'): - if (readonly()) { - fl_beep(); - return 1; - } - // insert a few selected control characters literally: - if (input_type() != FL_FLOAT_INPUT && input_type() != FL_INT_INPUT) - return replace(position(), mark(), &ascii, 1); + } + return cut(0, size()); + case ctrl('V'): // paste text + case ctrl('Y'): + if (readonly()) { + fl_beep(); + return 1; + } + Fl::paste(*this, 1); + return 1; + case ctrl('X'): // cut the selected text + case ctrl('W'): + if (readonly()) { + fl_beep(); + return 1; + } + copy(1); + return cut(); + case ctrl('Z'): // undo + case ctrl('_'): + if (readonly()) { + fl_beep(); + return 1; + } + return undo(); + case ctrl('I'): // insert literal + case ctrl('J'): + case ctrl('L'): + case ctrl('M'): + if (readonly()) { + fl_beep(); + return 1; + } + // insert a few selected control characters literally: + if (input_type() != FL_FLOAT_INPUT && input_type() != FL_INT_INPUT) + return replace(position(), mark(), &ascii, 1); } - + return 0; } -- cgit v1.2.3