Skip to content

Commit

Permalink
Merge with cgimage_with_crossing branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Jul 8, 2024
2 parents c2f8aea + d516c14 commit 365059d
Show file tree
Hide file tree
Showing 47 changed files with 1,592 additions and 1,043 deletions.
11 changes: 0 additions & 11 deletions generic/tkFont.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,17 +887,6 @@ TheWorldHasChanged(
{
TkFontInfo *fiPtr = (TkFontInfo *)clientData;

/*
* On macOS it is catastrophic to recompute all widgets while the
* [NSView drawRect] method is drawing. The best that we can do in
* that situation is to abort the recomputation and hope for the best.
* This is ignored on other platforms.
*/

if (TkpWillDrawWidget(NULL)) {
return;
}

fiPtr->updatePending = 0;
RecomputeWidgets(fiPtr->mainPtr->winPtr);
}
Expand Down
2 changes: 2 additions & 0 deletions generic/tkFrame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,8 @@ DisplayFrame(
Tk_Depth(tkwin));
#else
pixmap = Tk_WindowId(tkwin);
Tk_ClipDrawableToRect(Tk_Display(tkwin), pixmap, 0, 0,
Tk_Width(tkwin), Tk_Height(tkwin));
#endif /* TK_NO_DOUBLE_BUFFERING */

if (framePtr->type != TYPE_LABELFRAME) {
Expand Down
2 changes: 1 addition & 1 deletion generic/tkTextDisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "tkMacOSXInt.h"
#endif

#define OK_TO_LOG (!TkpWillDrawWidget(textPtr->tkwin))
#define OK_TO_LOG 1

/*
* "Calculations of line pixel heights and the size of the vertical
Expand Down
53 changes: 51 additions & 2 deletions generic/tkWindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ static int Initialize(Tcl_Interp *interp);
static int NameWindow(Tcl_Interp *interp, TkWindow *winPtr,
TkWindow *parentPtr, const char *name);
static void UnlinkWindow(TkWindow *winPtr);

/*
* This static variable only makes sense for macOS and Windows, which never
* have more than one display. It is set by TkCloseDisplay, and when set
* prevents sending Enter and Leave events when all of the windows in the
* display are being destroyed. Tk does not send those events on X11; that
* job is handled by the X server.
*/

static int displayBeingClosed = 0;


/*
*----------------------------------------------------------------------
Expand All @@ -239,6 +250,7 @@ static void
TkCloseDisplay(
TkDisplay *dispPtr)
{
displayBeingClosed = 1;
TkClipCleanup(dispPtr);

if (dispPtr->name != NULL) {
Expand Down Expand Up @@ -1334,6 +1346,39 @@ Tk_CreateWindowFromPath(
*--------------------------------------------------------------
*/

#if defined(MAC_OSX_TK) || defined(_WIN32)
static void SendEnterLeaveForDestroy(
Tk_Window tkwin)
{
int x, y;
unsigned int state;
Tk_Window pointerWin;
TkWindow *containerPtr;

if (displayBeingClosed) {
return;
}
XQueryPointer(Tk_Display(tkwin), None, NULL, NULL, &x, &y,
NULL, NULL, &state);
pointerWin = Tk_CoordsToWindow(x, y, tkwin);
if (pointerWin == tkwin) {
if (!Tk_IsTopLevel(tkwin)) {
containerPtr = TkGetContainer((TkWindow *)pointerWin);
Tk_UpdatePointer((Tk_Window) containerPtr, x, y, state);
}
}

if (pointerWin && (tkwin == Tk_Parent(pointerWin))) {
Tk_UpdatePointer(Tk_Parent(tkwin), x, y, state);
}
}
#else
static void SendEnterLeaveForDestroy(
TCL_UNUSED(Tk_Window))
{
}
#endif

void
Tk_DestroyWindow(
Tk_Window tkwin) /* Window to destroy. */
Expand All @@ -1353,6 +1398,10 @@ Tk_DestroyWindow(

return;
}
if ((winPtr->flags & TK_DONT_DESTROY_WINDOW) == 0) {
SendEnterLeaveForDestroy(tkwin);
}

winPtr->flags |= TK_ALREADY_DEAD;

/*
Expand Down Expand Up @@ -1523,7 +1572,7 @@ Tk_DestroyWindow(
* Cleanup the data structures associated with this window.
*/

if (winPtr->flags & TK_WIN_MANAGED) {
if (winPtr->wmInfoPtr && (winPtr->flags & TK_WIN_MANAGED)) {
TkWmDeadWindow(winPtr);
} else if (winPtr->flags & TK_WM_COLORMAP_WINDOW) {
TkWmRemoveFromColormapWindows(winPtr);
Expand Down Expand Up @@ -2612,7 +2661,7 @@ Tk_RestackWindow(
TkWindow *otherPtr = (TkWindow *) other;

/*
* Special case: if winPtr is a top-level window then just find the
* Special case: if winPtr is a toplevel window then just find the
* top-level ancestor of otherPtr and restack winPtr above otherPtr
* without changing any of Tk's childLists.
*/
Expand Down
12 changes: 6 additions & 6 deletions library/demos/mac_styles.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,16 @@ if { [wm attributes $w -isdark] } {
}
proc beLight {f w} {
wm attributes $w -appearance aqua
$f.dark state !selected
$f.light state selected
after 10 $f.light state !hover
# A small delay is needed for the appearance change to complete.
after 10 [list $f.dark state !selected]
after 10 [list $f.light state selected]
}

proc beDark {f w} {
wm attributes $w -appearance darkaqua
$f.light state !selected
$f.dark state selected
after 10 $f.dark state !hover
# A small delay is needed for the appearance change to complete.
after 10 [list $f.light state !selected]
after 10 [list $f.dark state selected]
}
$w.notebook add $appearanceFrame -text "Appearance"

Expand Down
27 changes: 16 additions & 11 deletions library/palette.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ proc ::tk_setPalette {args} {
# which contains color information. Each element
# is named after a widget configuration option, and
# each value is the value for that option.
# Return Value:
# A list of commands which can be run to update
# the defaults database when exec'ed.

proc ::tk::RecolorTree {w colors} {
upvar $colors c
Expand All @@ -200,11 +203,14 @@ proc ::tk::RecolorTree {w colors} {
foreach dbOption [array names c] {
set option -[string tolower $dbOption]
set class [string replace $dbOption 0 0 [string toupper \
[string index $dbOption 0]]]
[string index $dbOption 0]]]
# Make sure this option is valid for this window.
if {![catch {$w configure $option} value]} {
# if the option database has a preference for this
# dbOption, then use it, otherwise use the defaults
# for the widget.
# Update the option for this window.
$w configure $option $c($dbOption)
# Retrieve a default value for this option. First check
# the option database. If it is not in the database use
# the value for the temporary prototype widget.
set defaultcolor [option get $w $dbOption $class]
if {$defaultcolor eq "" || \
([info exists prototype] && \
Expand All @@ -214,16 +220,15 @@ proc ::tk::RecolorTree {w colors} {
if {$defaultcolor ne ""} {
set defaultcolor [winfo rgb . $defaultcolor]
}
set chosencolor [lindex $value 4]
if {$chosencolor ne ""} {
set chosencolor [winfo rgb . $chosencolor]
# If the color requested for this option differs from
# the default, append a command to update the default.
set requestcolor [lindex $value 4]
if {$requestcolor ne ""} {
set requestcolor [winfo rgb . $requestcolor]
}
if {[string match $defaultcolor $chosencolor]} {
# Change the option database so that future windows will get
# the same colors.
if {![string match $defaultcolor $requestcolor]} {
append result ";\noption add [list \
*[winfo class $w].$dbOption $c($dbOption) 60]"
$w configure $option $c($dbOption)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions macosx/README
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ https://developer.apple.com/library/mac/documentation/Cocoa/\
Reference/ApplicationKit/Classes/NSApplication_Class)

void NSApplicationMain(int argc, char *argv[]) {
[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"myMain" owner:NSApp];
[NSApp run];
[NSApplication sharedApplication];
[NSBundle loadNibNamed:@"myMain" owner:NSApp];
[NSApp run];
}
Here NSApp is a standard global variable, initialized by the OS, which
points to an object in a subclass of NSApplication (called
Expand Down
4 changes: 2 additions & 2 deletions macosx/tkMacOSXClipboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ TkSelGetSelection(
([[NSPasteboard generalPasteboard] changeCount] != changeCount);

if (dispPtr && (haveExternalClip || dispPtr->clipboardActive)
&& selection == dispPtr->clipboardAtom
&& (target == XA_STRING || target == dispPtr->utf8Atom)) {
&& selection == dispPtr->clipboardAtom
&& (target == XA_STRING || target == dispPtr->utf8Atom)) {
NSString *string = nil;
NSPasteboard *pb = [NSPasteboard generalPasteboard];
NSString *type = [pb availableTypeFromArray:[NSArray arrayWithObject:
Expand Down
52 changes: 35 additions & 17 deletions macosx/tkMacOSXColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static void initColorTable()
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *)) {
darkAqua = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
lightAqua = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
}
#endif

Expand Down Expand Up @@ -103,7 +103,7 @@ static void initColorTable()
name = (char *)ckalloc(length + 1);
strcpy(name, key.UTF8String);
name[0] = (char)toupper(UCHAR(name[0]));
if (!strcmp(name, "WindowBackgroundColor")) {
if (!strcmp(name, "WindowBackgroundColor")) {

/*
* Avoid black windows on old systems.
Expand Down Expand Up @@ -192,8 +192,8 @@ TkMacOSXRGBPixel(
MacPixel p = {0};
p.pixel.colortype = rgbColor;
p.pixel.value = (unsigned int)(((red & 0xff) << 16) |
((green & 0xff) << 8) |
(blue & 0xff));
((green & 0xff) << 8) |
(blue & 0xff));
return p.ulong;
}

Expand Down Expand Up @@ -436,7 +436,7 @@ TkMacOSXInDarkMode(Tk_Window tkwin)

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *)) {
TkWindow *winPtr = (TkWindow*) tkwin;
TkWindow *winPtr = (TkWindow*) tkwin;
NSAppearanceName name;
NSView *view = nil;
if (winPtr && winPtr->privatePtr) {
Expand Down Expand Up @@ -611,6 +611,7 @@ TkpGetColor(
XColor color;
Colormap colormap = tkwin ? Tk_Colormap(tkwin) : noColormap;
NSView *view = nil;
Bool haveValidXColor = False;
static Bool initialized = NO;

if (!initialized) {
Expand Down Expand Up @@ -638,16 +639,22 @@ TkpGetColor(
p.pixel.colortype = entry->type;
p.pixel.value = (unsigned int)entry->index;
color.pixel = p.ulong;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
NSAppearance *windowAppearance;
if (@available(macOS 10.14, *)) {
if (view) {
windowAppearance = [view effectiveAppearance];
} else {
windowAppearance = [NSApp effectiveAppearance];
}
}
#endif

if (entry->type == semantic) {
CGFloat rgba[4];
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *)) {
NSAppearance *windowAppearance;
if (view) {
windowAppearance = [view effectiveAppearance];
} else {
windowAppearance = [NSApp effectiveAppearance];
}
if ([windowAppearance name] == NSAppearanceNameDarkAqua) {
colormap = darkColormap;
} else {
Expand All @@ -671,13 +678,13 @@ TkpGetColor(
} else {
GetRGBA(entry, p.ulong, rgba);
}
#else
#else //MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
GetRGBA(entry, p.ulong, rgba);
#endif
color.red = (unsigned short)(rgba[0] * 65535.0);
color.green = (unsigned short)(rgba[1] * 65535.0);
color.blue = (unsigned short)(rgba[2] * 65535.0);
goto validXColor;
#endif //MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
haveValidXColor = True;
} else if (SetCGColorComponents(entry, 0, &c)) {
const size_t n = CGColorGetNumberOfComponents(c);
const CGFloat *rgba = CGColorGetComponents(c);
Expand All @@ -695,15 +702,26 @@ TkpGetColor(
Tcl_Panic("CGColor with %d components", (int) n);
}
CGColorRelease(c);
goto validXColor;
haveValidXColor = True;
}
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
if (@available(macOS 10.14, *)) {
// Not sure whether colormap should also be set for non-semantic color
if (haveValidXColor && entry->type == semantic) {
if ([windowAppearance name] == NSAppearanceNameDarkAqua) {
colormap = darkColormap;
} else {
colormap = lightColormap;
}
}
}
#endif
}
}
if (TkParseColor(display, colormap, name, &color) == 0) {
if (!haveValidXColor && TkParseColor(display, colormap, name, &color) == 0) {
return NULL;
}

validXColor:
tkColPtr = (TkColor *)ckalloc(sizeof(TkColor));
tkColPtr->colormap = colormap;
tkColPtr->color = color;
Expand Down
Loading

0 comments on commit 365059d

Please sign in to comment.