Skip to content

Commit

Permalink
Backport "cgimage_with_crossing" branch to Tk 8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Nov 5, 2024
2 parents e61b418 + 9e75799 commit 13a6169
Show file tree
Hide file tree
Showing 64 changed files with 1,514 additions and 1,220 deletions.
17 changes: 0 additions & 17 deletions generic/tkCanvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -3081,10 +3081,6 @@ DisplayCanvas(
Tk_Item *itemPtr;
Pixmap pixmap;
int screenX1, screenX2, screenY1, screenY2, width, height;
#ifdef MAC_OSX_TK
TkWindow *winPtr;
MacDrawable *macWin;
#endif

if (canvasPtr->tkwin == NULL) {
return;
Expand All @@ -3094,19 +3090,6 @@ DisplayCanvas(
goto done;
}

#ifdef MAC_OSX_TK
/*
* If drawing is disabled, all we need to do is
* clear the REDRAW_PENDING flag.
*/
winPtr = (TkWindow *)(canvasPtr->tkwin);
macWin = winPtr->privatePtr;
if (macWin && (macWin->flags & TK_DO_NOT_DRAW)){
canvasPtr->flags &= ~REDRAW_PENDING;
return;
}
#endif

/*
* Choose a new current item if that is needed (this could cause event
* handlers to be invoked).
Expand Down
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
6 changes: 3 additions & 3 deletions generic/tkImage.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ Tk_ImageObjCmd(
}
if (typePtr == NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"image type \"%s\" doesn't exist", arg));
"image type \"%s\" does not exist", arg));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE_TYPE", arg, (char *)NULL);
return TCL_ERROR;
}
Expand Down Expand Up @@ -510,7 +510,7 @@ Tk_ImageObjCmd(
return TCL_OK;

alreadyDeleted:
Tcl_SetObjResult(interp, Tcl_ObjPrintf("image \"%s\" doesn't exist",arg));
Tcl_SetObjResult(interp, Tcl_ObjPrintf("image \"%s\" does not exist",arg));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE", arg, (char *)NULL);
return TCL_ERROR;
}
Expand Down Expand Up @@ -656,7 +656,7 @@ Tk_GetImage(
noSuchImage:
if (interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"image \"%s\" doesn't exist", name));
"image \"%s\" does not exist", name));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "IMAGE", name, (char *)NULL);
}
return NULL;
Expand Down
3 changes: 3 additions & 0 deletions generic/tkStubInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ MODULE_SCOPE const TkStubs tkStubs;
#define TkMacOSXSetUpClippingRgn (void (*)(Drawable))(void *)doNothing
#undef TkMacOSXIsCharacterMissing
#define TkMacOSXIsCharacterMissing (int (*)(Tk_Font, unsigned int))(void *)doNothing
#undef TkMacOSXSetDrawingEnabled
#define TkMacOSXSetDrawingEnabled (void (*)(TkWindow *, int))(void *)doNothing


#if defined(_WIN32) && !defined(TK_NO_DEPRECATED) && TCL_MAJOR_VERSION < 9
# define Tk_TranslateWinEvent TkTranslateWinEvent
Expand Down
2 changes: 1 addition & 1 deletion generic/tkStyle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ Tk_GetStyle(
if (entryPtr == NULL) {
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"style \"%s\" doesn't exist", name));
"style \"%s\" does not exist", name));
Tcl_SetErrorCode(interp, "TK", "LOOKUP", "STYLE", name, (char *)NULL);
}
return NULL;
Expand Down
43 changes: 9 additions & 34 deletions generic/tkTextDisp.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include "tkMacOSXInt.h"
#endif

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

/*
* "Calculations of line pixel heights and the size of the vertical
* scrollbar."
Expand Down Expand Up @@ -205,20 +203,13 @@ typedef struct TextStyle {

/*
* Macros to make debugging/testing logging a little easier.
*
* On OSX 10.14 Drawing procedures are sometimes run because the system has
* decided to redraw the window. This can corrupt the data that a test is
* trying to collect. So we don't write to the logging variables when the
* drawing procedure is being run that way. Other systems can always log.
*/

#define LOG(toVar,what) \
if (OK_TO_LOG) \
Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
Tcl_SetVar2(textPtr->interp, toVar, NULL, (what), \
TCL_GLOBAL_ONLY|TCL_APPEND_VALUE|TCL_LIST_ELEMENT)
#define CLEAR(var) \
if (OK_TO_LOG) \
Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY)
Tcl_SetVar2(interp, var, NULL, "", TCL_GLOBAL_ONLY)

/*
* The following structure describes one line of the display, which may be
Expand Down Expand Up @@ -4192,22 +4183,6 @@ DisplayText(
return;
}

#ifdef MAC_OSX_TK
/*
* If the toplevel is being resized it would be dangerous to try redrawing
* the widget. But we can just clear the REDRAW_PENDING flag and return.
* This display proc will be called again after the widget has been
* reconfigured.
*/

TkWindow *winPtr = (TkWindow *)(textPtr->tkwin);
MacDrawable *macWin = winPtr->privatePtr;
if (macWin && (macWin->flags & TK_DO_NOT_DRAW)) {
dInfoPtr->flags &= ~REDRAW_PENDING;
return;
}
#endif

interp = textPtr->interp;
Tcl_Preserve(interp);

Expand Down Expand Up @@ -4411,8 +4386,8 @@ DisplayText(
Tk_Draw3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, textPtr->highlightWidth,
textPtr->highlightWidth,
Tk_Width(textPtr->tkwin) - 2*textPtr->highlightWidth,
Tk_Height(textPtr->tkwin) - 2*textPtr->highlightWidth,
Tk_Width(textPtr->tkwin) - 2 * textPtr->highlightWidth,
Tk_Height(textPtr->tkwin) - 2 * textPtr->highlightWidth,
textPtr->borderWidth, textPtr->relief);
if (textPtr->highlightWidth > 0) {
GC fgGC, bgGC;
Expand All @@ -4433,25 +4408,25 @@ DisplayText(
if (textPtr->padY > 0) {
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, borders, borders,
Tk_Width(textPtr->tkwin) - 2*borders, textPtr->padY,
Tk_Width(textPtr->tkwin) - 2 * borders, textPtr->padY,
0, TK_RELIEF_FLAT);
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, borders,
Tk_Height(textPtr->tkwin) - borders - textPtr->padY,
Tk_Width(textPtr->tkwin) - 2*borders,
Tk_Width(textPtr->tkwin) - 2 * borders,
textPtr->padY, 0, TK_RELIEF_FLAT);
}
if (textPtr->padX > 0) {
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border, borders, borders + textPtr->padY,
textPtr->padX,
Tk_Height(textPtr->tkwin) - 2*borders -2*textPtr->padY,
Tk_Height(textPtr->tkwin) - 2 * borders -2 * textPtr->padY,
0, TK_RELIEF_FLAT);
Tk_Fill3DRectangle(textPtr->tkwin, Tk_WindowId(textPtr->tkwin),
textPtr->border,
Tk_Width(textPtr->tkwin) - borders - textPtr->padX,
borders + textPtr->padY, textPtr->padX,
Tk_Height(textPtr->tkwin) - 2*borders -2*textPtr->padY,
Tk_Height(textPtr->tkwin) - 2 * borders -2 * textPtr->padY,
0, TK_RELIEF_FLAT);
}
dInfoPtr->flags &= ~REDRAW_BORDERS;
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 @@ -247,16 +247,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
Loading

0 comments on commit 13a6169

Please sign in to comment.