Carbon function TSMGetActiveDocument() and its friends are no longer documented on the Apple web site.

Don’t use them unless Fl::disable_im() is called.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10464 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy
2014-11-19 18:20:41 +00:00
parent f52b457cc2
commit d5d6b8ae19
+44 -48
View File
@@ -92,7 +92,6 @@ static void cocoaMouseHandler(NSEvent *theEvent);
static int calc_mac_os_version(); static int calc_mac_os_version();
static void clipboard_check(void); static void clipboard_check(void);
static NSString *calc_utf8_format(void); static NSString *calc_utf8_format(void);
static void im_update(void);
static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once static unsigned make_current_counts = 0; // if > 0, then Fl_Window::make_current() can be called only once
static Fl_X *fl_x_to_redraw = NULL; // set by Fl_X::flush() to the Fl_X object of the window to be redrawn static Fl_X *fl_x_to_redraw = NULL; // set by Fl_X::flush() to the Fl_X object of the window to be redrawn
static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h); static NSBitmapImageRep* rect_to_NSBitmapImageRep(Fl_Window *win, int x, int y, int w, int h);
@@ -1313,6 +1312,7 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
#endif #endif
{ {
void (*open_cb)(const char*); void (*open_cb)(const char*);
@public
TSMDocumentID currentDoc; TSMDocumentID currentDoc;
} }
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender; - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication*)sender;
@@ -1379,7 +1379,7 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
} }
- (void)applicationDidUpdate:(NSNotification *)aNotification - (void)applicationDidUpdate:(NSNotification *)aNotification
{ {
if ((im_enabled != -1) && (TSMGetActiveDocument != NULL)) { if (im_enabled != -1) {
TSMDocumentID newDoc; TSMDocumentID newDoc;
// It is extremely unclear when Cocoa decides to create/update // It is extremely unclear when Cocoa decides to create/update
// the input context, but debugging reveals that it is done // the input context, but debugging reveals that it is done
@@ -1388,8 +1388,21 @@ static FLWindowDelegate *flwindowdelegate_instance = nil;
// input methods status. // input methods status.
newDoc = TSMGetActiveDocument(); newDoc = TSMGetActiveDocument();
if (newDoc != currentDoc) { if (newDoc != currentDoc) {
im_update(); TSMDocumentID doc;
currentDoc = newDoc;
doc = TSMGetActiveDocument();
if (im_enabled)
TSMRemoveDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag);
else {
CFArrayRef inputSources;
inputSources = TISCreateASCIICapableInputSourceList();
TSMSetDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag,
sizeof(CFArrayRef), &inputSources);
CFRelease(inputSources);
}
currentDoc = newDoc;
} }
} }
} }
@@ -1549,13 +1562,6 @@ void fl_open_display() {
static char beenHereDoneThat = 0; static char beenHereDoneThat = 0;
if ( !beenHereDoneThat ) { if ( !beenHereDoneThat ) {
beenHereDoneThat = 1; beenHereDoneThat = 1;
TSMGetActiveDocument = (TSMGetActiveDocument_type)Fl_X::get_carbon_function("TSMGetActiveDocument");
TSMSetDocumentProperty = (TSMSetDocumentProperty_type)Fl_X::get_carbon_function("TSMSetDocumentProperty");
TSMRemoveDocumentProperty = (TSMRemoveDocumentProperty_type)Fl_X::get_carbon_function("TSMRemoveDocumentProperty");
TISCreateASCIICapableInputSourceList = (TISCreateASCIICapableInputSourceList_type)Fl_X::get_carbon_function("TISCreateASCIICapableInputSourceList");
KeyScript = (KeyScript_type)Fl_X::get_carbon_function("KeyScript");
BOOL need_new_nsapp = (NSApp == nil); BOOL need_new_nsapp = (NSApp == nil);
if (need_new_nsapp) [NSApplication sharedApplication]; if (need_new_nsapp) [NSApplication sharedApplication];
@@ -1636,59 +1642,49 @@ void fl_close_display() {
// (see nsTSMManager::SyncKeyScript in Mozilla and enableSecureTextInput // (see nsTSMManager::SyncKeyScript in Mozilla and enableSecureTextInput
// in Safari/Webcore). Should be good enough for us then... // in Safari/Webcore). Should be good enough for us then...
static void im_update(void) { static int input_method_startup()
if (fl_mac_os_version >= 100500) { {
TSMDocumentID doc; static int retval = -1; // -1: not initialized, 0: not usable, 1: ready for use
if (retval == -1) {
if ((TSMGetActiveDocument == NULL) || fl_open_display();
(TSMSetDocumentProperty == NULL) || if (fl_mac_os_version >= 100500) {
(TSMRemoveDocumentProperty == NULL) || TSMGetActiveDocument = (TSMGetActiveDocument_type)Fl_X::get_carbon_function("TSMGetActiveDocument");
(TISCreateASCIICapableInputSourceList == NULL)) TSMSetDocumentProperty = (TSMSetDocumentProperty_type)Fl_X::get_carbon_function("TSMSetDocumentProperty");
return; TSMRemoveDocumentProperty = (TSMRemoveDocumentProperty_type)Fl_X::get_carbon_function("TSMRemoveDocumentProperty");
TISCreateASCIICapableInputSourceList = (TISCreateASCIICapableInputSourceList_type)Fl_X::get_carbon_function("TISCreateASCIICapableInputSourceList");
doc = TSMGetActiveDocument(); retval = (TSMGetActiveDocument && TSMSetDocumentProperty && TSMRemoveDocumentProperty && TISCreateASCIICapableInputSourceList ? 1 : 0);
} else {
if (im_enabled) KeyScript = (KeyScript_type)Fl_X::get_carbon_function("KeyScript");
TSMRemoveDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag); retval = (KeyScript? 1 : 0);
else {
CFArrayRef inputSources;
inputSources = TISCreateASCIICapableInputSourceList();
TSMSetDocumentProperty(doc, kTSMDocumentEnabledInputSourcesPropertyTag,
sizeof(CFArrayRef), &inputSources);
CFRelease(inputSources);
} }
} else {
if (KeyScript == NULL)
return;
if (im_enabled)
KeyScript(smKeyEnableKybds);
else
KeyScript(smEnableRomanKybdsOnly);
} }
return retval;
} }
void Fl::enable_im() { void Fl::enable_im() {
fl_open_display(); if (!input_method_startup()) return;
im_enabled = 1; im_enabled = 1;
if (fl_mac_os_version >= 100500) if (fl_mac_os_version >= 100500) {
[NSApp updateWindows]; ((FLAppDelegate*)[NSApp delegate])->currentDoc = NULL;
[NSApp updateWindows]; // triggers [FLAppDelegate applicationDidUpdate]
}
else else
im_update(); KeyScript(smKeyEnableKybds);
} }
void Fl::disable_im() { void Fl::disable_im() {
fl_open_display(); if (!input_method_startup()) return;
im_enabled = 0; im_enabled = 0;
if (fl_mac_os_version >= 100500) if (fl_mac_os_version >= 100500) {
[NSApp updateWindows]; ((FLAppDelegate*)[NSApp delegate])->currentDoc = NULL;
[NSApp updateWindows]; // triggers [FLAppDelegate applicationDidUpdate]
}
else else
im_update(); KeyScript(smEnableRomanKybdsOnly);
} }