diff options
author | culler <culler> | 2019-10-25 17:58:58 (GMT) |
---|---|---|
committer | culler <culler> | 2019-10-25 17:58:58 (GMT) |
commit | d4a398392db6a69b9a99d89a9aa8e10b5d423a65 (patch) | |
tree | e857a8584a2ec1571b0d6da9d05d1f932a0d8178 /macosx/tkMacOSXServices.c | |
parent | 87f5fe063fabe957d6b3b116952d83b7c575e794 (diff) | |
parent | c7c2b3b52832d1b78f18359507d3b971ec1506e2 (diff) | |
download | tk-d4a398392db6a69b9a99d89a9aa8e10b5d423a65.zip tk-d4a398392db6a69b9a99d89a9aa8e10b5d423a65.tar.gz tk-d4a398392db6a69b9a99d89a9aa8e10b5d423a65.tar.bz2 |
Aqua: fix IME behavior; make accent menus work; rework Services; deal with non-BMP pastes.
Diffstat (limited to 'macosx/tkMacOSXServices.c')
-rw-r--r-- | macosx/tkMacOSXServices.c | 131 |
1 files changed, 25 insertions, 106 deletions
diff --git a/macosx/tkMacOSXServices.c b/macosx/tkMacOSXServices.c index f1e5951..e92158f 100644 --- a/macosx/tkMacOSXServices.c +++ b/macosx/tkMacOSXServices.c @@ -4,20 +4,18 @@ * This file allows the integration of Tk and the Cocoa NSServices API. * * Copyright (c) 2010-2019 Kevin Walzer/WordTech Communications LLC. + * Copyright (c) 2019 Marc Culler. * Copyright (c) 2010 Adrian Robert. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#include <CoreServices/CoreServices.h> #include <tkInt.h> #include <tkMacOSXInt.h> -static Tcl_Interp *ServicesInterp; - /* - * Event proc which calls the PerformService procedure + * Event proc which calls the PerformService procedure. */ static int @@ -25,22 +23,28 @@ ServicesEventProc( Tcl_Event *event, int flags) { - Tcl_GlobalEval(ServicesInterp, "::tk::mac::PerformService"); + TkMainInfo *info = TkGetMainInfoList(); + Tcl_GlobalEval(info->interp, "::tk::mac::PerformService"); return 1; } /* - * Class declarations for TkService class. + * The Wish application can send the current selection in the Tk clipboard + * to other applications which accept messages of type NSString. The TkService + * object provides this service via its provideService method. (The method + * must be specified in the application's Info.plist file for this to work.) */ -@interface TkService : NSView { +@interface TkService : NSObject { } + (void) initialize; -- (void)provideService:(NSPasteboard *)pboard userData:(NSString *)data error:(NSString **)error; -- (id)validRequestorForSendType:(NSString *)sendType returnType:(NSString *)returnType; -- (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard types:(NSArray *)types; +- (void) provideService:(NSPasteboard *)pboard + userData:(NSString *)data + error:(NSString **)error; +- (BOOL) writeSelectionToPasteboard:(NSPasteboard *)pboard + types:(NSArray *)types; @end @@ -57,32 +61,8 @@ ServicesEventProc( return; } - -- (id)validRequestorForSendType:(NSString *)sendType - returnType:(NSString *)returnType -{ - if ([sendType isEqualToString:@"NSStringPboardType"] || - [sendType isEqualToString:@"NSPasteboardTypeString"]) { - return self; - } - return [super validRequestorForSendType:sendType returnType:returnType]; -} - -/* - * Make sure the view accepts events. - */ - -- (BOOL)acceptsFirstResponder -{ - return YES; -} -- (BOOL)becomeFirstResponder -{ - return YES; -} - /* - * Get selected text, copy to pasteboard. + * Get the current Tk selection and copy it to the system pasteboard. */ - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard @@ -90,6 +70,7 @@ ServicesEventProc( { NSArray *typesDeclared = nil; NSString *pboardType = nil; + TkMainInfo *info = TkGetMainInfoList(); for (NSString *typeString in types) { if ([typeString isEqualToString:@"NSStringPboardType"] || @@ -102,9 +83,9 @@ ServicesEventProc( if (!typesDeclared) { return NO; } - Tcl_Eval(ServicesInterp, "selection get"); + Tcl_Eval(info->interp, "selection get"); - char *copystring = Tcl_GetString(Tcl_GetObjResult(ServicesInterp)); + char *copystring = Tcl_GetString(Tcl_GetObjResult(info->interp)); NSString *writestring = [NSString stringWithUTF8String:copystring]; [pboard declareTypes:typesDeclared owner:nil]; @@ -112,8 +93,8 @@ ServicesEventProc( } /* - * This is the method that actually calls the Tk service; this is the method - * that must be defined in info.plist. + * This is the method that actually calls the Tk service; it must be specified + * in Info.plist. */ - (void)provideService:(NSPasteboard *)pboard @@ -125,8 +106,8 @@ ServicesEventProc( Tcl_Event *event; /* - * Get string from private pasteboard, write to general pasteboard to make - * available to Tcl service. + * Get a string from the private pasteboard and copy it to the general + * pasteboard to make it available to other applications. */ for (NSString *typeString in types) { @@ -150,69 +131,9 @@ ServicesEventProc( @end /* - * Register a specific widget to access the Services menu. - */ - -int -TkMacOSXRegisterServiceWidgetObjCmd( - ClientData cd, - Tcl_Interp *interp, - int objc, - Tcl_Obj *const objv[]) -{ - /* - * Need proper number of args. - */ - - if (objc != 2) { - Tcl_WrongNumArgs(interp, 1, objv, "path?"); - return TCL_ERROR; - } - /* - * Get the object that holds this Tk Window... - */ - - Rect bounds; - NSRect frame; - Tk_Window path = Tk_NameToWindow(interp, - Tcl_GetString(objv[1]), Tk_MainWindow(interp)); - - if (path == NULL) { - return TCL_ERROR; - } - - Tk_MakeWindowExist(path); - Tk_MapWindow(path); - Drawable d = Tk_WindowId(path); - - /* - * Get NSView from Tk window and add subview. - */ - - TkService *serviceview = [[TkService alloc] init]; - NSView *view = TkMacOSXGetRootControl(d); - - if ([serviceview superview] != view) { - [view addSubview:serviceview]; - } - TkMacOSXWinBounds((TkWindow*)path, &bounds); - - /* - * Hack to make sure subview is set to take up entire geometry of window. - */ - - frame = NSMakeRect(bounds.left, bounds.top, 100000, 100000); - frame.origin.y = 0; - if (!NSEqualRects(frame, [serviceview frame])) { - [serviceview setFrame:frame]; - } - [serviceview release]; - return TCL_OK; -} - -/* - * Initalize the package in the Tcl interpreter, create Tcl commands. + * Instantiate a TkService object and register it with the NSApplication. + * This is called exactly one time from TkpInit. */ int @@ -220,12 +141,10 @@ TkMacOSXServices_Init( Tcl_Interp *interp) { /* - * Initialize instance of TclServices to provide service functionality. + * Initialize an instance of TkService and register it with the NSApp. */ TkService *service = [[TkService alloc] init]; - - ServicesInterp = interp; [NSApp setServicesProvider:service]; return TCL_OK; } |