Tk Source Code

Check-in [a7e34ff9]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Code and data type cleanup, thanks to Marc Culler for patch
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | mac_services
Files: files | file ages | folders
SHA3-256: a7e34ff9cec93f6354d6de80aa0c9d674a2c2d3ffb12fbf4920a605801239a9a
User & Date: kevin_walzer 2019-05-17 03:13:34
Context
2019-05-18
13:05
Finally got timing of initializing NSServices object correct; code cleanup; merge in 8.6 to pick up changes in Tk initialization code check-in: f126b00e user: kevin_walzer tags: mac_services
2019-05-17
03:13
Code and data type cleanup, thanks to Marc Culler for patch check-in: a7e34ff9 user: kevin_walzer tags: mac_services
2019-05-12
02:03
Restore deprecated call to NSPasteboardTypeString in writeSelectiontoPasteboard because it breaks sending data to the services menu. Data type must be identical in this call and in the NSSendTypes key in info.plist; we cannot do a clever mapping here of the old type to a new one because the info.plist does not have this kind of conditional reading on different versions of macOS. We will have to live with the deprecated call until it is obsolete/removed altogether by Apple. check-in: 42577ce4 user: kevin_walzer tags: mac_services
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to macosx/Wish-Info.plist.in.

   102    102               <key>NSMessage</key>
   103    103               <string>provideService</string>
   104    104               <key>NSPortName</key>
   105    105               <string>Wish</string>
   106    106   
   107    107               <key>NSSendTypes</key>
   108    108               <array>
          109  +                <string>NSStringPboardType</string>
   109    110                   <string>NSPasteboardTypeString</string>
   110    111               </array>
   111    112           </dict>
   112    113       </array>
   113    114   
   114    115   </dict>
   115    116   </plist>

Changes to macosx/tkMacOSXInit.c.

   112    112        */
   113    113       TkMacOSXUseAntialiasedText(_eventInterp, -1);
   114    114       TkMacOSXInitCGDrawing(_eventInterp, TRUE, 0);
   115    115   }
   116    116   
   117    117   -(void)applicationDidFinishLaunching:(NSNotification *)notification
   118    118   {
          119  +
   119    120       /*
   120    121        * It is not safe to force activation of the NSApp until this method is
   121    122        * called. Activating too early can cause the menu bar to be unresponsive.
   122    123        */
   123    124   
   124    125       [NSApp activateIgnoringOtherApps: YES];
   125    126   
................................................................................
   127    128        * Process events to ensure that the root window is fully initialized. See
   128    129        * ticket 56a1823c73.
   129    130        */
   130    131   
   131    132       [NSApp _lockAutoreleasePool];
   132    133       while (Tcl_DoOneEvent(TCL_WINDOW_EVENTS| TCL_DONT_WAIT)) {}
   133    134       [NSApp _unlockAutoreleasePool];
   134         -
   135         -    Tk_MacOSXServices_Init(_eventInterp);
          135  +    
          136  +    TkMacOSXServices_Init(_eventInterp);
   136    137   }
   137    138   
   138    139   - (void) _setup: (Tcl_Interp *) interp
   139    140   {
   140    141       /*
   141    142        * Remember our interpreter.
   142    143        */
................................................................................
   445    446     /* Convert the URL reference into a string reference. */
   446    447     CFStringRef appPath = CFURLCopyFileSystemPath(mainBundleURL, kCFURLPOSIXPathStyle);
   447    448    
   448    449     /* Get the system encoding method. */
   449    450     CFStringEncoding encodingMethod = CFStringGetSystemEncoding();
   450    451    
   451    452     /* Convert the string reference into a C string. */
   452         -  char *path = CFStringGetCStringPtr(appPath, encodingMethod);
          453  +  char *path = (char *) CFStringGetCStringPtr(appPath, encodingMethod);
   453    454   
   454    455     Tcl_SetResult(ip, path, NULL);
   455    456   
   456    457     CFRelease(mainBundleURL);
   457    458     CFRelease(appPath);
   458    459     return TCL_OK;
   459    460   

Changes to macosx/tkMacOSXPrivate.h.

   229    229   			    NSWindow *macWindow);
   230    230   MODULE_SCOPE int	TkMacOSXStandardAboutPanelObjCmd(ClientData clientData,
   231    231   			    Tcl_Interp *interp, int objc,
   232    232   			    Tcl_Obj *const objv[]);
   233    233   MODULE_SCOPE int	TkMacOSXIconBitmapObjCmd(ClientData clientData,
   234    234   			    Tcl_Interp *interp, int objc,
   235    235   			    Tcl_Obj *const objv[]);
          236  +MODULE_SCOPE void       TkMacOSXDrawSolidBorder(Tk_Window tkwin, GC gc,
          237  +			    int inset, int thickness);
          238  +MODULE_SCOPE int 	TkMacOSXServices_Init(Tcl_Interp *interp);
   236    239   MODULE_SCOPE int	TkMacOSXRegisterServiceWidgetObjCmd(ClientData clientData,
   237    240   			    Tcl_Interp *interp, int objc,
   238    241   			    Tcl_Obj *const objv[]);
   239    242   
   240    243   #pragma mark Private Objective-C Classes
   241    244   
   242    245   #define VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
