summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXImage.c
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2022-09-19 15:44:09 (GMT)
committermarc_culler <marc.culler@gmail.com>2022-09-19 15:44:09 (GMT)
commit86c5545fc2488fad191fa623fbb100ff1a452957 (patch)
treecdc42e5c048f83239098afd4f70aa04541824cd6 /macosx/tkMacOSXImage.c
parent74e03e32278cc4b3e3d09ca564aed76ae0a177aa (diff)
downloadtk-86c5545fc2488fad191fa623fbb100ff1a452957.zip
tk-86c5545fc2488fad191fa623fbb100ff1a452957.tar.gz
tk-86c5545fc2488fad191fa623fbb100ff1a452957.tar.bz2
Add -template option to nsimage.
Diffstat (limited to 'macosx/tkMacOSXImage.c')
-rw-r--r--macosx/tkMacOSXImage.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c
index d74ce01..c3dc4ed 100644
--- a/macosx/tkMacOSXImage.c
+++ b/macosx/tkMacOSXImage.c
@@ -1032,9 +1032,9 @@ typedef struct TkNSImageMaster TkNSImageMaster;
*/
struct TkNSImageInstance {
- TkNSImageMaster *masterPtr; /* Pointer to the master for the image. */
- NSImage *image; /* Pointer to a named NSImage.*/
- TkNSImageInstance *nextPtr; /* First in the list of instances associated
+ TkNSImageMaster *masterPtr; /* Pointer to the master for the image. */
+ NSImage *image; /* Pointer to an NSImage.*/
+ TkNSImageInstance *nextPtr; /* First in the list of instances associated
* with this master. */
};
@@ -1048,9 +1048,10 @@ struct TkNSImageMaster {
int width, height; /* Dimensions of the image. */
double alpha; /* Transparency, between 0.0 and 1.0*/
bool pressed; /* Image is for use in a pressed button.*/
+ bool template; /* Image is for use as a template.*/
char *imageName ; /* Malloc'ed image name. */
- char *source; /* Malloc'ed name of the NSimage. */
- char *as; /* Malloc'ed description of source */
+ char *source; /* Malloc'ed string describing the image. */
+ char *as; /* Malloc'ed interpretation of source */
int flags; /* Sundry flags, defined below. */
TkNSImageInstance *instancePtr; /* Start of list of instances associated
* with this master. */
@@ -1096,7 +1097,7 @@ static Tk_ImageType TkNSImageType = {
};
/*
- * Information used for parsing configuration specifications:
+ * Default values used for parsing configuration specifications:
*/
#define DEF_SOURCE ""
#define DEF_AS "name"
@@ -1104,6 +1105,7 @@ static Tk_ImageType TkNSImageType = {
#define DEF_WIDTH "32"
#define DEF_ALPHA "1.0"
#define DEF_PRESSED "0"
+#define DEF_TEMPLATE "0"
static const Tk_OptionSpec systemImageOptions[] = {
{TK_OPTION_STRING, "-source", NULL, NULL, DEF_SOURCE,
@@ -1118,6 +1120,8 @@ static const Tk_OptionSpec systemImageOptions[] = {
-1, Tk_Offset(TkNSImageMaster, alpha), 0, NULL, 0},
{TK_OPTION_BOOLEAN, "-pressed", NULL, NULL, DEF_PRESSED,
-1, Tk_Offset(TkNSImageMaster, pressed), 0, NULL, 0},
+ {TK_OPTION_BOOLEAN, "-template", NULL, NULL, DEF_TEMPLATE,
+ -1, Tk_Offset(TkNSImageMaster, pressed), 0, NULL, 0},
{TK_OPTION_END, NULL, NULL, NULL, NULL, 0, -1, 0, NULL, 0}
};
@@ -1269,6 +1273,9 @@ TkNSImageConfigureMaster(
[masterPtr->image release];
[masterPtr->darkModeImage release];
masterPtr->image = [newImage retain];
+ if (masterPtr->template) {
+ newImage.template = YES;
+ }
masterPtr->darkModeImage = [[masterPtr->image copy] retain];
if ([masterPtr->darkModeImage isTemplate]) {
@@ -1292,11 +1299,24 @@ TkNSImageConfigureMaster(
TintImage(masterPtr->darkModeImage, [NSColor whiteColor], 0.5);
}
} else {
- Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown named NSImage.\n"
- "Try omitting ImageName, "
- "e.g. use NSCaution for NSImageNameCaution.", -1));
- Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
- goto errorExit;
+ switch(sourceInterpretation) {
+ case NAME_SOURCE:
+ Tcl_SetObjResult(interp, Tcl_NewStringObj("Unknown named NSImage.\n"
+ "Try omitting ImageName, "
+ "e.g. use NSCaution for NSImageNameCaution.", -1));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
+ goto errorExit;
+ case FILE_SOURCE:
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "Failed to load image file.\n", -1));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
+ goto errorExit;
+ default:
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(
+ "Unrecognized file type.\n", -1));
+ Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL);
+ goto errorExit;
+ }
}
/*