Import Tk 8.6.11
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
* Macros and declarations that are purely internal & private to TkAqua.
|
||||
*
|
||||
* Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net>
|
||||
* Copyright 2008-2009, Apple Inc.
|
||||
* Copyright (c) 2008-2009 Apple Inc.
|
||||
* Copyright (c) 2020 Marc Culler
|
||||
*
|
||||
* See the file "license.terms" for information on usage and redistribution
|
||||
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
@@ -19,6 +20,10 @@
|
||||
#error Objective-C compiler required
|
||||
#endif
|
||||
|
||||
#ifndef __clang__
|
||||
#define instancetype id
|
||||
#endif
|
||||
|
||||
#define TextStyle MacTextStyle
|
||||
#import <ApplicationServices/ApplicationServices.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
@@ -98,11 +103,11 @@
|
||||
* debug message in case of failure.
|
||||
*/
|
||||
#define ChkErr(f, ...) ({ \
|
||||
OSStatus err = f(__VA_ARGS__); \
|
||||
if (err != noErr) { \
|
||||
TkMacOSXDbgOSErr(f, err); \
|
||||
OSStatus err_ = f(__VA_ARGS__); \
|
||||
if (err_ != noErr) { \
|
||||
TkMacOSXDbgOSErr(f, err_); \
|
||||
} \
|
||||
err;})
|
||||
err_;})
|
||||
|
||||
#else /* TK_MAC_DEBUG */
|
||||
#define TKLog(f, ...)
|
||||
@@ -122,6 +127,74 @@
|
||||
STRINGIFY(symbol)); \
|
||||
}
|
||||
|
||||
/*
|
||||
* The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
|
||||
* an unsigned int or as having either two or three bitfields.
|
||||
*/
|
||||
|
||||
typedef struct keycode_v_t {
|
||||
unsigned keychar: 22; /* UCS-32 character */
|
||||
unsigned o_s: 2; /* State of Option and Shift keys. */
|
||||
unsigned virtual: 8; /* 8-bit virtual keycode - identifies a key. */
|
||||
} keycode_v;
|
||||
|
||||
typedef struct keycode_x_t {
|
||||
unsigned keychar: 22; /* UCS-32 character */
|
||||
unsigned xvirtual: 10; /* Combines o_s and virtual. This 10-bit integer
|
||||
* is used as a key for looking up the character
|
||||
* produced when pressing a key with a particular
|
||||
* Shift and Option modifier state. */
|
||||
} keycode_x;
|
||||
|
||||
typedef union MacKeycode_t {
|
||||
unsigned int uint;
|
||||
keycode_v v;
|
||||
keycode_x x;
|
||||
} MacKeycode;
|
||||
|
||||
/*
|
||||
* Macros used in tkMacOSXKeyboard.c and tkMacOSXKeyEvent.c.
|
||||
* Note that 0x7f is del and 0xF8FF is the Apple Logo character.
|
||||
*/
|
||||
|
||||
#define ON_KEYPAD(virtual) ((virtual >= 0x41) && (virtual <= 0x5C))
|
||||
#define IS_PRINTABLE(keychar) ((keychar >= 0x20) && (keychar != 0x7f) && \
|
||||
((keychar < 0xF700) || keychar >= 0xF8FF))
|
||||
|
||||
/*
|
||||
* An "index" is 2-bit bitfield showing the state of the Option and Shift
|
||||
* keys. It is used as an index when building the keymaps and it
|
||||
* is the value of the o_s bitfield of a keycode_v.
|
||||
*/
|
||||
|
||||
#define INDEX_SHIFT 1
|
||||
#define INDEX_OPTION 2
|
||||
#define INDEX2STATE(index) ((index & INDEX_SHIFT ? ShiftMask : 0) | \
|
||||
(index & INDEX_OPTION ? Mod2Mask : 0))
|
||||
#define INDEX2CARBON(index) ((index & INDEX_SHIFT ? shiftKey : 0) | \
|
||||
(index & INDEX_OPTION ? optionKey : 0))
|
||||
#define STATE2INDEX(state) ((state & ShiftMask ? INDEX_SHIFT : 0) | \
|
||||
(state & Mod2Mask ? INDEX_OPTION : 0))
|
||||
|
||||
/*
|
||||
* Special values for the virtual bitfield. Actual virtual keycodes are < 128.
|
||||
*/
|
||||
|
||||
#define NO_VIRTUAL 0xFF /* Not generated by a key or the NSText"InputClient. */
|
||||
#define REPLACEMENT_VIRTUAL 0x80 /* A BMP char sent by the NSTextInputClient. */
|
||||
#define NON_BMP_VIRTUAL 0x81 /* A non-BMP char sent by the NSTextInputClient. */
|
||||
|
||||
/*
|
||||
* A special character is used in the keycode for simulated modifier KeyPress
|
||||
* or KeyRelease XEvents. It is near the end of the private-use range but
|
||||
* different from the UniChar 0xF8FF which Apple uses for their logo character.
|
||||
* A different special character is used for keys, like the Menu key, which do
|
||||
* not appear on Macintosh keyboards.
|
||||
*/
|
||||
|
||||
#define MOD_KEYCHAR 0xF8FE
|
||||
#define UNKNOWN_KEYCHAR 0xF8FD
|
||||
|
||||
/*
|
||||
* Structure encapsulating current drawing environment.
|
||||
*/
|
||||
@@ -143,24 +216,15 @@ MODULE_SCOPE long tkMacOSXMacOSXVersion;
|
||||
* Prototypes for TkMacOSXRegion.c.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
MODULE_SCOPE void TkMacOSXEmtpyRegion(TkRegion r);
|
||||
MODULE_SCOPE int TkMacOSXIsEmptyRegion(TkRegion r);
|
||||
#endif
|
||||
MODULE_SCOPE HIShapeRef TkMacOSXGetNativeRegion(TkRegion r);
|
||||
MODULE_SCOPE void TkMacOSXSetWithNativeRegion(TkRegion r,
|
||||
HIShapeRef rgn);
|
||||
MODULE_SCOPE void TkMacOSXOffsetRegion(TkRegion r, short dx, short dy);
|
||||
MODULE_SCOPE HIShapeRef TkMacOSXHIShapeCreateEmpty(void);
|
||||
MODULE_SCOPE HIMutableShapeRef TkMacOSXHIShapeCreateMutableWithRect(
|
||||
const CGRect *inRect);
|
||||
MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithShape(
|
||||
HIMutableShapeRef inDestShape,
|
||||
HIShapeRef inSrcShape);
|
||||
#if 0
|
||||
MODULE_SCOPE OSStatus TkMacOSXHIShapeSetWithRect(HIMutableShapeRef inShape,
|
||||
const CGRect *inRect);
|
||||
#endif
|
||||
MODULE_SCOPE OSStatus TkMacOSHIShapeDifferenceWithRect(
|
||||
HIMutableShapeRef inShape, const CGRect *inRect);
|
||||
MODULE_SCOPE OSStatus TkMacOSHIShapeUnionWithRect(HIMutableShapeRef inShape,
|
||||
@@ -181,46 +245,31 @@ MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp,
|
||||
int enable);
|
||||
MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable,
|
||||
int antiAlias);
|
||||
MODULE_SCOPE int TkMacOSXGenerateFocusEvent(TkWindow *winPtr,
|
||||
int activeFlag);
|
||||
MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr);
|
||||
MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr);
|
||||
MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window);
|
||||
MODULE_SCOPE EventModifiers TkMacOSXModifierState(void);
|
||||
MODULE_SCOPE NSBitmapImageRep* TkMacOSXBitmapRepFromDrawableRect(Drawable drawable,
|
||||
int x, int y, unsigned int width, unsigned int height);
|
||||
MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithXImage(XImage *image);
|
||||
MODULE_SCOPE void TkMacOSXDrawCGImage(Drawable d, GC gc, CGContextRef context,
|
||||
CGImageRef image, unsigned long imageForeground,
|
||||
unsigned long imageBackground, CGRect imageBounds,
|
||||
CGRect srcBounds, CGRect dstBounds);
|
||||
MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc,
|
||||
int useCG, TkMacOSXDrawingContext *dcPtr);
|
||||
TkMacOSXDrawingContext *dcPtr);
|
||||
MODULE_SCOPE void TkMacOSXRestoreDrawingContext(
|
||||
TkMacOSXDrawingContext *dcPtr);
|
||||
MODULE_SCOPE void TkMacOSXSetColorInContext(GC gc, unsigned long pixel,
|
||||
CGContextRef context);
|
||||
MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr,
|
||||
NSWindow *window, int fullscreen,
|
||||
Tcl_Interp *interp);
|
||||
MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr,
|
||||
int active);
|
||||
MODULE_SCOPE NSWindow* TkMacOSXDrawableWindow(Drawable drawable);
|
||||
MODULE_SCOPE NSView* TkMacOSXDrawableView(MacDrawable *macWin);
|
||||
#define TkMacOSXGetTkWindow(window) (TkWindow *)Tk_MacOSXGetTkWindow(window)
|
||||
#define TkMacOSXGetNSWindowForDrawable(drawable) ((NSWindow*)TkMacOSXDrawable(drawable))
|
||||
#define TkMacOSXGetNSViewForDrawable(macWin) (NSView *)Tk_MacOSXGetNSViewForDrawable((Drawable)(macWin))
|
||||
MODULE_SCOPE void TkMacOSXWinCGBounds(TkWindow *winPtr, CGRect *bounds);
|
||||
MODULE_SCOPE HIShapeRef TkMacOSXGetClipRgn(Drawable drawable);
|
||||
MODULE_SCOPE void TkMacOSXInvalidateViewRegion(NSView *view,
|
||||
HIShapeRef rgn);
|
||||
MODULE_SCOPE CGContextRef TkMacOSXGetCGContextForDrawable(Drawable drawable);
|
||||
MODULE_SCOPE CGImageRef TkMacOSXCreateCGImageWithDrawable(Drawable drawable);
|
||||
MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithTkImage(Display *display,
|
||||
MODULE_SCOPE NSImage* TkMacOSXGetNSImageFromTkImage(Display *display,
|
||||
Tk_Image image, int width, int height);
|
||||
MODULE_SCOPE NSImage* TkMacOSXGetNSImageWithBitmap(Display *display,
|
||||
MODULE_SCOPE NSImage* TkMacOSXGetNSImageFromBitmap(Display *display,
|
||||
Pixmap bitmap, GC gc, int width, int height);
|
||||
MODULE_SCOPE CGColorRef TkMacOSXCreateCGColor(GC gc, unsigned long pixel);
|
||||
MODULE_SCOPE NSColor* TkMacOSXGetNSColor(GC gc, unsigned long pixel);
|
||||
MODULE_SCOPE Tcl_Obj * TkMacOSXGetStringObjFromCFString(CFStringRef str);
|
||||
MODULE_SCOPE TkWindow* TkMacOSXGetTkWindow(NSWindow *w);
|
||||
MODULE_SCOPE NSFont* TkMacOSXNSFontForFont(Tk_Font tkfont);
|
||||
MODULE_SCOPE NSDictionary* TkMacOSXNSFontAttributesForFont(Tk_Font tkfont);
|
||||
MODULE_SCOPE NSModalSession TkMacOSXGetModalSession(void);
|
||||
@@ -237,12 +286,13 @@ MODULE_SCOPE void TkMacOSXDrawSolidBorder(Tk_Window tkwin, GC gc,
|
||||
int inset, int thickness);
|
||||
MODULE_SCOPE int TkMacOSXServices_Init(Tcl_Interp *interp);
|
||||
MODULE_SCOPE int TkMacOSXRegisterServiceWidgetObjCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE NSString* TclUniToNSString(const char *source, int numBytes);
|
||||
MODULE_SCOPE int TclUniAtIndex(NSString *string, int index, char *uni,
|
||||
unsigned int *code);
|
||||
MODULE_SCOPE char* NSStringToTclUni(NSString *string, int *numBytes);
|
||||
Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE unsigned TkMacOSXAddVirtual(unsigned int keycode);
|
||||
MODULE_SCOPE void TkMacOSXWinNSBounds(TkWindow *winPtr, NSView *view,
|
||||
NSRect *bounds);
|
||||
MODULE_SCOPE Bool TkMacOSXInDarkMode(Tk_Window tkwin);
|
||||
MODULE_SCOPE void TkMacOSXDrawAllViews(ClientData clientData);
|
||||
MODULE_SCOPE unsigned long TkMacOSXClearPixel(void);
|
||||
|
||||
#pragma mark Private Objective-C Classes
|
||||
|
||||
@@ -273,16 +323,21 @@ VISIBILITY_HIDDEN
|
||||
NSArray *_defaultApplicationMenuItems, *_defaultWindowsMenuItems;
|
||||
NSArray *_defaultHelpMenuItems, *_defaultFileMenuItems;
|
||||
NSAutoreleasePool *_mainPool;
|
||||
NSThread *_backgoundLoop;
|
||||
|
||||
#ifdef __i386__
|
||||
/* The Objective C runtime used on i386 requires this. */
|
||||
int _poolLock;
|
||||
int _macMinorVersion;
|
||||
int _macOSVersion; /* 10000 * major + 100*minor */
|
||||
Bool _isDrawing;
|
||||
Bool _needsToDraw;
|
||||
#endif
|
||||
|
||||
}
|
||||
@property int poolLock;
|
||||
@property int macMinorVersion;
|
||||
@property int macOSVersion;
|
||||
@property Bool isDrawing;
|
||||
@property Bool needsToDraw;
|
||||
|
||||
@end
|
||||
@interface TKApplication(TKInit)
|
||||
@@ -308,6 +363,7 @@ VISIBILITY_HIDDEN
|
||||
@interface NSApplication(TKNotify)
|
||||
/* We need to declare this hidden method. */
|
||||
- (void) _modalSession: (NSModalSession) session sendEvent: (NSEvent *) event;
|
||||
- (void) _runBackgroundLoop;
|
||||
@end
|
||||
@interface TKApplication(TKEvent)
|
||||
- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent;
|
||||
@@ -324,6 +380,7 @@ VISIBILITY_HIDDEN
|
||||
@end
|
||||
@interface TKApplication(TKHLEvents)
|
||||
- (void) terminate: (id) sender;
|
||||
- (void) superTerminate: (id) sender;
|
||||
- (void) preferences: (id) sender;
|
||||
- (void) handleQuitApplicationEvent: (NSAppleEventDescriptor *)event
|
||||
withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
|
||||
@@ -353,17 +410,22 @@ VISIBILITY_HIDDEN
|
||||
{
|
||||
@private
|
||||
NSString *privateWorkingText;
|
||||
Bool _needsRedisplay;
|
||||
Bool _tkNeedsDisplay;
|
||||
NSRect _tkDirtyRect;
|
||||
}
|
||||
@property Bool needsRedisplay;
|
||||
@property Bool tkNeedsDisplay;
|
||||
@property NSRect tkDirtyRect;
|
||||
@end
|
||||
|
||||
@interface TKContentView(TKKeyEvent)
|
||||
- (void) deleteWorkingText;
|
||||
- (void) cancelComposingText;
|
||||
@end
|
||||
|
||||
@interface TKContentView(TKWindowEvent)
|
||||
- (void) generateExposeEvents: (HIShapeRef) shape;
|
||||
- (void) addTkDirtyRect: (NSRect) rect;
|
||||
- (void) clearTkDirtyRect;
|
||||
- (void) generateExposeEvents: (NSRect) rect;
|
||||
- (void) tkToolbarButton: (id) sender;
|
||||
@end
|
||||
|
||||
@@ -374,16 +436,40 @@ VISIBILITY_HIDDEN
|
||||
|
||||
VISIBILITY_HIDDEN
|
||||
@interface TKWindow : NSWindow
|
||||
{
|
||||
#ifdef __i386__
|
||||
/* The Objective C runtime used on i386 requires this. */
|
||||
Bool _mouseInResizeArea;
|
||||
Window _tkWindow;
|
||||
#endif
|
||||
}
|
||||
@property Bool mouseInResizeArea;
|
||||
@property Window tkWindow;
|
||||
@end
|
||||
|
||||
@interface TKWindow(TKWm)
|
||||
- (void) tkLayoutChanged;
|
||||
@end
|
||||
|
||||
@interface NSDrawerWindow : NSWindow
|
||||
@interface TKDrawerWindow : NSWindow
|
||||
{
|
||||
id _i1, _i2;
|
||||
#ifdef __i386__
|
||||
/* The Objective C runtime used on i386 requires this. */
|
||||
Window _tkWindow;
|
||||
#endif
|
||||
}
|
||||
@property Window tkWindow;
|
||||
@end
|
||||
|
||||
@interface TKPanel : NSPanel
|
||||
{
|
||||
#ifdef __i386__
|
||||
/* The Objective C runtime used on i386 requires this. */
|
||||
Window _tkWindow;
|
||||
#endif
|
||||
}
|
||||
@property Window tkWindow;
|
||||
@end
|
||||
|
||||
#pragma mark NSMenu & NSMenuItem Utilities
|
||||
@@ -433,10 +519,54 @@ VISIBILITY_HIDDEN
|
||||
- (void) setAppleMenu: (NSMenu *) menu;
|
||||
@end
|
||||
|
||||
/*
|
||||
* These methods are exposed because they are needed to prevent zombie windows
|
||||
* on systems with a TouchBar. The TouchBar Key-Value observer holds a
|
||||
* reference to the key window, which prevents deallocation of the key window
|
||||
* when it is closed.
|
||||
*/
|
||||
|
||||
@interface NSApplication(TkWm)
|
||||
- (id) _setKeyWindow: (NSWindow *) window;
|
||||
- (id) _setMainWindow: (NSWindow *) window;
|
||||
@end
|
||||
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------------------------
|
||||
*
|
||||
* TKNSString --
|
||||
*
|
||||
* When Tcl is compiled with TCL_UTF_MAX = 3 (the default for 8.6) it cannot
|
||||
* deal directly with UTF-8 encoded non-BMP characters, since their UTF-8
|
||||
* encoding requires 4 bytes. Instead, when using these versions of Tcl, Tk
|
||||
* uses the CESU-8 encoding internally. This encoding is similar to UTF-8
|
||||
* except that it allows encoding surrogate characters as 3-byte sequences
|
||||
* using the same algorithm which UTF-8 uses for non-surrogates. This means
|
||||
* that a non-BMP character is encoded as a string of length 6. Apple's
|
||||
* NSString class does not provide a constructor which accepts a CESU-8 encoded
|
||||
* byte sequence as initial data. So we add a new class which does provide
|
||||
* such a constructor. It also has a DString property which is a DString whose
|
||||
* string pointer is a byte sequence encoding the NSString with the current Tk
|
||||
* encoding, namely UTF-8 if TCL_UTF_MAX >= 4 or CESU-8 if TCL_UTF_MAX = 3.
|
||||
*
|
||||
*---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
@interface TKNSString:NSString {
|
||||
@private
|
||||
Tcl_DString _ds;
|
||||
NSString *_string;
|
||||
const char *_UTF8String;
|
||||
}
|
||||
@property const char *UTF8String;
|
||||
@property (readonly) Tcl_DString DString;
|
||||
- (instancetype)initWithTclUtfBytes:(const void *)bytes
|
||||
length:(NSUInteger)len;
|
||||
@end
|
||||
|
||||
#endif /* _TKMACPRIV */
|
||||
|
||||
int TkMacOSXGetAppPath(ClientData cd, Tcl_Interp *ip, int objc, Tcl_Obj *const objv[]);
|
||||
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: objc
|
||||
|
||||
Reference in New Issue
Block a user