?? tkwinembed.c
字號:
/* * tkWinEmbed.c -- * * This file contains platform specific procedures for Windows platforms * to provide basic operations needed for application embedding (where * one application can use as its main window an internal window from * another application). * * Copyright (c) 1996 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * * SCCS: @(#) tkWinEmbed.c 1.20 97/11/05 17:47:09; */#include "tkWinInt.h"/* * One of the following structures exists for each container in this * application. It keeps track of the container window and its * associated embedded window. */typedef struct Container { HWND parentHWnd; /* Windows HWND to the parent window */ TkWindow *parentPtr; /* Tk's information about the container * or NULL if the container isn't * in this process. */ HWND embeddedHWnd; /* Windows HWND to the embedded window */ TkWindow *embeddedPtr; /* Tk's information about the embedded * window, or NULL if the * embedded application isn't in * this process. */ struct Container *nextPtr; /* Next in list of all containers in * this process. */} Container;static Container *firstContainerPtr = NULL; /* First in list of all containers * managed by this process. */static void CleanupContainerList _ANSI_ARGS_(( ClientData clientData));static void ContainerEventProc _ANSI_ARGS_((ClientData clientData, XEvent *eventPtr));static void EmbeddedEventProc _ANSI_ARGS_(( ClientData clientData, XEvent *eventPtr));static void EmbedGeometryRequest _ANSI_ARGS_(( Container*containerPtr, int width, int height));static void EmbedWindowDeleted _ANSI_ARGS_((TkWindow *winPtr));/* *---------------------------------------------------------------------- * * CleanupContainerList -- * * Finalizes the list of containers. * * Results: * None. * * Side effects: * Releases memory occupied by containers of embedded windows. * *---------------------------------------------------------------------- */ /* ARGSUSED */static voidCleanupContainerList(clientData) ClientData clientData;{ Container *nextPtr; for (; firstContainerPtr != (Container *) NULL; firstContainerPtr = nextPtr) { nextPtr = firstContainerPtr->nextPtr; ckfree((char *) firstContainerPtr); } firstContainerPtr = (Container *) NULL;}/* *---------------------------------------------------------------------- * * TkpTestembedCmd -- * * Test command for the embedding facility. * * Results: * Always returns TCL_OK. * * Side effects: * Currently it does not do anything. * *---------------------------------------------------------------------- */ /* ARGSUSED */intTkpTestembedCmd(clientData, interp, argc, argv) ClientData clientData; Tcl_Interp *interp; int argc; char **argv;{ return TCL_OK;}/* *---------------------------------------------------------------------- * * TkpUseWindow -- * * This procedure causes a Tk window to use a given Windows handle * for a window as its underlying window, rather than a new Windows * window being created automatically. It is invoked by an embedded * application to specify the window in which the application is * embedded. * * Results: * The return value is normally TCL_OK. If an error occurred (such as * if the argument does not identify a legal Windows window handle), * the return value is TCL_ERROR and an error message is left in the * interp->result if interp is not NULL. * * Side effects: * None. * *---------------------------------------------------------------------- */int TkpUseWindow(interp, tkwin, string) Tcl_Interp *interp; /* If not NULL, used for error reporting * if string is bogus. */ Tk_Window tkwin; /* Tk window that does not yet have an * associated X window. */ char *string; /* String identifying an X window to use * for tkwin; must be an integer value. */{ TkWindow *winPtr = (TkWindow *) tkwin; int id; HWND hwnd; Container *containerPtr; if (winPtr->window != None) { panic("TkpUseWindow: Already assigned a window"); } if (Tcl_GetInt(interp, string, &id) != TCL_OK) { return TCL_ERROR; } hwnd = (HWND) id; /* * Check if the window is a valid handle. If it is invalid, return * TCL_ERROR and potentially leave an error message in interp->result. */ if (!IsWindow(hwnd)) { if (interp != (Tcl_Interp *) NULL) { Tcl_AppendResult(interp, "window \"", string, "\" doesn't exist", (char *) NULL); } return TCL_ERROR; } /* * Store the parent window in the platform private data slot so * TkWmMapWindow can use it when creating the wrapper window. */ winPtr->privatePtr = (struct TkWindowPrivate*) hwnd; /* * Create an event handler to clean up the Container structure when * tkwin is eventually deleted. */ Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc, (ClientData) winPtr); /* * If this is the first container, register an exit handler so that * things will get cleaned up at finalization. */ if (firstContainerPtr == (Container *) NULL) { Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL); } /* * Save information about the container and the embedded window * in a Container structure. If there is already an existing * Container structure, it means that both container and embedded * app. are in the same process. */ for (containerPtr = firstContainerPtr; containerPtr != NULL; containerPtr = containerPtr->nextPtr) { if (containerPtr->parentHWnd == hwnd) { winPtr->flags |= TK_BOTH_HALVES; containerPtr->parentPtr->flags |= TK_BOTH_HALVES; break; } } if (containerPtr == NULL) { containerPtr = (Container *) ckalloc(sizeof(Container)); containerPtr->parentPtr = NULL; containerPtr->parentHWnd = hwnd; containerPtr->nextPtr = firstContainerPtr; firstContainerPtr = containerPtr; } /* * embeddedHWnd is not created yet. It will be created by TkWmMapWindow(), * which will send a TK_ATTACHWINDOW to the container window. * TkWinEmbeddedEventProc will process this message and set the embeddedHWnd * variable */ containerPtr->embeddedPtr = winPtr; containerPtr->embeddedHWnd = NULL; winPtr->flags |= TK_EMBEDDED; winPtr->flags &= (~(TK_MAPPED)); return TCL_OK;}/* *---------------------------------------------------------------------- * * TkpMakeContainer -- * * This procedure is called to indicate that a particular window will * be a container for an embedded application. This changes certain * aspects of the window's behavior, such as whether it will receive * events anymore. * * Results: * None. * * Side effects: * None. * *---------------------------------------------------------------------- */voidTkpMakeContainer(tkwin) Tk_Window tkwin;{ TkWindow *winPtr = (TkWindow *) tkwin; Container *containerPtr; /* * If this is the first container, register an exit handler so that * things will get cleaned up at finalization. */ if (firstContainerPtr == (Container *) NULL) { Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL); } /* * Register the window as a container so that, for example, we can * find out later if the embedded app. is in the same process. */ Tk_MakeWindowExist(tkwin); containerPtr = (Container *) ckalloc(sizeof(Container)); containerPtr->parentPtr = winPtr; containerPtr->parentHWnd = Tk_GetHWND(Tk_WindowId(tkwin)); containerPtr->embeddedHWnd = NULL; containerPtr->embeddedPtr = NULL; containerPtr->nextPtr = firstContainerPtr; firstContainerPtr = containerPtr; winPtr->flags |= TK_CONTAINER; /* * Unlike in tkUnixEmbed.c, we don't make any requests for events * in the embedded window here. Now we just allow the embedding * of another TK application into TK windows. When the embedded * window makes a request, that will be done by sending to the * container window a WM_USER message, which will be intercepted * by TkWinContainerProc. * * We need to get structure events of the container itself, though. */ Tk_CreateEventHandler(tkwin, StructureNotifyMask, ContainerEventProc, (ClientData) containerPtr);}/* *---------------------------------------------------------------------- * * EmbeddedEventProc -- * * This procedure is invoked by the Tk event dispatcher when various * useful events are received for a window that is embedded in * another application. * * Results: * None. * * Side effects: * Our internal state gets cleaned up when an embedded window is * destroyed. * *---------------------------------------------------------------------- */static voidEmbeddedEventProc(clientData, eventPtr) ClientData clientData; /* Token for container window. */ XEvent *eventPtr; /* ResizeRequest event. */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -