mirror of
https://github.com/fltk/fltk.git
synced 2026-05-09 21:06:51 +08:00
macOS: remove text-related code present only to support macOS versions older than 10.7.
This commit is contained in:
+2
-97
@@ -554,10 +554,9 @@ void Fl_Cocoa_Screen_Driver::breakMacEventLoop()
|
||||
@end
|
||||
|
||||
|
||||
@interface FLView : NSView <NSTextInput, NSTextInputClient, NSDraggingSource> {
|
||||
@interface FLView : NSView <NSTextInputClient, NSDraggingSource> {
|
||||
BOOL in_key_event; // YES means keypress is being processed by handleEvent
|
||||
BOOL need_handle; // YES means Fl::handle(FL_KEYBOARD,) is needed after handleEvent processing
|
||||
NSInteger identifier;
|
||||
NSRange selectedRange;
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_14
|
||||
@public
|
||||
@@ -1143,40 +1142,6 @@ static void cocoaMouseHandler(NSEvent *theEvent)
|
||||
}
|
||||
|
||||
|
||||
@interface FLTextView : NSTextView // this subclass is only needed under OS X < 10.6
|
||||
{
|
||||
BOOL isActive;
|
||||
}
|
||||
+ (void)initialize;
|
||||
+ (FLTextView*)singleInstance;
|
||||
- (void)insertText:(id)aString;
|
||||
- (void)doCommandBySelector:(SEL)aSelector;
|
||||
- (void)setActive:(BOOL)a;
|
||||
@end
|
||||
static FLTextView *fltextview_instance = nil;
|
||||
@implementation FLTextView
|
||||
+ (void)initialize {
|
||||
NSRect rect={{0,0},{20,20}};
|
||||
fltextview_instance = [[FLTextView alloc] initWithFrame:rect];
|
||||
}
|
||||
+ (FLTextView*)singleInstance {
|
||||
return fltextview_instance;
|
||||
}
|
||||
- (void)insertText:(id)aString
|
||||
{
|
||||
if (isActive) [[[NSApp keyWindow] contentView] insertText:aString];
|
||||
}
|
||||
- (void)doCommandBySelector:(SEL)aSelector
|
||||
{
|
||||
[[[NSApp keyWindow] contentView] doCommandBySelector:aSelector];
|
||||
}
|
||||
- (void)setActive:(BOOL)a
|
||||
{
|
||||
isActive = a;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@interface FLWindowDelegate : NSObject <NSWindowDelegate>
|
||||
+ (void)initialize;
|
||||
+ (FLWindowDelegate*)singleInstance;
|
||||
@@ -2130,9 +2095,7 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi
|
||||
/** How FLTK handles Mac OS text input
|
||||
|
||||
Let myview be the instance of the FLView class that has the keyboard focus. FLView is an FLTK-defined NSView subclass
|
||||
that implements the NSTextInputClient protocol to properly handle text input. It also implements the old NSTextInput
|
||||
protocol to run with OS <= 10.4. The few NSTextInput protocol methods that differ in signature from the NSTextInputClient
|
||||
protocol transmit the received message to the corresponding NSTextInputClient method.
|
||||
that implements the NSTextInputClient protocol to properly handle text input.
|
||||
|
||||
Keyboard input sends keyDown: and performKeyEquivalent: messages to myview. The latter occurs for keys such as
|
||||
ForwardDelete, arrows and F1, and when the Ctrl or Cmd modifiers are used. Other key presses send keyDown: messages.
|
||||
@@ -2171,23 +2134,6 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi
|
||||
selectedRange = NSMakeRange(100, 0); to indicate no text is selected. The setMarkedText: method does
|
||||
selectedRange = NSMakeRange(100, newSelection.length); to indicate that this length of text is selected.
|
||||
|
||||
With OS <= 10.5, the NSView class does not implement the inputContext message. [myview process_keydown:theEvent] is
|
||||
equivalent to [[FLTextInputContext singleInstance] handleEvent:theEvent].
|
||||
Method +[FLTextInputContext singleInstance] returns an instance of class FLTextInputContext that possesses
|
||||
a handleEvent: method. The class FLTextView implements the so-called view's "field editor". This editor is an instance
|
||||
of the FLTextView class allocated by the -(id)[FLWindowDelegate windowWillReturnFieldEditor: toObject:] method.
|
||||
The -(BOOL)[FLTextInputContext handleEvent:] method emulates the missing 10.6 -(BOOL)[NSTextInputContext handleEvent:]
|
||||
by sending the interpretKeyEvents: message to the FLTextView object. The system sends back doCommandBySelector: and
|
||||
insertText: messages to the FLTextView object that are transmitted unchanged to myview to be processed as with OS >= 10.6.
|
||||
The system also sends setMarkedText: messages directly to myview.
|
||||
|
||||
There is furthermore an oddity of dead key processing with OS <= 10.5. It occurs when a dead key followed by a non-accented
|
||||
key are pressed. Say, for example, that keys '^' followed by 'p' are pressed on a French or German keyboard. Resulting
|
||||
messages are: [myview setMarkedText:@"^"], [myview insertText:@"^"], [myview insertText:@"p"], [FLTextView insertText:@"^p"].
|
||||
The 2nd '^' replaces the marked 1st one, followed by p^p. The resulting text in the widget is "^p^p" instead of the
|
||||
desired "^p". To avoid that, the FLTextView object is deactivated by the insertText: message and reactivated after
|
||||
the handleEvent: message has been processed.
|
||||
|
||||
NSEvent's during a character composition sequence:
|
||||
- keyDown with deadkey -> [[theEvent characters] length] is 0
|
||||
- keyUp -> [theEvent characters] contains the deadkey
|
||||
@@ -2229,27 +2175,6 @@ static void cocoaKeyboardHandler(NSEvent *theEvent)
|
||||
Fl::e_text = (char*)"";
|
||||
}
|
||||
|
||||
@interface FLTextInputContext : NSObject // "emulates" NSTextInputContext before OS 10.6
|
||||
+ (void)initialize;
|
||||
+ (FLTextInputContext*)singleInstance;
|
||||
-(BOOL)handleEvent:(NSEvent*)theEvent;
|
||||
@end
|
||||
static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
@implementation FLTextInputContext
|
||||
+ (void)initialize {
|
||||
fltextinputcontext_instance = [[FLTextInputContext alloc] init];
|
||||
}
|
||||
+ (FLTextInputContext*)singleInstance {
|
||||
return fltextinputcontext_instance;
|
||||
}
|
||||
-(BOOL)handleEvent:(NSEvent*)theEvent {
|
||||
FLTextView *edit = [FLTextView singleInstance];
|
||||
[edit setActive:YES];
|
||||
[edit interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
|
||||
[edit setActive:YES];
|
||||
return YES;
|
||||
}
|
||||
@end
|
||||
|
||||
/* Implementation note for the support of layer-backed views.
|
||||
MacOS 10.14 Mojave changes the way all drawing to displays is performed:
|
||||
@@ -2330,11 +2255,9 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
}
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
static NSInteger counter = 0;
|
||||
self = [super initWithFrame:frameRect];
|
||||
if (self) {
|
||||
in_key_event = NO;
|
||||
identifier = ++counter;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -2744,10 +2667,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
Fl::handle(FL_KEYBOARD, target);
|
||||
}
|
||||
|
||||
- (void)insertText:(id)aString {
|
||||
[self insertText:aString replacementRange:NSMakeRange(NSNotFound, 0)];
|
||||
}
|
||||
|
||||
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange {
|
||||
NSString *received;
|
||||
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
||||
@@ -2798,10 +2717,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
fl_unlock_function();
|
||||
}
|
||||
|
||||
- (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection {
|
||||
[self setMarkedText:aString selectedRange:newSelection replacementRange:NSMakeRange(NSNotFound, 0)];
|
||||
}
|
||||
|
||||
- (void)setMarkedText:(id)aString selectedRange:(NSRange)newSelection replacementRange:(NSRange)replacementRange {
|
||||
NSString *received;
|
||||
if ([aString isKindOfClass:[NSAttributedString class]]) {
|
||||
@@ -2858,9 +2773,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
return (Fl::compose_state > 0);
|
||||
}
|
||||
|
||||
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange {
|
||||
return [self attributedSubstringForProposedRange:aRange actualRange:NULL];
|
||||
}
|
||||
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange {
|
||||
//NSLog(@"attributedSubstringFromRange: %d %d",aRange.location,aRange.length);
|
||||
return nil;
|
||||
@@ -2870,9 +2782,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSRect)firstRectForCharacterRange:(NSRange)aRange {
|
||||
return [self firstRectForCharacterRange:aRange actualRange:NULL];
|
||||
}
|
||||
- (NSRect)firstRectForCharacterRange:(NSRange)aRange actualRange:(NSRangePointer)actualRange {
|
||||
//NSLog(@"firstRectForCharacterRange %d %d actualRange=%p",aRange.location, aRange.length,actualRange);
|
||||
NSRect glyphRect;
|
||||
@@ -2925,10 +2834,6 @@ static FLTextInputContext* fltextinputcontext_instance = nil;
|
||||
return [[self window] level];
|
||||
}
|
||||
|
||||
- (NSInteger)conversationIdentifier {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
- (NSDragOperation)draggingSession:(NSDraggingSession *)session sourceOperationMaskForDraggingContext:(NSDraggingContext)context
|
||||
{
|
||||
return NSDragOperationCopy;
|
||||
|
||||
Reference in New Issue
Block a user