diff options
author | wordtech <wordtech> | 2011-01-04 22:36:58 (GMT) |
---|---|---|
committer | wordtech <wordtech> | 2011-01-04 22:36:58 (GMT) |
commit | 3c2ab580d7e8c701b9017fd96f5ca13b7f4276a2 (patch) | |
tree | 3425d75041cc0ce3130f13cc885d912ac3a2a764 | |
parent | cac9cbda71304b94b811f59ad1e287a27c5d021a (diff) | |
download | tk-3c2ab580d7e8c701b9017fd96f5ca13b7f4276a2.zip tk-3c2ab580d7e8c701b9017fd96f5ca13b7f4276a2.tar.gz tk-3c2ab580d7e8c701b9017fd96f5ca13b7f4276a2.tar.bz2 |
Textured background windows
-rw-r--r-- | macosx/README | 34 | ||||
-rw-r--r-- | macosx/tkMacOSXWindowEvent.c | 13 | ||||
-rw-r--r-- | macosx/tkMacOSXWm.c | 101 |
3 files changed, 142 insertions, 6 deletions
diff --git a/macosx/README b/macosx/README index b15dc0b..650fcef 100644 --- a/macosx/README +++ b/macosx/README @@ -1,7 +1,7 @@ Tcl/Tk Mac OS X README ---------------------- -RCS: @(#) $Id: README,v 1.30 2009/06/29 14:35:01 das Exp $ +RCS: @(#) $Id: README,v 1.31 2011/01/04 22:36:58 wordtech Exp $ This is the README file for the Mac OS X/Darwin version of Tcl/Tk. @@ -187,12 +187,42 @@ Window attribute names: verticalZoom, closeBox, collapseBox, toolbarButton, sideTitlebar, noTitleBar, unifiedTitleAndToolbar, metal, hud, noShadow, doesNotCycle, noActivates, hideOnSuspend, inWindowMenu, ignoreClicks, doesNotHide, - canJoinAllSpaces, moveToActiveSpace, nonActivating + canJoinAllSpaces, moveToActiveSpace, nonActivating, black, dark, light, + gray, red, green, blue, cyan, yellow, magenta, orange, purple, + brown, clear, opacity + Note that not all attributes are valid for all window classes. Support for the 3 argument form was added with the Cocoa-based Tk 8.6b2, at the same time support for some legacy Carbon-specific classes and attributes was removed (they are still accepted by the command but no longer have any effect). +The color window attributes (black, dark, red, etc.) and the "opacity" allow one to set the background and opacity of a textured ("metal") window. This allows a Tk window to implement a window without the dividing line between the titlebar and the rest of the window, or the "unified toolbar" effect, which is increasingly standard in Mac applications. An example: + +toplevel .f +tk::unsupported::MacWindowStyle style .f document {metal light opaque closeBox collapseBox resizable standardDocument } + +pack [label .f.f -bg #ababab -text "This is a textured window\nwith opacity and a gray background\nsimilar to other Mac applications"] -fill both -expand yes + +The color attributes correspond to system-defined NSColor constants (e.g., red is [NSColor redColor]. The "light" and "dark" attributes correspond to lightGrayColor and darkGrayColor, respectively (because of the way the attributes are parsed, using "lightgray" and "darkgray" would cause a conflict with the core "gray" attribute). + +Below are the corresponding hex and/or Tk-defined colors that can be used from Tk widgets to match the NSColor-based attributes: + +black #000000 +dark #545454 +light #ababab +white #ffffff +gray #7f7f7f +red #ff0000 +green #00ff00 +blue #0000ff +cyan #00ffff +yellow #ffff00 +magenta #ff00ff +orange #ff8000 +purple #800080 +brown #996633 +clear systemTransparent + - The Cocoa-based TkAqua can be distinguished from the older Carbon-based version via the [winfo server .] command, example output on Mac OS X 10.5.7: Cocoa-based: CG409.3 Apple AppKit GC 949.46 Mac OS X 1057 diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index 3e98ced..b17f97b 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWindowEvent.c,v 1.38 2009/08/24 00:55:08 das Exp $ + * RCS: @(#) $Id: tkMacOSXWindowEvent.c,v 1.39 2011/01/04 22:36:58 wordtech Exp $ */ #include "tkMacOSXPrivate.h" @@ -48,6 +48,8 @@ extern NSString *NSWindowDidOrderOffScreenNotification; #endif #endif +extern NSString *opaqueTag; + @implementation TKApplication(TKWindowEvent) - (void) windowActivation: (NSNotification *) notification @@ -924,8 +926,13 @@ ExposeRestrictProc( { NSWindow *w = [self window]; - return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) || - ![w isOpaque]) ? NO : YES); + if (opaqueTag != NULL) { + return YES; + } else { + + return (w && (([w styleMask] & NSTexturedBackgroundWindowMask) || + ![w isOpaque]) ? NO : YES); + } } - (BOOL) wantsDefaultClipping diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 44a64a3..fa1839f 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -9,11 +9,12 @@ * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright 2001-2009, Apple Inc. * Copyright (c) 2006-2009 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright (c) 2010 Kevin Walzer/WordTech Communications LLC. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWm.c,v 1.77 2009/08/14 14:51:02 das Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.78 2011/01/04 22:36:58 wordtech Exp $ */ #include "tkMacOSXPrivate.h" @@ -52,6 +53,11 @@ | tkCanJoinAllSpacesAttribute | tkMoveToActiveSpaceAttribute \ | tkNonactivatingPanelAttribute | tkHUDWindowAttribute) + +/*Objects for use in setting background color and opacity of window.*/ +NSColor *colorName = NULL; +NSString *opaqueTag = NULL; + static const struct { const UInt64 validAttrs, defaultAttrs, forceOnAttrs, forceOffAttrs; int flags; NSUInteger styleMask; @@ -4995,6 +5001,62 @@ TkUnsupported1ObjCmd( return TCL_ERROR; } + + /* Iterate through objc/objv to set correct background color and toggle opacity of window. */ + int i; + for (i= 0; i < objc; i++) { + + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*black*") == 1) { + colorName = [NSColor blackColor]; // use #000000 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*dark*") == 1) { + colorName = [NSColor darkGrayColor]; //use #545454 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*light*") == 1) { + colorName = [NSColor lightGrayColor]; //use #ababab in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*white*") == 1) { + colorName = [NSColor whiteColor]; //use #ffffff in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "gray*") == 1) { + colorName = [NSColor grayColor]; //use #7f7f7f in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*red*") == 1) { + colorName = [NSColor redColor]; //use #ff0000 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*green*") == 1) { + colorName = [NSColor greenColor]; //use #00ff00 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*blue*") == 1) { + colorName = [NSColor blueColor]; //use #0000ff in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*cyan*") == 1) { + colorName = [NSColor cyanColor]; //use #00ffff in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*yellow*") == 1) { + colorName = [NSColor yellowColor]; //use #ffff00 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*magenta*") == 1) { + colorName = [NSColor magentaColor]; //use #ff00ff in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*orange*") == 1) { + colorName = [NSColor orangeColor]; //use #ff8000 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*purple*") == 1) { + colorName = [NSColor purpleColor]; //use #800080 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*brown*") == 1){ + colorName = [NSColor brownColor]; //use #996633 in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*clear*") == 1) { + colorName = [NSColor clearColor]; //use systemTransparent in Tk scripts to match + } + if (Tcl_StringMatch(Tcl_GetString(objv[i]), "*opacity*") == 1) { + opaqueTag=@"YES"; + } + } + + winPtr = (TkWindow *) Tk_NameToWindow(interp, Tcl_GetString(objv[2]), tkwin); if (winPtr == NULL) { @@ -5077,6 +5139,9 @@ WmWinStyle( { "fullZoom", kWindowFullZoomAttribute }, { NULL } }; + + /* Map window attributes. Color and opacity are mapped to NULL; these are parsed from the objv in TkUnsupported1ObjCmd.*/ + static const struct StrIntMap attrMap[] = { { "closeBox", kWindowCloseBoxAttribute }, { "horizontalZoom", kWindowHorizontalZoomAttribute }, @@ -5106,8 +5171,24 @@ WmWinStyle( { "moveToActiveSpace", tkMoveToActiveSpaceAttribute }, { "nonActivating", tkNonactivatingPanelAttribute }, { "hud", tkHUDWindowAttribute }, + { "black", NULL }, + { "dark", NULL }, + { "light", NULL }, + { "gray", NULL }, + { "red", NULL }, + { "green", NULL }, + { "blue", NULL }, + { "cyan", NULL }, + { "yellow", NULL }, + { "magenta", NULL }, + { "orange", NULL }, + { "purple", NULL }, + { "brown", NULL }, + { "clear", NULL }, + { "opacity", NULL }, { NULL } }; + int index, i; WmInfo *wmPtr = winPtr->wmInfoPtr; @@ -5125,6 +5206,7 @@ WmWinStyle( Tcl_Panic("invalid class"); } + attributeList = Tcl_NewListObj(0, NULL); attributes = wmPtr->attributes; @@ -5186,14 +5268,18 @@ WmWinStyle( macClassAttrs[macClass].validAttrs); wmPtr->flags |= macClassAttrs[macClass].flags; wmPtr->macClass = macClass; + ApplyWindowAttributeFlagChanges(winPtr, NULL, oldAttributes, oldFlags, 0, 1); + return TCL_OK; badClassAttrs: wmPtr->attributes = oldAttributes; return TCL_ERROR; } + + return TCL_OK; } @@ -5350,6 +5436,17 @@ TkMacOSXMakeRealWindowExist( */ [window setMovableByWindowBackground:NO]; } + + + /* Set background color and opacity of window if those flags are set. */ + if (colorName != NULL) { + [window setBackgroundColor: colorName]; + } + + if (opaqueTag != NULL) { + [window setOpaque: opaqueTag]; + } + [window setDocumentEdited:NO]; wmPtr->window = window; macWin->view = contentView; @@ -6497,6 +6594,8 @@ RemapWindows( RemapWindows(childPtr, (MacDrawable *) winPtr->window); } } + + /* * Local Variables: |