Tk Source Code

Check-in [0eb7a8a6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:
* 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]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0eb7a8a6ca8d433636d52e87b055af3095eab74f
User & Date: hobbs 2004-09-23 01:08:11
Context
2004-09-23
14:56
text widget search fix check-in: 8d8ebd87 user: vincentdarley tags: trunk
01:08
* 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]
check-in: 0eb7a8a6 user: hobbs tags: trunk
2004-09-21
19:13
* generic/tkInt.decls: Add decl for TkWinGetPlatformTheme. It is only defined under Win32. * generic/tkIntPlatDecls.h: Regen. * generic/tkStubInit.c: Regen. * win/tkWinInt.h: Define TK_THEME_WIN_CLASSIC and TK_THEME_WIN_XP. * win/tkWinMenu.c (DrawMenuEntryAccelerator, DrawMenuEntryLabel): Draw a disabled 3D text highlight for the accelerator only with the Win95/98 look. Same goes for the menu entry text. * win/tkWinX.c (TkWinGetPlatformId, TkWinGetPlatformTheme): Automatically detect the Windows theme in use and return either TK_THEME_WIN_CLASSIC or TK_THEME_WIN_XP when the TkWinGetPlatformTheme function is invoked. [Patch 866194]
check-in: 24901585 user: mdejong tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.










1
2
3
4
5
6
7









2004-09-21  Mo DeJong  <[email protected]>

	* generic/tkInt.decls: Add decl for TkWinGetPlatformTheme.
	It is only defined under Win32.
	* generic/tkIntPlatDecls.h: Regen.
	* generic/tkStubInit.c: Regen.
	* win/tkWinInt.h: Define TK_THEME_WIN_CLASSIC and
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2004-09-22  Jeff Hobbs  <[email protected]>

	* 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]
	
2004-09-21  Mo DeJong  <[email protected]>

	* generic/tkInt.decls: Add decl for TkWinGetPlatformTheme.
	It is only defined under Win32.
	* generic/tkIntPlatDecls.h: Regen.
	* generic/tkStubInit.c: Regen.
	* win/tkWinInt.h: Define TK_THEME_WIN_CLASSIC and

Changes to win/tkWinInt.h.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * tkWinInt.h --
 *
 *	This file contains declarations that are shared among the
 *	Windows-specific parts of Tk, but aren't used by the rest of
 *	Tk.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkWinInt.h,v 1.18 2004/09/21 19:13:58 mdejong Exp $
 */

#ifndef _TKWININT
#define _TKWININT

#ifndef _TKINT
#include "tkInt.h"













|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * tkWinInt.h --
 *
 *	This file contains declarations that are shared among the
 *	Windows-specific parts of Tk, but aren't used by the rest of
 *	Tk.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkWinInt.h,v 1.19 2004/09/23 01:08:11 hobbs Exp $
 */

#ifndef _TKWININT
#define _TKWININT

#ifndef _TKINT
#include "tkInt.h"
167
168
169
170
171
172
173





174
175
176
177
178
179
180
EXTERN void	TkWinUpdatingClipboard(int mode);

/*
 * Used by tkWinDialog.c to associate the right icon with tk_messageBox
 */
EXTERN HICON	TkWinGetIcon(Tk_Window tkw, DWORD iconsize);






/*
 * The following structure keeps track of whether we are using the 
 * multi-byte or the wide-character interfaces to the operating system.
 * System calls should be made through the following function table.
 *
 * While some system calls need to use this A/W jump-table, it is not
 * necessary for all calls to do it, which is why you won't see this







>
>
>
>
>







167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
EXTERN void	TkWinUpdatingClipboard(int mode);

/*
 * Used by tkWinDialog.c to associate the right icon with tk_messageBox
 */
EXTERN HICON	TkWinGetIcon(Tk_Window tkw, DWORD iconsize);

/*
 * Used by tkWinX.c on for certain system display change messages
 */
EXTERN void	TkWinDisplayChanged(Display *display);

/*
 * The following structure keeps track of whether we are using the 
 * multi-byte or the wide-character interfaces to the operating system.
 * System calls should be made through the following function table.
 *
 * While some system calls need to use this A/W jump-table, it is not
 * necessary for all calls to do it, which is why you won't see this

Changes to win/tkWinWm.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkWinWm.c,v 1.75 2004/09/21 18:23:01 mdejong Exp $
 */

#include "tkWinInt.h"
#include <shellapi.h>

/*
 * These next two defines are only valid on Win2K/XP+.







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: tkWinWm.c,v 1.76 2004/09/23 01:08:11 hobbs Exp $
 */

