📄 tkwinembed.c
字号:
{ TkWindow *winPtr = (TkWindow *) clientData; if (eventPtr->type == DestroyNotify) { EmbedWindowDeleted(winPtr); }}/* *---------------------------------------------------------------------- * * TkWinEmbeddedEventProc -- * * This procedure is invoked by the Tk event dispatcher when * various useful events are received for the *children* of a * container window. It forwards relevant information, such as * geometry requests, from the events into the container's * application. * * Results: * None. * * Side effects: * Depends on the event. For example, when ConfigureRequest events * occur, geometry information gets set for the container window. * *---------------------------------------------------------------------- */LRESULTTkWinEmbeddedEventProc(hwnd, message, wParam, lParam) HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam;{ Container *containerPtr; /* * Find the Container structure associated with the parent window. */ for (containerPtr = firstContainerPtr; containerPtr->parentHWnd != hwnd; containerPtr = containerPtr->nextPtr) { if (containerPtr == NULL) { panic("TkWinContainerProc couldn't find Container record"); } } switch (message) { case TK_ATTACHWINDOW: /* An embedded window (either from this application or from * another application) is trying to attach to this container. * We attach it only if this container is not yet containing any * window. */ if (containerPtr->embeddedHWnd == NULL) { containerPtr->embeddedHWnd = (HWND)wParam; } else { return 0; } break; case TK_GEOMETRYREQ: EmbedGeometryRequest(containerPtr, wParam, lParam); break; } return 1;}/* *---------------------------------------------------------------------- * * EmbedGeometryRequest -- * * This procedure is invoked when an embedded application requests * a particular size. It processes the request (which may or may * not actually resize the window) and reflects the results back * to the embedded application. * * Results: * None. * * Side effects: * If we deny the child's size change request, a Configure event * is synthesized to let the child know that the size is the same * as it used to be. Events get processed while we're waiting for * the geometry managers to do their thing. * *---------------------------------------------------------------------- */voidEmbedGeometryRequest(containerPtr, width, height) Container *containerPtr; /* Information about the container window. */ int width, height; /* Size that the child has requested. */{ TkWindow * winPtr = containerPtr->parentPtr; /* * Forward the requested size into our geometry management hierarchy * via the container window. We need to send a Configure event back * to the embedded application even if we decide not to resize * the window; to make this happen, process all idle event handlers * synchronously here (so that the geometry managers have had a * chance to do whatever they want to do), and if the window's size * didn't change then generate a configure event. */ Tk_GeometryRequest((Tk_Window)winPtr, width, height); if (containerPtr->embeddedHWnd != NULL) { while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) { /* Empty loop body. */ } SetWindowPos(containerPtr->embeddedHWnd, NULL, 0, 0, winPtr->changes.width, winPtr->changes.height, SWP_NOZORDER); }}/* *---------------------------------------------------------------------- * * ContainerEventProc -- * * This procedure is invoked by the Tk event dispatcher when * various useful events are received for the container window. * * Results: * None. * * Side effects: * Depends on the event. For example, when ConfigureRequest events * occur, geometry information gets set for the container window. * *---------------------------------------------------------------------- */static voidContainerEventProc(clientData, eventPtr) ClientData clientData; /* Token for container window. */ XEvent *eventPtr; /* ResizeRequest event. */{ Container *containerPtr = (Container *)clientData; Tk_Window tkwin = (Tk_Window)containerPtr->parentPtr; if (eventPtr->type == ConfigureNotify) { if (containerPtr->embeddedPtr == NULL) { return; } /* Resize the embedded window, if there is any */ if (containerPtr->embeddedHWnd) { SetWindowPos(containerPtr->embeddedHWnd, NULL, 0, 0, Tk_Width(tkwin), Tk_Height(tkwin), SWP_NOZORDER); } } else if (eventPtr->type == DestroyNotify) { /* The container is gone, remove it from the list */ EmbedWindowDeleted(containerPtr->parentPtr); }}/* *---------------------------------------------------------------------- * * TkpGetOtherWindow -- * * If both the container and embedded window are in the same * process, this procedure will return either one, given the other. * * Results: * If winPtr is a container, the return value is the token for the * embedded window, and vice versa. If the "other" window isn't in * this process, NULL is returned. * * Side effects: * None. * *---------------------------------------------------------------------- */TkWindow *TkpGetOtherWindow(winPtr) TkWindow *winPtr; /* Tk's structure for a container or * embedded window. */{ Container *containerPtr; for (containerPtr = firstContainerPtr; containerPtr != NULL; containerPtr = containerPtr->nextPtr) { if (containerPtr->embeddedPtr == winPtr) { return containerPtr->parentPtr; } else if (containerPtr->parentPtr == winPtr) { return containerPtr->embeddedPtr; } } panic("TkpGetOtherWindow couldn't find window"); return NULL;}/* *---------------------------------------------------------------------- * * TkpClaimFocus -- * * This procedure is invoked when someone asks or the input focus * to be put on a window in an embedded application, but the * application doesn't currently have the focus. It requests the * input focus from the container application. * * Results: * None. * * Side effects: * The input focus may change. * *---------------------------------------------------------------------- */voidTkpClaimFocus(topLevelPtr, force) TkWindow *topLevelPtr; /* Top-level window containing desired * focus window; should be embedded. */ int force; /* One means that the container should * claim the focus if it doesn't * currently have it. */{ HWND hwnd = GetParent(Tk_GetHWND(topLevelPtr->window)); SendMessage(hwnd, TK_CLAIMFOCUS, (WPARAM) force, 0);}/* *---------------------------------------------------------------------- * * TkpRedirectKeyEvent -- * * This procedure is invoked when a key press or release event * arrives for an application that does not believe it owns the * input focus. This can happen because of embedding; for example, * X can send an event to an embedded application when the real * focus window is in the container application and is an ancestor * of the container. This procedure's job is to forward the event * back to the application where it really belongs. * * Results: * None. * * Side effects: * The event may get sent to a different application. * *---------------------------------------------------------------------- */voidTkpRedirectKeyEvent(winPtr, eventPtr) TkWindow *winPtr; /* Window to which the event was originally * reported. */ XEvent *eventPtr; /* X event to redirect (should be KeyPress * or KeyRelease). */{ /* not implemented */}/* *---------------------------------------------------------------------- * * EmbedWindowDeleted -- * * This procedure is invoked when a window involved in embedding * (as either the container or the embedded application) is * destroyed. It cleans up the Container structure for the window. * * Results: * None. * * Side effects: * A Container structure may be freed. * *---------------------------------------------------------------------- */static voidEmbedWindowDeleted(winPtr) TkWindow *winPtr; /* Tk's information about window that * was deleted. */{ Container *containerPtr, *prevPtr; /* * Find the Container structure for this window work. Delete the * information about the embedded application and free the container's * record. */ prevPtr = NULL; containerPtr = firstContainerPtr; while (1) { if (containerPtr->embeddedPtr == winPtr) { containerPtr->embeddedHWnd = NULL; containerPtr->embeddedPtr = NULL; break; } if (containerPtr->parentPtr == winPtr) { containerPtr->parentPtr = NULL; break; } prevPtr = containerPtr; containerPtr = containerPtr->nextPtr; if (containerPtr == NULL) { panic("EmbedWindowDeleted couldn't find window"); } } if ((containerPtr->embeddedPtr == NULL) && (containerPtr->parentPtr == NULL)) { if (prevPtr == NULL) { firstContainerPtr = containerPtr->nextPtr; } else { prevPtr->nextPtr = containerPtr->nextPtr; } ckfree((char *) containerPtr); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -