Attachment "tkWmIconBitmap.diff" to
ticket [574128ff]
added by
vincentdarley
2002-06-26 22:21:29.
Index: doc/wm.n
===================================================================
RCS file: /cvsroot/tktoolkit/tk/doc/wm.n,v
retrieving revision 1.10
diff -b -u -r1.10 wm.n
--- doc/wm.n 22 Jun 2002 10:13:26 -0000 1.10
+++ doc/wm.n 26 Jun 2002 14:27:21 -0000
@@ -238,7 +238,8 @@
If the \fI-default\fR
flag is given, the icon is applied to all toplevel windows (existing
and future) to which no other specific icon has yet been applied.
-In addition to bitmap image types, any file which contains a valid
+In addition to bitmap image types, a full path specification to
+any file which contains a valid
Windows icon is also accepted (usually .ico or .icr files). Tcl will
first test if the files contains an icon, and if that fails, test for
a bitmap.
@@ -548,9 +549,6 @@
operation of the \fBwm\fR command. For example, some changes won't
take effect if the window is already active: the window will have
to be withdrawn and de-iconified in order to make the change happen.
-.PP
-On the Windows operating system \fIwm iconbitmap\fR has no effect when
-passed a bitmap: only icon files currently work properly.
.SH KEYWORDS
aspect ratio, deiconify, focus model, geometry, grid, group, icon, iconify, increments, position, size, title, top-level window, units, window manager
Index: win/tkWinWm.c
===================================================================
RCS file: /cvsroot/tktoolkit/tk/win/tkWinWm.c,v
retrieving revision 1.46
diff -b -u -r1.46 tkWinWm.c
--- win/tkWinWm.c 24 Jun 2002 20:34:40 -0000 1.46
+++ win/tkWinWm.c 26 Jun 2002 14:27:24 -0000
@@ -412,6 +412,8 @@
Tcl_Interp *interp, char* fileName));
static WinIconPtr ReadIconFromFile _ANSI_ARGS_((
Tcl_Interp *interp, char *fileName));
+static WinIconPtr GetIconFromPixmap _ANSI_ARGS_((Display *dsPtr,
+ Pixmap pixmap));
static int ReadICOHeader _ANSI_ARGS_((Tcl_Channel channel));
static BOOL AdjustIconImagePointers _ANSI_ARGS_((LPICONIMAGE lpImage));
static HICON MakeIconFromResource _ANSI_ARGS_((LPICONIMAGE lpIcon));
@@ -996,6 +998,97 @@
/*
*----------------------------------------------------------------------
*
+ * GetIconFromPixmap --
+ *
+ * Turn a Tk Pixmap (i.e. a bitmap) into an icon resource, if
+ * possible, otherwise NULL is returned.
+ *
+ * Results:
+ * A WinIconPtr structure containing a conversion of the given
+ * bitmap into an icon, with its ref count already incremented. The
+ * calling procedure should either place this structure inside a
+ * WmInfo structure, or it should pass it on to DecrIconRefCount()
+ * to ensure no memory leaks occur.
+ *
+ * If the given pixmap did not contain a valid icon structure,
+ * return NULL.
+ *
+ * Side effects:
+ * Memory is allocated for the returned structure and the icons
+ * it contains. If the structure is not wanted, it should be
+ * passed to DecrIconRefCount, and in any case a valid ref count
+ * should be ensured to avoid memory leaks.
+ *
+ * Currently icon resources are not shared, so the ref count of
+ * one of these structures will always be 0 or 1. However all we
+ * need do is implement some sort of lookup function between
+ * pixmaps and WinIconPtr structures and no other code will need
+ * to be changed.
+ *
+ *----------------------------------------------------------------------
+ */
+static WinIconPtr
+GetIconFromPixmap(dsPtr, pixmap)
+ Display *dsPtr;
+ Pixmap pixmap;
+{
+ WinIconPtr titlebaricon = NULL;
+ TkWinDrawable* twdPtr = (TkWinDrawable*) pixmap;
+
+ if (twdPtr == NULL) {
+ return NULL;
+ }
+
+ if (0 /* If we already have an icon for this pixmap */) {
+ titlebaricon = NULL; /* Get the real value from a lookup */
+ titlebaricon->refCount++;
+ return titlebaricon;
+ } else {
+ BlockOfIconImagesPtr lpIR;
+ ICONINFO icon;
+ HICON hIcon;
+ int width, height;
+
+ Tk_SizeOfBitmap(dsPtr, pixmap, &width, &height);
+
+ icon.fIcon = TRUE;
+ icon.xHotspot = 0;
+ icon.yHotspot = 0;
+ icon.hbmMask = twdPtr->bitmap.handle;
+ icon.hbmColor = twdPtr->bitmap.handle;
+
+ hIcon = CreateIconIndirect(&icon);
+ if (hIcon == NULL) {
+ return NULL;
+ }
+
+ lpIR = (BlockOfIconImagesPtr) ckalloc(sizeof(BlockOfIconImages));
+ if (lpIR == NULL) {
+ DestroyIcon(hIcon);
+ return NULL;
+ }
+
+ lpIR->nNumImages = 1;
+ lpIR->IconImages[0].Width = width;
+ lpIR->IconImages[0].Height = height;
+ lpIR->IconImages[0].Colors = 1 << twdPtr->bitmap.depth;
+ lpIR->IconImages[0].hIcon = hIcon;
+ /* These fields are ignored */
+ lpIR->IconImages[0].lpBits = 0;
+ lpIR->IconImages[0].dwNumBytes = 0;
+ lpIR->IconImages[0].lpXOR = 0;
+ lpIR->IconImages[0].lpAND = 0;
+
+ titlebaricon = (WinIconPtr) ckalloc(sizeof(WinIconInstance));
+ titlebaricon->iconBlock = lpIR;
+ titlebaricon->refCount = 1;
+ return titlebaricon;
+ }
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* DecrIconRefCount --
*
* Reduces the reference count.
@@ -1071,7 +1164,13 @@
*----------------------------------------------------------------------
*/
static HICON GetIcon(WinIconPtr titlebaricon, int icon_size) {
- BlockOfIconImagesPtr lpIR = titlebaricon->iconBlock;
+ BlockOfIconImagesPtr lpIR;
+
+ if (titlebaricon == NULL) {
+ return NULL;
+ }
+
+ lpIR = titlebaricon->iconBlock;
if (lpIR == NULL) {
return NULL;
} else {
@@ -1086,6 +1185,14 @@
return lpIR->IconImages[i].hIcon;
}
}
+
+ /*
+ * If we get here, then just return the first one,
+ * it will have to do!
+ */
+ if (lpIR->nNumImages >= 1) {
+ return lpIR->IconImages[0].hIcon;
+ }
}
return NULL;
}
@@ -2680,6 +2787,10 @@
Tk_FreeBitmap(winPtr->display, wmPtr->hints.icon_pixmap);
}
wmPtr->hints.flags &= ~IconPixmapHint;
+ if (WinSetIcon(interp, NULL,
+ (isDefault ? NULL : (Tk_Window) winPtr)) != TCL_OK) {
+ return TCL_ERROR;
+ }
} else {
/*
* In the future this block of code will use Tk's 'image'
@@ -2728,6 +2839,16 @@
}
wmPtr->hints.icon_pixmap = pixmap;
wmPtr->hints.flags |= IconPixmapHint;
+ titlebaricon = GetIconFromPixmap(Tk_Display(winPtr), pixmap);
+ if (titlebaricon != NULL) {
+ if (WinSetIcon(interp, titlebaricon,
+ (isDefault ? NULL : (Tk_Window) winPtr)) != TCL_OK) {
+ /* We didn't use the titlebaricon after all */
+ DecrIconRefCount(titlebaricon);
+ titlebaricon = NULL;
+ }
+
+ }
}
}
} else if ((c == 'i') && (strncmp(argv[1], "iconify", length) == 0)