#include "tkWinInt.h"
#include <shellapi.h>

/*
 * These next two defines are only valid on Win2K/XP+.
412
413
414
415
416
417
418

419
420
421
422
423
424
425
			    int *minWidthPtr, int *minHeightPtr));
static TkWindow *	GetTopLevel _ANSI_ARGS_((HWND hwnd));
static void		InitWm _ANSI_ARGS_((void));
static int		InstallColormaps _ANSI_ARGS_((HWND hwnd, int message,
			    int isForemost));
static void		InvalidateSubTree _ANSI_ARGS_((TkWindow *winPtr,
			    Colormap colormap));

static int		ParseGeometry _ANSI_ARGS_((Tcl_Interp *interp,
			    char *string, TkWindow *winPtr));
static void		RefreshColormap _ANSI_ARGS_((Colormap colormap,
	                    TkDisplay *dispPtr));
static void		SetLimits _ANSI_ARGS_((HWND hwnd, MINMAXINFO *info));
static void		TkWmStackorderToplevelWrapperMap _ANSI_ARGS_((
			    TkWindow *winPtr,







>







412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
			    int *minWidthPtr, int *minHeightPtr));
static TkWindow *	GetTopLevel _ANSI_ARGS_((HWND hwnd));
static void		InitWm _ANSI_ARGS_((void));
static int		InstallColormaps _ANSI_ARGS_((HWND hwnd, int message,
			    int isForemost));
static void		InvalidateSubTree _ANSI_ARGS_((TkWindow *winPtr,
			    Colormap colormap));
static void		InvalidateSubTreeDepth _ANSI_ARGS_((TkWindow *winPtr));
static int		ParseGeometry _ANSI_ARGS_((Tcl_Interp *interp,
			    char *string, TkWindow *winPtr));
static void		RefreshColormap _ANSI_ARGS_((Colormap colormap,
	                    TkDisplay *dispPtr));
static void		SetLimits _ANSI_ARGS_((HWND hwnd, MINMAXINFO *info));
static void		TkWmStackorderToplevelWrapperMap _ANSI_ARGS_((
			    TkWindow *winPtr,
5825
5826
5827
5828
5829
5830
5831







5832
5833
5834
5835
5836
5837
5838
				 * queried. */
    int *xPtr, *yPtr;		/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr, *heightPtr;	/* Store dimensions of virtual root here. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;








    *xPtr = 0;
    *yPtr = 0;
    *widthPtr = DisplayWidth(winPtr->display, winPtr->screenNum);
    *heightPtr = DisplayHeight(winPtr->display, winPtr->screenNum);
}

/*







>
>
>
>
>
>
>







5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
				 * queried. */
    int *xPtr, *yPtr;		/* Store x and y offsets of virtual root
				 * here. */
    int *widthPtr, *heightPtr;	/* Store dimensions of virtual root here. */
{
    TkWindow *winPtr = (TkWindow *) tkwin;

    /*
     * XXX: This is not correct for multiple monitors.  There may be many
     * changes required to get this right, and it may effect existing
     * applications that don't consider possible <0 vroot.  See
     * http://msdn.microsoft.com/library/en-us/gdi/monitor_3lrn.asp
     * for more info.
     */
    *xPtr = 0;
    *yPtr = 0;
    *widthPtr = DisplayWidth(winPtr->display, winPtr->screenNum);
    *heightPtr = DisplayHeight(winPtr->display, winPtr->screenNum);
}

/*
6854
6855
6856
6857
6858
6859
6860
























































6861
6862
6863
6864
6865
6866
6867
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
























































 * TkWinGetSystemPalette --
 *
 *	Retrieves the currently installed foreground palette.
 *
 * Results:
 *	Returns the global foreground palette, if there is one.
 *	Otherwise, returns NULL.







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * InvalidateSubTreeDepth --
 *
 *	This function recursively updates depth info for a window and
 *	all of its children that belong to the same toplevel.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the depth of each window to that of the display.
 *
 *----------------------------------------------------------------------
 */

