Index: ChangeLog =================================================================== RCS file: /cvsroot/tktoolkit/tk/ChangeLog,v retrieving revision 1.1590 diff -u -p -r1.1590 ChangeLog --- ChangeLog 9 Mar 2007 00:46:15 -0000 1.1590 +++ ChangeLog 15 Mar 2007 02:42:00 -0000 @@ -1,3 +1,286 @@ +2007-03-15 Daniel Steffen + + * generic/tkCanvText.c: add fallback to fgColor when selFgColor is None + * generic/tkEntry.c: (new default on aqua to match native L&F). + * generic/tkListbox.c: + + * generic/tkCanvas.c: add support for bypassing all of Tk's double + * generic/tkEntry.c: buffered drawing into intermediate pixmaps + * generic/tkFrame.c: (via TK_NO_DOUBLE_BUFFERING #define), it is + * generic/tkListbox.c: unnecessary & wasteful on aqua where all + * generic/tkPanedWindow.c: drawing is already double-buffered by the + * generic/tkTextDisp.c: window server. (Use of this on other + * generic/ttk/ttkWidget.c: platforms would only require implementation + * macosx/tkMacOSXPort.h: of TkpClipDrawableToRect()). + * unix/tkUnixScale.c: + + * library/bgerror.tcl: on aqua, use moveable alert resp. modal dialog + * library/dialog.tcl: window class and corresponding system + background pattern; fix button padding. + + * library/tearoff.tcl: correct aqua menu bar height. + * library/tk.tcl: + + * library/demos/goldberg.tcl: fix overwriting of widget demo global. + + * library/demos/menu.tcl: on aqua, use custom MDEF and tearoffs; + * library/demos/menubu.tcl: correct menubutton toplevel name. + + * library/demos/puzzle.tcl: fix button size & padding for aqua. + * library/demos/radio.tcl: + + * macosx/tkMacOSXCarbonEvents.c: add window event target carbon event + * macosx/tkMacOSXEvent.c: handler for all kEventClassWindow and + * macosx/tkMacOSXEvent.h: kEventClassMouse events; handle + * macosx/tkMacOSXNotify.c: additional menu carbon events to + * macosx/tkMacOSXWindowEvent.c: support <> in menus that + are not using the custom MDEF [Bug 1620826], and to clear the current + Tk active menu entry upon carbon menu opening; move all remaining + events except for kEventClassKeyboard from dispatcher to application + event handler; pass event handler callRef downstream; fix debug event + tracing for Tiger; process all tcl event types in carbon event timer; + delay carbon event timer first fire; add TkMacOSXTrackingLoop() to mark + enter/exit of event tracking loop during which all tcl events but only + carbon update events should be processed by the timer (replaces various + calls to Tcl_SetServiceMode()); rename TkMacOSXReceiveAndProcessEvent() + to TkMacOSXReceiveAndDispatchEvent(), move it from tkMacOSXEvent.c to + tkMacOSXCarbonEvents.c and modify it to dequeue only update events + during a tracking loop; add TkMacOSXRunTclEventLoop() to standardize + the various ways in use to run the tcl event loop; add handling of + kEventClassAppearance events (for ScrollBarVariantChanged event). + + * macosx/tkMacOSXDialog.c: use new TkMacOSXTrackingLoop() around + * macosx/tkMacOSXEvent.c: blocking API that puts up modal dialogs + * macosx/tkMacOSXMenu.c: or when entering/exiting menu/control + * macosx/tkMacOSXMouseEvent.c: tracking, window dragging and other + * macosx/tkMacOSXScale.c: mouse tracking loops. + * macosx/tkMacOSXScrlbr.c: + * macosx/tkMacOSXWindowEvent.c: + * macosx/tkMacOSXWm.c: + + * macosx/tkMacOSXDialog.c: use new TkMacOSXRunTclEventLoop() + * macosx/tkMacOSXScale.c: instead of Tcl_DoOneEvent(), + * macosx/tkMacOSXScrlbr.c: Tcl_ServiceAll(), TclServiceIdle() + * macosx/tkMacOSXWindowEvent.c: and Tcl_GlobalEval("update idletasks"). + + * macosx/tkMacOSXColor.c: make available as Tk system colors all + * macosx/tkMacOSXPort.h: appearance manager brushes, text colors and + backgrounds with new and legacy names, as well as the fully transparent + color "systemTransparent"; add TkMacOSXSetColorIn{Port,Context}() to + directly set an X pixel color value in the current QD port resp. the + given CG context without requiring passage through rgb representation + (lossy for most system colors); modernize/remove Classic-era code; + replace crufty strcmp() elseifs by Tcl_GetIndexFromObjStruct(). + + * macosx/tkMacOSXButton.c: use new TkMacOSXSetColorInPort() + * macosx/tkMacOSXDraw.c: instead of setting rgb color directly + * macosx/tkMacOSXMenubutton.c: to allow for non-rgb system colors. + + * macosx/tkMacOSXCursor.c: implement "none" cursor as on other + platforms [Patch 1615427]; add all missing appearance manager cursors. + + * macosx/tkMacOSXDefault.h: set SELECT_FG_COLORs to None to match aqua + L&F; use standard system color names; use new 'menu' system font; + correct default scrollbar width. + + * macosx/tkMacOSXDraw.c: standardize initialization, use and + * macosx/tkMacOSXInt.h: emptying of various static temp rgns + * macosx/tkMacOSXRegion.c: onto two global RgnHandles; in debug + * macosx/tkMacOSXSubwindows.c: builds, verify emptiness of these temp + * macosx/tkMacOSXWindowEvent.c: rgns before use. + + * macosx/tkMacOSXDraw.c: add TkMacOSX{Setup,Restore}DrawingContext() to + * macosx/tkMacOSXInt.h: abstract common setup & teardown of drawing + environment (for both CG and QD); save/restore QD theme drawing state; + handle GC clip region; add TkpClipDrawableToRect() to allow clipped + drawing into drawable regardless of GC used; use new system color + "systemWindowHeaderBackground" to setup background in themed toplevels. + + * macosx/tkMacOSXEntry.c: use new TkMacOSXSetupDrawingContext() and + * macosx/tkMacOSXFont.c: TkMacOSXRestoreDrawingContext() instead of + * macosx/ttkMacOSXTheme.c: various setup/teardown procs like + TkMacOSX{SetUp,Release}CGContext(), TkMacOSXQuarz{Start,End}Draw(), + TkMacOSXSetUpGraphicsPort() etc. + + * macosx/tkMacOSXEmbed.c: add CG context and drawable clip rgn fields + * macosx/tkMacOSXInt.h: to MacDrawable struct. + * macosx/tkMacOSXSubwindows.c: + + * macosx/tkMacOSXDialog.c: make -parent option of tk_getOpenFile et al. + use the sheet version of NavServices dialogs; ensure native parent win + exists before using StandardSheet API for tk_messageBox [Bug 1677611]; + force sheets to behave like app-modal dialogs via WindowModality() API; + use more modern ColorPicker API. + + * macosx/tkAboutDlg.r: use themed movable modal dialog, fix (c) year. + + * macosx/tkMacOSXEntry.c: take xOff/yOff of MacDrawable into account + * macosx/ttkMacOSXTheme.c: when computing locations/bounds to ensure + correct posititioning when not drawing into intermediate pixmap. + + * macosx/tkMacOSXFont.c: use appearance manager API to map system font + * macosx/tkMacOSXFont.h: names to TkFonts; add "menu" system font for + menu item text drawing from MDEF; always draw with CG; remove QD + dependent stippling algorithm; move most header declarations into the + source file (as they were not used anywhere else). + + * macosx/tkMacOSXMenu.c: complete rewrite of custom MDEF. + + * macosx/tkMacOSXMouseEvent.c: add support for async window dragging by + the window server and make it the default. + + * macosx/tkMacOSXMouseEvent.c: rationalized handling order of + non-mousedown events; add TkMacOSXModifierState() to retrieve the + current key modifiers in carbon format. + + * macosx/tkMacOSXScrlbr.c: use appearance manager API to retrieve + scrollbar component metrics; add awareness of multiple possibilites for + scrollbar arrow position in aqua and handle user changes to arrow + position pref; handle difference in metrics of small & large scrollbar + variants; handle aqua "jump to here" scrollbar behaviour; correct + computation of scroll view size and position; enforce min scrollbar + height to avoid scrollbar component overlap; erase scrollbar area + outside of standard width; remove broken auto-adjust code; account for + window class when leaving space for grow box; remove code to manually + draw grow box; use modern API for thumb scroll proc; replace + HiliteControl() by modern API; replace control mgr constants with + appearance mgr equivalents. + + * macosx/tkMacOSXSubwindows.c: use SetWindowBounds() API instead of + SizeWindow(); remove unnecessary calls to TkMacOSXInvalClipRgns() and + unnecessary setting of QD port; use native-endian pixmap on intel; + remove obsolete pixmap pixel locking. + + * macosx/tkMacOSXWindowEvent.c: handle only the first of a batch of + kEventAppAvailableWindowBoundsChanged events sent per transaction; + handle kEventWindowBoundsChanged event to support live window resizing + and centralized sending of location/size changed ConfigureNotify + events; ensure HIGrowBox is redrawn after bounds change; constrain + window after dragging to ensure titlebar is not inacessible + offscreen or under dock/menubar; handle kEventWindowGetRegion and + kEventWindowDrawContent for transparent windows to mark resp. paint + content region as transparent; handle kEventWindowConstrain for + fullscreen windows to ensure bounds match new screen size; enter/exit + fullscreen UIMode upon activation/deactivation of fullscreen window. + + * macosx/tkMacOSXWm.c: use live-resize and async-drag carbon window + * macosx/tkMacOSXWm.h: attributes for toplevels by default; implement + new [wm attributes] -topmost, -transparent and -fullscreen; refactor + WmAttributesCmd() parallelling the tkUnixWm.c implementation, use thus + factored proc to set proxy icon from [wm iconbitmap]; dynamically + determine default values for toplevel min and max sizes (similar to + tkWinWm.c impl): min sizes depend on window class & attributes to + ensure visibility of all titlebar widgets and grow box, max sizes + depend on maximal window bounds for all active displays; factor out + code that puts into effect changes to master or override_redirect; use + RepositionWindow() API to determine staggered initial window bounds; + correct resize limit calculations, handle gridding and use modern + resize API in TkMacOSXGrowToplevel(); remove sending of ConfigureNotify + after resize or zoom (now handled by BoundsChanged handler); correct + composite carbon window attribute handling, remove currently unusable + attributes and add new attributes in [tk::unsupported::MacWindowStyle]; + ensure validity of window class and attributes before use; apply + changes to window class when handling carbon window attribute changes + (if HIWindowChangeClass() API available); add debug build warning + message when deprecated window style is used instead of window class; + use transparent HIGrowBox for resizable windows; avoid unnecessary + calls to window structure width API; use tcl time API in TkpGetMS(); + add TkMacOSXEnterExitFullscreen() to enter/exit UIMode with dock and + menubar hidden; restrict wmTracing output to debug builds; remove + unnecessary calls to TkMacOSXInvalClipRgns() and unnecessary setting of + QD port. + + * macosx/tkMacOSXXStubs.c (TkMacOSXDisplayChanged): add maximal window + bounds field to Screen record (in ext_data), computed as the union of + available window positioning bounds of all graphics devices (displays). + + * macosx/tkMacOSXBitmap.c: fix macRoman encoding leak. + * macosx/tkMacOSXCursor.c: + + * macosx/tkMacOSXDebug.c (TkMacOSXCarbonEventToAscii): use static + * macosx/tkMacOSXDebug.h: buffer to simplify callers; const fixes. + + * macosx/tkMacOSXBitmap.c: use more efficient QDSwapPort() instead of + * macosx/tkMacOSXButton.c: GetPort()/SetPort()/GetGWorld()/SetGWorld(). + * macosx/tkMacOSXDraw.c: + * macosx/tkMacOSXMenubutton.c: + * macosx/tkMacOSXScale.c: + * macosx/tkMacOSXScrlbr.c: + * macosx/tkMacOSXXStubs.c: + + * macosx/tkMacOSXColor.c: use kHIToolboxVersionNumber for runtime OS + * macosx/tkMacOSXEntry.c: version check rather than Gestalt() etc. + * macosx/tkMacOSXInt.h: + * macosx/tkMacOSXWm.c: + + * macosx/tkMacOSXDraw.c: remove obsolete and now incorrect + * macosx/tkMacOSXInt.h: tkMenuCascadeRgn clipping code. + * macosx/tkMacOSXMenu.c: + + * macosx/tkMacOSXHLEvents.c: replace Tcl_GlobalEval() by Tcl_EvalEx(). + * macosx/tkMacOSXScrlbr.c: + + * macosx/tkMacOSXInit.c (TkpInit): reorder initialization steps. + + * macosx/tkMacOSXKeyEvent.c: remove pre-10.2 support code. + + * macosx/tkMacOSXMenus.c: remove now useless call to + TkMacOSXHandleTearoffMenu(). + + * macosx/tkMacOSXScale.c: replace TrackControl() by modern + * macosx/tkMacOSXScrlbr.c: HandleControlClick() API (using new + TkMacOSXModifierState()). + + * macosx/tkMacOSXSend.c: remove duplicate/unused declarations. + * macosx/tkMacOSXXStubs.c: + + * macosx/Wish-Common.xcconfig: enable more warnings. + + * macosx/tkMacOSXDebug.c: const fixes. + * macosx/tkMacOSXInit.c: + * macosx/tkMacOSXWm.c: + * macosx/tkMacOSXXStubs.c: + + * macosx/tkMacOSXInt.h: move all constant #defines needed to + * macosx/tkMacOSXColor.c: support building on older OS X releases + * macosx/tkMacOSXEvent.h: to a central location in tkMacOSXInt.h. + * macosx/tkMacOSXMenu.c: + * macosx/tkMacOSXMenubutton.c: + * macosx/tkMacOSXMenus.c: + * macosx/tkMacOSXMouseEvent.c: + * macosx/tkMacOSXWm.c: + * macosx/ttkMacOSXTheme.c: + + * macosx/tkMacOSXInt.h: add ChkErr() macro to factor out + * macosx/tkMacOSXButton.c: Carbon OSStatus return value checking + * macosx/tkMacOSXCarbonEvents.c: and TkMacOSXDbgMsg() macro to factour + * macosx/tkMacOSXClipboard.c: out debug message output; use these + * macosx/tkMacOSXColor.c: macros to replace #ifdef TK_MAC_DEBUG + * macosx/tkMacOSXCursor.c: blocks & direct printing to stderr, + * macosx/tkMacOSXDebug.c: and to do additional OSStatus return + * macosx/tkMacOSXDialog.c: checking, and to standardize OSStatus + * macosx/tkMacOSXDraw.c: usage. + * macosx/tkMacOSXEntry.c: + * macosx/tkMacOSXEvent.c: + * macosx/tkMacOSXFont.c: + * macosx/tkMacOSXHLEvents.c: + * macosx/tkMacOSXInit.c: + * macosx/tkMacOSXKeyEvent.c: + * macosx/tkMacOSXMenu.c: + * macosx/tkMacOSXMenubutton.c: + * macosx/tkMacOSXMenus.c: + * macosx/tkMacOSXMouseEvent.c: + * macosx/tkMacOSXScrlbr.c: + * macosx/tkMacOSXSubwindows.c: + * macosx/tkMacOSXWindowEvent.c: + * macosx/tkMacOSXWm.c: + * macosx/tkMacOSXXStubs.c: + + * doc/colors.n: document new Mac OS X system colors. + * doc/cursors.n: document new Mac OS X native cursors. + * doc/font.n: document new Mac OS X 'menu' system font. + * doc/wm.n: document new Mac OS X [wm attributes]. + 2007-03-08 Joe English * tests/grid.test(grid-21.7): Reset wm geometry . and pack propagate . Index: doc/colors.n =================================================================== RCS file: /cvsroot/tktoolkit/tk/doc/colors.n,v retrieving revision 1.5 diff -u -p -r1.5 colors.n --- doc/colors.n 16 Nov 2006 13:50:17 -0000 1.5 +++ doc/colors.n 15 Mar 2007 02:42:01 -0000 @@ -1,6 +1,7 @@ '\" '\" Copyright (c) 1998-2000 by Scriptics Corporation. '\" Copyright (c) 2003 ActiveState Corporation. +'\" Copyright (c) 2006-2007 Daniel A. Steffen '\" '\" RCS: @(#) $Id: colors.n,v 1.5 2006/11/16 13:50:17 dkf Exp $ '\" @@ -778,6 +779,153 @@ yellow3 205 205 yellow4 139 139 0 YellowGreen 154 205 50 .CE + +.SH "PORTABILITY ISSUES" + +.TP +\fBMac OS X\fR +On Mac OS X, the following additional system colors are available +(note that the actual color values depend on the currently active OS theme, +and typically many of these will in fact be patterns rather than pure colors): +.RS +.CS +systemTransparent +systemBlack +systemWhite +systemHighlight +systemPrimaryHighlightColor +systemHighlightSecondary +systemSecondaryHighlightColor +systemHighlightAlternate +systemAlternatePrimaryHighlightColor +systemHighlightText +systemDialogBackgroundActive +systemDialogBackgroundInactive +systemAlertBackgroundActive +systemAlertBackgroundInactive +systemModelessDialogBackgroundActive +systemModelessDialogBackgroundInactive +systemUtilityWindowBackgroundActive +systemUtilityWindowBackgroundInactive +systemListViewSortColumnBackground +systemListViewBackground +systemIconLabelBackground +systemListViewSeparator +systemChasingArrows +systemDragHilite +systemWindowBody +systemDocumentWindowBackground +systemFinderWindowBackground +systemScrollBarDelimiterActive +systemScrollBarDelimiterInactive +systemFocusHighlight +systemPopupArrowActive +systemPopupArrowPressed +systemPopupArrowInactive +systemAppleGuideCoachmark +systemIconLabelBackgroundSelected +systemStaticAreaFill +systemActiveAreaFill +systemButtonFrame +systemButtonFrameActive +systemButtonFrameInactive +systemButtonFace +systemButtonFaceActive +systemButtonFaceInactive +systemButtonFacePressed +systemButtonActiveDarkShadow +systemButtonActiveDarkHighlight +systemButtonActiveLightShadow +systemButtonActiveLightHighlight +systemButtonInactiveDarkShadow +systemButtonInactiveDarkHighlight +systemButtonInactiveLightShadow +systemButtonInactiveLightHighlight +systemButtonPressedDarkShadow +systemButtonPressedDarkHighlight +systemButtonPressedLightShadow +systemButtonPressedLightHighlight +systemBevelActiveLight +systemBevelActiveDark +systemBevelInactiveLight +systemBevelInactiveDark +systemNotificationWindowBackground +systemMovableModalBackground +systemSheetBackground +systemSheetBackgroundOpaque +systemDrawerBackground +systemToolbarBackground +systemSheetBackgroundTransparent +systemMenu +systemMenuBackground +systemMenuActive +systemMenuBackgroundSelected +systemListViewOddRowBackground +systemListViewEvenRowBackground +systemListViewColumnDivider +systemTabPaneBackground +systemPlacardBackground +systemWindowHeaderBackground +systemListViewWindowHeaderBackground +systemSecondaryGroupBoxBackground +systemMetalBackground +systemBlackText +systemWhiteText +systemDialogActiveText +systemDialogInactiveText +systemAlertActiveText +systemAlertInactiveText +systemModelessDialogActiveText +systemModelessDialogInactiveText +systemWindowHeaderActiveText +systemWindowHeaderInactiveText +systemPlacardActiveText +systemPlacardInactiveText +systemPlacardPressedText +systemButtonText +systemPushButtonActiveText +systemPushButtonInactiveText +systemPushButtonPressedText +systemBevelButtonActiveText +systemBevelButtonInactiveText +systemBevelButtonPressedText +systemPopupButtonActiveText +systemPopupButtonInactiveText +systemPopupButtonPressedText +systemIconLabelText +systemListViewText +systemDocumentWindowTitleActiveText +systemDocumentWindowTitleInactiveText +systemMovableModalWindowTitleActiveText +systemMovableModalWindowTitleInactiveText +systemUtilityWindowTitleActiveText +systemUtilityWindowTitleInactiveText +systemPopupWindowTitleActiveText +systemPopupWindowTitleInactiveText +systemRootMenuActiveText +systemRootMenuSelectedText +systemRootMenuDisabledText +systemMenuText +systemMenuItemActiveText +systemMenuActiveText +systemMenuItemSelectedText +systemMenuDisabled +systemMenuItemDisabledText +systemPopupLabelActiveText +systemPopupLabelInactiveText +systemTabFrontActiveText +systemTabNonFrontActiveText +systemTabNonFrontPressedText +systemTabFrontInactiveText +systemTabNonFrontInactiveText +systemIconLabelSelectedText +systemBevelButtonStickyActiveText +systemBevelButtonStickyInactiveText +systemNotificationText +systemSystemDetailText +.CE +.RE + .SH "SEE ALSO" options(n), Tk_GetColor(3) .SH KEYWORDS Index: doc/cursors.n =================================================================== RCS file: /cvsroot/tktoolkit/tk/doc/cursors.n,v retrieving revision 1.4 diff -u -p -r1.4 cursors.n --- doc/cursors.n 17 Dec 2006 00:43:06 -0000 1.4 +++ doc/cursors.n 15 Mar 2007 02:42:01 -0000 @@ -2,6 +2,8 @@ '\" Copyright (c) 1998-2000 by Scriptics Corporation. '\" All rights reserved. '\" +'\" Copyright (c) 2006-2007 Daniel A. Steffen +'\" '\" RCS: @(#) $Id: cursors.n,v 1.4 2006/12/17 00:43:06 mdejong Exp $ '\" '\" @@ -135,8 +137,8 @@ wait .RE .TP -\fBMacintosh\fR -On Macintosh systems, the following cursors are mapped to native cursors: +\fBMac OS X\fR +On Mac OS X systems, the following cursors are mapped to native cursors: .RS .CS arrow @@ -148,10 +150,28 @@ plus watch xterm .CE -And the following additional cursors are available: +And the following additional native cursors are available: .CS +copyarrow +aliasarrow +contextualmenuarrow text cross-hair +closedhand +openhand +pointinghand +resizeleft +resizeright +resizeleftright +resizeup +resizedown +resizeupdown +notallowed +poof +countinguphand +countingdownhand +countingupanddownhand +spinning .CE .RE Index: doc/font.n =================================================================== RCS file: /cvsroot/tktoolkit/tk/doc/font.n,v retrieving revision 1.9 diff -u -p -r1.9 font.n --- doc/font.n 1 Dec 2006 20:14:23 -0000 1.9 +++ doc/font.n 15 Mar 2007 02:42:01 -0000 @@ -1,5 +1,6 @@ '\" '\" Copyright (c) 1996 Sun Microsystems, Inc. +'\" Copyright (c) 2006-2007 Daniel A. Steffen '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -274,10 +275,10 @@ MS Windows: systemfixed ansifixed oemfixed\fR .DE .TP -Macintosh: +Mac OS X: .DS .ta 3c 6c -\fBsystem application\fR +\fBsystem application menu\fR .DE .RE .SH EXAMPLE Index: doc/wm.n =================================================================== RCS file: /cvsroot/tktoolkit/tk/doc/wm.n,v retrieving revision 1.28 diff -u -p -r1.28 wm.n --- doc/wm.n 1 Dec 2006 19:48:00 -0000 1.28 +++ doc/wm.n 15 Mar 2007 02:42:01 -0000 @@ -105,6 +105,18 @@ can be dragged and dropped in lieu of th 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. +.TP +\fB\-topmost\fR +Specifies whether this is a topmost window (displays above all other windows). +.TP +\fB\-transparent\fR +Makes the window content area transparent and turns off the window shadow. For +the transparency to be effecive, the toplevel background needs to be set to a +color with some alpha, e.g. "systemTransparent". +.TP +\fB\-fullscreen\fR +Places the window in a mode that takes up the entire main screen and hides +the dock and menu bar. .RE .PP On X11, the following attributes may be set. Index: generic/tkCanvText.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkCanvText.c,v retrieving revision 1.23 diff -u -p -r1.23 tkCanvText.c --- generic/tkCanvText.c 13 Feb 2007 11:29:17 -0000 1.23 +++ generic/tkCanvText.c 15 Mar 2007 02:42:01 -0000 @@ -465,7 +465,9 @@ ConfigureText( gcValues.fill_style = FillStippled; mask |= GCStipple|GCFillStyle; } - gcValues.foreground = textInfoPtr->selFgColorPtr->pixel; + if (textInfoPtr->selFgColorPtr != NULL) { + gcValues.foreground = textInfoPtr->selFgColorPtr->pixel; + } newSelGC = Tk_GetGC(tkwin, mask|GCForeground, &gcValues); } if (textPtr->gc != None) { Index: generic/tkCanvas.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkCanvas.c,v retrieving revision 1.40 diff -u -p -r1.40 tkCanvas.c --- generic/tkCanvas.c 27 Nov 2005 02:36:13 -0000 1.40 +++ generic/tkCanvas.c 15 Mar 2007 02:42:02 -0000 @@ -21,6 +21,11 @@ #include "tkInt.h" #include "tkPort.h" #include "tkCanvas.h" +#ifdef TK_NO_DOUBLE_BUFFERING +#ifdef MAC_OSX_TK +#include "tkMacOSXInt.h" +#endif +#endif /* * See tkCanvas.h for key data structures used to implement canvases. @@ -2132,6 +2137,10 @@ DisplayCanvas( goto borders; } + width = screenX2 - screenX1; + height = screenY2 - screenY1; + +#ifndef TK_NO_DOUBLE_BUFFERING /* * Redrawing is done in a temporary pixmap that is allocated here and * freed at the end of the function. All drawing is done to the @@ -2166,14 +2175,19 @@ DisplayCanvas( (screenX2 + 30 - canvasPtr->drawableXOrigin), (screenY2 + 30 - canvasPtr->drawableYOrigin), Tk_Depth(tkwin)); +#else + canvasPtr->drawableXOrigin = canvasPtr->xOrigin; + canvasPtr->drawableYOrigin = canvasPtr->yOrigin; + pixmap = Tk_WindowId(tkwin); + TkpClipDrawableToRect(Tk_Display(tkwin), pixmap, + screenX1 - canvasPtr->xOrigin, screenY1 - canvasPtr->yOrigin, + width, height); +#endif /* * Clear the area to be redrawn. */ - width = screenX2 - screenX1; - height = screenY2 - screenY1; - XFillRectangle(Tk_Display(tkwin), pixmap, canvasPtr->pixmapGC, screenX1 - canvasPtr->drawableXOrigin, screenY1 - canvasPtr->drawableYOrigin, (unsigned int) width, @@ -2211,6 +2225,7 @@ DisplayCanvas( height); } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Copy from the temporary pixmap to the screen, then free up the * temporary pixmap. @@ -2220,10 +2235,13 @@ DisplayCanvas( canvasPtr->pixmapGC, screenX1 - canvasPtr->drawableXOrigin, screenY1 - canvasPtr->drawableYOrigin, - (unsigned) (screenX2 - screenX1), - (unsigned) (screenY2 - screenY1), + (unsigned int) width, + (unsigned int) height, screenX1 - canvasPtr->xOrigin, screenY1 - canvasPtr->yOrigin); Tk_FreePixmap(Tk_Display(tkwin), pixmap); +#else + TkpClipDrawableToRect(Tk_Display(tkwin), pixmap, 0, 0, -1, -1); +#endif } /* Index: generic/tkEntry.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkEntry.c,v retrieving revision 1.42 diff -u -p -r1.42 tkEntry.c --- generic/tkEntry.c 3 Jan 2007 05:06:26 -0000 1.42 +++ generic/tkEntry.c 15 Mar 2007 02:42:03 -0000 @@ -1449,7 +1449,9 @@ EntryWorldChanged( } entryPtr->textGC = gc; - gcValues.foreground = entryPtr->selFgColorPtr->pixel; + if (entryPtr->selFgColorPtr != NULL) { + gcValues.foreground = entryPtr->selFgColorPtr->pixel; + } gcValues.font = Tk_FontId(entryPtr->tkfont); mask = GCForeground | GCFont; gc = Tk_GetGC(entryPtr->tkwin, mask, &gcValues); @@ -1583,6 +1585,7 @@ DisplayEntry( Tcl_Release((ClientData) entryPtr); } +#ifndef TK_NO_DOUBLE_BUFFERING /* * In order to avoid screen flashes, this function redraws the textual * area of the entry into off-screen memory, then copies it back on-screen @@ -1592,6 +1595,9 @@ DisplayEntry( pixmap = Tk_GetPixmap(entryPtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); +#else + pixmap = Tk_WindowId(tkwin); +#endif /* * Compute x-coordinate of the pixel just after last visible one, plus @@ -1827,6 +1833,7 @@ DisplayEntry( } } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Everything's been redisplayed; now copy the pixmap onto the screen and * free up the pixmap. @@ -1836,6 +1843,7 @@ DisplayEntry( 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(entryPtr->display, pixmap); +#endif entryPtr->flags &= ~BORDER_NEEDED; } Index: generic/tkFrame.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkFrame.c,v retrieving revision 1.27 diff -u -p -r1.27 tkFrame.c --- generic/tkFrame.c 28 Feb 2007 04:58:24 -0000 1.27 +++ generic/tkFrame.c 15 Mar 2007 02:42:06 -0000 @@ -1427,6 +1427,7 @@ DisplayFrame( goto noLabel; } +#ifndef TK_NO_DOUBLE_BUFFERING /* * In order to avoid screen flashes, this function redraws the frame * into off-screen memory, then copies it back on-screen in a single @@ -1436,6 +1437,9 @@ DisplayFrame( pixmap = Tk_GetPixmap(framePtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); +#else + pixmap = Tk_WindowId(tkwin); +#endif /* * Clear the pixmap. @@ -1549,6 +1553,7 @@ DisplayFrame( } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Everything's been redisplayed; now copy the pixmap onto the screen * and free up the pixmap. @@ -1560,6 +1565,7 @@ DisplayFrame( (unsigned) (Tk_Height(tkwin) - 2 * hlWidth), hlWidth, hlWidth); Tk_FreePixmap(framePtr->display, pixmap); +#endif } } Index: generic/tkListbox.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkListbox.c,v retrieving revision 1.38 diff -u -p -r1.38 tkListbox.c --- generic/tkListbox.c 12 Jan 2007 10:41:23 -0000 1.38 +++ generic/tkListbox.c 15 Mar 2007 02:42:07 -0000 @@ -1777,7 +1777,9 @@ ListboxWorldChanged(instanceData) } listPtr->textGC = gc; - gcValues.foreground = listPtr->selFgColorPtr->pixel; + if (listPtr->selFgColorPtr != NULL) { + gcValues.foreground = listPtr->selFgColorPtr->pixel; + } gcValues.font = Tk_FontId(listPtr->tkfont); mask = GCForeground | GCFont; gc = Tk_GetGC(listPtr->tkwin, mask, &gcValues); @@ -1863,6 +1865,7 @@ DisplayListbox(clientData) listPtr->flags &= ~(REDRAW_PENDING|UPDATE_V_SCROLLBAR|UPDATE_H_SCROLLBAR); Tcl_Release((ClientData) listPtr); +#ifndef TK_NO_DOUBLE_BUFFERING /* * Redrawing is done in a temporary pixmap that is allocated here and * freed at the end of the procedure. All drawing is done to the pixmap, @@ -1873,6 +1876,9 @@ DisplayListbox(clientData) pixmap = Tk_GetPixmap(listPtr->display, Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); +#else + pixmap = Tk_WindowId(tkwin); +#endif Tk_Fill3DRectangle(tkwin, pixmap, listPtr->normalBorder, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT); @@ -1937,7 +1943,11 @@ DisplayListbox(clientData) * Default GC has the values from the widget at large. */ - gcValues.foreground = listPtr->selFgColorPtr->pixel; + if (listPtr->selFgColorPtr) { + gcValues.foreground = listPtr->selFgColorPtr->pixel; + } else { + gcValues.foreground = listPtr->fgColorPtr->pixel; + } gcValues.font = Tk_FontId(listPtr->tkfont); gcValues.graphics_exposures = False; mask = GCForeground | GCFont | GCGraphicsExposures; @@ -2154,10 +2164,12 @@ DisplayListbox(clientData) listPtr->highlightWidth, pixmap); } } +#ifndef TK_NO_DOUBLE_BUFFERING XCopyArea(listPtr->display, pixmap, Tk_WindowId(tkwin), listPtr->textGC, 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(listPtr->display, pixmap); +#endif } /* Index: generic/tkPanedWindow.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkPanedWindow.c,v retrieving revision 1.27 diff -u -p -r1.27 tkPanedWindow.c --- generic/tkPanedWindow.c 5 Jan 2007 00:00:50 -0000 1.27 +++ generic/tkPanedWindow.c 15 Mar 2007 02:42:07 -0000 @@ -1419,12 +1419,16 @@ DisplayPanedWindow( ArrangePanes(clientData); } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Create a pixmap for double-buffering, if necessary. */ pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); +#else + pixmap = Tk_WindowId(tkwin); +#endif /* * Redraw the widget's background and border. @@ -1467,6 +1471,7 @@ DisplayPanedWindow( } } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Copy the information from the off-screen pixmap onto the screen, then * delete the pixmap. @@ -1475,6 +1480,7 @@ DisplayPanedWindow( XCopyArea(Tk_Display(tkwin), pixmap, Tk_WindowId(tkwin), pwPtr->gc, 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(Tk_Display(tkwin), pixmap); +#endif } /* @@ -2699,12 +2705,16 @@ DisplayProxyWindow( return; } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Create a pixmap for double-buffering, if necessary. */ pixmap = Tk_GetPixmap(Tk_Display(tkwin), Tk_WindowId(tkwin), Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); +#else + pixmap = Tk_WindowId(tkwin); +#endif /* * Redraw the widget's background and border. @@ -2713,6 +2723,7 @@ DisplayProxyWindow( Tk_Fill3DRectangle(tkwin, pixmap, pwPtr->background, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), 2, pwPtr->sashRelief); +#ifndef TK_NO_DOUBLE_BUFFERING /* * Copy the pixmap to the display. */ @@ -2720,6 +2731,7 @@ DisplayProxyWindow( XCopyArea(Tk_Display(tkwin), pixmap, Tk_WindowId(tkwin), pwPtr->gc, 0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0); Tk_FreePixmap(Tk_Display(tkwin), pixmap); +#endif } /* Index: generic/tkTextDisp.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/tkTextDisp.c,v retrieving revision 1.62 diff -u -p -r1.62 tkTextDisp.c --- generic/tkTextDisp.c 22 Feb 2007 13:56:33 -0000 1.62 +++ generic/tkTextDisp.c 15 Mar 2007 02:42:08 -0000 @@ -2347,16 +2347,38 @@ DisplayDLine( TextDInfo *dInfoPtr = textPtr->dInfoPtr; Display *display; int height, y_off; +#ifndef TK_NO_DOUBLE_BUFFERING + const int y = 0; +#else + const int y = dlPtr->y; +#endif if (dlPtr->chunkPtr == NULL) return; + display = Tk_Display(textPtr->tkwin); + + height = dlPtr->height; + if ((height + dlPtr->y) > dInfoPtr->maxY) { + height = dInfoPtr->maxY - dlPtr->y; + } + if (dlPtr->y < dInfoPtr->y) { + y_off = dInfoPtr->y - dlPtr->y; + height -= y_off; + } else { + y_off = 0; + } + +#ifdef TK_NO_DOUBLE_BUFFERING + TkpClipDrawableToRect(display, pixmap, dInfoPtr->x, y + y_off, + dInfoPtr->maxX - dInfoPtr->x, height); +#endif + /* * First, clear the area of the line to the background color for the text * widget. */ - display = Tk_Display(textPtr->tkwin); - Tk_Fill3DRectangle(textPtr->tkwin, pixmap, textPtr->border, 0, 0, + Tk_Fill3DRectangle(textPtr->tkwin, pixmap, textPtr->border, 0, y, Tk_Width(textPtr->tkwin), dlPtr->height, 0, TK_RELIEF_FLAT); /* @@ -2379,7 +2401,7 @@ DisplayDLine( int x = chunkPtr->x + dInfoPtr->x - dInfoPtr->curXPixelOffset; (*chunkPtr->displayProc)(textPtr, chunkPtr, x, - dlPtr->spaceAbove, + y + dlPtr->spaceAbove, dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow, dlPtr->baseline - dlPtr->spaceAbove, display, pixmap, dlPtr->y + dlPtr->spaceAbove); @@ -2426,10 +2448,10 @@ DisplayDLine( x = -chunkPtr->width; } - (*chunkPtr->displayProc)(textPtr, chunkPtr, x, dlPtr->spaceAbove, - dlPtr->height - dlPtr->spaceAbove - dlPtr->spaceBelow, - dlPtr->baseline - dlPtr->spaceAbove, display, pixmap, - dlPtr->y + dlPtr->spaceAbove); + (*chunkPtr->displayProc)(textPtr, chunkPtr, x, + y + dlPtr->spaceAbove, dlPtr->height - dlPtr->spaceAbove - + dlPtr->spaceBelow, dlPtr->baseline - dlPtr->spaceAbove, + display, pixmap, dlPtr->y + dlPtr->spaceAbove); } if (dInfoPtr->dLinesInvalidated) { @@ -2446,19 +2468,13 @@ DisplayDLine( * possible. */ - height = dlPtr->height; - if ((height + dlPtr->y) > dInfoPtr->maxY) { - height = dInfoPtr->maxY - dlPtr->y; - } - if (dlPtr->y < dInfoPtr->y) { - y_off = dInfoPtr->y - dlPtr->y; - height -= y_off; - } else { - y_off = 0; - } +#ifndef TK_NO_DOUBLE_BUFFERING XCopyArea(display, pixmap, Tk_WindowId(textPtr->tkwin), dInfoPtr->copyGC, dInfoPtr->x, y_off, (unsigned) (dInfoPtr->maxX - dInfoPtr->x), (unsigned) height, dInfoPtr->x, dlPtr->y + y_off); +#else + TkpClipDrawableToRect(display, pixmap, 0, 0, -1, -1); +#endif linesRedrawn++; } @@ -2518,7 +2534,11 @@ DisplayLineBackground( int minX, maxX, xOffset; StyleValues *sValuePtr; Display *display; - +#ifndef TK_NO_DOUBLE_BUFFERING + const int y = 0; +#else + const int y = dlPtr->y; +#endif /* * Pass 1: scan through dlPtr from left to right. For each range of chunks @@ -2583,15 +2603,15 @@ DisplayLineBackground( } XFillRectangle(display, pixmap, chunkPtr->stylePtr->bgGC, - leftX + xOffset, 0, (unsigned int) (rightX - leftX), + leftX + xOffset, y, (unsigned int) (rightX - leftX), (unsigned int) dlPtr->height); if (sValuePtr->relief != TK_RELIEF_FLAT) { Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - leftX + xOffset, 0, sValuePtr->borderWidth, + leftX + xOffset, y, sValuePtr->borderWidth, dlPtr->height, 1, sValuePtr->relief); Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, rightX - sValuePtr->borderWidth + xOffset, - 0, sValuePtr->borderWidth, dlPtr->height, 0, + y, sValuePtr->borderWidth, dlPtr->height, 0, sValuePtr->relief); } } @@ -2651,7 +2671,7 @@ DisplayLineBackground( chunkPtr->nextPtr->stylePtr)) { if (!matchLeft && (sValuePtr->relief != TK_RELIEF_FLAT)) { Tk_3DHorizontalBevel(textPtr->tkwin, pixmap, - sValuePtr->border, leftX + xOffset, 0, + sValuePtr->border, leftX + xOffset, y, rightX - leftX, sValuePtr->borderWidth, leftXIn, 1, 1, sValuePtr->relief); } @@ -2690,7 +2710,7 @@ DisplayLineBackground( if (matchLeft && !matchRight) { if (sValuePtr->relief != TK_RELIEF_FLAT) { Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - rightX2 - sValuePtr->borderWidth + xOffset, 0, + rightX2 - sValuePtr->borderWidth + xOffset, y, sValuePtr->borderWidth, sValuePtr->borderWidth, 0, sValuePtr->relief); } @@ -2699,11 +2719,11 @@ DisplayLineBackground( } else if (!matchLeft && matchRight && (sValuePtr->relief != TK_RELIEF_FLAT)) { Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - rightX2 + xOffset, 0, sValuePtr->borderWidth, + rightX2 + xOffset, y, sValuePtr->borderWidth, sValuePtr->borderWidth, 1, sValuePtr->relief); Tk_3DHorizontalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - leftX + xOffset,0, rightX2 + sValuePtr->borderWidth -leftX, - sValuePtr->borderWidth, leftXIn, 0, 1, + leftX + xOffset, y, rightX2 + sValuePtr->borderWidth - + leftX, sValuePtr->borderWidth, leftXIn, 0, 1, sValuePtr->relief); } @@ -2767,7 +2787,7 @@ DisplayLineBackground( if (!matchLeft && (sValuePtr->relief != TK_RELIEF_FLAT)) { Tk_3DHorizontalBevel(textPtr->tkwin, pixmap, sValuePtr->border, leftX + xOffset, - dlPtr->height - sValuePtr->borderWidth, + y + dlPtr->height - sValuePtr->borderWidth, rightX - leftX, sValuePtr->borderWidth, leftXIn, 0, 0, sValuePtr->relief); } @@ -2794,7 +2814,7 @@ DisplayLineBackground( if (sValuePtr->relief != TK_RELIEF_FLAT) { Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, rightX2 - sValuePtr->borderWidth + xOffset, - dlPtr->height - sValuePtr->borderWidth, + y + dlPtr->height - sValuePtr->borderWidth, sValuePtr->borderWidth, sValuePtr->borderWidth, 0, sValuePtr->relief); } @@ -2803,13 +2823,14 @@ DisplayLineBackground( } else if (!matchLeft && matchRight && (sValuePtr->relief != TK_RELIEF_FLAT)) { Tk_3DVerticalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - rightX2 + xOffset, dlPtr->height - sValuePtr->borderWidth, + rightX2 + xOffset, y + dlPtr->height - sValuePtr->borderWidth, sValuePtr->borderWidth, - 1, sValuePtr->relief); + sValuePtr->borderWidth, 1, sValuePtr->relief); Tk_3DHorizontalBevel(textPtr->tkwin, pixmap, sValuePtr->border, - leftX + xOffset, dlPtr->height - sValuePtr->borderWidth, - rightX2 + sValuePtr->borderWidth - leftX, - sValuePtr->borderWidth, leftXIn, 1, 0, sValuePtr->relief); + leftX + xOffset, y + dlPtr->height - + sValuePtr->borderWidth, rightX2 + sValuePtr->borderWidth - + leftX, sValuePtr->borderWidth, leftXIn, 1, 0, + sValuePtr->relief); } nextChunk2b: @@ -4174,9 +4195,13 @@ DisplayText( } if (maxHeight > 0) { +#ifndef TK_NO_DOUBLE_BUFFERING pixmap = Tk_GetPixmap(Tk_Display(textPtr->tkwin), Tk_WindowId(textPtr->tkwin), Tk_Width(textPtr->tkwin), maxHeight, Tk_Depth(textPtr->tkwin)); +#else + pixmap = Tk_WindowId(textPtr->tkwin); +#endif for (prevPtr = NULL, dlPtr = textPtr->dInfoPtr->dLinePtr; (dlPtr != NULL) && (dlPtr->y < dInfoPtr->maxY); prevPtr = dlPtr, dlPtr = dlPtr->nextPtr) { @@ -4192,7 +4217,9 @@ DisplayText( } DisplayDLine(textPtr, dlPtr, prevPtr, pixmap); if (dInfoPtr->dLinesInvalidated) { +#ifndef TK_NO_DOUBLE_BUFFERING Tk_FreePixmap(Tk_Display(textPtr->tkwin), pixmap); +#endif return; } dlPtr->oldY = dlPtr->y; @@ -4246,7 +4273,9 @@ DisplayText( } } +#ifndef TK_NO_DOUBLE_BUFFERING Tk_FreePixmap(Tk_Display(textPtr->tkwin), pixmap); +#endif } /* Index: generic/ttk/ttkWidget.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/generic/ttk/ttkWidget.c,v retrieving revision 1.6 diff -u -p -r1.6 ttkWidget.c --- generic/ttk/ttkWidget.c 7 Mar 2007 23:49:38 -0000 1.6 +++ generic/ttk/ttkWidget.c 15 Mar 2007 02:42:08 -0000 @@ -10,6 +10,10 @@ #include "ttkTheme.h" #include "ttkWidget.h" +#ifdef MAC_OSX_TK +#define TK_NO_DOUBLE_BUFFERING 1 +#endif + /*------------------------------------------------------------------------ * +++ Internal helper routines. */ @@ -58,14 +62,17 @@ static void RedisplayWidget(ClientData r WidgetCore *corePtr = (WidgetCore *)recordPtr; Tk_Window tkwin = corePtr->tkwin; Drawable d; +#ifndef TK_NO_DOUBLE_BUFFERING XGCValues gcValues; GC gc; +#endif corePtr->flags &= ~REDISPLAY_PENDING; if (!Tk_IsMapped(tkwin)) { return; } +#ifndef TK_NO_DOUBLE_BUFFERING /* * Get a Pixmap for drawing in the background: */ @@ -79,6 +86,9 @@ static void RedisplayWidget(ClientData r gcValues.function = GXcopy; gcValues.graphics_exposures = False; gc = Tk_GetGC(corePtr->tkwin, GCFunction|GCGraphicsExposures, &gcValues); +#else + d = Tk_WindowId(tkwin); +#endif /* * Recompute layout and draw widget contents: @@ -86,6 +96,7 @@ static void RedisplayWidget(ClientData r corePtr->widgetSpec->layoutProc(recordPtr); corePtr->widgetSpec->displayProc(recordPtr, d); +#ifndef TK_NO_DOUBLE_BUFFERING /* * Copy to the screen. */ @@ -98,6 +109,7 @@ static void RedisplayWidget(ClientData r */ Tk_FreePixmap(Tk_Display(tkwin), d); Tk_FreeGC(Tk_Display(tkwin), gc); +#endif } /* TtkRedisplayWidget -- Index: library/bgerror.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/bgerror.tcl,v retrieving revision 1.32 diff -u -p -r1.32 bgerror.tcl --- library/bgerror.tcl 22 Jun 2006 00:38:16 -0000 1.32 +++ library/bgerror.tcl 15 Mar 2007 02:42:08 -0000 @@ -18,6 +18,12 @@ namespace eval ::tk::dialog::error { option add *ErrorDialog.function.text [mc "Save To Log"] \ widgetDefault option add *ErrorDialog.function.command [namespace code SaveToLog] + if {[tk windowingsystem] eq "aqua"} { + option add *ErrorDialog*background systemAlertBackgroundActive \ + widgetDefault + option add *ErrorDialog*Button.highlightBackground \ + systemAlertBackgroundActive widgetDefault + } } proc ::tk::dialog::error::Return {} { @@ -90,12 +96,10 @@ proc ::tk::dialog::error::bgerror err { # we use the default dialog then : set windowingsystem [tk windowingsystem] if {$windowingsystem eq "aqua"} { - set ok [mc Ok] set messageFont system set textRelief flat set textHilight 0 } else { - set ok [mc OK] set messageFont {Times -18} set textRelief sunken set textHilight 1 @@ -125,7 +129,7 @@ proc ::tk::dialog::error::bgerror err { set w .bgerrorDialog set title [mc "Application Error"] set text [mc "Error: %1\$s" $displayedErr] - set buttons [list ok $ok dismiss [mc "Skip Messages"] \ + set buttons [list ok [mc OK] dismiss [mc "Skip Messages"] \ function [mc "Details >>"]] # 1. Create the top-level window and divide it into top @@ -139,7 +143,7 @@ proc ::tk::dialog::error::bgerror err { wm protocol .bgerrorDialog WM_DELETE_WINDOW { } if {$windowingsystem eq "aqua"} { - ::tk::unsupported::MacWindowStyle style .bgerrorDialog zoomDocProc + ::tk::unsupported::MacWindowStyle style .bgerrorDialog moveableAlert {} } frame .bgerrorDialog.bot @@ -161,6 +165,9 @@ proc ::tk::dialog::error::bgerror err { -relief $textRelief \ -highlightthickness $textHilight \ -wrap char + if {$windowingsystem eq "aqua"} { + $W.text configure -width 80 -background white + } scrollbar $W.scroll -command [list $W.text yview] pack $W.scroll -side right -fill y @@ -218,6 +225,7 @@ proc ::tk::dialog::error::bgerror err { if {($name eq "ok") || ($name eq "dismiss")} { grid columnconfigure .bgerrorDialog.bot $i -minsize 79 } + grid configure .bgerrorDialog.$name -pady 7 } incr i } Index: library/dialog.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/dialog.tcl,v retrieving revision 1.20 diff -u -p -r1.20 dialog.tcl --- library/dialog.tcl 25 Jan 2006 18:22:04 -0000 1.20 +++ library/dialog.tcl 15 Mar 2007 02:42:08 -0000 @@ -67,7 +67,10 @@ proc ::tk_dialog {w title text bitmap de set windowingsystem [tk windowingsystem] if {$windowingsystem eq "aqua"} { - ::tk::unsupported::MacWindowStyle style $w dBoxProc + ::tk::unsupported::MacWindowStyle style $w moveableModal {} + option add *Dialog*background systemDialogBackgroundActive widgetDefault + option add *Dialog*Button.highlightBackground \ + systemDialogBackgroundActive widgetDefault } frame $w.bot @@ -120,6 +123,7 @@ proc ::tk_dialog {w title text bitmap de if {$tmp eq "ok" || $tmp eq "cancel"} { grid columnconfigure $w.bot $i -minsize [expr {59 + 20}] } + grid configure $w.button$i -pady 7 } incr i } Index: library/tearoff.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/tearoff.tcl,v retrieving revision 1.10 diff -u -p -r1.10 tearoff.tcl --- library/tearoff.tcl 25 Jul 2005 09:06:00 -0000 1.10 +++ library/tearoff.tcl 15 Mar 2007 02:42:08 -0000 @@ -39,7 +39,7 @@ proc ::tk::TearOffMenu {w {x 0} {y 0}} { set y [winfo rooty $w] if {[tk windowingsystem] eq "aqua"} { # Avoid the native menu bar which sits on top of everything. - if {$y < 20} { set y 20 } + if {$y < 22} { set y 22 } } } Index: library/tk.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/tk.tcl,v retrieving revision 1.60 diff -u -p -r1.60 tk.tcl --- library/tk.tcl 31 Oct 2006 01:42:26 -0000 1.60 +++ library/tk.tcl 15 Mar 2007 02:42:09 -0000 @@ -128,7 +128,7 @@ proc ::tk::PlaceWindow {w {place ""} {an } if {[tk windowingsystem] eq "aqua"} { # Avoid the native menu bar which sits on top of everything. - if {$y < 20} { set y 20 } + if {$y < 22} { set y 22 } } } wm geometry $w +$x+$y Index: library/demos/goldberg.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/demos/goldberg.tcl,v retrieving revision 1.2 diff -u -p -r1.2 goldberg.tcl --- library/demos/goldberg.tcl 21 Dec 2004 11:56:35 -0000 1.2 +++ library/demos/goldberg.tcl 15 Mar 2007 02:42:09 -0000 @@ -50,8 +50,7 @@ wm iconname $w "goldberg" wm resizable $w 0 0 #positionWindow $w -set font {Arial 10} -label $w.msg -font $font -wraplength 4i -justify left -text "This is a demonstration of just how complex you can make your animations become. Click the ball to start things moving!\n\n\"Man will always find a difficult means to perform a simple task\"\n - Rube Goldberg" +label $w.msg -font {Arial 10} -wraplength 4i -justify left -text "This is a demonstration of just how complex you can make your animations become. Click the ball to start things moving!\n\n\"Man will always find a difficult means to perform a simple task\"\n - Rube Goldberg" pack $w.msg -side top if 0 { Index: library/demos/menu.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/demos/menu.tcl,v retrieving revision 1.10 diff -u -p -r1.10 menu.tcl --- library/demos/menu.tcl 9 Aug 2005 07:39:19 -0000 1.10 +++ library/demos/menu.tcl 15 Mar 2007 02:42:09 -0000 @@ -19,9 +19,9 @@ wm iconname $w "menu" positionWindow $w label $w.msg -font $font -wraplength 4i -justify left -if {[string equal [tk windowingsystem] "classic"] - || [string equal [tk windowingsystem] "aqua"]} { - $w.msg configure -text "This window contains a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by dragging outside of its bounds and releasing the mouse." +if {[tk windowingsystem] eq "aqua"} { + catch {set origUseCustomMDEF $:tk::mac::useCustomMDEF; set ::tk::mac::useCustomMDEF 1} + $w.msg configure -text "This window has a menubar with cascaded menus. You can invoke entries with an accelerator by typing Command+x, where \"x\" is the character next to the command key symbol. The rightmost menu can be torn off into a palette by selecting the first item in the menu." } else { $w.msg configure -text "This window contains a menubar with cascaded menus. You can post a menu from the keyboard by typing Alt+x, where \"x\" is the character underlined on the menu. You can then traverse among the menus using the arrow keys. When a menu is posted, you can invoke the current entry by typing space, or you can invoke any entry by typing its underlined character. If a menu entry has an accelerator, you can invoke the entry without posting the menu just by typing the accelerator. The rightmost menu can be torn off into a palette by selecting the first item in the menu." } @@ -56,8 +56,7 @@ set m $w.menu.basic $w.menu add cascade -label "Basic" -menu $m -underline 0 menu $m -tearoff 0 $m add command -label "Long entry that does nothing" -if {[string equal [tk windowingsystem] "classic"] - || [string equal [tk windowingsystem] "aqua"]} { +if {[tk windowingsystem] eq "aqua"} { set modifier Command } elseif {$tcl_platform(platform) == "windows"} { set modifier Control @@ -144,7 +143,7 @@ $m entryconfigure "Does almost nothing" set m $w.menu.colors $w.menu add cascade -label "Colors" -menu $m -underline 1 -menu $m +menu $m -tearoff 1 foreach i {red orange yellow green blue} { $m add command -label $i -background $i -command [list \ puts "You invoked \"$i\"" ] @@ -160,3 +159,5 @@ bind Menu <> { set menustatus $label update idletasks } + +if {[tk windowingsystem] eq "aqua"} {catch {set ::tk::mac::useCustomMDEF $origUseCustomMDEF}} Index: library/demos/menubu.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/demos/menubu.tcl,v retrieving revision 1.5 diff -u -p -r1.5 menubu.tcl --- library/demos/menubu.tcl 21 Dec 2004 11:56:35 -0000 1.5 +++ library/demos/menubu.tcl 15 Mar 2007 02:42:09 -0000 @@ -11,16 +11,16 @@ if {![info exists widgetDemo]} { package require Tk -set w .menubutton +set w .menubu catch {destroy $w} toplevel $w wm title $w "Menu Button Demonstration" wm iconname $w "menubutton" positionWindow $w - frame $w.body pack $w.body -expand 1 -fill both +if {[tk windowingsystem] eq "aqua"} {catch {set origUseCustomMDEF $:tk::mac::useCustomMDEF; set ::tk::mac::useCustomMDEF 1}} menubutton $w.body.below -text "Below" -underline 0 -direction below -menu $w.body.below.m -relief raised menu $w.body.below.m -tearoff 0 @@ -57,8 +57,7 @@ pack $body.buttons -padx 25 -pady 25 tk_optionMenu $body.buttons.options menubuttonoptions one two three pack $body.buttons.options -side left -padx 25 -pady 25 set m [tk_optionMenu $body.buttons.colors paletteColor Black red4 DarkGreen NavyBlue gray75 Red Green Blue gray50 Yellow Cyan Magenta White Brown DarkSeaGreen DarkViolet] -if {[string equal [tk windowingsystem] "classic"] - || [string equal [tk windowingsystem] "aqua"]} { +if {[tk windowingsystem] eq "aqua"} { set topBorderColor Black set bottomBorderColor Black } else { @@ -90,5 +89,4 @@ foreach i {Black gray75 gray50 White} { pack $body.buttons.colors -side left -padx 25 -pady 25 - - +if {[tk windowingsystem] eq "aqua"} {catch {set ::tk::mac::useCustomMDEF $origUseCustomMDEF}} Index: library/demos/puzzle.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/demos/puzzle.tcl,v retrieving revision 1.6 diff -u -p -r1.6 puzzle.tcl --- library/demos/puzzle.tcl 21 Dec 2004 11:56:35 -0000 1.6 +++ library/demos/puzzle.tcl 15 Mar 2007 02:42:09 -0000 @@ -59,8 +59,8 @@ scrollbar $w.s # using place which doesn't autosize, then we need to have a # slightly larger frame here... -if {[string equal [tk windowingsystem] aqua]} { - set frameSize 160 +if {[tk windowingsystem] eq "aqua"} { + set frameSize 168 } else { set frameSize 120 } Index: library/demos/radio.tcl =================================================================== RCS file: /cvsroot/tktoolkit/tk/library/demos/radio.tcl,v retrieving revision 1.7 diff -u -p -r1.7 radio.tcl --- library/demos/radio.tcl 21 Dec 2004 11:56:35 -0000 1.7 +++ library/demos/radio.tcl 15 Mar 2007 02:42:09 -0000 @@ -29,7 +29,9 @@ labelframe $w.mid -pady 2 -text "Color" labelframe $w.right -pady 2 -text "Alignment" -padx 2 button $w.tristate -text Tristate -command "set size multi; set color multi" \ -pady 2 -padx 2 - +if {[tk windowingsystem] eq "aqua"} { + $w.tristate configure -padx 10 +} grid $w.left -column 0 -row 1 -pady .5c -padx .5c -rowspan 2 grid $w.mid -column 1 -row 1 -pady .5c -padx .5c -rowspan 2 grid $w.right -column 2 -row 1 -pady .5c -padx .5c Index: macosx/Wish-Common.xcconfig =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/Wish-Common.xcconfig,v retrieving revision 1.2 diff -u -p -r1.2 Wish-Common.xcconfig --- macosx/Wish-Common.xcconfig 7 Mar 2007 23:46:34 -0000 1.2 +++ macosx/Wish-Common.xcconfig 15 Mar 2007 02:42:09 -0000 @@ -25,7 +25,7 @@ GCC = /usr/bin/gcc GCC_VERSION = 4.0 CC = $(GCC)-$(GCC_VERSION) WARNING_CFLAGS_GCC3 = -Wall -Wno-implicit-int -Wno-unused-parameter -Wno-deprecated-declarations -WARNING_CFLAGS = -Wextra -Wno-missing-field-initializers $(WARNING_CFLAGS_GCC3) $(WARNING_CFLAGS) +WARNING_CFLAGS = -Wextra -Wno-missing-field-initializers -Winit-self -Wpointer-arith -Wcast-align -Wdisabled-optimization -Winline $(WARNING_CFLAGS_GCC3) $(WARNING_CFLAGS) REZ_RESOURCE_MAP_READ_ONLY = YES APPLICATION_INSTALL_PATH = /Applications/Utilities BINDIR = $(PREFIX)/bin Index: macosx/tkAboutDlg.r =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkAboutDlg.r,v retrieving revision 1.7 diff -u -p -r1.7 tkAboutDlg.r --- macosx/tkAboutDlg.r 28 Apr 2006 06:02:48 -0000 1.7 +++ macosx/tkAboutDlg.r 15 Mar 2007 02:42:09 -0000 @@ -6,6 +6,7 @@ * libraries in a Macintosh Application. * * Copyright (c) 1996 Sun Microsystems, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -34,7 +35,7 @@ resource 'DLOG' (128, "About Box", purgeable) { {60, 40, 332, 404}, - movableDBoxProc, + kWindowMovableModalDialogProc, visible, noGoAway, 0x0, @@ -48,8 +49,8 @@ resource 'DITL' (128, "About Box", purge {232, 147, 252, 217}, Button {enabled, "Ok"}, { 20, 108, 212, 344}, StaticText {disabled, "Tcl " TCL_PATCH_LEVEL " & Tk " TK_PATCH_LEVEL "\n\n" - "© 2002-2006 Tcl Core Team." "\n\n" - "© 2002-2006 Daniel A. Steffen." "\n\n" + "© 2002-2007 Tcl Core Team." "\n\n" + "© 2002-2007 Daniel A. Steffen." "\n\n" "Jim Ingham & Ian Reid" "\n" "© 2001-2002 Apple Computer, Inc." "\n\n" "Jim Ingham & Ray Johnson" "\n" @@ -59,6 +60,13 @@ resource 'DITL' (128, "About Box", purge } }; +resource 'dlgx' (128, "About Box", purgeable) { + versionZero { + kDialogFlagsUseThemeBackground | kDialogFlagsUseControlHierarchy + | kDialogFlagsHandleMovableModal | kDialogFlagsUseThemeControls + } +}; + data 'PICT' (128, purgeable) { $"13A4 0000 0000 0064 0044 0011 02FF 0C00" $"FFFE 0000 0048 0000 0048 0000 0000 0000" Index: macosx/tkMacOSXBitmap.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXBitmap.c,v retrieving revision 1.4 diff -u -p -r1.4 tkMacOSXBitmap.c --- macosx/tkMacOSXBitmap.c 24 Mar 2006 14:58:01 -0000 1.4 +++ macosx/tkMacOSXBitmap.c 15 Mar 2007 02:42:09 -0000 @@ -5,6 +5,7 @@ * * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -36,10 +37,10 @@ typedef struct { */ typedef struct { - char *name; /* Name of icon. */ + const char *name; /* Name of icon. */ long int type; /* Type of icon. */ - int id; /* Id of icon. */ - int size; /* Size of icon. */ + int id; /* Id of icon. */ + int size; /* Size of icon. */ } BuiltInIcon; /* @@ -91,7 +92,7 @@ TkpDefineNativeBitmaps() int new; Tcl_HashEntry *predefHashPtr; TkPredefBitmap *predefPtr; - CONST char * name; + const char * name; BuiltInIcon *builtInPtr; NativeIcon *nativeIconPtr; Tcl_HashTable *tablePtr; @@ -139,20 +140,16 @@ TkpCreateNativeBitmap( CONST char * source) /* Info about the icon to build. */ { Pixmap pix; - GWorldPtr destPort; Rect destRect; Handle icon; - CGrafPtr saveWorld; - GDHandle saveDevice; - NativeIcon *nativeIconPtr; + CGrafPtr savePort; + Boolean portChanged; + const NativeIcon *nativeIconPtr; pix = Tk_GetPixmap(display, None, 32, 32, 0); - destPort = TkMacOSXGetDrawablePort(pix); - - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); + portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort); - nativeIconPtr = (NativeIcon *) source; + nativeIconPtr = (const NativeIcon *) source; SetRect(&destRect, 0, 0, 32, 32); if (nativeIconPtr->type == TYPE1) { RGBColor white = {0xFFFF, 0xFFFF, 0xFFFF}; @@ -171,7 +168,9 @@ TkpCreateNativeBitmap( } } - SetGWorld(saveWorld, saveDevice); + if (portChanged) { + QDSwapPort(savePort, NULL); + } return pix; } @@ -201,23 +200,23 @@ TkpGetNativeAppBitmap( int *height) { Pixmap pix; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + CGrafPtr savePort; + Boolean portChanged; Rect destRect; Handle resource; int type = -1, destWrote; Str255 nativeName; + Tcl_Encoding encoding; /* * macRoman is the encoding that the resource fork uses. */ - Tcl_UtfToExternal(NULL, Tcl_GetEncoding(NULL, "macRoman"), name, - strlen(name), 0, NULL, - (char *) &nativeName[1], - 255, NULL, &destWrote, NULL); /* Internalize native */ + encoding = Tcl_GetEncoding(NULL, "macRoman"); + Tcl_UtfToExternal(NULL, encoding, name, strlen(name), 0, NULL, + (char *) &nativeName[1], 255, NULL, &destWrote, NULL); nativeName[0] = destWrote; + Tcl_FreeEncoding(encoding); resource = GetNamedResource('cicn', nativeName); if (resource != NULL) { @@ -234,10 +233,7 @@ TkpGetNativeAppBitmap( } pix = Tk_GetPixmap(display, None, 32, 32, 0); - destPort = TkMacOSXGetDrawablePort(pix); - - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); + portChanged = QDSwapPort(TkMacOSXGetDrawablePort(pix), &savePort); SetRect(&destRect, 0, 0, 32, 32); if (type == TYPE2) { @@ -268,6 +264,8 @@ TkpGetNativeAppBitmap( *width = 32; *height = 32; - SetGWorld(saveWorld, saveDevice); + if (portChanged) { + QDSwapPort(savePort, NULL); + } return pix; } Index: macosx/tkMacOSXButton.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXButton.c,v retrieving revision 1.20 diff -u -p -r1.20 tkMacOSXButton.c --- macosx/tkMacOSXButton.c 18 Aug 2006 07:30:54 -0000 1.20 +++ macosx/tkMacOSXButton.c 15 Mar 2007 02:42:09 -0000 @@ -6,6 +6,7 @@ * * Copyright (c) 1996-1997 by Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -70,7 +71,7 @@ typedef struct { int flags; /* initialisation status */ MacControlParams params; WindowRef windowRef; - RGBColor userPaneBackground; + unsigned long userPaneBackground; ControlRef userPane; /* Carbon control */ ControlRef control; /* Carbon control */ Str255 controlTitle; @@ -80,9 +81,9 @@ typedef struct { * beveled buttons - i.e. buttons with images. */ CCTabHandle tabHandle; + Pixmap picPixmap; ControlButtonContentInfo bevelButtonContent; OpenCPicParams picParams; - Pixmap picPixmap; } MacButton; /* @@ -90,23 +91,23 @@ typedef struct { */ -static OSErr SetUserPaneDrawProc(ControlRef control, +static OSStatus SetUserPaneDrawProc(ControlRef control, ControlUserPaneDrawProcPtr upp); -static OSErr SetUserPaneSetUpSpecialBackgroundProc(ControlRef control, +static OSStatus SetUserPaneSetUpSpecialBackgroundProc(ControlRef control, ControlUserPaneBackgroundProcPtr upp); static void UserPaneDraw(ControlRef control, ControlPartCode cpc); static void UserPaneBackgroundProc(ControlHandle, ControlBackgroundPtr info); -static void ButtonEventProc _ANSI_ARGS_(( ClientData clientData, XEvent *eventPtr)); -static int UpdateControlColors _ANSI_ARGS_((MacButton *mbPtr )); -static void TkMacOSXComputeControlParams _ANSI_ARGS_((TkButton * butPtr, MacControlParams * paramsPtr)); -static int TkMacOSXComputeDrawParams _ANSI_ARGS_((TkButton * butPtr, DrawParams * dpPtr)); -static void TkMacOSXDrawControl _ANSI_ARGS_((MacButton *butPtr, - GWorldPtr destPort, GC gc, Pixmap pixmap)); -static void SetupBevelButton _ANSI_ARGS_((MacButton *butPtr, - ControlRef controlHandle, - GWorldPtr destPort, GC gc, Pixmap pixmap)); +static void ButtonEventProc(ClientData clientData, XEvent *eventPtr); +static int UpdateControlColors(MacButton *mbPtr); +static void TkMacOSXComputeControlParams(TkButton * butPtr, + MacControlParams * paramsPtr); +static int TkMacOSXComputeDrawParams(TkButton * butPtr, DrawParams * dpPtr); +static void TkMacOSXDrawControl(MacButton *butPtr, GWorldPtr destPort, GC gc, + Pixmap pixmap); +static void SetupBevelButton(MacButton *butPtr, ControlRef controlHandle, + GWorldPtr destPort, GC gc, Pixmap pixmap); /* * The class procedure table for the button widgets. @@ -148,9 +149,7 @@ TkpCreateButton( macButtonPtr->id = bCount++; macButtonPtr->usingControl = 0; macButtonPtr->flags = 0; - macButtonPtr->userPaneBackground.red = 0; - macButtonPtr->userPaneBackground.green = 0; - macButtonPtr->userPaneBackground.blue = ~0; + macButtonPtr->userPaneBackground = PIXEL_MAGIC << 24; macButtonPtr->userPane = NULL; macButtonPtr->control = NULL; macButtonPtr->controlTitle[0] = 0; @@ -196,7 +195,8 @@ TkpDisplayButton( int width, height, fullWidth, fullHeight; int textXOffset, textYOffset; int haveImage = 0, haveText = 0; - GWorldPtr destPort; + CGrafPtr destPort, savePort; + Boolean portChanged; int borderWidth; Pixmap pixmap; int wasUsingControl; @@ -232,7 +232,7 @@ TkpDisplayButton( */ destPort = TkMacOSXGetDrawablePort(pixmap); - SetGWorld(destPort, NULL); + portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(pixmap); @@ -504,6 +504,9 @@ TkpDisplayButton( butPtr->borderWidth, dpPtr->relief); } } + if (portChanged) { + QDSwapPort(savePort, NULL); + } } /* @@ -803,7 +806,6 @@ TkMacOSXInitControl ( Rect *cntrRect ) { - OSErr status; TkButton * butPtr = ( TkButton * )mbPtr; ControlRef rootControl; SInt16 procID; @@ -814,8 +816,8 @@ TkMacOSXInitControl ( SInt32 controlReference; rootControl = TkMacOSXGetRootControl(Tk_WindowId(butPtr->tkwin)); - mbPtr->windowRef - = GetWindowFromPort(TkMacOSXGetDrawablePort(Tk_WindowId(butPtr->tkwin))); + mbPtr->windowRef = GetWindowFromPort(TkMacOSXGetDrawablePort( + Tk_WindowId(butPtr->tkwin))); /* * Set up the user pane @@ -827,54 +829,31 @@ TkMacOSXInitControl ( maxValue = 1; procID = kControlUserPaneProc; controlReference = (SInt32)mbPtr; - mbPtr->userPane = NewControl(mbPtr->windowRef, - paneRect, "\p", - initiallyVisible, - initialValue, - minValue, - maxValue, - procID, - controlReference ); - + mbPtr->userPane = NewControl(mbPtr->windowRef, paneRect, "\p", + initiallyVisible, initialValue, minValue, maxValue, procID, + controlReference); if (!mbPtr->userPane) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"Failed to create user pane control\n"); -#endif + TkMacOSXDbgMsg("Failed to create user pane control"); return 1; } - - if ((status = EmbedControl(mbPtr->userPane,rootControl)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"Failed to embed user pane control %d\n", status); -#endif + if (ChkErr(EmbedControl, mbPtr->userPane,rootControl) != noErr) { return 1; } SetUserPaneSetUpSpecialBackgroundProc(mbPtr->userPane, - UserPaneBackgroundProc); + UserPaneBackgroundProc); SetUserPaneDrawProc(mbPtr->userPane,UserPaneDraw); initiallyVisible = false; TkMacOSXComputeControlParams(butPtr,&mbPtr->params); - mbPtr->control = NewControl(mbPtr->windowRef, - cntrRect, "\p", - initiallyVisible, - mbPtr->params.initialValue, - mbPtr->params.minValue, - mbPtr->params.maxValue, - mbPtr->params.procID, - controlReference ); - + mbPtr->control = NewControl(mbPtr->windowRef, cntrRect, "\p", + initiallyVisible, mbPtr->params.initialValue, + mbPtr->params.minValue, mbPtr->params.maxValue, + mbPtr->params.procID, controlReference); if (!mbPtr->control) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"failed to create control of type %d\n",procID); -#endif + TkMacOSXDbgMsg("failed to create control of type %d\n", procID); return 1; } - - if (EmbedControl(mbPtr->control,mbPtr->userPane) != noErr ) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"failed to embed control of type %d\n",procID); -#endif + if (ChkErr(EmbedControl, mbPtr->control,mbPtr->userPane) != noErr ) { return 1; } @@ -996,11 +975,7 @@ TkMacOSXDrawControl( if (len) { TkMacOSXInitControlFontStyle(font, &fontStyle); if (bcmp(&mbPtr->fontStyle, &fontStyle, sizeof(fontStyle)) ) { - if (SetControlFontStyle(mbPtr->control, &fontStyle) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"SetControlFontStyle failed\n"); -#endif - } + ChkErr(SetControlFontStyle, mbPtr->control, &fontStyle); bcopy(&fontStyle, &mbPtr->fontStyle, sizeof(fontStyle)); } @@ -1063,7 +1038,7 @@ TkMacOSXDrawControl( } } - if (mbPtr->flags&2) { + if (mbPtr->flags & 2) { ShowControl(mbPtr->userPane); ShowControl(mbPtr->control); mbPtr->flags ^= 2; @@ -1104,12 +1079,13 @@ SetupBevelButton( for the bevel button */ ) { - int err; TkButton *butPtr = ( TkButton *)mbPtr; int height, width; ControlButtonGraphicAlignment theAlignment; + CGrafPtr savePort; + Boolean portChanged; - SetPort(destPort); + portChanged = QDSwapPort(destPort, &savePort); if (butPtr->image != None) { Tk_SizeOfImage(butPtr->image, @@ -1133,11 +1109,9 @@ SetupBevelButton( * Set the flag to circumvent clipping and bounds problems with OS 10.0.4 */ - if (!(mbPtr->bevelButtonContent.u.picture - = OpenCPicture(&mbPtr->picParams)) ) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"OpenCPicture failed\n"); -#endif + if (!(mbPtr->bevelButtonContent.u.picture = + OpenCPicture(&mbPtr->picParams))) { + TkMacOSXDbgMsg("OpenCPicture failed"); } tkPictureIsOpen = 1; @@ -1156,7 +1130,7 @@ SetupBevelButton( } else if (butPtr->image != NULL) { Tk_RedrawImage(butPtr->image, 0, 0, width, height, pixmap, 0, 0); - } else { + } else { XSetClipOrigin(butPtr->display, gc, 0, 0); XCopyPlane(butPtr->display, butPtr->bitmap, pixmap, gc, 0, 0, (unsigned int) width, (unsigned int) height, 0, 0, 1); @@ -1165,15 +1139,9 @@ SetupBevelButton( ClosePicture(); tkPictureIsOpen = 0; - if ((err = SetControlData(controlHandle, kControlButtonPart, - kControlBevelButtonContentTag, - sizeof(ControlButtonContentInfo), - (char *) &mbPtr->bevelButtonContent)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, - "SetControlData BevelButtonContent failed, %d\n", err ); -#endif - } + ChkErr(SetControlData, controlHandle, kControlButtonPart, + kControlBevelButtonContentTag, sizeof(ControlButtonContentInfo), + (char *) &mbPtr->bevelButtonContent); if (butPtr->anchor == TK_ANCHOR_N) { theAlignment = kControlBevelButtonAlignTop; @@ -1195,15 +1163,9 @@ SetupBevelButton( theAlignment = kControlBevelButtonAlignCenter; } - if ((err = SetControlData(controlHandle, kControlButtonPart, + ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonGraphicAlignTag, - sizeof(ControlButtonGraphicAlignment), - (char *) &theAlignment)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, - "SetControlData BevelButtonGraphicAlign failed, %d\n", err ); -#endif - } + sizeof(ControlButtonGraphicAlignment), (char *) &theAlignment); if (butPtr->compound != COMPOUND_NONE) { ControlButtonTextPlacement thePlacement = \ @@ -1217,15 +1179,12 @@ SetupBevelButton( } else if (butPtr->compound == COMPOUND_RIGHT) { thePlacement = kControlBevelButtonPlaceToLeftOfGraphic; } - if ((err = SetControlData(controlHandle, kControlButtonPart, + ChkErr(SetControlData, controlHandle, kControlButtonPart, kControlBevelButtonTextPlaceTag, - sizeof(ControlButtonTextPlacement), - (char *) &thePlacement)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, - "SetControlData BevelButtonTextPlace failed, %d\n", err ); -#endif - } + sizeof(ControlButtonTextPlacement), (char *) &thePlacement); + } + if (portChanged) { + QDSwapPort(savePort, NULL); } } @@ -1246,7 +1205,8 @@ SetupBevelButton( * *-------------------------------------------------------------- */ -OSErr SetUserPaneDrawProc ( +OSStatus +SetUserPaneDrawProc ( ControlRef control, ControlUserPaneDrawProcPtr upp) { @@ -1274,7 +1234,7 @@ OSErr SetUserPaneDrawProc ( * *-------------------------------------------------------------- */ -OSErr +OSStatus SetUserPaneSetUpSpecialBackgroundProc( ControlRef control, ControlUserPaneBackgroundProcPtr upp) @@ -1310,9 +1270,9 @@ UserPaneDraw( { Rect contrlRect; MacButton * mbPtr; - mbPtr = ( MacButton *)GetControlReference(control); + mbPtr = (MacButton *)(intptr_t)GetControlReference(control); GetControlBounds(control,&contrlRect); - RGBBackColor (&mbPtr->userPaneBackground); + TkMacOSXSetColorInPort(mbPtr->userPaneBackground, 0, NULL); EraseRect (&contrlRect); } @@ -1339,9 +1299,9 @@ UserPaneBackgroundProc( ControlBackgroundPtr info) { MacButton * mbPtr; - mbPtr = ( MacButton *)GetControlReference(control); + mbPtr = (MacButton *)(intptr_t)GetControlReference(control); if (info->colorDevice) { - RGBBackColor (&mbPtr->userPaneBackground); + TkMacOSXSetColorInPort(mbPtr->userPaneBackground, 0, NULL); } } @@ -1389,10 +1349,11 @@ UpdateControlColors(MacButton * mbPtr) } else { xcolor = Tk_3DBorderColor(butPtr->normalBorder); } - TkSetMacColor(xcolor->pixel, &mbPtr->userPaneBackground); + mbPtr->userPaneBackground = xcolor->pixel; return false; -} +} + /* *-------------------------------------------------------------- * @@ -1522,11 +1483,12 @@ TkMacOSXComputeControlParams(TkButton * } else { paramsPtr->procID = kControlBevelButtonLargeBevelProc; } - paramsPtr->isBevel = 1; + paramsPtr->isBevel = 1; } break; } -} +} + /* *---------------------------------------------------------------------- * Index: macosx/tkMacOSXCarbonEvents.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXCarbonEvents.c,v retrieving revision 1.13 diff -u -p -r1.13 tkMacOSXCarbonEvents.c --- macosx/tkMacOSXCarbonEvents.c 31 Oct 2006 22:33:34 -0000 1.13 +++ macosx/tkMacOSXCarbonEvents.c 15 Mar 2007 02:42:09 -0000 @@ -11,7 +11,7 @@ * application event target. * * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005 Daniel A. Steffen + * Copyright (c) 2005-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -68,15 +68,15 @@ #include "tkMacOSXDebug.h" /* -#ifdef TK_MAC_DEBUG +#ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_CARBON_EVENTS #endif */ /* Declarations of functions used only in this file */ static OSStatus CarbonEventHandlerProc(EventHandlerCallRef callRef, - EventRef event, void *userData); -static OSStatus InstallStandardApplicationEventHandler(); + EventRef event, void *userData); +static OSStatus InstallStandardApplicationEventHandler(void); static void ExitRaelEventHandlerProc (EventHandlerCallRef, EventRef, void*) __attribute__ ((__noreturn__)); static void CarbonTimerProc(EventLoopTimerRef timer, void *userData); @@ -85,7 +85,11 @@ static void CarbonTimerProc(EventLoopTim static jmp_buf exitRaelJmpBuf; static EventLoopTimerRef carbonTimer = NULL; static int carbonTimerEnabled = 0; +static EventHandlerUPP carbonEventHandlerUPP = NULL; +static Tcl_Interp *carbonEventInterp = NULL; +static int inTrackingLoop = 0; + /* *---------------------------------------------------------------------- * @@ -108,22 +112,22 @@ CarbonEventHandlerProc ( EventRef event, void *userData) { - OSStatus result = eventNotHandledErr; - TkMacOSXEvent macEvent; - MacEventStatus eventStatus; + OSStatus err = eventNotHandledErr; + TkMacOSXEvent macEvent; + MacEventStatus eventStatus; macEvent.eventRef = event; - macEvent.eClass = GetEventClass(macEvent.eventRef); - macEvent.eKind = GetEventKind(macEvent.eventRef); + macEvent.eClass = GetEventClass(event); + macEvent.eKind = GetEventKind(event); macEvent.interp = (Tcl_Interp *) userData; + macEvent.callRef = callRef; bzero(&eventStatus, sizeof(eventStatus)); -#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS) - char buf [256]; +#ifdef TK_MAC_DEBUG_CARBON_EVENTS if (macEvent.eKind != kEventMouseMoved && macEvent.eKind != kEventMouseDragged) { - TkMacOSXCarbonEventToAscii(event, buf); - fprintf(stderr, "CarbonEventHandlerProc started handling %s\n", buf); + TkMacOSXDbgMsg("Started handling %s", + TkMacOSXCarbonEventToAscii(event)); TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _DebugPrintEvent, EventRef inEvent); if (_DebugPrintEvent) { @@ -135,18 +139,18 @@ CarbonEventHandlerProc ( TkMacOSXProcessEvent(&macEvent,&eventStatus); if (eventStatus.stopProcessing) { - result = noErr; + err = noErr; } -#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS) +#ifdef TK_MAC_DEBUG_CARBON_EVENTS if (macEvent.eKind != kEventMouseMoved && macEvent.eKind != kEventMouseDragged) { - fprintf(stderr, - "CarbonEventHandlerProc finished handling %s: %s handled\n", - buf, eventStatus.stopProcessing ? " " : "not"); + TkMacOSXDbgMsg("Finished handling %s: %s handled", + TkMacOSXCarbonEventToAscii(event), + eventStatus.stopProcessing ? " " : "not"); } #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ - return result; + return err; } /* @@ -166,92 +170,81 @@ CarbonEventHandlerProc ( */ MODULE_SCOPE void -TkMacOSXInitCarbonEvents ( +TkMacOSXInitCarbonEvents( Tcl_Interp *interp) { - OSStatus err; const EventTypeSpec dispatcherEventTypes[] = { - {kEventClassMouse, kEventMouseDown}, - {kEventClassMouse, kEventMouseUp}, - {kEventClassMouse, kEventMouseMoved}, - {kEventClassMouse, kEventMouseDragged}, - {kEventClassMouse, kEventMouseWheelMoved}, - {kEventClassWindow, kEventWindowUpdate}, - {kEventClassWindow, kEventWindowActivated}, - {kEventClassWindow, kEventWindowDeactivated}, {kEventClassKeyboard, kEventRawKeyDown}, {kEventClassKeyboard, kEventRawKeyRepeat}, {kEventClassKeyboard, kEventRawKeyUp}, {kEventClassKeyboard, kEventRawKeyModifiersChanged}, {kEventClassKeyboard, kEventRawKeyRepeat}, - {kEventClassApplication, kEventAppActivated}, - {kEventClassApplication, kEventAppDeactivated}, - {kEventClassApplication, kEventAppQuit}, }; const EventTypeSpec applicationEventTypes[] = { {kEventClassMenu, kEventMenuBeginTracking}, {kEventClassMenu, kEventMenuEndTracking}, + {kEventClassMenu, kEventMenuOpening}, + {kEventClassMenu, kEventMenuTargetItem}, {kEventClassCommand, kEventCommandProcess}, {kEventClassCommand, kEventCommandUpdateStatus}, - {kEventClassMouse, kEventMouseWheelMoved}, - {kEventClassWindow, kEventWindowExpanded}, + {kEventClassApplication, kEventAppActivated}, + {kEventClassApplication, kEventAppDeactivated}, + {kEventClassApplication, kEventAppQuit}, {kEventClassApplication, kEventAppHidden}, {kEventClassApplication, kEventAppShown}, {kEventClassApplication, kEventAppAvailableWindowBoundsChanged}, + {kEventClassAppearance, kEventAppearanceScrollBarVariantChanged}, }; - EventHandlerUPP handler = NewEventHandlerUPP(CarbonEventHandlerProc); - - err = InstallStandardApplicationEventHandler(); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "InstallStandardApplicationEventHandler failed, %d\n", - (int) err); -#endif - } - err = InstallEventHandler(GetEventDispatcherTarget(), handler, - GetEventTypeCount(dispatcherEventTypes), dispatcherEventTypes, - (void *) interp, NULL); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "InstallEventHandler failed, %d\n", (int) err); -#endif - } - err = InstallEventHandler(GetApplicationEventTarget(), handler, - GetEventTypeCount(applicationEventTypes), applicationEventTypes, - (void *) interp, NULL); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "InstallEventHandler failed, %d\n", (int) err); -#endif - } -#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS) - TkMacOSXInitNamedDebugSymbol(HIToolbox, void, TraceEventByName, char*); - if (TraceEventByName) { + carbonEventHandlerUPP = NewEventHandlerUPP(CarbonEventHandlerProc); + carbonEventInterp = interp; + ChkErr(InstallStandardApplicationEventHandler); + ChkErr(InstallEventHandler, GetEventDispatcherTarget(), + carbonEventHandlerUPP, GetEventTypeCount(dispatcherEventTypes), + dispatcherEventTypes, (void *) carbonEventInterp, NULL); + ChkErr(InstallEventHandler, GetApplicationEventTarget(), + carbonEventHandlerUPP, GetEventTypeCount(applicationEventTypes), + applicationEventTypes, (void *) carbonEventInterp, NULL); + +#ifdef TK_MAC_DEBUG_CARBON_EVENTS + TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _TraceEventByName, + CFStringRef); + if (_TraceEventByName) { /* Carbon-internal event debugging (c.f. Technote 2124) */ - TraceEventByName("kEventMouseDown"); - TraceEventByName("kEventMouseUp"); - TraceEventByName("kEventMouseWheelMoved"); - TraceEventByName("kEventMouseScroll"); - TraceEventByName("kEventWindowUpdate"); - TraceEventByName("kEventWindowActivated"); - TraceEventByName("kEventWindowDeactivated"); - TraceEventByName("kEventRawKeyDown"); - TraceEventByName("kEventRawKeyRepeat"); - TraceEventByName("kEventRawKeyUp"); - TraceEventByName("kEventRawKeyModifiersChanged"); - TraceEventByName("kEventRawKeyRepeat"); - TraceEventByName("kEventAppActivated"); - TraceEventByName("kEventAppDeactivated"); - TraceEventByName("kEventAppQuit"); - TraceEventByName("kEventMenuBeginTracking"); - TraceEventByName("kEventMenuEndTracking"); - TraceEventByName("kEventCommandProcess"); - TraceEventByName("kEventCommandUpdateStatus"); - TraceEventByName("kEventWindowExpanded"); - TraceEventByName("kEventAppHidden"); - TraceEventByName("kEventAppShown"); - TraceEventByName("kEventAppAvailableWindowBoundsChanged"); + _TraceEventByName(CFSTR("kEventMouseDown")); + _TraceEventByName(CFSTR("kEventMouseUp")); +#if 0 + _TraceEventByName(CFSTR("kEventMouseMoved")); + _TraceEventByName(CFSTR("kEventMouseDragged")); +#endif + _TraceEventByName(CFSTR("kEventMouseWheelMoved")); + _TraceEventByName(CFSTR("kEventMouseScroll")); + _TraceEventByName(CFSTR("kEventRawKeyDown")); + _TraceEventByName(CFSTR("kEventRawKeyRepeat")); + _TraceEventByName(CFSTR("kEventRawKeyUp")); + _TraceEventByName(CFSTR("kEventRawKeyModifiersChanged")); + _TraceEventByName(CFSTR("kEventRawKeyRepeat")); + _TraceEventByName(CFSTR("kEventMenuBeginTracking")); + _TraceEventByName(CFSTR("kEventMenuEndTracking")); + _TraceEventByName(CFSTR("kEventCommandProcess")); + _TraceEventByName(CFSTR("kEventCommandUpdateStatus")); + _TraceEventByName(CFSTR("kEventAppActivated")); + _TraceEventByName(CFSTR("kEventAppDeactivated")); + _TraceEventByName(CFSTR("kEventAppQuit")); + _TraceEventByName(CFSTR("kEventAppHidden")); + _TraceEventByName(CFSTR("kEventAppShown")); + _TraceEventByName(CFSTR("kEventAppAvailableWindowBoundsChanged")); + _TraceEventByName(CFSTR("kEventAppearanceScrollBarVariantChanged")); + _TraceEventByName(CFSTR("kEventWindowActivated")); + _TraceEventByName(CFSTR("kEventWindowDeactivated")); + _TraceEventByName(CFSTR("kEventWindowUpdate")); + _TraceEventByName(CFSTR("kEventWindowExpanded")); + _TraceEventByName(CFSTR("kEventWindowBoundsChanged")); + _TraceEventByName(CFSTR("kEventWindowDragStarted")); + _TraceEventByName(CFSTR("kEventWindowDragCompleted")); + _TraceEventByName(CFSTR("kEventWindowConstrain")); + _TraceEventByName(CFSTR("kEventWindowGetRegion")); + _TraceEventByName(CFSTR("kEventWindowDrawContent")); } #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ } @@ -259,6 +252,50 @@ TkMacOSXInitCarbonEvents ( /* *---------------------------------------------------------------------- * + * TkMacOSXInstallWindowCarbonEventHandler -- + * + * This procedure installs our window CarbonEvent handler. + * + * Results: + * None. + * + * Side effects: + * Handler for Carbon Events is registered. + * + *---------------------------------------------------------------------- + */ + +MODULE_SCOPE void +TkMacOSXInstallWindowCarbonEventHandler( + Tcl_Interp *interp, WindowRef window) +{ + const EventTypeSpec windowEventTypes[] = { + {kEventClassMouse, kEventMouseDown}, + {kEventClassMouse, kEventMouseUp}, + {kEventClassMouse, kEventMouseMoved}, + {kEventClassMouse, kEventMouseDragged}, + {kEventClassMouse, kEventMouseWheelMoved}, + {kEventClassWindow, kEventWindowActivated}, + {kEventClassWindow, kEventWindowDeactivated}, + {kEventClassWindow, kEventWindowUpdate}, + {kEventClassWindow, kEventWindowExpanded}, + {kEventClassWindow, kEventWindowBoundsChanged}, + {kEventClassWindow, kEventWindowDragStarted}, + {kEventClassWindow, kEventWindowDragCompleted}, + {kEventClassWindow, kEventWindowConstrain}, + {kEventClassWindow, kEventWindowGetRegion}, + {kEventClassWindow, kEventWindowDrawContent}, + }; + + ChkErr(InstallEventHandler, GetWindowEventTarget(window), + carbonEventHandlerUPP, GetEventTypeCount(windowEventTypes), + windowEventTypes, (void *) (interp ? interp : carbonEventInterp), + NULL); +} + +/* + *---------------------------------------------------------------------- + * * InstallStandardApplicationEventHandler -- * * This procedure installs the carbon standard application event @@ -274,7 +311,7 @@ TkMacOSXInitCarbonEvents ( */ static OSStatus -InstallStandardApplicationEventHandler() +InstallStandardApplicationEventHandler(void) { /* * This is a hack to workaround missing Carbon API to install the standard @@ -297,16 +334,16 @@ InstallStandardApplicationEventHandler() exitRaelEventHandler = NewEventHandlerUPP( (EventHandlerProcPtr) ExitRaelEventHandlerProc); if (exitRaelEventHandler) { - err = InstallEventHandler(GetEventDispatcherTarget(), + err = ChkErr(InstallEventHandler, GetEventDispatcherTarget(), exitRaelEventHandler, 1, &exitRaelEventType, NULL, &exitRaelEventHandlerRef); } if (err == noErr) { - err = CreateEvent(NULL, kExitRaelEvent, kExitRaelEvent, + err = ChkErr(CreateEvent, NULL, kExitRaelEvent, kExitRaelEvent, GetCurrentEventTime(), kEventAttributeNone, &exitRaelEvent); } if (err == noErr) { - err = PostEventToQueue(GetMainEventQueue(), exitRaelEvent, + err = ChkErr(PostEventToQueue, GetMainEventQueue(), exitRaelEvent, kEventPriorityHigh); } if (err == noErr) { @@ -357,13 +394,38 @@ ExitRaelEventHandlerProc ( /* *---------------------------------------------------------------------- * + * TkMacOSXRunTclEventLoop -- + * + * Process a limited number of tcl events. + * + * Results: + * Returns 1 if events were handled and 0 otherwise. + * + * Side effects: + * Runs the Tcl event loop. + * + *---------------------------------------------------------------------- + */ + +MODULE_SCOPE int +TkMacOSXRunTclEventLoop(void) +{ + int i = 4, result = 0; + + /* Avoid starving main event loop: process at most 4 events. */ + while(--i && Tcl_ServiceAll()) { + result = 1; + } + return result; +} + +/* + *---------------------------------------------------------------------- + * * CarbonTimerProc -- * * This procedure is the carbon timer handler that runs the tcl - * event loop periodically. It does not process TCL_WINDOW_EVENTS - * to avoid reentry issues with Carbon, nor TCL_IDLE_EVENTS since - * it is only intended to be called during short periods of busy - * time such as during menu tracking. + * event loop periodically. * * Results: * None. @@ -379,15 +441,10 @@ CarbonTimerProc ( EventLoopTimerRef timer, void *userData) { - if(carbonTimerEnabled) { - /* Avoid starving main event loop: process at most 4 events. */ - int i = 4; - while(--i && Tcl_DoOneEvent( - TCL_FILE_EVENTS|TCL_TIMER_EVENTS|TCL_DONT_WAIT)) { -#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_CARBON_EVENTS) - fprintf(stderr, "Processed tcl event from carbon timer\n"); + if(carbonTimerEnabled > 0 && TkMacOSXRunTclEventLoop()) { +#ifdef TK_MAC_DEBUG_CARBON_EVENTS + TkMacOSXDbgMsg("Processed tcl events from carbon timer"); #endif /* TK_MAC_DEBUG_CARBON_EVENTS */ - } } } @@ -398,9 +455,9 @@ CarbonTimerProc ( * * This procedure installs (if necessary) and starts a carbon * event timer that runs the tcl event loop periodically. - * It should be called whenever a nested carbon event loop is - * run by HIToolbox (e.g. during menutracking) to ensure that - * non-window non-idle tcl events are processed. + * It should be called whenever a nested carbon event loop might + * run by HIToolbox (e.g. during mouse tracking) to ensure that + * tcl events continue to be processed. * * Results: * OS status code. @@ -412,32 +469,25 @@ CarbonTimerProc ( */ MODULE_SCOPE OSStatus -TkMacOSXStartTclEventLoopCarbonTimer() +TkMacOSXStartTclEventLoopCarbonTimer(void) { - OSStatus err; + OSStatus err = noErr; - if(!carbonTimer) { - EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(CarbonTimerProc); - err = InstallEventLoopTimer(GetMainEventLoop(), kEventDurationNoWait, - 5 * kEventDurationMillisecond, timerUPP, NULL, &carbonTimer); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "InstallEventLoopTimer failed, %d\n", (int) err); -#endif - } - } else { - err = SetEventLoopTimerNextFireTime(carbonTimer, kEventDurationNoWait); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "SetEventLoopTimerNextFireTime failed, %d\n", - (int) err); -#endif + if (++carbonTimerEnabled > 0) { + if(!carbonTimer) { + EventLoopTimerUPP timerUPP = NewEventLoopTimerUPP(CarbonTimerProc); + err = ChkErr(InstallEventLoopTimer, GetMainEventLoop(), + 5 * kEventDurationMillisecond, + 5 * kEventDurationMillisecond, + timerUPP, NULL, &carbonTimer); + } else { + err = ChkErr(SetEventLoopTimerNextFireTime, carbonTimer, + 5 * kEventDurationMillisecond); } } - carbonTimerEnabled = 1; return err; } - + /* *---------------------------------------------------------------------- * @@ -456,20 +506,127 @@ TkMacOSXStartTclEventLoopCarbonTimer() */ MODULE_SCOPE OSStatus -TkMacOSXStopTclEventLoopCarbonTimer() +TkMacOSXStopTclEventLoopCarbonTimer(void) { OSStatus err = noErr; - if(carbonTimer) { - err = SetEventLoopTimerNextFireTime(carbonTimer, kEventDurationForever); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "SetEventLoopTimerNextFireTime failed, %d\n", - (int) err); -#endif + if (--carbonTimerEnabled == 0) { + if(carbonTimer) { + err = ChkErr(SetEventLoopTimerNextFireTime, carbonTimer, + kEventDurationForever); } } - carbonTimerEnabled = 0; return err; } +/* + *---------------------------------------------------------------------- + * + * TkMacOSXTrackingLoop -- + * + * Call with 1 before entering a mouse tracking loop (e.g. window + * resizing or menu tracking) to enable tcl event processing but + * disable carbon event processing (except for update events) + * during the loop, and with 0 after exiting the loop to reset. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +MODULE_SCOPE void +TkMacOSXTrackingLoop(int tracking) +{ + static int previousServiceMode = TCL_SERVICE_NONE; + + if (tracking) { + inTrackingLoop++; + previousServiceMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); + TkMacOSXStartTclEventLoopCarbonTimer(); +#ifdef TK_MAC_DEBUG_CARBON_EVENTS + TkMacOSXDbgMsg("Entering tracking loop"); +#endif /* TK_MAC_DEBUG_CARBON_EVENTS */ + } else { + TkMacOSXStopTclEventLoopCarbonTimer(); + previousServiceMode = Tcl_SetServiceMode(previousServiceMode); + inTrackingLoop--; +#ifdef TK_MAC_DEBUG_CARBON_EVENTS + TkMacOSXDbgMsg("Exiting tracking loop"); +#endif /* TK_MAC_DEBUG_CARBON_EVENTS */ + } +} + +/* + *---------------------------------------------------------------------- + * + * TkMacOSXReceiveAndDispatchEvent -- + * + * This receives a carbon event and sends it to the carbon event + * dispatcher. + * + * Results: + * Mac OS status + * + * Side effects: + * This receives and dispatches the next Carbon event. + * + *---------------------------------------------------------------------- + */ +MODULE_SCOPE OSStatus +TkMacOSXReceiveAndDispatchEvent(void) +{ + static EventTargetRef targetRef = NULL; + int numEventTypes = 0; + const EventTypeSpec *eventTypes = NULL; + EventRef eventRef; + OSStatus err; + const EventTypeSpec trackingEventTypes[] = { + {'dniw', kEventWindowUpdate}, + {kEventClassWindow, kEventWindowUpdate}, + }; + + if (inTrackingLoop > 0) { + eventTypes = trackingEventTypes; + numEventTypes = GetEventTypeCount(trackingEventTypes); + } + + /* + * This is a poll, since we have already counted the events coming + * into this routine, and are guaranteed to have one waiting. + */ + + err = ChkErr(ReceiveNextEvent, numEventTypes, eventTypes, + kEventDurationNoWait, true, &eventRef); + if (err == noErr) { +#ifdef TK_MAC_DEBUG_CARBON_EVENTS + UInt32 kind = GetEventKind(eventRef); + + if (kind != kEventMouseMoved && kind != kEventMouseDragged) { + TkMacOSXDbgMsg("Dispatching %s", TkMacOSXCarbonEventToAscii(eventRef)); + TkMacOSXInitNamedDebugSymbol(HIToolbox, void, _DebugPrintEvent, + EventRef inEvent); + if (_DebugPrintEvent) { + /* Carbon-internal event debugging (c.f. Technote 2124) */ + _DebugPrintEvent(eventRef); + } + } +#endif /* TK_MAC_DEBUG_CARBON_EVENTS */ + if (!targetRef) { + targetRef = GetEventDispatcherTarget(); + } + TkMacOSXStartTclEventLoopCarbonTimer(); + err = SendEventToEventTarget(eventRef, targetRef); + TkMacOSXStopTclEventLoopCarbonTimer(); + if (err != noErr && err != eventLoopTimedOutErr + && err != eventNotHandledErr) { + TkMacOSXDbgMsg("SendEventToEventTarget(%s) failed: %ld", + TkMacOSXCarbonEventToAscii(eventRef), err); + } + ReleaseEvent(eventRef); + } + return err; +} Index: macosx/tkMacOSXClipboard.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXClipboard.c,v retrieving revision 1.7 diff -u -p -r1.7 tkMacOSXClipboard.c --- macosx/tkMacOSXClipboard.c 19 Jan 2007 00:36:45 -0000 1.7 +++ macosx/tkMacOSXClipboard.c 15 Mar 2007 02:42:09 -0000 @@ -62,7 +62,7 @@ TkSelGetSelection( * Get the scrap from the Macintosh global clipboard. */ - err = GetCurrentScrap(&scrapRef); + err = ChkErr(GetCurrentScrap, &scrapRef); if (err != noErr) { Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), " GetCurrentScrap failed.", (char *) NULL); @@ -72,7 +72,8 @@ TkSelGetSelection( /* * Try UNICODE first */ - err = GetScrapFlavorSize(scrapRef, kScrapFlavorTypeUnicode, &length); + err = ChkErr(GetScrapFlavorSize, scrapRef, kScrapFlavorTypeUnicode, + &length); if (err == noErr && length > 0) { Tcl_DString ds; char *data; @@ -80,7 +81,7 @@ TkSelGetSelection( buf = (char *) ckalloc(length + 2); buf[length] = 0; buf[length+1] = 0; /* 2-byte unicode null */ - err = GetScrapFlavorData(scrapRef, kScrapFlavorTypeUnicode, + err = ChkErr(GetScrapFlavorData, scrapRef, kScrapFlavorTypeUnicode, &length, buf); if (err == noErr) { Tcl_DStringInit(&ds); @@ -98,7 +99,7 @@ TkSelGetSelection( } } - err = GetScrapFlavorSize(scrapRef, 'TEXT', &length); + err = ChkErr(GetScrapFlavorSize, scrapRef, 'TEXT', &length); if (err != noErr) { Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), " GetScrapFlavorSize failed.", (char *) NULL); @@ -110,7 +111,7 @@ TkSelGetSelection( buf = (char *) ckalloc(length + 1); buf[length] = 0; - err = GetScrapFlavorData(scrapRef, 'TEXT', &length, buf); + err = ChkErr(GetScrapFlavorData, scrapRef, 'TEXT', &length, buf); if (err != noErr) { Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), " GetScrapFlavorData failed.", (char *) NULL); Index: macosx/tkMacOSXColor.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXColor.c,v retrieving revision 1.7 diff -u -p -r1.7 tkMacOSXColor.c --- macosx/tkMacOSXColor.c 3 Nov 2006 03:05:03 -0000 1.7 +++ macosx/tkMacOSXColor.c 15 Mar 2007 02:42:09 -0000 @@ -1,13 +1,14 @@ -/* +/* * tkMacOSXColor.c -- * - * This file maintains a database of color values for the Tk - * toolkit, in order to avoid round-trips to the server to - * map color names to pixel values. + * This file maintains a database of color values for the Tk + * toolkit, in order to avoid round-trips to the server to + * map color names to pixel values. * * Copyright (c) 1990-1994 The Regents of the University of California. * Copyright (c) 1994-1996 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -18,211 +19,509 @@ #include "tkMacOSXInt.h" #include "tkColor.h" -/* Define constants only available on Mac OS X 10.3 or later */ -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 - #define kThemeBrushAlternatePrimaryHighlightColor -5 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 +/* Undocumented CG API for creating CGPattern from CGImage */ +extern CGPatternRef CGPatternCreateWithImage(CGImageRef img, int i) WEAK_IMPORT_ATTRIBUTE; #endif -/* - * Default Auxillary Control Record for all controls. This is cached once - * and is updated by the system. We use this to get the default system - * colors used by controls. +struct SystemColorMapEntry { + const char *name; + ThemeBrush brush; + ThemeTextColor textColor; + ThemeBackgroundKind background; +}; /* unsigned char pixelCode; */ + +/* + * Array of system color definitions: the array index is required to equal the + * color's (pixelCode - MIN_PIXELCODE), i.e. the array order needs to be kept + * in sync with the public pixel code values in tkMacOSXPort.h ! + */ + +#define MIN_PIXELCODE 30 +static const struct SystemColorMapEntry systemColorMap[] = { + { "Transparent", 0, 0, 0 }, /* 30: TRANSPARENT_PIXEL */ + { "Highlight", kThemeBrushPrimaryHighlightColor, 0, 0 }, /* 31: HIGHLIGHT_PIXEL */ + { "HighlightSecondary", kThemeBrushSecondaryHighlightColor, 0, 0 }, /* 32: HIGHLIGHT_SECONDARY_PIXEL */ + { "HighlightText", kThemeBrushBlack, 0, 0 }, /* 33: HIGHLIGHT_TEXT_PIXEL */ + { "HighlightAlternate", kThemeBrushAlternatePrimaryHighlightColor, 0, 0 }, /* 34: HIGHLIGHT_ALTERNATE_PIXEL */ + { "ButtonText", 0, kThemeTextColorPushButtonActive, 0 }, /* 35: CONTROL_TEXT_PIXEL */ + { "PrimaryHighlightColor", kThemeBrushPrimaryHighlightColor, 0, 0 }, /* 36 */ + { "ButtonFace", kThemeBrushButtonFaceActive, 0, 0 }, /* 37: CONTROL_BODY_PIXEL */ + { "SecondaryHighlightColor", kThemeBrushSecondaryHighlightColor, 0, 0 }, /* 38 */ + { "ButtonFrame", kThemeBrushButtonFrameActive, 0, 0 }, /* 39: CONTROL_FRAME_PIXEL */ + { "AlternatePrimaryHighlightColor", kThemeBrushAlternatePrimaryHighlightColor, 0, 0 }, /* 40 */ + { "WindowBody", kThemeBrushDocumentWindowBackground, 0, 0 }, /* 41: WINDOW_BODY_PIXEL */ + { "SheetBackground", kThemeBrushSheetBackground, 0, 0 }, /* 42 */ + { "MenuActive", kThemeBrushMenuBackgroundSelected, 0, 0 }, /* 43: MENU_ACTIVE_PIXEL */ + { "Black", kThemeBrushBlack, 0, 0 }, /* 44 */ + { "MenuActiveText", 0, kThemeTextColorMenuItemSelected, 0 }, /* 45: MENU_ACTIVE_TEXT_PIXEL */ + { "White", kThemeBrushWhite, 0, 0 }, /* 46 */ + { "Menu", kThemeBrushMenuBackground, 0, 0 }, /* 47: MENU_BACKGROUND_PIXEL */ + { "DialogBackgroundActive", kThemeBrushDialogBackgroundActive, 0, 0 }, /* 48 */ + { "MenuDisabled", 0, kThemeTextColorMenuItemDisabled, 0 }, /* 49: MENU_DISABLED_PIXEL */ + { "DialogBackgroundInactive", kThemeBrushDialogBackgroundInactive, 0, 0 }, /* 50 */ + { "MenuText", 0, kThemeTextColorMenuItemActive, 0 }, /* 51: MENU_TEXT_PIXEL */ + { "AppearanceColor", 0, 0, 0 }, /* 52: APPEARANCE_PIXEL */ + { "AlertBackgroundActive", kThemeBrushAlertBackgroundActive, 0, 0 }, /* 53 */ + { "AlertBackgroundInactive", kThemeBrushAlertBackgroundInactive, 0, 0 }, /* 54 */ + { "ModelessDialogBackgroundActive", kThemeBrushModelessDialogBackgroundActive, 0, 0 }, /* 55 */ + { "ModelessDialogBackgroundInactive", kThemeBrushModelessDialogBackgroundInactive, 0, 0 }, /* 56 */ + { "UtilityWindowBackgroundActive", kThemeBrushUtilityWindowBackgroundActive, 0, 0 }, /* 57 */ + { "UtilityWindowBackgroundInactive", kThemeBrushUtilityWindowBackgroundInactive, 0, 0 }, /* 58 */ + { "ListViewSortColumnBackground", kThemeBrushListViewSortColumnBackground, 0, 0 }, /* 59 */ + { "ListViewBackground", kThemeBrushListViewBackground, 0, 0 }, /* 60 */ + { "IconLabelBackground", kThemeBrushIconLabelBackground, 0, 0 }, /* 61 */ + { "ListViewSeparator", kThemeBrushListViewSeparator, 0, 0 }, /* 62 */ + { "ChasingArrows", kThemeBrushChasingArrows, 0, 0 }, /* 63 */ + { "DragHilite", kThemeBrushDragHilite, 0, 0 }, /* 64 */ + { "DocumentWindowBackground", kThemeBrushDocumentWindowBackground, 0, 0 }, /* 65 */ + { "FinderWindowBackground", kThemeBrushFinderWindowBackground, 0, 0 }, /* 66 */ + { "ScrollBarDelimiterActive", kThemeBrushScrollBarDelimiterActive, 0, 0 }, /* 67 */ + { "ScrollBarDelimiterInactive", kThemeBrushScrollBarDelimiterInactive, 0, 0 }, /* 68 */ + { "FocusHighlight", kThemeBrushFocusHighlight, 0, 0 }, /* 69 */ + { "PopupArrowActive", kThemeBrushPopupArrowActive, 0, 0 }, /* 70 */ + { "PopupArrowPressed", kThemeBrushPopupArrowPressed, 0, 0 }, /* 71 */ + { "PopupArrowInactive", kThemeBrushPopupArrowInactive, 0, 0 }, /* 72 */ + { "AppleGuideCoachmark", kThemeBrushAppleGuideCoachmark, 0, 0 }, /* 73 */ + { "IconLabelBackgroundSelected", kThemeBrushIconLabelBackgroundSelected, 0, 0 }, /* 74 */ + { "StaticAreaFill", kThemeBrushStaticAreaFill, 0, 0 }, /* 75 */ + { "ActiveAreaFill", kThemeBrushActiveAreaFill, 0, 0 }, /* 76 */ + { "ButtonFrameActive", kThemeBrushButtonFrameActive, 0, 0 }, /* 77 */ + { "ButtonFrameInactive", kThemeBrushButtonFrameInactive, 0, 0 }, /* 78 */ + { "ButtonFaceActive", kThemeBrushButtonFaceActive, 0, 0 }, /* 79 */ + { "ButtonFaceInactive", kThemeBrushButtonFaceInactive, 0, 0 }, /* 80 */ + { "ButtonFacePressed", kThemeBrushButtonFacePressed, 0, 0 }, /* 81 */ + { "ButtonActiveDarkShadow", kThemeBrushButtonActiveDarkShadow, 0, 0 }, /* 82 */ + { "ButtonActiveDarkHighlight", kThemeBrushButtonActiveDarkHighlight, 0, 0 }, /* 83 */ + { "ButtonActiveLightShadow", kThemeBrushButtonActiveLightShadow, 0, 0 }, /* 84 */ + { "ButtonActiveLightHighlight", kThemeBrushButtonActiveLightHighlight, 0, 0 }, /* 85 */ + { "ButtonInactiveDarkShadow", kThemeBrushButtonInactiveDarkShadow, 0, 0 }, /* 86 */ + { "ButtonInactiveDarkHighlight", kThemeBrushButtonInactiveDarkHighlight, 0, 0 }, /* 87 */ + { "ButtonInactiveLightShadow", kThemeBrushButtonInactiveLightShadow, 0, 0 }, /* 88 */ + { "ButtonInactiveLightHighlight", kThemeBrushButtonInactiveLightHighlight, 0, 0 }, /* 89 */ + { "ButtonPressedDarkShadow", kThemeBrushButtonPressedDarkShadow, 0, 0 }, /* 90 */ + { "ButtonPressedDarkHighlight", kThemeBrushButtonPressedDarkHighlight, 0, 0 }, /* 91 */ + { "ButtonPressedLightShadow", kThemeBrushButtonPressedLightShadow, 0, 0 }, /* 92 */ + { "ButtonPressedLightHighlight", kThemeBrushButtonPressedLightHighlight, 0, 0 }, /* 93 */ + { "BevelActiveLight", kThemeBrushBevelActiveLight, 0, 0 }, /* 94 */ + { "BevelActiveDark", kThemeBrushBevelActiveDark, 0, 0 }, /* 95 */ + { "BevelInactiveLight", kThemeBrushBevelInactiveLight, 0, 0 }, /* 96 */ + { "BevelInactiveDark", kThemeBrushBevelInactiveDark, 0, 0 }, /* 97 */ + { "NotificationWindowBackground", kThemeBrushNotificationWindowBackground, 0, 0 }, /* 98 */ + { "MovableModalBackground", kThemeBrushMovableModalBackground, 0, 0 }, /* 99 */ + { "SheetBackgroundOpaque", kThemeBrushSheetBackgroundOpaque, 0, 0 }, /* 100 */ + { "DrawerBackground", kThemeBrushDrawerBackground, 0, 0 }, /* 101 */ + { "ToolbarBackground", kThemeBrushToolbarBackground, 0, 0 }, /* 102 */ + { "SheetBackgroundTransparent", kThemeBrushSheetBackgroundTransparent, 0, 0 }, /* 103 */ + { "MenuBackground", kThemeBrushMenuBackground, 0, 0 }, /* 104 */ + { "Pixel", 0, 0, 0 }, /* 105: PIXEL_MAGIC */ + { "MenuBackgroundSelected", kThemeBrushMenuBackgroundSelected, 0, 0 }, /* 106 */ + { "ListViewOddRowBackground", kThemeBrushListViewOddRowBackground, 0, 0 }, /* 107 */ + { "ListViewEvenRowBackground", kThemeBrushListViewEvenRowBackground, 0, 0 }, /* 108 */ + { "ListViewColumnDivider", kThemeBrushListViewColumnDivider, 0, 0 }, /* 109 */ + { "BlackText", 0, kThemeTextColorBlack, 0 }, /* 110 */ + { "DialogActiveText", 0, kThemeTextColorDialogActive, 0 }, /* 111 */ + { "DialogInactiveText", 0, kThemeTextColorDialogInactive, 0 }, /* 112 */ + { "AlertActiveText", 0, kThemeTextColorAlertActive, 0 }, /* 113 */ + { "AlertInactiveText", 0, kThemeTextColorAlertInactive, 0 }, /* 114 */ + { "ModelessDialogActiveText", 0, kThemeTextColorModelessDialogActive, 0 }, /* 115 */ + { "ModelessDialogInactiveText", 0, kThemeTextColorModelessDialogInactive, 0 }, /* 116 */ + { "WindowHeaderActiveText", 0, kThemeTextColorWindowHeaderActive, 0 }, /* 117 */ + { "WindowHeaderInactiveText", 0, kThemeTextColorWindowHeaderInactive, 0 }, /* 118 */ + { "PlacardActiveText", 0, kThemeTextColorPlacardActive, 0 }, /* 119 */ + { "PlacardInactiveText", 0, kThemeTextColorPlacardInactive, 0 }, /* 120 */ + { "PlacardPressedText", 0, kThemeTextColorPlacardPressed, 0 }, /* 121 */ + { "PushButtonActiveText", 0, kThemeTextColorPushButtonActive, 0 }, /* 122 */ + { "PushButtonInactiveText", 0, kThemeTextColorPushButtonInactive, 0 }, /* 123 */ + { "PushButtonPressedText", 0, kThemeTextColorPushButtonPressed, 0 }, /* 124 */ + { "BevelButtonActiveText", 0, kThemeTextColorBevelButtonActive, 0 }, /* 125 */ + { "BevelButtonInactiveText", 0, kThemeTextColorBevelButtonInactive, 0 }, /* 126 */ + { "BevelButtonPressedText", 0, kThemeTextColorBevelButtonPressed, 0 }, /* 127 */ + { "PopupButtonActiveText", 0, kThemeTextColorPopupButtonActive, 0 }, /* 128 */ + { "PopupButtonInactiveText", 0, kThemeTextColorPopupButtonInactive, 0 }, /* 129 */ + { "PopupButtonPressedText", 0, kThemeTextColorPopupButtonPressed, 0 }, /* 130 */ + { "IconLabelText", 0, kThemeTextColorIconLabel, 0 }, /* 131 */ + { "ListViewText", 0, kThemeTextColorListView, 0 }, /* 132 */ + { "DocumentWindowTitleActiveText", 0, kThemeTextColorDocumentWindowTitleActive, 0 }, /* 133 */ + { "DocumentWindowTitleInactiveText", 0, kThemeTextColorDocumentWindowTitleInactive, 0 }, /* 134 */ + { "MovableModalWindowTitleActiveText", 0, kThemeTextColorMovableModalWindowTitleActive, 0 }, /* 135 */ + { "MovableModalWindowTitleInactiveText",0, kThemeTextColorMovableModalWindowTitleInactive, 0 }, /* 136 */ + { "UtilityWindowTitleActiveText", 0, kThemeTextColorUtilityWindowTitleActive, 0 }, /* 137 */ + { "UtilityWindowTitleInactiveText", 0, kThemeTextColorUtilityWindowTitleInactive, 0 }, /* 138 */ + { "PopupWindowTitleActiveText", 0, kThemeTextColorPopupWindowTitleActive, 0 }, /* 139 */ + { "PopupWindowTitleInactiveText", 0, kThemeTextColorPopupWindowTitleInactive, 0 }, /* 140 */ + { "RootMenuActiveText", 0, kThemeTextColorRootMenuActive, 0 }, /* 141 */ + { "RootMenuSelectedText", 0, kThemeTextColorRootMenuSelected, 0 }, /* 142 */ + { "RootMenuDisabledText", 0, kThemeTextColorRootMenuDisabled, 0 }, /* 143 */ + { "MenuItemActiveText", 0, kThemeTextColorMenuItemActive, 0 }, /* 144 */ + { "MenuItemSelectedText", 0, kThemeTextColorMenuItemSelected, 0 }, /* 145 */ + { "MenuItemDisabledText", 0, kThemeTextColorMenuItemDisabled, 0 }, /* 146 */ + { "PopupLabelActiveText", 0, kThemeTextColorPopupLabelActive, 0 }, /* 147 */ + { "PopupLabelInactiveText", 0, kThemeTextColorPopupLabelInactive, 0 }, /* 148 */ + { "TabFrontActiveText", 0, kThemeTextColorTabFrontActive, 0 }, /* 149 */ + { "TabNonFrontActiveText", 0, kThemeTextColorTabNonFrontActive, 0 }, /* 150 */ + { "TabNonFrontPressedText", 0, kThemeTextColorTabNonFrontPressed, 0 }, /* 151 */ + { "TabFrontInactiveText", 0, kThemeTextColorTabFrontInactive, 0 }, /* 152 */ + { "TabNonFrontInactiveText", 0, kThemeTextColorTabNonFrontInactive, 0 }, /* 153 */ + { "IconLabelSelectedText", 0, kThemeTextColorIconLabelSelected, 0 }, /* 154 */ + { "BevelButtonStickyActiveText", 0, kThemeTextColorBevelButtonStickyActive, 0 }, /* 155 */ + { "BevelButtonStickyInactiveText", 0, kThemeTextColorBevelButtonStickyInactive, 0 }, /* 156 */ + { "NotificationText", 0, kThemeTextColorNotification, 0 }, /* 157 */ + { "SystemDetailText", 0, kThemeTextColorSystemDetail, 0 }, /* 158 */ + { "WhiteText", 0, kThemeTextColorWhite, 0 }, /* 159 */ + { "TabPaneBackground", 0, 0, kThemeBackgroundTabPane }, /* 160 */ + { "PlacardBackground", 0, 0, kThemeBackgroundPlacard }, /* 161 */ + { "WindowHeaderBackground", 0, 0, kThemeBackgroundWindowHeader }, /* 162 */ + { "ListViewWindowHeaderBackground", 0, 0, kThemeBackgroundListViewWindowHeader }, /* 163 */ + { "SecondaryGroupBoxBackground", 0, 0, kThemeBackgroundSecondaryGroupBox }, /* 164 */ + { "MetalBackground", 0, 0, kThemeBackgroundMetal }, /* 165 */ + { NULL, 0, 0, 0 } +}; +#define MAX_PIXELCODE 165 + +/* + *---------------------------------------------------------------------- + * + * GetThemeFromPixelCode -- + * + * When given a pixel code corresponding to a theme system color, + * set one of brush, textColor or background to the corresponding + * Appearance Mgr theme constant. + * + * Results: + * Returns false if not a real pixel, true otherwise. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- */ -/* - * Stubbed out for OS X -static AuxCtlHandle defaultAuxCtlHandle = NULL; -*/ +static int +GetThemeFromPixelCode(unsigned char code, ThemeBrush *brush, + ThemeTextColor *textColor, ThemeBackgroundKind *background) +{ + if (code >= MIN_PIXELCODE && code <= MAX_PIXELCODE && code != PIXEL_MAGIC) { + *brush = systemColorMap[code - MIN_PIXELCODE].brush; + *textColor = systemColorMap[code - MIN_PIXELCODE].textColor; + *background = systemColorMap[code - MIN_PIXELCODE].background; + } else { + *brush = 0; + *textColor = 0; + *background = 0; + } + if (!*brush && !*textColor && !*background && code != PIXEL_MAGIC) { + return false; + } else { + return true; + } +} + /* - * Forward declarations for procedures defined later in this file: + *---------------------------------------------------------------------- + * + * GetThemeColor -- + * + * Get RGB color for a given system color or pixel value. + * + * Results: + * OSStatus + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- */ -static int GetControlPartColor _ANSI_ARGS_((short part, RGBColor *macColor)); -static int GetMenuPartColor _ANSI_ARGS_((int part, RGBColor *macColor)); -static int GetWindowPartColor _ANSI_ARGS_((short part, RGBColor *macColor)); +static OSStatus +GetThemeColor(unsigned long pixel, ThemeBrush brush, ThemeTextColor textColor, + ThemeBackgroundKind background, RGBColor *c) +{ + OSStatus err = noErr; + + if (brush) { + err = ChkErr(GetThemeBrushAsColor, + brush == kThemeBrushMenuBackgroundSelected ? + kThemeBrushFocusHighlight : brush, 32, true, c); + } else if (textColor) { + err = ChkErr(GetThemeTextColor, textColor, 32, true, c); + } else { + c->red = ((pixel >> 16) & 0xff) << 8; + c->green = ((pixel >> 8) & 0xff) << 8; + c->blue = ((pixel ) & 0xff) << 8; + } + return err; +} /* *---------------------------------------------------------------------- * * TkSetMacColor -- * - * Populates a Macintosh RGBColor structure from a X style - * pixel value. + * Populates a Macintosh RGBColor structure from a X style + * pixel value. * * Results: - * Returns false if not a real pixel, true otherwise. + * Returns false if not a real pixel, true otherwise. * * Side effects: - * The variable macColor is updated to the pixels value. + * The variable macColor is updated to the pixels value. * *---------------------------------------------------------------------- */ int TkSetMacColor( - unsigned long pixel, /* Pixel value to convert. */ - RGBColor *macColor) /* Mac color struct to modify. */ + unsigned long pixel, /* Pixel value to convert. */ + RGBColor *macColor) /* Mac color struct to modify. */ { - OSStatus err; - - switch (pixel >> 24) { - case HIGHLIGHT_PIXEL: - err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor, - 32, true, macColor); - if (err != noErr) { - LMGetHiliteRGB(macColor); - } - return true; - case HIGHLIGHT_SECONDARY_PIXEL: - err = GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, - 32, true, macColor); - if (err != noErr) { - LMGetHiliteRGB(macColor); - } - return true; - case HIGHLIGHT_ALTERNATE_PIXEL: - err = GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, - 32, true, macColor); - if (err != noErr) { - LMGetHiliteRGB(macColor); - } - return true; - case HIGHLIGHT_TEXT_PIXEL: - err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor, - 32, true, macColor); - if (err != noErr) { - LMGetHiliteRGB(macColor); - } - if ((macColor->red == 0) && (macColor->green == 0) - && (macColor->blue == 0)) { - macColor->red = macColor->green = macColor->blue = 0xFFFF; - } else { - macColor->red = macColor->green = macColor->blue = 0; - } - return true; - case CONTROL_TEXT_PIXEL: - GetControlPartColor(cTextColor, macColor); - return true; - case CONTROL_BODY_PIXEL: - GetControlPartColor(cBodyColor, macColor); - return true; - case CONTROL_FRAME_PIXEL: - GetControlPartColor(cFrameColor, macColor); - return true; - case WINDOW_BODY_PIXEL: - GetWindowPartColor(wContentColor, macColor); - return true; - case MENU_ACTIVE_PIXEL: - case MENU_ACTIVE_TEXT_PIXEL: - case MENU_BACKGROUND_PIXEL: - case MENU_DISABLED_PIXEL: - case MENU_TEXT_PIXEL: - return GetMenuPartColor((pixel >> 24), macColor); - case APPEARANCE_PIXEL: - return false; - case PIXEL_MAGIC: - default: - macColor->blue = (unsigned short) ((pixel & 0xFF) << 8); - macColor->green = (unsigned short) (((pixel >> 8) & 0xFF) << 8); - macColor->red = (unsigned short) (((pixel >> 16) & 0xFF) << 8); - return true; + OSStatus err = -1; + ThemeBrush brush; + ThemeTextColor textColor; + ThemeBackgroundKind background; + + if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor, + &background)) { + err = ChkErr(GetThemeColor, pixel, brush, textColor, background, + macColor); } + return (err == noErr); } -#if !TK_DRAW_IN_CONTEXT /* *---------------------------------------------------------------------- * - * TkMacOSXCompareColors -- + * TkMacOSXSetColorInPort -- * - * On Mac, color codes may specify symbolic values like "highlight - * foreground", but we really need the actual values to compare. - * Maybe see also: "TIP #154: Add Named Colors to Tk". + * Sets fore or back color in the current QD port from an X pixel + * value, and if the pixel code indicates a system color, sets + * the corresponding brush, textColor or background via + * Appearance mgr APIs. * * Results: - * Returns true if both colors are the same, false otherwise. + * None. * * Side effects: - * None. + * If penPat is non-NULL it is set to the forground color/pattern. * *---------------------------------------------------------------------- */ -int -TkMacOSXCompareColors( - unsigned long c1, - unsigned long c2) +void +TkMacOSXSetColorInPort(unsigned long pixel, int fg, PixPatHandle penPat) { - RGBColor col1, col2; - return TkSetMacColor(c1,&col1) && - TkSetMacColor(c1,&col2) && - !memcmp(&col1,&col2,sizeof(col1)); + OSStatus err; + RGBColor c; + ThemeBrush brush; + ThemeTextColor textColor; + ThemeBackgroundKind background; + + if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor, + &background)) { + CGrafPtr port; + + GetPort(&port); + err = ChkErr(GetThemeColor, pixel, brush, textColor, background, &c); + if (err == noErr) { + if (fg) { + RGBForeColor(&c); + if (penPat) { + MakeRGBPat(penPat, &c); + } + } else { + RGBBackColor(&c); + } + } + err = -1; + if (brush) { + err = ChkErr(SetThemeBackground, + brush == kThemeBrushMenuBackgroundSelected ? + kThemeBrushFocusHighlight : brush, 32, true); + } else if (textColor && fg) { + err = ChkErr(SetThemeTextColor, textColor, 32, true); + } else if (background) { + Rect bounds; + + GetPortBounds(port, &bounds); + err = ChkErr(ApplyThemeBackground, background, &bounds, + kThemeStateActive, 32, true); + } + if (penPat && err == noErr && !textColor) { + GetPortBackPixPat(port, penPat); + } + } } -#endif /* !TK_DRAW_IN_CONTEXT */ /* *---------------------------------------------------------------------- * - * Stub functions -- + * TkMacOSXSetColorInContext -- * - * These functions are just stubs for functions that either - * don't make sense on the Mac or have yet to be implemented. + * Sets fill and stroke color in the given CG context from an X + * pixel value, or if the pixel code indicates a system color, + * sets the corresponding brush, textColor or background via + * HITheme APIs if available or Appearance mgr APIs. * * Results: - * None. + * None. * * Side effects: - * These calls do nothing - which may not be expected. + * None. * *---------------------------------------------------------------------- */ -Status -XAllocColor( - Display *display, /* Display. */ - Colormap map, /* Not used. */ - XColor *colorPtr) /* XColor struct to modify. */ -{ - display->request++; - colorPtr->pixel = TkpGetPixel(colorPtr); - return 1; -} - -Colormap -XCreateColormap( - Display *display, /* Display. */ - Window window, /* X window. */ - Visual *visual, /* Not used. */ - int alloc) /* Not used. */ -{ - static Colormap index = 1; - - /* - * Just return a new value each time. - */ - return index++; -} - void -XFreeColormap( - Display* display, /* Display. */ - Colormap colormap) /* Colormap. */ +TkMacOSXSetColorInContext(unsigned long pixel, CGContextRef context) { -} + OSStatus err = -1; + RGBColor c; + ThemeBrush brush; + ThemeTextColor textColor; + ThemeBackgroundKind background; + + if (GetThemeFromPixelCode((pixel >> 24) & 0xff, &brush, &textColor, + &background)) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 + if (brush) { + if (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && HIThemeSetFill != NULL && HIThemeSetStroke != NULL +#endif + ) { + err = ChkErr(HIThemeSetFill, brush, NULL, context, + kHIThemeOrientationNormal); + if (err == noErr) { + err = ChkErr(HIThemeSetStroke, brush, NULL, context, + kHIThemeOrientationNormal); + } + } + } else if (textColor) { + if (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && HIThemeSetTextFill != NULL +#endif + ) { + err = ChkErr(HIThemeSetTextFill, textColor, NULL, context, + kHIThemeOrientationNormal); + } + } else +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + if (background) { + if (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030 + && CGContextGetClipBoundingBox != NULL + && HIThemeApplyBackground != NULL + && &kHIToolboxVersionNumber != NULL /* c.f. QA1377 */ + && kHIToolboxVersionNumber >= kHIToolboxVersionNumber10_3 +#endif + ) { + CGRect rect = CGContextGetClipBoundingBox(context); + HIThemeBackgroundDrawInfo info = { 0, kThemeStateActive, + background }; -void -XFreeColors( - Display* display, /* Display. */ - Colormap colormap, /* Colormap. */ - unsigned long* pixels, /* Array of pixels. */ - int npixels, /* Number of pixels. */ - unsigned long planes) /* Number of pixel planes. */ -{ - /* - * The Macintosh version of Tk uses TrueColor. Nothing - * needs to be done to release colors as there really is - * no colormap in the Tk sense. - */ + err = ChkErr(HIThemeApplyBackground, &rect, &info, context, + kHIThemeOrientationNormal); + } + } +#endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 */ + if (err == noErr) { + return; + } +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + /* + * Convert Appearance theme pattern to CGPattern: + */ + if ((brush || background) && CGPatternCreateWithImage != NULL) { + static PixPatHandle pixpat = NULL; + static GWorldPtr patGWorld = NULL; + static uint32_t bitmapInfo = 0; + const short patDim = 16; + const Rect bounds = {0, 0, patDim, patDim}; + CGrafPtr savePort; + Boolean portChanged; + PixMapHandle pixmap; + long rowbytes; + CGImageRef img; + CGColorSpaceRef rgbCspace; + CGDataProviderRef provider; + + if (!pixpat) { + pixpat = NewPixPat(); + err = ChkErr(NewGWorld, &patGWorld, 32, &bounds, NULL, NULL, 0 +#ifdef __LITTLE_ENDIAN__ + | kNativeEndianPixMap +#endif + ); + if (!pixpat || err != noErr || !patGWorld) { + Tcl_Panic("TkMacOSXSetColorInContext(): " + "pattern initialization failed !"); + } + bitmapInfo = +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 + (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && &kHIToolboxVersionNumber != NULL + && kHIToolboxVersionNumber >= kHIToolboxVersionNumber10_4 +#endif + ) ? kCGBitmapByteOrder32Host : +#endif + 0; + } + portChanged = QDSwapPort(patGWorld, &savePort); + TkMacOSXSetColorInPort(pixel, 1, pixpat); +#ifdef TK_MAC_DEBUG + Rect patBounds; + GetPixBounds((**pixpat).patMap, &patBounds); + if (patBounds.right > patDim || patBounds.bottom > patDim) { + Tcl_Panic("TkMacOSXSetColorInContext(): " + "pattern larger than expected !"); + } +#endif /* TK_MAC_DEBUG */ + FillCRect(&bounds, pixpat); + if (portChanged) { + QDSwapPort(savePort, NULL); + } + pixmap = GetPortPixMap(patGWorld); + rowbytes = GetPixRowBytes(pixmap); + provider = CGDataProviderCreateWithData(&patGWorld, + GetPixBaseAddr(pixmap), rowbytes * patDim, NULL); + rgbCspace = CGColorSpaceCreateDeviceRGB(); + img = CGImageCreate(patDim, patDim, 8, 32, + rowbytes, rgbCspace, kCGImageAlphaFirst | bitmapInfo, + provider, NULL, 0, kCGRenderingIntentDefault); + CGColorSpaceRelease(rgbCspace); + CGDataProviderRelease(provider); + if (img) { + CGPatternRef pat = CGPatternCreateWithImage(img, 2); + CGColorSpaceRef patCSpace = CGColorSpaceCreatePattern(NULL); + const float alpha = 1; + + CGContextSetFillColorSpace(context, patCSpace); + CGContextSetFillPattern(context, pat, &alpha); + CGContextSetStrokeColorSpace(context, patCSpace); + CGContextSetStrokePattern(context, pat, &alpha); + CGColorSpaceRelease(patCSpace); + CGPatternRelease(pat); + CGImageRelease(img); + return; + } + } +#endif /* MAC_OS_X_VERSION_MIN_REQUIRED < 1040 */ + err = ChkErr(GetThemeColor, pixel, brush, textColor, background, &c); + if (err == noErr) { + double r = c.red / 65535.0; + double g = c.green / 65535.0; + double b = c.blue / 65535.0; + + CGContextSetRGBFillColor(context, r, g, b, 1.0); + CGContextSetRGBStrokeColor(context, r, g, b, 1.0); + } + } else if (((pixel >> 24) & 0xff) == TRANSPARENT_PIXEL) { + CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0); + CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 0.0); + } } /* @@ -230,24 +529,24 @@ XFreeColors( * * TkpGetColor -- * - * Allocate a new TkColor for the color with the given name. + * Allocate a new TkColor for the color with the given name. * * Results: - * Returns a newly allocated TkColor, or NULL on failure. + * Returns a newly allocated TkColor, or NULL on failure. * * Side effects: - * May invalidate the colormap cache associated with tkwin upon - * allocating a new colormap entry. Allocates a new TkColor - * structure. + * May invalidate the colormap cache associated with tkwin upon + * allocating a new colormap entry. Allocates a new TkColor + * structure. * *---------------------------------------------------------------------- */ TkColor * TkpGetColor( - Tk_Window tkwin, /* Window in which color will be used. */ - Tk_Uid name) /* Name of color to allocated (in form - * suitable for passing to XParseColor). */ + Tk_Window tkwin, /* Window in which color will be used. */ + Tk_Uid name) /* Name of color to allocated (in form + * suitable for passing to XParseColor). */ { Display *display = Tk_Display(tkwin); Colormap colormap = Tk_Colormap(tkwin); @@ -259,112 +558,39 @@ TkpGetColor( * will do all the work. */ if (strncasecmp(name, "system", 6) == 0) { - OSStatus err; - int foundSystemColor = false; - RGBColor rgbValue; - char pixelCode = 0; - - if (!strcasecmp(name+6, "Highlight")) { - err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor, - 32, true, &rgbValue); - if (err != noErr) { - LMGetHiliteRGB(&rgbValue); - } - pixelCode = HIGHLIGHT_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "HighlightSecondary")) { - err = GetThemeBrushAsColor(kThemeBrushSecondaryHighlightColor, - 32, true, &rgbValue); - if (err != noErr) { - LMGetHiliteRGB(&rgbValue); - } - pixelCode = HIGHLIGHT_SECONDARY_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "HighlightAlternate")) { - err = GetThemeBrushAsColor(kThemeBrushAlternatePrimaryHighlightColor, - 32, true, &rgbValue); - if (err != noErr) { - LMGetHiliteRGB(&rgbValue); - } - pixelCode = HIGHLIGHT_ALTERNATE_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "HighlightText")) { - err = GetThemeBrushAsColor(kThemeBrushPrimaryHighlightColor, - 32, true, &rgbValue); - if (err != noErr) { - LMGetHiliteRGB(&rgbValue); + Tcl_Obj *strPtr = Tcl_NewStringObj(name+6, -1); + int idx, result; + + result = Tcl_GetIndexFromObjStruct(NULL, strPtr, systemColorMap, + sizeof(struct SystemColorMapEntry), NULL, TCL_EXACT, &idx); + Tcl_DecrRefCount(strPtr); + if (result == TCL_OK) { + OSStatus err; + RGBColor c; + unsigned char pixelCode = idx + MIN_PIXELCODE; + ThemeBrush brush = systemColorMap[idx].brush; + ThemeTextColor textColor = systemColorMap[idx].textColor; + ThemeBackgroundKind background = systemColorMap[idx].background; + + err = ChkErr(GetThemeColor, 0, brush, textColor, background, &c); + if (err == noErr) { + color.red = c.red; + color.green = c.green; + color.blue = c.blue; + color.pixel = ((((((pixelCode << 8) + | ((color.red >> 8) & 0xff)) << 8) + | ((color.green >> 8) & 0xff)) << 8) + | ((color.blue >> 8) & 0xff)); + goto validXColor; } - if ((rgbValue.red == 0) && (rgbValue.green == 0) - && (rgbValue.blue == 0)) { - rgbValue.red = rgbValue.green = rgbValue.blue = 0xFFFF; - } else { - rgbValue.red = rgbValue.green = rgbValue.blue = 0; - } - pixelCode = HIGHLIGHT_TEXT_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "ButtonText")) { - GetControlPartColor(cTextColor, &rgbValue); - pixelCode = CONTROL_TEXT_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "ButtonFace")) { - GetControlPartColor(cBodyColor, &rgbValue); - pixelCode = CONTROL_BODY_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "ButtonFrame")) { - GetControlPartColor(cFrameColor, &rgbValue); - pixelCode = CONTROL_FRAME_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "WindowBody")) { - GetWindowPartColor(wContentColor, &rgbValue); - pixelCode = WINDOW_BODY_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "MenuActive")) { - GetMenuPartColor(MENU_ACTIVE_PIXEL, &rgbValue); - pixelCode = MENU_ACTIVE_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "MenuActiveText")) { - GetMenuPartColor(MENU_ACTIVE_TEXT_PIXEL, &rgbValue); - pixelCode = MENU_ACTIVE_TEXT_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "Menu")) { - GetMenuPartColor(MENU_BACKGROUND_PIXEL, &rgbValue); - pixelCode = MENU_BACKGROUND_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "MenuDisabled")) { - GetMenuPartColor(MENU_DISABLED_PIXEL, &rgbValue); - pixelCode = MENU_DISABLED_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "MenuText")) { - GetMenuPartColor(MENU_TEXT_PIXEL, &rgbValue); - pixelCode = MENU_TEXT_PIXEL; - foundSystemColor = true; - } else if (!strcasecmp(name+6, "AppearanceColor")) { - color.red = 0; - color.green = 0; - color.blue = 0; - pixelCode = APPEARANCE_PIXEL; - foundSystemColor = true; - } - - if (foundSystemColor) { - color.red = rgbValue.red; - color.green = rgbValue.green; - color.blue = rgbValue.blue; - color.pixel = ((((((pixelCode << 8) - | ((color.red >> 8) & 0xff)) << 8) - | ((color.green >> 8) & 0xff)) << 8) - | ((color.blue >> 8) & 0xff)); - - tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); - tkColPtr->color = color; - return tkColPtr; - } + } } - + if (XParseColor(display, colormap, name, &color) == 0) { - return (TkColor *) NULL; + return (TkColor *) NULL; } - + +validXColor: tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); tkColPtr->color = color; @@ -376,28 +602,28 @@ TkpGetColor( * * TkpGetColorByValue -- * - * Given a desired set of red-green-blue intensities for a color, - * locate a pixel value to use to draw that color in a given - * window. + * Given a desired set of red-green-blue intensities for a color, + * locate a pixel value to use to draw that color in a given + * window. * * Results: - * The return value is a pointer to an TkColor structure that - * indicates the closest red, blue, and green intensities available - * to those specified in colorPtr, and also specifies a pixel - * value to use to draw in that color. + * The return value is a pointer to an TkColor structure that + * indicates the closest red, blue, and green intensities available + * to those specified in colorPtr, and also specifies a pixel + * value to use to draw in that color. * * Side effects: - * May invalidate the colormap cache for the specified window. - * Allocates a new TkColor structure. + * May invalidate the colormap cache for the specified window. + * Allocates a new TkColor structure. * *---------------------------------------------------------------------- */ TkColor * TkpGetColorByValue( - Tk_Window tkwin, /* Window in which color will be used. */ - XColor *colorPtr) /* Red, green, and blue fields indicate - * desired color. */ + Tk_Window tkwin, /* Window in which color will be used. */ + XColor *colorPtr) /* Red, green, and blue fields indicate + * desired color. */ { TkColor *tkColPtr = (TkColor *) ckalloc(sizeof(TkColor)); @@ -408,123 +634,98 @@ TkpGetColorByValue( return tkColPtr; } +#if !TK_DRAW_IN_CONTEXT /* *---------------------------------------------------------------------- * - * GetControlPartColor -- + * TkMacOSXCompareColors -- * - * Given a part number this function will return the standard - * system default color for that part. On MacOS X this uses the - * Theme Brushes to find the active color, though for now, only - * the "Text Color" is supported. + * On Mac, color codes may specify symbolic values like "highlight + * foreground", but we really need the actual values to compare. + * Maybe see also: "TIP #154: Add Named Colors to Tk". * * Results: - * True if a color is found, false otherwise. + * Returns true if both colors are the same, false otherwise. * * Side effects: - * If a color is found then the RGB variable will be changed to - * the parts color. + * None. * *---------------------------------------------------------------------- */ -static int -GetControlPartColor( - short part, /* Part code. */ - RGBColor *macColor) /* Pointer to Mac color. */ -{ - int retVal = false; - OSErr err; - - switch (part) { - case cTextColor: - err = GetThemeTextColor(kThemeTextColorPushButtonActive, 32, - true, macColor); - if (err == noErr) { - retVal = true; - } - break; - default: - retVal = false; - } - return retVal; +int +TkMacOSXCompareColors( + unsigned long c1, + unsigned long c2) +{ + RGBColor col1, col2; + return TkSetMacColor(c1,&col1) && + TkSetMacColor(c1,&col2) && + !memcmp(&col1,&col2,sizeof(col1)); } +#endif /* !TK_DRAW_IN_CONTEXT */ /* *---------------------------------------------------------------------- * - * GetWindowPartColor -- + * Stub functions -- * - * Given a part number this function will return the standard - * system default color for that part. It does this by looking - * in the system's 'wctb' resource. + * These functions are just stubs for functions that either + * don't make sense on the Mac or have yet to be implemented. * * Results: - * True if a color is found, false otherwise. + * None. * * Side effects: - * If a color is found then the RGB variable will be changed to - * the parts color. + * These calls do nothing - which may not be expected. * *---------------------------------------------------------------------- */ -static int -GetWindowPartColor( - short part, /* Part code. */ - RGBColor *macColor) /* Pointer to Mac color. */ -{ - short index; - WCTabHandle wcTab; - - if (part == wContentColor) { - GetThemeBrushAsColor(kThemeBrushDocumentWindowBackground, - 0xFFFF, true, macColor); - return true; - } else { - wcTab = (WCTabHandle) GetResource('wctb', 0); - if(wcTab && (ResError() == noErr)) { - for(index = 0; index <= (**wcTab).ctSize; index++) { - if((**wcTab).ctTable[index].value == part) { - *macColor = (**wcTab).ctTable[index].rgb; - return true; - } - } - } - return false; - } +Status +XAllocColor( + Display *display, /* Display. */ + Colormap map, /* Not used. */ + XColor *colorPtr) /* XColor struct to modify. */ +{ + display->request++; + colorPtr->pixel = TkpGetPixel(colorPtr); + return 1; } - -/* - *---------------------------------------------------------------------- - * - * GetMenuPartColor -- - * - * Given a magic pixel value, returns the RGB color associated - * with it by looking the value up in the system's 'mctb' resource. - * - * Results: - * True if a color is found, false otherwise. - * - * Side effects: - * If a color is found then the RGB variable will be changed to - * the parts color. - * - *---------------------------------------------------------------------- - */ -static int -GetMenuPartColor( - int pixel, /* The magic pixel value */ - RGBColor *macColor) /* Pointer to Mac color */ -{ - - /* Under Appearance, we don't want to set any menu colors when we - are asked for the standard menu colors. So we return false (which - means don't use this color... */ - - macColor->red = 0xFFFF; - macColor->green = 0; - macColor->blue = 0; - return false; +Colormap +XCreateColormap( + Display *display, /* Display. */ + Window window, /* X window. */ + Visual *visual, /* Not used. */ + int alloc) /* Not used. */ +{ + static Colormap index = 1; + + /* + * Just return a new value each time. + */ + return index++; +} + +void +XFreeColormap( + Display* display, /* Display. */ + Colormap colormap) /* Colormap. */ +{ +} + +void +XFreeColors( + Display* display, /* Display. */ + Colormap colormap, /* Colormap. */ + unsigned long* pixels, /* Array of pixels. */ + int npixels, /* Number of pixels. */ + unsigned long planes) /* Number of pixel planes. */ +{ + /* + * The Macintosh version of Tk uses TrueColor. Nothing + * needs to be done to release colors as there really is + * no colormap in the Tk sense. + */ } Index: macosx/tkMacOSXCursor.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXCursor.c,v retrieving revision 1.8 diff -u -p -r1.8 tkMacOSXCursor.c --- macosx/tkMacOSXCursor.c 20 Jul 2006 06:24:16 -0000 1.8 +++ macosx/tkMacOSXCursor.c 15 Mar 2007 02:42:09 -0000 @@ -1,10 +1,11 @@ -/* +/* * tkMacOSXCursor.c -- * - * This file contains Macintosh specific cursor related routines. + * This file contains Macintosh specific cursor related routines. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -20,10 +21,11 @@ * color resource cursors, & normal cursors. */ -#define THEME 0 /* Theme cursors */ -#define ANIMATED 1 /* Animated theme cursors */ -#define COLOR 2 /* Cursors of type crsr. */ -#define NORMAL 3 /* Cursors of type CURS. */ +#define NONE -1 /* Hidden cursor */ +#define THEME 0 /* Theme cursors */ +#define ANIMATED 1 /* Animated theme cursors */ +#define COLOR 2 /* Cursors of type crsr. */ +#define NORMAL 3 /* Cursors of type CURS. */ /* * The following data structure contains the system specific data @@ -31,14 +33,14 @@ */ typedef struct { - TkCursor info; /* Generic cursor info used by tkCursor.c */ - Handle macCursor; /* Resource containing Macintosh cursor. - * For theme cursors, this is -1. */ - int type; /* Type of Mac cursor: for theme cursors - * this is the theme cursor constant, - * otherwise one of crsr or CURS */ - int count; /* For animating cursors, the count for the - cursor. */ + TkCursor info; /* Generic cursor info used by tkCursor.c */ + Handle macCursor; /* Resource containing Macintosh cursor. + * For theme cursors, this is -1. */ + int type; /* Type of Mac cursor: for theme cursors + * this is the theme cursor constant, + * otherwise one of crsr or CURS */ + int count; /* For animating cursors, the count for the + * cursor. */ } TkMacOSXCursor; /* @@ -47,32 +49,45 @@ typedef struct { */ struct CursorName { - char *name; + const char *name; int id; }; +static struct CursorName noneCursorName = {"none", 0}; + static struct CursorName themeCursorNames[] = { - {"ibeam", kThemeIBeamCursor}, - {"text", kThemeIBeamCursor}, - {"xterm", kThemeIBeamCursor}, - {"cross", kThemeCrossCursor}, - {"crosshair", kThemeCrossCursor}, - {"cross-hair", kThemeCrossCursor}, - {"plus", kThemePlusCursor}, - {"arrow", kThemeArrowCursor}, - {"closedhand", kThemeClosedHandCursor}, - {"openhand", kThemeOpenHandCursor}, - {"pointinghand", kThemePointingHandCursor}, - {NULL, 0} + {"arrow", kThemeArrowCursor}, + {"copyarrow", kThemeCopyArrowCursor}, + {"aliasarrow", kThemeAliasArrowCursor}, + {"contextualmenuarrow", kThemeContextualMenuArrowCursor}, + {"ibeam", kThemeIBeamCursor}, + {"text", kThemeIBeamCursor}, + {"xterm", kThemeIBeamCursor}, + {"cross", kThemeCrossCursor}, + {"crosshair", kThemeCrossCursor}, + {"cross-hair", kThemeCrossCursor}, + {"plus", kThemePlusCursor}, + {"closedhand", kThemeClosedHandCursor}, + {"openhand", kThemeOpenHandCursor}, + {"pointinghand", kThemePointingHandCursor}, + {"resizeleft", kThemeResizeLeftCursor}, + {"resizeright", kThemeResizeRightCursor}, + {"resizeleftright", kThemeResizeLeftRightCursor}, + {"resizeup", kThemeResizeUpCursor}, + {"resizedown", kThemeResizeDownCursor}, + {"resizeupdown", kThemeResizeUpDownCursor}, + {"notallowed", kThemeNotAllowedCursor}, + {"poof", kThemePoofCursor}, + {NULL, 0} }; static struct CursorName animatedThemeCursorNames[] = { - {"watch", kThemeWatchCursor}, - {"countinguphand", kThemeCountingUpHandCursor}, + {"watch", kThemeWatchCursor}, + {"countinguphand", kThemeCountingUpHandCursor}, {"countingdownhand", kThemeCountingDownHandCursor}, {"countingupanddownhand", kThemeCountingUpAndDownHandCursor}, - {"spinning", kThemeSpinningCursor}, - {NULL, 0} + {"spinning", kThemeSpinningCursor}, + {NULL, 0} }; /* @@ -80,86 +95,82 @@ static struct CursorName animatedThemeCu */ static TkMacOSXCursor * gCurrentCursor = NULL; /* A pointer to the current - * cursor. */ -static int gResizeOverride = false; /* A boolean indicating whether - * we should use the resize - * cursor during installations. */ -static int gTkOwnsCursor = true; /* A boolean indicating whether - Tk owns the cursor. If not (for - instance, in the case where a Tk - window is embedded in another app's - window, and the cursor is out of - the tk window, we will not attempt - to adjust the cursor */ + * cursor. */ +static int gResizeOverride = false; /* A boolean indicating whether + * we should use the resize + * cursor during installations. */ +static int gTkOwnsCursor = true; /* A boolean indicating whether + * Tk owns the cursor. If not (for + * instance, in the case where a Tk + * window is embedded in another app's + * window, and the cursor is out of + * the tk window, we will not attempt + * to adjust the cursor */ /* * Declarations of procedures local to this file */ -static void FindCursorByName _ANSI_ARGS_ ((TkMacOSXCursor *macCursorPtr, - CONST char *string)); +static void FindCursorByName(TkMacOSXCursor *macCursorPtr, const char *string); + /* *---------------------------------------------------------------------- * * FindCursorByName -- * - * Retrieve a system cursor by name, and fill the macCursorPtr - * structure. If the cursor cannot be found, the macCursor field - * will be NULL. The function first attempts to load a color - * cursor. If that fails it will attempt to load a black & white - * cursor. + * Retrieve a system cursor by name, and fill the macCursorPtr + * structure. If the cursor cannot be found, the macCursor field + * will be NULL. The function first attempts to load a color + * cursor. If that fails it will attempt to load a black & white + * cursor. * * Results: - * Fills the macCursorPtr record. + * Fills the macCursorPtr record. * * Side effects: - * None + * None * *---------------------------------------------------------------------- */ - -void + +void FindCursorByName( TkMacOSXCursor *macCursorPtr, - CONST char *string) + const char *string) { Handle resource; Str255 curName; int destWrote, inCurLen; + Tcl_Encoding encoding; inCurLen = strlen(string); if (inCurLen > 255) { - return; + return; } /* * macRoman is the encoding that the resource fork uses. */ - Tcl_UtfToExternal(NULL, Tcl_GetEncoding(NULL, "macRoman"), string, - inCurLen, 0, NULL, - (char *) &curName[1], - 255, NULL, &destWrote, NULL); /* Internalize native */ + encoding = Tcl_GetEncoding(NULL, "macRoman"); + Tcl_UtfToExternal(NULL, encoding, string, inCurLen, 0, NULL, + (char *) &curName[1], 255, NULL, &destWrote, NULL); curName[0] = destWrote; + Tcl_FreeEncoding(encoding); resource = GetNamedResource('crsr', curName); - - if (resource != NULL) { - short id; - Str255 theName; - ResType theType; - - HLock(resource); - GetResInfo(resource, &id, &theType, theName); - HUnlock(resource); - macCursorPtr->macCursor = (Handle) GetCCursor(id); - macCursorPtr->type = COLOR; - } - - if (resource == NULL) { - macCursorPtr->macCursor = GetNamedResource('CURS', curName); - macCursorPtr->type = NORMAL; + if (resource) { + short id; + Str255 theName; + ResType theType; + + GetResInfo(resource, &id, &theType, theName); + macCursorPtr->macCursor = (Handle) GetCCursor(id); + macCursorPtr->type = COLOR; + } else { + macCursorPtr->macCursor = GetNamedResource('CURS', curName); + macCursorPtr->type = NORMAL; } } @@ -168,28 +179,28 @@ FindCursorByName( * * TkGetCursorByName -- * - * Retrieve a system cursor by name. + * Retrieve a system cursor by name. * * Results: - * Returns a new cursor, or NULL on errors. + * Returns a new cursor, or NULL on errors. * * Side effects: - * Allocates a new cursor. + * Allocates a new cursor. * *---------------------------------------------------------------------- */ TkCursor * TkGetCursorByName( - Tcl_Interp *interp, /* Interpreter to use for error reporting. */ - Tk_Window tkwin, /* Window in which cursor will be used. */ - Tk_Uid string) /* Description of cursor. See manual entry - * for details on legal syntax. */ + Tcl_Interp *interp, /* Interpreter to use for error reporting. */ + Tk_Window tkwin, /* Window in which cursor will be used. */ + Tk_Uid string) /* Description of cursor. See manual entry + * for details on legal syntax. */ { struct CursorName *namePtr; TkMacOSXCursor *macCursorPtr; int count = -1; - + macCursorPtr = (TkMacOSXCursor *) ckalloc(sizeof(TkMacOSXCursor)); macCursorPtr->info.cursor = (Tk_Cursor) macCursorPtr; @@ -199,71 +210,68 @@ TkGetCursorByName( * attempt to load the cursor as a named Mac resource. */ - for (namePtr = themeCursorNames; namePtr->name != NULL; namePtr++) { - if (strcmp(namePtr->name, string) == 0) { - macCursorPtr->count = -1; - macCursorPtr->macCursor = (Handle) namePtr; - macCursorPtr->type = THEME; - break; - } - } - - if (namePtr->name == NULL) { - for (namePtr = animatedThemeCursorNames; - namePtr->name != NULL; namePtr++) { - int namelen = strlen (namePtr->name); - if (strncmp(namePtr->name, string, namelen) == 0) { - const char *numPtr = string + namelen; - if (*numPtr == '\0') { - count = -1; - } else { - int result; - result = Tcl_GetInt(NULL, numPtr, &count); - if (result != TCL_OK) { - continue; - } - } - macCursorPtr->macCursor = (Handle) namePtr; - macCursorPtr->type = ANIMATED; - macCursorPtr->count = count; - break; - } - } + if (strcmp(noneCursorName.name, string) == 0) { + namePtr = &noneCursorName; + macCursorPtr->type = NONE; + } else { + for (namePtr = themeCursorNames; namePtr->name != NULL; namePtr++) { + if (strcmp(namePtr->name, string) == 0) { + macCursorPtr->type = THEME; + break; + } + } } - - if (namePtr->name == NULL) { - FindCursorByName(macCursorPtr, string); + for (namePtr = animatedThemeCursorNames; + namePtr->name != NULL; namePtr++) { + int namelen = strlen (namePtr->name); + if (strncmp(namePtr->name, string, namelen) == 0) { + const char *numPtr = string + namelen; + if (*numPtr) { + int result = Tcl_GetInt(NULL, numPtr, &count); + if (result != TCL_OK) { + continue; + } + } + macCursorPtr->type = ANIMATED; + break; + } + } + } + + if (namePtr->name != NULL) { + macCursorPtr->macCursor = (Handle) namePtr; + macCursorPtr->count = count; + } else { + FindCursorByName(macCursorPtr, string); - if (macCursorPtr->macCursor == NULL) { - CONST char **argv; - int argc, err; - - /* - * The user may be trying to specify an XCursor with fore - * & back colors. We don't want this to be an error, so pick - * off the first word, and try again. - */ - - err = Tcl_SplitList(interp, string, &argc, &argv); - if (err == TCL_OK ) { - if (argc > 1) { - FindCursorByName(macCursorPtr, argv[0]); - } - - ckfree((char *) argv); - } - } + if (macCursorPtr->macCursor == NULL) { + const char **argv; + int argc; + + /* + * The user may be trying to specify an XCursor with fore + * & back colors. We don't want this to be an error, so pick + * off the first word, and try again. + */ + + if (Tcl_SplitList(interp, string, &argc, &argv) == TCL_OK ) { + if (argc > 1) { + FindCursorByName(macCursorPtr, argv[0]); + } + ckfree((char *) argv); + } + } } if (macCursorPtr->macCursor == NULL) { - ckfree((char *)macCursorPtr); - Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"", - (char *) NULL); - return NULL; + ckfree((char *)macCursorPtr); + Tcl_AppendResult(interp, "bad cursor spec \"", string, "\"", + (char *) NULL); + return NULL; } else { - return (TkCursor *) macCursorPtr; + return (TkCursor *) macCursorPtr; } } @@ -272,26 +280,26 @@ TkGetCursorByName( * * TkCreateCursorFromData -- * - * Creates a cursor from the source and mask bits. + * Creates a cursor from the source and mask bits. * * Results: - * Returns a new cursor, or NULL on errors. + * Returns a new cursor, or NULL on errors. * * Side effects: - * Allocates a new cursor. + * Allocates a new cursor. * *---------------------------------------------------------------------- */ TkCursor * TkCreateCursorFromData( - Tk_Window tkwin, /* Window in which cursor will be used. */ - CONST char *source, /* Bitmap data for cursor shape. */ - CONST char *mask, /* Bitmap data for cursor mask. */ - int width, int height, /* Dimensions of cursor. */ - int xHot, int yHot, /* Location of hot-spot in cursor. */ - XColor fgColor, /* Foreground color for cursor. */ - XColor bgColor) /* Background color for cursor. */ + Tk_Window tkwin, /* Window in which cursor will be used. */ + CONST char *source, /* Bitmap data for cursor shape. */ + CONST char *mask, /* Bitmap data for cursor mask. */ + int width, int height, /* Dimensions of cursor. */ + int xHot, int yHot, /* Location of hot-spot in cursor. */ + XColor fgColor, /* Foreground color for cursor. */ + XColor bgColor) /* Background color for cursor. */ { return NULL; } @@ -301,14 +309,14 @@ TkCreateCursorFromData( * * TkpFreeCursor -- * - * This procedure is called to release a cursor allocated by - * TkGetCursorByName. + * This procedure is called to release a cursor allocated by + * TkGetCursorByName. * * Results: - * None. + * None. * * Side effects: - * The cursor data structure is deallocated. + * The cursor data structure is deallocated. * *---------------------------------------------------------------------- */ @@ -320,32 +328,33 @@ TkpFreeCursor( TkMacOSXCursor *macCursorPtr = (TkMacOSXCursor *) cursorPtr; switch (macCursorPtr->type) { - case COLOR: - DisposeCCursor((CCrsrHandle) macCursorPtr->macCursor); - break; - case NORMAL: - ReleaseResource(macCursorPtr->macCursor); - break; + case COLOR: + DisposeCCursor((CCrsrHandle) macCursorPtr->macCursor); + break; + case NORMAL: + ReleaseResource(macCursorPtr->macCursor); + break; } if (macCursorPtr == gCurrentCursor) { - gCurrentCursor = NULL; + gCurrentCursor = NULL; } } + /* *---------------------------------------------------------------------- * * TkMacOSXInstallCursor -- * - * Installs either the current cursor as defined by TkpSetCursor - * or a resize cursor as the cursor the Macintosh should currently - * display. + * Installs either the current cursor as defined by TkpSetCursor + * or a resize cursor as the cursor the Macintosh should currently + * display. * * Results: - * None. + * None. * * Side effects: - * Changes the Macintosh mouse cursor. + * Changes the Macintosh mouse cursor. * *---------------------------------------------------------------------- */ @@ -358,45 +367,56 @@ TkMacOSXInstallCursor( CCrsrHandle ccursor; CursHandle cursor; static unsigned int cursorStep = 0; - + static int cursorHidden = 0; + int cursorNone = 0; + gResizeOverride = resizeOverride; if (resizeOverride) { - cursor = (CursHandle) GetNamedResource('CURS', "\presize"); - if (cursor) { - SetCursor(*cursor); - } else { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"Resize cursor failed, %d\n", ResError()); -#endif - } + cursor = (CursHandle) GetNamedResource('CURS', "\presize"); + if (cursor) { + SetCursor(*cursor); + } else { + TkMacOSXDbgMsg("Resize cursor failed: %d", ResError()); + } } else if (macCursorPtr == NULL) { - SetThemeCursor(kThemeArrowCursor); + SetThemeCursor(kThemeArrowCursor); } else { - struct CursorName *namePtr; - switch (macCursorPtr->type) { - case THEME: - namePtr = (struct CursorName *) macCursorPtr->macCursor; - SetThemeCursor( - namePtr->id); - break; - case ANIMATED: - namePtr = (struct CursorName *) macCursorPtr->macCursor; - if (macCursorPtr->count == -1) { - SetAnimatedThemeCursor(namePtr->id, cursorStep++); - } else { - SetAnimatedThemeCursor(namePtr->id, macCursorPtr->count); - } - break; - case COLOR: - ccursor = (CCrsrHandle) macCursorPtr->macCursor; - SetCCursor(ccursor); - break; - case NORMAL: - cursor = (CursHandle) macCursorPtr->macCursor; - SetCursor(*cursor); - break; - } + struct CursorName *namePtr; + switch (macCursorPtr->type) { + case NONE: + if (!cursorHidden) { + cursorHidden = 1; + HideCursor(); + } + cursorNone = 1; + break; + case THEME: + namePtr = (struct CursorName *) macCursorPtr->macCursor; + SetThemeCursor( + namePtr->id); + break; + case ANIMATED: + namePtr = (struct CursorName *) macCursorPtr->macCursor; + if (macCursorPtr->count == -1) { + SetAnimatedThemeCursor(namePtr->id, cursorStep++); + } else { + SetAnimatedThemeCursor(namePtr->id, macCursorPtr->count); + } + break; + case COLOR: + ccursor = (CCrsrHandle) macCursorPtr->macCursor; + SetCCursor(ccursor); + break; + case NORMAL: + cursor = (CursHandle) macCursorPtr->macCursor; + SetCursor(*cursor); + break; + } + } + if (cursorHidden && !cursorNone) { + cursorHidden = 0; + ShowCursor(); } } @@ -405,13 +425,13 @@ TkMacOSXInstallCursor( * * TkpSetCursor -- * - * Set the current cursor and install it. + * Set the current cursor and install it. * * Results: - * None. + * None. * * Side effects: - * Changes the current cursor. + * Changes the current cursor. * *---------------------------------------------------------------------- */ @@ -421,30 +441,30 @@ TkpSetCursor( TkpCursor cursor) { int cursorChanged = 1; - + if (!gTkOwnsCursor) { - return; + return; } - + if (cursor == None) { - /* - * This is a little tricky. We can't really tell whether - * gCurrentCursor is NULL because it was NULL last time around - * or because we just freed the current cursor. So if the input - * cursor is NULL, we always need to reset it, we can't trust the - * cursorChanged logic. - */ - - gCurrentCursor = NULL; + /* + * This is a little tricky. We can't really tell whether + * gCurrentCursor is NULL because it was NULL last time around + * or because we just freed the current cursor. So if the input + * cursor is NULL, we always need to reset it, we can't trust the + * cursorChanged logic. + */ + + gCurrentCursor = NULL; } else { - if (gCurrentCursor == (TkMacOSXCursor *) cursor) { - cursorChanged = 0; - } - gCurrentCursor = (TkMacOSXCursor *) cursor; + if (gCurrentCursor == (TkMacOSXCursor *) cursor) { + cursorChanged = 0; + } + gCurrentCursor = (TkMacOSXCursor *) cursor; } if (Tk_MacOSXIsAppInFront() && cursorChanged) { - TkMacOSXInstallCursor(gResizeOverride); + TkMacOSXInstallCursor(gResizeOverride); } } @@ -453,13 +473,13 @@ TkpSetCursor( * * Tk_MacOSXTkOwnsCursor -- * - * Sets whether Tk has the right to adjust the cursor. + * Sets whether Tk has the right to adjust the cursor. * * Results: - * None. + * None. * * Side effects: - * May keep Tk from changing the cursor. + * May keep Tk from changing the cursor. * *---------------------------------------------------------------------- */ Index: macosx/tkMacOSXDebug.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDebug.c,v retrieving revision 1.11 diff -u -p -r1.11 tkMacOSXDebug.c --- macosx/tkMacOSXDebug.c 7 Mar 2007 23:46:34 -0000 1.11 +++ macosx/tkMacOSXDebug.c 15 Mar 2007 02:42:10 -0000 @@ -66,13 +66,13 @@ #include typedef struct { - EventKind kind; - char * name; + EventKind kind; + const char * name; } MyEventName; typedef struct { - EventClass c; - MyEventName * names; + EventClass c; + MyEventName * names; } MyEventNameList; static MyEventName windowEventNames [] = { @@ -254,21 +254,22 @@ static MyEventName classicEventNames [] #endif /* TK_MACOSXDEBUG_UNUSED */ MODULE_SCOPE char * -TkMacOSXCarbonEventToAscii(EventRef eventRef, char * buf) +TkMacOSXCarbonEventToAscii(EventRef eventRef) { EventClass eventClass; - EventKind eventKind; + EventKind eventKind; MyEventNameList * list = eventNameList; - MyEventName * names = NULL; - int * iPtr = ( int * )buf; - char * iBuf = buf; + MyEventName * names = NULL; + static char str[256]; + char *buf = str; + int *iPtr = (int*)str; int found = 0; eventClass = GetEventClass(eventRef); eventKind = GetEventKind(eventRef); *iPtr = eventClass; - buf [ 4 ] = 0; + buf[4] = 0; strcat(buf, " "); buf += strlen(buf); while (list->names && (!names) ) { @@ -278,23 +279,18 @@ TkMacOSXCarbonEventToAscii(EventRef even list++; } } - if (names) { - found = 0; - while (names->name && !found) { - if (eventKind == names->kind) { - sprintf(buf, "%-20s", names->name); - found = 1; - } else { - names++; - } - } - if (!found) { - sprintf(buf, "%-20d", eventKind ); - } - } else { - sprintf(buf, "%-20d", eventKind ); + while (names && names->name) { + if (eventKind == names->kind) { + snprintf(buf, 250, "%-20s", names->name); + break; + } else { + names++; + } + } + if (!found) { + snprintf(buf, 250, "%-20d", eventKind); } - return iBuf; + return str; } #ifdef TK_MACOSXDEBUG_UNUSED @@ -367,14 +363,13 @@ TkMacOSXClassicEventToAscii(EventRecord MODULE_SCOPE void TkMacOSXPrintPoint(char * tag, Point * p ) { - fprintf(stderr,"%s %4d %4d\n", - tag,p->h,p->v ); + TkMacOSXDbgMsg("%s %4d %4d", tag,p->h,p->v ); } MODULE_SCOPE void TkMacOSXPrintRect(char * tag, Rect * r ) { - fprintf(stderr,"%s %4d %4d %4d %4d (%dx%d)\n", + TkMacOSXDbgMsg("%s %4d %4d %4d %4d (%dx%d)", tag, r->left, r->top, r->right, r->bottom, r->right - r->left + 1, r->bottom - r->top + 1); } @@ -393,7 +388,7 @@ TkMacOSXPrintWindowTitle(char * tag, Win Str255 title; GetWTitle(window,title); title [title[0] + 1] = 0; - fprintf(stderr, "%s %s\n", tag, title +1 ); + TkMacOSXDbgMsg("%s %s", tag, title +1 ); } typedef struct { @@ -520,7 +515,7 @@ TkMacOSXGetNamedDebugSymbol(const char* struct segment_command *sg = NULL; uint32_t j, m, nsect = 0, txtsectx = 0; - lc = (struct load_command*)((char *) mh + + lc = (struct load_command*)((const char*) mh + sizeof(struct mach_header)); m = mh->ncmds; for (j = 0; j < m; j++) { @@ -573,7 +568,7 @@ TkMacOSXGetNamedDebugSymbol(const char* sym->n_sect == txtsectx && strx > 0 && (uint32_t) strx < strsize && strcmp(strings + strx, symbol) == 0) { - addr = (void*) sym->n_value + slide; + addr = (char*) sym->n_value + slide; break; } sym++; Index: macosx/tkMacOSXDebug.h =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDebug.h,v retrieving revision 1.9 diff -u -p -r1.9 tkMacOSXDebug.h --- macosx/tkMacOSXDebug.h 31 Oct 2006 22:33:34 -0000 1.9 +++ macosx/tkMacOSXDebug.h 15 Mar 2007 02:42:10 -0000 @@ -60,12 +60,9 @@ #include "tkMacOSXInt.h" #endif -/* The following define enables printing of debug messages to stderr: */ -/* #define TK_MAC_DEBUG 1 */ - #ifdef TK_MAC_DEBUG -MODULE_SCOPE char* TkMacOSXCarbonEventToAscii(EventRef eventRef, char * buf ); +MODULE_SCOPE char* TkMacOSXCarbonEventToAscii(EventRef eventRef); #ifdef TK_MACOSXDEBUG_UNUSED MODULE_SCOPE char* TkMacOSXCarbonEventKindToAscii(EventRef eventRef, char * buf ); Index: macosx/tkMacOSXDefault.h =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDefault.h,v retrieving revision 1.11 diff -u -p -r1.11 tkMacOSXDefault.h --- macosx/tkMacOSXDefault.h 10 Sep 2006 17:06:32 -0000 1.11 +++ macosx/tkMacOSXDefault.h 15 Mar 2007 02:42:10 -0000 @@ -7,6 +7,7 @@ * Copyright (c) 1991-1994 The Regents of the University of California. * Copyright (c) 1994-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -28,17 +29,16 @@ * DISABLED - Foreground color when widget is disabled. */ -#define BLACK "Black" -#define WHITE "White" - -#define NORMAL_BG "systemWindowBody" -#define ACTIVE_BG "#ececec" -#define SELECT_BG "systemHighlight" -#define SELECT_FG "systemHighlightText" -#define INACTIVE_SELECT_BG "systemHighlightSecondary" -#define TROUGH "#c3c3c3" -#define INDICATOR "#b03060" -#define DISABLED "#a3a3a3" +#define BLACK "Black" +#define WHITE "White" +#define NORMAL_BG "systemWindowBody" +#define ACTIVE_BG "#ececec" +#define SELECT_BG "systemHighlight" +#define SELECT_FG None +#define INACTIVE_SELECT_BG "systemHighlightSecondary" +#define TROUGH "#c3c3c3" +#define INDICATOR "#b03060" +#define DISABLED "#a3a3a3" /* * Defaults for labels, buttons, checkbuttons, and radiobuttons: @@ -50,7 +50,7 @@ #define DEF_BUTTON_ACTIVE_FG_COLOR "systemButtonFace" #define DEF_CHKRAD_ACTIVE_FG_COLOR DEF_BUTTON_ACTIVE_FG_COLOR #define DEF_BUTTON_ACTIVE_FG_MONO WHITE -//IGR#define DEF_BUTTON_BG_COLOR "systemButtonFace" +/* #define DEF_BUTTON_BG_COLOR "systemButtonFace"*/ #define DEF_BUTTON_BG_COLOR WHITE #define DEF_BUTTON_BG_MONO WHITE #define DEF_BUTTON_BITMAP "" @@ -61,8 +61,7 @@ #define DEF_BUTTON_DEFAULT "disabled" #define DEF_BUTTON_DISABLED_FG_COLOR DISABLED #define DEF_BUTTON_DISABLED_FG_MONO "" -//IGR#define DEF_BUTTON_FG "systemButtonText" -#define DEF_BUTTON_FG BLACK +#define DEF_BUTTON_FG "systemButtonText" #define DEF_CHKRAD_FG DEF_BUTTON_FG #define DEF_BUTTON_FONT "system" #define DEF_BUTTON_HEIGHT "0" @@ -127,7 +126,7 @@ #define DEF_CANVAS_SELECT_MONO BLACK #define DEF_CANVAS_SELECT_BD_COLOR "1" #define DEF_CANVAS_SELECT_BD_MONO "0" -#define DEF_CANVAS_SELECT_FG_COLOR BLACK +#define DEF_CANVAS_SELECT_FG_COLOR SELECT_FG #define DEF_CANVAS_SELECT_FG_MONO WHITE #define DEF_CANVAS_TAKE_FOCUS (char *) NULL #define DEF_CANVAS_WIDTH "10c" @@ -289,22 +288,22 @@ * Defaults for menus overall: */ -#define DEF_MENU_ACTIVE_BG_COLOR "SystemMenuActive" +#define DEF_MENU_ACTIVE_BG_COLOR "systemMenuActive" #define DEF_MENU_ACTIVE_BG_MONO BLACK #define DEF_MENU_ACTIVE_BORDER_WIDTH "0" -#define DEF_MENU_ACTIVE_FG_COLOR "SystemMenuActiveText" +#define DEF_MENU_ACTIVE_FG_COLOR "systemMenuActiveText" #define DEF_MENU_ACTIVE_FG_MONO WHITE -#define DEF_MENU_BG_COLOR "SystemMenu" +#define DEF_MENU_BG_COLOR "systemMenu" #define DEF_MENU_BG_MONO WHITE #define DEF_MENU_BORDER_WIDTH "0" #define DEF_MENU_CURSOR "arrow" -#define DEF_MENU_DISABLED_FG_COLOR "SystemMenuDisabled" +#define DEF_MENU_DISABLED_FG_COLOR "systemMenuDisabled" #define DEF_MENU_DISABLED_FG_MONO "" -#define DEF_MENU_FONT "system" -#define DEF_MENU_FG "SystemMenuText" +#define DEF_MENU_FONT "menu" +#define DEF_MENU_FG "systemMenuText" #define DEF_MENU_POST_COMMAND "" #define DEF_MENU_RELIEF "flat" -#define DEF_MENU_SELECT_COLOR "SystemMenuActive" +#define DEF_MENU_SELECT_COLOR "systemMenuActive" #define DEF_MENU_SELECT_MONO BLACK #define DEF_MENU_TAKE_FOCUS "0" @@ -334,7 +333,7 @@ #define DEF_MENUBUTTON_DIRECTION "below" #define DEF_MENUBUTTON_DISABLED_FG_COLOR DISABLED #define DEF_MENUBUTTON_DISABLED_FG_MONO "" -#define DEF_MENUBUTTON_FONT "system" +#define DEF_MENUBUTTON_FONT "menu" #define DEF_MENUBUTTON_FG BLACK #define DEF_MENUBUTTON_HEIGHT "0" #define DEF_MENUBUTTON_HIGHLIGHT_BG_COLOR DEF_MENUBUTTON_BG_COLOR @@ -483,8 +482,7 @@ #define DEF_SCROLLBAR_TAKE_FOCUS (char *) NULL #define DEF_SCROLLBAR_TROUGH_COLOR TROUGH #define DEF_SCROLLBAR_TROUGH_MONO WHITE -/*#define DEF_SCROLLBAR_WIDTH "15" */ -#define DEF_SCROLLBAR_WIDTH "16" +#define DEF_SCROLLBAR_WIDTH "15" /* * Defaults for texts: Index: macosx/tkMacOSXDialog.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDialog.c,v retrieving revision 1.21 diff -u -p -r1.21 tkMacOSXDialog.c --- macosx/tkMacOSXDialog.c 1 Dec 2006 07:13:00 -0000 1.21 +++ macosx/tkMacOSXDialog.c 15 Mar 2007 02:42:10 -0000 @@ -1,10 +1,11 @@ /* * tkMacOSXDialog.c -- * - * Contains the Mac implementation of the common dialog boxes. + * Contains the Mac implementation of the common dialog boxes. * * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -22,28 +23,22 @@ #define StrBody(s) ((char *) (s) + 1) #endif -/* - * The following are ID's for resources that are defined in tkMacOSXResource.r - */ -#define OPEN_BOX 130 -#define OPEN_POPUP 131 -#define OPEN_MENU 132 #define OPEN_POPUP_ITEM 10 -#define SAVE_FILE 0 -#define OPEN_FILE 1 -#define CHOOSE_FOLDER 2 +#define SAVE_FILE 0 +#define OPEN_FILE 1 +#define CHOOSE_FOLDER 2 -#define MATCHED 0 -#define UNMATCHED 1 +#define MATCHED 0 +#define UNMATCHED 1 #define TK_DEFAULT_ABOUT 128 /* - * The following structure is used in the GetFileName() function. It stored + * The following structures are used in the GetFileName() function. They store * information about the file dialog and the file filters. */ -typedef struct _OpenFileData { +typedef struct OpenFileData { FileFilterList fl; /* List of file filters. */ SInt16 curType; /* The filetype currently being listed. */ short popupItem; /* Item number of the popup in the dialog. */ @@ -52,37 +47,46 @@ typedef struct _OpenFileData { * option is set). */ } OpenFileData; +typedef struct NavHandlerUserData { + OpenFileData *ofdPtr; + NavReplyRecord reply; + OSStatus err; + CFStringRef saveNameRef; + int sheet; + WindowRef dialogWindow, origUnavailWindow; + WindowModality origModality; +} NavHandlerUserData; /* - * The following structure is used in the tk_messageBox - * implementation. + * The following structure is used in the tk_messageBox implementation. */ typedef struct { - WindowRef windowRef; - int buttonIndex; -} CallbackUserData; + int buttonIndex; + WindowRef dialogWindow, origUnavailWindow; + WindowModality origModality; + EventHandlerRef handlerRef; +} AlertHandlerUserData; static OSStatus AlertHandler(EventHandlerCallRef callRef, EventRef eventRef, void *userData); -static Boolean MatchOneType(StringPtr fileNamePtr, OSType fileType, +static Boolean MatchOneType(StringPtr fileNamePtr, OSType fileType, OpenFileData *myofdPtr, FileFilter *filterPtr); -static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info, +static pascal Boolean OpenFileFilterProc(AEDesc* theItem, void* info, NavCallBackUserData callBackUD, NavFilterModes filterMode); -static pascal void OpenEventProc(NavEventCallbackMessage callBackSelector, +static pascal void OpenEventProc(NavEventCallbackMessage callBackSelector, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD); -static void InitFileDialogs(); -static int NavServicesGetFile(Tcl_Interp *interp, OpenFileData *ofd, - AEDesc *initialDescPtr, +static void InitFileDialogs(void); +static int NavServicesGetFile(Tcl_Interp *interp, + OpenFileData *ofd, AEDesc *initialDescPtr, char *initialFile, AEDescList *selectDescPtr, - CFStringRef title, CFStringRef message, int multiple, int isOpen); -static int HandleInitialDirectory (Tcl_Interp *interp, - char *initialFile, char *initialDir, - FSRef *dirRef, - AEDescList *selectDescPtr, - AEDesc *dirDescPtr); + CFStringRef title, CFStringRef message, + int multiple, int isOpen, Tk_Window parent); +static int HandleInitialDirectory(Tcl_Interp *interp, + char *initialFile, char *initialDir, FSRef *dirRef, + AEDescList *selectDescPtr, AEDesc *dirDescPtr); /* * Have we initialized the file dialog subsystem @@ -104,43 +108,46 @@ static NavEventUPP openFileEventUPP; * * Tk_ChooseColorObjCmd -- * - * This procedure implements the color dialog box for the Mac - * platform. See the user documentation for details on what it - * does. + * This procedure implements the color dialog box for the Mac + * platform. See the user documentation for details on what it + * does. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * See the user documentation. + * See the user documentation. * *---------------------------------------------------------------------- */ int Tk_ChooseColorObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ - Tcl_Interp *interp, /* Current interpreter. */ - int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { - Tk_Window parent; - char *title; - int i, picked, srcRead, dstWrote; - ColorPickerInfo cpinfo; + OSStatus err; + Tk_Window parent, tkwin = (Tk_Window) clientData; + const char *title; + int i, picked = 0, srcRead, dstWrote; + CMError cmerr; + CMProfileRef prof; + NColorPickerInfo cpinfo; static int inited = 0; static RGBColor in; - static CONST char *optionStrings[] = { - "-initialcolor", "-parent", "-title", NULL + static const char *optionStrings[] = { + "-initialcolor", "-parent", "-title", NULL }; enum options { - COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE + COLOR_INITIAL, COLOR_PARENT, COLOR_TITLE }; if (inited == 0) { /* - * 'in' stores the last color picked. The next time the color dialog - * pops up, the last color will remain in the dialog. + * 'in' stores the last color picked. The next time the color + * dialog pops up, the last color will remain in the dialog. */ in.red = 0xffff; @@ -148,14 +155,11 @@ Tk_ChooseColorObjCmd( in.blue = 0xffff; inited = 1; } - - parent = (Tk_Window) clientData; title = "Choose a color:"; - picked = 0; for (i = 1; i < objc; i += 2) { int index; - char *option, *value; + const char *option, *value; if (Tcl_GetIndexFromObj(interp, objv[i], optionStrings, "option", TCL_EXACT, &index) != TCL_OK) { @@ -173,7 +177,7 @@ Tk_ChooseColorObjCmd( case COLOR_INITIAL: { XColor *colorPtr; - colorPtr = Tk_GetColor(interp, parent, value); + colorPtr = Tk_GetColor(interp, tkwin, value); if (colorPtr == NULL) { return TCL_ERROR; } @@ -184,7 +188,7 @@ Tk_ChooseColorObjCmd( break; } case COLOR_PARENT: { - parent = Tk_NameToWindow(interp, value, parent); + parent = Tk_NameToWindow(interp, value, tkwin); if (parent == NULL) { return TCL_ERROR; } @@ -197,31 +201,31 @@ Tk_ChooseColorObjCmd( } } - - cpinfo.theColor.profile = 0L; + cmerr = CMGetDefaultProfileBySpace(cmRGBData, &prof); + bzero(&cpinfo, sizeof(cpinfo)); + cpinfo.theColor.profile = prof; cpinfo.theColor.color.rgb.red = in.red; cpinfo.theColor.color.rgb.green = in.green; cpinfo.theColor.color.rgb.blue = in.blue; - cpinfo.dstProfile = 0L; - cpinfo.flags = kColorPickerCanModifyPalette - | kColorPickerCanAnimatePalette; - cpinfo.placeWhere = kDeepestColorScreen; - cpinfo.pickerType = 0L; - cpinfo.eventProc = NULL; - cpinfo.colorProc = NULL; - cpinfo.colorProcData = 0; - - /* This doesn't seem to actually set the title! */ - Tcl_UtfToExternal(NULL, NULL, title, -1, 0, NULL, + cpinfo.dstProfile = prof; + cpinfo.flags = kColorPickerDialogIsMoveable + | kColorPickerCanAnimatePalette; + cpinfo.placeWhere = kCenterOnMainScreen; + /* Currently, this does not actually change the colorpicker title */ + Tcl_UtfToExternal(NULL, TkMacOSXCarbonEncoding, title, -1, 0, NULL, StrBody(cpinfo.prompt), 255, &srcRead, &dstWrote, NULL); StrLength(cpinfo.prompt) = (unsigned char) dstWrote; - if ((PickColor(&cpinfo) == noErr) && (cpinfo.newColorChosen != 0)) { + TkMacOSXTrackingLoop(1); + err = ChkErr(NPickColor, &cpinfo); + TkMacOSXTrackingLoop(0); + if ((err == noErr) && (cpinfo.newColorChosen != 0)) { in.red = cpinfo.theColor.color.rgb.red; in.green = cpinfo.theColor.color.rgb.green; in.blue = cpinfo.theColor.color.rgb.blue; picked = 1; } + cmerr = CMCloseProfile(prof); if (picked != 0) { char result[32]; @@ -230,7 +234,6 @@ Tk_ChooseColorObjCmd( in.blue >> 8); Tcl_AppendResult(interp, result, NULL); } - return TCL_OK; } @@ -239,35 +242,35 @@ Tk_ChooseColorObjCmd( * * Tk_GetOpenFileObjCmd -- * - * This procedure implements the "open file" dialog box for the - * Mac platform. See the user documentation for details on what - * it does. + * This procedure implements the "open file" dialog box for the + * Mac platform. See the user documentation for details on what + * it does. * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * See user documentation. + * See user documentation. *---------------------------------------------------------------------- */ int Tk_GetOpenFileObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ - Tcl_Interp *interp, /* Current interpreter. */ - int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { - int i, result, multiple; + int i, result = TCL_ERROR, multiple = 0; OpenFileData ofd; - Tk_Window parent; - CFStringRef message, title; + Tk_Window parent = NULL; + CFStringRef message = NULL, title = NULL; AEDesc initialDesc = {typeNull, NULL}; FSRef dirRef; AEDesc *initialPtr = NULL; AEDescList selectDesc = {typeNull, NULL}; char *initialFile = NULL, *initialDir = NULL; - static CONST char *openOptionStrings[] = { + static const char *openOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", "-message", "-multiple", @@ -283,18 +286,10 @@ Tk_GetOpenFileObjCmd( if (!fileDlgInited) { InitFileDialogs(); } - - result = TCL_ERROR; - parent = (Tk_Window) clientData; - multiple = false; - title = NULL; - message = NULL; - TkInitFileFilters(&ofd.fl); - - ofd.curType = 0; - ofd.popupItem = OPEN_POPUP_ITEM; - ofd.usePopup = 1; + ofd.curType = 0; + ofd.popupItem = OPEN_POPUP_ITEM; + ofd.usePopup = 1; for (i = 1; i < objc; i += 2) { char *choice; @@ -303,14 +298,12 @@ Tk_GetOpenFileObjCmd( if (Tcl_GetIndexFromObj(interp, objv[i], openOptionStrings, "option", TCL_EXACT, &index) != TCL_OK) { - result = TCL_ERROR; goto end; } if (i + 1 == objc) { string = Tcl_GetStringFromObj(objv[i], NULL); Tcl_AppendResult(interp, "value for \"", string, "\" missing", (char *) NULL); - result = TCL_ERROR; goto end; } @@ -320,7 +313,6 @@ Tk_GetOpenFileObjCmd( case OPEN_FILETYPES: if (TkGetFileFilters(interp, &ofd.fl, objv[i + 1], 0) != TCL_OK) { - result = TCL_ERROR; goto end; } break; @@ -336,55 +328,55 @@ Tk_GetOpenFileObjCmd( break; case OPEN_MESSAGE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + message = CFStringCreateWithBytes(NULL, (unsigned char*) + choice, choiceLen, kCFStringEncodingUTF8, false); break; case OPEN_MULTIPLE: if (Tcl_GetBooleanFromObj(interp, objv[i + 1], &multiple) != TCL_OK) { - result = TCL_ERROR; goto end; } break; case OPEN_PARENT: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); + parent = Tk_NameToWindow(interp, choice, + (Tk_Window) clientData); if (parent == NULL) { - result = TCL_ERROR; goto end; } break; case OPEN_TITLE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + title = CFStringCreateWithBytes(NULL, (unsigned char*) + choice, choiceLen, kCFStringEncodingUTF8, false); break; } } if (HandleInitialDirectory(interp, initialFile, initialDir, &dirRef, - &selectDesc, &initialDesc) != TCL_OK) { - result = TCL_ERROR; + &selectDesc, &initialDesc) != TCL_OK) { goto end; } if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } - result = NavServicesGetFile(interp, &ofd, initialPtr, - NULL, &selectDesc, title, message, multiple, OPEN_FILE); - - end: + result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, &selectDesc, + title, message, multiple, OPEN_FILE, parent); +end: TkFreeFileFilters(&ofd.fl); - AEDisposeDesc(&initialDesc); - AEDisposeDesc(&selectDesc); - if (title != NULL) { + if (initialDesc.dataHandle) { + ChkErr(AEDisposeDesc, &initialDesc); + } + if (selectDesc.dataHandle) { + ChkErr(AEDisposeDesc, &selectDesc); + } + if (title) { CFRelease(title); } - if (message != NULL) { + if (message) { CFRelease(message); } - return result; } @@ -393,35 +385,35 @@ Tk_GetOpenFileObjCmd( * * Tk_GetSaveFileObjCmd -- * - * Same as Tk_GetOpenFileCmd but opens a "save file" dialog box - * instead + * Same as Tk_GetOpenFileCmd but opens a "save file" dialog box + * instead * * Results: - * A standard Tcl result. + * A standard Tcl result. * * Side effects: - * See user documentation. + * See user documentation. *---------------------------------------------------------------------- */ int Tk_GetSaveFileObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ - Tcl_Interp *interp, /* Current interpreter. */ - int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { - int i, result; + int i, result = TCL_ERROR; char *initialFile = NULL; - Tk_Window parent; + Tk_Window parent = NULL; AEDesc initialDesc = {typeNull, NULL}; AEDesc *initialPtr = NULL; FSRef dirRef; - CFStringRef title, message; + CFStringRef title = NULL, message = NULL; OpenFileData ofd; - static CONST char *saveOptionStrings[] = { + static const char *saveOptionStrings[] = { "-defaultextension", "-filetypes", "-initialdir", "-initialfile", - "-message", "-parent", "-title", NULL + "-message", "-parent", "-title", NULL }; enum saveOptions { SAVE_DEFAULT, SAVE_FILETYPES, SAVE_INITDIR, SAVE_INITFILE, @@ -432,11 +424,6 @@ Tk_GetSaveFileObjCmd( InitFileDialogs(); } - result = TCL_ERROR; - parent = (Tk_Window) clientData; - title = NULL; - message = NULL; - for (i = 1; i < objc; i += 2) { char *choice; int index, choiceLen; @@ -444,13 +431,13 @@ Tk_GetSaveFileObjCmd( if (Tcl_GetIndexFromObj(interp, objv[i], saveOptionStrings, "option", TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; + goto end; } if (i + 1 == objc) { string = Tcl_GetStringFromObj(objv[i], NULL); Tcl_AppendResult(interp, "value for \"", string, "\" missing", (char *) NULL); - return TCL_ERROR; + goto end; } switch (index) { case SAVE_DEFAULT: @@ -464,7 +451,6 @@ Tk_GetSaveFileObjCmd( if (choiceLen && HandleInitialDirectory(interp, NULL, choice, &dirRef, NULL, &initialDesc) != TCL_OK) { - result = TCL_ERROR; goto end; } break; @@ -475,44 +461,43 @@ Tk_GetSaveFileObjCmd( break; case SAVE_MESSAGE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + message = CFStringCreateWithBytes(NULL, (unsigned char*) + choice, choiceLen, kCFStringEncodingUTF8, false); break; case SAVE_PARENT: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); + parent = Tk_NameToWindow(interp, choice, + (Tk_Window) clientData); if (parent == NULL) { - result = TCL_ERROR; goto end; } break; case SAVE_TITLE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + title = CFStringCreateWithBytes(NULL, (unsigned char*) + choice, choiceLen, kCFStringEncodingUTF8, false); break; } } TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; - if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } result = NavServicesGetFile(interp, &ofd, initialPtr, initialFile, NULL, - title, message, false, SAVE_FILE); - - end: - - AEDisposeDesc(&initialDesc); - if (title != NULL) { + title, message, false, SAVE_FILE, parent); + TkFreeFileFilters(&ofd.fl); +end: + if (initialDesc.dataHandle) { + ChkErr(AEDisposeDesc, &initialDesc); + } + if (title) { CFRelease(title); } - if (message != NULL) { + if (message) { CFRelease(message); } - return result; } @@ -521,53 +506,43 @@ Tk_GetSaveFileObjCmd( * * Tk_ChooseDirectoryObjCmd -- * - * This procedure implements the "tk_chooseDirectory" dialog box - * for the Windows platform. See the user documentation for details - * on what it does. + * This procedure implements the "tk_chooseDirectory" dialog box + * for the Windows platform. See the user documentation for details + * on what it does. * * Results: - * See user documentation. + * See user documentation. * * Side effects: - * A modal dialog window is created. Tcl_SetServiceMode() is - * called to allow background events to be processed + * A modal dialog window is created. * *---------------------------------------------------------------------- */ int Tk_ChooseDirectoryObjCmd(clientData, interp, objc, objv) - ClientData clientData; /* Main window associated with interpreter. */ - Tcl_Interp *interp; /* Current interpreter. */ - int objc; /* Number of arguments. */ - Tcl_Obj *CONST objv[]; /* Argument objects. */ + ClientData clientData; /* Main window associated with interpreter. */ + Tcl_Interp *interp; /* Current interpreter. */ + int objc; /* Number of arguments. */ + Tcl_Obj *CONST objv[]; /* Argument objects. */ { - int i, result; - Tk_Window parent; - AEDesc initialDesc = {typeNull, NULL}; - AEDesc *initialPtr = NULL; + int i, result = TCL_ERROR; + Tk_Window parent = NULL; + AEDesc initialDesc = {typeNull, NULL}, *initialPtr = NULL; FSRef dirRef; - CFStringRef message, title; + CFStringRef message = NULL, title = NULL; OpenFileData ofd; - static CONST char *chooseOptionStrings[] = { + static const char *chooseOptionStrings[] = { "-initialdir", "-message", "-mustexist", "-parent", "-title", NULL }; enum chooseOptions { - CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, - CHOOSE_PARENT, CHOOSE_TITLE + CHOOSE_INITDIR, CHOOSE_MESSAGE, CHOOSE_MUSTEXIST, CHOOSE_PARENT, + CHOOSE_TITLE }; - if (!NavServicesAvailable()) { - return TCL_ERROR; - } - if (!fileDlgInited) { InitFileDialogs(); } - result = TCL_ERROR; - parent = (Tk_Window) clientData; - title = NULL; - message = NULL; for (i = 1; i < objc; i += 2) { char *choice; @@ -576,68 +551,82 @@ Tk_ChooseDirectoryObjCmd(clientData, int if (Tcl_GetIndexFromObj(interp, objv[i], chooseOptionStrings, "option", TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; + goto end; } if (i + 1 == objc) { string = Tcl_GetStringFromObj(objv[i], NULL); Tcl_AppendResult(interp, "value for \"", string, "\" missing", (char *) NULL); - return TCL_ERROR; + goto end; } switch (index) { case CHOOSE_INITDIR: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - if (choiceLen && - HandleInitialDirectory(interp, NULL, choice, &dirRef, - NULL, &initialDesc) != TCL_OK) { - result = TCL_ERROR; + if (choiceLen && HandleInitialDirectory(interp, NULL, choice, + &dirRef, NULL, &initialDesc) != TCL_OK) { goto end; } break; case CHOOSE_MESSAGE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - message = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + message = CFStringCreateWithBytes(NULL, (unsigned char*) + choice, choiceLen, kCFStringEncodingUTF8, false); break; case CHOOSE_PARENT: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - parent = Tk_NameToWindow(interp, choice, parent); + parent = Tk_NameToWindow(interp, choice, + (Tk_Window) clientData); if (parent == NULL) { - result = TCL_ERROR; goto end; } break; case CHOOSE_TITLE: choice = Tcl_GetStringFromObj(objv[i + 1], &choiceLen); - title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, choiceLen, - kCFStringEncodingUTF8, false); + title = CFStringCreateWithBytes(NULL, (unsigned char*) choice, + choiceLen, kCFStringEncodingUTF8, false); break; } } TkInitFileFilters(&ofd.fl); ofd.usePopup = 0; - if (initialDesc.descriptorType == typeFSRef) { initialPtr = &initialDesc; } - result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, - title, message, false, CHOOSE_FOLDER); - - end: - AEDisposeDesc(&initialDesc); - if (title != NULL) { + result = NavServicesGetFile(interp, &ofd, initialPtr, NULL, NULL, title, + message, false, CHOOSE_FOLDER, parent); + TkFreeFileFilters(&ofd.fl); +end: + if (initialDesc.dataHandle) { + ChkErr(AEDisposeDesc, &initialDesc); + } + if (title) { CFRelease(title); } - if (message != NULL) { + if (message) { CFRelease(message); } - return result; } + +/* + *---------------------------------------------------------------------- + * + * HandleInitialDirectory -- + * + * Helper for -initialdir setup. + * + * Results: + * Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ int -HandleInitialDirectory ( +HandleInitialDirectory( Tcl_Interp *interp, char *initialFile, char *initialDir, @@ -646,42 +635,37 @@ HandleInitialDirectory ( AEDesc *dirDescPtr) { Tcl_DString ds; - OSErr err; + OSStatus err; Boolean isDirectory; char *dirName = NULL; - int result = TCL_OK; + int result = TCL_ERROR; - if (initialDir != NULL) { + if (initialDir) { dirName = Tcl_TranslateFileName(interp, initialDir, &ds); if (dirName == NULL) { - return TCL_ERROR; + goto end; } - - err = FSPathMakeRef((unsigned char*) dirName, + err = ChkErr(FSPathMakeRef, (unsigned char*) dirName, dirRef, &isDirectory); - if (err != noErr) { - Tcl_AppendResult(interp, "bad directory \"", - initialDir, "\"", NULL); - result = TCL_ERROR; + Tcl_AppendResult(interp, "bad directory \"", initialDir, "\"", + NULL); goto end; } if (!isDirectory) { Tcl_AppendResult(interp, "-intialdir \"", initialDir, " is a file, not a directory.\"", NULL); - result = TCL_ERROR; goto end; } - - AECreateDesc(typeFSRef, dirRef, sizeof(*dirRef), dirDescPtr); + ChkErr(AECreateDesc, typeFSRef, dirRef, sizeof(*dirRef), dirDescPtr); } - if (initialFile != NULL && selectDescPtr != NULL) { + if (initialFile && selectDescPtr) { FSRef fileRef; AEDesc fileDesc; char *namePtr; - if (initialDir != NULL) { + if (initialDir) { Tcl_DStringAppend(&ds, "/", 1); Tcl_DStringAppend(&ds, initialFile, -1); namePtr = Tcl_DStringValue(&ds); @@ -689,35 +673,68 @@ HandleInitialDirectory ( namePtr = initialFile; } - AECreateList(NULL, 0, false, selectDescPtr); + ChkErr(AECreateList, NULL, 0, false, selectDescPtr); - err = FSPathMakeRef((unsigned char*) namePtr, &fileRef, &isDirectory); + err = ChkErr(FSPathMakeRef, (unsigned char*) namePtr, &fileRef, + &isDirectory); if (err != noErr) { Tcl_AppendResult(interp, "bad initialfile \"", initialFile, "\" file does not exist.", NULL); - return TCL_ERROR; + goto end; } - AECreateDesc(typeFSRef, &fileRef, sizeof(fileRef), &fileDesc); - AEPutDesc(selectDescPtr, 1, &fileDesc); - AEDisposeDesc(&fileDesc); + ChkErr(AECreateDesc, typeFSRef, &fileRef, sizeof(fileRef), &fileDesc); + ChkErr(AEPutDesc, selectDescPtr, 1, &fileDesc); + ChkErr(AEDisposeDesc, &fileDesc); } - + result = TCL_OK; end: - if (dirName != NULL) { + if (dirName) { Tcl_DStringFree(&ds); } return result; } + +/* + *---------------------------------------------------------------------- + * + * InitFileDialogs -- + * + * Initialize file dialog subsystem. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ -static void +void InitFileDialogs() { fileDlgInited = 1; openFileFilterUPP = NewNavObjectFilterUPP(OpenFileFilterProc); openFileEventUPP = NewNavEventUPP(OpenEventProc); } + +/* + *---------------------------------------------------------------------- + * + * NavServicesGetFile -- + * + * Common wrapper for NavServices API. + * + * Results: + * Tcl result. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ -static int +int NavServicesGetFile( Tcl_Interp *interp, OpenFileData *ofdPtr, @@ -727,30 +744,43 @@ NavServicesGetFile( CFStringRef title, CFStringRef message, int multiple, - int isOpen) + int isOpen, + Tk_Window parent) { - NavReplyRecord theReply; - NavDialogCreationOptions diagOptions; + NavHandlerUserData data; + NavDialogCreationOptions options; NavDialogRef dialogRef = NULL; CFStringRef * menuItemNames = NULL; - OSErr err; + OSStatus err; Tcl_Obj *theResult = NULL; - int result; + int result = TCL_ERROR; - err = NavGetDefaultDialogCreationOptions(&diagOptions); - if (err!=noErr) { - return TCL_ERROR; - } - diagOptions.location.h = -1; - diagOptions.location.v = -1; - diagOptions.optionFlags = kNavDontAutoTranslate - + kNavDontAddTranslateItems; + bzero(&data, sizeof(data)); + err = NavGetDefaultDialogCreationOptions(&options); + if (err != noErr) { + return result; + } + options.optionFlags = kNavDontAutoTranslate | kNavDontAddTranslateItems + | kNavSupportPackages | kNavAllFilesInPopup; if (multiple) { - diagOptions.optionFlags += kNavAllowMultipleFiles; + options.optionFlags |= kNavAllowMultipleFiles; + } + options.modality = kWindowModalityAppModal; + if (parent && ((TkWindow*)parent)->window != None && + TkMacOSXHostToplevelExists(parent)) { + options.parentWindow = GetWindowFromPort(TkMacOSXGetDrawablePort( + Tk_WindowId(parent))); + if (options.parentWindow) { + options.modality = kWindowModalityWindowModal; + data.sheet = 1; + } } - diagOptions.modality = kWindowModalityAppModal; - if (ofdPtr != NULL && ofdPtr->usePopup) { + /* + * Now process the selection list. We have to use the popupExtension + * to fill the menu. + */ + if (ofdPtr && ofdPtr->usePopup) { FileFilter *filterPtr; filterPtr = ofdPtr->fl.filters; @@ -758,8 +788,7 @@ NavServicesGetFile( ofdPtr->usePopup = 0; } } - - if (ofdPtr != NULL && ofdPtr->usePopup) { + if (ofdPtr && ofdPtr->usePopup) { FileFilter *filterPtr; int index = 0; ofdPtr->curType = 0; @@ -772,98 +801,60 @@ NavServicesGetFile( menuItemNames[index] = CFStringCreateWithCString(NULL, filterPtr->name, kCFStringEncodingUTF8); } - diagOptions.popupExtension = CFArrayCreate(NULL, + options.popupExtension = CFArrayCreate(NULL, (const void **) menuItemNames, ofdPtr->fl.numFilters, NULL); } else { - diagOptions.optionFlags += kNavNoTypePopup; - diagOptions.popupExtension = NULL; + options.optionFlags |= kNavNoTypePopup; + options.popupExtension = NULL; } - - /* - * This is required to allow App packages to be selectable in the - * file dialogs... - */ - - diagOptions.optionFlags += kNavSupportPackages; - - diagOptions.clientName = CFStringCreateWithCString(NULL, "Wish", kCFStringEncodingUTF8); - diagOptions.message = message; - diagOptions.windowTitle = title; + options.clientName = CFSTR("Wish"); + options.message = message; + options.windowTitle = title; if (initialFile) { - diagOptions.saveFileName = CFStringCreateWithCString(NULL, + options.saveFileName = CFStringCreateWithCString(NULL, initialFile, kCFStringEncodingUTF8); } else { - diagOptions.saveFileName = NULL; + options.saveFileName = NULL; } - - diagOptions.actionButtonLabel = NULL; - diagOptions.cancelButtonLabel = NULL; - diagOptions.preferenceKey = 0; - - /* - * Now process the selection list. We have to use the popupExtension - * to fill the menu. - */ - if (isOpen == OPEN_FILE) { - err = NavCreateGetFileDialog(&diagOptions, - NULL, - openFileEventUPP, - NULL, - openFileFilterUPP, - ofdPtr, - &dialogRef); - if (err != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreateGetFileDialog failed, %d\n", err); -#endif - dialogRef = NULL; - } + data.ofdPtr = ofdPtr; + err = ChkErr(NavCreateGetFileDialog, &options, NULL, + openFileEventUPP, NULL, openFileFilterUPP, &data, &dialogRef); } else if (isOpen == SAVE_FILE) { - err = NavCreatePutFileDialog(&diagOptions, 'TEXT', 'WIsH', - openFileEventUPP, NULL, &dialogRef); - if (err!=noErr){ -#ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreatePutFileDialog failed, %d\n", err); -#endif - dialogRef = NULL; - } + err = ChkErr(NavCreatePutFileDialog, &options, 'TEXT', 'WIsH', + openFileEventUPP, &data, &dialogRef); } else if (isOpen == CHOOSE_FOLDER) { - err = NavCreateChooseFolderDialog(&diagOptions, openFileEventUPP, - openFileFilterUPP, NULL, &dialogRef); - if (err!=noErr){ -#ifdef TK_MAC_DEBUG - fprintf(stderr,"NavCreateChooseFolderDialog failed, %d\n", err); -#endif - dialogRef = NULL; - } + err = ChkErr(NavCreateChooseFolderDialog, &options, + openFileEventUPP, openFileFilterUPP, &data, &dialogRef); } - - if (dialogRef) { - if (initialDescPtr != NULL) { - NavCustomControl (dialogRef, kNavCtlSetLocation, initialDescPtr); + if (err == noErr && dialogRef) { + if (initialDescPtr) { + ChkErr(NavCustomControl, dialogRef, kNavCtlSetLocation, + initialDescPtr); + } + if (selectDescPtr && selectDescPtr->descriptorType != typeNull) { + ChkErr(NavCustomControl, dialogRef, kNavCtlSetSelection, + selectDescPtr); } - if ((selectDescPtr != NULL) - && (selectDescPtr->descriptorType != typeNull)) { - NavCustomControl(dialogRef, kNavCtlSetSelection, selectDescPtr); - } - - if ((err = NavDialogRun(dialogRef)) != noErr){ -#ifdef TK_MAC_DEBUG - fprintf(stderr,"NavDialogRun failed, %d\n", err); -#endif - } else { - if ((err = NavDialogGetReply(dialogRef, &theReply)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"NavGetReply failed, %d\n", err); -#endif + TkMacOSXTrackingLoop(1); + err = ChkErr(NavDialogRun, dialogRef); + if (err == noErr) { + if (data.sheet) { + data.dialogWindow = NavDialogGetWindow(dialogRef); + ChkErr(GetWindowModality, data.dialogWindow, + &data.origModality, &data.origUnavailWindow); + ChkErr(SetWindowModality, data.dialogWindow, + kWindowModalityAppModal, NULL); + ChkErr(RunAppModalLoopForWindow, data.dialogWindow); } + err = data.err; } + TkMacOSXTrackingLoop(0); } /* * Most commands assume that the file dialogs return a single - * item, not a list. So only build a list if multiple is true... + * item, not a list. So only build a list if multiple is true... */ if (err == noErr) { if (multiple) { @@ -875,55 +866,50 @@ NavServicesGetFile( err = memFullErr; } } - if (theReply.validRecord && err == noErr) { + if (err == noErr && data.reply.validRecord) { AEDesc resultDesc; long count; - FSRef fsRef; - char pathPtr[1024]; - int pathValid = 0; - err = AECountItems(&theReply.selection, &count); + FSRef fsRef; + char pathPtr[PATH_MAX + 1]; + + err = ChkErr(AECountItems, &data.reply.selection, &count); if (err == noErr) { long i; for (i = 1; i <= count; i++) { - err = AEGetNthDesc(&theReply.selection, - i, typeFSRef, NULL, &resultDesc); - pathValid = 0; + err = ChkErr(AEGetNthDesc, &data.reply.selection, i, + typeFSRef, NULL, &resultDesc); if (err == noErr) { - if ((err = AEGetDescData(&resultDesc, &fsRef, sizeof(fsRef))) - != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"AEGetDescData failed %d\n", err); -#endif - } else { - if ((err = FSRefMakePath(&fsRef, (unsigned char*) pathPtr, 1024))) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"FSRefMakePath failed, %d\n", err); -#endif - } else { + err = ChkErr(AEGetDescData, &resultDesc, &fsRef, + sizeof(fsRef)); + if (err == noErr) { + err = ChkErr(FSRefMakePath, &fsRef, (unsigned char*) + pathPtr, PATH_MAX + 1); + if (err == noErr) { + int pathValid = 0; + if (isOpen == SAVE_FILE) { - CFStringRef saveNameRef; - char saveName [1024]; - if ((saveNameRef = NavDialogGetSaveFileName(dialogRef))) { - if (CFStringGetCString(saveNameRef, saveName, - 1024, kCFStringEncodingUTF8)) { - if (strlen(pathPtr) + strlen(saveName) < 1023) { + if (data.saveNameRef) { + char saveName [PATH_MAX + 1]; + + if (CFStringGetCString(data.saveNameRef, + saveName, PATH_MAX + 1, + kCFStringEncodingUTF8)) { + if (strlen(pathPtr) + strlen(saveName) + < PATH_MAX) { strcat(pathPtr, "/"); strcat(pathPtr, saveName); pathValid = 1; } else { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "Path name too long\n"); -#endif + TkMacOSXDbgMsg("Path name too " + "long"); } } else { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "CFStringGetCString failed\n"); -#endif + TkMacOSXDbgMsg("CFStringGetCString " + "failed"); } } else { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "NavDialogGetSaveFileName failed\n"); -#endif + TkMacOSXDbgMsg("NavDialogGetSaveFileName " + "failed"); } } else { pathValid = 1; @@ -938,73 +924,137 @@ NavServicesGetFile( } } } - AEDisposeDesc(&resultDesc); + ChkErr(AEDisposeDesc, &resultDesc); } } - } - err = NavDisposeReply(&theReply); - Tcl_SetObjResult(interp, theResult); - result = TCL_OK; + } + Tcl_SetObjResult(interp, theResult); + result = TCL_OK; } else if (err == userCanceledErr) { result = TCL_OK; - } else { - result = TCL_ERROR; } /* - * Clean up any allocated strings - * dispose of things in reverse order of creation + * Clean up any allocated memory. */ - if (diagOptions.windowTitle) { - CFRelease(diagOptions.windowTitle); + if (data.reply.validRecord) { + ChkErr(NavDisposeReply, &data.reply); } - if (diagOptions.saveFileName) { - CFRelease(diagOptions.saveFileName); + if (data.saveNameRef) { + CFRelease(data.saveNameRef); } - if (diagOptions.message) { - CFRelease(diagOptions.message); + if (options.saveFileName) { + CFRelease(options.saveFileName); } - if (diagOptions.clientName) { - CFRelease(diagOptions.clientName); + if (options.clientName) { + CFRelease(options.clientName); } - /* - * dispose of the CFArray diagOptions.popupExtension - */ - if (menuItemNames) { int i; - for (i = 0;i < ofdPtr->fl.numFilters; i++) { + for (i = 0; i < ofdPtr->fl.numFilters; i++) { CFRelease(menuItemNames[i]); } ckfree((void *)menuItemNames); } - if (diagOptions.popupExtension != NULL) { - CFRelease(diagOptions.popupExtension); + if (options.popupExtension) { + CFRelease(options.popupExtension); } - return result; } + +/* + *---------------------------------------------------------------------- + * + * OpenEventProc -- + * + * NavServices event handling callback. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +pascal void +OpenEventProc( + NavEventCallbackMessage callBackSelector, + NavCBRecPtr callBackParams, + NavCallBackUserData callBackUD) +{ + NavHandlerUserData *data = (NavHandlerUserData*) callBackUD; -static pascal Boolean + switch (callBackSelector) { + case kNavCBPopupMenuSelect: + data->ofdPtr->curType = ((NavMenuItemSpec *) + callBackParams->eventData.eventDataParms.param)->menuType; + break; + case kNavCBAccept: + case kNavCBCancel: + if (data->sheet) { + ChkErr(QuitAppModalLoopForWindow, data->dialogWindow); + ChkErr(SetWindowModality, data->dialogWindow, + data->origModality, data->origUnavailWindow); + } + break; + case kNavCBUserAction: + if (data->reply.validRecord) { + ChkErr(NavDisposeReply, &data->reply); + data->reply.validRecord = 0; + } + data->err = NavDialogGetReply(callBackParams->context, + &data->reply); + if (callBackParams->userAction == kNavUserActionSaveAs) { + data->saveNameRef = NavDialogGetSaveFileName( + callBackParams->context); + if (data->saveNameRef) { + CFRetain(data->saveNameRef); + } + } + break; + case kNavCBTerminate: + NavDialogDispose(callBackParams->context); + break; + case kNavCBEvent: + TkMacOSXRunTclEventLoop(); + break; + } +} + +/* + *---------------------------------------------------------------------- + * + * OpenFileFilterProc -- + * + * NavServices file filter callback. + * + * Results: + * Whether to use the file in question. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +pascal Boolean OpenFileFilterProc( AEDesc* theItem, void* info, NavCallBackUserData callBackUD, NavFilterModes filterMode) { - OpenFileData *ofdPtr = (OpenFileData *) callBackUD; + OpenFileData *ofdPtr = ((NavHandlerUserData*) callBackUD)->ofdPtr; + int result = MATCHED; - if (!ofdPtr || !ofdPtr->usePopup) { - return true; - } else { - if (ofdPtr->fl.numFilters == 0) { - return true; - } else { + if (ofdPtr && ofdPtr->usePopup) { + if (ofdPtr->fl.numFilters > 0) { if ((theItem->descriptorType == typeFSS) - || (theItem->descriptorType = typeFSRef)) { + || (theItem->descriptorType == typeFSRef)) { NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo *) info; char fileName[256]; - int result; if (!theInfo->isFolder) { OSType fileType; @@ -1019,7 +1069,7 @@ OpenFileFilterProc( if (theItem->descriptorType == typeFSS) { int len; - fileNamePtr = (((FSSpec *) *theItem->dataHandle)->name); + fileNamePtr = ((FSSpec *) *theItem->dataHandle)->name; len = fileNamePtr[0]; strncpy(fileName, (char*) fileNamePtr + 1, len); fileName[len] = '\0'; @@ -1029,15 +1079,15 @@ OpenFileFilterProc( OSStatus err; FSRef *theRef = (FSRef *) *theItem->dataHandle; HFSUniStr255 uniFileName; - err = FSGetCatalogInfo (theRef, kFSCatInfoNone, NULL, - &uniFileName, NULL, NULL); + err = ChkErr(FSGetCatalogInfo, theRef, kFSCatInfoNone, + NULL, &uniFileName, NULL, NULL); if (err == noErr) { Tcl_UniCharToUtfDString ( (Tcl_UniChar *) uniFileName.unicode, - uniFileName.length, - &fileNameDString); - fileNamePtr = (unsigned char*) Tcl_DStringValue(&fileNameDString); + uniFileName.length, &fileNameDString); + fileNamePtr = (unsigned char*) + Tcl_DStringValue(&fileNameDString); } else { fileNamePtr = NULL; } @@ -1052,7 +1102,7 @@ OpenFileFilterProc( result = MatchOneType(fileNamePtr, fileType, ofdPtr, filterPtr); } else { - result = false; + result = UNMATCHED; } } else { /* @@ -1071,42 +1121,12 @@ OpenFileFilterProc( } } } - Tcl_DStringFree (&fileNameDString); - return (result == MATCHED); - } else { - return true; } } } - - return true; - } -} - -pascal void -OpenEventProc( - NavEventCallbackMessage callBackSelector, - NavCBRecPtr callBackParams, - NavCallBackUserData callBackUD) -{ - NavMenuItemSpec *chosenItem; - OpenFileData *ofd = (OpenFileData *) callBackUD; - static SInt32 otherEvent = ~(kNavCBCustomize|kNavCBStart|kNavCBTerminate - |kNavCBNewLocation|kNavCBShowDesktop|kNavCBSelectEntry|kNavCBAccept - |kNavCBCancel|kNavCBAdjustPreview); - - if (callBackSelector == kNavCBPopupMenuSelect) { - chosenItem = (NavMenuItemSpec *) callBackParams->eventData.eventDataParms.param; - ofd->curType = chosenItem->menuType; - } else if (callBackSelector == kNavCBAdjustRect - || (callBackSelector & otherEvent) != 0) { - while (Tcl_DoOneEvent(TCL_IDLE_EVENTS - | TCL_DONT_WAIT - | TCL_WINDOW_EVENTS)) { - /* Empty Body */ - } } + return (result == MATCHED); } /* @@ -1114,24 +1134,25 @@ OpenEventProc( * * MatchOneType -- * - * Match a file with one file type in the list of file types. + * Match a file with one file type in the list of file types. * * Results: - * Returns MATCHED if the file matches with the file type; returns - * UNMATCHED otherwise. + * Returns MATCHED if the file matches with the file type; returns + * UNMATCHED otherwise. * * Side effects: - * None + * None * *---------------------------------------------------------------------- */ static Boolean MatchOneType( - StringPtr fileNamePtr, /* Name of the file */ - OSType fileType, /* Type of the file, 0 means there was no specified type. */ - OpenFileData * ofdPtr, /* Information about this file dialog */ - FileFilter * filterPtr) /* Match the file described by pb against + StringPtr fileNamePtr, /* Name of the file */ + OSType fileType, /* Type of the file, 0 means there was no + * specified type. */ + OpenFileData * ofdPtr, /* Information about this file dialog */ + FileFilter * filterPtr) /* Match the file described by pb against * this filter */ { FileFilterClause * clausePtr; @@ -1155,7 +1176,7 @@ MatchOneType( for (clausePtr = filterPtr->clauses; clausePtr; clausePtr = clausePtr->next) { - int macMatched = 0; + int macMatched = 0; int globMatched = 0; GlobPattern * globPtr; MacFileType * mfPtr; @@ -1196,10 +1217,10 @@ MatchOneType( goto glob_unmatched; } - glob_unmatched: + glob_unmatched: continue; - glob_matched: + glob_matched: globMatched = 1; break; } @@ -1213,11 +1234,11 @@ MatchOneType( /* * On Mac OS X, it is not uncommon for files to have NO - * file type. But folks with Tcl code on Classic MacOS pretty - * much assume that a generic file will have type TEXT. So + * file type. But folks with Tcl code on Classic MacOS pretty + * much assume that a generic file will have type TEXT. So * if we were strict about matching types when the source file * had NO type set, they would have to add another rule always - * with no fileType. To avoid that, we pass the macMatch side + * with no fileType. To avoid that, we pass the macMatch side * of the test if no fileType is set. */ @@ -1228,51 +1249,46 @@ MatchOneType( return UNMATCHED; } - + /* *---------------------------------------------------------------------- * * TkAboutDlg -- * - * Displays the default Tk About box. This code uses Macintosh - * resources to define the content of the About Box. + * Displays the default Tk About box. This code uses Macintosh + * resources to define the content of the About Box. * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ void -TkAboutDlg() +TkAboutDlg(void) { DialogPtr aboutDlog; WindowRef windowRef; short itemHit = -9; - aboutDlog = GetNewDialog(128, NULL, (void *) (-1)); - + aboutDlog = GetNewDialog(TK_DEFAULT_ABOUT, NULL, (void *) (-1)); if (!aboutDlog) { return; } - windowRef = GetDialogWindow(aboutDlog); SelectWindow(windowRef); - + TkMacOSXTrackingLoop(1); while (itemHit != 1) { ModalDialog(NULL, &itemHit); } + TkMacOSXTrackingLoop(0); DisposeDialog(aboutDlog); - aboutDlog = NULL; - SelectWindow(ActiveNonFloatingWindow()); - - return; } - + /* *---------------------------------------------------------------------- * @@ -1291,48 +1307,42 @@ TkAboutDlg() int Tk_MessageBoxObjCmd( - ClientData clientData, /* Main window associated with interpreter. */ - Tcl_Interp *interp, /* Current interpreter. */ - int objc, /* Number of arguments. */ - Tcl_Obj *CONST objv[]) /* Argument objects. */ + ClientData clientData, /* Main window associated with interpreter. */ + Tcl_Interp *interp, /* Current interpreter. */ + int objc, /* Number of arguments. */ + Tcl_Obj *CONST objv[]) /* Argument objects. */ { - Tk_Window tkwin = (Tk_Window) clientData; + Tk_Window tkwin = (Tk_Window) clientData; AlertStdCFStringAlertParamRec paramCFStringRec; - AlertType alertType; - DialogRef dialogRef; - CFStringRef messageTextCF = NULL; - CFStringRef finemessageTextCF = NULL; - OSErr osError; - SInt16 itemHit; - Boolean haveDefaultOption = false; - Boolean haveParentOption = false; - char *str; - int index; - int defaultButtonIndex; - int defaultNativeButtonIndex; /* 1, 2, 3: right to left. */ - int typeIndex; - int i; - int indexDefaultOption = 0; - int result = TCL_OK; + AlertType alertType; + DialogRef dialogRef; + CFStringRef messageTextCF = NULL, finemessageTextCF = NULL; + OSStatus err; + SInt16 itemHit; + Boolean haveDefaultOption = false, haveParentOption = false; + char *str; + int index, defaultButtonIndex; + int defaultNativeButtonIndex; /* 1, 2, 3: right to left */ + int typeIndex, i, indexDefaultOption = 0, result = TCL_ERROR; - static CONST char *movableAlertStrings[] = { + static const char *movableAlertStrings[] = { "-default", "-detail", "-icon", "-message", "-parent", "-title", "-type", (char *)NULL }; - static CONST char *movableTypeStrings[] = { + static const char *movableTypeStrings[] = { "abortretryignore", "ok", "okcancel", "retrycancel", "yesno", "yesnocancel", (char *)NULL }; - static CONST char *movableButtonStrings[] = { + static const char *movableButtonStrings[] = { "abort", "retry", "ignore", "ok", "cancel", "yes", "no", (char *)NULL }; - static CONST char *movableIconStrings[] = { + static const char *movableIconStrings[] = { "error", "info", "question", "warning", (char *)NULL }; @@ -1355,19 +1365,19 @@ Tk_MessageBoxObjCmd( }; /* - * Need to map from 'movableButtonStrings' and its corresponding integer index, - * to the native button index, which is 1, 2, 3, from right to left. + * Need to map from 'movableButtonStrings' and its corresponding integer, + * index to the native button index, which is 1, 2, 3, from right to left. * This is necessary to do for each separate '-type' of button sets. */ - short buttonIndexAndTypeToNativeButtonIndex[][7] = { - /* abort retry ignore ok cancel yes no */ - {1, 2, 3, 0, 0, 0, 0}, /* abortretryignore */ - {0, 0, 0, 1, 0, 0, 0}, /* ok */ - {0, 0, 0, 1, 2, 0, 0}, /* okcancel */ - {0, 1, 0, 0, 2, 0, 0}, /* retrycancel */ - {0, 0, 0, 0, 0, 1, 2}, /* yesno */ - {0, 0, 0, 0, 3, 1, 2}, /* yesnocancel */ + short buttonIndexAndTypeToNativeButtonIndex[][7] = { + /* abort retry ignore ok cancel yes no */ + {1, 2, 3, 0, 0, 0, 0}, /* abortretryignore */ + {0, 0, 0, 1, 0, 0, 0}, /* ok */ + {0, 0, 0, 1, 2, 0, 0}, /* okcancel */ + {0, 1, 0, 0, 2, 0, 0}, /* retrycancel */ + {0, 0, 0, 0, 0, 1, 2}, /* yesno */ + {0, 0, 0, 0, 3, 1, 2}, /* yesnocancel */ }; /* @@ -1375,137 +1385,137 @@ Tk_MessageBoxObjCmd( * descriptive button text string index. */ - short nativeButtonIndexAndTypeToButtonIndex[][4] = { - {-1, 0, 1, 2}, /* abortretryignore */ - {-1, 3, 0, 0}, /* ok */ - {-1, 3, 4, 0}, /* okcancel */ - {-1, 1, 4, 0}, /* retrycancel */ - {-1, 5, 6, 0}, /* yesno */ - {-1, 5, 6, 4}, /* yesnocancel */ + short nativeButtonIndexAndTypeToButtonIndex[][4] = { + {-1, 0, 1, 2}, /* abortretryignore */ + {-1, 3, 0, 0}, /* ok */ + {-1, 3, 4, 0}, /* okcancel */ + {-1, 1, 4, 0}, /* retrycancel */ + {-1, 5, 6, 0}, /* yesno */ + {-1, 5, 6, 4}, /* yesnocancel */ }; alertType = kAlertPlainAlert; typeIndex = TYPE_OK; - GetStandardAlertDefaultParams(¶mCFStringRec, kStdCFStringAlertVersionOne); + ChkErr(GetStandardAlertDefaultParams, ¶mCFStringRec, + kStdCFStringAlertVersionOne); paramCFStringRec.movable = true; paramCFStringRec.helpButton = false; paramCFStringRec.defaultButton = kAlertStdAlertOKButton; paramCFStringRec.cancelButton = kAlertStdAlertCancelButton; for (i = 1; i < objc; i += 2) { - int iconIndex; - char *string; + int iconIndex; + char *string; if (Tcl_GetIndexFromObj(interp, objv[i], movableAlertStrings, "option", - TCL_EXACT, &index) != TCL_OK) { - result = TCL_ERROR; + TCL_EXACT, &index) != TCL_OK) { goto end; } if (i + 1 == objc) { string = Tcl_GetStringFromObj(objv[i], NULL); Tcl_AppendResult(interp, "value for \"", string, "\" missing", - (char *) NULL); - result = TCL_ERROR; + (char *) NULL); goto end; } switch (index) { - case ALERT_DEFAULT: - - /* - * Need to postpone processing of this option until we are - * sure to know the '-type' as well. - */ - - haveDefaultOption = true; - indexDefaultOption = i; - break; + /* + * Need to postpone processing of this option until we are + * sure to know the '-type' as well. + */ + haveDefaultOption = true; + indexDefaultOption = i; + break; case ALERT_DETAIL: - str = Tcl_GetStringFromObj(objv[i + 1], NULL); - finemessageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); - break; + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + finemessageTextCF = CFStringCreateWithCString(NULL, str, + kCFStringEncodingUTF8); + break; case ALERT_ICON: - /* not sure about UTF translation here... */ - if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableIconStrings, - "value", TCL_EXACT, &iconIndex) != TCL_OK) { - result = TCL_ERROR; - goto end; - } - switch (iconIndex) { - case ICON_ERROR: - alertType = kAlertStopAlert; - break; - case ICON_INFO: - alertType = kAlertNoteAlert; - break; - case ICON_QUESTION: - alertType = kAlertCautionAlert; - break; - case ICON_WARNING: - alertType = kAlertCautionAlert; + if (Tcl_GetIndexFromObj(interp, objv[i + 1], + movableIconStrings, "value", TCL_EXACT, &iconIndex) + != TCL_OK) { + goto end; + } + switch (iconIndex) { + case ICON_ERROR: + alertType = kAlertStopAlert; + break; + case ICON_INFO: + alertType = kAlertNoteAlert; + break; + case ICON_QUESTION: + alertType = kAlertCautionAlert; + break; + case ICON_WARNING: + alertType = kAlertCautionAlert; + break; + } break; - } - break; case ALERT_MESSAGE: - str = Tcl_GetStringFromObj(objv[i + 1], NULL); - messageTextCF = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); - break; + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + messageTextCF = CFStringCreateWithCString(NULL, str, + kCFStringEncodingUTF8); + break; case ALERT_PARENT: - str = Tcl_GetStringFromObj(objv[i + 1], NULL); - tkwin = Tk_NameToWindow(interp, str, tkwin); - if (tkwin == NULL) { - result = TCL_ERROR; - goto end; - } - haveParentOption = true; - break; + str = Tcl_GetStringFromObj(objv[i + 1], NULL); + tkwin = Tk_NameToWindow(interp, str, tkwin); + if (tkwin == NULL) { + goto end; + } + if (((TkWindow*)tkwin)->window != None && + TkMacOSXHostToplevelExists(tkwin)) { + haveParentOption = true; + } + break; case ALERT_TITLE: - break; + break; case ALERT_TYPE: - /* not sure about UTF translation here... */ - if (Tcl_GetIndexFromObj(interp, objv[i + 1], movableTypeStrings, - "value", TCL_EXACT, &typeIndex) != TCL_OK) { - result = TCL_ERROR; - goto end; - } - switch (typeIndex) { - case TYPE_ABORTRETRYIGNORE: - paramCFStringRec.defaultText = CFSTR("Abort"); - paramCFStringRec.cancelText = CFSTR("Retry"); - paramCFStringRec.otherText = CFSTR("Ignore"); - paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; - break; - case TYPE_OK: - paramCFStringRec.defaultText = CFSTR("OK"); - break; - case TYPE_OKCANCEL: - paramCFStringRec.defaultText = CFSTR("OK"); - paramCFStringRec.cancelText = CFSTR("Cancel"); - break; - case TYPE_RETRYCANCEL: - paramCFStringRec.defaultText = CFSTR("Retry"); - paramCFStringRec.cancelText = CFSTR("Cancel"); - break; - case TYPE_YESNO: - paramCFStringRec.defaultText = CFSTR("Yes"); - paramCFStringRec.cancelText = CFSTR("No"); - break; - case TYPE_YESNOCANCEL: - paramCFStringRec.defaultText = CFSTR("Yes"); - paramCFStringRec.cancelText = CFSTR("No"); - paramCFStringRec.otherText = CFSTR("Cancel"); - paramCFStringRec.cancelButton = kAlertStdAlertOtherButton; + if (Tcl_GetIndexFromObj(interp, objv[i + 1],\ + movableTypeStrings, "value", TCL_EXACT, &typeIndex) + != TCL_OK) { + goto end; + } + switch (typeIndex) { + case TYPE_ABORTRETRYIGNORE: + paramCFStringRec.defaultText = CFSTR("Abort"); + paramCFStringRec.cancelText = CFSTR("Retry"); + paramCFStringRec.otherText = CFSTR("Ignore"); + paramCFStringRec.cancelButton = + kAlertStdAlertOtherButton; + break; + case TYPE_OK: + paramCFStringRec.defaultText = CFSTR("OK"); + break; + case TYPE_OKCANCEL: + paramCFStringRec.defaultText = CFSTR("OK"); + paramCFStringRec.cancelText = CFSTR("Cancel"); + break; + case TYPE_RETRYCANCEL: + paramCFStringRec.defaultText = CFSTR("Retry"); + paramCFStringRec.cancelText = CFSTR("Cancel"); + break; + case TYPE_YESNO: + paramCFStringRec.defaultText = CFSTR("Yes"); + paramCFStringRec.cancelText = CFSTR("No"); + break; + case TYPE_YESNOCANCEL: + paramCFStringRec.defaultText = CFSTR("Yes"); + paramCFStringRec.cancelText = CFSTR("No"); + paramCFStringRec.otherText = CFSTR("Cancel"); + paramCFStringRec.cancelButton = + kAlertStdAlertOtherButton; + break; + } break; - } - break; } } @@ -1520,7 +1530,6 @@ Tk_MessageBoxObjCmd( if (Tcl_GetIndexFromObj(interp, objv[indexDefaultOption + 1], movableButtonStrings, "value", TCL_EXACT, &defaultButtonIndex) != TCL_OK) { - result = TCL_ERROR; goto end; } @@ -1530,8 +1539,7 @@ Tk_MessageBoxObjCmd( buttonIndexAndTypeToNativeButtonIndex[typeIndex][defaultButtonIndex]; if (defaultNativeButtonIndex == 0) { Tcl_SetObjResult(interp, - Tcl_NewStringObj("Illegal default option", -1)); - result = TCL_ERROR; + Tcl_NewStringObj("Illegal default option", -1)); goto end; } paramCFStringRec.defaultButton = defaultNativeButtonIndex; @@ -1539,67 +1547,62 @@ Tk_MessageBoxObjCmd( paramCFStringRec.cancelButton = 0; } } - SetThemeCursor(kThemeArrowCursor); + ChkErr(SetThemeCursor, kThemeArrowCursor); if (haveParentOption) { - TkWindow *winPtr; - WindowRef windowRef; - EventTargetRef notifyTarget; - EventHandlerUPP handler; - CallbackUserData data; + AlertHandlerUserData data; + static EventHandlerUPP handler = NULL; + WindowRef windowRef; const EventTypeSpec kEvents[] = { {kEventClassCommand, kEventProcessCommand} }; - winPtr = (TkWindow *) tkwin; - - /* - * Create the underlying Mac window for this Tk window. - */ - - windowRef = GetWindowFromPort( - TkMacOSXGetDrawablePort(Tk_WindowId(tkwin))); - notifyTarget = GetWindowEventTarget(windowRef); - osError = CreateStandardSheet(alertType, messageTextCF, - finemessageTextCF, ¶mCFStringRec, - notifyTarget, &dialogRef); - if(osError != noErr) { - result = TCL_ERROR; + bzero(&data, sizeof(data)); + if (!handler) { + handler = NewEventHandlerUPP(AlertHandler); + } + windowRef = GetWindowFromPort(TkMacOSXGetDrawablePort( + Tk_WindowId(tkwin))); + if (!windowRef) { goto end; } - data.windowRef = windowRef; - data.buttonIndex = 1; - handler = NewEventHandlerUPP(AlertHandler); - InstallEventHandler(notifyTarget, handler, - GetEventTypeCount(kEvents), - kEvents, &data, NULL); - osError = ShowSheetWindow(GetDialogWindow(dialogRef), windowRef); - if(osError != noErr) { - result = TCL_ERROR; + err = ChkErr(CreateStandardSheet, alertType, messageTextCF, + finemessageTextCF, ¶mCFStringRec, NULL, &dialogRef); + if(err != noErr) { goto end; } - osError = RunAppModalLoopForWindow(windowRef); - if (osError != noErr) { - result = TCL_ERROR; + data.dialogWindow = GetDialogWindow(dialogRef); + err = ChkErr(ShowSheetWindow, data.dialogWindow, windowRef); + if(err != noErr) { + DisposeDialog(dialogRef); goto end; } + ChkErr(GetWindowModality, data.dialogWindow, &data.origModality, + &data.origUnavailWindow); + ChkErr(SetWindowModality, data.dialogWindow, kWindowModalityAppModal, + NULL); + ChkErr(InstallEventHandler, GetWindowEventTarget(data.dialogWindow), + handler, GetEventTypeCount(kEvents), kEvents, &data, + &data.handlerRef); + TkMacOSXTrackingLoop(1); + ChkErr(RunAppModalLoopForWindow, data.dialogWindow); + TkMacOSXTrackingLoop(0); itemHit = data.buttonIndex; - DisposeEventHandlerUPP(handler); } else { - osError = CreateStandardAlert(alertType, messageTextCF, - finemessageTextCF, ¶mCFStringRec, &dialogRef); - if(osError != noErr) { - result = TCL_ERROR; + err = ChkErr(CreateStandardAlert, alertType, messageTextCF, + finemessageTextCF, ¶mCFStringRec, &dialogRef); + if(err != noErr) { goto end; } - osError = RunStandardAlert(dialogRef, NULL, &itemHit); - if (osError != noErr) { - result = TCL_ERROR; + TkMacOSXTrackingLoop(1); + err = ChkErr(RunStandardAlert, dialogRef, NULL, &itemHit); + TkMacOSXTrackingLoop(0); + if (err != noErr) { goto end; } } - if(osError == noErr) { - int ind; + if (err == noErr) { + int ind; /* * Map 'itemHit' (1, 2, 3) to descriptive text string. @@ -1608,20 +1611,19 @@ Tk_MessageBoxObjCmd( ind = nativeButtonIndexAndTypeToButtonIndex[typeIndex][itemHit]; Tcl_SetObjResult(interp, Tcl_NewStringObj(movableButtonStrings[ind], -1)); - } else { - result = TCL_ERROR; + result = TCL_OK; } - end: - if (finemessageTextCF != NULL) { +end: + if (finemessageTextCF) { CFRelease(finemessageTextCF); } - if (messageTextCF != NULL) { + if (messageTextCF) { CFRelease(messageTextCF); } return result; } - + /* *---------------------------------------------------------------------- * @@ -1638,31 +1640,30 @@ Tk_MessageBoxObjCmd( *---------------------------------------------------------------------- */ -static OSStatus +OSStatus AlertHandler(EventHandlerCallRef callRef, EventRef eventRef, void *userData) { - OSStatus result = eventNotHandledErr; - HICommand cmd; - CallbackUserData *dataPtr = (CallbackUserData *) userData; + AlertHandlerUserData *data = (AlertHandlerUserData *) userData; + HICommand cmd; - GetEventParameter(eventRef, kEventParamDirectObject, typeHICommand, - NULL, sizeof(cmd), NULL, &cmd); + ChkErr(GetEventParameter,eventRef, kEventParamDirectObject, typeHICommand, + NULL, sizeof(cmd), NULL, &cmd); switch (cmd.commandID) { case kHICommandOK: - dataPtr->buttonIndex = 1; - result = noErr; - break; + data->buttonIndex = 1; + break; case kHICommandCancel: - dataPtr->buttonIndex = 2; - result = noErr; - break; + data->buttonIndex = 2; + break; case kHICommandOther: - dataPtr->buttonIndex = 3; - result = noErr; - break; + data->buttonIndex = 3; + break; } - if (result == noErr) { - result = QuitAppModalLoopForWindow(dataPtr->windowRef); + if (data->buttonIndex) { + ChkErr(QuitAppModalLoopForWindow, data->dialogWindow); + ChkErr(RemoveEventHandler, data->handlerRef); + ChkErr(SetWindowModality, data->dialogWindow, + data->origModality, data->origUnavailWindow); } - return result; + return eventNotHandledErr; } Index: macosx/tkMacOSXDraw.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXDraw.c,v retrieving revision 1.18 diff -u -p -r1.18 tkMacOSXDraw.c --- macosx/tkMacOSXDraw.c 16 Oct 2006 16:25:38 -0000 1.18 +++ macosx/tkMacOSXDraw.c 15 Mar 2007 02:42:10 -0000 @@ -7,7 +7,7 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2006 Daniel A. Steffen + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -24,9 +24,6 @@ #endif */ -#define RGBFLOATRED(c) ((c).red / 65535.0) -#define RGBFLOATGREEN(c) ((c).green / 65535.0) -#define RGBFLOATBLUE(c) ((c).blue / 65535.0) #define radians(d) ((d) * (M_PI/180.0)) /* @@ -39,8 +36,9 @@ * Temporary regions that can be reused. */ -static RgnHandle tmpRgn = NULL; -static RgnHandle tmpRgn2 = NULL; +RgnHandle tkMacOSXtmpRgn1 = NULL; +RgnHandle tkMacOSXtmpRgn2 = NULL; + static PixPatHandle gPenPat = NULL; static int useCGDrawing = 1; @@ -54,10 +52,7 @@ static int useThemedFrame = 0; * Prototypes for functions used only in this file. */ static unsigned char InvertByte(unsigned char data); -static void TkMacOSXSetUpCGContext(MacDrawable *macWin, CGrafPtr destPort, - GC gc, CGContextRef *contextPtr); -static void TkMacOSXReleaseCGContext(MacDrawable *macWin, CGrafPtr destPort, - CGContextRef *context); + /* *---------------------------------------------------------------------- @@ -112,7 +107,20 @@ TkMacOSXInitCGDrawing(interp, enable, li (char *) &useThemedFrame, TCL_LINK_BOOLEAN) != TCL_OK) { Tcl_ResetResult(interp); } + + if (tkMacOSXtmpRgn1 == NULL) { + tkMacOSXtmpRgn1 = NewRgn(); + } + if (tkMacOSXtmpRgn2 == NULL) { + tkMacOSXtmpRgn2 = NewRgn(); + } + } +#ifdef TK_MAC_DEBUG_DRAWING + TkMacOSXInitNamedDebugSymbol(QD, void, QD_DebugPrint, char*); + if (QD_DebugPrint) { + ; /* gdb: b *QD_DebugPrint */ } +#endif /* TK_MAC_DEBUG_WINDOWS */ return TCL_OK; } @@ -153,9 +161,8 @@ XCopyArea( const BitMap * dstBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *dstDraw = (MacDrawable *) dst; - CGrafPtr srcPort, dstPort; - CGrafPtr saveWorld; - GDHandle saveDevice; + CGrafPtr srcPort, dstPort, savePort; + Boolean portChanged; short tmode; RGBColor origForeColor, origBackColor, whiteColor, blackColor; Rect clpRect; @@ -164,8 +171,7 @@ XCopyArea( srcPort = TkMacOSXGetDrawablePort(src); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(dstPort, NULL); + portChanged = QDSwapPort(dstPort, &savePort); GetForeColor(&origForeColor); GetBackColor(&origBackColor); whiteColor.red = 0; @@ -177,9 +183,6 @@ XCopyArea( blackColor.green = 0xFFFF; RGBBackColor(&blackColor); - if (tmpRgn2 == NULL) { - tmpRgn2 = NewRgn(); - } srcPtr = &srcRect; SetRect(&srcRect, (short) (srcDraw->xOff + src_x), (short) (srcDraw->yOff + src_y), @@ -200,7 +203,8 @@ XCopyArea( * be able to restore it when we exit. */ - GetClip(tmpRgn2); + TkMacOSXCheckTmpRgnEmpty(2); + GetClip(tkMacOSXtmpRgn2); if (tkPictureIsOpen) { /* * When rendering into a picture, after a call to "OpenCPicture" @@ -215,23 +219,22 @@ XCopyArea( dstPtr = &srcRect; ClipRect(&clpRect); } - if (!gc->clip_mask) { - } else if (((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) { + if (gc->clip_mask && ((TkpClipMask*)gc->clip_mask)->type + == TKP_CLIP_REGION) { RgnHandle clipRgn = (RgnHandle) ((TkpClipMask*)gc->clip_mask)->value.region; - int xOffset = 0, yOffset = 0; - if (tmpRgn == NULL) { - tmpRgn = NewRgn(); - } + if (!tkPictureIsOpen) { xOffset = dstDraw->xOff + gc->clip_x_origin; yOffset = dstDraw->yOff + gc->clip_y_origin; OffsetRgn(clipRgn, xOffset, yOffset); } - GetClip(tmpRgn); - SectRgn(tmpRgn, clipRgn, tmpRgn); - SetClip(tmpRgn); + TkMacOSXCheckTmpRgnEmpty(1); + GetClip(tkMacOSXtmpRgn1); + SectRgn(tkMacOSXtmpRgn1, clipRgn, tkMacOSXtmpRgn1); + SetClip(tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn1); if (!tkPictureIsOpen) { OffsetRgn(clipRgn, -xOffset, -yOffset); } @@ -243,8 +246,11 @@ XCopyArea( CopyBits(srcBit, dstBit, srcPtr, dstPtr, tmode, NULL); RGBForeColor(&origForeColor); RGBBackColor(&origBackColor); - SetClip(tmpRgn2); - SetGWorld(saveWorld, saveDevice); + SetClip(tkMacOSXtmpRgn2); + SetEmptyRgn(tkMacOSXtmpRgn2); + if (portChanged) { + QDSwapPort(savePort, NULL); + } } /* @@ -287,10 +293,8 @@ XCopyPlane( const BitMap * mskBit; MacDrawable *srcDraw = (MacDrawable *) src; MacDrawable *dstDraw = (MacDrawable *) dst; - GWorldPtr srcPort, dstPort, mskPort; - CGrafPtr saveWorld; - GDHandle saveDevice; - RGBColor macColor; + CGrafPtr srcPort, dstPort, mskPort, savePort; + Boolean portChanged; TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask; short tmode; @@ -298,8 +302,7 @@ XCopyPlane( dstPort = TkMacOSXGetDrawablePort(dst); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(dstPort, NULL); + portChanged = QDSwapPort(dstPort, &savePort); TkMacOSXSetUpClippingRgn(dst); srcBit = GetPortBitMapForCopyBits(srcPort); @@ -331,17 +334,14 @@ XCopyPlane( tmode = srcOr; tmode = srcCopy + transparent; - if (TkSetMacColor(gc->foreground, &macColor) == true) { - RGBForeColor(&macColor); - } + TkMacOSXSetColorInPort(gc->foreground, 1, NULL); if (clipPtr == NULL || clipPtr->type == TKP_CLIP_REGION) { /* * Case 1: opaque bitmaps. */ - TkSetMacColor(gc->background, &macColor); - RGBBackColor(&macColor); + TkMacOSXSetColorInPort(gc->background, 0, NULL); tmode = srcCopy; CopyBits(srcBit, dstBit, srcPtr, dstPtr, tmode, NULL); } else if (clipPtr->type == TKP_CLIP_PIXMAP) { @@ -371,8 +371,9 @@ XCopyPlane( srcPtr, srcPtr, dstPtr, tmode, NULL); } } - - SetGWorld(saveWorld, saveDevice); + if (portChanged) { + QDSwapPort(savePort, NULL); + } } /* @@ -407,9 +408,8 @@ TkPutImage( unsigned int width, /* Same width & height for both */ unsigned int height) /* distination and source. */ { - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + CGrafPtr destPort, savePort; + Boolean portChanged; const BitMap * destBits; MacDrawable *dstDraw = (MacDrawable *) d; int i, j; @@ -420,9 +420,8 @@ TkPutImage( int slices, sliceRowBytes, lastSliceRowBytes, sliceWidth, lastSliceWidth; display->request++; - GetGWorld(&saveWorld, &saveDevice); destPort = TkMacOSXGetDrawablePort(d); - SetGWorld(destPort, NULL); + portChanged = QDSwapPort(destPort, &savePort); destBits = GetPortBitMapForCopyBits(destPort); TkMacOSXSetUpClippingRgn(d); @@ -580,8 +579,9 @@ TkPutImage( if (newData != NULL) { ckfree(newData); } - - SetGWorld(saveWorld, saveDevice); + if (portChanged) { + QDSwapPort(savePort, NULL); + } } /* @@ -610,50 +610,37 @@ XDrawLines( int mode) /* Line drawing mode. */ { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GWorldPtr destPort; - GDHandle saveDevice; + TkMacOSXDrawingContext dc; int i, lw = gc->line_width; if (npoints < 2) { return; /* TODO: generate BadValue error. */ } - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; - float prevx, prevy; - float o = (lw % 2) ? .5 : 0; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { + double prevx, prevy; + double o = (lw % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); - CGContextBeginPath(outContext); + CGContextBeginPath(dc.context); prevx = macWin->xOff + points[0].x + o; prevy = macWin->yOff + points[0].y + o; - CGContextMoveToPoint(outContext, prevx, prevy); + CGContextMoveToPoint(dc.context, prevx, prevy); for (i = 1; i < npoints; i++) { if (mode == CoordModeOrigin) { - CGContextAddLineToPoint(outContext, + CGContextAddLineToPoint(dc.context, macWin->xOff + points[i].x + o, macWin->yOff + points[i].y + o); } else { prevx += points[i].x; prevy += points[i].y; - CGContextAddLineToPoint(outContext, prevx, prevy); + CGContextAddLineToPoint(dc.context, prevx, prevy); } } - CGContextStrokePath(outContext); - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); + CGContextStrokePath(dc.context); } else { int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); /* This is broken for fat lines, it is not possible to correctly * imitate X11 drawing of oblique fat lines with QD line drawing, * we should draw a filled polygon instead. */ @@ -667,10 +654,8 @@ XDrawLines( Line((short) points[i].x, (short) points[i].y); } } - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } /* @@ -697,39 +682,26 @@ void XDrawSegments( int nsegments) { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GWorldPtr destPort; - GDHandle saveDevice; + TkMacOSXDrawingContext dc; int i, lw = gc->line_width; - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { + double o = (lw % 2) ? .5 : 0; - if (useCGDrawing) { - CGContextRef outContext; - float o = (lw % 2) ? .5 : 0; - - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); for (i = 0; i < nsegments; i++) { - CGContextBeginPath(outContext); - CGContextMoveToPoint(outContext, + CGContextBeginPath(dc.context); + CGContextMoveToPoint(dc.context, macWin->xOff + segments[i].x1 + o, macWin->yOff + segments[i].y1 + o); - CGContextAddLineToPoint(outContext, + CGContextAddLineToPoint(dc.context, macWin->xOff + segments[i].x2 + o, macWin->yOff + segments[i].y2 + o); - CGContextStrokePath(outContext); + CGContextStrokePath(dc.context); } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); /* This is broken for fat lines, it is not possible to correctly * imitate X11 drawing of oblique fat lines with QD line drawing, * we should draw a filled polygon instead. */ @@ -739,10 +711,8 @@ void XDrawSegments( LineTo((short) (macWin->xOff + segments[i].x2 + o), (short) (macWin->yOff + segments[i].y2 + o)); } - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } /* @@ -772,45 +742,33 @@ XFillPolygon( int mode) /* Drawing mode. */ { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; int i; - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; - float prevx, prevy; - float o = (gc->line_width % 2) ? .5 : 0; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { + double prevx, prevy; + double o = (gc->line_width % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); - CGContextBeginPath(outContext); + CGContextBeginPath(dc.context); prevx = macWin->xOff + points[0].x + o; prevy = macWin->yOff + points[0].y + o; - CGContextMoveToPoint(outContext, prevx, prevy); + CGContextMoveToPoint(dc.context, prevx, prevy); for (i = 1; i < npoints; i++) { if (mode == CoordModeOrigin) { - CGContextAddLineToPoint(outContext, + CGContextAddLineToPoint(dc.context, macWin->xOff + points[i].x + o, macWin->yOff + points[i].y + o); } else { prevx += points[i].x; prevy += points[i].y; - CGContextAddLineToPoint(outContext, prevx, prevy); + CGContextAddLineToPoint(dc.context, prevx, prevy); } } - CGContextEOFillPath(outContext); - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); + CGContextEOFillPath(dc.context); } else { PolyHandle polygon; - TkMacOSXSetUpGraphicsPort(gc, destPort); - PenNormal(); polygon = OpenPoly(); MoveTo((short) (macWin->xOff + points[0].x), (short) (macWin->yOff + points[0].y)); @@ -826,8 +784,7 @@ XFillPolygon( FillCPoly(polygon, gPenPat); KillPoly(polygon); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } /* @@ -857,49 +814,34 @@ XDrawRectangle( unsigned int height) { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; int lw = gc->line_width; if (width == 0 || height == 0) { return; } - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0; + double o = (lw % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); rect = CGRectMake( macWin->xOff + x + o, macWin->yOff + y + o, width, height); - CGContextStrokeRect(outContext, rect); - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); + CGContextStrokeRect(dc.context, rect); } else { Rect theRect; int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); theRect.left = (short) (macWin->xOff + x + o); theRect.top = (short) (macWin->yOff + y + o); theRect.right = (short) (theRect.left + width + lw); theRect.bottom = (short) (theRect.top + height + lw); FrameRect(&theRect); - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #ifdef TK_MACOSXDRAW_UNUSED @@ -938,24 +880,15 @@ XDrawRectangles( int nRects) { MacDrawable *macWin = (MacDrawable *) drawable; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; XRectangle * rectPtr; int i, lw = gc->line_width; - destPort = TkMacOSXGetDrawablePort(drawable); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(drawable); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0; + double o = (lw % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); for (i = 0, rectPtr = rectArr; i < nRects; i++, rectPtr++) { if (rectPtr->width == 0 || rectPtr->height == 0) { continue; @@ -964,16 +897,12 @@ XDrawRectangles( macWin->xOff + rectPtr->x + o, macWin->yOff + rectPtr->y + o, rectPtr->width, rectPtr->height); - CGContextStrokeRect(outContext, rect); + CGContextStrokeRect(dc.context, rect); } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); for (i = 0, rectPtr = rectArr; i < nRects;i++, rectPtr++) { theRect.left = (short) (macWin->xOff + rectPtr->x + o); theRect.top = (short) (macWin->yOff + rectPtr->y + o); @@ -981,10 +910,8 @@ XDrawRectangles( theRect.bottom = (short) (theRect.top + rectPtr->height + lw); FrameRect(&theRect); } - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #endif @@ -1012,23 +939,14 @@ XFillRectangles( int n_rectangles) /* Number of rectangles. */ { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; XRectangle * rectPtr; int i; - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); for (i = 0, rectPtr = rectangles; i < n_rectangles; i++, rectPtr++) { if (rectPtr->width == 0 || rectPtr->height == 0) { continue; @@ -1037,13 +955,11 @@ XFillRectangles( macWin->xOff + rectPtr->x, macWin->yOff + rectPtr->y, rectPtr->width, rectPtr->height); - CGContextFillRect(outContext, rect); + CGContextFillRect(dc.context, rect); } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; - TkMacOSXSetUpGraphicsPort(gc, destPort); for (i = 0, rectPtr = rectangles; i < n_rectangles; i++, rectPtr++) { theRect.left = (short) (macWin->xOff + rectPtr->x); theRect.top = (short) (macWin->yOff + rectPtr->y); @@ -1052,8 +968,7 @@ XFillRectangles( FillCRect(&theRect, gPenPat); } } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } /* @@ -1085,63 +1000,53 @@ XDrawArc( int angle2) /* Extent of arc. */ { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; int lw = gc->line_width; if (width == 0 || height == 0 || angle2 == 0) { return; } - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0; + double o = (lw % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); rect = CGRectMake( macWin->xOff + x + o, macWin->yOff + y + o, width, height); #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 - if (angle1 == 0 && angle2 == 23040 && - CGContextStrokeEllipseInRect != NULL) { - CGContextStrokeEllipseInRect(outContext, rect); + if (angle1 == 0 && angle2 == 23040 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && CGContextStrokeEllipseInRect != NULL +#endif + ) { + CGContextStrokeEllipseInRect(dc.context, rect); } else #endif { CGMutablePathRef p = CGPathCreateMutable(); CGAffineTransform t = CGAffineTransformIdentity; CGPoint c = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); - float w = CGRectGetWidth(rect); + double w = CGRectGetWidth(rect); if (width != height) { - t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w); + t = CGAffineTransformMakeScale(1.0, CGRectGetHeight(rect)/w); c = CGPointApplyAffineTransform(c, CGAffineTransformInvert(t)); } CGPathAddArc(p, &t, c.x, c.y, w/2, radians(-angle1/64.0), radians(-(angle1 + angle2)/64.0), angle2 > 0); - CGContextAddPath(outContext, p); + CGContextAddPath(dc.context, p); CGPathRelease(p); - CGContextStrokePath(outContext); + CGContextStrokePath(dc.context); } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; short start, extent; int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); theRect.left = (short) (macWin->xOff + x + o); theRect.top = (short) (macWin->yOff + y + o); theRect.right = (short) (theRect.left + width + lw); @@ -1149,10 +1054,8 @@ XDrawArc( start = (short) (90 - (angle1/64)); extent = (short) (-(angle2/64)); FrameArc(&theRect, start, extent); - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #ifdef TK_MACOSXDRAW_UNUSED @@ -1188,24 +1091,15 @@ XDrawArcs( { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; XArc * arcPtr; int i, lw = gc->line_width; - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0; + double o = (lw % 2) ? .5 : 0; - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); for (i=0, arcPtr = arcArr; i < nArcs; i++, arcPtr++) { if (arcPtr->width == 0 || arcPtr->height == 0 || arcPtr->angle2 == 0) { @@ -1217,9 +1111,12 @@ XDrawArcs( arcPtr->width, arcPtr->height); #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 - if (arcPtr->angle1 == 0 && arcPtr->angle2 == 23040 && - CGContextStrokeEllipseInRect != NULL) { - CGContextStrokeEllipseInRect(outContext, rect); + if (arcPtr->angle1 == 0 && arcPtr->angle2 == 23040 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && CGContextStrokeEllipseInRect != NULL +#endif + ) { + CGContextStrokeEllipseInRect(dc.context, rect); } else #endif { @@ -1227,7 +1124,7 @@ XDrawArcs( CGAffineTransform t = CGAffineTransformIdentity; CGPoint c = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); - float w = CGRectGetWidth(rect); + double w = CGRectGetWidth(rect); if (arcPtr->width != arcPtr->height) { t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w); @@ -1238,20 +1135,16 @@ XDrawArcs( radians(-arcPtr->angle1/64.0), radians(-(arcPtr->angle1 + arcPtr->angle2)/64.0), arcPtr->angle2 > 0); - CGContextAddPath(outContext, p); + CGContextAddPath(dc.context, p); CGPathRelease(p); - CGContextStrokePath(outContext); + CGContextStrokePath(dc.context); } } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; short start, extent; int o = -lw/2; - TkMacOSXSetUpGraphicsPort(gc, destPort); - ShowPen(); - PenPixPat(gPenPat); for (i = 0, arcPtr = arcArr;i < nArcs;i++, arcPtr++) { theRect.left = (short) (macWin->xOff + arcPtr->x + o); theRect.top = (short) (macWin->yOff + arcPtr->y + o); @@ -1261,10 +1154,8 @@ XDrawArcs( extent = (short) (-(arcPtr->angle2/64)); FrameArc(&theRect, start, extent); } - HidePen(); } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #endif @@ -1297,47 +1188,41 @@ XFillArc( int angle2) /* Extent of arc. */ { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; int lw = gc->line_width; if (width == 0 || height == 0 || angle2 == 0) { return; } - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0, u = 0; + double o = (lw % 2) ? .5 : 0, u = 0; if (notAA(lw)) { o += NON_AA_CG_OFFSET/2; u += NON_AA_CG_OFFSET; } - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); rect = CGRectMake( macWin->xOff + x + o, macWin->yOff + y + o, width - u, height - u); #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 - if (angle1 == 0 && angle2 == 23040 && - CGContextFillEllipseInRect != NULL) { - CGContextFillEllipseInRect(outContext, rect); + if (angle1 == 0 && angle2 == 23040 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && CGContextFillEllipseInRect != NULL +#endif + ) { + CGContextFillEllipseInRect(dc.context, rect); } else #endif { CGMutablePathRef p = CGPathCreateMutable(); CGAffineTransform t = CGAffineTransformIdentity; CGPoint c = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); - float w = CGRectGetWidth(rect); + double w = CGRectGetWidth(rect); if (width != height) { t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w); @@ -1349,11 +1234,10 @@ XFillArc( CGPathAddArc(p, &t, c.x, c.y, w/2, radians(-angle1/64.0), radians(-(angle1 + angle2)/64.0), angle2 > 0); CGPathCloseSubpath(p); - CGContextAddPath(outContext, p); + CGContextAddPath(dc.context, p); CGPathRelease(p); - CGContextFillPath(outContext); + CGContextFillPath(dc.context); } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; short start, extent; @@ -1363,7 +1247,6 @@ XFillArc( double boxWidth, boxHeight; double vertex[2], center1[2], center2[2]; - TkMacOSXSetUpGraphicsPort(gc, destPort); theRect.left = (short) (macWin->xOff + x + o); theRect.top = (short) (macWin->yOff + y + o); theRect.right = (short) (theRect.left + width + lw); @@ -1392,19 +1275,14 @@ XFillArc( LineTo((short) (center1[0] + .5), (short) (center1[1] + .5)); LineTo((short) (center2[0] + .5), (short) (center2[1] + .5)); ClosePoly(); - ShowPen(); FillCArc(&theRect, start, extent, gPenPat); FillCPoly(polygon, gPenPat); - HidePen(); KillPoly(polygon); } else { - ShowPen(); FillCArc(&theRect, start, extent, gPenPat); - HidePen(); } } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #ifdef TK_MACOSXDRAW_UNUSED @@ -1432,28 +1310,19 @@ XFillArcs( int nArcs) { MacDrawable *macWin = (MacDrawable *) d; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; XArc * arcPtr; int i, lw = gc->line_width; - destPort = TkMacOSXGetDrawablePort(d); display->request++; - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - TkMacOSXSetUpClippingRgn(d); - - if (useCGDrawing) { - CGContextRef outContext; + if (TkMacOSXSetupDrawingContext(d, gc, useCGDrawing, &dc)) { CGRect rect; - float o = (lw % 2) ? .5 : 0, u = 0; + double o = (lw % 2) ? .5 : 0, u = 0; if (notAA(lw)) { o += NON_AA_CG_OFFSET/2; u += NON_AA_CG_OFFSET; } - TkMacOSXSetUpCGContext(macWin, destPort, gc, &outContext); for (i = 0, arcPtr = arcArr; i < nArcs; i++, arcPtr++) { if (arcPtr->width == 0 || arcPtr->height == 0 || arcPtr->angle2 == 0) { @@ -1465,9 +1334,12 @@ XFillArcs( arcPtr->width - u, arcPtr->height - u); #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 - if (arcPtr->angle1 == 0 && arcPtr->angle2 == 23040 && - CGContextFillEllipseInRect != NULL) { - CGContextFillEllipseInRect(outContext, rect); + if (arcPtr->angle1 == 0 && arcPtr->angle2 == 23040 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040 + && CGContextFillEllipseInRect != NULL +#endif + ) { + CGContextFillEllipseInRect(dc.context, rect); } else #endif { @@ -1475,7 +1347,7 @@ XFillArcs( CGAffineTransform t = CGAffineTransformIdentity; CGPoint c = CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); - float w = CGRectGetWidth(rect); + double w = CGRectGetWidth(rect); if (arcPtr->width != arcPtr->height) { t = CGAffineTransformMakeScale(1, CGRectGetHeight(rect)/w); @@ -1490,12 +1362,11 @@ XFillArcs( radians(-(arcPtr->angle1 + arcPtr->angle2)/64.0), arcPtr->angle2 > 0); CGPathCloseSubpath(p); - CGContextAddPath(outContext, p); + CGContextAddPath(dc.context, p); CGPathRelease(p); - CGContextFillPath(outContext); + CGContextFillPath(dc.context); } } - TkMacOSXReleaseCGContext(macWin, destPort, &outContext); } else { Rect theRect; short start, extent; @@ -1505,7 +1376,6 @@ XFillArcs( double boxWidth, boxHeight; double vertex[2], center1[2], center2[2]; - TkMacOSXSetUpGraphicsPort(gc, destPort); for (i = 0, arcPtr = arcArr;ixOff + arcPtr->x + o); theRect.top = (short) (macWin->yOff + arcPtr->y + o); @@ -1536,20 +1406,15 @@ XFillArcs( LineTo((short) (center1[0] + .5), (short) (center1[1] + .5)); LineTo((short) (center2[0] + .5), (short) (center2[1] + .5)); ClosePoly(); - ShowPen(); FillCArc(&theRect, start, extent, gPenPat); FillCPoly(polygon, gPenPat); - HidePen(); KillPoly(polygon); } else { - ShowPen(); FillCArc(&theRect, start, extent, gPenPat); - HidePen(); } } } - - SetGWorld(saveWorld, saveDevice); + TkMacOSXRestoreDrawingContext(&dc); } #endif @@ -1601,15 +1466,12 @@ TkScrollWindow( { MacDrawable *destDraw = (MacDrawable *) Tk_WindowId(tkwin); RgnHandle rgn = (RgnHandle) damageRgn; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + CGrafPtr destPort, savePort; + Boolean portChanged; Rect srcRect, scrollRect; - RgnHandle visRgn, clipRgn; destPort = TkMacOSXGetDrawablePort(Tk_WindowId(tkwin)); - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); + portChanged = QDSwapPort(destPort, &savePort); TkMacOSXSetUpClippingRgn(Tk_WindowId(tkwin)); /* @@ -1642,44 +1504,25 @@ TkScrollWindow( * Adjust clip region so that we don't copy any windows * that may overlap us. */ - visRgn = NewRgn(); - clipRgn = NewRgn(); + TkMacOSXCheckTmpRgnEmpty(1); + TkMacOSXCheckTmpRgnEmpty(2); RectRgn(rgn, &srcRect); - GetPortVisibleRegion(destPort,visRgn); - DiffRgn(rgn, visRgn, rgn); + GetPortVisibleRegion(destPort,tkMacOSXtmpRgn1); + DiffRgn(rgn, tkMacOSXtmpRgn1, rgn); OffsetRgn(rgn, dx, dy); - GetPortClipRegion(destPort, clipRgn); - DiffRgn(clipRgn, rgn, clipRgn); - SetPortClipRegion(destPort, clipRgn); + GetPortClipRegion(destPort, tkMacOSXtmpRgn2); + DiffRgn(tkMacOSXtmpRgn2, rgn, tkMacOSXtmpRgn2); + SetPortClipRegion(destPort, tkMacOSXtmpRgn2); + SetEmptyRgn(tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn2); SetEmptyRgn(rgn); - /* - * When a menu is up, the Mac does not expect drawing to occur and - * does not clip out the menu. We have to do it ourselves. This - * is pretty gross. - */ - - if (tkUseMenuCascadeRgn == 1) { - Point scratch = {0, 0}; - MacDrawable *macDraw = (MacDrawable *) Tk_WindowId(tkwin); - - LocalToGlobal(&scratch); - CopyRgn(tkMenuCascadeRgn, rgn); - OffsetRgn(rgn, -scratch.h, -scratch.v); - DiffRgn(clipRgn, rgn, clipRgn); - SetPortClipRegion(destPort, clipRgn); - SetEmptyRgn(rgn); - macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU; - } - ScrollRect(&scrollRect, dx, dy, rgn); - - SetGWorld(saveWorld, saveDevice); - - DisposeRgn(clipRgn); - DisposeRgn(visRgn); + if (portChanged) { + QDSwapPort(savePort, NULL); + } /* - * Fortunantly, the region returned by ScrollRect is symanticlly + * Fortunately, the region returned by ScrollRect is semantically * the same as what we need to return in this function. If the * region is empty we return zero to denote that no damage was * created. @@ -1709,62 +1552,40 @@ TkScrollWindow( void TkMacOSXSetUpGraphicsPort( - GC gc, - GWorldPtr destPort) /* GC to apply to current port. */ + GC gc, /* GC to apply to current port. */ + GWorldPtr destPort) { - RGBColor macColor; - if (gPenPat == NULL) { gPenPat = NewPixPat(); } - - if (TkSetMacColor(gc->foreground, &macColor) == true) { - /* TODO: cache RGBPats for preformace - measure gains... */ - MakeRGBPat(gPenPat, &macColor); - } - PenNormal(); - if(gc->function == GXxor) { - PenMode(patXor); - } - if (gc->line_width > 1) { - PenSize(gc->line_width, gc->line_width); - } - if (gc->line_style != LineSolid) { - /* - * Here the dash pattern should be set in the drawing, - * environment, but I don't know how to do that for the Mac. - * - * p[] is an array of unsigned chars containing the dash list. - * A '\0' indicates the end of this list. - * - * Someone knows how to implement this? If you have a more - * complete implementation of SetUpGraphicsPort() for - * the Mac (or for Windows), please let me know. - * - * Jan Nijtmans - * CMG Arnhem, B.V. - * email: j.nijtmans@chello.nl (private) - * jan.nijtmans@cmg.nl (work) - * url: http://purl.oclc.org/net/nijtmans/ - * - * FIXME: - * This is not possible with QuickDraw line drawing. As of - * Tk 8.4.7 we have a complete set of drawing routines using - * CG, so there is no reason to support this here. - */ + if (gc) { + TkMacOSXSetColorInPort(gc->foreground, 1, gPenPat); + if(gc->function == GXxor) { + PenMode(patXor); + } + if (gc->line_width > 1) { + PenSize(gc->line_width, gc->line_width); + } + if (gc->line_style != LineSolid) { + /* + * FIXME: + * Here the dash pattern should be set in the drawing environment. + * This is not possible with QuickDraw line drawing. + */ + } } } /* *---------------------------------------------------------------------- * - * TkMacOSXSetUpCGContext -- + * TkMacOSXSetUpDrawingContext -- * - * Set up a CGContext for the given graphics port. + * Set up a drawing context for the given drawable and GC. * * Results: - * None. + * Boolean indicating whether to use CG drawing. * * Side effects: * None. @@ -1772,126 +1593,201 @@ TkMacOSXSetUpGraphicsPort( *---------------------------------------------------------------------- */ -static void -TkMacOSXSetUpCGContext( - MacDrawable *macWin, - CGrafPtr destPort, - GC gc, - CGContextRef *contextPtr) +int +TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG, + TkMacOSXDrawingContext *dc) { - RGBColor macColor; - CGContextRef outContext; - OSStatus err; - Rect boundsRect; - CGAffineTransform coordsTransform; - static RgnHandle clipRgn = NULL; - float w; - - err = QDBeginCGContext(destPort, contextPtr); - outContext = *contextPtr; - - /* - * Now clip the CG Context to the port. Note, we have already - * set up the port with our clip region, so we can just get - * the clip back out of there. If we use the macWin->clipRgn - * directly at this point, we get some odd drawing effects. - * - * We also have to intersect our clip region with the port - * visible region so we don't overwrite the window decoration. - */ + MacDrawable *macDraw = ((MacDrawable*)d); + CGContextRef context = macDraw->context; + CGrafPtr port; + Rect portBounds; + + port = TkMacOSXGetDrawablePort(d); + if (port) { + GetPortBounds(port, &portBounds); + } + + if (port && !context) { + dc->portChanged = QDSwapPort(port, &(dc->savePort)); + TkMacOSXSetUpClippingRgn(d); + TkMacOSXCheckTmpRgnEmpty(1); + if (useCG) { + if (ChkErr(QDBeginCGContext, port, &context) == noErr) { + /* + * Now clip the CG Context to the port. Note, we have already + * set up the port with our clip region, so we can just get + * the clip back out of there. If we use the macWin->clipRgn + * directly at this point, we get some odd drawing effects. + * + * We also have to intersect our clip region with the port + * visible region so we don't overwrite the window decoration. + */ + + RectRgn(tkMacOSXtmpRgn1, &portBounds); + SectRegionWithPortClipRegion(port, tkMacOSXtmpRgn1); + SectRegionWithPortVisibleRegion(port, tkMacOSXtmpRgn1); + if (gc && gc->clip_mask && ((TkpClipMask*)gc->clip_mask)->type + == TKP_CLIP_REGION) { + RgnHandle clipRgn = (RgnHandle) + ((TkpClipMask*)gc->clip_mask)->value.region; + int xOffset = macDraw->xOff + gc->clip_x_origin; + int yOffset = macDraw->yOff + gc->clip_y_origin; + + OffsetRgn(clipRgn, xOffset, yOffset); + SectRgn(clipRgn, tkMacOSXtmpRgn1, tkMacOSXtmpRgn1); + OffsetRgn(clipRgn, -xOffset, -yOffset); + } + ClipCGContextToRegion(context, &portBounds, tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn1); - if (!clipRgn) { - clipRgn = NewRgn(); - } + /* + * Note: You have to call SyncCGContextOriginWithPort + * AFTER all the clip region manipulations. + */ - GetPortBounds(destPort, &boundsRect); + SyncCGContextOriginWithPort(context, port); + dc->saveState = NULL; + } else { + context = NULL; + useCG = 0; + } + } + } else if (context) { +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + if (!port +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030 + && CGContextGetClipBoundingBox != NULL +#endif + ) { + CGRect r = CGContextGetClipBoundingBox(context); - RectRgn(clipRgn, &boundsRect); - SectRegionWithPortClipRegion(destPort, clipRgn); - SectRegionWithPortVisibleRegion(destPort, clipRgn); - ClipCGContextToRegion(outContext, &boundsRect, clipRgn); - SetEmptyRgn(clipRgn); + SetRect(&portBounds, r.origin.x + macDraw->xOff, + r.origin.y + macDraw->yOff, + r.origin.x + r.size.width + macDraw->xOff, + r.origin.y + r.size.height + macDraw->yOff); + } +#endif + CGContextSaveGState(context); + TkMacOSXCheckTmpRgnEmpty(1); + RectRgn(tkMacOSXtmpRgn1, &portBounds); + if (port) { + TkMacOSXSetUpClippingRgn(d); + SectRegionWithPortClipRegion(port, tkMacOSXtmpRgn1); + SectRegionWithPortVisibleRegion(port, tkMacOSXtmpRgn1); + } else if (macDraw->flags & TK_CLIPPED_DRAW) { + OffsetRgn(macDraw->drawRgn, macDraw->xOff, macDraw->yOff); + SectRgn(macDraw->clipRgn, macDraw->drawRgn, tkMacOSXtmpRgn1); + OffsetRgn(macDraw->drawRgn, -macDraw->xOff, -macDraw->yOff); + } + if (gc && gc->clip_mask && ((TkpClipMask*)gc->clip_mask)->type + == TKP_CLIP_REGION) { + RgnHandle clipRgn = (RgnHandle) + ((TkpClipMask*)gc->clip_mask)->value.region; + int xOffset = macDraw->xOff + gc->clip_x_origin; + int yOffset = macDraw->yOff + gc->clip_y_origin; - /* - * Note: You have to call SyncCGContextOriginWithPort - * AFTER all the clip region manipulations. - */ + OffsetRgn(clipRgn, xOffset, yOffset); + SectRgn(clipRgn, tkMacOSXtmpRgn1, tkMacOSXtmpRgn1); + OffsetRgn(clipRgn, -xOffset, -yOffset); + } + ClipCGContextToRegion(context, &portBounds, tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn1); + port = NULL; + dc->portChanged = false; + dc->saveState = (void*)1; + useCG = 1; + } + if (useCG) { + CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, + 0.0, portBounds.bottom - portBounds.top)); + if (gc) { + double w = gc->line_width; + + TkMacOSXSetColorInContext(gc->foreground, context); + if (port) { + CGContextSetPatternPhase(context, CGSizeMake(portBounds.right - + portBounds.left, portBounds.bottom - portBounds.top)); + } + if(gc->function == GXxor) { + TkMacOSXDbgMsg("GXxor mode not supported for CG drawing!"); + } + /* When should we antialias? */ + if (notAA(gc->line_width)) { + /* Make non-antialiased CG drawing look more like X11 */ + w -= (gc->line_width ? NON_AA_CG_OFFSET : 0); + CGContextSetShouldAntialias(context, 0); + } else { + CGContextSetShouldAntialias(context, 1); + } + CGContextSetLineWidth(context, w); - SyncCGContextOriginWithPort(outContext, destPort); + if (gc->line_style != LineSolid) { + int num = 0; + char *p = &(gc->dashes); + double dashOffset = gc->dash_offset; + float lengths[10]; + + while (p[num] != '\0' && num < 10) { + lengths[num] = p[num]; + num++; + } + CGContextSetLineDash(context, dashOffset, lengths, num); + } - coordsTransform = CGAffineTransformMake(1, 0, 0, -1, 0, - boundsRect.bottom - boundsRect.top); - CGContextConcatCTM(outContext, coordsTransform); - - /* Now offset the CTM to the subwindow offset */ - - if (TkSetMacColor(gc->foreground, &macColor) == true) { - CGContextSetRGBFillColor(outContext, - RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), - 1); - CGContextSetRGBStrokeColor(outContext, - RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), - 1); - } - - if(gc->function == GXxor) { - } - - w = gc->line_width; - /* When should we antialias? */ - if (notAA(gc->line_width)) { - /* Make non-antialiased CG drawing look more like X11 */ - w -= (gc->line_width ? NON_AA_CG_OFFSET : 0); - CGContextSetShouldAntialias(outContext, 0); + if (gc->cap_style == CapButt) { + /* + * What about CapNotLast, CapProjecting? + */ + + CGContextSetLineCap(context, kCGLineCapButt); + } else if (gc->cap_style == CapRound) { + CGContextSetLineCap(context, kCGLineCapRound); + } else if (gc->cap_style == CapProjecting) { + CGContextSetLineCap(context, kCGLineCapSquare); + } + + if (gc->join_style == JoinMiter) { + CGContextSetLineJoin(context, kCGLineJoinMiter); + } else if (gc->join_style == JoinRound) { + CGContextSetLineJoin(context, kCGLineJoinRound); + } else if (gc->join_style == JoinBevel) { + CGContextSetLineJoin(context, kCGLineJoinBevel); + } + } } else { - CGContextSetShouldAntialias(outContext, 1); - } - CGContextSetLineWidth(outContext, w); - - if (gc->line_style != LineSolid) { - int num = 0; - char *p = &(gc->dashes); - float dashOffset = gc->dash_offset; - float lengths[10]; - - while (p[num] != '\0') { - lengths[num] = p[num]; - num++; + ChkErr(GetThemeDrawingState, &(dc->saveState)); + TkMacOSXSetUpGraphicsPort(gc, port); + if (gc) { + if (gc->clip_mask && ((TkpClipMask*)gc->clip_mask)->type + == TKP_CLIP_REGION) { + RgnHandle clipRgn = (RgnHandle) + ((TkpClipMask*)gc->clip_mask)->value.region; + int xOffset = macDraw->xOff + gc->clip_x_origin; + int yOffset = macDraw->yOff + gc->clip_y_origin; + + OffsetRgn(clipRgn, xOffset, yOffset); + GetClip(tkMacOSXtmpRgn1); + SectRgn(clipRgn, tkMacOSXtmpRgn1, tkMacOSXtmpRgn1); + SetClip(tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn1); + OffsetRgn(clipRgn, -xOffset, -yOffset); + } + PenPixPat(gPenPat); } - CGContextSetLineDash(outContext, dashOffset, lengths, num); - } - - if (gc->cap_style == CapButt) { - /* - * What about CapNotLast, CapProjecting? - */ - - CGContextSetLineCap(outContext, kCGLineCapButt); - } else if (gc->cap_style == CapRound) { - CGContextSetLineCap(outContext, kCGLineCapRound); - } else if (gc->cap_style == CapProjecting) { - CGContextSetLineCap(outContext, kCGLineCapSquare); - } - - if (gc->join_style == JoinMiter) { - CGContextSetLineJoin(outContext, kCGLineJoinMiter); - } else if (gc->join_style == JoinRound) { - CGContextSetLineJoin(outContext, kCGLineJoinRound); - } else if (gc->join_style == JoinBevel) { - CGContextSetLineJoin(outContext, kCGLineJoinBevel); + ShowPen(); } + dc->port = port; + dc->portBounds = portBounds; + dc->context = context; + return useCG; } /* *---------------------------------------------------------------------- * - * TkMacOSXReleaseCGContext -- + * TkMacOSXRestoreDrawingContext -- * - * Release the CGContext for the given graphics port. + * Restore drawing context. * * Results: * None. @@ -1902,14 +1798,27 @@ TkMacOSXSetUpCGContext( *---------------------------------------------------------------------- */ -static void -TkMacOSXReleaseCGContext( - MacDrawable *macWin, - CGrafPtr destPort, - CGContextRef *outContext) +void +TkMacOSXRestoreDrawingContext(TkMacOSXDrawingContext *dc) { - CGContextSynchronize(*outContext); - QDEndCGContext(destPort, outContext); + if (dc->context) { + CGContextSynchronize(dc->context); + if (dc->saveState) { + CGContextRestoreGState(dc->context); + } + if (dc->port) { + ChkErr(QDEndCGContext, dc->port, &(dc->context)); + } + } else { + HidePen(); + ChkErr(SetThemeDrawingState, dc->saveState, true); + } + if (dc->portChanged) { + QDSwapPort(dc->savePort, NULL); + } +#ifdef TK_MAC_DEBUG + bzero(dc, sizeof(dc)); +#endif /* TK_MAC_DEBUG */ } /* @@ -1940,7 +1849,7 @@ TkMacOSXSetUpClippingRgn( TkMacOSXUpdateClipRgn(macDraw->winPtr); } -#if defined(TK_MAC_DEBUG) && defined(TK_MAC_DEBUG_DRAWING) +#ifdef TK_MAC_DEBUG_DRAWING TkMacOSXInitNamedDebugSymbol(HIToolbox, int, QDDebugFlashRegion, CGrafPtr port, RgnHandle region); if (QDDebugFlashRegion) { @@ -1949,34 +1858,56 @@ TkMacOSXSetUpClippingRgn( QDDebugFlashRegion(grafPtr, macDraw->clipRgn); } #endif /* TK_MAC_DEBUG_DRAWING */ + } - /* - * When a menu is up, the Mac does not expect drawing to occur and - * does not clip out the menu. We have to do it ourselves. This - * is pretty gross. - */ + if (macDraw->clipRgn != NULL) { + if (macDraw->flags & TK_CLIPPED_DRAW) { + TkMacOSXCheckTmpRgnEmpty(1); + OffsetRgn(macDraw->drawRgn, macDraw->xOff, macDraw->yOff); + SectRgn(macDraw->clipRgn, macDraw->drawRgn, tkMacOSXtmpRgn1); + OffsetRgn(macDraw->drawRgn, -macDraw->xOff, -macDraw->yOff); + SetClip(tkMacOSXtmpRgn1); + SetEmptyRgn(tkMacOSXtmpRgn1); + } else { + SetClip(macDraw->clipRgn); + } + } else if (macDraw->flags & TK_CLIPPED_DRAW) { + OffsetRgn(macDraw->drawRgn, macDraw->xOff, macDraw->yOff); + SetClip(macDraw->drawRgn); + OffsetRgn(macDraw->drawRgn, -macDraw->xOff, -macDraw->yOff); + } +} + +/* + *---------------------------------------------------------------------- + * + * TkpClipDrawableToRect -- + * + * Clip all drawing into the drawable d to the given rectangle. + * If width and height are negative, reset to no clipping. + * + * Results: + * None. + * + * Side effects: + * Subsequent drawing into d is offset and clipped as specified. + * + *---------------------------------------------------------------------- + */ - if (macDraw->clipRgn != NULL) { - if (tkUseMenuCascadeRgn == 1) { - Point scratch = {0, 0}; - GDHandle saveDevice; - GWorldPtr saveWorld; - - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(TkMacOSXGetDrawablePort(drawable), NULL); - LocalToGlobal(&scratch); - SetGWorld(saveWorld, saveDevice); - if (tmpRgn == NULL) { - tmpRgn = NewRgn(); - } - CopyRgn(tkMenuCascadeRgn, tmpRgn); - OffsetRgn(tmpRgn, -scratch.h, -scratch.v); - DiffRgn(macDraw->clipRgn, tmpRgn, tmpRgn); - SetClip(tmpRgn); - macDraw->toplevel->flags |= TK_DRAWN_UNDER_MENU; - } else { - SetClip(macDraw->clipRgn); - } +void +TkpClipDrawableToRect(Display *display, Drawable d, int x, int y, int width, + int height) +{ + MacDrawable *macDraw = (MacDrawable *) d; + + if (macDraw->drawRgn) { + if (width < 0 && height < 0) { + SetEmptyRgn(macDraw->drawRgn); + macDraw->flags &= ~TK_CLIPPED_DRAW; + } else { + SetRectRgn(macDraw->drawRgn, x, y, x + width, y + height); + macDraw->flags |= TK_CLIPPED_DRAW; } } } @@ -2142,48 +2073,19 @@ TkpDrawFrame (Tk_Window tkwin, Tk_3DBord int highlightWidth, int borderWidth, int relief) { if (useThemedToplevel && Tk_IsTopLevel(tkwin)) { - /* - * Currently only support themed toplevels, until we can better - * factor this to handle individual windows (blanket theming of - * frames will work for very few UIs). - */ - Rect bounds; - Point origin; - CGrafPtr saveWorld; - GDHandle saveDevice; - XGCValues gcValues; - GC gc; - Pixmap pixmap; - Display *display = Tk_Display(tkwin); - - pixmap = Tk_GetPixmap(display, Tk_WindowId(tkwin), - Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin)); - - gc = Tk_GetGC(tkwin, 0, &gcValues); - TkMacOSXWinBounds((TkWindow *) tkwin, &bounds); - origin.v = -bounds.top; - origin.h = -bounds.left; - bounds.top = bounds.left = 0; - bounds.right = Tk_Width(tkwin); - bounds.bottom = Tk_Height(tkwin); - - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(TkMacOSXGetDrawablePort(pixmap), 0); - ApplyThemeBackground(kThemeBackgroundWindowHeader, &bounds, - kThemeStateActive, 32 /* depth */, true /* inColor */); - QDSetPatternOrigin(origin); - EraseRect(&bounds); - SetGWorld(saveWorld, saveDevice); - - XCopyArea(display, pixmap, Tk_WindowId(tkwin), - gc, 0, 0, bounds.right, bounds.bottom, 0, 0); - Tk_FreePixmap(display, pixmap); - Tk_FreeGC(display, gc); - } else { - Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), - border, highlightWidth, highlightWidth, - Tk_Width(tkwin) - 2 * highlightWidth, - Tk_Height(tkwin) - 2 * highlightWidth, - borderWidth, relief); + static Tk_3DBorder themedBorder = NULL; + + if (!themedBorder) { + themedBorder = Tk_Get3DBorder(NULL, tkwin, + "systemWindowHeaderBackground"); + } + if (themedBorder) { + border = themedBorder; + } } + Tk_Fill3DRectangle(tkwin, Tk_WindowId(tkwin), + border, highlightWidth, highlightWidth, + Tk_Width(tkwin) - 2 * highlightWidth, + Tk_Height(tkwin) - 2 * highlightWidth, + borderWidth, relief); } Index: macosx/tkMacOSXEmbed.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXEmbed.c,v retrieving revision 1.8 diff -u -p -r1.8 tkMacOSXEmbed.c --- macosx/tkMacOSXEmbed.c 31 Oct 2006 22:33:34 -0000 1.8 +++ macosx/tkMacOSXEmbed.c 15 Mar 2007 02:42:10 -0000 @@ -10,6 +10,7 @@ * * Copyright (c) 1996-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -56,21 +57,15 @@ TkMacOSXEmbedHandler *tkMacOSXEmbedHandl * Prototypes for static procedures defined in this file: */ -static void ContainerEventProc _ANSI_ARGS_(( - ClientData clientData, XEvent *eventPtr)); -static void EmbeddedEventProc _ANSI_ARGS_(( - ClientData clientData, XEvent *eventPtr)); -static void EmbedActivateProc _ANSI_ARGS_((ClientData clientData, - XEvent *eventPtr)); -static void EmbedFocusProc _ANSI_ARGS_((ClientData clientData, - XEvent *eventPtr)); -static void EmbedGeometryRequest _ANSI_ARGS_(( - Container * containerPtr, int width, int height)); -static void EmbedSendConfigure _ANSI_ARGS_(( - Container *containerPtr)); -static void EmbedStructureProc _ANSI_ARGS_((ClientData clientData, - XEvent *eventPtr)); -static void EmbedWindowDeleted _ANSI_ARGS_((TkWindow *winPtr)); +static void ContainerEventProc(ClientData clientData, XEvent *eventPtr); +static void EmbeddedEventProc(ClientData clientData, XEvent *eventPtr); +static void EmbedActivateProc(ClientData clientData, XEvent *eventPtr); +static void EmbedFocusProc(ClientData clientData, XEvent *eventPtr); +static void EmbedGeometryRequest(Container * containerPtr, int width, + int height); +static void EmbedSendConfigure(Container *containerPtr); +static void EmbedStructureProc(ClientData clientData, XEvent *eventPtr); +static void EmbedWindowDeleted(TkWindow *winPtr); /* @@ -156,21 +151,20 @@ TkpMakeWindow( winPtr->privatePtr = macWin; macWin->clipRgn = NewRgn(); macWin->aboveClipRgn = NewRgn(); + macWin->drawRgn = NewRgn(); macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; + macWin->grafPtr = NULL; + macWin->context = NULL; if (Tk_IsTopLevel(macWin->winPtr)) { - /* *This will be set when we are mapped. */ - - macWin->grafPtr = NULL; - macWin->toplevel = macWin; macWin->xOff = 0; macWin->yOff = 0; + macWin->toplevel = macWin; } else { - macWin->grafPtr = NULL; macWin->xOff = winPtr->parentPtr->privatePtr->xOff + winPtr->parentPtr->changes.border_width + winPtr->changes.x; @@ -179,7 +173,6 @@ TkpMakeWindow( winPtr->changes.y; macWin->toplevel = winPtr->parentPtr->privatePtr->toplevel; } - macWin->toplevel->referenceCount++; /* @@ -305,9 +298,11 @@ TkpUseWindow( */ macWin->grafPtr = NULL; + macWin->context = NULL; macWin->clipRgn = NewRgn(); macWin->aboveClipRgn = NewRgn(); + macWin->drawRgn = NewRgn(); macWin->referenceCount = 0; macWin->flags = TK_CLIP_INVALID; macWin->toplevel = macWin; @@ -758,6 +753,7 @@ TkpGetOtherWindow( } return NULL; } + /* *---------------------------------------------------------------------- * Index: macosx/tkMacOSXEntry.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXEntry.c,v retrieving revision 1.7 diff -u -p -r1.7 tkMacOSXEntry.c --- macosx/tkMacOSXEntry.c 10 Sep 2006 17:06:32 -0000 1.7 +++ macosx/tkMacOSXEntry.c 15 Mar 2007 02:42:11 -0000 @@ -1,10 +1,13 @@ /* * tkMacOSXEntry.c -- * - * This file implements functions that decode & handle keyboard events - * on MacOS X. + * This file implements the native aqua entry widget. * - * Copyright 2001, Apple Computer, Inc. + * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2006-2007 Daniel A. Steffen + * + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * * The following terms apply to all files originating from Apple * Computer, Inc. ("Apple") and associated with the software @@ -65,8 +68,8 @@ static ThemeButtonKind ComputeIncDecPara * ComputeIncDecParameters -- * * This procedure figures out which of the kThemeIncDec - * buttons to use. It also sets width to the width of the - * IncDec button. + * buttons to use. It also sets width to the width of the + * IncDec button. * * Results: * The ThemeButtonKind of the button we should use. @@ -79,45 +82,37 @@ static ThemeButtonKind ComputeIncDecPara static ThemeButtonKind ComputeIncDecParameters (int height, int *width) { - static int version = 0; - - if (version == 0) { - Gestalt(gestaltSystemVersion, (long *) &version); - } - - /* - * The small and mini incDec buttons were introduced in 10.3. - */ - #ifndef kThemeIncDecButtonSmall - #define kThemeIncDecButtonSmall 21 - #endif - #ifndef kThemeIncDecButtonMini - #define kThemeIncDecButtonMini 22 - #endif - - if (version >= 0x1030) { - if (height < 11 || height > 28) { - *width = 0; - return (ThemeButtonKind) 0; - } - - if (height >= 21) { - *width = 13; - return kThemeIncDecButton; - } else if (height >= 18) { - *width = 12; - return kThemeIncDecButtonSmall; - } else { - *width = 11; - return kThemeIncDecButtonMini; - } - } else { - if (height < 21 || height > 28) { - *width = 0; - return (ThemeButtonKind) 0; - } - *width = 13; - return kThemeIncDecButton; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + if (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030 + && &kHIToolboxVersionNumber != NULL + && kHIToolboxVersionNumber >= kHIToolboxVersionNumber10_3 +#endif + ) { + if (height < 11 || height > 28) { + *width = 0; + return (ThemeButtonKind) 0; + } + + if (height >= 21) { + *width = 13; + return kThemeIncDecButton; + } else if (height >= 18) { + *width = 12; + return kThemeIncDecButtonSmall; + } else { + *width = 11; + return kThemeIncDecButtonMini; + } + } else +#endif + { + if (height < 21 || height > 28) { + *width = 0; + return (ThemeButtonKind) 0; + } + *width = 13; + return kThemeIncDecButton; } } @@ -127,11 +122,11 @@ ComputeIncDecParameters (int height, int * TkpDrawEntryBorderAndFocus -- * * This procedure redraws the border of an entry window. - * It overrides the generic border drawing code if the - * entry widget parameters are such that the native widget - * drawing is a good fit. - * This version just returns 1, so platforms that don't - * do special native drawing don't have to implement it. + * It overrides the generic border drawing code if the + * entry widget parameters are such that the native widget + * drawing is a good fit. + * This version just returns 1, so platforms that don't + * do special native drawing don't have to implement it. * * Results: * 1 if it has drawn the border, 0 if not. @@ -145,44 +140,41 @@ int TkpDrawEntryBorderAndFocus(Entry *entryPtr, Drawable d, int isSpinbox) { Rect bounds; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; GC bgGC; Tk_Window tkwin = entryPtr->tkwin; ThemeDrawState drawState; int oldWidth = 0; + MacDrawable *macDraw = (MacDrawable *) d; - /* + /* * I use 6 as the borderwidth. 2 of the 5 go into the actual frame the * 3 are because the Mac OS Entry widgets leave more space around the * Text than Tk does on X11. */ - - if (entryPtr->borderWidth != MAC_OSX_ENTRY_BORDER - || entryPtr->highlightWidth != MAC_OSX_FOCUS_WIDTH - || entryPtr->relief != MAC_OSX_ENTRY_RELIEF) { - return 0; + + if (entryPtr->borderWidth != MAC_OSX_ENTRY_BORDER + || entryPtr->highlightWidth != MAC_OSX_FOCUS_WIDTH + || entryPtr->relief != MAC_OSX_ENTRY_RELIEF) { + return 0; } - - destPort = TkMacOSXGetDrawablePort(d); /* * For the spinbox, we have to make the entry part smaller by the size * of the buttons. We also leave 2 pixels to the left (as per the HIG) * and space for one pixel to the right, 'cause it makes the buttons look - * nicer. + * nicer. */ - + if (isSpinbox) { - ThemeButtonKind buttonKind; - int incDecWidth; - - oldWidth = Tk_Width(tkwin); - - buttonKind = ComputeIncDecParameters(Tk_Height(tkwin) - - 2 * MAC_OSX_FOCUS_WIDTH, &incDecWidth); - Tk_Width(tkwin) -= incDecWidth + 1; + ThemeButtonKind buttonKind; + int incDecWidth; + + oldWidth = Tk_Width(tkwin); + + buttonKind = ComputeIncDecParameters(Tk_Height(tkwin) + - 2 * MAC_OSX_FOCUS_WIDTH, &incDecWidth); + Tk_Width(tkwin) -= incDecWidth + 1; } /* @@ -190,42 +182,39 @@ TkpDrawEntryBorderAndFocus(Entry *entryP * part of the ring, so we have to draw over the edges of the * ring before drawing the focus or the text will peep through. */ - + bgGC = Tk_GCForColor(entryPtr->highlightBgColorPtr, d); TkDrawInsetFocusHighlight(entryPtr->tkwin, bgGC, MAC_OSX_FOCUS_WIDTH, d, 0); - - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - + /* - * Inset the entry Frame by the maximum width of the focus rect, + * Inset the entry Frame by the maximum width of the focus rect, * which is 3 according to the Carbon docs. */ - - bounds.top = MAC_OSX_FOCUS_WIDTH; - bounds.left = MAC_OSX_FOCUS_WIDTH; - bounds.right = Tk_Width(tkwin) - MAC_OSX_FOCUS_WIDTH; - bounds.bottom = Tk_Height(tkwin) - MAC_OSX_FOCUS_WIDTH; + + bounds.left = macDraw->xOff + MAC_OSX_FOCUS_WIDTH; + bounds.top = macDraw->yOff + MAC_OSX_FOCUS_WIDTH; + bounds.right = macDraw->xOff + Tk_Width(tkwin) - MAC_OSX_FOCUS_WIDTH; + bounds.bottom = macDraw->yOff + Tk_Height(tkwin) - MAC_OSX_FOCUS_WIDTH; if (entryPtr->state == STATE_DISABLED) { - drawState = kThemeStateInactive; + drawState = kThemeStateInactive; } else { - drawState = kThemeStateActive; + drawState = kThemeStateActive; } + TkMacOSXSetupDrawingContext(d, NULL, 0, &dc); DrawThemeEditTextFrame(&bounds, drawState); if (entryPtr->flags & GOT_FOCUS) { - /* - * Don't call this if we don't have the focus, because then it - * erases the focus rect to white, but we've already drawn the - * highlightbackground above. - */ + /* + * Don't call this if we don't have the focus, because then it + * erases the focus rect to white, but we've already drawn the + * highlightbackground above. + */ - DrawThemeFocusRect(&bounds, (entryPtr->flags & GOT_FOCUS) != 0); + DrawThemeFocusRect(&bounds, (entryPtr->flags & GOT_FOCUS) != 0); } - SetGWorld(saveWorld, saveDevice); - if (isSpinbox) { - Tk_Width(tkwin) = oldWidth; + Tk_Width(tkwin) = oldWidth; } + TkMacOSXRestoreDrawingContext(&dc); return 1; } /* @@ -234,11 +223,11 @@ TkpDrawEntryBorderAndFocus(Entry *entryP * TkpDrawSpinboxButtons -- * * This procedure redraws the buttons of an spinbox widget. - * It overrides the generic button drawing code if the - * spinbox widget parameters are such that the native widget - * drawing is a good fit. - * This version just returns 0, so platforms that don't - * do special native drawing don't have to implement it. + * It overrides the generic button drawing code if the + * spinbox widget parameters are such that the native widget + * drawing is a good fit. + * This version just returns 0, so platforms that don't + * do special native drawing don't have to implement it. * * Results: * 1 if it has drawn the border, 0 if not. @@ -252,7 +241,6 @@ TkpDrawEntryBorderAndFocus(Entry *entryP int TkpDrawSpinboxButtons(Spinbox *sbPtr, Drawable d) { - OSStatus err; Rect inBounds; ThemeButtonKind inKind; ThemeButtonDrawInfo inNewInfo; @@ -264,71 +252,65 @@ TkpDrawSpinboxButtons(Spinbox *sbPtr, Dr int height = Tk_Height(tkwin); int buttonHeight = height - 2 * MAC_OSX_FOCUS_WIDTH; int incDecWidth; - CGrafPtr saveWorld; - GDHandle saveDevice; - GWorldPtr destPort; + TkMacOSXDrawingContext dc; XRectangle rects[1]; GC bgGC; + MacDrawable *macDraw = (MacDrawable *) d; /* FIXME RAISED really makes more sense */ if (sbPtr->buRelief != TK_RELIEF_FLAT) { - return 0; + return 0; } - - /* + + /* * The actual sizes of the IncDec button are 21 for the normal, * 18 for the small and 15 for the mini. But the spinbox still * looks okay if the entry is a little bigger than this, so we * give it a little slop. */ - + inKind = ComputeIncDecParameters(buttonHeight, &incDecWidth); if (inKind == (ThemeButtonKind) 0) { - return 0; + return 0; } - - destPort = TkMacOSXGetDrawablePort(d); - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); if (sbPtr->entry.state == STATE_DISABLED) { - inNewInfo.state = kThemeStateInactive; - inNewInfo.value = kThemeButtonOff; + inNewInfo.state = kThemeStateInactive; + inNewInfo.value = kThemeButtonOff; } else if (sbPtr->selElement == SEL_BUTTONUP) { - inNewInfo.state = kThemeStatePressedUp; - inNewInfo.value = kThemeButtonOn; + inNewInfo.state = kThemeStatePressedUp; + inNewInfo.value = kThemeButtonOn; } else if (sbPtr->selElement == SEL_BUTTONDOWN) { - inNewInfo.state = kThemeStatePressedDown; - inNewInfo.value = kThemeButtonOn; + inNewInfo.state = kThemeStatePressedDown; + inNewInfo.value = kThemeButtonOn; } else { - inNewInfo.state = kThemeStateActive; - inNewInfo.value = kThemeButtonOff; + inNewInfo.state = kThemeStateActive; + inNewInfo.value = kThemeButtonOff; } - + inNewInfo.adornment = kThemeAdornmentNone; - inBounds.left = Tk_Width(tkwin) - incDecWidth - 1; - inBounds.right = Tk_Width(tkwin) - 1; - inBounds.top = MAC_OSX_FOCUS_WIDTH; - inBounds.bottom = Tk_Height(tkwin) - MAC_OSX_FOCUS_WIDTH; - + inBounds.left = macDraw->xOff + Tk_Width(tkwin) - incDecWidth - 1; + inBounds.right = macDraw->xOff + Tk_Width(tkwin) - 1; + inBounds.top = macDraw->yOff + MAC_OSX_FOCUS_WIDTH; + inBounds.bottom = macDraw->yOff + Tk_Height(tkwin) - MAC_OSX_FOCUS_WIDTH; + /* We had to make the entry part of the window smaller so that we * wouldn't overdraw the spin buttons with the focus highlight. SO * now we have to draw the highlightbackground. */ - + bgGC = Tk_GCForColor(sbPtr->entry.highlightBgColorPtr, d); rects[0].x = inBounds.left; rects[0].y = 0; rects[0].width = Tk_Width(tkwin); rects[0].height = Tk_Height(tkwin); XFillRectangles(Tk_Display(tkwin), d, bgGC, rects, 1); - - err = DrawThemeButton (&inBounds, inKind, &inNewInfo, inPrevInfo, - inEraseProc, inLabelProc, inUserData); - - SetGWorld(saveWorld, saveDevice); + TkMacOSXSetupDrawingContext(d, NULL, 0, &dc); + ChkErr(DrawThemeButton, &inBounds, inKind, &inNewInfo, inPrevInfo, + inEraseProc, inLabelProc, inUserData); + TkMacOSXRestoreDrawingContext(&dc); return 1; } Index: macosx/tkMacOSXEvent.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXEvent.c,v retrieving revision 1.12 diff -u -p -r1.12 tkMacOSXEvent.c --- macosx/tkMacOSXEvent.c 31 Oct 2006 22:33:34 -0000 1.12 +++ macosx/tkMacOSXEvent.c 15 Mar 2007 02:42:11 -0000 @@ -1,11 +1,11 @@ -/* +/* * tkMacOSXEvent.c -- * * This file contains the basic Mac OS X Event handling routines. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2006 Daniel A. Steffen + * Copyright (c) 2005-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -17,19 +17,20 @@ #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" + /* *---------------------------------------------------------------------- * * TkMacOSXFlushWindows -- * - * This routine flushes all the Carbon windows of the application. It - * is called by the setup procedure for the Tcl/Carbon event source. + * This routine flushes all the Carbon windows of the application. It + * is called by the setup procedure for the Tcl/Carbon event source. * * Results: - * None. + * None. * * Side effects: - * Flushes all Carbon windows + * Flushes all Carbon windows * *---------------------------------------------------------------------- */ @@ -38,72 +39,70 @@ MODULE_SCOPE void TkMacOSXFlushWindows () { WindowRef wRef = GetWindowList(); - + while (wRef) { - CGrafPtr portPtr = GetWindowPort(wRef); - if (QDIsPortBuffered(portPtr)) { - QDFlushPortBuffer(portPtr, NULL); - } - wRef = GetNextWindow(wRef); + CGrafPtr portPtr = GetWindowPort(wRef); + if (QDIsPortBuffered(portPtr)) { + QDFlushPortBuffer(portPtr, NULL); + } + wRef = GetNextWindow(wRef); } } -/* +/* *---------------------------------------------------------------------- - * + * * TkMacOSXProcessEvent -- - * - * This dispatches a filtered Carbon event to the appropriate handler * - * Note on MacEventStatus.stopProcessing: Please be conservative in the - * individual handlers and don't assume the event is fully handled - * unless you *really* need to ensure that other handlers don't see the - * event anymore. Some OS manager or library might be interested in - * events even after they are already handled on the Tk level. - * - * Results: - * 0 on success - * -1 on failure + * This dispatches a filtered Carbon event to the appropriate handler + * + * Note on MacEventStatus.stopProcessing: Please be conservative in the + * individual handlers and don't assume the event is fully handled + * unless you *really* need to ensure that other handlers don't see the + * event anymore. Some OS manager or library might be interested in + * events even after they are already handled on the Tk level. + * + * Results: + * 0 on success + * -1 on failure * * Side effects: - * Converts a Carbon event to a Tk event - * + * Converts a Carbon event to a Tk event + * *---------------------------------------------------------------------- */ -MODULE_SCOPE int +MODULE_SCOPE int TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr) { switch (eventPtr->eClass) { - case kEventClassMouse: - TkMacOSXProcessMouseEvent(eventPtr, statusPtr); - break; - case kEventClassWindow: - TkMacOSXProcessWindowEvent(eventPtr, statusPtr); - break; - case kEventClassKeyboard: - TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr); - break; - case kEventClassApplication: - TkMacOSXProcessApplicationEvent(eventPtr, statusPtr); - break; - case kEventClassMenu: - TkMacOSXProcessMenuEvent(eventPtr, statusPtr); - break; - case kEventClassCommand: - TkMacOSXProcessCommandEvent(eventPtr, statusPtr); - break; - default: -#ifdef TK_MAC_DEBUG - { - char buf [256]; - fprintf(stderr, - "Unrecognised event : %s\n", - TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf)); - } -#endif - break; - } + case kEventClassMouse: + TkMacOSXProcessMouseEvent(eventPtr, statusPtr); + break; + case kEventClassWindow: + TkMacOSXProcessWindowEvent(eventPtr, statusPtr); + break; + case kEventClassKeyboard: + TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr); + break; + case kEventClassApplication: + TkMacOSXProcessApplicationEvent(eventPtr, statusPtr); + break; + case kEventClassAppearance: + TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr); + break; + case kEventClassMenu: + TkMacOSXProcessMenuEvent(eventPtr, statusPtr); + break; + case kEventClassCommand: + TkMacOSXProcessCommandEvent(eventPtr, statusPtr); + break; + default: { + TkMacOSXDbgMsg("Unrecognised event: %s", + TkMacOSXCarbonEventToAscii(eventPtr->eventRef)); + break; + } + } return 0; } @@ -127,36 +126,61 @@ TkMacOSXProcessEvent(TkMacOSXEvent * eve MODULE_SCOPE int TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { - int menuContext; - OSStatus status; + int menuContext; + OSStatus err; switch (eventPtr->eKind) { case kEventMenuBeginTracking: case kEventMenuEndTracking: + case kEventMenuOpening: + case kEventMenuTargetItem: break; default: return 0; break; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamMenuContext, - typeUInt32, NULL, - sizeof(menuContext), NULL, - &menuContext); - if (status == noErr && (menuContext & kMenuContextMenuBar)) { - static int oldMode = TCL_SERVICE_ALL; - if (eventPtr->eKind == kEventMenuBeginTracking) { - oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); - TkMacOSXClearMenubarActive(); - - /* - * Handle -postcommand - */ - - TkMacOSXPreprocessMenu(); - } else { - Tcl_SetServiceMode(oldMode); - } + err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMenuContext, + typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); + if (err == noErr && ((menuContext & kMenuContextMenuBarTracking) || + (menuContext & kMenuContextPopUpTracking))) { + if (eventPtr->eKind == kEventMenuTargetItem) { + MenuRef menu; + MenuItemIndex index; + + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu), + NULL, &menu); + if (err == noErr) { + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamMenuItemIndex, typeMenuItemIndex, NULL, + sizeof(index), NULL, &index); + if (err == noErr) { + return TkMacOSXGenerateMenuSelectEvent(menu, index); + } + } + } else if (eventPtr->eKind == kEventMenuOpening) { + MenuRef menu; + + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu), + NULL, &menu); + if (err == noErr) { + TkMacOSXClearActiveMenu(menu); + } + } else { + if (eventPtr->eKind == kEventMenuBeginTracking) { + TkMacOSXClearMenubarActive(); + + /* + * Handle -postcommand + */ + + TkMacOSXPreprocessMenu(); + TkMacOSXTrackingLoop(1); + } else { + TkMacOSXTrackingLoop(0); + } + } } return 0; } @@ -181,9 +205,9 @@ TkMacOSXProcessMenuEvent(TkMacOSXEvent * MODULE_SCOPE int TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) { - HICommand command; - int menuContext; - OSStatus status; + HICommand command; + int menuContext; + OSStatus err; switch (eventPtr->eKind) { case kEventCommandProcess: @@ -193,19 +217,15 @@ TkMacOSXProcessCommandEvent(TkMacOSXEven return 0; break; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamDirectObject, - typeHICommand, NULL, - sizeof(command), NULL, - &command); - if (status == noErr && (command.attributes & kHICommandFromMenu)) { + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamDirectObject, typeHICommand, NULL, sizeof(command), + NULL, &command); + if (err == noErr && (command.attributes & kHICommandFromMenu)) { if (eventPtr->eKind == kEventCommandProcess) { - status = GetEventParameter(eventPtr->eventRef, - kEventParamMenuContext, - typeUInt32, NULL, - sizeof(menuContext), NULL, - &menuContext); - if (status == noErr && (menuContext & kMenuContextMenuBar) && + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamMenuContext, typeUInt32, NULL, + sizeof(menuContext), NULL, &menuContext); + if (err == noErr && (menuContext & kMenuContextMenuBar) && (menuContext & kMenuContextMenuBarTracking)) { TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), command.menu.menuItemIndex, @@ -215,15 +235,15 @@ TkMacOSXProcessCommandEvent(TkMacOSXEven } else { Tcl_CmdInfo dummy; if (command.commandID == kHICommandPreferences && eventPtr->interp) { - if (Tcl_GetCommandInfo(eventPtr->interp, + if (Tcl_GetCommandInfo(eventPtr->interp, "::tk::mac::ShowPreferences", &dummy)) { - if (!IsMenuItemEnabled(command.menu.menuRef, + if (!IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { EnableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); } } else { - if (IsMenuItemEnabled(command.menu.menuRef, + if (IsMenuItemEnabled(command.menu.menuRef, command.menu.menuItemIndex)) { DisableMenuItem(command.menu.menuRef, command.menu.menuItemIndex); @@ -236,56 +256,3 @@ TkMacOSXProcessCommandEvent(TkMacOSXEven } return 0; } - -/* - *---------------------------------------------------------------------- - * - * TkMacOSXReceiveAndProcessEvent -- - * - * This receives a carbon event and converts it to a Tk event - * - * Results: - * 0 on success - * Mac OS error number on failure - * - * Side effects: - * This receives the next Carbon event and converts it to the - * appropriate Tk event - * - *---------------------------------------------------------------------- - */ - -MODULE_SCOPE OSStatus -TkMacOSXReceiveAndProcessEvent() -{ - static EventTargetRef targetRef = NULL; - EventRef eventRef; - OSStatus err; - - /* - * This is a poll, since we have already counted the events coming - * into this routine, and are guaranteed to have one waiting. - */ - - err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef); - if (err == noErr) { - if (!targetRef) { - targetRef = GetEventDispatcherTarget(); - } - TkMacOSXStartTclEventLoopCarbonTimer(); - err = SendEventToEventTarget(eventRef,targetRef); - TkMacOSXStopTclEventLoopCarbonTimer(); -#ifdef TK_MAC_DEBUG - if (err != noErr && err != eventLoopTimedOutErr - && err != eventNotHandledErr - ) { - char buf [256]; - fprintf(stderr, - "RCNE SendEventToEventTarget (%s) failed, %d\n", - TkMacOSXCarbonEventToAscii(eventRef, buf), (int)err); - } -#endif - ReleaseEvent(eventRef); - } - return err; -} Index: macosx/tkMacOSXEvent.h =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXEvent.h,v retrieving revision 1.11 diff -u -p -r1.11 tkMacOSXEvent.h --- macosx/tkMacOSXEvent.h 20 Jul 2006 06:25:19 -0000 1.11 +++ macosx/tkMacOSXEvent.h 15 Mar 2007 02:42:11 -0000 @@ -74,10 +74,10 @@ typedef struct { UInt32 eClass; /* Defines the class of event : see CarbonEvents.h */ UInt32 eKind; /* Defines the kind of the event : see CarbonEvents.h */ Tcl_Interp *interp; /* Interp to handle events in */ + EventHandlerCallRef callRef; } TkMacOSXEvent; -MODULE_SCOPE OSStatus TkMacOSXReceiveAndProcessEvent(); -MODULE_SCOPE void TkMacOSXFlushWindows(); +MODULE_SCOPE void TkMacOSXFlushWindows(void); MODULE_SCOPE int TkMacOSXProcessEvent(TkMacOSXEvent *eventPtr, MacEventStatus *statusPtr); MODULE_SCOPE int TkMacOSXProcessMouseEvent(TkMacOSXEvent *e, @@ -88,6 +88,8 @@ MODULE_SCOPE int TkMacOSXProcessKeyboard MacEventStatus *statusPtr); MODULE_SCOPE int TkMacOSXProcessApplicationEvent(TkMacOSXEvent *e, MacEventStatus *statusPtr); +MODULE_SCOPE int TkMacOSXProcessAppearanceEvent(TkMacOSXEvent *e, + MacEventStatus *statusPtr); MODULE_SCOPE int TkMacOSXProcessMenuEvent(TkMacOSXEvent *e, MacEventStatus *statusPtr); MODULE_SCOPE int TkMacOSXProcessCommandEvent(TkMacOSXEvent *e, @@ -97,12 +99,5 @@ MODULE_SCOPE int TkMacOSXKeycodeToUnicod EventKind eKind, UInt32 keycode, UInt32 modifiers, UInt32 * deadKeyStatePtr); -MODULE_SCOPE OSStatus TkMacOSXStartTclEventLoopCarbonTimer(); -MODULE_SCOPE OSStatus TkMacOSXStopTclEventLoopCarbonTimer(); - -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 -/* Define constants only available on Mac OS X 10.3 or later */ -#define kEventAppAvailableWindowBoundsChanged 110 -#endif #endif Index: macosx/tkMacOSXFont.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXFont.c,v retrieving revision 1.21 diff -u -p -r1.21 tkMacOSXFont.c --- macosx/tkMacOSXFont.c 30 Dec 2006 23:15:22 -0000 1.21 +++ macosx/tkMacOSXFont.c 15 Mar 2007 02:42:12 -0000 @@ -1,10 +1,11 @@ /* * tkMacOSXFont.c -- * - * Contains the Macintosh implementation of the platform-independant - * font package interface. This version uses ATSU instead of Quickdraw. + * Contains the Macintosh implementation of the platform-independant + * font package interface. This version uses ATSU instead of Quickdraw. * * Copyright 2002-2004 Benjamin Riefenstahl, Benjamin.Riefenstahl@epost.de + * Copyright (c) 2006-2007 Daniel A. Steffen * * Some functions were originally copied verbatim from the QuickDraw version * of tkMacOSXFont.c, which had these copyright notices: @@ -42,17 +43,17 @@ #include "tkMacOSXFont.h" /* -#ifdef TK_MAC_DEBUG +#ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_FONTS #endif */ /* Define macros only available on Mac OS X 10.3 or later */ #ifndef FixedToInt -#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16)) +#define FixedToInt(a) ((short)(((Fixed)(a) + fixed1/2) >> 16)) #endif #ifndef IntToFixed -#define IntToFixed(a) ((Fixed)(a) << 16) +#define IntToFixed(a) ((Fixed)(a) << 16) #endif /* @@ -68,8 +69,36 @@ */ #define TK_MAC_COALESCE_LINE 0 -typedef TkMacOSXFont MacFont; -typedef TkMacOSXFontDrawingContext DrawingContext; +/* + * The following structure represents our Macintosh-specific implementation + * of a font object. + */ + +typedef struct { + TkFont font; /* Stuff used by generic font package. Must + * be first in structure. */ + + /* + * The ATSU view of the font and other text properties. Used for drawing + * and measuring. + */ + + ATSUFontID atsuFontId; /* == FMFont. */ + ATSUTextLayout atsuLayout; /* ATSU layout object, representing the whole + * text that ATSU sees with some option + * bits. */ + ATSUStyle atsuStyle; /* ATSU style object, representing a run of + * text with the same properties. */ + + /* + * The QuickDraw view of the font. Used to configure controls. + */ + + FMFontFamily qdFont; /* == FMFontFamilyId, Carbon replacement for + * QD face numbers. */ + short qdSize; /* Font size in points. */ + short qdStyle; /* QuickDraw style bits. */ +} MacFont; /* * Information about font families, initialized at startup time. Font @@ -89,9 +118,9 @@ typedef struct { static MacFontFamily * familyList = NULL; static int - familyListNextFree = 0, /* The next free slot in familyList. */ - familyListMaxValid = 0, /* The top of the sorted area. */ - familyListSize = 0; /* The size of the whole array. */ + familyListNextFree = 0, /* The next free slot in familyList. */ + familyListMaxValid = 0, /* The top of the sorted area. */ + familyListSize = 0; /* The size of the whole array. */ /* * A simple one-shot sub-allocator for fast and efficient allocation of @@ -101,14 +130,14 @@ static int * and start over. */ -#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) == - * 1024. */ +#define STRING_BLOCK_MAX (1024-8) /* Make sizeof(StringBlock) == + * 1024. */ typedef struct StringBlock { - struct StringBlock * next; /* Starting from "stringMemory" these - * blocks form a linked list. */ - int nextFree; /* Top of the used area in the - * "strings" member. */ - char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */ + struct StringBlock * next; /* Starting from "stringMemory" these + * blocks form a linked list. */ + int nextFree; /* Top of the used area in the + * "strings" member. */ + char strings[STRING_BLOCK_MAX]; /* The actual memory managed here. */ } StringBlock; static StringBlock * stringMemory = NULL; @@ -116,40 +145,40 @@ static StringBlock * stringMemory = NULL #if TK_MAC_COALESCE_LINE static Tcl_DString currentLine; /* The current line as seen so far. This - * contains a Tcl_UniChar DString. */ + * contains a Tcl_UniChar DString. */ static int - currentY = -1, /* The Y position (row in pixels) of the - * current line. */ - currentLeft = -1, /* The left edge (pixels) of the current - * line. */ - currentRight = -1; /* The right edge (pixels) of the current - * line. */ + currentY = -1, /* The Y position (row in pixels) of the + * current line. */ + currentLeft = -1, /* The left edge (pixels) of the current + * line. */ + currentRight = -1; /* The right edge (pixels) of the current + * line. */ static const MacFont * currentFontPtr = NULL; - /* The font of the current line. */ + /* The font of the current line. */ #endif /* TK_MAC_COALESCE_LINE */ static int antialiasedTextEnabled; /* - * The names for our two "native" fonts. + * The names for our "native" fonts. */ -#define SYSTEMFONT_NAME "system" -#define APPLFONT_NAME "application" +#define SYSTEMFONT_NAME "system" +#define APPLFONT_NAME "application" +#define MENUITEMFONT_NAME "menu" /* * Procedures used only in this file. */ +static void LayoutSetString(const MacFont *fontPtr, + const TkMacOSXDrawingContext *drawingContextPtr, + const UniChar * uchars, int ulen); + /* * The actual workers. */ -static void MacFontDrawText( - const MacFont * fontPtr, - const char * source, int numBytes, - int rangeStart, int rangeLength, - int x, int y); static int MeasureStringWidth( const MacFont * fontPtr, int start, int end); @@ -157,7 +186,7 @@ static int MeasureStringWidth( #if TK_MAC_COALESCE_LINE static const Tcl_UniChar * UpdateLineBuffer( const MacFont * fontPtr, - const DrawingContext * drawingContextPtr, + const TkMacOSXDrawingContext *drawingContextPtr, const char * source, int numBytes, int x, int y, int * offset); @@ -185,7 +214,7 @@ static void SetFontFeatures( static void AdjustFontHeight( MacFont * fontPtr); static void InitATSULayout( - const DrawingContext * drawingContextPtr, + const TkMacOSXDrawingContext *drawingContextPtr, ATSUTextLayout layout, int fixed); static void ReleaseFont( MacFont * fontPtr); @@ -211,6 +240,9 @@ static OSStatus GetFontFamilyName( * Accessor functions and internal utilities for the font family list. */ +static OSStatus GetThemeFontAndFamily(const ThemeFontID themeFontId, + FMFontFamily* fontFamily, Str255 fontName, SInt16 *fontSize, + Style *fontStyle); static const MacFontFamily * AddFontFamily( const char * name, FMFontFamily familyId); static const MacFontFamily * FindFontFamily(const char * name); @@ -227,15 +259,15 @@ static const char * AddString(const char * * TkpFontPkgInit -- * - * This procedure is called when an application is created. It - * initializes all the structures that are used by the - * platform-dependant code on a per application basis. + * This procedure is called when an application is created. It + * initializes all the structures that are used by the + * platform-dependant code on a per application basis. * * Results: - * None. + * None. * * Side effects: - * Initialization of variables local to this file. + * Initialization of variables local to this file. * *------------------------------------------------------------------------- */ @@ -249,11 +281,31 @@ TkpFontPkgInit( #if TK_MAC_COALESCE_LINE Tcl_DStringInit(¤tLine); #endif +} + +/* + *--------------------------------------------------------------------------- + * + * GetThemeFontAndFamily -- + * + * Wrapper around the GetThemeFont and FMGetFontFamilyFromName APIs. + * + *--------------------------------------------------------------------------- + */ -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "tkMacOSXFont.c (ATSU version) intialized " - "(" __TIME__ ")\n"); -#endif +OSStatus +GetThemeFontAndFamily(const ThemeFontID themeFontId, FMFontFamily* fontFamily, + Str255 fontName, SInt16 *fontSize, Style *fontStyle) { + OSStatus err = ChkErr(GetThemeFont, themeFontId, smSystemScript, fontName, + fontSize, fontStyle); + if (err == noErr) { + *fontFamily = FMGetFontFamilyFromName(fontName); + if (*fontFamily == kInvalidFontFamily) { + err = kFMInvalidFontFamilyErr; + TkMacOSXDbgMsg("FMGetFontFamilyFromName failed."); + } + } + return err; } /* @@ -261,45 +313,56 @@ TkpFontPkgInit( * * TkpGetNativeFont -- * - * Map a platform-specific native font name to a TkFont. + * Map a platform-specific native font name to a TkFont. * * Results: - * The return value is a pointer to a TkFont that represents the - * native font. If a native font by the given name could not be - * found, the return value is NULL. + * The return value is a pointer to a TkFont that represents the + * native font. If a native font by the given name could not be + * found, the return value is NULL. * - * Every call to this procedure returns a new TkFont structure, even - * if the name has already been seen before. The caller should call - * TkpDeleteFont() when the font is no longer needed. + * Every call to this procedure returns a new TkFont structure, even + * if the name has already been seen before. The caller should call + * TkpDeleteFont() when the font is no longer needed. * - * The caller is responsible for initializing the memory associated - * with the generic TkFont when this function returns and releasing - * the contents of the generics TkFont before calling TkpDeleteFont(). + * The caller is responsible for initializing the memory associated + * with the generic TkFont when this function returns and releasing + * the contents of the generics TkFont before calling TkpDeleteFont(). * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ TkFont * TkpGetNativeFont( - Tk_Window tkwin, /* For display where font will be used. */ - const char * name) /* Platform-specific font name. */ + Tk_Window tkwin, /* For display where font will be used. */ + const char * name) /* Platform-specific font name. */ { - FMFontFamily familyId; + ThemeFontID themeFontId; + FMFontFamily fontFamily; + Str255 fontName; + SInt16 fontSize; + Style fontStyle; MacFont * fontPtr; if (strcmp(name, SYSTEMFONT_NAME) == 0) { - familyId = GetSysFont(); + themeFontId = kThemeSystemFont; } else if (strcmp(name, APPLFONT_NAME) == 0) { - familyId = GetAppFont(); + themeFontId = kThemeApplicationFont; + } else if (strcmp(name, MENUITEMFONT_NAME) == 0) { + themeFontId = kThemeMenuItemFont; } else { - return NULL; + return NULL; + } + if (GetThemeFontAndFamily(themeFontId, &fontFamily, fontName, &fontSize, + &fontStyle) != noErr) { + return NULL; } + CopyPascalStringToC(fontName, (char*)fontName); fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); - InitFont(tkwin, familyId, NULL, 0, 0, fontPtr); + InitFont(tkwin, fontFamily, (char*)fontName, fontSize, fontStyle, fontPtr); return (TkFont *) fontPtr; } @@ -309,41 +372,41 @@ TkpGetNativeFont( * * TkpGetFontFromAttributes -- * - * Given a desired set of attributes for a font, find a font with the - * closest matching attributes. + * Given a desired set of attributes for a font, find a font with the + * closest matching attributes. * * Results: - * The return value is a pointer to a TkFont that represents the font - * with the desired attributes. If a font with the desired attributes - * could not be constructed, some other font will be substituted - * automatically. + * The return value is a pointer to a TkFont that represents the font + * with the desired attributes. If a font with the desired attributes + * could not be constructed, some other font will be substituted + * automatically. * - * Every call to this procedure returns a new TkFont structure, even - * if the specified attributes have already been seen before. The - * caller should call TkpDeleteFont() to free the platform- specific - * data when the font is no longer needed. + * Every call to this procedure returns a new TkFont structure, even + * if the specified attributes have already been seen before. The + * caller should call TkpDeleteFont() to free the platform- specific + * data when the font is no longer needed. * - * The caller is responsible for initializing the memory associated - * with the generic TkFont when this function returns and releasing - * the contents of the generic TkFont before calling TkpDeleteFont(). + * The caller is responsible for initializing the memory associated + * with the generic TkFont when this function returns and releasing + * the contents of the generic TkFont before calling TkpDeleteFont(). * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ TkFont * TkpGetFontFromAttributes( - TkFont * tkFontPtr, /* If non-NULL, store the information in this - * existing TkFont structure, rather than - * allocating a new structure to hold the font; - * the existing contents of the font will be - * released. If NULL, a new TkFont structure is - * allocated. */ - Tk_Window tkwin, /* For display where font will be used. */ + TkFont * tkFontPtr, /* If non-NULL, store the information in this + * existing TkFont structure, rather than + * allocating a new structure to hold the font; + * the existing contents of the font will be + * released. If NULL, a new TkFont structure is + * allocated. */ + Tk_Window tkwin, /* For display where font will be used. */ const TkFontAttributes * faPtr) - /* Set of attributes to match. */ + /* Set of attributes to match. */ { short qdStyle; FMFontFamily familyId; @@ -356,27 +419,27 @@ TkpGetFontFromAttributes( qdStyle = 0; if (faPtr->family != NULL) { - familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family); - if (familyPtr != NULL) { - name = familyPtr->name; - familyId = familyPtr->familyId; - } + familyPtr = FindFontFamilyOrAliasOrFallback(faPtr->family); + if (familyPtr != NULL) { + name = familyPtr->name; + familyId = familyPtr->familyId; + } } if (faPtr->weight != TK_FW_NORMAL) { - qdStyle |= bold; + qdStyle |= bold; } if (faPtr->slant != TK_FS_ROMAN) { - qdStyle |= italic; + qdStyle |= italic; } if (faPtr->underline) { - qdStyle |= underline; + qdStyle |= underline; } if (tkFontPtr == NULL) { - fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); + fontPtr = (MacFont *) ckalloc(sizeof(MacFont)); } else { - fontPtr = (MacFont *) tkFontPtr; - ReleaseFont(fontPtr); + fontPtr = (MacFont *) tkFontPtr; + ReleaseFont(fontPtr); } InitFont(tkwin, familyId, name, faPtr->size, qdStyle, fontPtr); @@ -388,23 +451,23 @@ TkpGetFontFromAttributes( * * TkpDeleteFont -- * - * Called to release a font allocated by TkpGetNativeFont() or - * TkpGetFontFromAttributes(). The caller should have already - * released the fields of the TkFont that are used exclusively by the - * generic TkFont code. + * Called to release a font allocated by TkpGetNativeFont() or + * TkpGetFontFromAttributes(). The caller should have already + * released the fields of the TkFont that are used exclusively by the + * generic TkFont code. * * Results: - * TkFont is deallocated. + * TkFont is deallocated. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ void TkpDeleteFont( - TkFont * tkFontPtr) /* Token of font to be deleted. */ + TkFont * tkFontPtr) /* Token of font to be deleted. */ { ReleaseFont((MacFont *) tkFontPtr); } @@ -414,23 +477,23 @@ TkpDeleteFont( * * TkpGetFontFamilies -- * - * Return information about the font families that are available on - * the display of the given window. + * Return information about the font families that are available on + * the display of the given window. * * Results: - * Modifies interp's result object to hold a list of all the available - * font families. + * Modifies interp's result object to hold a list of all the available + * font families. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ void TkpGetFontFamilies( - Tcl_Interp * interp, /* Interp to hold result. */ - Tk_Window tkwin) /* For display to query. */ + Tcl_Interp * interp, /* Interp to hold result. */ + Tk_Window tkwin) /* For display to query. */ { Tcl_SetObjResult(interp,EnumFontFamilies()); } @@ -440,23 +503,23 @@ TkpGetFontFamilies( * * TkpGetSubFonts -- * - * A function used by the testing package for querying the actual - * screen fonts that make up a font object. + * A function used by the testing package for querying the actual + * screen fonts that make up a font object. * * Results: - * Modifies interp's result object to hold a list containing the names - * of the screen fonts that make up the given font object. + * Modifies interp's result object to hold a list containing the names + * of the screen fonts that make up the given font object. * * Side effects: - * None. + * None. * *------------------------------------------------------------------------- */ void TkpGetSubFonts( - Tcl_Interp * interp, /* Interp to hold result. */ - Tk_Font tkfont) /* Font object to query. */ + Tcl_Interp * interp, /* Interp to hold result. */ + Tk_Font tkfont) /* Font object to query. */ { /* We don't know much about our fallback fonts, ATSU does all that for * us. We could use ATSUMatchFont to implement this function. But as @@ -469,28 +532,28 @@ TkpGetSubFonts( * * TkpGetFontAttrsForChar -- * - * Retrieve the font attributes of the actual font used to render a - * given character. + * Retrieve the font attributes of the actual font used to render a + * given character. * * Results: - * None. + * None. * * Side effects: - * The font attributes are stored in *faPtr. + * The font attributes are stored in *faPtr. * *---------------------------------------------------------------------- */ void TkpGetFontAttrsForChar( - Tk_Window tkwin, /* Window on the font's display */ - Tk_Font tkfont, /* Font to query */ - Tcl_UniChar c, /* Character of interest */ - TkFontAttributes* faPtr) /* Output: Font attributes */ + Tk_Window tkwin, /* Window on the font's display */ + Tk_Font tkfont, /* Font to query */ + Tcl_UniChar c, /* Character of interest */ + TkFontAttributes* faPtr) /* Output: Font attributes */ { - TkMacOSXFont* fontPtr = (TkMacOSXFont*) tkfont; + const MacFont * fontPtr = (const MacFont *) tkfont; UniChar uchar = c; - DrawingContext drawingContext; + TkMacOSXDrawingContext drawingContext; OSStatus err; ATSUFontID fontId; UniCharArrayOffset changedOffset; @@ -507,70 +570,51 @@ TkpGetFontAttrsForChar( * But the name of the actual font may still differ, so we activate the * string as an ATSU layout and ask ATSU about the fallback. */ + TkMacOSXSetupDrawingContext(Tk_WindowId(tkwin), NULL, 1, &drawingContext); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - - TkMacOSXLayoutSetString(fontPtr, &drawingContext, &uchar, 1); + LayoutSetString(fontPtr, &drawingContext, &uchar, 1); fontId = fontPtr->atsuFontId; err = ATSUMatchFontsToText( - fontPtr->atsuLayout, 0, 1, - &fontId, &changedOffset, &changedLength); -#ifdef TK_MAC_DEBUG_FONTS + fontPtr->atsuLayout, 0, 1, + &fontId, &changedOffset, &changedLength); if (err != kATSUFontsMatched && err != noErr) { - fprintf(stderr, "TkpGetFontAttrsForChar: " - "Can't match \\u%04X\n", - (unsigned) c); + TkMacOSXDbgMsg("Can't match \\u%04X", (unsigned) c); } -#endif if (err == kATSUFontsMatched) { - /* - * A fallback was used and the actual font is in fontId. Determine - * the name. - */ - - FMFontFamily fontFamilyId; - FMFontStyle fontStyle; - int i; - - err = FMGetFontFamilyInstanceFromFont( - fontId, &fontFamilyId, &fontStyle); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFamilyInstanceFromFont: Error %d\n", - (int) err); - } -#endif - - if (err == noErr) { - - /* - * Find the canonical name in our global list. - */ - - for (i=0; ifamily = familyList[i].name; - break; - } - } -#ifdef TK_MAC_DEBUG_FONTS - if (i >= familyListMaxValid) { - fprintf(stderr, "TkpGetFontAttrsForChar: " - "Can't find font %d for \\u%04X\n", - (int) fontFamilyId, (unsigned) c); - } -#endif - } + /* + * A fallback was used and the actual font is in fontId. Determine + * the name. + */ + + FMFontFamily fontFamilyId; + FMFontStyle fontStyle; + int i; + + err = ChkErr(FMGetFontFamilyInstanceFromFont, fontId, &fontFamilyId, + &fontStyle); + if (err == noErr) { + + /* + * Find the canonical name in our global list. + */ + + for (i=0; ifamily = familyList[i].name; + break; + } + } + if (i >= familyListMaxValid) { + TkMacOSXDbgMsg("Can't find font %d for \\u%04X", fontFamilyId, + (unsigned) c); + } + } } -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif + TkMacOSXRestoreDrawingContext(&drawingContext); } /* @@ -578,55 +622,55 @@ TkpGetFontAttrsForChar( * * Tk_MeasureChars -- * - * Determine the number of characters from the string that will fit in - * the given horizontal span. The measurement is done under the - * assumption that Tk_DrawChars() will be used to actually display the - * characters. + * Determine the number of characters from the string that will fit in + * the given horizontal span. The measurement is done under the + * assumption that Tk_DrawChars() will be used to actually display the + * characters. * - * With ATSUI we need the line context to do this right, so we have the - * actual implementation in TkpMeasureCharsInContext(). + * With ATSUI we need the line context to do this right, so we have the + * actual implementation in TkpMeasureCharsInContext(). * * Results: * - * The return value is the number of bytes from source that fit into the - * span that extends from 0 to maxLength. *lengthPtr is filled with the - * x-coordinate of the right edge of the last character that did fit. + * The return value is the number of bytes from source that fit into the + * span that extends from 0 to maxLength. *lengthPtr is filled with the + * x-coordinate of the right edge of the last character that did fit. * * Side effects: * - * None. + * None. * * Todo: * - * Effects of the "flags" parameter are untested. + * Effects of the "flags" parameter are untested. * *--------------------------------------------------------------------------- */ int Tk_MeasureChars( - Tk_Font tkfont, /* Font in which characters will be drawn. */ - const char * source, /* UTF-8 string to be displayed. Need not be - * '\0' terminated. */ - int numBytes, /* Maximum number of bytes to consider from - * source string. */ - int maxLength, /* If >= 0, maxLength specifies the longest - * permissible line length; don't consider any - * character that would cross this x-position. - * If < 0, then line length is unbounded and the - * flags argument is ignored. */ - int flags, /* Various flag bits OR-ed together: - * TK_PARTIAL_OK means include the last char - * which only partially fit on this line. - * TK_WHOLE_WORDS means stop on a word boundary, - * if possible. TK_AT_LEAST_ONE means return at - * least one character even if no characters - * fit. */ - int * lengthPtr) /* Filled with x-location just after the - * terminating character. */ + Tk_Font tkfont, /* Font in which characters will be drawn. */ + const char * source, /* UTF-8 string to be displayed. Need not be + * '\0' terminated. */ + int numBytes, /* Maximum number of bytes to consider from + * source string. */ + int maxLength, /* If >= 0, maxLength specifies the longest + * permissible line length; don't consider any + * character that would cross this x-position. + * If < 0, then line length is unbounded and the + * flags argument is ignored. */ + int flags, /* Various flag bits OR-ed together: + * TK_PARTIAL_OK means include the last char + * which only partially fit on this line. + * TK_WHOLE_WORDS means stop on a word boundary, + * if possible. TK_AT_LEAST_ONE means return at + * least one character even if no characters + * fit. */ + int * lengthPtr) /* Filled with x-location just after the + * terminating character. */ { return TkpMeasureCharsInContext( - tkfont, source, numBytes, 0, numBytes, maxLength, flags, lengthPtr); + tkfont, source, numBytes, 0, numBytes, maxLength, flags, lengthPtr); } /* @@ -634,55 +678,55 @@ Tk_MeasureChars( * * TkpMeasureCharsInContext -- * - * Determine the number of bytes from the string that will fit in the - * given horizontal span. The measurement is done under the assumption - * that TkpDrawCharsInContext() will be used to actually display the - * characters. + * Determine the number of bytes from the string that will fit in the + * given horizontal span. The measurement is done under the assumption + * that TkpDrawCharsInContext() will be used to actually display the + * characters. * - * This one is almost the same as Tk_MeasureChars(), but with access to - * all the characters on the line for context. + * This one is almost the same as Tk_MeasureChars(), but with access to + * all the characters on the line for context. * * Results: - * The return value is the number of bytes from source that - * fit into the span that extends from 0 to maxLength. *lengthPtr is - * filled with the x-coordinate of the right edge of the last - * character that did fit. + * The return value is the number of bytes from source that + * fit into the span that extends from 0 to maxLength. *lengthPtr is + * filled with the x-coordinate of the right edge of the last + * character that did fit. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ int TkpMeasureCharsInContext( - Tk_Font tkfont, /* Font in which characters will be drawn. */ - const char * source, /* UTF-8 string to be displayed. Need not be - * '\0' terminated. */ - int numBytes, /* Maximum number of bytes to consider from - * source string in all. */ - int rangeStart, /* Index of first byte to measure. */ - int rangeLength, /* Length of range to measure in bytes. */ - int maxLength, /* If >= 0, maxLength specifies the longest - * permissible line length; don't consider any - * character that would cross this x-position. - * If < 0, then line length is unbounded and the - * flags argument is ignored. */ - int flags, /* Various flag bits OR-ed together: - * TK_PARTIAL_OK means include the last char - * which only partially fits on this line. - * TK_WHOLE_WORDS means stop on a word boundary, - * if possible. - * TK_AT_LEAST_ONE means return at least one - * character (or at least the first partial word - * in case TK_WHOLE_WORDS is also set) even if no - * characters (words) fit. - * TK_ISOLATE_END means that the last character - * should not be considered in context with the - * rest of the string (used for breaking - * lines). */ - int * lengthPtr) /* Filled with x-location just after the - * terminating character. */ + Tk_Font tkfont, /* Font in which characters will be drawn. */ + const char * source, /* UTF-8 string to be displayed. Need not be + * '\0' terminated. */ + int numBytes, /* Maximum number of bytes to consider from + * source string in all. */ + int rangeStart, /* Index of first byte to measure. */ + int rangeLength, /* Length of range to measure in bytes. */ + int maxLength, /* If >= 0, maxLength specifies the longest + * permissible line length; don't consider any + * character that would cross this x-position. + * If < 0, then line length is unbounded and the + * flags argument is ignored. */ + int flags, /* Various flag bits OR-ed together: + * TK_PARTIAL_OK means include the last char + * which only partially fits on this line. + * TK_WHOLE_WORDS means stop on a word boundary, + * if possible. + * TK_AT_LEAST_ONE means return at least one + * character (or at least the first partial word + * in case TK_WHOLE_WORDS is also set) even if no + * characters (words) fit. + * TK_ISOLATE_END means that the last character + * should not be considered in context with the + * rest of the string (used for breaking + * lines). */ + int * lengthPtr) /* Filled with x-location just after the + * terminating character. */ { const MacFont * fontPtr = (const MacFont *) tkfont; int curX = -1; @@ -690,19 +734,15 @@ TkpMeasureCharsInContext( UniChar * uchars; int ulen, urstart, urlen, urend; Tcl_DString ucharBuffer; - DrawingContext drawingContext; - /* * Sanity checks. */ - if ((rangeStart < 0) || ((rangeStart+rangeLength) > numBytes)) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "MeasureChars: bad parameters\n"); -#endif - *lengthPtr = 0; - return 0; + if (rangeStart < 0 || (rangeStart+rangeLength) > numBytes) { + TkMacOSXDbgMsg("Bad parameters"); + *lengthPtr = 0; + return 0; } /* @@ -710,24 +750,14 @@ TkpMeasureCharsInContext( */ if (rangeLength == 0 || (maxLength == 0 && !(flags & TK_AT_LEAST_ONE))) { -#ifdef TK_MAC_DEBUG_FONTS - fflush(stdout); - fprintf(stderr, "measure: '%.*s', empty\n", - rangeLength, source+rangeStart); - fflush(stderr); -#endif - *lengthPtr = 0; - return 0; + *lengthPtr = 0; + return 0; } -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - Tcl_DStringInit(&ucharBuffer); uchars = Tcl_UtfToUniCharDString(source, numBytes, &ucharBuffer); ulen = Tcl_DStringLength(&ucharBuffer) / sizeof(Tcl_UniChar); - TkMacOSXLayoutSetString(fontPtr, &drawingContext, uchars, ulen); + LayoutSetString(fontPtr, NULL, uchars, ulen); urstart = Tcl_NumUtfChars(source, rangeStart); urlen = Tcl_NumUtfChars(source+rangeStart,rangeLength); @@ -735,259 +765,243 @@ TkpMeasureCharsInContext( if (maxLength < 0) { - curX = MeasureStringWidth(fontPtr, urstart, urend); - curByte = rangeLength; + curX = MeasureStringWidth(fontPtr, urstart, urend); + curByte = rangeLength; } else { - UniCharArrayOffset offset = 0; - OSStatus err; - - /* - * Have some upper limit on the size actually used. - */ - - if (maxLength > 32767) { - maxLength = 32767; - } - - offset = urstart; - err = noErr; - - if (maxLength > 1) { - - /* - * Let the system do some work by calculating a line break. - * - * Somehow ATSUBreakLine seems to assume that it needs at least - * one pixel padding. So we add one to the limit. Note also - * that ATSUBreakLine sometimes runs into an endless loop when - * the third parameter is equal or less than IntToFixed(2), so we - * need at least IntToFixed(3) (at least that's the current state - * of my knowledge). - */ - - err = ATSUBreakLine( - fontPtr->atsuLayout, - urstart, - IntToFixed(maxLength+1), - false, /* !iUseAsSoftLineBreak */ - &offset); - - /* - * There is no way to signal an error from this routine, so we - * use predefined offset=urstart and otherwise ignore the - * possibility. - */ - -#ifdef TK_MAC_DEBUG_FONTS - if ((err != noErr) && (err != kATSULineBreakInWord)) { - fprintf(stderr, "ATSUBreakLine(): Error %d for '%.*s'\n", - (int) err, rangeLength, source+rangeStart); - } -#endif - -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "measure: '%.*s', break offset=%d, errcode=%d\n", - rangeLength, source+rangeStart, (int) offset, (int) err); -#endif - - /* - * ATSUBreakLine includes the whitespace that separates words, - * but we don't want that. Besides, ATSUBreakLine thinks that - * spaces don't occupy pixels at the end of the break, which is - * also something we like to decide for ourself. - */ - - while ((offset > (UniCharArrayOffset)urstart) && (uchars[offset-1] == ' ')) { - offset--; - } - - /* - * Fix up left-overs for the TK_WHOLE_WORDS case. - */ - - if (flags & TK_WHOLE_WORDS) { - if(flags & TK_AT_LEAST_ONE) { - - /* - * If we are the the start of the range, we need to look - * forward. If we are not at the end of a word, we must - * be in the middle of the first word, so we also look - * forward. - */ - - if ((offset == (UniCharArrayOffset)urstart) || (uchars[offset] != ' ')) { - while ((offset < (UniCharArrayOffset)urend) - && (uchars[offset] != ' ')) { - offset++; - } - } - } else { - - /* - * If we are not at the end of a word, we need to look - * backward. - */ - - if ((offset != (UniCharArrayOffset)urend) && (uchars[offset] != ' ')) { - while ((offset > (UniCharArrayOffset)urstart) - && (uchars[offset-1] != ' ')) { - offset--; - } - while ((offset > (UniCharArrayOffset)urstart) - && (uchars[offset-1] == ' ')) { - offset--; - } - } - } - } - } - - if (offset > (UniCharArrayOffset)urend) { - offset = urend; - } - - /* - * If "flags" says that we don't actually want a word break, we need - * to find the next character break ourself, as ATSUBreakLine() will - * only give us word breaks. Do a simple linear search. - */ - - if ((err != kATSULineBreakInWord) - && !(flags & TK_WHOLE_WORDS) - && (offset <= (UniCharArrayOffset)urend)) { - - UniCharArrayOffset lastOffset = offset; - UniCharArrayOffset nextoffset; - int lastX = -1; - int wantonemorechar = -1; /* undecided */ - - while (offset <= (UniCharArrayOffset)urend) { - - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, offset); - } - curX = MeasureStringWidth(fontPtr, urstart, offset); - -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "measure: '%.*s', try until=%d, width=%d\n", - rangeLength, source+rangeStart, (int) offset, curX); -#endif - - if (curX > maxLength) { - - /* - * Even if we are over the limit, we may want another - * character in some situations. Than we keep looking - * for one more character. - */ - - if (wantonemorechar == -1) { - wantonemorechar = - ((flags & TK_AT_LEAST_ONE) - && (lastOffset == (UniCharArrayOffset)urstart)) - || - ((flags & TK_PARTIAL_OK) - && (lastX != maxLength)) - ; - if (!wantonemorechar) { - break; - } - lastX = curX; - } - - /* - * There may belong combining marks to this character. - * Wait for a new curX to collect them all. - */ - - if (lastX != curX) { - break; - } - } - - /* - * Save this position, so we can come back to it. - */ - - lastX = curX; - lastOffset = offset; - - /* - * Increment offset by one character, taking combining marks - * into account. - */ - - if (offset >= (UniCharArrayOffset)urend) { - break; - } - nextoffset = 0; - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, ulen); - } - err = ATSUNextCursorPosition( - fontPtr->atsuLayout, - offset, - kATSUByCluster, - &nextoffset); - if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUNextCursorPosition(): " - "Error %d\n", (int) err); -#endif - break; - } - if (nextoffset <= offset) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUNextCursorPosition(): " - "Can't move further " - "(shouldn't happen, bad data?)\n"); -#endif - break; - } - - offset = nextoffset; - } + UniCharArrayOffset offset = 0; + OSStatus err; - /* - * We have overshot one character, so backup one position. - */ - - curX = lastX; - offset = lastOffset; - } - - if (curX < 0) { - if (flags & TK_ISOLATE_END) { - TkMacOSXLayoutSetString(fontPtr, &drawingContext, - uchars, offset); - } - curX = MeasureStringWidth(fontPtr, urstart, offset); - } + /* + * Have some upper limit on the size actually used. + */ + + if (maxLength > 32767) { + maxLength = 32767; + } + + offset = urstart; + err = noErr; + + if (maxLength > 1) { + + /* + * Let the system do some work by calculating a line break. + * + * Somehow ATSUBreakLine seems to assume that it needs at least + * one pixel padding. So we add one to the limit. Note also + * that ATSUBreakLine sometimes runs into an endless loop when + * the third parameter is equal or less than IntToFixed(2), so we + * need at least IntToFixed(3) (at least that's the current state + * of my knowledge). + */ + + err = ATSUBreakLine( + fontPtr->atsuLayout, + urstart, + IntToFixed(maxLength+1), + false, /* !iUseAsSoftLineBreak */ + &offset); + + /* + * There is no way to signal an error from this routine, so we + * use predefined offset=urstart and otherwise ignore the + * possibility. + */ + + if ((err != noErr) && (err != kATSULineBreakInWord)) { + TkMacOSXDbgMsg("ATSUBreakLine failed: %ld for '%.*s'", err, + rangeLength, source+rangeStart); + } + +#ifdef TK_MAC_DEBUG_FONTS + TkMacOSXDbgMsg("measure: '%.*s', break offset=%ld, errcode=%ld", + rangeLength, source+rangeStart, offset, err); +#endif + + /* + * ATSUBreakLine includes the whitespace that separates words, + * but we don't want that. Besides, ATSUBreakLine thinks that + * spaces don't occupy pixels at the end of the break, which is + * also something we like to decide for ourself. + */ + + while ((offset > (UniCharArrayOffset)urstart) && (uchars[offset-1] == ' ')) { + offset--; + } + + /* + * Fix up left-overs for the TK_WHOLE_WORDS case. + */ + + if (flags & TK_WHOLE_WORDS) { + if(flags & TK_AT_LEAST_ONE) { + + /* + * If we are the the start of the range, we need to look + * forward. If we are not at the end of a word, we must + * be in the middle of the first word, so we also look + * forward. + */ + + if ((offset == (UniCharArrayOffset)urstart) || (uchars[offset] != ' ')) { + while ((offset < (UniCharArrayOffset)urend) + && (uchars[offset] != ' ')) { + offset++; + } + } + } else { + + /* + * If we are not at the end of a word, we need to look + * backward. + */ + + if ((offset != (UniCharArrayOffset)urend) && (uchars[offset] != ' ')) { + while ((offset > (UniCharArrayOffset)urstart) + && (uchars[offset-1] != ' ')) { + offset--; + } + while ((offset > (UniCharArrayOffset)urstart) + && (uchars[offset-1] == ' ')) { + offset--; + } + } + } + } + } + + if (offset > (UniCharArrayOffset)urend) { + offset = urend; + } + + /* + * If "flags" says that we don't actually want a word break, we need + * to find the next character break ourself, as ATSUBreakLine() will + * only give us word breaks. Do a simple linear search. + */ + + if ((err != kATSULineBreakInWord) + && !(flags & TK_WHOLE_WORDS) + && (offset <= (UniCharArrayOffset)urend)) { + + UniCharArrayOffset lastOffset = offset; + UniCharArrayOffset nextoffset; + int lastX = -1; + int wantonemorechar = -1; /* undecided */ + + while (offset <= (UniCharArrayOffset)urend) { + + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, + uchars, offset); + } + curX = MeasureStringWidth(fontPtr, urstart, offset); + +#ifdef TK_MAC_DEBUG_FONTS + TkMacOSXDbgMsg("measure: '%.*s', try until=%ld, width=%d", + rangeLength, source+rangeStart, offset, curX); +#endif + + if (curX > maxLength) { + + /* + * Even if we are over the limit, we may want another + * character in some situations. Than we keep looking + * for one more character. + */ + + if (wantonemorechar == -1) { + wantonemorechar = + ((flags & TK_AT_LEAST_ONE) + && (lastOffset == (UniCharArrayOffset)urstart)) + || + ((flags & TK_PARTIAL_OK) + && (lastX != maxLength)) + ; + if (!wantonemorechar) { + break; + } + lastX = curX; + } + + /* + * There may belong combining marks to this character. + * Wait for a new curX to collect them all. + */ + + if (lastX != curX) { + break; + } + } + + /* + * Save this position, so we can come back to it. + */ + + lastX = curX; + lastOffset = offset; + + /* + * Increment offset by one character, taking combining marks + * into account. + */ + + if (offset >= (UniCharArrayOffset)urend) { + break; + } + nextoffset = 0; + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, + uchars, ulen); + } + err = ChkErr(ATSUNextCursorPosition, fontPtr->atsuLayout, + offset, kATSUByCluster, &nextoffset); + if (err != noErr) { + break; + } + if (nextoffset <= offset) { +#ifdef TK_MAC_DEBUG_FONTS + TkMacOSXDbgMsg("ATSUNextCursorPosition: Can't move further" + " (shouldn't happen, bad data?)"); +#endif + break; + } + + offset = nextoffset; + } + + /* + * We have overshot one character, so backup one position. + */ + + curX = lastX; + offset = lastOffset; + } + + if (curX < 0) { + if (flags & TK_ISOLATE_END) { + LayoutSetString(fontPtr, NULL, + uchars, offset); + } + curX = MeasureStringWidth(fontPtr, urstart, offset); + } - curByte = Tcl_UtfAtIndex(source, offset) - source; - curByte -= rangeStart; + curByte = Tcl_UtfAtIndex(source, offset) - source; + curByte -= rangeStart; } Tcl_DStringFree(&ucharBuffer); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif - #ifdef TK_MAC_DEBUG_FONTS - fflush(stdout); - fprintf(stderr, "measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, " - "flags=%s%s%s%s\n", - rangeLength, source+rangeStart, maxLength, curX, curByte, - flags & TK_PARTIAL_OK ? "partialOk " : "", - flags & TK_WHOLE_WORDS ? "wholeWords " : "", - flags & TK_AT_LEAST_ONE ? "atLeastOne " : "", - flags & TK_ISOLATE_END ? "isolateEnd " : ""); - fflush(stderr); + TkMacOSXDbgMsg("measure: '%.*s', maxpix=%d, -> width=%d, bytes=%d, " + "flags=%s%s%s%s", rangeLength, source+rangeStart, maxLength, curX, + curByte, + flags & TK_PARTIAL_OK ? "partialOk " : "", + flags & TK_WHOLE_WORDS ? "wholeWords " : "", + flags & TK_AT_LEAST_ONE ? "atLeastOne " : "", + flags & TK_ISOLATE_END ? "isolateEnd " : ""); #endif *lengthPtr = curX; @@ -999,360 +1013,122 @@ TkpMeasureCharsInContext( * * Tk_DrawChars -- * - * Draw a string of characters on the screen. + * Draw a string of characters on the screen. * - * With ATSUI we need the line context to do this right, so we have the - * actual implementation in TkpDrawCharsInContext(). + * With ATSUI we need the line context to do this right, so we have the + * actual implementation in TkpDrawCharsInContext(). * * Results: * - * None. + * None. * * Side effects: * - * Information gets drawn on the screen. + * Information gets drawn on the screen. * *--------------------------------------------------------------------------- */ void Tk_DrawChars( - Display * display, /* Display on which to draw. */ - Drawable drawable, /* Window or pixmap in which to draw. */ - GC gc, /* Graphics context for drawing characters. */ - Tk_Font tkfont, /* Font in which characters will be drawn; must - * be the same as font used in GC. */ - const char * source, /* UTF-8 string to be displayed. Need not be - * '\0' terminated. All Tk meta-characters - * (tabs, control characters, and newlines) - * should be stripped out of the string that is - * passed to this function. If they are not - * stripped out, they will be displayed as - * regular printing characters. */ - int numBytes, /* Number of bytes in string. */ - int x, int y) /* Coordinates at which to place origin of the - * string when drawing. */ + Display * display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for drawing characters. */ + Tk_Font tkfont, /* Font in which characters will be drawn; must + * be the same as font used in GC. */ + const char * source, /* UTF-8 string to be displayed. Need not be + * '\0' terminated. All Tk meta-characters + * (tabs, control characters, and newlines) + * should be stripped out of the string that is + * passed to this function. If they are not + * stripped out, they will be displayed as + * regular printing characters. */ + int numBytes, /* Number of bytes in string. */ + int x, int y) /* Coordinates at which to place origin of the + * string when drawing. */ { TkpDrawCharsInContext(display, drawable, gc, tkfont, source, numBytes, - 0, numBytes, x, y); + 0, numBytes, x, y); } - /* *--------------------------------------------------------------------------- * * TkpDrawCharsInContext -- * - * Draw a string of characters on the screen like Tk_DrawChars(), with - * access to all the characters on the line for context. + * Draw a string of characters on the screen like Tk_DrawChars(), with + * access to all the characters on the line for context. * * Results: - * None. + * None. * * Side effects: - * Information gets drawn on the screen. + * Information gets drawn on the screen. * * Todo: - * - * We could try to implement a correct stipple algorithm. - * - * The fiddling with QD GraphPorts can be replaced with just working - * with the Quarz CGContext (see TkMacOSXQuarzStartDraw()), once we - * decide to stick to Quarz and really forget about QD drawing in here. + * Stippled text drawing. * *--------------------------------------------------------------------------- */ void TkpDrawCharsInContext( - Display * display, /* Display on which to draw. */ - Drawable drawable, /* Window or pixmap in which to draw. */ - GC gc, /* Graphics context for drawing characters. */ - Tk_Font tkfont, /* Font in which characters will be drawn; must - * be the same as font used in GC. */ - const char * source, /* UTF-8 string to be displayed. Need not be - * '\0' terminated. All Tk meta-characters - * (tabs, control characters, and newlines) - * should be stripped out of the string that is - * passed to this function. If they are not - * stripped out, they will be displayed as - * regular printing characters. */ - int numBytes, /* Number of bytes in string. */ - int rangeStart, /* Index of first byte to draw. */ - int rangeLength, /* Length of range to draw in bytes. */ - int x, int y) /* Coordinates at which to place origin of the - * whole (not just the range) string when - * drawing. */ -{ - const MacFont * fontPtr; - MacDrawable * macWin; - RGBColor macColor, origColor; - GWorldPtr destPort; - CGrafPtr saveWorld; - GDHandle saveDevice; - BitMapPtr stippleMap; - Rect portRect; - - fontPtr = (const MacFont *) tkfont; - macWin = (MacDrawable *) drawable; - - destPort = TkMacOSXGetDrawablePort(drawable); - GetPortBounds(destPort, &portRect); - GetGWorld(&saveWorld, &saveDevice); - SetGWorld(destPort, NULL); - - TkMacOSXSetUpClippingRgn(drawable); - TkMacOSXSetUpGraphicsPort(gc, destPort); - - GetForeColor(&origColor); - - if ((gc->fill_style == FillStippled - || gc->fill_style == FillOpaqueStippled) - && gc->stipple != None) { - - Pixmap pixmap; - GWorldPtr bufferPort; - Pattern white; - - stippleMap = TkMacOSXMakeStippleMap(drawable, gc->stipple); - - pixmap = Tk_GetPixmap(display, drawable, - stippleMap->bounds.right, stippleMap->bounds.bottom, 0); - - bufferPort = TkMacOSXGetDrawablePort(pixmap); - SetGWorld(bufferPort, NULL); - - if (TkSetMacColor(gc->foreground, &macColor)) { - RGBForeColor(&macColor); - } - GetQDGlobalsWhite(&white); - ShowPen(); - FillRect(&stippleMap->bounds, &white); - MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength, - 0, 0); - HidePen(); - - SetGWorld(destPort, NULL); - - CopyDeepMask(GetPortBitMapForCopyBits(bufferPort), stippleMap, - GetPortBitMapForCopyBits(destPort), &stippleMap->bounds, - &stippleMap->bounds, &portRect, - srcOr, NULL); - - /* - * TODO: this doesn't work quite right - it does a blend. you can't - * draw white text when you have a stipple. - */ - - Tk_FreePixmap(display, pixmap); - ckfree(stippleMap->baseAddr); - ckfree((char *)stippleMap); - } else { - if (TkSetMacColor(gc->foreground, &macColor)) { - RGBForeColor(&macColor); - } - ShowPen(); - MacFontDrawText(fontPtr, source, numBytes, rangeStart, rangeLength, - macWin->xOff + x, macWin->yOff + y); - HidePen(); - } - - RGBForeColor(&origColor); - - SetGWorld(saveWorld, saveDevice); -} - -#if TK_MAC_USE_QUARZ -#define RGBFLOATRED(c) (float)((float)(c.red) / 65535.0f) -#define RGBFLOATGREEN(c) (float)((float)(c.green) / 65535.0f) -#define RGBFLOATBLUE(c) (float)((float)(c.blue) / 65535.0f) -/* - *------------------------------------------------------------------------- - * - * TkMacOSXQuarzStartDraw -- - * - * Setup a Quarz CGContext from the current QD GraphPort for use in - * drawing or measuring. - * - * Results: - * - * A CGContext is allocated, configured and returned in - * drawingContextPtr. Also drawingContextPtr->portRect is filled in. - * - * Side effects: - * - * None. - * - * Assumptions: - * - * The current QD GraphPort contains all the data necessary. This is - * clearly the case for the actual drawing, but not so clear for - * measuring. OTOH for measuring the specific parameters are not really - * interesting and the GraphPort is not changed either. The - * availability of a CGContext may be important for the measuring - * process though. - * - *------------------------------------------------------------------------- - */ - -void -TkMacOSXQuarzStartDraw( - DrawingContext * drawingContextPtr) /* Quarz context data filled in - * by this function. */ -{ - GDHandle currentDevice; - CGrafPtr destPort; - RGBColor macColor; - CGContextRef outContext; - OSStatus err; - Rect boundsRect; - static RgnHandle clipRgn = NULL; - - GetGWorld(&destPort, ¤tDevice); - - err = QDBeginCGContext(destPort, &outContext); - - if (err == noErr && outContext) { - /* - * Now clip the CG Context to the port. We also have to intersect our clip - * region with the port visible region so we don't overwrite the window - * decoration. - */ - - if (!clipRgn) { - clipRgn = NewRgn(); - } - - GetPortBounds(destPort, &boundsRect); - - RectRgn(clipRgn, &boundsRect); - SectRegionWithPortClipRegion(destPort, clipRgn); - SectRegionWithPortVisibleRegion(destPort, clipRgn); - ClipCGContextToRegion(outContext, &boundsRect, clipRgn); - SetEmptyRgn(clipRgn); - - /* - * Note: You have to call SyncCGContextOriginWithPort - * AFTER all the clip region manipulations. - */ - - SyncCGContextOriginWithPort(outContext, destPort); - - /* - * Scale the color values, as QD uses UInt16 with the range [0..2^16-1] - * while Quarz uses float with [0..1]. NB: Only - * CGContextSetRGBFillColor() seems to be actually used by ATSU. - */ - - GetForeColor(&macColor); - CGContextSetRGBFillColor(outContext, - RGBFLOATRED(macColor), - RGBFLOATGREEN(macColor), - RGBFLOATBLUE(macColor), - 1.0f); - #ifdef TK_MAC_DEBUG_FONTS - } else { - fprintf(stderr, "QDBeginCGContext(): Error %d\n", (int) err); - #endif - } - - drawingContextPtr->graphPort = destPort; - drawingContextPtr->cgContext = outContext; - drawingContextPtr->portRect = boundsRect; - -} - -/* - *------------------------------------------------------------------------- - * - * TkMacOSXQuarzEndDraw -- - * - * Free the Quarz CGContext in drawingContextPtr. - * - * Results: - * - * The CGContext is de-allocated. drawingContextPtr->cgContext will be - * invalid after this. - * - * Side effects: - * - * None. - * - *------------------------------------------------------------------------- - */ - -void -TkMacOSXQuarzEndDraw( - DrawingContext * drawingContextPtr) -{ - if (drawingContextPtr->cgContext) { - QDEndCGContext( - drawingContextPtr->graphPort, - &drawingContextPtr->cgContext); - } -} -#endif /* TK_MAC_USE_QUARZ */ - -/* - *------------------------------------------------------------------------- - * - * MacFontDrawText -- - * - * Helper function for Tk_DrawChars. Draws characters, using the - * screen font in fontPtr to draw multilingual characters. - * - * Results: - * None. - * - * Side effects: - * Information gets drawn on the screen. - * - *------------------------------------------------------------------------- - */ - -static void -MacFontDrawText( - const MacFont * fontPtr, /* Contains font to use when drawing - * following string. */ - const char * source, /* Potentially multilingual UTF-8 string. */ - int numBytes, /* Length of string in bytes. */ - int rangeStart, /* Index of first byte to draw. */ - int rangeLength, /* Length of range to draw in bytes. */ - int x, int y) /* Coordinates at which to place origin of - * string when drawing. */ + Display * display, /* Display on which to draw. */ + Drawable drawable, /* Window or pixmap in which to draw. */ + GC gc, /* Graphics context for drawing characters. */ + Tk_Font tkfont, /* Font in which characters will be drawn; must + * be the same as font used in GC. */ + const char * source, /* UTF-8 string to be displayed. Need not be + * '\0' terminated. All Tk meta-characters + * (tabs, control characters, and newlines) + * should be stripped out of the string that is + * passed to this function. If they are not + * stripped out, they will be displayed as + * regular printing characters. */ + int numBytes, /* Number of bytes in string. */ + int rangeStart, /* Index of first byte to draw. */ + int rangeLength, /* Length of range to draw in bytes. */ + int x, int y) /* Coordinates at which to place origin of the + * whole (not just the range) string when + * drawing. */ { + const MacFont * fontPtr = (const MacFont *) tkfont; + MacDrawable *macWin = (MacDrawable *) drawable; Fixed fx, fy; int ulen, urstart, urlen; const UniChar * uchars; int lineOffset; - DrawingContext drawingContext; - OSStatus err; - + TkMacOSXDrawingContext drawingContext; #if !TK_MAC_COALESCE_LINE Tcl_DString runString; #endif + TkMacOSXSetupDrawingContext(drawable, gc, 1, &drawingContext); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); - - /* - * Turn the y coordinate upside-down for Quarz drawing. We would have - * liked to just use a CTM transform in the CGContext, but than we get - * upside-down text, so doing it that way gets more painfull than to just - * hack around the problem right here. - */ - - y = drawingContext.portRect.bottom - drawingContext.portRect.top - y; - fy = IntToFixed(y); -#else - fy = IntToFixed(y); +#if 0 + /* TODO: implement stippled text drawing */ + if ((gc->fill_style == FillStippled + || gc->fill_style == FillOpaqueStippled) + && gc->stipple != None) { + #error Stippling not implemented + } #endif + x += macWin->xOff; + y += macWin->yOff; + /* Turn the y coordinate upside-down for Quarz drawing. */ + if (drawingContext.context) { + CGContextConcatCTM(drawingContext.context, CGAffineTransformMake(1.0, + 0.0, 0.0, -1.0, 0.0, drawingContext.portBounds.bottom - + drawingContext.portBounds.top)); + y = drawingContext.portBounds.bottom - + drawingContext.portBounds.top - y; + } + fy = IntToFixed(y); #if TK_MAC_COALESCE_LINE UpdateLineBuffer( - fontPtr, &drawingContext, source, numBytes, x, y, &lineOffset); + fontPtr, &drawingContext, source, numBytes, x, y, &lineOffset); fx = IntToFixed(currentLeft); @@ -1366,59 +1142,49 @@ MacFontDrawText( uchars = Tcl_UtfToUniCharDString(source, numBytes, &runString); ulen = Tcl_DStringLength(&runString) / sizeof(uchars[0]); - TkMacOSXLayoutSetString(fontPtr, &drawingContext, uchars, ulen); + LayoutSetString(fontPtr, &drawingContext, uchars, ulen); #endif urstart = Tcl_NumUtfChars(source, rangeStart); urlen = Tcl_NumUtfChars(source+rangeStart,rangeLength); - err = ATSUDrawText( - fontPtr->atsuLayout, - lineOffset+urstart, urlen, - fx, fy); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUDrawText(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUDrawText, fontPtr->atsuLayout, lineOffset+urstart, urlen, fx, + fy); #if !TK_MAC_COALESCE_LINE Tcl_DStringFree(&runString); #endif -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif + TkMacOSXRestoreDrawingContext(&drawingContext); } - /* *--------------------------------------------------------------------------- * * MeasureStringWidth -- * - * Low-level measuring of strings. + * Low-level measuring of strings. * * Results: * - * The width of the string in pixels. + * The width of the string in pixels. * * Side effects: * - * None. + * None. * * Assumptions: * - * fontPtr->atsuLayout is setup with the actual string data to measure. + * fontPtr->atsuLayout is setup with the actual string data to measure. * *--------------------------------------------------------------------------- */ static int MeasureStringWidth( const MacFont * fontPtr, /* Contains font, ATSU layout and string data - * to measure. */ - int start, int end) /* Start and end positions to measure in that - * string. */ + * to measure. */ + int start, int end) /* Start and end positions to measure in that + * string. */ { /* * This implementation of measuring via ATSUGetGlyphBounds() does not @@ -1434,26 +1200,18 @@ MeasureStringWidth( ATSTrapezoid bounds; ItemCount numBounds; - OSStatus err; if (end <= start) { - return 0; + return 0; } bounds.upperRight.x = bounds.upperLeft.x = 0; - err = ATSUGetGlyphBounds( - fontPtr->atsuLayout, - 0, 0, - start, end-start, - kATSUseFractionalOrigins, - 1, &bounds, &numBounds); + ChkErr(ATSUGetGlyphBounds, fontPtr->atsuLayout, 0, 0, start, end-start, + kATSUseFractionalOrigins, 1, &bounds, &numBounds); #ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUGetGlyphBounds(): Error %d\n", (int) err); - } else if (numBounds < 1) { - fprintf(stderr, "ATSUGetGlyphBounds(): No output\n"); - } else if (numBounds > 1) { - fprintf(stderr, "ATSUGetGlyphBounds(): More output\n"); + if (numBounds < 1 || numBounds > 1) { + TkMacOSXDbgMsg("ATSUGetGlyphBounds: %s output", + numBounds < 1 ? "No " : "More"); } #endif @@ -1466,58 +1224,58 @@ MeasureStringWidth( * * UpdateLineBuffer -- * - * See the general dicussion of TK_MAC_COALESCE_LINE on the header - * pages. This function maintains the data for this feature. + * See the general dicussion of TK_MAC_COALESCE_LINE on the header + * pages. This function maintains the data for this feature. * * Results: * - * The Tcl_UniChar string of the whole line as seen so far. + * The Tcl_UniChar string of the whole line as seen so far. * * Side effects: * - * "*offset" is filled with the index of the first new character in - * "currentLine". The globals currentLine, currentY, currentLeft, - * currentRight and currentFontPtr are updated as necessary. + * "*offset" is filled with the index of the first new character in + * "currentLine". The globals currentLine, currentY, currentLeft, + * currentRight and currentFontPtr are updated as necessary. * - * The currentLine string is set as the current text in - * fontPtr->atsuLayout (see TkMacOSXLayoutSetString()). + * The currentLine string is set as the current text in + * fontPtr->atsuLayout (see LayoutSetString()). * *------------------------------------------------------------------------- */ static const Tcl_UniChar * UpdateLineBuffer( - const MacFont * fontPtr,/* The font to be used for the new piece of - * text. */ - const DrawingContext * drawingContextPtr, - /* The Quarz drawing parameters. Needed for - * measuring the new piece. */ - const char * source, /* A new piece of line to be added. */ - int numBytes, /* Length of the new piece. */ - int x, int y, /* Position of the new piece in the window. */ - int * offset) /* Filled with the offset of the new piece in - * currentLine. */ + const MacFont * fontPtr, /* The font to be used for the new piece of + * text. */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* The Quarz drawing parameters. Needed for + * measuring the new piece. */ + const char * source, /* A new piece of line to be added. */ + int numBytes, /* Length of the new piece. */ + int x, int y, /* Position of the new piece in the window. */ + int * offset) /* Filled with the offset of the new piece in + * currentLine. */ { const Tcl_UniChar * uchars; int ulen; if (y != currentY - || x < currentRight-1 || x > currentRight+2 - || currentFontPtr != fontPtr) { - Tcl_DStringFree(¤tLine); - Tcl_DStringInit(¤tLine); - currentY = y; - currentLeft = x; - currentFontPtr = fontPtr; - *offset = 0; + || x < currentRight-1 || x > currentRight+2 + || currentFontPtr != fontPtr) { + Tcl_DStringFree(¤tLine); + Tcl_DStringInit(¤tLine); + currentY = y; + currentLeft = x; + currentFontPtr = fontPtr; + *offset = 0; } else { - *offset = Tcl_DStringLength(¤tLine) / 2; + *offset = Tcl_DStringLength(¤tLine) / 2; } Tcl_UtfToUniCharDString(source, numBytes, ¤tLine); uchars = (const Tcl_UniChar*) Tcl_DStringValue(¤tLine); ulen = Tcl_DStringLength(¤tLine) / sizeof(*uchars); - TkMacOSXLayoutSetString(fontPtr, drawingContextPtr, uchars, ulen); + LayoutSetString(fontPtr, drawingContextPtr, uchars, ulen); currentRight = x + MeasureStringWidth(fontPtr, *offset, ulen); return uchars; @@ -1529,33 +1287,33 @@ UpdateLineBuffer( * * InitFont -- * - * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes(). - * Initializes the memory for a MacFont that wraps the - * platform-specific data. + * Helper for TkpGetNativeFont() and TkpGetFontFromAttributes(). + * Initializes the memory for a MacFont that wraps the + * platform-specific data. * - * The caller is responsible for initializing the fields of the TkFont - * that are used exclusively by the generic TkFont code, and for - * releasing those fields before calling TkpDeleteFont(). + * The caller is responsible for initializing the fields of the TkFont + * that are used exclusively by the generic TkFont code, and for + * releasing those fields before calling TkpDeleteFont(). * * Results: - * Fills the MacFont structure. + * Fills the MacFont structure. * * Side effects: - * Memory allocated. + * Memory allocated. * *--------------------------------------------------------------------------- */ static void InitFont( - Tk_Window tkwin, /* For display where font will be used. */ - FMFontFamily familyId, /* The font family to initialize for. */ - const char * familyName,/* The font family name, if known. Otherwise - * this can be NULL. */ - int size, /* Point size for the font. */ - int qdStyle, /* QuickDraw style bits. */ - MacFont * fontPtr) /* Filled with information constructed from the - * above arguments. */ + Tk_Window tkwin, /* For display where font will be used. */ + FMFontFamily familyId, /* The font family to initialize for. */ + const char * familyName, /* The font family name, if known. Otherwise + * this can be NULL. */ + int size, /* Point size for the font. */ + int qdStyle, /* QuickDraw style bits. */ + MacFont * fontPtr) /* Filled with information constructed from the + * above arguments. */ { OSStatus err; FontInfo fi; @@ -1565,38 +1323,31 @@ InitFont( int periodWidth, wWidth; if (size == 0) { - size = GetDefFontSize(); + size = GetDefFontSize(); } points = (short) TkFontGetPoints(tkwin, size); - - err = FetchFontInfo(familyId, points, qdStyle, &fi); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FetchFontInfo(): Error %d\n", (int) err); - } -#endif - + ChkErr(FetchFontInfo, familyId, points, qdStyle, &fi); if (familyName == NULL) { - char name[256] = ""; - const MacFontFamily * familyPtr; + char name[256] = ""; + const MacFontFamily * familyPtr; - err = GetFontFamilyName(familyId, name, sizeof(name)); - if (err == noErr) { + err = ChkErr(GetFontFamilyName, familyId, name, sizeof(name)); + if (err == noErr) { - /* - * We find the canonical font name, so we can avoid unnecessary - * memory management. - */ - - familyPtr = FindFontFamily(name); - if (familyPtr != NULL) { - familyName = familyPtr->name; - } else { + /* + * We find the canonical font name, so we can avoid unnecessary + * memory management. + */ + + familyPtr = FindFontFamily(name); + if (familyPtr != NULL) { + familyName = familyPtr->name; + } else { #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "Font family '%s': Not found\n", name); + TkMacOSXDbgMsg("Font family '%s' not found", name); #endif - } - } + } + } } fontPtr->font.fid = (Font) fontPtr; @@ -1628,8 +1379,8 @@ InitFont( fontPtr->qdStyle = (short) qdStyle; InitATSUObjects( - familyId, points, qdStyle, - &fontPtr->atsuFontId, &fontPtr->atsuLayout, &fontPtr->atsuStyle); + familyId, points, qdStyle, + &fontPtr->atsuFontId, &fontPtr->atsuLayout, &fontPtr->atsuStyle); Tk_MeasureChars((Tk_Font)fontPtr, ".", 1, -1, 0, &periodWidth); Tk_MeasureChars((Tk_Font)fontPtr, "W", 1, -1, 0, &wWidth); @@ -1645,31 +1396,30 @@ InitFont( * * InitATSUObjects -- * - * Helper for InitFont(). Initializes the ATSU data handles for a - * MacFont. + * Helper for InitFont(). Initializes the ATSU data handles for a + * MacFont. * * Results: * - * Sets up all we know and can do at this point in time in fontIdPtr, - * layoutPtr and stylePtr. + * Sets up all we know and can do at this point in time in fontIdPtr, + * layoutPtr and stylePtr. * * Side effects: * - * Allocates data structures inside of ATSU. + * Allocates data structures inside of ATSU. * *--------------------------------------------------------------------------- */ static void InitATSUObjects( - FMFontFamily familyId, /* The font family to use. */ - short ptSize, short qdStyles, /* The additional font parameters. */ - ATSUFontID * fontIdPtr, /* Filled with the font id. */ - ATSUTextLayout * layoutPtr, /* Filled with the ATSU layout handle. */ - ATSUStyle * stylePtr) /* Filled with the ATSU style handle, - * configured with all parameters. */ + FMFontFamily familyId, /* The font family to use. */ + short ptSize, short qdStyles, /* The additional font parameters. */ + ATSUFontID * fontIdPtr, /* Filled with the font id. */ + ATSUTextLayout * layoutPtr, /* Filled with the ATSU layout handle. */ + ATSUStyle * stylePtr) /* Filled with the ATSU style handle, + * configured with all parameters. */ { - OSStatus err; FMFontStyle stylesDone, stylesLeft; /* @@ -1684,14 +1434,8 @@ InitATSUObjects( * Generate a font id from family id and QD style bits. */ - err = FMGetFontFromFontFamilyInstance( - familyId, qdStyles, fontIdPtr, &stylesDone); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFromFontFamilyInstance(): Error %d\n", - (int) err); - } -#endif + ChkErr(FMGetFontFromFontFamilyInstance, familyId, qdStyles, fontIdPtr, + &stylesDone); /* * We see what style bits are left and tell ATSU to synthesize what's @@ -1704,12 +1448,7 @@ InitATSUObjects( * Create the style and set its attributes. */ - err = ATSUCreateStyle(stylePtr); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUCreateStyle(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUCreateStyle, stylePtr); InitATSUStyle(*fontIdPtr, ptSize, stylesLeft, *stylePtr); /* @@ -1717,12 +1456,7 @@ InitATSUObjects( * because the text and the style must be set first. */ - err = ATSUCreateTextLayout(layoutPtr); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUCreateTextLayout(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUCreateTextLayout, layoutPtr); /*InitATSULayout(*layoutPtr);*/ } @@ -1731,25 +1465,25 @@ InitATSUObjects( * * InitATSUStyle -- * - * Helper for InitATSUObjects(). Initializes the ATSU style for a - * MacFont. + * Helper for InitATSUObjects(). Initializes the ATSU style for a + * MacFont. * * Results: * - * Sets up all parameters needed for an ATSU style. + * Sets up all parameters needed for an ATSU style. * * Side effects: * - * Allocates data structures for the style inside of ATSU. + * Allocates data structures for the style inside of ATSU. * *--------------------------------------------------------------------------- */ static void InitATSUStyle( - ATSUFontID fontId, /* The font id to use. */ - short ptSize, short qdStyles, /* Additional font parameters. */ - ATSUStyle style) /* The style handle to configure. */ + ATSUFontID fontId, /* The font id to use. */ + short ptSize, short qdStyles, /* Additional font parameters. */ + ATSUStyle style) /* The style handle to configure. */ { /* * Attributes for the style. @@ -1757,69 +1491,59 @@ InitATSUStyle( Fixed fsize = IntToFixed(ptSize); Boolean - isBold = (qdStyles&bold) != 0, - isUnderline = (qdStyles&underline) != 0, - isItalic = (qdStyles&italic) != 0; + isBold = (qdStyles&bold) != 0, + isUnderline = (qdStyles&underline) != 0, + isItalic = (qdStyles&italic) != 0; ATSStyleRenderingOptions options = - antialiasedTextEnabled == -1 ? kATSStyleNoOptions : - antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing : - kATSStyleApplyAntiAliasing; + antialiasedTextEnabled == -1 ? kATSStyleNoOptions : + antialiasedTextEnabled == 0 ? kATSStyleNoAntiAliasing : + kATSStyleApplyAntiAliasing; static const ATSUAttributeTag styleTags[] = { - kATSUFontTag, kATSUSizeTag, - kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag, - kATSUStyleRenderingOptionsTag, + kATSUFontTag, kATSUSizeTag, + kATSUQDBoldfaceTag, kATSUQDItalicTag, kATSUQDUnderlineTag, + kATSUStyleRenderingOptionsTag, }; static const ByteCount styleSizes[] = { - sizeof(ATSUFontID), sizeof(Fixed), - sizeof(Boolean), sizeof(Boolean), sizeof(Boolean), - sizeof(ATSStyleRenderingOptions), + sizeof(ATSUFontID), sizeof(Fixed), + sizeof(Boolean), sizeof(Boolean), sizeof(Boolean), + sizeof(ATSStyleRenderingOptions), }; const ATSUAttributeValuePtr styleValues[] = { - &fontId, &fsize, - &isBold, &isItalic, &isUnderline, - &options, + &fontId, &fsize, + &isBold, &isItalic, &isUnderline, + &options, }; - OSStatus err; - - err = ATSUSetAttributes( - style, - sizeof(styleTags)/sizeof(styleTags[0]), - styleTags, styleSizes, styleValues); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetAttributes(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetAttributes, style, sizeof(styleTags)/sizeof(styleTags[0]), + styleTags, styleSizes, styleValues); } - /* *--------------------------------------------------------------------------- * * SetFontFeatures -- * - * Helper for InitFont(). Request specific font features of the ATSU - * style object for a MacFont. + * Helper for InitFont(). Request specific font features of the ATSU + * style object for a MacFont. * * Results: * - * None. + * None. * * Side effects: * - * Specific font features are enabled on the ATSU style object. + * Specific font features are enabled on the ATSU style object. * *--------------------------------------------------------------------------- */ static void SetFontFeatures( - ATSUFontID fontId, /* The font id to use. */ - int fixed, /* Is this a fixed font? */ - ATSUStyle style) /* The style handle to configure. */ + ATSUFontID fontId, /* The font id to use. */ + int fixed, /* Is this a fixed font? */ + ATSUStyle style) /* The style handle to configure. */ { /* * Don't use the standard latin ligatures, if this is determined to be a @@ -1827,24 +1551,16 @@ SetFontFeatures( */ static const ATSUFontFeatureType fixed_featureTypes[] = { - kLigaturesType, kLigaturesType + kLigaturesType, kLigaturesType }; static const ATSUFontFeatureSelector fixed_featureSelectors[] = { - kCommonLigaturesOffSelector, kRareLigaturesOffSelector + kCommonLigaturesOffSelector, kRareLigaturesOffSelector }; - OSStatus err; - if (fixed) { - err = ATSUSetFontFeatures( - style, - sizeof(fixed_featureTypes)/sizeof(fixed_featureTypes[0]), - fixed_featureTypes, fixed_featureSelectors); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetFontFeatures(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetFontFeatures, style, sizeof(fixed_featureTypes) / + sizeof(fixed_featureTypes[0]), fixed_featureTypes, + fixed_featureSelectors); } } @@ -1853,17 +1569,17 @@ SetFontFeatures( * * AdjustFontHeight -- * - * Helper for InitFont(). Check font height against some real world - * examples. + * Helper for InitFont(). Check font height against some real world + * examples. * * Results: * - * None. + * None. * * Side effects: * - * The metrics in fontPtr->font.fm are adjusted so that typical combined - * characters fit into ascent+descent. + * The metrics in fontPtr->font.fm are adjusted so that typical combined + * characters fit into ascent+descent. * *--------------------------------------------------------------------------- */ @@ -1888,232 +1604,177 @@ AdjustFontHeight( */ static const UniChar chars[] - /* Auml, Aacute, Acirc, Atilde, Ccedilla */ - = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7}; + /* Auml, Aacute, Acirc, Atilde, Ccedilla */ + = {0x00C4, 0x00C1, 0x00C2, 0x00C3, 0x00C7}; static const int charslen = sizeof(chars) / sizeof(chars[0]); - DrawingContext drawingContext; Rect size; OSStatus err; - -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzStartDraw(&drawingContext); -#endif - - TkMacOSXLayoutSetString(fontPtr, &drawingContext, chars, charslen); + LayoutSetString(fontPtr, NULL, chars, charslen); size.top = size.bottom = 0; - err = ATSUMeasureTextImage( - fontPtr->atsuLayout, - 0, charslen, - 0, 0, - &size); + err = ChkErr(ATSUMeasureTextImage, fontPtr->atsuLayout, 0, charslen, 0, 0, + &size); -#if TK_MAC_USE_QUARZ - TkMacOSXQuarzEndDraw(&drawingContext); -#endif - - if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "ATSUMeasureTextImage(): Error %d\n", (int) err); -#endif - } else { - TkFontMetrics * fmPtr = &fontPtr->font.fm; - int ascent = -size.top; - int descent = size.bottom; - - if (ascent > fmPtr->ascent) { - fmPtr->ascent = ascent; - } - if (descent > fmPtr->descent) { - fmPtr->descent = descent; - } + if (err == noErr) { + TkFontMetrics * fmPtr = &fontPtr->font.fm; + int ascent = -size.top; + int descent = size.bottom; + + if (ascent > fmPtr->ascent) { + fmPtr->ascent = ascent; + } + if (descent > fmPtr->descent) { + fmPtr->descent = descent; + } } } - /* *--------------------------------------------------------------------------- * * InitATSULayout -- * - * Helper for TkMacOSXLayoutSetString(). Initializes the ATSU layout - * object for a MacFont and a specific string. + * Helper for LayoutSetString(). Initializes the ATSU layout + * object for a MacFont and a specific string. * * Results: * - * Sets up all parameters needed for an ATSU layout object. + * Sets up all parameters needed for an ATSU layout object. * * Side effects: * - * Allocates data structures for the layout object inside of ATSU. + * Allocates data structures for the layout object inside of ATSU. * * Assumptions: * - * The actual string data and style information is already set by - * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see - * TkMacOSXLayoutSetString()). + * The actual string data and style information is already set by + * ATSUSetTextPointerLocation() and ATSUSetRunStyle() (see + * LayoutSetString()). * *--------------------------------------------------------------------------- */ static void InitATSULayout( - const DrawingContext * drawingContextPtr, - /* Specifies the CGContext to use. */ - ATSUTextLayout layout, /* The layout object to configure. */ - int fixed) /* Is this a fixed font? */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* Specifies the CGContext to use. */ + ATSUTextLayout layout, /* The layout object to configure. */ + int fixed) /* Is this a fixed font? */ { /* * Attributes for the layout. */ - ATSLineLayoutOptions layoutOptions = - 0 + ATSLineLayoutOptions layoutOptions = 0 #if TK_MAC_COALESCE_LINE - /* - * Options to use unconditionally, when we try to do coalescing in here. - */ - | kATSLineDisableAllLayoutOperations - | kATSLineFractDisable - | kATSLineUseDeviceMetrics -#endif - ; + /* + * Options to use unconditionally, when we try to do coalescing. + */ + | kATSLineDisableAllLayoutOperations + | kATSLineFractDisable + | kATSLineUseDeviceMetrics +#endif + ; + CGContextRef context = drawingContextPtr ? + drawingContextPtr->context : NULL; static const ATSUAttributeTag layoutTags[] = { -#if TK_MAC_USE_QUARZ - kATSUCGContextTag, -#endif - kATSULineLayoutOptionsTag, + kATSUCGContextTag, + kATSULineLayoutOptionsTag, }; static const ByteCount layoutSizes[] = { -#if TK_MAC_USE_QUARZ - sizeof(CGContextRef), -#endif - sizeof(ATSLineLayoutOptions), + sizeof(CGContextRef), + sizeof(ATSLineLayoutOptions), }; const ATSUAttributeValuePtr layoutValues[] = { -#if TK_MAC_USE_QUARZ - (void*)&drawingContextPtr->cgContext, -#endif - &layoutOptions, + &context, + &layoutOptions, }; - OSStatus err; - /* * Ensure W(abcdefg) == W(a)*7 for fixed fonts (Latin scripts only). */ if (fixed) { - layoutOptions |= - kATSLineFractDisable - | kATSLineUseDeviceMetrics - ; - } - - err = ATSUSetLayoutControls( - layout, - sizeof(layoutTags)/sizeof(layoutTags[0]), - layoutTags, layoutSizes, layoutValues); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetLayoutControls(): Error %d\n", (int) err); + layoutOptions |= + kATSLineFractDisable + | kATSLineUseDeviceMetrics + ; } -#endif - err = ATSUSetTransientFontMatching(layout, true); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetTransientFontMatching(): Error %d\n", - (int) err); - } -#endif + ChkErr(ATSUSetLayoutControls, layout, sizeof(layoutTags) / + sizeof(layoutTags[0]), layoutTags, layoutSizes, layoutValues); + ChkErr(ATSUSetTransientFontMatching, layout, true); } /* *--------------------------------------------------------------------------- * - * TkMacOSXLayoutSetString -- + * LayoutSetString -- * - * Setup the MacFont for a specific string. + * Setup the MacFont for a specific string. * * Results: * - * Sets up all parameters so that ATSU can work with the objects in - * MacFont. + * Sets up all parameters so that ATSU can work with the objects in + * MacFont. * * Side effects: * - * Sets parameters on the layout object fontPtr->atsuLayout. + * Sets parameters on the layout object fontPtr->atsuLayout. * *--------------------------------------------------------------------------- */ void -TkMacOSXLayoutSetString( - const MacFont * fontPtr, /* The fontPtr to configure. */ - const DrawingContext * drawingContextPtr, - /* For the CGContext to be used.*/ +LayoutSetString( + const MacFont * fontPtr, /* The fontPtr to configure. */ + const TkMacOSXDrawingContext *drawingContextPtr, + /* For the CGContext to be used.*/ const UniChar * uchars, int ulen) /* The UniChar string to set into - * fontPtr->atsuLayout. */ + * fontPtr->atsuLayout. */ { - OSStatus err; - err = ATSUSetTextPointerLocation( - fontPtr->atsuLayout, - uchars, kATSUFromTextBeginning, ulen, - ulen); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetTextPointerLocation(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetTextPointerLocation, fontPtr->atsuLayout, uchars, + kATSUFromTextBeginning, ulen, ulen); /* * Styles can only be set after the text is set. */ - err = ATSUSetRunStyle( - fontPtr->atsuLayout, fontPtr->atsuStyle, - kATSUFromTextBeginning, kATSUToTextEnd); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSUSetRunStyle(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSUSetRunStyle, fontPtr->atsuLayout, fontPtr->atsuStyle, + kATSUFromTextBeginning, kATSUToTextEnd); /* * Layout attributes can only be set after the styles are set. */ - InitATSULayout( - drawingContextPtr, fontPtr->atsuLayout, - fontPtr->font.fm.fixed); + InitATSULayout(drawingContextPtr, fontPtr->atsuLayout, + fontPtr->font.fm.fixed); } - /* *------------------------------------------------------------------------- * * ReleaseFont -- * - * Called to release the Macintosh-specific contents of a TkFont. The - * caller is responsible for freeing the memory used by the font - * itself. + * Called to release the Macintosh-specific contents of a TkFont. The + * caller is responsible for freeing the memory used by the font + * itself. * * Results: - * None. + * None. * * Side effects: - * Memory is freed. + * Memory is freed. * *--------------------------------------------------------------------------- */ static void ReleaseFont( - MacFont * fontPtr) /* The font to delete. */ + MacFont * fontPtr) /* The font to delete. */ { ATSUDisposeTextLayout(fontPtr->atsuLayout); ATSUDisposeStyle(fontPtr->atsuStyle); @@ -2124,40 +1785,40 @@ ReleaseFont( * * FindFontFamilyOrAlias, FindFontFamilyOrAliasOrFallback -- * - * Determine if any physical screen font exists on the system with The - * given family name. If the family exists, then it should be possible - * to construct some physical screen font with that family name. + * Determine if any physical screen font exists on the system with The + * given family name. If the family exists, then it should be possible + * to construct some physical screen font with that family name. * - * FindFontFamilyOrAlias also considers font aliases as determined by - * TkFontGetAliasList(). + * FindFontFamilyOrAlias also considers font aliases as determined by + * TkFontGetAliasList(). * - * FindFontFamilyOrAliasOrFallback also considers font aliases as - * determined by TkFontGetFallbacks(). + * FindFontFamilyOrAliasOrFallback also considers font aliases as + * determined by TkFontGetFallbacks(). * - * The overall algorithm to get the closest font to the one requested is - * this: + * The overall algorithm to get the closest font to the one requested is + * this: * - * try fontname - * try all aliases for fontname - * foreach fallback for fontname - * try the fallback - * try all aliases for the fallback + * try fontname + * try all aliases for fontname + * foreach fallback for fontname + * try the fallback + * try all aliases for the fallback * * Results: * - * The return value is NULL if the specified font family does not exist, - * a valid MacFontFamily* otherwise. + * The return value is NULL if the specified font family does not exist, + * a valid MacFontFamily* otherwise. * * Side effects: * - * None. + * None. * *------------------------------------------------------------------------- */ static const MacFontFamily * FindFontFamilyOrAlias( - const char * name) /* Name or alias name of the font to find. */ + const char * name) /* Name or alias name of the font to find. */ { const MacFontFamily * familyPtr; char ** aliases; @@ -2165,24 +1826,24 @@ FindFontFamilyOrAlias( familyPtr = FindFontFamily(name); if (familyPtr != NULL) { - return familyPtr; + return familyPtr; } aliases = TkFontGetAliasList(name); if (aliases != NULL) { - for (i = 0; aliases[i] != NULL; i++) { - familyPtr = FindFontFamily(aliases[i]); - if (familyPtr != NULL) { - return familyPtr; - } - } + for (i = 0; aliases[i] != NULL; i++) { + familyPtr = FindFontFamily(aliases[i]); + if (familyPtr != NULL) { + return familyPtr; + } + } } return NULL; } static const MacFontFamily * FindFontFamilyOrAliasOrFallback( - const char * name) /* Name or alias name of the font to find. */ + const char * name) /* Name or alias name of the font to find. */ { const MacFontFamily * familyPtr; const char * fallback; @@ -2191,23 +1852,23 @@ FindFontFamilyOrAliasOrFallback( familyPtr = FindFontFamilyOrAlias(name); if (familyPtr != NULL) { - return familyPtr; + return familyPtr; } fallbacks = TkFontGetFallbacks(); for (i = 0; fallbacks[i] != NULL; i++) { - for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { - if (strcasecmp(name, fallback) == 0) { - for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { - familyPtr = FindFontFamilyOrAlias(fallback); - if (familyPtr != NULL) { - return familyPtr; - } - } - } - break; /* benny: This "break" is a carry-over from - * tkMacOSXFont.c, but what is actually its purpose - * ???? */ - } + for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { + if (strcasecmp(name, fallback) == 0) { + for (j = 0; (fallback = fallbacks[i][j]) != NULL; j++) { + familyPtr = FindFontFamilyOrAlias(fallback); + if (familyPtr != NULL) { + return familyPtr; + } + } + } + break; /* benny: This "break" is a carry-over from + * tkMacOSXFont.c, but what is actually its purpose + * ???? */ + } } @@ -2220,7 +1881,7 @@ FindFontFamilyOrAliasOrFallback( */ #ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "Font family '%s': Not found\n", name); + TkMacOSXDbgMsg("Font family '%s' not found", name); #endif return NULL; @@ -2231,16 +1892,16 @@ FindFontFamilyOrAliasOrFallback( * * InitFontFamilies -- * - * Helper to TkpFontPkgInit. Use the Font Manager to fill in the - * familyList global array. + * Helper to TkpFontPkgInit. Use the Font Manager to fill in the + * familyList global array. * * Results: * - * None. + * None. * * Side effects: * - * Allocates memory. + * Allocates memory. * *------------------------------------------------------------------------- */ @@ -2248,32 +1909,58 @@ FindFontFamilyOrAliasOrFallback( static void InitFontFamilies(void) { - OSStatus err; + FMFontFamily fontFamily; + Str255 fontName; + SInt16 fontSize; + Style fontStyle; /* * Has this been called before? */ if (familyListNextFree > 0) { - return; + return; } - err = ATSFontFamilyApplyFunction(FontFamilyEnumCallback,NULL); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "ATSFontFamilyApplyFunction(): Error %d\n", (int) err); - } -#endif + ChkErr(ATSFontFamilyApplyFunction, FontFamilyEnumCallback,NULL); - AddFontFamily(APPLFONT_NAME, GetAppFont()); - AddFontFamily(SYSTEMFONT_NAME, GetSysFont()); + if (GetThemeFontAndFamily(kThemeSystemFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(SYSTEMFONT_NAME, fontFamily); + } + if (GetThemeFontAndFamily(kThemeApplicationFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(APPLFONT_NAME, fontFamily); + } + if (GetThemeFontAndFamily(kThemeMenuItemFont, &fontFamily, fontName, + &fontSize, &fontStyle) == noErr) { + AddFontFamily(MENUITEMFONT_NAME, fontFamily); + } SortFontFamilies(); } + +/* + *------------------------------------------------------------------------- + * + * FontFamilyEnumCallback -- + * + * Callback for ATSFontFamilyApplyFunction(). + * + * Results: + * + * noErr. + * + * Side effects: + * + * None. + * + *------------------------------------------------------------------------- + */ static OSStatus FontFamilyEnumCallback( - ATSFontFamilyRef family, + ATSFontFamilyRef family, void *refCon) { OSStatus err; @@ -2281,42 +1968,41 @@ FontFamilyEnumCallback( (void) refCon; - err = GetFontFamilyName(family, name, sizeof(name)); + err = ChkErr(GetFontFamilyName, family, name, sizeof(name)); if (err == noErr) { - AddFontFamily(name, family); + AddFontFamily(name, family); } return noErr; } - /* *------------------------------------------------------------------------- * * GetFontFamilyName -- * - * Use the Font Manager to get the name of a given FMFontfamily. This - * currently gets the standard, non-localized QuickDraw name. Other - * names would be possible, see docs for ATSUFindFontName for a - * selection. The MacOSX font selector seems to use the localized - * family name given by ATSUFindFontName(kFontFamilyName), but that API - * doesn't give us a name at all for some fonts. + * Use the Font Manager to get the name of a given FMFontfamily. This + * currently gets the standard, non-localized QuickDraw name. Other + * names would be possible, see docs for ATSUFindFontName for a + * selection. The MacOSX font selector seems to use the localized + * family name given by ATSUFindFontName(kFontFamilyName), but that API + * doesn't give us a name at all for some fonts. * * Results: - * An OS error code, noErr on success. name is filled with the - * resulting name. + * An OS error code, noErr on success. name is filled with the + * resulting name. * * Side effects: - * None. + * None. * *------------------------------------------------------------------------- */ static OSStatus GetFontFamilyName( - FMFontFamily fontFamily, /* The font family for which to find the - * name. */ - char * name, int numBytes) /* Filled with the result. */ + FMFontFamily fontFamily, /* The font family for which to find the + * name. */ + char * name, int numBytes) /* Filled with the result. */ { OSStatus err; Str255 nativeName; @@ -2326,13 +2012,9 @@ GetFontFamilyName( nativeName[0] = 0; name[0] = 0; - - err = FMGetFontFamilyName(fontFamily, nativeName); + err = ChkErr(FMGetFontFamilyName, fontFamily, nativeName); if (err != noErr) { -#ifdef TK_MAC_DEBUG_FONTS - fprintf(stderr, "FMGetFontFamilyName(): Error %d\n", (int) err); -#endif - return err; + return err; } /* @@ -2341,21 +2023,10 @@ GetFontFamilyName( */ encoding = kTextEncodingMacRoman; - err = FMGetFontFamilyTextEncoding(fontFamily, &encoding); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "FMGetFontFamilyTextEncoding(): Error %d\n", (int) err); - } -#endif - + ChkErr(FMGetFontFamilyTextEncoding, fontFamily, &encoding); nameencoding = encoding; - err = RevertTextEncodingToScriptInfo(encoding, &nameencoding, NULL, NULL); -#ifdef TK_MAC_DEBUG_FONTS - if (err != noErr) { - fprintf(stderr, "RevertTextEncodingToScriptInfo(): Error %d\n", - (int) err); - } -#endif + ChkErr(RevertTextEncodingToScriptInfo, encoding, &nameencoding, NULL, + NULL); /* * Note: We could use Tcl facilities to do the re-encoding here. We'd @@ -2368,9 +2039,9 @@ GetFontFamilyName( */ cfString = CFStringCreateWithPascalStringNoCopy( - NULL, nativeName, nameencoding, kCFAllocatorNull); + NULL, nativeName, nameencoding, kCFAllocatorNull); CFStringGetCString( - cfString, name, numBytes, kCFStringEncodingUTF8); + cfString, name, numBytes, kCFStringEncodingUTF8); CFRelease(cfString); return noErr; @@ -2381,41 +2052,41 @@ GetFontFamilyName( * * FindFontFamily -- * - * Find the font family with the given name in the global familyList. - * Uses bsearch() for convenient access. Comparision is done - * non-case-sensitively with CompareFontFamilies() which see. + * Find the font family with the given name in the global familyList. + * Uses bsearch() for convenient access. Comparision is done + * non-case-sensitively with CompareFontFamilies() which see. * * Results: * - * MacFontFamily: A pair of family id and the actual name registered for - * the font. + * MacFontFamily: A pair of family id and the actual name registered for + * the font. * * Side effects: * - * None. + * None. * * Assumption: * - * Requires the familyList array to be sorted. + * Requires the familyList array to be sorted. * *------------------------------------------------------------------------- */ static const MacFontFamily * FindFontFamily( - const char * name) /* The family name. Note: Names are compared - * non-case-sensitive. */ + const char * name) /* The family name. Note: Names are compared + * non-case-sensitive. */ { const MacFontFamily key = {name,-1}; if(familyListMaxValid <= 0) { - return NULL; + return NULL; } return bsearch( - &key, - familyList, familyListMaxValid, sizeof(*familyList), - CompareFontFamilies); + &key, + familyList, familyListMaxValid, sizeof(*familyList), + CompareFontFamilies); } /* @@ -2423,15 +2094,15 @@ FindFontFamily( * * EnumFontFamilies -- * - * Create a Tcl list with the registered names in the global familyList. + * Create a Tcl list with the registered names in the global familyList. * * Results: * - * A Tcl list of names. + * A Tcl list of names. * * Side effects: * - * None. + * None. * *------------------------------------------------------------------------- */ @@ -2444,8 +2115,8 @@ EnumFontFamilies(void) tclList = Tcl_NewListObj(0, NULL); for (i=0; i= familyListSize) { - familyListSize += 100; - familyList = (MacFontFamily *) ckrealloc( - (void*) familyList, - familyListSize * sizeof(*familyList)); + familyListSize += 100; + familyList = (MacFontFamily *) ckrealloc( + (void*) familyList, + familyListSize * sizeof(*familyList)); } familyPtr = familyList + familyListNextFree; @@ -2499,18 +2170,18 @@ AddFontFamily( * * SortFontFamilies -- * - * Sort the entries in familyList. Only after calling - * SortFontFamilies(), the new families registered with AddFontFamily() - * are actually available for FindFontFamily(), because FindFontFamily() - * requires the array to be sorted. + * Sort the entries in familyList. Only after calling + * SortFontFamilies(), the new families registered with AddFontFamily() + * are actually available for FindFontFamily(), because FindFontFamily() + * requires the array to be sorted. * * Results: * - * None. + * None. * * Side effects: * - * familyList is sorted and familyListMaxValid is updated. + * familyList is sorted and familyListMaxValid is updated. * *------------------------------------------------------------------------- */ @@ -2519,8 +2190,8 @@ static void SortFontFamilies(void) { if (familyListNextFree > 0) { - qsort( familyList, familyListNextFree, sizeof(*familyList), - CompareFontFamilies); + qsort( familyList, familyListNextFree, sizeof(*familyList), + CompareFontFamilies); } familyListMaxValid = familyListNextFree; } @@ -2530,21 +2201,21 @@ SortFontFamilies(void) * * CompareFontFamilies -- * - * Comparison function used by SortFontFamilies() and FindFontFamily(). + * Comparison function used by SortFontFamilies() and FindFontFamily(). * * Results: * - * Result as required to generate a stable sort order for bsearch() and - * qsort(). The ordering is not case-sensitive as far as - * Tcl_UtfNcasecmp() (which see) can provide that. + * Result as required to generate a stable sort order for bsearch() and + * qsort(). The ordering is not case-sensitive as far as + * Tcl_UtfNcasecmp() (which see) can provide that. * - * Note: It would be faster to compare first the length and the actual - * strings only as a tie-breaker, but than the ordering wouldn't look so - * pretty in [font families] ;-). + * Note: It would be faster to compare first the length and the actual + * strings only as a tie-breaker, but than the ordering wouldn't look so + * pretty in [font families] ;-). * * Side effects: * - * None. + * None. * *------------------------------------------------------------------------- */ @@ -2576,36 +2247,36 @@ CompareFontFamilies( * * AddString -- * - * Helper for AddFontFamily(). Allocates a string in the one-shot - * allocator. + * Helper for AddFontFamily(). Allocates a string in the one-shot + * allocator. * * Results: * - * A duplicated string in the one-shot allocator. + * A duplicated string in the one-shot allocator. * * Side effects: * - * May allocate a new memory block. + * May allocate a new memory block. * *------------------------------------------------------------------------- */ static const char * AddString( - const char * in) /* String to add, zero-terminated. */ + const char * in) /* String to add, zero-terminated. */ { int len; char * result; - + len = strlen(in) +1; if (stringMemory == NULL - || (stringMemory->nextFree+len) > STRING_BLOCK_MAX ) { - StringBlock * newblock = - (StringBlock *) ckalloc(sizeof(StringBlock)); - newblock->next = stringMemory; - newblock->nextFree = 0; - stringMemory = newblock; + || (stringMemory->nextFree+len) > STRING_BLOCK_MAX ) { + StringBlock * newblock = + (StringBlock *) ckalloc(sizeof(StringBlock)); + newblock->next = stringMemory; + newblock->nextFree = 0; + stringMemory = newblock; } result = stringMemory->strings + stringMemory->nextFree; @@ -2621,22 +2292,22 @@ AddString( * * TkMacOSXIsCharacterMissing -- * - * Given a tkFont and a character determine whether the character has - * a glyph defined in the font or not. + * Given a tkFont and a character determine whether the character has + * a glyph defined in the font or not. * * Results: - * Returns a 1 if the character is missing, a 0 if it is not. + * Returns a 1 if the character is missing, a 0 if it is not. * * Side effects: - * None. + * None. * *--------------------------------------------------------------------------- */ int TkMacOSXIsCharacterMissing( - Tk_Font tkfont, /* The font we are looking in. */ - unsigned int searchChar) /* The character we are looking for. */ + Tk_Font tkfont, /* The font we are looking in. */ + unsigned int searchChar) /* The character we are looking for. */ { /* Background: This function is private and only used in * tkMacOSXMenu.c:FindMarkCharacter(). @@ -2656,30 +2327,30 @@ TkMacOSXIsCharacterMissing( * * TkMacOSXInitControlFontStyle -- * - * This procedure sets up the appropriate ControlFontStyleRec - * for a Mac control. + * This procedure sets up the appropriate ControlFontStyleRec + * for a Mac control. * * Results: - * None. + * None. * * Side effects: - * None. + * None. * *---------------------------------------------------------------------- */ void TkMacOSXInitControlFontStyle( - Tk_Font tkfont, /* Tk font object to use for the control. */ - ControlFontStylePtr fsPtr) /* The style object to configure. */ + Tk_Font tkfont, /* Tk font object to use for the control. */ + ControlFontStylePtr fsPtr) /* The style object to configure. */ { const MacFont * fontPtr; fontPtr = (MacFont *) tkfont; fsPtr->flags = - kControlUseFontMask| - kControlUseSizeMask| - kControlUseFaceMask| - kControlUseJustMask; + kControlUseFontMask| + kControlUseSizeMask| + kControlUseFaceMask| + kControlUseJustMask; fsPtr->font = fontPtr->qdFont; fsPtr->size = fontPtr->qdSize; fsPtr->style = fontPtr->qdStyle; @@ -2691,46 +2362,46 @@ TkMacOSXInitControlFontStyle( * * TkMacOSXUseAntialiasedText -- * - * Enables or disables application-wide use of antialiased text (where - * available). Sets up a linked Tcl global variable to allow - * disabling of antialiased text from tcl. - * The possible values for this variable are: + * Enables or disables application-wide use of antialiased text (where + * available). Sets up a linked Tcl global variable to allow + * disabling of antialiased text from tcl. + * The possible values for this variable are: * - * -1 - Use system default as configurable in "System Preferences" -> - * "General". - * 0 - Unconditionally disable antialiasing. - * 1 - Unconditionally enable antialiasing. + * -1 - Use system default as configurable in "System Preferences" -> + * "General". + * 0 - Unconditionally disable antialiasing. + * 1 - Unconditionally enable antialiasing. * * Results: * - * TCL_OK. + * TCL_OK. * * Side effects: * - * None. + * None. * *---------------------------------------------------------------------- */ MODULE_SCOPE int TkMacOSXUseAntialiasedText( - Tcl_Interp * interp, /* The Tcl interpreter to receive the - * variable .*/ - int enable) /* Initial value. */ + Tcl_Interp * interp, /* The Tcl interpreter to receive the + * variable .*/ + int enable) /* Initial value. */ { static Boolean initialized = FALSE; if(!initialized) { - initialized = TRUE; + initialized = TRUE; - if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) { - Tcl_ResetResult(interp); - } - if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext", - (char *) &antialiasedTextEnabled, - TCL_LINK_INT) != TCL_OK) { - Tcl_ResetResult(interp); - } + if (Tcl_CreateNamespace(interp, "::tk::mac", NULL, NULL) == NULL) { + Tcl_ResetResult(interp); + } + if (Tcl_LinkVar(interp, "::tk::mac::antialiasedtext", + (char *) &antialiasedTextEnabled, + TCL_LINK_INT) != TCL_OK) { + Tcl_ResetResult(interp); + } } antialiasedTextEnabled = enable; return TCL_OK; Index: macosx/tkMacOSXFont.h =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXFont.h,v retrieving revision 1.4 diff -u -p -r1.4 tkMacOSXFont.h --- macosx/tkMacOSXFont.h 28 Apr 2006 06:02:48 -0000 1.4 +++ macosx/tkMacOSXFont.h 15 Mar 2007 02:42:12 -0000 @@ -12,8 +12,8 @@ * RCS: @(#) $Id: tkMacOSXFont.h,v 1.4 2006/04/28 06:02:48 das Exp $ */ -#ifndef TKMACOSXFONT_H -#define TKMACOSXFONT_H 1 +#ifndef TKMACOSXFONT_H +#define TKMACOSXFONT_H 1 #include "tkFont.h" @@ -22,93 +22,10 @@ #endif /* - * Switches - */ - -#define TK_MAC_USE_QUARZ 1 - -/* - * Types - */ - -/* - * The following structure represents our Macintosh-specific implementation - * of a font object. - */ - -typedef struct { - TkFont font; /* Stuff used by generic font package. Must - * be first in structure. */ - - /* - * The ATSU view of the font and other text properties. Used for drawing - * and measuring. - */ - - ATSUFontID atsuFontId; /* == FMFont. */ - ATSUTextLayout atsuLayout; /* ATSU layout object, representing the whole - * text that ATSU sees with some option - * bits. */ - ATSUStyle atsuStyle; /* ATSU style object, representing a run of - * text with the same properties. */ - - /* - * The QuickDraw view of the font. Used to configure controls. - */ - - FMFontFamily qdFont; /* == FMFontFamilyId, Carbon replacement for - * QD face numbers. */ - short qdSize; /* Font size in points. */ - short qdStyle; /* QuickDraw style bits. */ -} TkMacOSXFont; - - -#if TK_MAC_USE_QUARZ - -/* - * To use Quarz drawing we need some additional context. FIXME: We would - * have liked to use the similar functions from tkMacOSXDraw.c to do this - * (TkMacOSXSetUpCGContext(), etc), but a) those don't quite work for us - * (e.g. we can't use a simple upside-down coordinate system transformation, - * as we don't want upside-down characters ;-), and b) we don't have the - * necessary context information (MacDrawable), that we need as parameter for - * those functions. So I just cobbled together a limited edition, getting - * the necessary parameters from the current QD GraphPort. - */ - -typedef struct { - CGContextRef cgContext; /* Quarz context. */ - CGrafPtr graphPort; /* QD graph port to which this belongs. - * Needed for releasing cgContext. */ - Rect portRect; /* Cached size of port. */ -} TkMacOSXFontDrawingContext; - -#else /* ! TK_MAC_USE_QUARZ */ - -/* - * Just a dummy, so we don't have to #ifdef the parameter lists of functions - * that use this. - */ - -typedef struct {} DrawingContext; - -#endif /* ? TK_MAC_USE_QUARZ */ - -/* * Function prototypes */ -MODULE_SCOPE void TkMacOSXLayoutSetString(const TkMacOSXFont * fontPtr, - const TkMacOSXFontDrawingContext *drawingContextPtr, - const UniChar * uchars, int ulen); -MODULE_SCOPE void TkMacOSXInitControlFontStyle(Tk_Font tkfont, - ControlFontStylePtr fsPtr); - -#if TK_MAC_USE_QUARZ -MODULE_SCOPE void TkMacOSXQuarzStartDraw( - TkMacOSXFontDrawingContext * contextPtr); -MODULE_SCOPE void TkMacOSXQuarzEndDraw( - TkMacOSXFontDrawingContext * contextPtr); -#endif /* TK_MAC_USE_QUARZ */ +MODULE_SCOPE void TkMacOSXInitControlFontStyle(Tk_Font tkfont, + ControlFontStylePtr fsPtr); -#endif /*TKMACOSXFONT_H*/ +#endif /*TKMACOSXFONT_H*/ Index: macosx/tkMacOSXHLEvents.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXHLEvents.c,v retrieving revision 1.12 diff -u -p -r1.12 tkMacOSXHLEvents.c --- macosx/tkMacOSXHLEvents.c 12 May 2006 18:18:36 -0000 1.12 +++ macosx/tkMacOSXHLEvents.c 15 Mar 2007 02:42:12 -0000 @@ -49,7 +49,7 @@ static OSErr PrefsHandler(const AppleEve static int MissedAnyParameters(const AppleEvent *theEvent); static int ReallyKillMe(Tcl_Event *eventPtr, int flags); -static OSErr FSRefToDString(const FSRef *fsref, Tcl_DString *ds); +static OSStatus FSRefToDString(const FSRef *fsref, Tcl_DString *ds); /* *---------------------------------------------------------------------- @@ -72,10 +72,8 @@ void TkMacOSXInitAppleEvents( Tcl_Interp *interp) /* Interp to handle basic events. */ { - OSErr err; AEEventHandlerUPP OappHandlerUPP, RappHandlerUPP, OdocHandlerUPP, - PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP, - PrefsHandlerUPP; + PrintHandlerUPP, QuitHandlerUPP, ScriptHandlerUPP, PrefsHandlerUPP; static Boolean initialized = FALSE; if (!initialized) { @@ -85,32 +83,32 @@ TkMacOSXInitAppleEvents( * Install event handlers for the core apple events. */ QuitHandlerUPP = NewAEEventHandlerUPP(QuitHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEQuitApplication, QuitHandlerUPP, (long) interp, false); OappHandlerUPP = NewAEEventHandlerUPP(OappHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenApplication, OappHandlerUPP, (long) interp, false); RappHandlerUPP = NewAEEventHandlerUPP(RappHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEReopenApplication, RappHandlerUPP, (long) interp, false); OdocHandlerUPP = NewAEEventHandlerUPP(OdocHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEOpenDocuments, OdocHandlerUPP, (long) interp, false); PrintHandlerUPP = NewAEEventHandlerUPP(PrintHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEPrintDocuments, PrintHandlerUPP, (long) interp, false); PrefsHandlerUPP = NewAEEventHandlerUPP(PrefsHandler); - err = AEInstallEventHandler(kCoreEventClass, kAEShowPreferences, + ChkErr(AEInstallEventHandler, kCoreEventClass, kAEShowPreferences, PrefsHandlerUPP, (long) interp, false); if (interp) { ScriptHandlerUPP = NewAEEventHandlerUPP(ScriptHandler); - err = AEInstallEventHandler(kAEMiscStandards, kAEDoScript, + ChkErr(AEInstallEventHandler, kAEMiscStandards, kAEDoScript, ScriptHandlerUPP, (long) interp, false); } } @@ -142,9 +140,9 @@ TkMacOSXDoHLEvent( /* *---------------------------------------------------------------------- * - * QuitHandler, OappHandler, etc. -- + * QuitHandler -- * - * These are the core Apple event handlers. + * This is the 'quit' core Apple event handler. * * Results: * None. @@ -154,8 +152,9 @@ TkMacOSXDoHLEvent( * *---------------------------------------------------------------------- */ -static OSErr -QuitHandler ( + +OSErr +QuitHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -180,8 +179,24 @@ QuitHandler ( return noErr; } -static OSErr -OappHandler ( +/* + *---------------------------------------------------------------------- + * + * OappHandler -- + * + * This is the 'oapp' core Apple event handler. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +OSErr +OappHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -196,8 +211,24 @@ OappHandler ( return noErr; } -static OSErr -RappHandler ( +/* + *---------------------------------------------------------------------- + * + * RappHandler -- + * + * This is the 'rapp' core Apple event handler. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +OSErr +RappHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -205,18 +236,34 @@ RappHandler ( Tcl_CmdInfo dummy; Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; ProcessSerialNumber thePSN = {0, kCurrentProcess}; - OSStatus status = SetFrontProcess(&thePSN); + OSStatus err = ChkErr(SetFrontProcess, &thePSN); if (interp && Tcl_GetCommandInfo(interp, "::tk::mac::ReopenApplication", &dummy)) { Tcl_GlobalEval(interp, "::tk::mac::ReopenApplication"); } - return status; + return err; } -/* Called when the user selects 'Preferences...' in MacOS X */ -static OSErr -PrefsHandler ( +/* + *---------------------------------------------------------------------- + * + * PrefsHandler -- + * + * This is the 'pref' core Apple event handler. + * Called when the user selects 'Preferences...' in MacOS X + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +OSErr +PrefsHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -231,8 +278,24 @@ PrefsHandler ( return noErr; } -static OSErr -OdocHandler ( +/* + *---------------------------------------------------------------------- + * + * OdocHandler -- + * + * This is the 'odoc' core Apple event handler. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +OSErr +OdocHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -240,7 +303,7 @@ OdocHandler ( Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; FSRef file; - OSErr err; + OSStatus err; DescType type; Size actual; long count; @@ -265,8 +328,8 @@ OdocHandler ( * we just return with no error. */ - err = AEGetParamDesc(event, keyDirectObject, - typeAEList, &fileSpecList); + err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList, + &fileSpecList); if (err != noErr) { return noErr; } @@ -276,7 +339,7 @@ OdocHandler ( return noErr; } - err = AECountItems(&fileSpecList, &count); + err = ChkErr(AECountItems, &fileSpecList, &count); if (err != noErr) { return noErr; } @@ -284,27 +347,44 @@ OdocHandler ( Tcl_DStringInit(&command); Tcl_DStringAppend(&command, "::tk::mac::OpenDocument", -1); for (index = 1; index <= count; index++) { - err = AEGetNthPtr(&fileSpecList, index, typeFSRef, + err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual); if ( err != noErr ) { continue; } - err = FSRefToDString(&file, &pathName); + err = ChkErr(FSRefToDString, &file, &pathName); if (err == noErr) { Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName)); Tcl_DStringFree(&pathName); } } - Tcl_GlobalEval(interp, Tcl_DStringValue(&command)); + Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command), + TCL_EVAL_GLOBAL); Tcl_DStringFree(&command); return noErr; } -static OSErr -PrintHandler ( +/* + *---------------------------------------------------------------------- + * + * PrintHandler -- + * + * This is the 'pdoc' core Apple event handler. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +OSErr +PrintHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) @@ -312,7 +392,7 @@ PrintHandler ( Tcl_Interp *interp = (Tcl_Interp *) handlerRefcon; AEDescList fileSpecList; FSRef file; - OSErr err; + OSStatus err; DescType type; Size actual; long count; @@ -337,18 +417,18 @@ PrintHandler ( * we just return with no error. */ - err = AEGetParamDesc(event, keyDirectObject, - typeAEList, &fileSpecList); + err = ChkErr(AEGetParamDesc, event, keyDirectObject, typeAEList, + &fileSpecList); if (err != noErr) { return noErr; } - err = MissedAnyParameters(event); + err = ChkErr(MissedAnyParameters, event); if (err != noErr) { return noErr; } - err = AECountItems(&fileSpecList, &count); + err = ChkErr(AECountItems, &fileSpecList, &count); if (err != noErr) { return noErr; } @@ -356,20 +436,21 @@ PrintHandler ( Tcl_DStringInit(&command); Tcl_DStringAppend(&command, "::tk::mac::PrintDocument", -1); for (index = 1; index <= count; index++) { - err = AEGetNthPtr(&fileSpecList, index, typeFSRef, - &keyword, &type, (Ptr) &file, sizeof(FSRef), &actual); + err = ChkErr(AEGetNthPtr, &fileSpecList, index, typeFSRef, &keyword, + &type, (Ptr) &file, sizeof(FSRef), &actual); if ( err != noErr ) { continue; } - err = FSRefToDString(&file, &pathName); + err = ChkErr(FSRefToDString, &file, &pathName); if (err == noErr) { Tcl_DStringAppendElement(&command, Tcl_DStringValue(&pathName)); Tcl_DStringFree(&pathName); } } - Tcl_GlobalEval(interp, Tcl_DStringValue(&command)); + Tcl_EvalEx(interp, Tcl_DStringValue(&command), Tcl_DStringLength(&command), + TCL_EVAL_GLOBAL); Tcl_DStringFree(&command); return noErr; @@ -391,13 +472,13 @@ PrintHandler ( *---------------------------------------------------------------------- */ -static OSErr -ScriptHandler ( +OSErr +ScriptHandler( const AppleEvent * event, AppleEvent * reply, long handlerRefcon) { - OSErr theErr; + OSStatus theErr; AEDescList theDesc; int tclErr = -1; Tcl_Interp *interp; @@ -411,7 +492,8 @@ ScriptHandler ( theErr = AEGetParamDesc(event, keyDirectObject, typeWildCard, &theDesc); if (theErr != noErr) { - sprintf(errString, "AEDoScriptHandler: GetParamDesc error %d", theErr); + sprintf(errString, "AEDoScriptHandler: GetParamDesc error %ld", + theErr); theErr = AEPutParamPtr(reply, keyErrorString, typeChar, errString, strlen(errString)); } else if (MissedAnyParameters(event)) { @@ -443,7 +525,8 @@ ScriptHandler ( } Tcl_ExternalToUtfDString(NULL, data, size, &encodedText); - tclErr = Tcl_GlobalEval(interp, Tcl_DStringValue(&encodedText)); + tclErr = Tcl_EvalEx(interp, Tcl_DStringValue(&encodedText), + Tcl_DStringLength(&encodedText), TCL_EVAL_GLOBAL); Tcl_DStringFree(&encodedText); } else if (theDesc.descriptorType == (DescType)typeAlias) { Boolean dummy; @@ -554,16 +637,16 @@ ReallyKillMe( *---------------------------------------------------------------------- */ -static int +int MissedAnyParameters( const AppleEvent *theEvent) { DescType returnedType; Size actualSize; - OSErr err; + OSStatus err; - err = AEGetAttributePtr(theEvent, keyMissedKeywordAttr, typeWildCard, - &returnedType, NULL, 0, &actualSize); + err = ChkErr(AEGetAttributePtr, theEvent, keyMissedKeywordAttr, + typeWildCard, &returnedType, NULL, 0, &actualSize); return (err != errAEDescNotFound); } @@ -584,15 +667,15 @@ MissedAnyParameters( *---------------------------------------------------------------------- */ -static OSErr +OSStatus FSRefToDString( const FSRef *fsref, Tcl_DString *ds) { UInt8 fileName[PATH_MAX+1]; - OSErr err; + OSStatus err; - err = FSRefMakePath(fsref, fileName, sizeof(fileName)); + err = ChkErr(FSRefMakePath, fsref, fileName, sizeof(fileName)); if (err == noErr) { Tcl_ExternalToUtfDString(NULL, (char*) fileName, -1, ds); } Index: macosx/tkMacOSXInit.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXInit.c,v retrieving revision 1.25 diff -u -p -r1.25 tkMacOSXInit.c --- macosx/tkMacOSXInit.c 24 Nov 2006 19:03:50 -0000 1.25 +++ macosx/tkMacOSXInit.c 15 Mar 2007 02:42:12 -0000 @@ -1,4 +1,4 @@ -/* +/* * tkMacOSXInit.c -- * * This file contains Mac OS X -specific interpreter initialization @@ -6,7 +6,7 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2006 Daniel A. Steffen + * Copyright (c) 2005-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -46,7 +46,7 @@ typedef struct Map { CFStringEncoding numKey; - char *strKey; + const char *strKey; } Map; static Map scriptMap[] = { @@ -93,6 +93,7 @@ Tcl_Encoding TkMacOSXCarbonEncoding = NU */ static char scriptPath[PATH_MAX + 1] = ""; + /* *---------------------------------------------------------------------- * @@ -116,56 +117,36 @@ TkpInit(interp) Tcl_Interp *interp; { static char tkLibPath[PATH_MAX + 1]; - static int tkMacOSXInitialized = false; + static int tkMacOSXInitialized = 0; Tk_MacOSXSetupTkNotifier(); - /* + /* * Since it is possible for TkInit to be called multiple times - * and we don't want to do the initialization multiple times + * and we don't want to do the following initialization multiple times * we protect against doing it more than once. */ - if (tkMacOSXInitialized == false) { + if (!tkMacOSXInitialized) { + int bundledExecutable = 0; + CFBundleRef bundleRef; + CFURLRef bundleUrl = NULL; CFStringEncoding encoding; - char *encodingStr = NULL; + const char *encodingStr = NULL; int i; - tkMacOSXInitialized = true; - - TkMacOSXInitAppleEvents(interp); - TkMacOSXInitCarbonEvents(interp); - TkMacOSXInitMenus(interp); - TkMacOSXUseAntialiasedText(interp, -1); - TkMacOSXInitCGDrawing(interp, TRUE, 0); - TkMacOSXInitKeyboard(interp); - - encoding = CFStringGetSystemEncoding(); - - for (i = 0; scriptMap[i].strKey != NULL; i++) { - if (scriptMap[i].numKey == encoding) { - encodingStr = scriptMap[i].strKey; - break; - } - } - if (encodingStr == NULL) { - encodingStr = "macRoman"; - } - - TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, encodingStr); - if (TkMacOSXCarbonEncoding == NULL) { - TkMacOSXCarbonEncoding = Tcl_GetEncoding (NULL, NULL); - } + tkMacOSXInitialized = 1; /* - * When Tk is in a framework, force tcl_findLibrary to look in the + * When Tk is in a framework, force tcl_findLibrary to look in the * framework scripts directory. * FIXME: Should we come up with a more generic way of doing this? */ #ifdef TK_FRAMEWORK if (Tcl_MacOSXOpenVersionedBundleResources(interp, - "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, tkLibPath) != TCL_OK) + "com.tcltk.tklibrary", TK_FRAMEWORK_VERSION, 1, PATH_MAX, + tkLibPath) != TCL_OK) #endif { /* Tk.framework not found, check if resource file is open */ @@ -181,12 +162,13 @@ TkpInit(interp) char fileName[L_tmpnam + 15]; uint32_t i, n; - /* Get resource data from __tk_rsrc section of tk library file */ + /* Get resource data from __tk_rsrc section of tk dylib file*/ n = _dyld_image_count(); for (i = 0; i < n; i++) { image = _dyld_get_image_header(i); if (image) { - data = getsectdatafromheader(image, SEG_TEXT, "__tk_rsrc", &size); + data = getsectdatafromheader(image, SEG_TEXT, + "__tk_rsrc", (void*)&size); if (data) { data += _dyld_get_image_vmaddr_slide(i); break; @@ -194,7 +176,6 @@ TkpInit(interp) } } while (data) { - OSStatus err; FSRef ref; SInt16 refNum; @@ -208,12 +189,10 @@ TkpInit(interp) if (fd == -1) break; fcntl(fd, F_SETFD, FD_CLOEXEC); if (write(fd, data, size) == -1) break; - err = FSPathMakeRef((unsigned char*)fileName, &ref, NULL); - if (err != noErr) break; - err = FSOpenResourceFile(&ref, 0, NULL, fsRdPerm, &refNum); -#ifdef TK_MAC_DEBUG - if (err != noErr) fprintf(stderr,"FSOpenResourceFile error %ld\n",err); -#endif + if(ChkErr(FSPathMakeRef, (unsigned char*)fileName, &ref, + NULL) != noErr) break; + ChkErr(FSOpenResourceFile, &ref, 0, NULL, fsRdPerm, + &refNum); break; } if (fd != -1) { @@ -224,8 +203,102 @@ TkpInit(interp) } } + /* + * If we are loaded into an executable that is not a bundled + * application, the window server does not let us come to the + * foreground. For such an executable, notify the window server that + * we are now a full GUI application. + */ + + /* Check whether we are a bundled executable: */ + bundleRef = CFBundleGetMainBundle(); + if (bundleRef) { + bundleUrl = CFBundleCopyBundleURL(bundleRef); + } + if (bundleUrl) { + /* + * A bundled executable is two levels down from its main bundle + * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas an + * unbundled executable's main bundle directory is just the + * directory containing the executable. So to check whether we are + * bundled, we delete the last three path components of the + * executable's url and compare the resulting url with the main + * bundle url. + */ + int j = 3; + CFURLRef url = CFBundleCopyExecutableURL(bundleRef); + while (url && j--) { + CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, + url); + CFRelease(url); + url = parent; + } + if (url) { + bundledExecutable = CFEqual(bundleUrl, url); + CFRelease(url); + } + CFRelease(bundleUrl); + } + + /* If we are not a bundled executable, notify the window server that + * we are a foregroundable app. */ + if (!bundledExecutable) { + OSStatus err = procNotFound; + ProcessSerialNumber psn = { 0, kCurrentProcess }; + +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 + if (1 +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1030 + && TransformProcessType != NULL +#endif + ) { + err = ChkErr(TransformProcessType, &psn, + kProcessTransformToForegroundApplication); + } +#endif +#if MAC_OSX_TK_USE_CPS_SPI + if (err != noErr) { + /* + * When building or running on 10.2 or when the above fails, + * attempt to use undocumented CPS SPI to notify the window + * server. Load the SPI symbol dynamically, so that we don't + * break if it ever disappears or changes its name. + */ + TkMacOSXInitNamedSymbol(CoreGraphics, OSStatus, + CPSEnableForegroundOperation, ProcessSerialNumberPtr); + if (CPSEnableForegroundOperation) { + ChkErr(CPSEnableForegroundOperation, &psn); + } + } +#endif /* MAC_OSX_TK_USE_CPS_SPI */ + } + + TkMacOSXInitAppleEvents(interp); + TkMacOSXInitCarbonEvents(interp); + TkMacOSXInitMenus(interp); + TkMacOSXUseAntialiasedText(interp, -1); + TkMacOSXInitCGDrawing(interp, TRUE, 0); + TkMacOSXInitKeyboard(interp); + + encoding = CFStringGetSystemEncoding(); + + for (i = 0; scriptMap[i].strKey != NULL; i++) { + if (scriptMap[i].numKey == encoding) { + encodingStr = scriptMap[i].strKey; + break; + } + } + if (encodingStr == NULL) { + encodingStr = "macRoman"; + } + + TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, encodingStr); + if (TkMacOSXCarbonEncoding == NULL) { + TkMacOSXCarbonEncoding = Tcl_GetEncoding(NULL, NULL); + } + /* REMOVE ME: Close stdin & stdout for remote debugging otherwise we - * will fight with gdb for stdin & stdout + * will fight with gdb for stdin & stdout */ if (getenv ("XCNOSTDIN") != NULL) { @@ -251,7 +324,7 @@ TkpInit(interp) * and tcl_interactive hasn't been set already. */ if (Tcl_GetStartupScript(NULL) == NULL) { - CONST char *intvar = + const char *intvar = Tcl_GetVar(interp, "tcl_interactive", TCL_GLOBAL_ONLY); if (intvar == NULL) { Tcl_SetVar(interp, "tcl_interactive", "1", @@ -263,73 +336,6 @@ TkpInit(interp) } } } - - /* - * If we are loaded into an executable that is not a bundled - * application, the window server does not let us come to the - * foreground. For such an executable, notify the window server that - * we are now a full GUI application. - */ - { - /* Check whether we are a bundled executable: */ - int bundledExecutable = 0; - CFBundleRef bundleRef = CFBundleGetMainBundle(); - CFURLRef bundleUrl = NULL; - if (bundleRef) { - bundleUrl = CFBundleCopyBundleURL(bundleRef); - } - if (bundleUrl) { - /* - * A bundled executable is two levels down from its main bundle - * directory (e.g. Wish.app/Contents/MacOS/Wish), whereas - * an unbundled executable's main bundle directory is just - * the directory containing the executable. - * So to check whether we are bundled, we delete the last three - * path components of the executable's url and compare the - * resulting url with the main bundle url. - */ - int j = 3; - CFURLRef url = CFBundleCopyExecutableURL(bundleRef); - while (url && j--) { - CFURLRef parent = CFURLCreateCopyDeletingLastPathComponent(NULL, url); - CFRelease(url); - url = parent; - } - if (url) { - bundledExecutable = CFEqual(bundleUrl, url); - CFRelease(url); - } - CFRelease(bundleUrl); - } - - /* If we are not a bundled executable, notify the window server that - * we are a foregroundable app. */ - if (!bundledExecutable) { - OSStatus err = procNotFound; - ProcessSerialNumber psn = { 0, kCurrentProcess }; -#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1030 - if (TransformProcessType != NULL) { - err = TransformProcessType(&psn, - kProcessTransformToForegroundApplication); - } -#endif -#if MAC_OSX_TK_USE_CPS_SPI - if (err != noErr) { - /* - * When building or running on 10.2 or when the above fails, - * attempt to use undocumented CPS SPI to notify the window - * server. Load the SPI symbol dynamically, so that we don't - * break if it ever disappears or changes its name. - */ - TkMacOSXInitNamedSymbol(CoreGraphics, OSErr, - CPSEnableForegroundOperation, ProcessSerialNumberPtr); - if (CPSEnableForegroundOperation) { - CPSEnableForegroundOperation(&psn); - } - } -#endif /* MAC_OSX_TK_USE_CPS_SPI */ - } - } } if (tkLibPath[0] != '\0') { @@ -367,7 +373,7 @@ TkpGetAppName(interp, namePtr) Tcl_Interp *interp; Tcl_DString *namePtr; /* A previously initialized Tcl_DString. */ { - CONST char *p, *name; + const char *p, *name; name = Tcl_GetVar(interp, "argv0", TCL_GLOBAL_ONLY); if ((name == NULL) || (*name == 0)) { @@ -443,9 +449,9 @@ TkMacOSXDefaultStartupScript(void) if (bundleRef != NULL) { CFURLRef appMainURL; - appMainURL = CFBundleCopyResourceURL(bundleRef, - CFSTR("AppMain"), - CFSTR("tcl"), + appMainURL = CFBundleCopyResourceURL(bundleRef, + CFSTR("AppMain"), + CFSTR("tcl"), CFSTR("Scripts")); if (appMainURL != NULL) { @@ -458,7 +464,7 @@ TkMacOSXDefaultStartupScript(void) scriptFldrURL = CFURLCreateCopyDeletingLastPathComponent( NULL, appMainURL); if (scriptFldrURL != NULL) { - CFURLGetFileSystemRepresentation(scriptFldrURL, + CFURLGetFileSystemRepresentation(scriptFldrURL, true, (unsigned char*) scriptPath, PATH_MAX); CFRelease(scriptFldrURL); } @@ -479,7 +485,7 @@ TkMacOSXDefaultStartupScript(void) * available on all OS versions. * If module is non-NULL and not the empty string, use twolevel * namespace lookup. - * + * * Results: * Address of given symbol or NULL if unavailable. * Index: macosx/tkMacOSXInt.h =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXInt.h,v retrieving revision 1.20 diff -u -p -r1.20 tkMacOSXInt.h --- macosx/tkMacOSXInt.h 31 Oct 2006 22:33:34 -0000 1.20 +++ macosx/tkMacOSXInt.h 15 Mar 2007 02:42:12 -0000 @@ -5,6 +5,7 @@ * * Copyright (c) 1995-1997 Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. + * Copyright (c) 2005-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -23,6 +24,64 @@ #include #undef TextStyle +/* Define constants only available on Mac OS X 10.3 or later */ +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 + #define kEventAppAvailableWindowBoundsChanged 110 + #define kEventParamTransactionID 'trns' + #define kEventParamWindowPartCode 'wpar' + #define typeWindowPartCode 'wpar' + #define kMenuAttrDoNotUseUserCommandKeys (1 << 7) + #define kSimpleWindowClass 18 + #define kWindowDoesNotCycleAttribute (1L << 15) + #define kWindowAsyncDragAttribute (1L << 23) + #define kThemeBrushAlternatePrimaryHighlightColor -5 + #define kThemeResizeUpCursor 19 + #define kThemeResizeDownCursor 19 + #define kThemeResizeUpDownCursor 19 + #define kThemePoofCursor 19 + #define kThemeBackgroundMetal 6 + #define kThemeIncDecButtonSmall 21 + #define kThemeIncDecButtonMini 22 + #define kAppearancePartUpButton 20 + #define kAppearancePartDownButton 21 + #define kAppearancePartPageUpArea 22 + #define kAppearancePartPageDownArea 23 + #define kAppearancePartIndicator 129 +#endif +/* Define constants only available on Mac OS X 10.4 or later */ +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1040 + #define kWindowNoTitleBarAttribute (1L << 9) + #define kWindowMetalNoContentSeparatorAttribute (1L << 11) + #define kThemeDisclosureTriangle 6 + #define kThemeBrushListViewOddRowBackground 56 + #define kThemeBrushListViewEvenRowBackground 57 + #define kThemeBrushListViewColumnDivider 58 + #define kThemeMetricScrollBarMinThumbHeight 132 + #define kThemeMetricSmallScrollBarMinThumbHeight 134 + #define kThemeScrollBarMedium kThemeMediumScrollBar + #define kThemeScrollBarSmall kThemeSmallScrollBar + #ifdef __BIG_ENDIAN__ + #define kCGBitmapByteOrder32Host (4 << 12) + #else + #define kCGBitmapByteOrder32Host (2 << 12) + #endif + #endif +/* Define constants only available on Mac OS X 10.5 or later */ +#if MAC_OS_X_VERSION_MAX_ALLOWED < 1050 + #define kWindowUnifiedTitleAndToolbarAttribute (1L << 7) + #define kWindowTexturedSquareCornersAttribute (1L << 10) +#endif +/* Runtime HIToolbox version checking */ +#ifndef kHIToolboxVersionNumber10_3 + #define kHIToolboxVersionNumber10_3 (145) +#endif +#ifndef kHIToolboxVersionNumber10_4 + #define kHIToolboxVersionNumber10_4 (219) +#endif +#ifndef kHIToolboxVersionNumber10_5 + #define kHIToolboxVersionNumber10_5 (291) +#endif + /* * Include platform specific public interfaces. */ @@ -34,11 +93,13 @@ struct TkWindowPrivate { TkWindow *winPtr; /* Ptr to tk window or NULL if Pixmap */ CGrafPtr grafPtr; + CGContextRef context; ControlRef rootControl; int xOff; /* X offset from toplevel window */ int yOff; /* Y offset from toplevel window */ RgnHandle clipRgn; /* Visible region of window */ RgnHandle aboveClipRgn; /* Visible region of window & it's children */ + RgnHandle drawRgn; /* Clipped drawing region */ int referenceCount; /* Don't delete toplevel until children are * gone. */ struct TkWindowPrivate *toplevel; /* Pointer to the toplevel @@ -62,10 +123,11 @@ typedef struct TkMacOSXWindowList { * Defines use for the flags field of the MacDrawable data structure. */ -#define TK_SCROLLBAR_GROW 1 -#define TK_CLIP_INVALID 2 -#define TK_HOST_EXISTS 4 -#define TK_DRAWN_UNDER_MENU 8 +#define TK_SCROLLBAR_GROW 0x01 +#define TK_CLIP_INVALID 0x02 +#define TK_HOST_EXISTS 0x04 +#define TK_DRAWN_UNDER_MENU 0x08 +#define TK_CLIPPED_DRAW 0x10 /* * I am reserving TK_EMBEDDED = 0x100 in the MacDrawable flags @@ -95,6 +157,18 @@ typedef struct { MODULE_SCOPE TkMacOSXEmbedHandler *tkMacOSXEmbedHandler; /* + * Structure encapsulating current drawing environment. + */ + +typedef struct TkMacOSXDrawingContext { + CGContextRef context; + CGrafPtr port, savePort; + ThemeDrawingState saveState; + Rect portBounds; + Boolean portChanged; +} TkMacOSXDrawingContext; + +/* * Defines used for TkMacOSXInvalidateWindow */ @@ -123,11 +197,47 @@ MODULE_SCOPE TkMacOSXEmbedHandler *tkMac #define TK_LAYOUT_WITH_BASE_CHUNKS 1 #define TK_DRAW_IN_CONTEXT 1 + +#ifdef TK_MAC_DEBUG +/* + * Macro to do debug message output. + */ +#define TkMacOSXDbgMsg(m, ...) do { \ + fprintf(stderr, "%s:%d: %s(): " m "\n", __FILE__, __LINE__, \ + __func__, ##__VA_ARGS__); \ + } while (0) +/* + * Macro to do very common check for noErr return from given API and output + * debug message in case of failure. + */ +#define ChkErr(f, ...) ({ \ + OSStatus err = f(__VA_ARGS__); \ + if (err != noErr) { \ + TkMacOSXDbgMsg("%s failed: %ld", #f, err); \ + } \ + err;}) +/* + * Macro to check emptyness of shared temp regions before use in debug builds. + */ +#define TkMacOSXCheckTmpRgnEmpty(r) do { \ + if (!EmptyRgn(tkMacOSXtmpRgn##r)) { \ + Tcl_Panic("tkMacOSXtmpRgn%s nonempty", #r); \ + } \ + } while(0) +#else /* TK_MAC_DEBUG */ +#define TkMacOSXDbgMsg(m, ...) +#define ChkErr(f, ...) ({f(__VA_ARGS__);}) +#define TkMacOSXCheckTmpRgnEmpty(r) +#endif /* TK_MAC_DEBUG */ + /* * Variables shared among various Mac Tk modules but are not * exported to the outside world. */ +MODULE_SCOPE RgnHandle tkMacOSXtmpRgn1; +MODULE_SCOPE RgnHandle tkMacOSXtmpRgn2; + /* * Globals shared among Macintosh Tk */ @@ -136,13 +246,6 @@ MODULE_SCOPE MenuHandle tkCurrentAppleMe MODULE_SCOPE MenuHandle tkAppleMenu; /* Handle to default Apple Menu */ MODULE_SCOPE MenuHandle tkFileMenu; /* Handles to menus */ MODULE_SCOPE MenuHandle tkEditMenu; /* Handles to menus */ -MODULE_SCOPE RgnHandle tkMenuCascadeRgn;/* A region to clip with. */ -MODULE_SCOPE int tkUseMenuCascadeRgn; /* If this is 1, clipping code - * should intersect tkMenuCascadeRgn - * before drawing occurs. - * tkMenuCascadeRgn will only - * be valid when the value of this - * variable is 1. */ MODULE_SCOPE int tkPictureIsOpen; /* If this is 1, we are drawing to a * picture The clipping should then be * done relative to the bounds of the @@ -159,24 +262,56 @@ MODULE_SCOPE TkMacOSXWindowList *tkMacOS MODULE_SCOPE Tcl_Encoding TkMacOSXCarbonEncoding; +#if 0 +MODULE_SCOPE int XSetClipRectangles(Display *d, GC gc, int clip_x_origin, + int clip_y_origin, XRectangle* rectangles, int n, int ordering); +#endif +MODULE_SCOPE void TkpClipDrawableToRect(Display *display, Drawable d, int x, + int y, int width, int height); + MODULE_SCOPE void TkMacOSXDisplayChanged(Display *display); +MODULE_SCOPE void TkMacOSXInitScrollbarMetrics(void); MODULE_SCOPE int TkMacOSXUseAntialiasedText(Tcl_Interp *interp, int enable); MODULE_SCOPE void TkMacOSXInitCarbonEvents(Tcl_Interp *interp); -MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable, int antiAlias); +MODULE_SCOPE int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable, + int antiAlias); MODULE_SCOPE void TkMacOSXInitKeyboard(Tcl_Interp *interp); MODULE_SCOPE void TkMacOSXDefaultStartupScript(void); -MODULE_SCOPE int TkMacOSXGenerateFocusEvent( Window window, int activeFlag); +MODULE_SCOPE int TkMacOSXGenerateFocusEvent(Window window, int activeFlag); +MODULE_SCOPE int TkMacOSXGenerateMenuSelectEvent(MenuRef menu, + MenuItemIndex index); +MODULE_SCOPE void TkMacOSXClearActiveMenu(MenuRef menu); MODULE_SCOPE WindowClass TkMacOSXWindowClass(TkWindow *winPtr); MODULE_SCOPE int TkMacOSXIsWindowZoomed(TkWindow *winPtr); MODULE_SCOPE int TkGenerateButtonEventForXPointer(Window window); +MODULE_SCOPE EventModifiers TkMacOSXModifierState(void); MODULE_SCOPE int TkMacOSXCompareColors(unsigned long c1, unsigned long c2); - -MODULE_SCOPE void* TkMacOSXGetNamedSymbol(const char* module, const char* symbol); -/* Macro to abstract common use of TkMacOSXGetNamedSymbol to initialize named symbols */ +MODULE_SCOPE int TkMacOSXSetupDrawingContext(Drawable d, GC gc, int useCG, + TkMacOSXDrawingContext *dc); +MODULE_SCOPE void TkMacOSXRestoreDrawingContext(TkMacOSXDrawingContext *dc); +MODULE_SCOPE void TkMacOSXSetColorInPort(unsigned long pixel, int fg, + PixPatHandle penPat); +MODULE_SCOPE void TkMacOSXSetColorInContext(unsigned long pixel, + CGContextRef context); +MODULE_SCOPE int TkMacOSXRunTclEventLoop(void); +MODULE_SCOPE OSStatus TkMacOSXStartTclEventLoopCarbonTimer(void); +MODULE_SCOPE OSStatus TkMacOSXStopTclEventLoopCarbonTimer(void); +MODULE_SCOPE void TkMacOSXTrackingLoop(int tracking); +MODULE_SCOPE OSStatus TkMacOSXReceiveAndDispatchEvent(void); +MODULE_SCOPE void TkMacOSXInstallWindowCarbonEventHandler(Tcl_Interp *interp, + WindowRef window); +MODULE_SCOPE int TkMacOSXMakeFullscreen(TkWindow *winPtr, WindowRef window, + int fullscreen, Tcl_Interp *interp); +MODULE_SCOPE void TkMacOSXEnterExitFullscreen(TkWindow *winPtr, int active); + +MODULE_SCOPE void* TkMacOSXGetNamedSymbol(const char* module, + const char* symbol); +/* Macro abstracting use of TkMacOSXGetNamedSymbol to init named symbols */ #define TkMacOSXInitNamedSymbol(module, ret, symbol, ...) \ static ret (* symbol)(__VA_ARGS__) = (void*)(-1L); \ if (symbol == (void*)(-1L)) { \ - symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), STRINGIFY(_##symbol));\ + symbol = TkMacOSXGetNamedSymbol(STRINGIFY(module), \ + STRINGIFY(_##symbol)); \ } #include "tkIntPlatDecls.h" Index: macosx/tkMacOSXKeyEvent.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXKeyEvent.c,v retrieving revision 1.18 diff -u -p -r1.18 tkMacOSXKeyEvent.c --- macosx/tkMacOSXKeyEvent.c 11 Sep 2006 14:41:04 -0000 1.18 +++ macosx/tkMacOSXKeyEvent.c 15 Mar 2007 02:42:13 -0000 @@ -61,7 +61,7 @@ #include "tkMacOSXEvent.h" /* -#ifdef TK_MAC_DEBUG +#ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_KEYBOARD #endif */ @@ -71,15 +71,15 @@ typedef struct { int global_x, global_y; int local_x, local_y; unsigned int state; - unsigned char ch; UInt32 keyCode; UInt32 keyModifiers; UInt32 message; + unsigned char ch; } KeyEventData; -static Tk_Window gGrabWinPtr = NULL; /* Current grab window, +static Tk_Window grabWinPtr = NULL; /* Current grab window, * NULL if no grab. */ -static Tk_Window gKeyboardWinPtr = NULL; /* Current keyboard grab window. */ +static Tk_Window keyboardGrabWinPtr = NULL; /* Current keyboard grab window. */ static UInt32 deadKeyStateUp = 0; /* The deadkey state for the current * sequence of keyup events or 0 if @@ -150,7 +150,7 @@ TkMacOSXProcessKeyboardEvent( static UInt32 savedKeyCode = 0; static UInt32 savedModifiers = 0; static UniChar savedChar = 0; - OSStatus status; + OSStatus err; KeyEventData keyEventData; MenuRef menuRef; MenuItemIndex menuItemIndex; @@ -203,39 +203,25 @@ TkMacOSXProcessKeyboardEvent( } } - status = GetEventParameter(eventPtr->eventRef, - kEventParamKeyMacCharCodes, - typeChar, NULL, - sizeof(keyEventData.ch), NULL, - &keyEventData.ch); - if (status != noErr) { -#ifdef TK_MAC_DEBUG - fprintf (stderr, "Failed to retrieve KeyMacCharCodes\n"); -#endif + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamKeyMacCharCodes, typeChar, NULL, + sizeof(keyEventData.ch), NULL, &keyEventData.ch); + if (err != noErr) { statusPtr->err = 1; return false; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamKeyCode, - typeUInt32, NULL, - sizeof(keyEventData.keyCode), NULL, - &keyEventData.keyCode); - if (status != noErr) { -#ifdef TK_MAC_DEBUG - fprintf (stderr, "Failed to retrieve KeyCode\n"); -#endif + err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamKeyCode, + typeUInt32, NULL, sizeof(keyEventData.keyCode), NULL, + &keyEventData.keyCode); + if (err != noErr) { statusPtr->err = 1; return false; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamKeyModifiers, - typeUInt32, NULL, - sizeof(keyEventData.keyModifiers), NULL, - &keyEventData.keyModifiers); - if (status != noErr) { -#ifdef TK_MAC_DEBUG - fprintf (stderr, "Failed to retrieve KeyModifiers\n"); -#endif + err = ChkErr(GetEventParameter, eventPtr->eventRef, + kEventParamKeyModifiers, typeUInt32, NULL, + sizeof(keyEventData.keyModifiers), NULL, + &keyEventData.keyModifiers); + if (err != noErr) { statusPtr->err = 1; return false; } @@ -412,11 +398,7 @@ GenerateKeyEvent( Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); break; default: -#ifdef TK_MAC_DEBUG - fprintf (stderr, - "GenerateKeyEvent(): Invalid parameter eKind %d\n", - (int) eKind); -#endif + TkMacOSXDbgMsg("Invalid parameter eKind %ld", eKind); return -1; } } @@ -522,18 +504,14 @@ InitKeyEvent( dispPtr = TkGetDisplayList(); tkwin = Tk_IdToWindow(dispPtr->display, window); - if (tkwin == NULL) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"tkwin == NULL, %d\n", __LINE__); -#endif + if (!tkwin) { + TkMacOSXDbgMsg("tkwin == NULL"); return -1; } tkwin = (Tk_Window) ((TkWindow *) tkwin)->dispPtr->focusPtr; - if (tkwin == NULL) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"tkwin == NULL, %d\n", __LINE__); -#endif + if (!tkwin) { + TkMacOSXDbgMsg("tkwin == NULL"); return -1; } @@ -564,21 +542,6 @@ InitKeyEvent( /* - * If we have old headers, we need to define these types and constants - * ourself. We use preprocessor macros instead of enums and typedefs, - * because macros work even in case of version misunderstandings, while - * duplicate enums and typedefs would give errrors. - */ - -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1020 -#define KeyboardLayoutRef Ptr -#define KeyboardLayoutPropertyTag UInt32 -#define kKLKCHRData 0 -#define kKLuchrData 1 -#define kKLIdentifier 2 -#endif - -/* *---------------------------------------------------------------------- * * GetKeyboardLayout -- @@ -601,141 +564,79 @@ InitKeyEvent( */ static int -GetKeyboardLayout (Ptr * resourcePtr, TextEncoding * encodingPtr) +GetKeyboardLayout(Ptr * resourcePtr, TextEncoding * encodingPtr) { static KeyboardLayoutRef lastLayout = NULL; static SInt32 lastLayoutId; static TextEncoding lastEncoding = kTextEncodingMacRoman; static Ptr uchr = NULL; static Ptr KCHR = NULL; - static Handle handle = NULL; - int hasLayoutChanged = false; KeyboardLayoutRef currentLayout = NULL; SInt32 currentLayoutId = 0; ScriptCode currentKeyScript; - /* - * Several code branches need this information. - */ - currentKeyScript = GetScriptManagerVariable(smKeyScript); - TkMacOSXInitNamedSymbol(HIToolbox, OSStatus, KLGetCurrentKeyboardLayout, - KeyboardLayoutRef*); - TkMacOSXInitNamedSymbol(HIToolbox, OSStatus, KLGetKeyboardLayoutProperty, - KeyboardLayoutRef, KeyboardLayoutPropertyTag, const void**); - if (KLGetCurrentKeyboardLayout && KLGetKeyboardLayoutProperty) { - - /* - * Use the Keyboard Layout Services (these functions only exist since - * 10.2). - */ - - KLGetCurrentKeyboardLayout(¤tLayout); - - if (currentLayout != NULL) { - - /* - * The layout pointer could in theory be the same for different - * layouts, only the id gives us the information that the - * keyboard has actually changed. OTOH the layout object can - * also change and it could still be the same layoutid. - */ - - KLGetKeyboardLayoutProperty(currentLayout, kKLIdentifier, - (const void**)¤tLayoutId); - - if ((lastLayout != currentLayout) - || (lastLayoutId != currentLayoutId)) { + /* + * Use the Keyboard Layout Services. + */ -#ifdef TK_MAC_DEBUG_KEYBOARD - fprintf (stderr, "GetKeyboardLayout(): Use KLS\n"); -#endif + KLGetCurrentKeyboardLayout(¤tLayout); - hasLayoutChanged = true; + if (currentLayout != NULL) { - /* - * Reinitialize all relevant variables. - */ - - lastLayout = currentLayout; - lastLayoutId = currentLayoutId; - uchr = NULL; - KCHR = NULL; - - if ((KLGetKeyboardLayoutProperty(currentLayout, - kKLuchrData, (const void**)&uchr) - == noErr) - && (uchr != NULL)) { - /* done */ - } else if ((KLGetKeyboardLayoutProperty(currentLayout, - kKLKCHRData, (const void**)&KCHR) - == noErr) - && (KCHR != NULL)) { - /* done */ - } - } - } + /* + * The layout pointer could in theory be the same for different + * layouts, only the id gives us the information that the + * keyboard has actually changed. OTOH the layout object can + * also change and it could still be the same layoutid. + */ - } else { + KLGetKeyboardLayoutProperty(currentLayout, kKLIdentifier, + (const void**)¤tLayoutId); - /* - * Use the classic approach as shown in Apple code samples, loading - * the keyboard resources directly. This is broken for 10.3 and - * possibly already in 10.2. - */ - - currentLayoutId = GetScriptVariable(currentKeyScript,smScriptKeys); - - if ((lastLayout == NULL) || (lastLayoutId != currentLayoutId)) { + if ((lastLayout != currentLayout) + || (lastLayoutId != currentLayoutId)) { #ifdef TK_MAC_DEBUG_KEYBOARD - fprintf (stderr, "GetKeyboardLayout(): Use GetResource()\n"); + TkMacOSXDbgMsg("Use KLS"); #endif - hasLayoutChanged = true; - - /* - * Reinitialize all relevant variables. - */ - - lastLayout = (KeyboardLayoutRef)-1; - lastLayoutId = currentLayoutId; - uchr = NULL; - KCHR = NULL; - - /* - * Get the new layout resource in the classic way. - */ + hasLayoutChanged = true; - if (handle != NULL) { - HUnlock(handle); - } - - if ((handle = GetResource('uchr',currentLayoutId)) != NULL) { - HLock(handle); - uchr = *handle; - } else if ((handle = GetResource('KCHR',currentLayoutId)) != NULL) { - HLock(handle); - KCHR = *handle; - } - } + /* + * Reinitialize all relevant variables. + */ + + lastLayout = currentLayout; + lastLayoutId = currentLayoutId; + uchr = NULL; + KCHR = NULL; + + if ((KLGetKeyboardLayoutProperty(currentLayout, + kKLuchrData, (const void**)&uchr) + == noErr) + && (uchr != NULL)) { + /* done */ + } else if ((KLGetKeyboardLayoutProperty(currentLayout, + kKLKCHRData, (const void**)&KCHR) + == noErr) + && (KCHR != NULL)) { + /* done */ + } + } } if (hasLayoutChanged) { - #ifdef TK_MAC_DEBUG_KEYBOARD - if (KCHR != NULL) { - fprintf (stderr, "GetKeyboardLayout(): New 'KCHR' layout %d\n", - (int) (short) currentLayoutId); - } else if (uchr != NULL) { - fprintf (stderr, "GetKeyboardLayout(): New 'uchr' layout %d\n", - (int) (short) currentLayoutId); + if (KCHR) { + TkMacOSXDbgMsg("New 'KCHR' layout %ld", currentLayoutId); + } else if (uchr) { + TkMacOSXDbgMsg("New 'uchr' layout %ld", currentLayoutId); } else { - fprintf (stderr, "GetKeyboardLayout(): Use cached layout " - "(should have been %d)\n", - (int) (short) currentLayoutId); + TkMacOSXDbgMsg("Use cached layout (should have been %ld)", + currentLayoutId); } #endif @@ -751,20 +652,19 @@ GetKeyboardLayout (Ptr * resourcePtr, Te * work. */ - if (KCHR != NULL) { + if (KCHR) { lastEncoding = GetKCHREncoding(currentKeyScript, currentLayoutId); #ifdef TK_MAC_DEBUG_KEYBOARD - fprintf (stderr, "GetKeyboardLayout(): New 'KCHR' encoding %lu " - "(%lu + 0x%lX)\n", - lastEncoding, lastEncoding & 0xFFFFL, - lastEncoding & ~0xFFFFL); + TkMacOSXDbgMsg("New 'KCHR' encoding %lu (%lu + 0x%lX)", + lastEncoding, lastEncoding & 0xFFFFL, + lastEncoding & ~0xFFFFL); #endif - } else if (uchr == NULL) { - KCHR = (Ptr) GetScriptManagerVariable(smKCHRCache); + } else if (!uchr) { + KCHR = (Ptr)(intptr_t)GetScriptManagerVariable(smKCHRCache); } } - if (uchr != NULL) { + if (uchr) { *resourcePtr = uchr; return 1; } else { @@ -895,7 +795,7 @@ KeycodeToUnicodeViaUnicodeResource( OptionBits options = 0; UInt32 dummy_state; UniCharCount actuallength; - OSStatus status; + OSStatus err; keycode &= 0xFF; modifiers = (modifiers >> 8) & 0xFF; @@ -918,19 +818,12 @@ KeycodeToUnicodeViaUnicodeResource( action = kUCKeyActionAutoKey; break; default: -#ifdef TK_MAC_DEBUG - fprintf (stderr, - "KeycodeToUnicodeViaUnicodeResource(): " - "Invalid parameter eKind %d\n", - (int) eKind); -#endif + TkMacOSXDbgMsg("Invalid parameter eKind %d", eKind); return 0; } - status = UCKeyTranslate( - (const UCKeyboardLayout *) uchr, - keycode, action, modifiers, keyboardType, - options, deadKeyStatePtr, + err = ChkErr(UCKeyTranslate, (const UCKeyboardLayout *) uchr, keycode, + action, modifiers, keyboardType, options, deadKeyStatePtr, maxChars, &actuallength, uniChars); if ((0 == actuallength) && (0 != *deadKeyStatePtr)) { @@ -947,10 +840,7 @@ KeycodeToUnicodeViaUnicodeResource( *deadKeyStatePtr = 0; - if (noErr != status) { -#ifdef TK_MAC_DEBUG - fprintf(stderr,"UCKeyTranslate failed: %d", (int) status); -#endif + if (err != noErr) { actuallength = 0; } @@ -1073,10 +963,8 @@ KeycodeToUnicodeViaKCHRResource( cfString = CFStringCreateWithCStringNoCopy( NULL, macStr, encoding, kCFAllocatorNull); if (cfString == NULL) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "CFString: Can't convert with encoding %d\n", - (int) encoding); -#endif + TkMacOSXDbgMsg("CFString: Can't convert with encoding %ld", + encoding); return 0; } @@ -1169,7 +1057,7 @@ XGrabKeyboard( int keyboard_mode, Time time) { - gKeyboardWinPtr = Tk_IdToWindow(display, grab_window); + keyboardGrabWinPtr = Tk_IdToWindow(display, grab_window); return GrabSuccess; } @@ -1194,7 +1082,7 @@ XUngrabKeyboard( Display* display, Time time) { - gKeyboardWinPtr = NULL; + keyboardGrabWinPtr = NULL; } /* @@ -1211,7 +1099,7 @@ XUngrabKeyboard( Tk_Window TkMacOSXGetCapture() { - return gGrabWinPtr; + return grabWinPtr; } /* @@ -1237,10 +1125,28 @@ void TkpSetCapture( TkWindow *winPtr) /* Capture window, or NULL. */ { - while ((winPtr != NULL) && !Tk_IsTopLevel(winPtr)) { + while (winPtr && !Tk_IsTopLevel(winPtr)) { winPtr = winPtr->parentPtr; } - gGrabWinPtr = (Tk_Window) winPtr; +#if 0 + { + TkWindow *w = NULL; + WindowModality m; + + if (winPtr) { + w = winPtr; + m = kWindowModalityAppModal; + } else if (grabWinPtr) { + w = (TkWindow*)grabWinPtr; + m = kWindowModalityNone; + } + if (w && w->window != None && TkMacOSXHostToplevelExists(w)) { + ChkErr(SetWindowModality, GetWindowFromPort( + TkMacOSXGetDrawablePort(w->window)), m, NULL); + } + } +#endif + grabWinPtr = (Tk_Window) winPtr; } /* Index: macosx/tkMacOSXMenu.c =================================================================== RCS file: /cvsroot/tktoolkit/tk/macosx/tkMacOSXMenu.c,v retrieving revision 1.34 diff -u -p -r1.34 tkMacOSXMenu.c --- macosx/tkMacOSXMenu.c 31 Oct 2006 22:26:06 -0000 1.34 +++ macosx/tkMacOSXMenu.c 15 Mar 2007 02:42:16 -0000 @@ -1,11 +1,11 @@ -/* +/* * tkMacOSXMenu.c -- * * This module implements the Mac-platform specific features of menus. * * Copyright (c) 1996-1997 by Sun Microsystems, Inc. * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2006 Daniel A. Steffen + * Copyright (c) 2005-2007 Daniel A. Steffen * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -17,29 +17,22 @@ #include "tkMenubutton.h" #include "tkMenu.h" #include "tkColor.h" +#include "tkFont.h" #include "tkMacOSXDebug.h" #define USE_TK_MDEF -//#define USE_ATSU /* -#ifdef TK_MAC_DEBUG +#ifdef TK_MAC_DEBUG #define TK_MAC_DEBUG_MENUS #endif */ -#if MAC_OS_X_VERSION_MAX_ALLOWED < 1030 - /* Define constants only available on Mac OS X 10.3 or later */ - #define kMenuAttrDoNotUseUserCommandKeys (1 << 7) -#endif - typedef struct MacMenu { MenuRef menuHdl; /* The Menu Manager data structure. */ - Rect menuRect; /* The rectangle as calculated in the - * MDEF. This is used to figure ou the - * clipping rgn before we push - * the <> virtual binding - * through. */ +#ifdef USE_TK_MDEF + int useMDEF; /* true if this menu uses the MDEF */ +#endif } MacMenu; typedef struct MenuEntryUserData { @@ -48,14 +41,6 @@ typedef struct MenuEntryUserData { Tk_Font tkfont; Tk_FontMetrics *fmPtr; } MenuEntryUserData; -/* - * Various geometry definitions: - */ - -#define CASCADE_ARROW_HEIGHT 10 -#define CASCADE_ARROW_WIDTH 8 -#define DECORATION_BORDER_WIDTH 2 -#define MAC_MARGIN_WIDTH 8 /* * The following are constants relating to the SICNs used for drawing the MDEF. @@ -63,8 +48,8 @@ typedef struct MenuEntryUserData { #define SICN_RESOURCE_NUMBER 128 -#define SICN_HEIGHT 16 -#define SICN_ROWS 2 +#define SICN_HEIGHT 16 +#define SICN_ROWS 2 #define CASCADE_ICON_WIDTH 7 #define SHIFT_ICON_WIDTH 10 #define OPTION_ICON_WIDTH 16 @@ -106,14 +91,16 @@ typedef struct MenuEntryUserData { typedef struct EntryGeometry { int accelTextStart; /* Offset into the accel string where - * the text starts. Everything before - * this is modifier key descriptions. - */ + * the text starts. Everything before + * this is modifier key descriptions. + */ int modifierWidth; /* Width of modifier symbols. */ - int accelTextWidth; /* Width of the text after the modifier - * keys. */ + int accelTextWidth; /* Width of the text after the modifier + * keys. */ int nonAccelMargin; /* The width of the margin for entries - * without accelerators. */ + * without accelerators. */ + int accelNum; /* Number of accelerators */ + Tcl_UniChar accelUniChars[4]; /* UniChar accelerator representation. */ } EntryGeometry; /* @@ -122,10 +109,10 @@ typedef struct EntryGeometry { typedef struct TopLevelMenubarList { struct TopLevelMenubarList *nextPtr; - /* The next window in the list. */ + /* The next window in the list. */ Tk_Window tkwin; /* The toplevel window. */ TkMenu *menuPtr; /* The menu associated with this - * toplevel. */ + * toplevel. */ } TopLevelMenubarList; /* @@ -146,24 +133,13 @@ typedef struct TopLevelMenubarList { #define MENU_HELP_MENU MENU_PLATFORM_FLAG2 #define MENU_RECONFIGURE_PENDING MENU_PLATFORM_FLAG3 -#define CASCADE_CMD (0x1b) +#define CASCADE_CMD (0x1b) /* The special command char for cascade - * menus. */ + * menus. */ #define MENUBAR_REDRAW_PENDING 1 -#define SCREEN_MARGIN 5 -static int gNoTkMenus = 0; /* This is used by Tk_MacOSXTurnOffMenus as the - * flag that Tk is not to draw any menus. */ - -RgnHandle tkMenuCascadeRgn = NULL; - /* The region to clip drawing to when the - * MDEF is up. */ -int tkUseMenuCascadeRgn = 0; /* If this is 1, clipping code - * should intersect tkMenuCascadeRgn - * before drawing occurs. - * tkMenuCascadeRgn will only - * be valid when the value of this - * variable is 1. */ +static int gNoTkMenus = 0; /* This is used by Tk_MacOSXTurnOffMenus as the + * flag that Tk is not to draw any menus. */ static Tcl_HashTable commandTable; /* The list of menuInstancePtrs associated with @@ -182,9 +158,6 @@ static char *currentMenuBarName; * DString. */ static Tk_Window currentMenuBarOwner; /* Which window owns the current menu bar. */ -static char elipsisString[TCL_UTF_MAX + 1]; - /* The UTF representation of the elipsis (...) - * character. */ static int inPostMenu; /* We cannot be re-entrant like X * windows. */ static short lastMenuID; /* To pass to NewMenu; need to figure out @@ -192,162 +165,153 @@ static short lastMenuID; /* To pass to N static short lastCascadeID; /* Cascades have to have ids that are * less than 256. */ -static MacDrawable macMDEFDrawable; - /* Drawable for use by MDEF code */ -static int MDEFScrollFlag = 0; /* Used so that popups don't scroll too soon. */ static int menuBarFlags; /* Used for whether the menu bar needs * redrawing or not. */ - -static struct TearoffSelect { - TkMenu *menuPtr; /* The menu that is torn off */ - Point point; /* The point to place the new menu */ - Rect excludeRect; /* We don't want to drag tearoff highlights - * when we are in this menu */ -} tearoffStruct; - -struct MenuCommandHandlerData { /* This is the ClientData we pass to */ - TkMenu *menuPtr; /* Tcl_DoWhenIdle to move handling */ - int index; /* menu commands to the event loop. */ -}; -static RgnHandle totalMenuRgn = NULL; - /* Used to update windows which have been - * obscured by menus. */ -static RgnHandle utilRgn = NULL;/* Used when creating the region that is to - * be clipped out while the MDEF is active. */ +struct MenuCommandHandlerData { /* This is the ClientData we pass to */ + TkMenu *menuPtr; /* Tcl_DoWhenIdle to move handling */ + int index; /* menu commands to the event loop. */ +}; static TopLevelMenubarList *windowListPtr; /* A list of windows that have menubars set. */ -static MenuItemDrawingUPP tkThemeMenuItemDrawingUPP; - /* Points to the UPP for theme Item drawing. */ -static Tcl_Obj *useMDEFVar; + +/* + * Array of unicode, charcode and utf representations of the most common + * special menu symbols. + */ +typedef struct MenuSymbol { + const Tcl_UniChar unicode; + const char charCode; + /* char padding; */ + int utfLen, width; + char utf[TCL_UTF_MAX + 1]; +} MenuSymbol; + +static MenuSymbol menuSymbols[] = { + {kCommandUnicode, kCommandCharCode}, + {kOptionUnicode, kMenuOptionGlyph}, + {kControlUnicode, kMenuControlGlyph}, + {kShiftUnicode, kMenuShiftGlyph}, + {kCheckUnicode, kCheckCharCode}, + {kDiamondUnicode, kDiamondCharCode}, + {kBulletUnicode, kBulletCharCode}, + {0x2026, kNullCharCode}, + {0, 0}, +}; + +enum MenuSymbolIdx { + COMMAND_SYMBOL, + OPTION_SYMBOL, + CONTROL_SYMBOL, + SHIFT_SYMBOL, + CHECK_SYMBOL, + DIAMDOND_SYMBOL, + BULLET_SYMBOL, + ELLIPSIS_SYMBOL, +}; MenuRef tkCurrentAppleMenu = NULL; +static SInt32 menuMarkColumnWidth = 0, menuMarkIndent = 0; +static SInt32 menuTextLeadingEdgeMargin = 0, menuTextTrailingEdgeMargin = 0; +static SInt16 menuItemExtraHeight = 0, menuItemExtraWidth = 0; +static SInt16 menuSeparatorHeight = 0; + /* * Forward declarations for procedures defined later in this file: */ -MODULE_SCOPE int TkMacOSXGetNewMenuID _ANSI_ARGS_((Tcl_Interp *interp, - TkMenu *menuInstPtr, - int cascade, - short *menuIDPtr)); -MODULE_SCOPE void TkMacOSXFreeMenuID _ANSI_ARGS_((short menuID)); - -static void CompleteIdlers _ANSI_ARGS_((TkMenu *menuPtr)); -static void DrawMenuBarWhenIdle _ANSI_ARGS_(( - ClientData clientData)); -static void DrawMenuBackground _ANSI_ARGS_(( - Rect *menuRectPtr, Drawable d, ThemeMenuType type)); -static void DrawMenuEntryAccelerator _ANSI_ARGS_(( - TkMenu *menuPtr, TkMenuEntry *mePtr, - Drawable d, GC gc, Tk_Font tkfont, - CONST Tk_FontMetrics *fmPtr, - Tk_3DBorder activeBorder, int x, int y, - int width, int height, int drawArrow)); -static void DrawMenuEntryBackground _ANSI_ARGS_(( - TkMenu *menuPtr, TkMenuEntry *mePtr, - Drawable d, Tk_3DBorder activeBorder, - Tk_3DBorder bgBorder, int x, int y, - int width, int heigth)); -static void DrawMenuEntryIndicator _ANSI_ARGS_(( - TkMenu *menuPtr, TkMenuEntry *mePtr, - Drawable d, GC gc, GC indicatorGC, - Tk_Font tkfont, - CONST Tk_FontMetrics *fmPtr, int x, int y, - int width, int height)); -static void DrawMenuEntryLabel _ANSI_ARGS_(( - TkMenu * menuPtr, TkMenuEntry *mePtr, Drawable d, - GC gc, Tk_Font tkfont, - CONST Tk_FontMetrics *fmPtr, int x, int y, - int width, int height)); -static void DrawMenuSeparator _ANSI_ARGS_((TkMenu *menuPtr, - TkMenuEntry *mePtr, Drawable d, GC gc, - Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, - int x, int y, int width, int height)); -static void DrawTearoffEntry _ANSI_ARGS_((TkMenu *menuPtr, - TkMenuEntry *mePtr, Drawable d, GC gc, - Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, - int x, int y, int width, int height)); -static void EventuallyInvokeMenu (ClientData data); -static void GetEntryText _ANSI_ARGS_((TkMenuEntry *mePtr, - Tcl_DString *dStringPtr)); -static void GetMenuAccelGeometry _ANSI_ARGS_((TkMenu *menuPtr, - TkMenuEntry *mePtr, Tk_Font tkfont, - CONST Tk_FontMetrics *fmPtr, int *modWidthPtr, - int *textWidthPtr, int *heightPtr)); -static void GetMenuLabelGeometry _ANSI_ARGS_((TkMenuEntry *mePtr, - Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, - int *widthPtr, int *heightPtr)); -static void GetMenuIndicatorGeometry _ANSI_ARGS_(( - TkMenu *menuPtr, TkMenuEntry *mePtr, - Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, - int *widthPtr, int *heightPtr)); -static void GetMenuSeparatorGeometry _ANSI_ARGS_(( - TkMenu *menuPtr, TkMenuEntry *mePtr, - Tk_Font tkfont, CONST Tk_FontMetrics *fmPtr, - int *widthPtr, int *heightPtr)); -static void GetTearoffEntryGeometry _ANSI_ARGS_((TkMenu *menuPtr, - TkMenuEntry *mePtr, Tk_Font tkfont, - CONST Tk_FontMetrics *fmPtr, int *widthPtr, - int *heightPtr)); -static char FindMarkCharacter _ANSI_ARGS_((TkMenuEntry *mePtr)); -static void InvalidateMDEFRgns _ANSI_ARGS_((void)); - -static void MenuDefProc _ANSI_ARGS_((short message, - MenuHandle menu, Rect *menuRectPtr, - Point hitPt, short *whichItem )); -static void HandleMenuHiliteMsg (MenuRef menu, - Rect *menuRectPtr, - Point hitPt, - SInt16 *whichItem, - TkMenu *menuPtr); -static void HandleMenuDrawMsg (MenuRef menu, - Rect *menuRectPtr, - Point hitPt, - SInt16 *whichItem, - TkMenu *menuPtr); -static void HandleMenuFindItemsMsg (MenuRef menu, - Rect *menuRectPtr, - Point hitPt, - SInt16 *whichItem, - TkMenu *menuPtr); -static void HandleMenuPopUpMsg (MenuRef menu, - Rect *menuRectPtr, - Point hitPt, - SInt16 *whichItem, - TkMenu *menuPtr); -static void HandleMenuCalcItemMsg (MenuRef menu, - Rect *menuRectPtr, - Point hitPt, - SInt16 *whichItem, - TkMenu *menuPtr); - -static void MenuSelectEvent _ANSI_ARGS_((TkMenu *menuPtr)); -static void ReconfigureIndividualMenu _ANSI_ARGS_(( - TkMenu *menuPtr, MenuHandle macMenuHdl, - int base)); -static void ReconfigureMacintoshMenu _ANSI_ARGS_ (( - ClientData clientData)); -static void RecursivelyClearActiveMenu _ANSI_ARGS_(( - TkMenu *menuPtr)); -static void RecursivelyDeleteMenu _ANSI_ARGS_(( - TkMenu *menuPtr)); -static void RecursivelyInsertMenu _ANSI_ARGS_(( - TkMenu *menuPtr)); -static void SetDefaultMenubar _ANSI_ARGS_((void)); -static int SetMenuCascade _ANSI_ARGS_((TkMenu *menuPtr)); -static void mySetMenuTitle _ANSI_ARGS_((MenuHandle menuHdl, - Tcl_Obj *titlePtr)); -static void AppearanceEntryDrawWrapper _ANSI_ARGS_((TkMenuEntry *mePtr, - Rect * menuRectPtr, MenuTrackingData *mtdPtr, - Drawable d, Tk_FontMetrics *fmPtr, Tk_Font tkfont, - int x, int y, int width, int height)); -static pascal void ThemeMenuItemDrawingProc _ANSI_ARGS_ ((const Rect *inBounds, - SInt16 inDepth, Boolean inIsColorDevice, - SInt32 inUserData)); +MODULE_SCOPE int TkMacOSXGetNewMenuID(Tcl_Interp *interp, TkMenu *menuInstPtr, + int cascade, short *menuIDPtr); +MODULE_SCOPE void TkMacOSXFreeMenuID(short menuID); + +static void CompleteIdlers(TkMenu *menuPtr); +static void DrawMenuBarWhenIdle(ClientData clientData); +static void DrawMenuEntryAccelerator(TkMenu *menuPtr, TkMenuEntry *mePtr, + Drawable d, GC gc, Tk_Font tkfont, const Tk_FontMetrics *fmPtr, + Tk_3DBorder activeBorder, int x, int y, int width, int height, + int drawArrow); +static void DrawMenuEntryBackground(TkMenu *menuPtr, TkMenuEntry *mePtr, + Drawable d, Tk_3DBorder activeBorder, Tk_3DBorder bgBorder, int x, + int y, int width, int heigth); +static void DrawMenuEntryIndicator(TkMenu *menuPtr, TkMenuEntry *mePtr, + Drawable d, GC gc, GC indicatorGC, Tk_Font tkfont, + const Tk_FontMetrics *fmPtr, int x, int y, int width, int height); +static void DrawMenuEntryLabel(TkMenu * menuPtr, TkMenuEntry *mePtr, + Drawable d, GC gc, Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int x, + int y, int width, int height); +static void DrawMenuSeparator(TkMenu *menuPtr, TkMenuEntry *mePtr, Drawable d, + GC gc, Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int x, int y, + int width, int height); +static void DrawTearoffEntry(TkMenu *menuPtr, TkMenuEntry *mePtr, Drawable d, + GC gc, Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int x, int y, + int width, int height); +static void EventuallyInvokeMenu(ClientData data); +static void GetEntryText(TkMenuEntry *mePtr, Tcl_DString *dStringPtr); +static void GetMenuAccelGeometry(TkMenu *menuPtr, TkMenuEntry *mePtr, + Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int *modWidthPtr, + int *textWidthPtr, int *heightPtr); +static void GetMenuLabelGeometry(TkMenuEntry *mePtr, Tk_Font tkfont, + const Tk_FontMetrics *fmPtr, int *widthPtr, int *heightPtr); +static void GetMenuIndicatorGeometry(TkMenu *menuPtr, TkMenuEntry *mePtr, + Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int *widthPtr, + int *heightPtr); +static void GetMenuSeparatorGeometry(TkMenu *menuPtr, TkMenuEntry *mePtr, + Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int *widthPtr, + int *heightPtr); +static void GetTearoffEntryGeometry(TkMenu *menuPtr, TkMenuEntry *mePtr, + Tk_Font tkfont, const Tk_FontMetrics *fmPtr, int *widthPtr, + int *heightPtr); +static char FindMarkCharacter(TkMenuEntry *mePtr); +static int GetUtfMarkCharacter(char markChar, const char **markUtfPtr); +static TkMenu* MenuPtrForMenuRef(MenuRef menu); +static int ParseAccelerators(const char **accelStringPtr, int *accelNumPtr, + Tcl_UniChar *accelUniChars); +static void MenuSelectEvent(TkMenu *menuPtr); +static void ReconfigureIndividualMenu(TkMenu *menuPtr, MenuHandle macMenuHdl, + int base); +static void ReconfigureMacintoshMenu(ClientData clientData); +static void RecursivelyClearActiveMenu(TkMenu *menuPtr); +static void RecursivelyDeleteMenu(TkMenu *menuPtr); +static void RecursivelyInsertMenu(TkMenu *menuPtr); +static void SetDefaultMenubar(void); +static int SetMenuCascade(TkMenu *menuPtr); + +#ifdef USE_TK_MDEF +#define SCREEN_MARGIN 5 +static MacDrawable macMDEFDrawable; + /* Drawable for use by MDEF code */ +static int MDEFScrollFlag = 0; /* Used so that popups don't scroll too soon.*/ +static MenuItemDrawingUPP tkThemeMenuItemDrawingUPP; + /* Points to the UPP for theme Item drawing. */ +static Tcl_Obj *useMDEFVar; + +static void DrawMenuBackground(TkMenu *menuPtr, Rect *menuRectPtr, + Drawable d); +static void MenuDefProc(short message, MenuHandle menu, Rect *menuRectPtr, + Point hitPt, short *whichItem ); +static void HandleMenuHiliteMsg(MenuRef menu, Rect *menuRectPtr, Point hitPt, + SInt16 *whichItem, TkMenu *menuPtr); +static void HandleMenuDrawMsg(MenuRef menu, Rect *menuRectPtr, Point hitPt, + SInt16 *whichItem, TkMenu *menuPtr); +static void HandleMenuFindItemMsg(MenuRef menu, Rect *menuRectPtr, + Point hitPt, SInt16 *whichItem, TkMenu *menuPtr); +static void HandleMenuPopUpMsg(MenuRef menu, Rect *menuRectPtr, Point hitPt, + SInt16 *whichItem, TkMenu *menuPtr); +static void HandleMenuCalcItemMsg(MenuRef menu, Rect *menuRectPtr, Point hitPt, + SInt16 *whichItem, TkMenu *menuPtr); +static void AppearanceEntryDrawWrapper(TkMenuEntry *mePtr, Rect * menuRectPtr, + MenuTrackingData *mtdPtr, Drawable d, Tk_FontMetrics *fmPtr, + Tk_Font tkfont, int erase); +static pascal void ThemeMenuItemDrawingProc(const Rect *inBounds, + SInt16 inDepth, Boolean inIsColorDevice, SInt32 inUserData); +#else /* USE_TK_MDEF */ +# define useMDEF 0 +#endif /* USE_TK_MDEF */ + +#define IS_THEME_MENU_FONT(tkfont) (strcmp(Tk_NameOfFont(tkfont), "menu") == 0) - /* *---------------------------------------------------------------------- * @@ -375,15 +339,15 @@ TkMacOSXUseMenuID( Tcl_HashEntry *commandEntryPtr; int newEntry; int iMacID = macID; /* Do this to remove compiler warning */ - + TkMenuInit(); commandEntryPtr = Tcl_CreateHashEntry(&commandTable, (char *) iMacID, - &newEntry); + &newEntry); if (newEntry == 1) { - Tcl_SetHashValue(commandEntryPtr, NULL); - return TCL_OK; + Tcl_SetHashValue(commandEntryPtr, NULL); + return TCL_OK; } else { - return TCL_ERROR; + return TCL_ERROR; } } @@ -416,12 +380,13 @@ TkMacOSXUseMenuID( * *---------------------------------------------------------------------- */ + int TkMacOSXGetNewMenuID( Tcl_Interp *interp, /* Used for error reporting */ TkMenu *menuPtr, /* The menu we are working with */ int cascade, /* 0 if we are working with a normal menu; - 1 if we are working with a cascade */ + 1 if we are working with a cascade */ short *menuIDPtr) /* The resulting id */ { int found = 0; @@ -434,64 +399,64 @@ int * when the highest value is incremented. Also, the values between * 236 and 255 inclusive are reserved for DA's by the Mac OS. */ - + if (!cascade) { - short curID = lastMenuID + 1; - if (curID == 236) { - curID = 256; - } - - while (curID != lastMenuID) { - int iCurID = curID; - commandEntryPtr = Tcl_CreateHashEntry(&commandTable, + short curID = lastMenuID + 1; + if (curID == 236) { + curID = 256; + } + + while (curID != lastMenuID) { + int iCurID = curID; + commandEntryPtr = Tcl_CreateHashEntry(&commandTable, (char *) iCurID, &newEntry); - if (newEntry == 1) { - found = 1; - lastMenuID = returnID = curID; - break; - } - curID++; - if (curID == 236) { - curID = 256; - } - } + if (newEntry == 1) { + found = 1; + lastMenuID = returnID = curID; + break; + } + curID++; + if (curID == 236) { + curID = 256; + } + } } else { - - /* - * Cascade ids must be between 0 and 235 only, so they must be - * dealt with separately. - */ - - short curID = lastCascadeID + 1; - if (curID == 2000) { - curID = 0; - } - - while (curID != lastCascadeID) { - int iCurID = curID; - commandEntryPtr = Tcl_CreateHashEntry(&commandTable, + + /* + * Cascade ids must be between 0 and 235 only, so they must be + * dealt with separately. + */ + + short curID = lastCascadeID + 1; + if (curID == 2000) { + curID = 0; + } + + while (curID != lastCascadeID) { + int iCurID = curID; + commandEntryPtr = Tcl_CreateHashEntry(&commandTable, (char *) iCurID, &newEntry); - if (newEntry == 1) { - found = 1; - lastCascadeID = returnID = curID; - break; - } - curID++; - if (curID == 2000) { - curID = 0; - } - } + if (newEntry == 1) { + found = 1; + lastCascadeID = returnID = curID; + break; + } + curID++; + if (curID == 2000) { + curID = 0; + } + } } if (found) { - Tcl_SetHashValue(commandEntryPtr, (char *) menuPtr); - *menuIDPtr = returnID; - return TCL_OK; + Tcl_SetHashValue(commandEntryPtr, (char *) menuPtr); + *menuIDPtr = returnID; + return TCL_OK; } else { - Tcl_ResetResult(interp); - Tcl_AppendResult(interp, "No more menus can be allocated.", - (char *) NULL); - return TCL_ERROR; + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "No more menus can be allocated.", + (char *) NULL); + return TCL_ERROR; } } @@ -516,17 +481,47 @@ TkMacOSXFreeMenuID( short menuID) /* The id to free */ { Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&commandTable, - (char *) ((int)menuID)); - + (char*)(intptr_t)menuID); + if (entryPtr != NULL) { - Tcl_DeleteHashEntry(entryPtr); + Tcl_DeleteHashEntry(entryPtr); } if (menuID == currentAppleMenuID) { - currentAppleMenuID = 0; + currentAppleMenuID = 0; } if (menuID == currentHelpMenuID) { - currentHelpMenuID = 0; + currentHelpMenuID = 0; + } +} + +/* + *---------------------------------------------------------------------- + * + * MenuPtrForMenuRef -- + * + * Returns a pointer to the TkMenu corresponding to a given + * Carbon MenuRef. + * + * Results: + * Returns a pointer to a TkMenu or NULL. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + +TkMenu* +MenuPtrForMenuRef(MenuRef menu) { + TkMenu *menuPtr = NULL; + MenuID menuID = GetMenuID(menu); + Tcl_HashEntry *commandEntryPtr = Tcl_FindHashEntry(&commandTable, + (char*)(intptr_t)menuID); + + if (commandEntryPtr) { + menuPtr = (TkMenu *) Tcl_GetHashValue(commandEntryPtr); } + return menuPtr; } /* @@ -550,81 +545,84 @@ TkMacOSXFreeMenuID( int TkpNewMenu( TkMenu *menuPtr) /* The common structure we are making the - * platform structure for. */ + * platform structure for. */ { short menuID; MenuRef macMenuHdl; +#ifdef USE_TK_MDEF MenuDefSpec menuDefSpec; Tcl_Obj *useMDEFObjPtr; - int useMDEF; + int useMDEF = 1; +#endif int error = TCL_OK; OSStatus err; CFStringRef cfStr; - + error = TkMacOSXGetNewMenuID(menuPtr->interp, menuPtr, 0, &menuID); if (error != TCL_OK) { - return error; + return error; } - err = CreateNewMenu(menuID, kMenuAttrDoNotUseUserCommandKeys, &macMenuHdl); + err = ChkErr(CreateNewMenu, menuID, kMenuAttrDoNotUseUserCommandKeys, + &macMenuHdl); if (err != noErr) { - Tcl_AppendResult(menuPtr->interp, "CreateNewMenu failed.", - (char *) NULL); - return TCL_ERROR; + Tcl_AppendResult(menuPtr->interp, "CreateNewMenu failed.", + (char *) NULL); + return TCL_ERROR; } cfStr = CFStringCreateWithCString(NULL, Tk_PathName(menuPtr->tkwin), - kCFStringEncodingUTF8); + kCFStringEncodingUTF8); if (!cfStr) { - Tcl_AppendResult(menuPtr->interp, "CFStringCreateWithCString failed.", - (char *) NULL); - return TCL_ERROR; + Tcl_AppendResult(menuPtr->interp, "CFStringCreateWithCString failed.", + (char *) NULL); + return TCL_ERROR; } - err = SetMenuTitleWithCFString(macMenuHdl, cfStr); + err = ChkErr(SetMenuTitleWithCFString, macMenuHdl, cfStr); CFRelease(cfStr); if (err != noErr) { - Tcl_AppendResult(menuPtr->interp, "SetMenuTitleWithCFString failed.", - (char *) NULL); - return TCL_ERROR; + Tcl_AppendResult(menuPtr->interp, "SetMenuTitleWithCFString failed.", + (char *) NULL); + return TCL_ERROR; } - + + menuPtr->platformData = (TkMenuPlatformData) ckalloc(sizeof(MacMenu)); + ((MacMenu *) menuPtr->platformData)->menuHdl = macMenuHdl; + +#ifdef USE_TK_MDEF /* * Check whether we want to use the custom mdef or not. For now * the default is to use it unless the variable is explicitly * set to no. */ - - useMDEFObjPtr = Tcl_ObjGetVar2(menuPtr->interp, useMDEFVar, NULL, TCL_GLOBAL_ONLY); + + useMDEFObjPtr = Tcl_ObjGetVar2(menuPtr->interp, useMDEFVar, NULL, + TCL_GLOBAL_ONLY); if (useMDEFObjPtr == NULL - || Tcl_GetBooleanFromObj(NULL, useMDEFObjPtr, &useMDEF) == TCL_ERROR - || useMDEF) { - menuDefSpec.defType = kMenuDefProcPtr; - menuDefSpec.u.defProc = MenuDefProc; - if ((err = SetMenuDefinition(macMenuHdl, &menuDefSpec)) != noErr) { -#ifdef TK_MAC_DEBUG - fprintf(stderr, "SetMenuDefinition failed %d\n", (int) err); -#endif - } + || Tcl_GetBooleanFromObj(NULL, useMDEFObjPtr, &useMDEF) == TCL_ERROR + || useMDEF) { + menuDefSpec.defType = kMenuDefProcPtr; + menuDefSpec.u.defProc = MenuDefProc; + ChkErr(SetMenuDefinition, macMenuHdl, &menuDefSpec); } - menuPtr->platformData = (TkMenuPlatformData) ckalloc(sizeof(MacMenu)); - ((MacMenu *) menuPtr->platformData)->menuHdl = macMenuHdl; - SetRect(&((MacMenu *) menuPtr->platformData)->menuRect, 0, 0, 0, 0); + ((MacMenu *) menuPtr->platformData)->useMDEF = useMDEF; +#endif /* USE_TK_MDEF */ if ((currentMenuBarInterp == menuPtr->interp) - && (currentMenuBarName != NULL)) { - Tk_Window parentWin = Tk_Parent(menuPtr->tkwin); - - if (strcmp(currentMenuBarName, Tk_PathName(parentWin)) == 0) { - if ((strcmp(Tk_PathName(menuPtr->tkwin) - + strlen(Tk_PathName(parentWin)), ".apple") == 0) - || (strcmp(Tk_PathName(menuPtr->tkwin) - + strlen(Tk_PathName(parentWin)), ".help") == 0)) { - if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) { - Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL); - menuBarFlags |= MENUBAR_REDRAW_PENDING; - } - } - } + && (currentMenuBarName != NULL)) { + Tk_Window parentWin = Tk_Parent(menuPtr->tkwin); + + if (strcmp(currentMenuBarName, Tk_PathName(parentWin)) == 0) { + if ((strcmp(Tk_PathName(menuPtr->tkwin) + + strlen(Tk_PathName(parentWin)), ".apple") == 0) + || (strcmp(Tk_PathName(menuPtr->tkwin) + + strlen(Tk_PathName(parentWin)), ".help") == 0)) { + if (!(menuBarFlags & MENUBAR_REDRAW_PENDING)) { + Tcl_DoWhenIdle(DrawMenuBarWhenIdle, (ClientData *) NULL); + menuBarFlags |= MENUBAR_REDRAW_PENDING; + } + } + } } - + menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING; Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr); return TCL_OK; @@ -653,35 +651,34 @@ TkpDestroyMenu( MenuRef macMenuHdl = ((MacMenu *) menuPtr->platformData)->menuHdl; if (menuPtr->menuFlags & MENU_RECONFIGURE_PENDING) { - Tcl_CancelIdleCall(ReconfigureMacintoshMenu, (ClientData) menuPtr); - menuPtr->menuFlags &= ~MENU_RECONFIGURE_PENDING; + Tcl_CancelIdleCall(ReconfigureMacintoshMenu, (ClientData) menuPtr); + menuPtr->menuFlags &= ~MENU_RECONFIGURE_PENDING; } if (GetMenuID(macMenuHdl) == currentHelpMenuID) { - MenuRef helpMenuHdl; - MenuItemIndex helpIndex; - - if ((HMGetHelpMenu(&helpMenuHdl,&helpIndex) == noErr) - && (helpMenuHdl != NULL)) { - int i, count = CountMenuItems(helpMenuHdl); - - for (i = helpIndex; i <= count; i++) { - DeleteMenuItem(helpMenuHdl, helpIndex); - } - } - currentHelpMenuID = 0; + MenuRef helpMenuHdl; + MenuItemIndex helpIndex; + + if ((HMGetHelpMenu(&helpMenuHdl,&helpIndex) == noErr) + && (helpMenuHdl != NULL)) { + int i, count = CountMenuItems(helpMenuHdl); + + for (i = helpIndex; i <= count; i++) { + DeleteMenuItem(helpMenuHdl, helpIndex); + } + } + currentHelpMenuID = 0; } if (menuPtr->platformData != NULL) { - MenuID menuID; - menuID = GetMenuID(macMenuHdl); - DeleteMenu(menuID); - TkMacOSXFreeMenuID(menuID); - DisposeMenu(macMenuHdl); - ckfree((char *) menuPtr->platformData); + MenuID menuID; + menuID = GetMenuID(macMenuHdl); + DeleteMenu(menuID); + TkMacOSXFreeMenuID(menuID); + DisposeMenu(macMenuHdl); + ckfree((char *) menuPtr->platformData); menuPtr->platformData = NULL; } } - - + /* *---------------------------------------------------------------------- * @@ -698,7 +695,7 @@ TkpDestroyMenu( *---------------------------------------------------------------------- */ -static int +int SetMenuCascade( TkMenu* menuPtr) /* The menu we are setting up to be a * cascade. */ @@ -707,11 +704,11 @@ SetMenuCascade( MenuID newMenuID, menuID = GetMenuID(macMenuHdl); int error = TCL_OK; if (menuID >= 256) { - error = TkMacOSXGetNewMenuID(menuPtr->interp, menuPtr, 1, &newMenuID); - if (error == TCL_OK) { - TkMacOSXFreeMenuID(menuID); - SetMenuID (macMenuHdl,newMenuID); - } + error = TkMacOSXGetNewMenuID(menuPtr->interp, menuPtr, 1, &newMenuID); + if (error == TCL_OK) { + TkMacOSXFreeMenuID(menuID); + SetMenuID (macMenuHdl,newMenuID); + } } return error; } @@ -734,16 +731,16 @@ SetMenuCascade( void TkpDestroyMenuEntry( - TkMenuEntry *mePtr) /* The common structure for the menu - * entry. */ + TkMenuEntry *mePtr) /* The common structure for the menu + * entry. */ { - TkMenu *menuPtr = mePtr->menuPtr; - + TkMenu *menuPtr = mePtr->menuPtr; + ckfree((char *) mePtr->platformEntryData); - if ((menuPtr->platformData != NULL) - && !(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) { - menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING; - Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr); + if ((menuPtr->platformData != NULL) + && !(menuPtr->menuFlags & MENU_RECONFIGURE_PENDING)) { + menuPtr->menuFlags |= MENU_RECONFIGURE_PENDING; + Tcl_DoWhenIdle(ReconfigureMacintoshMenu, (ClientData) menuPtr); } } @@ -766,45 +763,49 @@ TkpDestroyMenuEntry( *---------------------------------------------------------------------- */ -static void +void GetEntryText( TkMenuEntry *mePtr, /* A pointer to the menu entry. */ Tcl_DString *dStringPtr) /* The DString to put the text into. This - * will be initialized by this routine. */ + * will be initialized by this routine. */ { +#ifdef USE_TK_MDEF + int useMDEF = ((MacMenu *) mePtr->menuPtr->platformData)->useMDEF; +#endif + int noLabel = (mePtr->labelPtr == NULL || mePtr->labelLength == 0); + Tcl_DStringInit(dStringPtr); - if (mePtr->type == TEAROFF_ENTRY) { - Tcl_DStringAppend(dStringPtr, "(Tear-off)", -1); - } else if (mePtr->imagePtr != NULL) { - Tcl_DStringAppend(dStringPtr, "(Image)", -1); - } else if (mePtr->bitmapPtr != NULL) { - Tcl_DStringAppend(dStringPtr, "(Pixmap)", -1); - } else if (mePtr->labelPtr == NULL || mePtr->labelLength == 0) { + if (mePtr->type == TEAROFF_ENTRY && (useMDEF || noLabel)) { + Tcl_DStringAppend(dStringPtr, "(Tear-off)", -1); + } else if (mePtr->imagePtr != NULL && (useMDEF || noLabel)) { + Tcl_DStringAppend(dStringPtr, "(Image)", -1); + } else if (mePtr->bitmapPtr != NULL && (useMDEF || noLabel)) { + Tcl_DStringAppend(dStringPtr, "(Pixmap)", -1); + } else if (noLabel) { /* * The Mac menu manager does not like null strings. */ Tcl_DStringAppend(dStringPtr, " ", -1); } else { - int length; - char *text = Tcl_GetStringFromObj(mePtr->labelPtr, &length); - char *dStringText; - int i; + int length; + char *text = Tcl_GetStringFromObj(mePtr->labelPtr, &length); + char *dStringText; + int i; for (i = 0; *text; text++, i++) { - if ((*text == '.') - && (*(text + 1) != '\0') && (*(text + 1) == '.') - && (*(text + 2) != '\0') && (*(text + 2) == '.')) { - Tcl_DStringAppend(dStringPtr, elipsisString, -1); - i += strlen(elipsisString) - 1; + if ((*text == '.') && (*(text+1) == '.') && (*(text+2) == '.')) { + Tcl_DStringAppend(dStringPtr, menuSymbols[ELLIPSIS_SYMBOL].utf, + menuSymbols[ELLIPSIS_SYMBOL].utfLen); + i += menuSymbols[ELLIPSIS_SYMBOL].utfLen - 1; text += 2; - } else { - Tcl_DStringSetLength(dStringPtr, + } else { + Tcl_DStringSetLength(dStringPtr, Tcl_DStringLength(dStringPtr) + 1); - dStringText = Tcl_DStringValue(dStringPtr); - dStringText[i] = *text; - } - } + dStringText = Tcl_DStringValue(dStringPtr); + dStringText[i] = *text; + } + } } } @@ -815,134 +816,146 @@ GetEntryText( * * Finds the Macintosh mark character based on the font of the * item. We calculate a good mark character based on the font - * that this item is rendered in. - * - * We try the following special mac characters. If none of them - * are present, just use the check mark. - * '' - Check mark character (\022) - * 'Â¥' - Mac Bullet character (\245) - * '' - Filled diamond (\023) - * '—' - Hollow diamond (\327) - * '‘' = Mac Long dash ("em dash") (\321) - * '-' = short dash (minus, "en dash"); + * that this item is rendered in. * * Results: - * None. + * Mark char. * * Side effects: - * New item is added to platform menu + * None. * *---------------------------------------------------------------------- */ -static char +char FindMarkCharacter( TkMenuEntry *mePtr) /* The entry we are finding the character - * for. */ + * for. */ { - char markChar; + static const char markChars[] = {kCheckCharCode, kDiamondCharCode, + kBulletCharCode, '-', kCheckCharCode}; + const char *markChar = markChars; + int i = sizeof(markChars); Tk_Font tkfont; tkfont = Tk_GetFontFromObj(mePtr->menuPtr->tkwin, - (mePtr->fontPtr == NULL) ? mePtr->menuPtr->fontPtr + (mePtr->fontPtr == NULL) ? mePtr->menuPtr->fontPtr : mePtr->fontPtr); - - if (!TkMacOSXIsCharacterMissing(tkfont, '\022')) { - markChar = '\022'; /* Check mark */ - } else if (!TkMacOSXIsCharacterMissing(tkfont, '\245')) { - markChar = '\245'; /* Bullet */ - } else if (!TkMacOSXIsCharacterMissing(tkfont, '\023')) { - markChar = '\023'; /* Filled Diamond */ - } else if (!TkMacOSXIsCharacterMissing(tkfont, '\327')) { - markChar = '\327'; /* Hollow Diamond */ - } else if (!TkMacOSXIsCharacterMissing(tkfont, '\321')) { - markChar = '\321'; /* Long Dash */ - } else if (!TkMacOSXIsCharacterMissing(tkfont, '-')) { - markChar = '-'; /* Short Dash */ - } else { - markChar = '\022'; /* Check mark */ + + while (--i) { + if (!TkMacOSXIsCharacterMissing(tkfont, *markChar)) { + break; + } + markChar++; } - return markChar; + return *markChar; } /* *---------------------------------------------------------------------- * - * SetMenuTitle -- + * GetUtfMarkCharacter -- * - * Sets title of menu so that the text displays correctly in menubar. - * This code directly manipulates menu handle data. This code - * was originally part of an ancient Apple Developer Response mail. + * Get the utf8 string for the given mark character, taking into + * account the special menu font char codes. * * Results: + * Length of returned utf8 string. + * + * Side effects: * None. * + *---------------------------------------------------------------------- + */ + +int +GetUtfMarkCharacter(char markChar, const char **markUtfPtr) +{ + const MenuSymbol *ms = menuSymbols; + int len = 0; + + while (ms->unicode) { + if (ms->charCode && ms->charCode == markChar) { + *markUtfPtr = ms->utf; + len = ms->utfLen; + break; + } + ms++; + } + if (!len) { + static char markUtf[TCL_UTF_MAX + 1]; + + Tcl_ExternalToUtf(NULL, TkMacOSXCarbonEncoding, &markChar, 1, 0, NULL, + markUtf, TCL_UTF_MAX + 1, NULL, &len, NULL); + *markUtfPtr = markUtf; + } + return len; +} + +/* + *---------------------------------------------------------------------- + * + * ParseAccelerators -- + * + * Parse menu accelerator string. + * + * Results: + * Accelerator flags. + * * Side effects: - * The menu handle will change size depending on the length of the - * title + * None. * *---------------------------------------------------------------------- */ -static void -mySetMenuTitle( - MenuRef menuHdl, /* The menu we are setting the title of. */ - Tcl_Obj *titlePtr) /* The C string to set the title to. */ -{ - char *title = (titlePtr == NULL) ? "" - : Tcl_GetStringFromObj(titlePtr, NULL); - CFStringRef cf = CFStringCreateWithCString(NULL, - title, kCFStringEncodingUTF8); - - SetMenuTitleWithCFString(menuHdl, cf); - CFRelease(cf); -} - -static int ParseAccelerators(char **accelStringPtr) { - char *accelString = *accelStringPtr; - int flags = 0; +int +ParseAccelerators(const char **accelStringPtr, int *accelNumPtr, + Tcl_UniChar *accelUniChars) { + struct Modif { + const char *name; + const size_t len; + const int flag, symbol; + }; +#define MODIF(n, f) { #n, sizeof(#n)-1, ENTRY_##f##_ACCEL, f##_SYMBOL } + static const struct Modif modifs[] = { + MODIF(Control, CONTROL), + MODIF(Ctrl, CONTROL), + MODIF(Option, OPTION), + MODIF(Opt, OPTION), + MODIF(Alt, OPTION), + MODIF(Shift, SHIFT), + MODIF(Command, COMMAND), + MODIF(Cmd, COMMAND), + MODIF(Meta, COMMAND), + { NULL, 0, 0, 0} + }; +#undef MODIF + const char *accelString = *accelStringPtr; + int flags = 0, num = 0; + while (1) { - if ((0 == strncasecmp("Control", accelString, 6)) - && (('-' == accelString[6]) || ('+' == accelString[6]))) { - flags |= ENTRY_CONTROL_ACCEL; - accelString += 7; - } else if ((0 == strncasecmp("Ctrl", accelString, 4)) - && (('-' == accelString[4]) || ('+' == accelString[4]))) { - flags |= ENTRY_CONTROL_ACCEL; - accelString += 5; - } else if ((0 == strncasecmp("Shift", accelString, 5)) - && (('-' == accelString[5]) || ('+' == accelString[5]))) { - flags |= ENTRY_SHIFT_ACCEL; - accelString += 6; - } else if ((0 == strncasecmp("Option", accelString, 6)) - && (('-' == accelString[6]) || ('+' == accelString[6]))) { - flags |= ENTRY_OPTION_ACCEL; - accelString += 7; - } else if ((0 == strncasecmp("Opt", accelString, 3)) - && (('-' == accelString[3]) || ('+' == accelString[3]))) { - flags |= ENTRY_OPTION_ACCEL; - accelString += 4; - } else if ((0 == str