From 5a6d13273b98767ce73bce25863a3e6189daaa74 Mon Sep 17 00:00:00 2001 From: wolfsuit Date: Sat, 12 Mar 2005 00:49:27 +0000 Subject: Fix for 1124237 and the mysterious "sometimes buttons don't draw" bug. --- ChangeLog | 21 +++++++++++++++++++++ macosx/tkMacOSXButton.c | 42 +++++++++++++++++++----------------------- macosx/tkMacOSXInt.h | 3 ++- macosx/tkMacOSXSubwindows.c | 27 ++++++++++++++++++++++++++- macosx/tkMacOSXWindowEvent.c | 10 ++++------ macosx/tkMacOSXWm.c | 5 +++-- 6 files changed, 75 insertions(+), 33 deletions(-) diff --git a/ChangeLog b/ChangeLog index a6655ab..ed9f58e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2005-03-11 Jim Ingham + + * macosx/tkMacOSXButton.c (TkpDisplayButton): Set the port to + the Button window's port BEFORE you set the clip, otherwise you + are setting the clip on the wrong window! + Also, a little cleanup - move x & y into the branches where they are + used, and don't compute the TextAnchor if we are using the native + button text, since we aren't going to use it. + (TkMacOSXDrawControl): Call ShowControl & SetControlVisibility in a more + logical order. + + * tkMacOSXInt.h: Add TkMacOSXGenerateFocusEvent. + * tkMacOSXSubwindows.c (XDestroyWindow): We don't get Activate events + for the remaining windows when a Floating window is destroyed. This + can cause the focus to disappear. So catch this case when the window + is being destroyed and move the focus here. + * tkMacOSXWindowEvent.c (TkMacOSXGenerateFocusEvent): Make this public + (used to be GenerateFocusEvent) since we need it here and in + tkMacOSXSubwindows.c. Then change the name everywhere it is used. + [Bug 1124237] + 2005-03-10 Jim Ingham * macosx/tkMacOSXMouseEvent.c (TkMacOSXProcessMouseEvent): In diff --git a/macosx/tkMacOSXButton.c b/macosx/tkMacOSXButton.c index 0083935..fde6cc0 100644 --- a/macosx/tkMacOSXButton.c +++ b/macosx/tkMacOSXButton.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXButton.c,v 1.2.2.7 2004/11/11 01:26:42 das Exp $ + * RCS: @(#) $Id: tkMacOSXButton.c,v 1.2.2.8 2005/03/12 00:49:28 wolfsuit Exp $ */ #include "tkButton.h" @@ -197,9 +197,6 @@ TkpDisplayButton( MacButton *macButtonPtr = (MacButton *)clientData; TkButton *butPtr = (TkButton *) clientData; Tk_Window tkwin = butPtr->tkwin; - int x = 0; /* Initialization only needed to stop - * compiler warning. */ - int y; int width, height, fullWidth, fullHeight; int textXOffset, textYOffset; int haveImage = 0, haveText = 0; @@ -234,11 +231,15 @@ TkpDisplayButton( } /* - * set up clipping region + * set up clipping region. Make sure the we are using the port + * for this button, or we will set the wrong window's clip. */ + destPort = TkMacOSXGetDrawablePort(pixmap); + SetGWorld(destPort, NULL); TkMacOSXSetUpClippingRgn(pixmap); + /* * See the comment in UpdateControlColors as to why we use the * highlightbackground for the border of Macintosh buttons. @@ -262,13 +263,6 @@ TkpDisplayButton( if (macButtonPtr->usingControl) { borderWidth = 0; - /* - * This part uses Macintosh rather than Tk calls to draw - * to the screen. Make sure the ports etc. are set correctly. - */ - - destPort = TkMacOSXGetDrawablePort(pixmap); - SetGWorld(destPort, NULL); TkMacOSXDrawControl(macButtonPtr, destPort, dpPtr->gc, pixmap); } else { if (wasUsingControl && macButtonPtr->userPane) { @@ -304,6 +298,8 @@ TkpDisplayButton( haveText = (butPtr->textWidth != 0 && butPtr->textHeight != 0); if (butPtr->compound != COMPOUND_NONE && haveImage && haveText) { + int x; + int y; textXOffset = 0; textYOffset = 0; fullWidth = 0; @@ -407,6 +403,9 @@ TkpDisplayButton( y += fullHeight/2; } else { if (haveImage) { + int x = 0; + int y; + TkComputeAnchor(butPtr->anchor, tkwin, 0, 0, butPtr->indicatorSpace + width, height, &x, &y); x += butPtr->indicatorSpace; @@ -440,19 +439,16 @@ TkpDisplayButton( XSetClipOrigin(butPtr->display, dpPtr->gc, 0, 0); } y += height/2; - } else { + } else if (macButtonPtr->useTkText) { + int x = 0; + int y; TkComputeAnchor(butPtr->anchor, tkwin, butPtr->padX, butPtr->padY, butPtr->indicatorSpace + butPtr->textWidth, - butPtr->textHeight, &x, &y); - - x += butPtr->indicatorSpace; - - if (macButtonPtr->useTkText) { - Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, + butPtr->textHeight, &x, &y); + x += butPtr->indicatorSpace; + Tk_DrawTextLayout(butPtr->display, pixmap, dpPtr->gc, butPtr->textLayout, x, y, 0, -1); - } - y += butPtr->textHeight/2; } } } @@ -1046,12 +1042,12 @@ TkMacOSXDrawControl( } if (mbPtr->flags&2) { - ShowControl(mbPtr->control); ShowControl(mbPtr->userPane); + ShowControl(mbPtr->control); mbPtr->flags ^= 2; } else { - Draw1Control(mbPtr->userPane); SetControlVisibility(mbPtr->control, true, true); + Draw1Control(mbPtr->userPane); } if (mbPtr->params.isBevel) { diff --git a/macosx/tkMacOSXInt.h b/macosx/tkMacOSXInt.h index b5347f9..acf67ec 100644 --- a/macosx/tkMacOSXInt.h +++ b/macosx/tkMacOSXInt.h @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXInt.h,v 1.3.2.2 2004/11/11 01:26:43 das Exp $ + * RCS: @(#) $Id: tkMacOSXInt.h,v 1.3.2.3 2005/03/12 00:49:28 wolfsuit Exp $ */ #ifndef _TKMACINT @@ -153,6 +153,7 @@ extern Tcl_Encoding TkMacOSXCarbonEncoding; extern int TkMacOSXUseAntialiasedText(Tcl_Interp *interp, int enable); extern int TkMacOSXInitCGDrawing(Tcl_Interp *interp, int enable, int antiAlias); extern void TkMacOSXDefaultStartupScript(void); +extern int TkMacOSXGenerateFocusEvent( Window window, int activeFlag); #include "tkIntPlatDecls.h" diff --git a/macosx/tkMacOSXSubwindows.c b/macosx/tkMacOSXSubwindows.c index fda9ae5..e7025b7 100644 --- a/macosx/tkMacOSXSubwindows.c +++ b/macosx/tkMacOSXSubwindows.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXSubwindows.c,v 1.2.2.3 2004/11/11 01:26:43 das Exp $ + * RCS: @(#) $Id: tkMacOSXSubwindows.c,v 1.2.2.4 2005/03/12 00:49:28 wolfsuit Exp $ */ #include "tkInt.h" @@ -68,6 +68,31 @@ XDestroyWindow( if (Tk_IsTopLevel(macWin->winPtr)) { + WindowRef winRef; + /* + * We are relying on the Activate Mac OS event to pass the + * focus away from a window that is getting Destroyed to the + * Front non-floating window. BUT we don't get activate events + * when a floating window is destroyed - since the front non-floating + * window doesn't in fact get activated... So maybe we can check here + * and if we are destroying a floating window, we can pass the focus + * back to the front non-floating window... + */ + + if (macWin->grafPtr != NULL) { + TkWindow *focusPtr = TkGetFocusWin(macWin->winPtr); + if (focusPtr == NULL || (focusPtr->mainPtr->winPtr == macWin->winPtr)) { + winRef = GetWindowFromPort(macWin->grafPtr); + if (TkpIsWindowFloating (winRef)) { + Window window; + + window = TkMacOSXGetXWindow(FrontNonFloatingWindow()); + if (window != None) { + TkMacOSXGenerateFocusEvent(window, 1); + } + } + } + } DisposeRgn(macWin->clipRgn); DisposeRgn(macWin->aboveClipRgn); diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index f718d08..dbb94cc 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -75,8 +75,6 @@ static RgnHandle visRgn; static int GenerateUpdateEvent( Window window); static void GenerateUpdates( RgnHandle updateRgn, TkWindow *winPtr); static int GenerateActivateEvents( Window window, int activeFlag); -static int GenerateFocusEvent( Window window, int activeFlag); - /* @@ -172,11 +170,11 @@ TkMacOSXProcessWindowEvent( switch (eventPtr->eKind) { case kEventWindowActivated: eventFound |= GenerateActivateEvents(window, 1); - eventFound |= GenerateFocusEvent(window, 1); + eventFound |= TkMacOSXGenerateFocusEvent(window, 1); break; case kEventWindowDeactivated: eventFound |= GenerateActivateEvents(window, 0); - eventFound |= GenerateFocusEvent(window, 0); + eventFound |= TkMacOSXGenerateFocusEvent(window, 0); break; case kEventWindowUpdate: if (GenerateUpdateEvent(window)) { @@ -382,7 +380,7 @@ GenerateActivateEvents( /* *---------------------------------------------------------------------- * - * GenerateFocusEvent -- + * TkMacOSXGenerateFocusEvent -- * * Given a Macintosh window activate event this function generates all the * X Focus events needed by Tk. @@ -397,7 +395,7 @@ GenerateActivateEvents( */ int -GenerateFocusEvent( +TkMacOSXGenerateFocusEvent( Window window, /* Root X window for event. */ int activeFlag ) { diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index fe8b9a0..9913688 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -12,7 +12,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXWm.c,v 1.7.2.6 2004/11/11 01:26:43 das Exp $ + * RCS: @(#) $Id: tkMacOSXWm.c,v 1.7.2.7 2005/03/12 00:49:38 wolfsuit Exp $ */ #include @@ -5049,6 +5049,7 @@ TkpMakeMenuWindow( } } + /* *---------------------------------------------------------------------- * @@ -5156,7 +5157,7 @@ TkMacOSXMakeRealWindowExist( listPtr->winPtr = winPtr; tkMacOSXWindowListPtr = listPtr; - macWin->grafPtr = GetWindowPort ( newWindow ); + macWin->grafPtr = GetWindowPort (newWindow); macWin->rootControl = rootControl; MoveWindowStructure(newWindow, geometry.left, geometry.top); SetPort(GetWindowPort(newWindow)); -- cgit v0.12