Author: manolo
Date: 2012-12-16 08:32:19 -0800 (Sun, 16 Dec 2012)
New Revision: 9760
Log:
Mac OS: completed text input support with visible display of marked text in
text widgets.
Modified:
branches/branch-3.0/src/fltk3/TextEditor.cxx
branches/branch-3.0/src/fltk3/cocoa.mm
branches/branch-3.0/src/fltk3/compose.cxx
Modified: branches/branch-3.0/src/fltk3/TextEditor.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/TextEditor.cxx 2012-12-16 16:04:02 UTC
(rev 9759)
+++ branches/branch-3.0/src/fltk3/TextEditor.cxx 2012-12-16 16:32:19 UTC
(rev 9760)
@@ -526,8 +526,9 @@
int del = 0;
if (fltk3::compose(del)) {
if (del) {
- int dp = insert_position(), di = del;
- while (di--) dp = buffer()->prev_char_clipped(dp);
+ // del is a number of bytes
+ int dp = insert_position() - del;
+ if ( dp < 0 ) dp = 0;
buffer()->select(dp, insert_position());
}
kill_selection(this);
Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm 2012-12-16 16:04:02 UTC (rev
9759)
+++ branches/branch-3.0/src/fltk3/cocoa.mm 2012-12-16 16:32:19 UTC (rev
9760)
@@ -1653,6 +1653,7 @@
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
- (void)draggingExited:(id < NSDraggingInfo >)sender;
- (NSDragOperation)draggingSourceOperationMaskForLocal:(BOOL)isLocal;
+- (void)FLselectMarkedText;
@end
@implementation FLView
@@ -1916,6 +1917,8 @@
fltk3::Window *target = [(FLWindow*)[self window] getFl_Window];
fltk3::handle( (in_key_event || fltk3::compose_state) ? fltk3::KEYBOARD :
fltk3::PASTE, target);
fltk3::compose_state = 0;
+ [self FLselectMarkedText];
+
// 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!
fltk3::flush();
@@ -1933,17 +1936,35 @@
// This code creates the OS X behaviour of seeing dead keys as things
// are being composed.
[FLView prepareEtext:received];
- /*NSLog(@"setMarkedText:%@ %d %d fltk3::e_length=%d fltk3::compose_state=%d
[received length]=%d",
- received, newSelection.location, newSelection.length, fltk3::e_length,
fltk3::compose_state, [received length]);*/
+ /*NSLog(@"setMarkedText:%@ %d %d fltk3::compose_state=%d
fltk3::e_length=%d",
+ received, newSelection.location, newSelection.length, fltk3::compose_state,
fltk3::e_length);*/
fltk3::Window *target = [(FLWindow*)[self window] getFl_Window];
fltk3::handle(fltk3::KEYBOARD, target);
- fltk3::compose_state = [received length];
+ fltk3::compose_state = fltk3::e_length;
+ [self FLselectMarkedText];
fl_unlock_function();
}
+- (void)FLselectMarkedText
+{ // set/clear marked text as selected in text widgets
+ fltk3::Widget *widget = fltk3::focus();
+ if (!widget) return;
+ if (dynamic_cast<fltk3::Input_*>(widget) != NULL) {
+ fltk3::Input_* input = (fltk3::Input_*)widget;
+ input->mark( input->position() - fltk3::compose_state );
+ }
+ else if (dynamic_cast<fltk3::TextDisplay*>(widget) != NULL) {
+ fltk3::TextDisplay* input = (fltk3::TextDisplay*)widget;
+ fltk3::TextSelection* sel =
(fltk3::TextSelection*)input->buffer()->highlight_selection();
+ int pos = input->insert_position();
+ sel->set(pos - fltk3::compose_state, pos);
+ }
+}
+
- (void)unmarkText {
fl_lock_function();
fltk3::compose_state = 0;
+ [self FLselectMarkedText];
fl_unlock_function();
//NSLog(@"unmarkText");
}
Modified: branches/branch-3.0/src/fltk3/compose.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/compose.cxx 2012-12-16 16:04:02 UTC (rev
9759)
+++ branches/branch-3.0/src/fltk3/compose.cxx 2012-12-16 16:32:19 UTC (rev
9760)
@@ -59,8 +59,10 @@
del = 0;
#if defined(__APPLE__)
int has_text_key = fltk3::compose_state || fltk3::e_keysym <= '~' ||
fltk3::e_keysym == fltk3::IsoKey ||
- (fltk3::e_keysym >= fltk3::KPKey && fltk3::e_keysym <= fltk3::KPLastKey &&
fltk3::e_keysym != fltk3::KPEnterKey);
- if ( fltk3::e_state&(fltk3::META | fltk3::CTRL) || !has_text_key ) {
+ (fltk3::e_keysym >= fltk3::KPKey && fltk3::e_keysym <= fltk3::KPLastKey &&
fltk3::e_keysym != fltk3::KPEnterKey);
+ if ( fltk3::e_state&(fltk3::META | fltk3::CTRL) ||
+ (fltk3::e_keysym >= fltk3::ShiftLKey && fltk3::e_keysym <=
fltk3::AltRKey) || // called from flagsChanged
+ !has_text_key ) {
// this stuff is to be treated as a function key
return 0;
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit