summaryrefslogtreecommitdiffstats
path: root/win/tkWinX.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2004-09-23 01:08:11 (GMT)
committerhobbs <hobbs>2004-09-23 01:08:11 (GMT)
commit1709b7b141a400dba7c70616c6a6d46cb0ceaea0 (patch)
treefd784f52acf31c941302f0a30a35e5a2dc79e215 /win/tkWinX.c
parenta25c5763f281dd91e24bcdff1ef95473cca5eb0f (diff)
downloadtk-1709b7b141a400dba7c70616c6a6d46cb0ceaea0.zip
tk-1709b7b141a400dba7c70616c6a6d46cb0ceaea0.tar.gz
tk-1709b7b141a400dba7c70616c6a6d46cb0ceaea0.tar.bz2
* win/tkWinInt.h (TkWinDisplayChanged): added decl
* win/tkWinX.c (TkWinDisplayChanged, TkpOpenDisplay): Correctly * win/tkWinWm.c (InvalidateSubTreeDepth, WmProc): handle color and screen resolution changes. Tested for 16/24/32 bpp changes on XP. May need more fixes for 8bpp switch, use of special colormaps, or other special palette handling cases. [Bug 223689]
Diffstat (limited to 'win/tkWinX.c')
-rw-r--r--win/tkWinX.c174
1 files changed, 106 insertions, 68 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c
index 082bfe1..83866a5 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.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: tkWinX.c,v 1.32 2004/09/21 19:13:58 mdejong Exp $
+ * RCS: @(#) $Id: tkWinX.c,v 1.33 2004/09/23 01:08:12 hobbs Exp $
*/
#include "tkWinInt.h"
@@ -353,7 +353,7 @@ TkWinXCleanup(hInstance)
*----------------------------------------------------------------------
*/
-int
+int
TkWinGetPlatformId()
{
if (tkPlatformId == 0) {
@@ -411,7 +411,7 @@ TkWinGetPlatformId()
*----------------------------------------------------------------------
*/
-int
+int
TkWinGetPlatformTheme()
{
if (tkPlatformId == 0) {
@@ -451,6 +451,100 @@ TkGetDefaultScreenName(interp, screenName)
/*
*----------------------------------------------------------------------
*
+ * TkWinDisplayChanged --
+ *
+ * Called to set up initial screen info or when an event indicated
+ * display (screen) change.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * May change info regarding the screen.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TkWinDisplayChanged(Display *display)
+{
+ HDC dc;
+ Screen *screen;
+
+ if (display == NULL || display->screens == NULL) {
+ return;
+ }
+ screen = display->screens;
+
+ dc = GetDC(NULL);
+ screen->width = GetDeviceCaps(dc, HORZRES);
+ screen->height = GetDeviceCaps(dc, VERTRES);
+ screen->mwidth = MulDiv(screen->width, 254,
+ GetDeviceCaps(dc, LOGPIXELSX) * 10);
+ screen->mheight = MulDiv(screen->height, 254,
+ GetDeviceCaps(dc, LOGPIXELSY) * 10);
+
+ /*
+ * On windows, when creating a color bitmap, need two pieces of
+ * information: the number of color planes and the number of pixels per
+ * plane. Need to remember both quantities so that when constructing an
+ * HBITMAP for offscreen rendering, we can specify the correct value for
+ * the number of planes. Otherwise the HBITMAP won't be compatible with
+ * the HWND and we'll just get blank spots copied onto the screen.
+ */
+
+ screen->ext_data = (XExtData *) GetDeviceCaps(dc, PLANES);
+ screen->root_depth = GetDeviceCaps(dc, BITSPIXEL) * (int) screen->ext_data;
+
+ if (screen->root_visual != NULL) {
+ ckfree((char *) screen->root_visual);
+ }
+ screen->root_visual = (Visual *) ckalloc(sizeof(Visual));
+ screen->root_visual->visualid = 0;
+ if (GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) {
+ screen->root_visual->map_entries = GetDeviceCaps(dc, SIZEPALETTE);
+ screen->root_visual->class = PseudoColor;
+ screen->root_visual->red_mask = 0x0;
+ screen->root_visual->green_mask = 0x0;
+ screen->root_visual->blue_mask = 0x0;
+ } else if (screen->root_depth == 4) {
+ screen->root_visual->class = StaticColor;
+ screen->root_visual->map_entries = 16;
+ } else if (screen->root_depth == 8) {
+ screen->root_visual->class = StaticColor;
+ screen->root_visual->map_entries = 256;
+ } else if (screen->root_depth == 12) {
+ screen->root_visual->class = TrueColor;
+ screen->root_visual->map_entries = 32;
+ screen->root_visual->red_mask = 0xf0;
+ screen->root_visual->green_mask = 0xf000;
+ screen->root_visual->blue_mask = 0xf00000;
+ } else if (screen->root_depth == 16) {
+ screen->root_visual->class = TrueColor;
+ screen->root_visual->map_entries = 64;
+ screen->root_visual->red_mask = 0xf8;
+ screen->root_visual->green_mask = 0xfc00;
+ screen->root_visual->blue_mask = 0xf80000;
+ } else if (screen->root_depth >= 24) {
+ screen->root_visual->class = TrueColor;
+ screen->root_visual->map_entries = 256;
+ screen->root_visual->red_mask = 0xff;
+ screen->root_visual->green_mask = 0xff00;
+ screen->root_visual->blue_mask = 0xff0000;
+ }
+ screen->root_visual->bits_per_rgb = screen->root_depth;
+ ReleaseDC(NULL, dc);
+
+ if (screen->cmap != None) {
+ XFreeColormap(display, screen->cmap);
+ }
+ screen->cmap = XCreateColormap(display, None, screen->root_visual,
+ AllocNone);
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* TkpOpenDisplay --
*
* Create the Display structure and fill it with device
@@ -470,7 +564,6 @@ TkpOpenDisplay(display_name)
CONST char *display_name;
{
Screen *screen;
- HDC dc;
TkWinDrawable *twdPtr;
Display *display;
ThreadSpecificData *tsdPtr = (ThreadSpecificData *)
@@ -492,21 +585,14 @@ TkpOpenDisplay(display_name)
strcpy(display->display_name, display_name);
display->cursor_font = 1;
- display->nscreens = 1;
- display->request = 1;
- display->qlen = 0;
+ display->nscreens = 1;
+ display->request = 1;
+ display->qlen = 0;
screen = (Screen *) ckalloc(sizeof(Screen));
+ ZeroMemory(screen, sizeof(Screen));
screen->display = display;
- dc = GetDC(NULL);
- screen->width = GetDeviceCaps(dc, HORZRES);
- screen->height = GetDeviceCaps(dc, VERTRES);
- screen->mwidth = MulDiv(screen->width, 254,
- GetDeviceCaps(dc, LOGPIXELSX) * 10);
- screen->mheight = MulDiv(screen->height, 254,
- GetDeviceCaps(dc, LOGPIXELSY) * 10);
-
/*
* Set up the root window.
*/
@@ -521,72 +607,24 @@ TkpOpenDisplay(display_name)
screen->root = (Window)twdPtr;
/*
- * On windows, when creating a color bitmap, need two pieces of
- * information: the number of color planes and the number of
- * pixels per plane. Need to remember both quantities so that
- * when constructing an HBITMAP for offscreen rendering, we can
- * specify the correct value for the number of planes. Otherwise
- * the HBITMAP won't be compatible with the HWND and we'll just
- * get blank spots copied onto the screen.
- */
-
- screen->ext_data = (XExtData *) GetDeviceCaps(dc, PLANES);
- screen->root_depth = GetDeviceCaps(dc, BITSPIXEL) * (int) screen->ext_data;
-
- screen->root_visual = (Visual *) ckalloc(sizeof(Visual));
- screen->root_visual->visualid = 0;
- if (GetDeviceCaps(dc, RASTERCAPS) & RC_PALETTE) {
- screen->root_visual->map_entries = GetDeviceCaps(dc, SIZEPALETTE);
- screen->root_visual->class = PseudoColor;
- screen->root_visual->red_mask = 0x0;
- screen->root_visual->green_mask = 0x0;
- screen->root_visual->blue_mask = 0x0;
- } else {
- if (screen->root_depth == 4) {
- screen->root_visual->class = StaticColor;
- screen->root_visual->map_entries = 16;
- } else if (screen->root_depth == 8) {
- screen->root_visual->class = StaticColor;
- screen->root_visual->map_entries = 256;
- } else if (screen->root_depth == 12) {
- screen->root_visual->class = TrueColor;
- screen->root_visual->map_entries = 32;
- screen->root_visual->red_mask = 0xf0;
- screen->root_visual->green_mask = 0xf000;
- screen->root_visual->blue_mask = 0xf00000;
- } else if (screen->root_depth == 16) {
- screen->root_visual->class = TrueColor;
- screen->root_visual->map_entries = 64;
- screen->root_visual->red_mask = 0xf8;
- screen->root_visual->green_mask = 0xfc00;
- screen->root_visual->blue_mask = 0xf80000;
- } else if (screen->root_depth >= 24) {
- screen->root_visual->class = TrueColor;
- screen->root_visual->map_entries = 256;
- screen->root_visual->red_mask = 0xff;
- screen->root_visual->green_mask = 0xff00;
- screen->root_visual->blue_mask = 0xff0000;
- }
- }
- screen->root_visual->bits_per_rgb = screen->root_depth;
- ReleaseDC(NULL, dc);
-
- /*
* Note that these pixel values are not palette relative.
*/
screen->white_pixel = RGB(255, 255, 255);
screen->black_pixel = RGB(0, 0, 0);
+ screen->cmap = None;
display->screens = screen;
display->nscreens = 1;
display->default_screen = 0;
- screen->cmap = XCreateColormap(display, None, screen->root_visual,
- AllocNone);
+
+ TkWinDisplayChanged(display);
+
tsdPtr->winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
tsdPtr->winDisplay->display = display;
tsdPtr->updatingClipboard = FALSE;
+
return tsdPtr->winDisplay;
}