Skip to content

Commit

Permalink
* generic/tkCanvas.c: allow -selectforeground option to be None; add
Browse files Browse the repository at this point in the history
	* generic/tkCanvText.c:	fallback to fgColor when selFgColor is None
	* generic/tkEntry.c:	(new default on aqua to match native L&F).
	* generic/tkListbox.c:
	* generic/tkText.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
	* unix/tkUnixScale.c:	   of TkpClipDrawableToRect()).
  • Loading branch information
das committed Apr 23, 2007
1 parent c168d68 commit 83e0003
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 59 deletions.
6 changes: 4 additions & 2 deletions generic/tkCanvText.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: tkCanvText.c,v 1.23 2007/02/13 11:29:17 das Exp $
* RCS: @(#) $Id: tkCanvText.c,v 1.24 2007/04/23 21:15:17 das Exp $
*/

#include <stdio.h>
Expand Down Expand Up @@ -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) {
Expand Down
33 changes: 25 additions & 8 deletions generic/tkCanvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: tkCanvas.c,v 1.42 2007/04/17 15:24:48 dkf Exp $
* RCS: @(#) $Id: tkCanvas.c,v 1.43 2007/04/23 21:15:18 das Exp $
*/

/* #define USE_OLD_TAG_SEARCH 1 */
Expand All @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* See tkCanvas.h for key data structures used to implement canvases.
Expand Down Expand Up @@ -177,10 +182,10 @@ static Tk_ConfigSpec configSpecs[] = {
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_CANVAS_SELECT_FG_COLOR, Tk_Offset(TkCanvas, textInfo.selFgColorPtr),
TK_CONFIG_COLOR_ONLY},
TK_CONFIG_COLOR_ONLY|TK_CONFIG_NULL_OK},
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_CANVAS_SELECT_FG_MONO, Tk_Offset(TkCanvas, textInfo.selFgColorPtr),
TK_CONFIG_MONO_ONLY},
TK_CONFIG_MONO_ONLY|TK_CONFIG_NULL_OK},
{TK_CONFIG_CUSTOM, "-state", "state", "State",
"normal", Tk_Offset(TkCanvas, canvas_state), TK_CONFIG_DONT_SET_DEFAULT,
&stateOption},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* 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,
Expand Down Expand Up @@ -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.
Expand All @@ -2220,10 +2235,12 @@ 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 /* TK_NO_DOUBLE_BUFFERING */
}

/*
Expand Down
16 changes: 12 additions & 4 deletions generic/tkEntry.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkEntry.c,v 1.43 2007/04/17 14:36:49 dkf Exp $
* RCS: @(#) $Id: tkEntry.c,v 1.44 2007/04/23 21:15:18 das Exp $
*/

#include "tkInt.h"
Expand Down Expand Up @@ -135,7 +135,7 @@ static const Tk_OptionSpec entryOptSpec[] = {
0, (ClientData) DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
0, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
TK_CONFIG_NULL_OK, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
{TK_OPTION_STRING, "-show", "show", "Show",
DEF_ENTRY_SHOW, -1, Tk_Offset(Entry, showChar),
TK_OPTION_NULL_OK, 0, 0},
Expand Down Expand Up @@ -281,7 +281,7 @@ static const Tk_OptionSpec sbOptSpec[] = {
0, (ClientData) DEF_ENTRY_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_ENTRY_SELECT_FG_COLOR, -1, Tk_Offset(Entry, selFgColorPtr),
0, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
TK_CONFIG_NULL_OK, (ClientData) DEF_ENTRY_SELECT_FG_MONO, 0},
{TK_OPTION_STRING_TABLE, "-state", "state", "State",
DEF_ENTRY_STATE, -1, Tk_Offset(Entry, state),
0, (ClientData) stateStrings, 0},
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* Compute x-coordinate of the pixel just after last visible one, plus
Expand Down Expand Up @@ -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.
Expand All @@ -1836,6 +1843,7 @@ DisplayEntry(
0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin),
0, 0);
Tk_FreePixmap(entryPtr->display, pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
entryPtr->flags &= ~BORDER_NEEDED;
}

Expand Down
8 changes: 7 additions & 1 deletion generic/tkFrame.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkFrame.c,v 1.27 2007/02/28 04:58:24 chengyemao Exp $
* RCS: @(#) $Id: tkFrame.c,v 1.28 2007/04/23 21:15:18 das Exp $
*/

#include "default.h"
Expand Down Expand Up @@ -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
Expand All @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* Clear the pixmap.
Expand Down Expand Up @@ -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.
Expand All @@ -1560,6 +1565,7 @@ DisplayFrame(
(unsigned) (Tk_Height(tkwin) - 2 * hlWidth),
hlWidth, hlWidth);
Tk_FreePixmap(framePtr->display, pixmap);
#endif /* TK_NO_DOUBLE_BUFFERING */
}

}
Expand Down
20 changes: 16 additions & 4 deletions generic/tkListbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkListbox.c,v 1.39 2007/04/17 14:32:28 dkf Exp $
* RCS: @(#) $Id: tkListbox.c,v 1.40 2007/04/23 21:15:18 das Exp $
*/

#include "tkPort.h"
Expand Down Expand Up @@ -280,7 +280,7 @@ static const Tk_OptionSpec optionSpecs[] = {
Tk_Offset(Listbox, selBorderWidth), 0, 0, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_LISTBOX_SELECT_FG_COLOR, -1, Tk_Offset(Listbox, selFgColorPtr),
0, (ClientData) DEF_LISTBOX_SELECT_FG_MONO, 0},
TK_CONFIG_NULL_OK, (ClientData) DEF_LISTBOX_SELECT_FG_MONO, 0},
{TK_OPTION_STRING, "-selectmode", "selectMode", "SelectMode",
DEF_LISTBOX_SELECT_MODE, -1, Tk_Offset(Listbox, selectMode),
TK_OPTION_NULL_OK, 0, 0},
Expand Down Expand Up @@ -1776,7 +1776,9 @@ ListboxWorldChanged(
}
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);
Expand Down Expand Up @@ -1861,6 +1863,7 @@ DisplayListbox(
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,
Expand All @@ -1871,6 +1874,9 @@ DisplayListbox(

pixmap = Tk_GetPixmap(listPtr->display, Tk_WindowId(tkwin),
Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));
#else
pixmap = Tk_WindowId(tkwin);
#endif /* TK_NO_DOUBLE_BUFFERING */
Tk_Fill3DRectangle(tkwin, pixmap, listPtr->normalBorder, 0, 0,
Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);

Expand Down Expand Up @@ -1935,7 +1941,11 @@ DisplayListbox(
* 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;
Expand Down Expand Up @@ -2152,10 +2162,12 @@ DisplayListbox(
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 /* TK_NO_DOUBLE_BUFFERING */
}

/*
Expand Down
14 changes: 13 additions & 1 deletion generic/tkPanedWindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: tkPanedWindow.c,v 1.27 2007/01/05 00:00:50 nijtmans Exp $
* RCS: @(#) $Id: tkPanedWindow.c,v 1.28 2007/04/23 21:15:18 das Exp $
*/

#include "tkPort.h"
Expand Down Expand Up @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* Redraw the widget's background and border.
Expand Down Expand Up @@ -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.
Expand All @@ -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 /* TK_NO_DOUBLE_BUFFERING */
}

/*
Expand Down Expand Up @@ -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 /* TK_NO_DOUBLE_BUFFERING */

/*
* Redraw the widget's background and border.
Expand All @@ -2713,13 +2723,15 @@ 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.
*/

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 /* TK_NO_DOUBLE_BUFFERING */
}

/*
Expand Down
4 changes: 2 additions & 2 deletions generic/tkText.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tkText.c,v 1.74 2007/02/23 15:02:58 dkf Exp $
* RCS: @(#) $Id: tkText.c,v 1.75 2007/04/23 21:15:18 das Exp $
*/

#include "default.h"
Expand Down Expand Up @@ -200,7 +200,7 @@ static const Tk_OptionSpec optionSpecs[] = {
TK_OPTION_NULL_OK, (ClientData) DEF_TEXT_SELECT_BD_MONO, 0},
{TK_OPTION_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_TEXT_SELECT_FG_COLOR, -1, Tk_Offset(TkText, selFgColorPtr),
0, (ClientData) DEF_TEXT_SELECT_FG_MONO, 0},
TK_CONFIG_NULL_OK, (ClientData) DEF_TEXT_SELECT_FG_MONO, 0},
{TK_OPTION_BOOLEAN, "-setgrid", "setGrid", "SetGrid",
DEF_TEXT_SET_GRID, -1, Tk_Offset(TkText, setGrid), 0, 0, 0},
{TK_OPTION_PIXELS, "-spacing1", "spacing1", "Spacing",
Expand Down

0 comments on commit 83e0003

Please sign in to comment.