Skip to content

Commit

Permalink
Make everything compile (again) against Tcl 8.6 headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jan.nijtmans committed Nov 5, 2024
1 parent 1176a0f commit 9e75799
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 34 deletions.
6 changes: 3 additions & 3 deletions macosx/tkMacOSXDraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TkMacOSXInitCGDrawing(
}

if (Tcl_LinkVar(interp, "::tk::mac::CGAntialiasLimit",
&cgAntiAliasLimit, TCL_LINK_INT) != TCL_OK) {
(char *)&cgAntiAliasLimit, TCL_LINK_INT) != TCL_OK) {
Tcl_ResetResult(interp);
}
cgAntiAliasLimit = limit;
Expand All @@ -96,11 +96,11 @@ TkMacOSXInitCGDrawing(
*/

if (Tcl_LinkVar(interp, "::tk::mac::useThemedToplevel",
&useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
(char *)&useThemedToplevel, TCL_LINK_BOOLEAN) != TCL_OK) {
Tcl_ResetResult(interp);
}
if (Tcl_LinkVar(interp, "::tk::mac::useThemedFrame",
&useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
(char *)&useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) {
Tcl_ResetResult(interp);
}
transparentColor = TkMacOSXClearPixel();
Expand Down
42 changes: 11 additions & 31 deletions macosx/tkMacOSXFont.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@
#endif
*/

/*
* TclNumUtfChars() is the same as Tcl_NumUtfChars(), but counting
* in UTF-16 in stead of UTF-32. For Tcl 8.7 it's a little bit
* tricky to get this function, because we are compiling with
* TCL_UTF_MAX=4. Same for TclUtfAtIndex()
*/
#if TCL_MAJOR_VERSION < 9
# undef TclNumUtfChars
# undef TclUtfAtIndex
# ifdef USE_TCL_STUBS
# define TclNumUtfChars \
(tclStubsPtr->tcl_NumUtfChars) /* 312 */
# define TclUtfAtIndex \
(tclStubsPtr->tcl_UtfAtIndex) /* 325 */
# else
# define TclNumUtfChars Tcl_NumUtfChars
# define TclUtfAtIndex Tcl_UtfAtIndex
# endif
#endif

/*
* The following structure represents our Macintosh-specific implementation
* of a font object.
Expand Down Expand Up @@ -73,7 +53,7 @@ struct SystemFontMapEntry {

#define ThemeFont(n, ...) { kTheme##n##Font, "system" #n "Font", ##__VA_ARGS__ }
static const struct SystemFontMapEntry systemFontMap[] = {
ThemeFont(System, "TkDefaultFont", "TkIconFont"),
ThemeFont(System, "TkDefaultFont", "TkIconFont"),
ThemeFont(EmphasizedSystem, "TkCaptionFont", NULL),
ThemeFont(SmallSystem, "TkHeadingFont", "TkTooltipFont"),
ThemeFont(SmallEmphasizedSystem, NULL, NULL),
Expand Down Expand Up @@ -476,7 +456,7 @@ startOfClusterObjCmd(
if (stringArg == NULL) {
return TCL_ERROR;
}
Tcl_Size ulen = Tcl_GetCharLength(objv[1]);
Tcl_Size ulen = TkGetCharLength(objv[1]);
S = [[TKNSString alloc] initWithTclUtfBytes:stringArg length:len];
len = [S length];
if (TkGetIntForIndex(objv[2], ulen - 1, 0, &idx) != TCL_OK) {
Expand All @@ -490,7 +470,7 @@ startOfClusterObjCmd(
/* The string contains codepoints > \uFFFF. Determine UTF-16 index */
Tcl_Size newIdx = 0;
for (Tcl_Size i = 0; i < idx; i++) {
newIdx += 1 + (((newIdx < len-1) && ([S characterAtIndex:newIdx]&0xFC00) == 0xD800) && (([S characterAtIndex:newIdx+1]&0xFC00) == 0xDC00));
newIdx += 1 + (((newIdx < (Tcl_Size)len-1) && ([S characterAtIndex:newIdx]&0xFC00) == 0xD800) && (([S characterAtIndex:newIdx+1]&0xFC00) == 0xDC00));
}
idx = newIdx;
}
Expand Down Expand Up @@ -533,7 +513,7 @@ endOfClusterObjCmd(
if (stringArg == NULL) {
return TCL_ERROR;
}
Tcl_Size ulen = Tcl_GetCharLength(objv[1]);
Tcl_Size ulen = TkGetCharLength(objv[1]);
S = [[TKNSString alloc] initWithTclUtfBytes:stringArg length:len];
len = [S length];
if (TkGetIntForIndex(objv[2], ulen - 1, 0, &idx) != TCL_OK) {
Expand Down Expand Up @@ -923,7 +903,7 @@ void
TkpGetFontAttrsForChar(
TCL_UNUSED(Tk_Window), /* Window on the font's display */
Tk_Font tkfont, /* Font to query */
int c, /* Character of interest */
int c, /* Character of interest */
TkFontAttributes* faPtr) /* Output: Font attributes */
{
MacFont *fontPtr = (MacFont *) tkfont;
Expand Down Expand Up @@ -1082,8 +1062,8 @@ TkpMeasureCharsInContext(
attributes:fontPtr->nsAttributes];
typesetter = CTTypesetterCreateWithAttributedString(
(CFAttributedStringRef)attributedString);
start = TclNumUtfChars(source, rangeStart);
len = TclNumUtfChars(source + rangeStart, rangeLength);
start = Tcl_NumUtfChars(source, rangeStart);
len = Tcl_NumUtfChars(source + rangeStart, rangeLength);
if (start > 0) {
range.length = start;
line = CTTypesetterCreateLine(typesetter, range);
Expand Down Expand Up @@ -1184,7 +1164,7 @@ TkpMeasureCharsInContext(
[attributedString release];
[string release];
length = ceil(width - offset);
fit = (TclUtfAtIndex(source, index) - source) - rangeStart;
fit = (Tcl_UtfAtIndex(source, index) - source) - rangeStart;
done:
#ifdef TK_MAC_DEBUG_FONTS
TkMacOSXDbgMsg("measure: source=\"%s\" range=\"%.*s\" maxLength=%d "
Expand Down Expand Up @@ -1383,8 +1363,8 @@ TkpDrawAngledCharsInContext(
-textX, -textY);
}
CGContextConcatCTM(context, t);
start = TclNumUtfChars(source, rangeStart);
length = TclNumUtfChars(source, rangeStart + rangeLength) - start;
start = Tcl_NumUtfChars(source, rangeStart);
length = Tcl_NumUtfChars(source, rangeStart + rangeLength) - start;
line = CTTypesetterCreateLine(typesetter, CFRangeMake(start, length));
if (start > 0) {

Expand Down Expand Up @@ -1552,7 +1532,7 @@ TkMacOSXUseAntialiasedText(
Tcl_ResetResult(interp);
}
if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext",
&antialiasedTextEnabled,
(char *)&antialiasedTextEnabled,
TCL_LINK_INT) != TCL_OK) {
Tcl_ResetResult(interp);
}
Expand Down
28 changes: 28 additions & 0 deletions macosx/tkMacOSXNotify.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@
#include "tkMacOSXPrivate.h"
#include "tkMacOSXInt.h"
#include "tkMacOSXConstants.h"
#if TCL_MAJOR_VERSION < 9
#undef Tcl_MacOSXNotifierAddRunLoopMode
#ifdef USE_TCL_STUBS
#ifdef __cplusplus
extern "C" {
#endif
/* Little hack to eliminate the need for "tclInt.h" here:
Just copy a small portion of TclIntPlatStubs, just
enough to make it work. See [600b72bfbc] */
typedef struct TclIntPlatStubs {
int magic;
void *hooks;
void (*dummy[19]) (void); /* dummy entries 0-18, not used */
void (*tclMacOSXNotifierAddRunLoopMode) (const void *runLoopMode); /* 19 */
} TclIntPlatStubs;
extern const TclIntPlatStubs *tclIntPlatStubsPtr;
#ifdef __cplusplus
}
#endif
#define Tcl_MacOSXNotifierAddRunLoopMode \
(tclIntPlatStubsPtr->tclMacOSXNotifierAddRunLoopMode) /* 19 */
#elif TCL_MINOR_VERSION < 7
extern void TclMacOSXNotifierAddRunLoopMode(const void *runLoopMode);
# define Tcl_MacOSXNotifierAddRunLoopMode TclMacOSXNotifierAddRunLoopMode
#else
extern void Tcl_MacOSXNotifierAddRunLoopMode(const void *runLoopMode);
#endif
#endif
#import <objc/objc-auto.h>

/* This is not used for anything at the moment. */
Expand Down

0 comments on commit 9e75799

Please sign in to comment.