From 46abc078b451f07a2105a8d3338e70bac37bd0ec Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Mon, 17 Dec 2012 17:44:15 +0000 Subject: [PATCH] Mac OS: improved text input support with visible display of marked text in text widgets. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9761 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/mac.H | 1 + src/Fl_Text_Display.cxx | 2 +- src/Fl_cocoa.mm | 45 ++++++++++++++++++++--------------------- src/Fl_compose.cxx | 6 +++++- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/FL/mac.H b/FL/mac.H index bb0621681..9365f5007 100644 --- a/FL/mac.H +++ b/FL/mac.H @@ -131,6 +131,7 @@ public: static CGContextRef none_cursor_image(void); static void *get_carbon_function(const char *name); static void screen_work_area(int &X, int &Y, int &W, int &H, int n); // compute work area of a given screen + static void compose_state(int); private: static void relink(Fl_Window*, Fl_Window*); bool subwindow; diff --git a/src/Fl_Text_Display.cxx b/src/Fl_Text_Display.cxx index 03be48e60..5f261c5b0 100644 --- a/src/Fl_Text_Display.cxx +++ b/src/Fl_Text_Display.cxx @@ -1943,7 +1943,7 @@ void Fl_Text_Display::draw_string(int style, if (Fl::focus() == (Fl_Widget*)this) background = selection_color(); else background = fl_color_average(color(), selection_color(), 0.4f); } else if (style & HIGHLIGHT_MASK) { - if (Fl::focus() == (Fl_Widget*)this) background = fl_color_average(color(), selection_color(), 0.5f); + if (Fl::focus() == (Fl_Widget*)this) background = fl_color_average(color(), selection_color(), Fl::compose_state ? 0.3f : 0.5f); else background = fl_color_average(color(), selection_color(), 0.6f); } else background = color(); foreground = fl_contrast(styleRec->color, background); diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 02119ddcb..6525a89e2 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -44,6 +44,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -1674,7 +1675,6 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi - (BOOL)performDragOperation:(id )sender; - (void)draggingExited:(id < NSDraggingInfo >)sender; - (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal; -- (void)FLselectMarkedText; @end @implementation FLView @@ -1937,8 +1937,7 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi // Transform character palette actions to FL_PASTE events. Fl_Window *target = [(FLWindow*)[self window] getFl_Window]; Fl::handle( (in_key_event || Fl::compose_state) ? FL_KEYBOARD : FL_PASTE, target); - Fl::compose_state = 0; - [self FLselectMarkedText]; + Fl_X::compose_state(0); // for some reason, with the palette, the window does not redraw until the next mouse move or button push // sending a 'redraw()' or 'awake()' does not solve the issue! @@ -1961,32 +1960,14 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi received, newSelection.location, newSelection.length, Fl::compose_state, Fl::e_length);*/ Fl_Window *target = [(FLWindow*)[self window] getFl_Window]; Fl::handle(FL_KEYBOARD, target); - Fl::compose_state = Fl::e_length; - [self FLselectMarkedText]; + Fl_X::compose_state(Fl::e_length); fl_unlock_function(); } -- (void)FLselectMarkedText -{ // set/clear marked text as selected in text widgets - Fl_Widget *widget = Fl::focus(); - if (!widget) return; - if (dynamic_cast(widget) != NULL) { - Fl_Input_* input = (Fl_Input_*)widget; - input->mark( input->position() - Fl::compose_state ); - } - else if (dynamic_cast(widget) != NULL) { - Fl_Text_Display* input = (Fl_Text_Display*)widget; - Fl_Text_Selection* sel = (Fl_Text_Selection*)input->buffer()->highlight_selection(); - int pos = input->insert_position(); - sel->set(pos - Fl::compose_state, pos); - } -} - - (void)unmarkText { fl_lock_function(); - Fl::compose_state = 0; - [self FLselectMarkedText]; + Fl_X::compose_state(0); fl_unlock_function(); //NSLog(@"unmarkText"); } @@ -2052,6 +2033,24 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi @end +void Fl_X::compose_state(int new_val) +{ // highlight marked text in text widgets + if (Fl::compose_state == 0 && new_val == 0) return; + Fl::compose_state = new_val; + Fl_Widget *widget = Fl::focus(); + if (!widget) return; + if (dynamic_cast(widget) != NULL) { + if (dynamic_cast(widget) != NULL) return; + Fl_Input_* input = (Fl_Input_*)widget; + input->mark( input->position() - Fl::compose_state ); + } + else if (dynamic_cast(widget) != NULL) { + Fl_Text_Display* input = (Fl_Text_Display*)widget; + int pos = input->insert_position(); + input->buffer()->highlight(pos - Fl::compose_state, pos); + } +} + void Fl_Window::fullscreen_x() { _set_fullscreen(); /* On OS X < 10.6, it is necessary to recreate the window. This is done diff --git a/src/Fl_compose.cxx b/src/Fl_compose.cxx index 9bda479c4..870d2dc78 100644 --- a/src/Fl_compose.cxx +++ b/src/Fl_compose.cxx @@ -84,10 +84,14 @@ int Fl::compose(int& del) { */ void Fl::compose_reset() { +#ifdef __APPLE__ + Fl_X::compose_state(0); +#else Fl::compose_state = 0; -#if !defined(WIN32) && !defined(__APPLE__) +#if !defined(WIN32) if (fl_xim_ic) XmbResetIC(fl_xim_ic); #endif +#endif } //