................................................................................
   333    336   - (void)handleURLEvent:                (NSAppleEventDescriptor*)event
   334    337   	           withReplyEvent:     (NSAppleEventDescriptor*)replyEvent;
   335    338   @end
   336    339   
   337    340   VISIBILITY_HIDDEN
   338    341   @interface TKContentView : NSView <NSTextInput>
   339    342   {
          343  +@private
   340    344       NSString *privateWorkingText;
   341         -    #ifdef __i386__
          345  +#ifdef __i386__
   342    346       /* The Objective C runtime used on i386 requires this. */
   343    347       Bool _needsRedisplay;
   344    348   #endif
   345    349   }
   346    350   @property Bool needsRedisplay;
   347    351   @end
   348    352   

Changes to macosx/tkMacOSXServices.c.

    46     46   /*
    47     47    * Class methods.
    48     48    */
    49     49   
    50     50   @implementation TkService
    51     51   
    52     52   + (void) initialize {
    53         -    NSArray *sendTypes = [NSArray arrayWithObjects:NSPasteboardTypeString, nil];
    54         -
    55         -    [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:nil];
           53  +    NSArray *sendTypes = [NSArray arrayWithObjects:@"NSStringPboardType",
           54  +				  @"NSPasteboardTypeString", nil];
           55  +    [NSApp registerServicesMenuSendTypes:sendTypes returnTypes:sendTypes];
    56     56       NSUpdateDynamicServices();
    57     57       return;
    58     58   }
    59     59   
    60     60   
    61     61   - (id)validRequestorForSendType:(NSString *)sendType
    62     62   		     returnType:(NSString *)returnType
    63     63   {
    64         -    if ([sendType isEqual:NSStringPboardType]) {
           64  +    if ([sendType isEqualToString:@"NSStringPboardType"] ||
           65  +	[sendType isEqualToString:@"NSPasteboardTypeString"]) {
    65     66   	return self;
    66     67       }
    67     68       return [super validRequestorForSendType:sendType returnType:returnType];
    68     69   }
    69     70   
    70     71   /*
    71     72    * Make sure the view accepts events.
................................................................................
    83     84   /*
    84     85    * Get selected text, copy to pasteboard.
    85     86    */
    86     87   
    87     88   - (BOOL)writeSelectionToPasteboard:(NSPasteboard *)pboard
    88     89   			     types:(NSArray *)types
    89     90   {
    90         -    NSArray *typesDeclared;
    91         -    if ([types containsObject:NSStringPboardType] == NO) {
           91  +    NSArray *typesDeclared = nil;
           92  +    NSString *pboardType = nil;
           93  +    for (NSString *typeString in types) {
           94  +	if ([typeString isEqualToString:@"NSStringPboardType"] ||
           95  +	    [typeString isEqualToString:@"NSPasteboardTypeString"]) {
           96  +	    typesDeclared = [NSArray arrayWithObject:typeString];
           97  +	    pboardType = typeString;
           98  +	    break;
           99  +	}
          100  +    }
          101  +    if (!typesDeclared) {
    92    102   	return NO;
    93    103       }
    94         -
    95    104       Tcl_Eval(ServicesInterp,"selection get");
    96    105       char *copystring;
    97    106       copystring = Tcl_GetString(Tcl_GetObjResult(ServicesInterp));
    98    107   
    99    108       NSString *writestring = [NSString stringWithUTF8String:copystring];
   100         -    typesDeclared = [NSArray arrayWithObject:NSStringPboardType];
   101    109       [pboard declareTypes:typesDeclared owner:nil];
   102         -    return [pboard setString:writestring forType:NSPasteboardTypeString];
          110  +    return [pboard setString:writestring forType:pboardType];
   103    111   }
   104    112   
   105    113   
   106    114   /*
   107    115    * This is the method that actually calls the Tk service; this is the method
   108    116    * that must be defined in info.plist.
   109    117    */
   110    118   
   111    119   - (void)provideService:(NSPasteboard *)pboard
   112    120   	      userData:(NSString *)data
   113    121   		 error:(NSString **)error
   114    122   {
   115         -    NSString *pboardString;
          123  +    NSString *pboardString, *pboardType;
   116    124       NSArray *types = [pboard types];
   117    125       Tcl_Event *event;
   118    126   
   119    127       /*
   120    128        * Get string from private pasteboard, write to general pasteboard to make
   121    129        * available to Tcl service.
   122    130        */
   123    131   
   124         -    if ([types containsObject:NSStringPboardType] &&
   125         -	(pboardString = [pboard stringForType:NSStringPboardType])) {
   126         -
          132  +    for (NSString *typeString in types) {
          133  +	if ([typeString isEqualToString:@"NSStringPboardType"] ||
          134  +	    [typeString isEqualToString:@"NSPasteboardTypeString"]) {
          135  +	    pboardString = [pboard stringForType:typeString];
          136  +	    pboardType = typeString;
          137  +	    break;
          138  +	}
          139  +    }
          140  +    if (pboardString) {
   127    141   	NSPasteboard *generalpasteboard = [NSPasteboard generalPasteboard];
   128         -	[generalpasteboard declareTypes:[NSArray
   129         -	     arrayWithObjects:NSStringPboardType, nil] owner:nil];
   130         -	[generalpasteboard setString:pboardString forType: NSPasteboardTypeString];
          142  +	[generalpasteboard declareTypes:[NSArray arrayWithObjects:pboardType, nil]
          143  +				  owner:nil];
          144  +	[generalpasteboard setString:pboardString forType:pboardType];
   131    145   	event = ckalloc(sizeof(Tcl_Event));
   132    146   	event->proc = ServicesEventProc;
   133    147   	Tcl_QueueEvent((Tcl_Event *)event, TCL_QUEUE_TAIL);
   134    148       }
   135    149   }
   136         -
   137    150   @end
   138    151   
   139    152   
   140    153   /*
   141    154    * Register a specific widget to access the Services menu.
   142    155    */
   143    156   
................................................................................
   201    214       return TCL_OK;
   202    215   }
   203    216   
   204    217   /*
   205    218    * Initalize the package in the tcl interpreter, create tcl commands.
   206    219    */
   207    220   
   208         -int Tk_MacOSXServices_Init(
          221  +int TkMacOSXServices_Init(
   209    222       Tcl_Interp *interp)
   210    223   {
   211    224       /*
   212    225        * Set up an autorelease pool.
   213    226        */
   214    227   
   215    228       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];