diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/wm.n | 64 | ||||
-rw-r--r-- | tests/winWm.test | 27 | ||||
-rw-r--r-- | win/tkWinWm.c | 106 |
4 files changed, 154 insertions, 48 deletions
@@ -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-11-30 Daniel Steffen <das@users.sourceforge.net> * macosx/tkMacOSXDialog.c (Tk_MessageBoxObjCmd): fix inability to use @@ -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.11.2.4 2006/04/11 07:36:40 das Exp $ +'\" RCS: @(#) $Id: wm.n,v 1.11.2.5 2006/12/01 19:47:41 hobbs Exp $ '\" .so man.macros .TH wm n 8.4 Tk "Tk Built-In Commands" @@ -51,34 +51,58 @@ 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). -\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. +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). +.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. +.RE .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. -.PP -On Unix, there are currently no special attribute values. .RE +.PP +On X11, there are currently no special attribute values. .VE 8.4 .TP \fBwm client \fIwindow\fR ?\fIname\fR? diff --git a/tests/winWm.test b/tests/winWm.test index 250cf47..b422df3 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.9.2.3 2004/10/05 22:27:27 hobbs Exp $ +# RCS: @(#) $Id: winWm.test,v 1.9.2.4 2006/12/01 19:47:42 hobbs Exp $ package require tcltest 2.1 namespace import -force tcltest::configure @@ -232,7 +232,7 @@ test winWm-6.1 {wm attributes} win { destroy .t toplevel .t wm attributes .t -} {-alpha 1.0 -disabled 0 -toolwindow 0 -topmost 0} +} {-alpha 1.0 -transparentcolor {} -disabled 0 -toolwindow 0 -topmost 0} test winWm-6.2 {wm attributes} win { destroy .t toplevel .t @@ -243,7 +243,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?? ?-toolwindow ?bool?? ?-topmost ?bool??"}} +} {1 {wrong # args: should be "wm attributes window ?-alpha ?double?? ?-transparentcolor ?color?? ?-disabled ?bool?? ?-toolwindow ?bool?? ?-topmost ?bool??"}} test winWm-6.4 {wm attributes -alpha} win { # Expect this to return all 1.0 {} on pre-2K/XP @@ -288,6 +288,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} {pcOnly} { destroy .t diff --git a/win/tkWinWm.c b/win/tkWinWm.c index de4056a..3525b1a 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.54.2.25 2006/04/11 20:23:45 hobbs Exp $ + * RCS: @(#) $Id: tkWinWm.c,v 1.54.2.26 2006/12/01 19:47:42 hobbs Exp $ */ #include "tkWinInt.h" @@ -24,6 +24,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 @@ -238,6 +241,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) */ @@ -1910,6 +1915,8 @@ TkWmNewWindow(winPtr) 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; @@ -2109,13 +2116,17 @@ UpdateWrapper(winPtr) * 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 { /* * Layering not used or supported. */ wmPtr->alpha = 1.0; + if (wmPtr->crefObj) { + Tcl_DecrRefCount(wmPtr->crefObj); + wmPtr->crefObj = NULL; + } } place.length = sizeof(WINDOWPLACEMENT); @@ -2552,6 +2563,10 @@ TkWmDeadWindow(winPtr) WmWaitVisibilityOrMapProc, (ClientData) winPtr); wmPtr->masterPtr = NULL; } + if (wmPtr->crefObj != NULL) { + Tcl_DecrRefCount(wmPtr->crefObj); + wmPtr->crefObj = NULL; + } /* * Destroy the decorative frame window. @@ -2877,6 +2892,7 @@ WmAttributesCmd(tkwin, winPtr, interp, objc, objv) Tcl_WrongNumArgs(interp, 2, objv, "window" " ?-alpha ?double??" + " ?-transparentcolor ?color??" " ?-disabled ?bool??" " ?-toolwindow ?bool??" " ?-topmost ?bool??"); @@ -2890,6 +2906,10 @@ WmAttributesCmd(tkwin, winPtr, interp, objc, objv) 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))); @@ -2912,7 +2932,9 @@ WmAttributesCmd(tkwin, winPtr, interp, objc, objv) 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 ((length > 3) @@ -2933,28 +2955,62 @@ WmAttributesCmd(tkwin, winPtr, interp, objc, objv) 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()); } - /* - * 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; + } else { + if (string[1] == 'a') { /* -alpha */ + double dval; + + if (Tcl_GetDoubleFromObj(interp, objv[i+1], &dval) + != TCL_OK) { + return TCL_ERROR; + } + + /* + * 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; @@ -2968,8 +3024,8 @@ WmAttributesCmd(tkwin, winPtr, interp, objc, objv) * 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 { |