static void
InvalidateSubTreeDepth(winPtr)
    TkWindow *winPtr;
{
    Display *display = Tk_Display(winPtr);
    int screenNum = Tk_ScreenNumber(winPtr);
    TkWindow *childPtr;

    winPtr->depth = DefaultDepth(display, screenNum);

#if 0
    /*
     * XXX: What other elements may require changes?  Changing just
     * the depth works for standard windows and 16/24/32-bpp changes.
     * I suspect 8-bit (palettized) displays may require colormap and/or
     * visual changes as well.
     */

    if (winPtr->window) {
	InvalidateRect(Tk_GetHWND(winPtr->window), NULL, FALSE);
    }
    winPtr->visual = DefaultVisual(display, screenNum);
    winPtr->atts.colormap = DefaultColormap(display, screenNum);
    winPtr->dirtyAtts |= CWColormap;
#endif

    for (childPtr = winPtr->childList; childPtr != NULL;
	 childPtr = childPtr->nextPtr) {
	/*
	 * We can stop the descent when we hit a toplevel window, as it
	 * should get its own message.
	 */

	if (!Tk_TopWinHierarchy(childPtr)) {
	    InvalidateSubTreeDepth(childPtr);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinGetSystemPalette --
 *
 *	Retrieves the currently installed foreground palette.
 *
 * Results:
 *	Returns the global foreground palette, if there is one.
 *	Otherwise, returns NULL.
7140
7141
7142
7143
7144
7145
7146










































7147
7148
7149
7150
7151
7152
7153
	    }
	    break;

	case WM_GETMINMAXINFO:
	    SetLimits(hwnd, (MINMAXINFO *) lParam);
	    result = 0;
	    goto done;











































	case WM_PALETTECHANGED:
	    result = InstallColormaps(hwnd, WM_PALETTECHANGED,
		    hwnd == (HWND)wParam);
	    goto done;

	case WM_QUERYNEWPALETTE:







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
	    }
	    break;

	case WM_GETMINMAXINFO:
	    SetLimits(hwnd, (MINMAXINFO *) lParam);
	    result = 0;
	    goto done;

	case WM_DISPLAYCHANGE:
	    /* display and/or color resolution changed */
	    winPtr = GetTopLevel(hwnd);
	    if (winPtr) {
		Screen *screen = Tk_Screen(winPtr);
		if (screen->root_depth != (int) wParam) {
		    /*
		     * Color resolution changed, so do extensive rebuild of
		     * display parameters.  This will affect the display for
		     * all Tk windows.  We will receive this event for each
		     * toplevel, but this check makes us update only once, for
		     * the first toplevel that receives the message.
		     */
		    TkWinDisplayChanged(Tk_Display(winPtr));
		} else {
		    HDC dc = GetDC(NULL);
		    screen->width   = LOWORD(lParam); /* horizontal res */
		    screen->height  = HIWORD(lParam); /* vertical res */
		    screen->mwidth  = MulDiv(screen->width, 254,
			    GetDeviceCaps(dc, LOGPIXELSX) * 10);
		    screen->mheight = MulDiv(screen->height, 254,
			    GetDeviceCaps(dc, LOGPIXELSY) * 10);
		    ReleaseDC(NULL, dc);
		}
		if (Tk_Depth(winPtr) != (int) wParam) {
		    /*
		     * Defer the window depth check to here so that each
		     * toplevel will properly update depth info.
		     */
		    InvalidateSubTreeDepth(winPtr);
		}
	    }
	    result = 0;
	    goto done;

	case WM_SYSCOLORCHANGE:
	    /*
	     * XXX: Called when system color changes.  We need to
	     * update any widgets that use a system color.
	     */
	    break;

	case WM_PALETTECHANGED:
	    result = InstallColormaps(hwnd, WM_PALETTECHANGED,
		    hwnd == (HWND)wParam);
	    goto done;

	case WM_QUERYNEWPALETTE:

Changes to win/tkWinX.c.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tkWinX.c --
 *
 *	This file contains Windows emulation procedures for X routines. 
 *
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright (c) 1994 Software Research Associates, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * 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 $
 */

#include "tkWinInt.h"

/*
 * The w32api 1.1 package (included in Mingw 1.1) does not define _WIN32_IE
 * by default. Define it here to gain access to the InitCommonControlsEx API












|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* 
 * tkWinX.c --
 *
 *	This file contains Windows emulation procedures for X routines. 
 *
 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
 * Copyright (c) 1994 Software Research Associates, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * 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.33 2004/09/23 01:08:12 hobbs Exp $
 */

#include "tkWinInt.h"

/*
 * The w32api 1.1 package (included in Mingw 1.1) does not define _WIN32_IE
 * by default. Define it here to gain access to the InitCommonControlsEx API
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int		
TkWinGetPlatformId()
{
    if (tkPlatformId == 0) {
	OSVERSIONINFO os;

	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&os);







|







349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkWinGetPlatformId()
{
    if (tkPlatformId == 0) {
	OSVERSIONINFO os;

	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	GetVersionEx(&os);
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
 *
 * Side effects:
 *	Could invoke TkWinGetPlatformId.
 *
 *----------------------------------------------------------------------
 */

int		
TkWinGetPlatformTheme()
{
    if (tkPlatformId == 0) {
        TkWinGetPlatformId();
    }
    return tkWinTheme;
}







|







407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
 *
 * Side effects:
 *	Could invoke TkWinGetPlatformId.
 *
 *----------------------------------------------------------------------
 */

int
TkWinGetPlatformTheme()
{
    if (tkPlatformId == 0) {
        TkWinGetPlatformId();
    }
    return tkWinTheme;
}
447
448
449
450
451
452
453






























































































454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
    }
    return screenName;
}

