📄 tkwinx.c
字号:
/* * 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. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkWinX.c 1.51 97/09/02 13:06:57 */#include "tkInt.h"#include "tkWinInt.h"/* * Definitions of extern variables supplied by this file. */int tkpIsWin32s = -1;/* * Declarations of static variables used in this file. */static HINSTANCE tkInstance = (HINSTANCE) NULL; /* Global application instance handle. */static TkDisplay *winDisplay; /* Display that represents Windows screen. */static char winScreenName[] = ":0"; /* Default name of windows display. */static WNDCLASS childClass; /* Window class for child windows. */static childClassInitialized = 0; /* Registered child class? *//* * Forward declarations of procedures used in this file. */static void GenerateXEvent _ANSI_ARGS_((HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam));static unsigned int GetState _ANSI_ARGS_((UINT message, WPARAM wParam, LPARAM lParam));static void GetTranslatedKey _ANSI_ARGS_((XKeyEvent *xkey));/* *---------------------------------------------------------------------- * * TkGetServerInfo -- * * Given a window, this procedure returns information about * the window server for that window. This procedure provides * the guts of the "winfo server" command. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */voidTkGetServerInfo(interp, tkwin) Tcl_Interp *interp; /* The server information is returned in * this interpreter's result. */ Tk_Window tkwin; /* Token for window; this selects a * particular display and server. */{ char buffer[50]; OSVERSIONINFO info; info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&info); sprintf(buffer, "Windows %d.%d %d ", info.dwMajorVersion, info.dwMinorVersion, info.dwBuildNumber); Tcl_AppendResult(interp, buffer, (info.dwPlatformId == VER_PLATFORM_WIN32s) ? "Win32s" : "Win32", (char *) NULL);}/* *---------------------------------------------------------------------- * * Tk_GetHINSTANCE -- * * Retrieves the global instance handle used by the Tk library. * * Results: * Returns the global instance handle. * * Side effects: * None. * *---------------------------------------------------------------------- */HINSTANCETk_GetHINSTANCE(){ return tkInstance;}/* *---------------------------------------------------------------------- * * TkWinXInit -- * * Initialize Xlib emulation layer. * * Results: * None. * * Side effects: * Sets up various data structures. * *---------------------------------------------------------------------- */voidTkWinXInit(hInstance) HINSTANCE hInstance;{ OSVERSIONINFO info; info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&info); tkpIsWin32s = (info.dwPlatformId == VER_PLATFORM_WIN32s); if (childClassInitialized != 0) { return; } childClassInitialized = 1; tkInstance = hInstance; childClass.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC; childClass.cbClsExtra = 0; childClass.cbWndExtra = 0; childClass.hInstance = hInstance; childClass.hbrBackground = NULL; childClass.lpszMenuName = NULL; /* * Register the Child window class. */ childClass.lpszClassName = TK_WIN_CHILD_CLASS_NAME; childClass.lpfnWndProc = TkWinChildProc; childClass.hIcon = NULL; childClass.hCursor = NULL; if (!RegisterClass(&childClass)) { panic("Unable to register TkChild class"); }#ifdef USE_CKGRAPH_IMP TkWinGdiInit(hInstance);#endif}/* *---------------------------------------------------------------------- * * TkWinXCleanup -- * * Removes the registered classes for Tk. * * Results: * None. * * Side effects: * Removes window classes from the system. * *---------------------------------------------------------------------- */voidTkWinXCleanup(hInstance) HINSTANCE hInstance;{ /* * Clean up our own class. */ if (childClassInitialized) { childClassInitialized = 0; UnregisterClass(TK_WIN_CHILD_CLASS_NAME, hInstance); } /* * And let the window manager clean up its own class(es). */ TkWinWmCleanup(hInstance);#ifdef USE_CKGRAPH_IMP TkWinGdiCleanup(hInstance);#endif}/* *---------------------------------------------------------------------- * * TkGetDefaultScreenName -- * * Returns the name of the screen that Tk should use during * initialization. * * Results: * Returns a statically allocated string. * * Side effects: * None. * *---------------------------------------------------------------------- */char *TkGetDefaultScreenName(interp, screenName) Tcl_Interp *interp; /* Not used. */ char *screenName; /* If NULL, use default string. */{ if ((screenName == NULL) || (screenName[0] == '\0')) { screenName = winScreenName; } return screenName;}/* *---------------------------------------------------------------------- * * TkpOpenDisplay -- * * Create the Display structure and fill it with device * specific information. * * Results: * Returns a Display structure on success or NULL on failure. * * Side effects: * Allocates a new Display structure. * *---------------------------------------------------------------------- */TkDisplay *TkpOpenDisplay(display_name) char *display_name;{ Screen *screen; HDC dc; TkWinDrawable *twdPtr; Display *display; if (winDisplay != NULL) { if (strcmp(winDisplay->display->display_name, display_name) == 0) { return winDisplay; } else { return NULL; } } display = (Display *) ckalloc(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 = TkWinGetNULLDC(); 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; TkWinReleaseNULLDC(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); winDisplay = (TkDisplay *) ckalloc(sizeof(TkDisplay)); winDisplay->display = display; return winDisplay;}/* *---------------------------------------------------------------------- * * TkpCloseDisplay -- * * Closes and deallocates a Display structure created with the * TkpOpenDisplay function. * * Results: * None. * * Side effects: * Frees up memory. * *---------------------------------------------------------------------- */voidTkpCloseDisplay(dispPtr) TkDisplay *dispPtr;{ Display *display = dispPtr->display; HWND hwnd; if (dispPtr != winDisplay) { panic("TkpCloseDisplay: tried to call TkpCloseDisplay on another display"); return; } /* * Force the clipboard to be rendered if we are the clipboard owner. */ if (dispPtr->clipWindow) { hwnd = Tk_GetHWND(Tk_WindowId(dispPtr->clipWindow)); if (GetClipboardOwner() == hwnd) { OpenClipboard(hwnd); EmptyClipboard(); TkWinClipboardRender(dispPtr, CF_TEXT); CloseClipboard(); } } winDisplay = NULL; if (display->display_name != (char *) NULL) { ckfree(display->display_name); } if (display->screens != (Screen *) NULL) { if (display->screens->root_visual != NULL) { ckfree((char *) display->screens->root_visual); } if (display->screens->root != None) { ckfree((char *) display->screens->root); } if (display->screens->cmap != None) { XFreeColormap(display, display->screens->cmap); } ckfree((char *) display->screens); } ckfree((char *) display); ckfree((char *) dispPtr);}/* *---------------------------------------------------------------------- * * XBell -- * * Generate a beep. * * Results: * None. * * Side effects: * Plays a sounds out the system speakers. * *---------------------------------------------------------------------- */voidXBell(display, percent) Display* display; int percent;{ MessageBeep(MB_OK);}/* *---------------------------------------------------------------------- * * TkWinChildProc -- * * Callback from Windows whenever an event occurs on a child * window. * * Results: * Standard Windows return value. * * Side effects: * May process events off the Tk event queue. * *---------------------------------------------------------------------- */LRESULT CALLBACKTkWinChildProc(hwnd, message, wParam, lParam) HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam;{ LRESULT result; switch (message) { case WM_SETCURSOR: /* * Short circuit the WM_SETCURSOR message since we set * the cursor elsewhere. */ result = TRUE; break; case WM_CREATE: case WM_ERASEBKGND: case WM_WINDOWPOSCHANGED: result = 0; break; case WM_PAINT: GenerateXEvent(hwnd, message, wParam, lParam); result = DefWindowProc(hwnd, message, wParam, lParam); break; case TK_CLAIMFOCUS: case TK_GEOMETRYREQ: case TK_ATTACHWINDOW: case TK_DETACHWINDOW: result = TkWinEmbeddedEventProc(hwnd, message, wParam, lParam); break; default: if (!Tk_TranslateWinEvent(hwnd, message, wParam, lParam, &result)) { result = DefWindowProc(hwnd, message, wParam, lParam); } break; } /* * Handle any newly queued events before returning control to Windows. */ Tcl_ServiceAll(); return result;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -