tkMacOSXPrivate.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. * tkMacOSXPrivate.h --
  3. *
  4. * Macros and declarations that are purely internal & private to TkAqua.
  5. *
  6. * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net>
  7. * Copyright (c) 2008-2009 Apple Inc.
  8. * Copyright (c) 2020 Marc Culler
  9. *
  10. * See the file "license.terms" for information on usage and redistribution
  11. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. *
  13. * RCS: @(#) $Id$
  14. */
  15. #ifndef _TKMACPRIV
  16. #define _TKMACPRIV
  17. #if !__OBJC__
  18. #error Objective-C compiler required
  19. #endif
  20. #ifndef __clang__
  21. #define instancetype id
  22. #endif
  23. #define TextStyle MacTextStyle
  24. #import <ApplicationServices/ApplicationServices.h>
  25. #import <Cocoa/Cocoa.h>
  26. #import <QuartzCore/QuartzCore.h>
  27. #ifndef NO_CARBON_H
  28. #import <Carbon/Carbon.h>
  29. #endif
  30. #undef TextStyle
  31. #import <objc/runtime.h> /* for sel_isEqual() */
  32. #ifndef _TKMACINT
  33. #include "tkMacOSXInt.h"
  34. #endif
  35. #ifndef _TKMACDEFAULT
  36. #include "tkMacOSXDefault.h"
  37. #endif
  38. /* Macros for Mac OS X API availability checking */
  39. #define TK_IF_MAC_OS_X_API(vers, symbol, ...) \
  40. tk_if_mac_os_x_10_##vers(symbol != NULL, 1, __VA_ARGS__)
  41. #define TK_ELSE_MAC_OS_X(vers, ...) \
  42. tk_else_mac_os_x_10_##vers(__VA_ARGS__)
  43. #define TK_IF_MAC_OS_X_API_COND(vers, symbol, cond, ...) \
  44. tk_if_mac_os_x_10_##vers(symbol != NULL, cond, __VA_ARGS__)
  45. #define TK_ELSE(...) \
  46. } else { __VA_ARGS__
  47. #define TK_ENDIF \
  48. }
  49. /* Private macros that implement the checking macros above */
  50. #define tk_if_mac_os_x_yes(chk, cond, ...) \
  51. if (cond) { __VA_ARGS__
  52. #define tk_else_mac_os_x_yes(...) \
  53. } else {
  54. #define tk_if_mac_os_x_chk(chk, cond, ...) \
  55. if ((chk) && (cond)) { __VA_ARGS__
  56. #define tk_else_mac_os_x_chk(...) \
  57. } else { __VA_ARGS__
  58. #define tk_if_mac_os_x_no(chk, cond, ...) \
  59. if (0) {
  60. #define tk_else_mac_os_x_no(...) \
  61. } else { __VA_ARGS__
  62. /*
  63. * Macros for DEBUG_ASSERT_MESSAGE et al from Debugging.h.
  64. */
  65. #undef kComponentSignatureString
  66. #undef COMPONENT_SIGNATURE
  67. #define kComponentSignatureString "TkMacOSX"
  68. #define COMPONENT_SIGNATURE 'Tk '
  69. /*
  70. * Macros abstracting checks only active in a debug build.
  71. */
  72. #ifdef TK_MAC_DEBUG
  73. #define TKLog(f, ...) NSLog(f, ##__VA_ARGS__)
  74. /*
  75. * Macro to do debug message output.
  76. */
  77. #define TkMacOSXDbgMsg(m, ...) \
  78. do { \
  79. TKLog(@"%s:%d: %s(): " m, strrchr(__FILE__, '/')+1, \
  80. __LINE__, __func__, ##__VA_ARGS__); \
  81. } while (0)
  82. /*
  83. * Macro to do debug API failure message output.
  84. */
  85. #define TkMacOSXDbgOSErr(f, err) \
  86. do { \
  87. TkMacOSXDbgMsg("%s failed: %d", #f, (int)(err)); \
  88. } while (0)
  89. /*
  90. * Macro to do very common check for noErr return from given API and output
  91. * debug message in case of failure.
  92. */
  93. #define ChkErr(f, ...) ({ \
  94. OSStatus err_ = f(__VA_ARGS__); \
  95. if (err_ != noErr) { \
  96. TkMacOSXDbgOSErr(f, err_); \
  97. } \
  98. err_;})
  99. #else /* TK_MAC_DEBUG */
  100. #define TKLog(f, ...)
  101. #define TkMacOSXDbgMsg(m, ...)
  102. #define TkMacOSXDbgOSErr(f, err)
  103. #define ChkErr(f, ...) ({f(__VA_ARGS__);})
  104. #endif /* TK_MAC_DEBUG */
  105. /*
  106. * Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols.
  107. */
  108. #define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \
  109. static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \
  110. if (symbol == (void*)(-1L)) { \
  111. symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \
  112. STRINGIFY(symbol)); \
  113. }
  114. /*
  115. * The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
  116. * an unsigned int or as having either two or three bitfields.
  117. */
  118. typedef struct keycode_v_t {
  119. unsigned keychar: 22; /* UCS-32 character */
  120. unsigned o_s: 2; /* State of Option and Shift keys. */
  121. unsigned virt: 8; /* 8-bit virtual keycode - identifies a key. */
  122. } keycode_v;
  123. typedef struct keycode_x_t {
  124. unsigned keychar: 22; /* UCS-32 character */
  125. unsigned xvirtual: 10; /* Combines o_s and virtual. This 10-bit integer
  126. * is used as a key for looking up the character
  127. * produced when pressing a key with a particular
  128. * Shift and Option modifier state. */
  129. } keycode_x;
  130. typedef union MacKeycode_t {
  131. unsigned int uint;
  132. keycode_v v;
  133. keycode_x x;
  134. } MacKeycode;
  135. /*
  136. * Macros used in tkMacOSXKeyboard.c and tkMacOSXKeyEvent.c.
  137. * Note that 0x7f is del and 0xF8FF is the Apple Logo character.
  138. */
  139. #define ON_KEYPAD(virt) ((virt >= 0x41) && (virt <= 0x5C))
  140. #define IS_PRINTABLE(keychar) ((keychar >= 0x20) && (keychar != 0x7f) && \
  141. ((keychar < 0xF700) || keychar >= 0xF8FF))
  142. /*
  143. * An "index" is 2-bit bitfield showing the state of the Option and Shift
  144. * keys. It is used as an index when building the keymaps and it
  145. * is the value of the o_s bitfield of a keycode_v.
  146. */
  147. #define INDEX_SHIFT 1
  148. #define INDEX_OPTION 2
  149. #define INDEX2STATE(index) ((index & INDEX_SHIFT ? ShiftMask : 0) | \
  150. (index & INDEX_OPTION ? Mod2Mask : 0))
  151. #define INDEX2CARBON(index) ((index & INDEX_SHIFT ? shiftKey : 0) | \
  152. (index & INDEX_OPTION ? optionKey : 0))
  153. #define STATE2INDEX(state) ((state & ShiftMask ? INDEX_SHIFT : 0) | \
  154. (state & Mod2Mask ? INDEX_OPTION : 0))
  155. /*
  156. * Special values for the virtual bitfield. Actual virtual keycodes are < 128.
  157. */
  158. #define NO_VIRTUAL 0xFF /* Not generated by a key or the NSText"InputClient. */
  159. #define REPLACEMENT_VIRTUAL 0x80 /* A BMP char sent by the NSTextInputClient. */
  160. #define NON_BMP_VIRTUAL 0x81 /* A non-BMP char sent by the NSTextInputClient. */
  161. /*
  162. * A special character is used in the keycode for simulated modifier KeyPress
  163. * or KeyRelease XEvents. It is near the end of the private-use range but
  164. * different from the UniChar 0xF8FF which Apple uses for their logo character.
  165. * A different special character is used for keys, like the Menu key, which do
  166. * not appear on Macintosh keyboards.
  167. */
  168. #define MOD_KEYCHAR 0xF8FE
  169. #define UNKNOWN_KEYCHAR 0xF8FD
  170. /*
  171. * Structure encapsulating current drawing environment.
  172. */
  173. typedef struct TkMacOSXDrawingContext {
  174. CGContextRef context;
  175. NSView *view;
  176. HIShapeRef clipRgn;
  177. } TkMacOSXDrawingContext;
  178. /*
  179. * Variables internal to TkAqua.
  180. */
  181. MODULE_SCOPE long tkMacOSXMacOSXVersion;
  182. /*
  183. * Prototypes for TkMacOSXRegion.c.
  184. */
  185. MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r);
  186. MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r,
  187. HIShapeRef rgn);
  188. MODULE_SCOPE HIShapeRef TkMacOSXHIShapeCreateEmpty(void);
  189. MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
  190. const CGRect *inRect);
  191. MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithShape(
  192. HIMutableShapeRef inDestShape,
  193. HIShapeRef inSrcShape);
  194. MODULE_SCOPE OSStatus TkMacOSHIShapeDifferenceWithRect(
  195. HIMutableShapeRef inShape, const CGRect *inRect);
  196. MODULE_SCOPE OSStatus TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
  197. const CGRect *inRect);
  198. MODULE_SCOPE OSStatus TkMacOSHIShapeUnion(HIShapeRef inShape1,
  199. HIShapeRef inShape2, HIMutableShapeRef outResult);
  200. MODULE_SCOPE int TkMacOSXCountRectsInRegion(HIShapeRef shape);
  201. MODULE_SCOPE void TkMacOSXPrintRectsInRegion(HIShapeRef shape);
  202. /*
  203. * Prototypes of TkAqua internal procs.
  204. */
  205. MODULE_SCOPE void * TkMacOSXGetNamedSymbol(const char *module,
  206. const char *symbol);
  207. MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display);
  208. MODULE_SCOPE CGFloat TkMacOSXZeroScreenHeight();
  209. MODULE_SCOPE CGFloat TkMacOSXZeroScreenTop();
  210. MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
  211. int enable);
  212. MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
  213. int antiAlias);
  214. MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
  215. MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
  216. MODULE_SCOPE void TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context,
  217. CGImageRef image, unsigned long imageForeground,
  218. unsigned long imageBackground, CGRect imageBounds,
  219. CGRect srcBounds, CGRect dstBounds);
  220. MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc,
  221. TkMacOSXDrawingContext *dcPtr);
  222. MODULE_SCOPE void TkMacOSXRestoreDrawingContext(
  223. TkMacOSXDrawingContext *dcPtr);
  224. MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, unsigned long pixel,
  225. CGContextRef context);
  226. #define TkMacOSXGetTkWindow(window) (TkWindow *)Tk_MacOSXGetTkWindow(window)
  227. #define TkMacOSXGetNSWindowForDrawable(drawable) ((NSWindow*)TkMacOSXDrawable(drawable))
  228. #define TkMacOSXGetNSViewForDrawable(macWin) (NSView *)Tk_MacOSXGetNSViewForDrawable((Drawable)(macWin))
  229. MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds);
  230. MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable);
  231. MODULE_SCOPE void TkMacOSXInvalidateViewRegion(NSView *view,
  232. HIShapeRef rgn);
  233. MODULE_SCOPE CGContextRef TkMacOSXGetCGContextForDrawable(Drawable drawable);
  234. MODULE_SCOPE NSImage* TkMacOSXGetNSImageFromTkImage(Display *display,
  235. Tk_Image image, int width, int height);
  236. MODULE_SCOPE NSImage* TkMacOSXGetNSImageFromBitmap(Display *display,
  237. Pixmap bitmap, GC gc, int width, int height);
  238. MODULE_SCOPE NSColor* TkMacOSXGetNSColor(GC gc, unsigned long pixel);
  239. MODULE_SCOPE NSFont* TkMacOSXNSFontForFont(Tk_Font tkfont);
  240. MODULE_SCOPE NSDictionary* TkMacOSXNSFontAttributesForFont(Tk_Font tkfont);
  241. MODULE_SCOPE NSModalSession TkMacOSXGetModalSession(void);
  242. MODULE_SCOPE void TkMacOSXSelDeadWindow(TkWindow *winPtr);
  243. MODULE_SCOPE void TkMacOSXApplyWindowAttributes(TkWindow *winPtr,
  244. NSWindow *macWindow);
  245. MODULE_SCOPE int TkMacOSXStandardAboutPanelObjCmd(ClientData clientData,
  246. Tcl_Interp *interp, int objc,
  247. Tcl_Obj *const objv[]);
  248. MODULE_SCOPE int TkMacOSXIconBitmapObjCmd(ClientData clientData,
  249. Tcl_Interp *interp, int objc,
  250. Tcl_Obj *const objv[]);
  251. MODULE_SCOPE void TkMacOSXDrawSolidBorder(Tk_Window tkwin, GC gc,
  252. int inset, int thickness);
  253. MODULE_SCOPE int TkMacOSXServices_Init(Tcl_Interp *interp);
  254. MODULE_SCOPE int TkMacOSXRegisterServiceWidgetObjCmd(ClientData clientData,
  255. Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
  256. MODULE_SCOPE unsigned TkMacOSXAddVirtual(unsigned int keycode);
  257. MODULE_SCOPE void TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view,
  258. NSRect *bounds);
  259. MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin);
  260. MODULE_SCOPE void TkMacOSXDrawAllViews(ClientData clientData);
  261. MODULE_SCOPE unsigned long TkMacOSXClearPixel(void);
  262. #pragma mark Private Objective-C Classes
  263. #define VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
  264. enum { tkMainMenu = 1, tkApplicationMenu, tkWindowsMenu, tkHelpMenu};
  265. VISIBILITY_HIDDEN
  266. @interface TKMenu : NSMenu {
  267. @private
  268. void *_tkMenu;
  269. NSUInteger _tkOffset, _tkItemCount, _tkSpecial;
  270. }
  271. - (void)setSpecial:(NSUInteger)special;
  272. - (BOOL)isSpecial:(NSUInteger)special;
  273. @end
  274. @interface TKMenu(TKMenuDelegate) <NSMenuDelegate>
  275. @end
  276. VISIBILITY_HIDDEN
  277. @interface TKApplication : NSApplication {
  278. @private
  279. Tcl_Interp *_eventInterp;
  280. NSMenu *_servicesMenu;
  281. TKMenu *_defaultMainMenu, *_defaultApplicationMenu;
  282. NSMenuItem *_demoMenuItem;
  283. NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
  284. NSArray *_defaultHelpMenuItems, *_defaultFileMenuItems;
  285. NSAutoreleasePool *_mainPool;
  286. NSThread *_backgoundLoop;
  287. #ifdef __i386__
  288. /* The Objective C runtime used on i386 requires this. */
  289. int _poolLock;
  290. int _macOSVersion; /* 10000 * major + 100*minor */
  291. Bool _isDrawing;
  292. Bool _needsToDraw;
  293. #endif
  294. }
  295. @property int poolLock;
  296. @property int macOSVersion;
  297. @property Bool isDrawing;
  298. @property Bool needsToDraw;
  299. @end
  300. @interface TKApplication(TKInit)
  301. - (NSString *)tkFrameworkImagePath:(NSString*)image;
  302. - (void)_resetAutoreleasePool;
  303. - (void)_lockAutoreleasePool;
  304. - (void)_unlockAutoreleasePool;
  305. @end
  306. @interface TKApplication(TKKeyboard)
  307. - (void) keyboardChanged: (NSNotification *) notification;
  308. @end
  309. @interface TKApplication(TKWindowEvent) <NSApplicationDelegate>
  310. - (void) _setupWindowNotifications;
  311. @end
  312. @interface TKApplication(TKDialog) <NSOpenSavePanelDelegate>
  313. @end
  314. @interface TKApplication(TKMenu)
  315. - (void)tkSetMainMenu:(TKMenu *)menu;
  316. @end
  317. @interface TKApplication(TKMenus)
  318. - (void) _setupMenus;
  319. @end
  320. @interface NSApplication(TKNotify)
  321. /* We need to declare this hidden method. */
  322. - (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
  323. - (void) _runBackgroundLoop;
  324. @end
  325. @interface TKApplication(TKEvent)
  326. - (NSEvent *)tkProcessEvent:(NSEvent *)theEvent;
  327. @end
  328. @interface TKApplication(TKMouseEvent)
  329. - (NSEvent *)tkProcessMouseEvent:(NSEvent *)theEvent;
  330. @end
  331. @interface TKApplication(TKKeyEvent)
  332. - (NSEvent *)tkProcessKeyEvent:(NSEvent *)theEvent;
  333. @end
  334. @interface TKApplication(TKClipboard)
  335. - (void)tkProvidePasteboard:(TkDisplay *)dispPtr;
  336. - (void)tkCheckPasteboard;
  337. @end
  338. @interface TKApplication(TKHLEvents)
  339. - (void) terminate: (id) sender;
  340. - (void) superTerminate: (id) sender;
  341. - (void) preferences: (id) sender;
  342. - (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event
  343. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  344. - (void) handleOpenApplicationEvent: (NSAppleEventDescriptor *)event
  345. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  346. - (void) handleReopenApplicationEvent: (NSAppleEventDescriptor *)event
  347. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  348. - (void) handleShowPreferencesEvent: (NSAppleEventDescriptor *)event
  349. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  350. - (void) handleOpenDocumentsEvent: (NSAppleEventDescriptor *)event
  351. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  352. - (void) handlePrintDocumentsEvent: (NSAppleEventDescriptor *)event
  353. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  354. - (void) handleDoScriptEvent: (NSAppleEventDescriptor *)event
  355. withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
  356. - (void)handleURLEvent: (NSAppleEventDescriptor*)event
  357. withReplyEvent: (NSAppleEventDescriptor*)replyEvent;
  358. @end
  359. VISIBILITY_HIDDEN
  360. /*
  361. * Subclass TKContentView from NSTextInputClient to enable composition and
  362. * input from the Character Palette.
  363. */
  364. @interface TKContentView : NSView <NSTextInputClient>
  365. {
  366. @private
  367. NSString *privateWorkingText;
  368. Bool _tkNeedsDisplay;
  369. NSRect _tkDirtyRect;
  370. }
  371. @property Bool tkNeedsDisplay;
  372. @property NSRect tkDirtyRect;
  373. @end
  374. @interface TKContentView(TKKeyEvent)
  375. - (void) deleteWorkingText;
  376. - (void) cancelComposingText;
  377. @end
  378. @interface TKContentView(TKWindowEvent)
  379. - (void) addTkDirtyRect: (NSRect) rect;
  380. - (void) clearTkDirtyRect;
  381. - (void) generateExposeEvents: (NSRect) rect;
  382. - (void) tkToolbarButton: (id) sender;
  383. @end
  384. @interface NSWindow(TKWm)
  385. - (NSPoint) tkConvertPointToScreen:(NSPoint)point;
  386. - (NSPoint) tkConvertPointFromScreen:(NSPoint)point;
  387. @end
  388. VISIBILITY_HIDDEN
  389. @interface TKWindow : NSWindow
  390. {
  391. #ifdef __i386__
  392. /* The Objective C runtime used on i386 requires this. */
  393. Bool _mouseInResizeArea;
  394. Window _tkWindow;
  395. #endif
  396. }
  397. @property Bool mouseInResizeArea;
  398. @property Window tkWindow;
  399. @end
  400. @interface TKWindow(TKWm)
  401. - (void) tkLayoutChanged;
  402. @end
  403. @interface TKDrawerWindow : NSWindow
  404. {
  405. id _i1, _i2;
  406. #ifdef __i386__
  407. /* The Objective C runtime used on i386 requires this. */
  408. Window _tkWindow;
  409. #endif
  410. }
  411. @property Window tkWindow;
  412. @end
  413. @interface TKPanel : NSPanel
  414. {
  415. #ifdef __i386__
  416. /* The Objective C runtime used on i386 requires this. */
  417. Window _tkWindow;
  418. #endif
  419. }
  420. @property Window tkWindow;
  421. @end
  422. #pragma mark NSMenu & NSMenuItem Utilities
  423. @interface NSMenu(TKUtils)
  424. + (id)menuWithTitle:(NSString *)title;
  425. + (id)menuWithTitle:(NSString *)title menuItems:(NSArray *)items;
  426. + (id)menuWithTitle:(NSString *)title submenus:(NSArray *)submenus;
  427. - (NSMenuItem *)itemWithSubmenu:(NSMenu *)submenu;
  428. - (NSMenuItem *)itemInSupermenu;
  429. @end
  430. @interface NSMenuItem(TKUtils)
  431. + (id)itemWithSubmenu:(NSMenu *)submenu;
  432. + (id)itemWithTitle:(NSString *)title submenu:(NSMenu *)submenu;
  433. + (id)itemWithTitle:(NSString *)title action:(SEL)action;
  434. + (id)itemWithTitle:(NSString *)title action:(SEL)action
  435. target:(id)target;
  436. + (id)itemWithTitle:(NSString *)title action:(SEL)action
  437. keyEquivalent:(NSString *)keyEquivalent;
  438. + (id)itemWithTitle:(NSString *)title action:(SEL)action
  439. target:(id)target keyEquivalent:(NSString *)keyEquivalent;
  440. + (id)itemWithTitle:(NSString *)title action:(SEL)action
  441. keyEquivalent:(NSString *)keyEquivalent
  442. keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
  443. + (id)itemWithTitle:(NSString *)title action:(SEL)action
  444. target:(id)target keyEquivalent:(NSString *)keyEquivalent
  445. keyEquivalentModifierMask:(NSUInteger)keyEquivalentModifierMask;
  446. @end
  447. @interface NSColorPanel(TKDialog)
  448. - (void) _setUseModalAppearance: (BOOL) flag;
  449. @end
  450. @interface NSFont(TKFont)
  451. - (NSFont *) bestMatchingFontForCharacters: (const UTF16Char *) characters
  452. length: (NSUInteger) length attributes: (NSDictionary *) attributes
  453. actualCoveredLength: (NSUInteger *) coveredLength;
  454. @end
  455. /*
  456. * This method of NSApplication is not declared in NSApplication.h so we
  457. * declare it here to be a method of the TKMenu category.
  458. */
  459. @interface NSApplication(TKMenu)
  460. - (void) setAppleMenu: (NSMenu *) menu;
  461. @end
  462. /*
  463. * These methods are exposed because they are needed to prevent zombie windows
  464. * on systems with a TouchBar. The TouchBar Key-Value observer holds a
  465. * reference to the key window, which prevents deallocation of the key window
  466. * when it is closed.
  467. */
  468. @interface NSApplication(TkWm)
  469. - (id) _setKeyWindow: (NSWindow *) window;
  470. - (id) _setMainWindow: (NSWindow *) window;
  471. @end
  472. /*
  473. *---------------------------------------------------------------------------
  474. *
  475. * TKNSString --
  476. *
  477. * When Tcl is compiled with TCL_UTF_MAX = 3 (the default for 8.6) it cannot
  478. * deal directly with UTF-8 encoded non-BMP characters, since their UTF-8
  479. * encoding requires 4 bytes. Instead, when using these versions of Tcl, Tk
  480. * uses the CESU-8 encoding internally. This encoding is similar to UTF-8
  481. * except that it allows encoding surrogate characters as 3-byte sequences
  482. * using the same algorithm which UTF-8 uses for non-surrogates. This means
  483. * that a non-BMP character is encoded as a string of length 6. Apple's
  484. * NSString class does not provide a constructor which accepts a CESU-8 encoded
  485. * byte sequence as initial data. So we add a new class which does provide
  486. * such a constructor. It also has a DString property which is a DString whose
  487. * string pointer is a byte sequence encoding the NSString with the current Tk
  488. * encoding, namely UTF-8 if TCL_UTF_MAX >= 4 or CESU-8 if TCL_UTF_MAX = 3.
  489. *
  490. *---------------------------------------------------------------------------
  491. */
  492. @interface TKNSString:NSString {
  493. @private
  494. Tcl_DString _ds;
  495. NSString *_string;
  496. const char *_UTF8String;
  497. }
  498. @property const char *UTF8String;
  499. @property (readonly) Tcl_DString DString;
  500. - (instancetype)initWithTclUtfBytes:(const void *)bytes
  501. length:(NSUInteger)len;
  502. @end
  503. #endif /* _TKMACPRIV */
  504. /*
  505. * Local Variables:
  506. * mode: objc
  507. * c-basic-offset: 4
  508. * fill-column: 79
  509. * coding: utf-8
  510. * End:
  511. */