/*
 *----------------------------------------------------------------------
 *






























































































 * TkpOpenDisplay --
 *
 *	Create the Display structure and fill it with device
 *	specific information.
 *
 * Results:
 *	Returns a TkDisplay structure on success or NULL on failure.
 *
 * Side effects:
 *	Allocates a new TkDisplay structure.
 *
 *----------------------------------------------------------------------
 */

TkDisplay *
TkpOpenDisplay(display_name)
    CONST char *display_name;
{
    Screen *screen;
    HDC dc;
    TkWinDrawable *twdPtr;
    Display *display;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->winDisplay != NULL) {
	if (strcmp(tsdPtr->winDisplay->display->display_name, display_name) 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



















<







447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566

567
568
569
570
571
572
573
    }
    return 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
 *	specific information.
 *
 * Results:
 *	Returns a TkDisplay structure on success or NULL on failure.
 *
 * Side effects:
 *	Allocates a new TkDisplay structure.
 *
 *----------------------------------------------------------------------
 */

TkDisplay *
TkpOpenDisplay(display_name)
    CONST char *display_name;
{
    Screen *screen;

    TkWinDrawable *twdPtr;
    Display *display;
    ThreadSpecificData *tsdPtr = (ThreadSpecificData *) 
	    Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData));

    if (tsdPtr->winDisplay != NULL) {
	if (strcmp(tsdPtr->winDisplay->display->display_name, display_name) 
488
489
490
491
492
493
494
495
496
497
498
499

500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579

580
581
582
583
584

585
586
587
588
589

590
591
592
593
594
595
596
    display = (Display *) ckalloc(sizeof(Display));
    ZeroMemory(display, sizeof(Display));

    display->display_name = (char *) ckalloc(strlen(display_name)+1);
    strcpy(display->display_name, display_name);

    display->cursor_font = 1;
    display->nscreens = 1;
    display->request = 1;
    display->qlen = 0;

    screen = (Screen *) ckalloc(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.
     */

    twdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
    if (twdPtr == NULL) {
	return None;
    }
    twdPtr->type = TWD_WINDOW;
    twdPtr->window.winPtr = NULL;
    twdPtr->window.handle = NULL;
    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);


    display->screens		= screen;
    display->nscreens		= 1;
    display->default_screen	= 0;
    screen->cmap = XCreateColormap(display, None, screen->root_visual,

	    AllocNone);
    tsdPtr->winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
    ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
    tsdPtr->winDisplay->display = display;
    tsdPtr->updatingClipboard = FALSE;

    return tsdPtr->winDisplay;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCloseDisplay --







|
|
|


>


<
<
<
<
<
<
<
<














<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<





>




|
>
|




>







581
582
583
584
585
586
587
588
589
590
591
592
593
594
595








596
597
598
599
600
601
602
603
604
605
606
607
608
609



















































610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
    display = (Display *) ckalloc(sizeof(Display));
    ZeroMemory(display, sizeof(Display));

    display->display_name = (char *) ckalloc(strlen(display_name)+1);
    strcpy(display->display_name, display_name);

    display->cursor_font = 1;
    display->nscreens    = 1;
    display->request     = 1;
    display->qlen        = 0;

    screen = (Screen *) ckalloc(sizeof(Screen));
    ZeroMemory(screen, sizeof(Screen));
    screen->display = display;









    /*
     * Set up the root window.
     */

    twdPtr = (TkWinDrawable*) ckalloc(sizeof(TkWinDrawable));
    if (twdPtr == NULL) {
	return None;
    }
    twdPtr->type = TWD_WINDOW;
    twdPtr->window.winPtr = NULL;
    twdPtr->window.handle = NULL;
    screen->root = (Window)twdPtr;

    /*



















































     * 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;

    TkWinDisplayChanged(display);

    tsdPtr->winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay));
    ZeroMemory(tsdPtr->winDisplay, sizeof(TkDisplay));
    tsdPtr->winDisplay->display = display;
    tsdPtr->updatingClipboard = FALSE;

    return tsdPtr->winDisplay;
}

/*
 *----------------------------------------------------------------------
 *
 * TkpCloseDisplay --