summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--doc/wm.n73
-rw-r--r--tests/winWm.test27
-rw-r--r--win/tkWinWm.c107
4 files changed, 157 insertions, 55 deletions
diff --git a/ChangeLog b/ChangeLog
index fd16dd7..16f7c1d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-12-01 Jeff Hobbs <jeffh@ActiveState.com>
+
+ * doc/wm.n, tests/winWm.test:
+ * win/tkWinWm.c: add -transparentcolor attribute for Windows.
+
2006-12-01 Joe English <jenglish@users.sourceforge.net>
* generic/ttk/ttkTheme.h, generic/ttk/ttkLayout.c:
diff --git a/doc/wm.n b/doc/wm.n
index c55dcb2..8f3aa4d 100644
--- a/doc/wm.n
+++ b/doc/wm.n
@@ -5,7 +5,7 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: wm.n,v 1.27 2006/11/16 13:50:17 dkf Exp $
+'\" RCS: @(#) $Id: wm.n,v 1.28 2006/12/01 19:48:00 hobbs Exp $
'\"
.so man.macros
.TH wm n 8.5 Tk "Tk Built-In Commands"
@@ -50,38 +50,62 @@ returned).
\fBwm attributes \fIwindow\fR ?\fBoption\fR?
.TP
\fBwm attributes \fIwindow\fR ?\fBoption value option value...\fR?
-.RS
This subcommand returns or sets platform specific attributes associated
with a window. The first form returns a list of the platform specific
flags and their values. The second form returns the value for the
specific option. The third form sets one or more of the values. The
values are as follows:
.PP
-On Windows, \fB\-disabled\fR gets or sets whether the window is in a
-disabled state. \fB\-toolwindow\fR gets or sets the style of the window
-to toolwindow (as defined in the MSDN). \fB\-topmost\fR gets or sets
-whether this is a topmost window (displays above all other windows).
+On Windows, the following attributes may be set.
+.RS
+.TP
+\fB\-disabled\fR
+Specifies whether the window is in a disabled state.
+.TP
+\fB\-toolwindow\fR
+Specifies a toolwindow style window (as defined in the MSDN).
+.TP
+\fB\-topmost\fR
+Specifies whether this is a topmost window (displays above all other windows).
.VS 8.5
-The
-\fB\-alpha\fR sets the alpha transparency level of the toplevel. It accepts
-a value from \fB0.0\fR (fully transparent) to \fB1.0\fR (opaque). Values
-outside that range will be constrained. This is supported on Windows
-2000/XP+. Where not supported, the \fB\-alpha\fR value remains at
-\fB1.0\fR.
-The
-\fB\-fullscreen\fR attribute will place the window in a mode that
-takes up the entire screen, has no borders, and covers the Start
-menu and taskbar.
+.TP
+\fB\-alpha\fR
+Specifies the alpha transparency level of the toplevel.
+It accepts a value from \fB0.0\fR (fully transparent) to \fB1.0\fR
+(opaque). Values outside that range will be constrained. This is
+supported on Windows 2000/XP+. Where not supported, the \fB\-alpha\fR
+value remains at \fB1.0\fR.
+.TP
+\fB\-transparentcolor\fR
+Specifies the transparent color index of the toplevel. It takes any color
+value accepted by \fBTk_GetColor\fR. If the empty string is specified
+(default), no transparent color is used. This is supported on Windows
+2000/XP+. Where not supported, the \fB\-transparentcolor\fR value remains
+at \fB{}\fR.
+.TP
+\fB\-fullscreen\fR
+Places the window in a mode that takes up the entire screen, has no
+borders, and covers the Start menu and taskbar.
+.RE
.VE 8.5
.PP
-On Mac OS X, \fB\-modified\fR gets or sets the modification state of the
-window (determines whether the window close widget contains the modification
-indicator and whether the proxy icon is draggable).
-\fB\-titlepath\fR gets or sets the path of the file referenced as
-the window proxy icon (which can be dragged and dropped in lieu of the file's
-finder icon). \fB\-alpha\fR sets the alpha transparency level of the window,
-it accepts a value from \fB0.0\fR (fully transparent) to \fB1.0\fR (opaque),
+On Mac OS X, the following attributes may be set.
+.RS
+.TP
+\fB\-modified\fR
+Specifies the modification state of the window (determines whether the
+window close widget contains the modification indicator and whether the
+proxy icon is draggable).
+.TP
+\fB\-titlepath\fR
+Specifies the path of the file referenced as the window proxy icon (which
+can be dragged and dropped in lieu of the file's finder icon).
+.TP
+\fB\-alpha\fR
+Specifies the alpha transparency level of the window.
+It accepts a value from \fB0.0\fR (fully transparent) to \fB1.0\fR (opaque),
values outside that range will be constrained.
+.RE
.PP
On X11, the following attributes may be set.
These are not supported by all window managers,
@@ -108,7 +132,6 @@ Querying the value of an attribute returns the current state,
which will not be the same as the value most recently set
if the window manager has not yet processed the request
or if it does not support the attribute.
-.RE
.TP
\fBwm client \fIwindow\fR ?\fIname\fR?
If \fIname\fR is specified, this command stores \fIname\fR (which
@@ -334,7 +357,7 @@ most modern window managers support. A \fBwm iconbitmap\fR may exist
simultaneously. It is recommended to use not more than 2 icons, placing
the larger icon first.
.PP
-On Macintosh, this is currently does nothing.
+On Macintosh, this currently does nothing.
.VE 8.5
.RE
.TP
diff --git a/tests/winWm.test b/tests/winWm.test
index e3b0d84..0b5592a 100644
--- a/tests/winWm.test
+++ b/tests/winWm.test
@@ -9,7 +9,7 @@
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
#
-# RCS: @(#) $Id: winWm.test,v 1.17 2006/10/17 10:21:50 patthoyts Exp $
+# RCS: @(#) $Id: winWm.test,v 1.18 2006/12/01 19:48:00 hobbs Exp $
package require tcltest 2.1
eval tcltest::configure $argv
@@ -235,7 +235,7 @@ test winWm-6.1 {wm attributes} win {
destroy .t
toplevel .t
wm attributes .t
-} {-alpha 1.0 -disabled 0 -fullscreen 0 -toolwindow 0 -topmost 0}
+} {-alpha 1.0 -transparentcolor {} -disabled 0 -fullscreen 0 -toolwindow 0 -topmost 0}
test winWm-6.2 {wm attributes} win {
destroy .t
toplevel .t
@@ -246,7 +246,7 @@ test winWm-6.3 {wm attributes} win {
destroy .t
toplevel .t
list [catch {wm attributes .t -foo} msg] $msg
-} {1 {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}}
+} {1 {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-fullscreen ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}}
test winWm-6.4 {wm attributes -alpha} win {
# Expect this to return all 1.0 {} on pre-2K/XP
@@ -291,6 +291,27 @@ test winWm-6.6 {wm attributes -alpha} win {
}
} {}
+test winWm-6.7 {wm attributes -transparentcolor} win {
+ # Expect this to return all "" on pre-2K/XP
+ destroy .t
+ toplevel .t
+ set res {}
+ lappend res [wm attributes .t -transparentcolor]
+ # we don't return on set yet
+ lappend res [wm attributes .t -trans black]
+ lappend res [wm attributes .t -trans]
+ lappend res [wm attributes .t -trans "#FFFFFF"]
+ lappend res [wm attributes .t -trans]
+ destroy .t
+ set res
+} [list {} {} black {} "#FFFFFF"]
+
+test winWm-6.8 {wm attributes -transparentcolor} win {
+ destroy .t
+ toplevel .t
+ list [catch {wm attributes .t -tr foo} msg] $msg
+} {1 {unknown color name "foo"}}
+
test winWm-7.1 {deiconify on an unmapped toplevel\
will raise the window and set the focus} win {
destroy .t
diff --git a/win/tkWinWm.c b/win/tkWinWm.c
index c9a8777..86360fb 100644
--- a/win/tkWinWm.c
+++ b/win/tkWinWm.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tkWinWm.c,v 1.109 2006/04/05 20:56:40 hobbs Exp $
+ * RCS: @(#) $Id: tkWinWm.c,v 1.110 2006/12/01 19:48:00 hobbs Exp $
*/
#include "tkWinInt.h"
@@ -25,6 +25,9 @@
#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED 0x00080000
#endif
+#ifndef LWA_COLORKEY
+#define LWA_COLORKEY 0x00000001
+#endif
#ifndef LWA_ALPHA
#define LWA_ALPHA 0x00000002
#endif
@@ -244,6 +247,8 @@ typedef struct TkWmInfo {
DWORD style, exStyle; /* Style flags for the wrapper window. */
LONG styleConfig; /* Extra user requested style bits */
LONG exStyleConfig; /* Extra user requested extended style bits */
+ Tcl_Obj *crefObj; /* COLORREF object for transparent handling */
+ COLORREF colorref; /* COLORREF for transparent handling */
double alpha; /* Alpha transparency level 0.0 (fully
* transparent) .. 1.0 (opaque) */
@@ -2045,6 +2050,8 @@ TkWmNewWindow(
wmPtr->height = -1;
wmPtr->x = winPtr->changes.x;
wmPtr->y = winPtr->changes.y;
+ wmPtr->crefObj = NULL;
+ wmPtr->colorref = (COLORREF) NULL;
wmPtr->alpha = 1.0;
wmPtr->configWidth = -1;
@@ -2264,13 +2271,17 @@ UpdateWrapper(
*/
setLayeredWindowAttributesProc((HWND) wmPtr->wrapper,
- (COLORREF) NULL, (BYTE) (wmPtr->alpha * 255 + 0.5),
- LWA_ALPHA);
+ wmPtr->colorref, (BYTE) (wmPtr->alpha * 255 + 0.5),
+ LWA_ALPHA | (wmPtr->crefObj ? LWA_COLORKEY : 0));
} else {
/*
* Layering not used or supported.
*/
wmPtr->alpha = 1.0;
+ if (wmPtr->crefObj) {
+ Tcl_DecrRefCount(wmPtr->crefObj);
+ wmPtr->crefObj = NULL;
+ }
}
place.length = sizeof(WINDOWPLACEMENT);
@@ -2808,6 +2819,10 @@ TkWmDeadWindow(
WmWaitVisibilityOrMapProc, (ClientData) winPtr);
wmPtr->masterPtr = NULL;
}
+ if (wmPtr->crefObj != NULL) {
+ Tcl_DecrRefCount(wmPtr->crefObj);
+ wmPtr->crefObj = NULL;
+ }
/*
* Destroy the decorative frame window.
@@ -3140,6 +3155,7 @@ WmAttributesCmd(
Tcl_WrongNumArgs(interp, 2, objv,
"window"
" ?-alpha ?double??"
+ " ?-transparentcolor ?color??"
" ?-disabled ?bool??"
" ?-fullscreen ?bool??"
" ?-toolwindow ?bool??"
@@ -3154,6 +3170,10 @@ WmAttributesCmd(
Tcl_NewStringObj("-alpha", -1));
Tcl_ListObjAppendElement(NULL, objPtr, Tcl_NewDoubleObj(wmPtr->alpha));
Tcl_ListObjAppendElement(NULL, objPtr,
+ Tcl_NewStringObj("-transparentcolor", -1));
+ Tcl_ListObjAppendElement(NULL, objPtr,
+ wmPtr->crefObj ? wmPtr->crefObj : Tcl_NewObj());
+ Tcl_ListObjAppendElement(NULL, objPtr,
Tcl_NewStringObj("-disabled", -1));
Tcl_ListObjAppendElement(NULL, objPtr,
Tcl_NewBooleanObj((style & WS_DISABLED)));
@@ -3180,7 +3200,9 @@ WmAttributesCmd(
if (strncmp(string, "-disabled", length) == 0) {
stylePtr = &style;
styleBit = WS_DISABLED;
- } else if (strncmp(string, "-alpha", length) == 0) {
+ } else if ((strncmp(string, "-alpha", length) == 0)
+ || ((length > 2) && (strncmp(string, "-transparentcolor",
+ length) == 0))) {
stylePtr = &exStyle;
styleBit = WS_EX_LAYERED;
} else if (strncmp(string, "-fullscreen", length) == 0) {
@@ -3203,30 +3225,62 @@ WmAttributesCmd(
goto configArgs;
}
if (styleBit == WS_EX_LAYERED) {
- double dval;
-
if (objc == 4) {
- Tcl_SetDoubleObj(Tcl_GetObjResult(interp), wmPtr->alpha);
- } else {
- if ((i < objc-1) &&
- (Tcl_GetDoubleFromObj(interp, objv[i+1], &dval)
- != TCL_OK)) {
- return TCL_ERROR;
+ if (string[1] == 'a') { /* -alpha */
+ Tcl_SetObjResult(interp, Tcl_NewDoubleObj(wmPtr->alpha));
+ } else { /* -transparentcolor */
+ Tcl_SetObjResult(interp,
+ wmPtr->crefObj ? wmPtr->crefObj : Tcl_NewObj());
}
+ } else {
+ if (string[1] == 'a') { /* -alpha */
+ double dval;
- /*
- * The user should give (transparent) 0 .. 1.0 (opaque), but
- * we ignore the setting of this (it will always be 1) in the
- * case that the API is not available.
- */
+ if (Tcl_GetDoubleFromObj(interp, objv[i+1], &dval)
+ != TCL_OK) {
+ return TCL_ERROR;
+ }
- if (dval < 0.0) {
- dval = 0;
- } else if (dval > 1.0) {
- dval = 1;
+ /*
+ * The user should give (transparent) 0 .. 1.0 (opaque),
+ * but we ignore the setting of this (it will always be 1)
+ * in the case that the API is not available.
+ */
+ if (dval < 0.0) {
+ dval = 0;
+ } else if (dval > 1.0) {
+ dval = 1;
+ }
+ wmPtr->alpha = dval;
+ } else { /* -transparentcolor */
+ char *crefstr = Tcl_GetStringFromObj(objv[i+1], &length);
+
+ if (length == 0) {
+ /* reset to no transparent color */
+ if (wmPtr->crefObj) {
+ Tcl_DecrRefCount(wmPtr->crefObj);
+ wmPtr->crefObj = NULL;
+ }
+ } else {
+ XColor *cPtr =
+ Tk_GetColor(interp, tkwin, Tk_GetUid(crefstr));
+ if (cPtr == NULL) {
+ return TCL_ERROR;
+ }
+
+ if (wmPtr->crefObj) {
+ Tcl_DecrRefCount(wmPtr->crefObj);
+ }
+ wmPtr->crefObj = objv[i+1];
+ Tcl_IncrRefCount(wmPtr->crefObj);
+ wmPtr->colorref = RGB((BYTE) (cPtr->red >> 8),
+ (BYTE) (cPtr->green >> 8),
+ (BYTE) (cPtr->blue >> 8));
+ Tk_FreeColor(cPtr);
+ }
}
- wmPtr->alpha = dval;
- if (dval < 1.0) {
+
+ if ((wmPtr->alpha < 1.0) || (wmPtr->crefObj != NULL)) {
*stylePtr |= styleBit;
} else {
*stylePtr &= ~styleBit;
@@ -3237,12 +3291,11 @@ WmAttributesCmd(
* Set the window directly regardless of UpdateWrapper.
* The user supplies a double from [0..1], but Windows
* wants an int (transparent) 0..255 (opaque), so do the
- * translation. Add the 0.5 to round the value.
+ * translation. Add the 0.5 to round the value.
*/
-
setLayeredWindowAttributesProc((HWND) wmPtr->wrapper,
- (COLORREF) NULL, (BYTE) (wmPtr->alpha * 255 + 0.5),
- LWA_ALPHA);
+ wmPtr->colorref, (BYTE) (wmPtr->alpha * 255 + 0.5),
+ LWA_ALPHA | (wmPtr->crefObj ? LWA_COLORKEY : 0));
}
}
} else {