OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [insight/] [tk/] [win/] [tkWinEmbed.c] - Diff between revs 578 and 579

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 578 Rev 579
/*
/*
 * tkWinEmbed.c --
 * tkWinEmbed.c --
 *
 *
 *      This file contains platform specific procedures for Windows platforms
 *      This file contains platform specific procedures for Windows platforms
 *      to provide basic operations needed for application embedding (where
 *      to provide basic operations needed for application embedding (where
 *      one application can use as its main window an internal window from
 *      one application can use as its main window an internal window from
 *      another application).
 *      another application).
 *
 *
 * Copyright (c) 1996 Sun Microsystems, Inc.
 * Copyright (c) 1996 Sun Microsystems, Inc.
 *
 *
 * See the file "license.terms" for information on usage and redistribution
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 *
 * RCS: @(#) $Id: tkWinEmbed.c,v 1.1.1.1 2002-01-16 10:26:02 markom Exp $
 * RCS: @(#) $Id: tkWinEmbed.c,v 1.1.1.1 2002-01-16 10:26:02 markom Exp $
 */
 */
 
 
#include "tkWinInt.h"
#include "tkWinInt.h"
 
 
 
 
/*
/*
 * One of the following structures exists for each container in this
 * One of the following structures exists for each container in this
 * application.  It keeps track of the container window and its
 * application.  It keeps track of the container window and its
 * associated embedded window.
 * associated embedded window.
 */
 */
 
 
typedef struct Container {
typedef struct Container {
    HWND parentHWnd;                    /* Windows HWND to the parent window */
    HWND parentHWnd;                    /* Windows HWND to the parent window */
    TkWindow *parentPtr;                /* Tk's information about the container
    TkWindow *parentPtr;                /* Tk's information about the container
                                         * or NULL if the container isn't
                                         * or NULL if the container isn't
                                         * in this process. */
                                         * in this process. */
    HWND embeddedHWnd;                  /* Windows HWND to the embedded window
    HWND embeddedHWnd;                  /* Windows HWND to the embedded window
                                         */
                                         */
    TkWindow *embeddedPtr;              /* Tk's information about the embedded
    TkWindow *embeddedPtr;              /* Tk's information about the embedded
                                         * window, or NULL if the
                                         * window, or NULL if the
                                         * embedded application isn't in
                                         * embedded application isn't in
                                         * this process. */
                                         * this process. */
    struct Container *nextPtr;          /* Next in list of all containers in
    struct Container *nextPtr;          /* Next in list of all containers in
                                         * this process. */
                                         * this process. */
} Container;
} Container;
 
 
static Container *firstContainerPtr = NULL;
static Container *firstContainerPtr = NULL;
                                        /* First in list of all containers
                                        /* First in list of all containers
                                         * managed by this process.  */
                                         * managed by this process.  */
 
 
static void             CleanupContainerList _ANSI_ARGS_((
static void             CleanupContainerList _ANSI_ARGS_((
                            ClientData clientData));
                            ClientData clientData));
static void             ContainerEventProc _ANSI_ARGS_((ClientData clientData,
static void             ContainerEventProc _ANSI_ARGS_((ClientData clientData,
                            XEvent *eventPtr));
                            XEvent *eventPtr));
static void             EmbeddedEventProc _ANSI_ARGS_((
static void             EmbeddedEventProc _ANSI_ARGS_((
                            ClientData clientData, XEvent *eventPtr));
                            ClientData clientData, XEvent *eventPtr));
static void             EmbedGeometryRequest _ANSI_ARGS_((
static void             EmbedGeometryRequest _ANSI_ARGS_((
                            Container*containerPtr, int width, int height));
                            Container*containerPtr, int width, int height));
static void             EmbedWindowDeleted _ANSI_ARGS_((TkWindow *winPtr));
static void             EmbedWindowDeleted _ANSI_ARGS_((TkWindow *winPtr));


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * CleanupContainerList --
 * CleanupContainerList --
 *
 *
 *      Finalizes the list of containers.
 *      Finalizes the list of containers.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Releases memory occupied by containers of embedded windows.
 *      Releases memory occupied by containers of embedded windows.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
static void
static void
CleanupContainerList(clientData)
CleanupContainerList(clientData)
    ClientData clientData;
    ClientData clientData;
{
{
    Container *nextPtr;
    Container *nextPtr;
 
 
    for (;
    for (;
        firstContainerPtr != (Container *) NULL;
        firstContainerPtr != (Container *) NULL;
        firstContainerPtr = nextPtr) {
        firstContainerPtr = nextPtr) {
        nextPtr = firstContainerPtr->nextPtr;
        nextPtr = firstContainerPtr->nextPtr;
        ckfree((char *) firstContainerPtr);
        ckfree((char *) firstContainerPtr);
    }
    }
    firstContainerPtr = (Container *) NULL;
    firstContainerPtr = (Container *) NULL;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpTestembedCmd --
 * TkpTestembedCmd --
 *
 *
 *      Test command for the embedding facility.
 *      Test command for the embedding facility.
 *
 *
 * Results:
 * Results:
 *      Always returns TCL_OK.
 *      Always returns TCL_OK.
 *
 *
 * Side effects:
 * Side effects:
 *      Currently it does not do anything.
 *      Currently it does not do anything.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
        /* ARGSUSED */
        /* ARGSUSED */
int
int
TkpTestembedCmd(clientData, interp, argc, argv)
TkpTestembedCmd(clientData, interp, argc, argv)
    ClientData clientData;
    ClientData clientData;
    Tcl_Interp *interp;
    Tcl_Interp *interp;
    int argc;
    int argc;
    char **argv;
    char **argv;
{
{
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpUseWindow --
 * TkpUseWindow --
 *
 *
 *      This procedure causes a Tk window to use a given Windows handle
 *      This procedure causes a Tk window to use a given Windows handle
 *      for a window as its underlying window, rather than a new Windows
 *      for a window as its underlying window, rather than a new Windows
 *      window being created automatically. It is invoked by an embedded
 *      window being created automatically. It is invoked by an embedded
 *      application to specify the window in which the application is
 *      application to specify the window in which the application is
 *      embedded.
 *      embedded.
 *
 *
 * Results:
 * Results:
 *      The return value is normally TCL_OK. If an error occurred (such as
 *      The return value is normally TCL_OK. If an error occurred (such as
 *      if the argument does not identify a legal Windows window handle),
 *      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
 *      the return value is TCL_ERROR and an error message is left in the
 *      interp->result if interp is not NULL.
 *      interp->result if interp is not NULL.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
int
int
TkpUseWindow(interp, tkwin, string)
TkpUseWindow(interp, tkwin, string)
    Tcl_Interp *interp;         /* If not NULL, used for error reporting
    Tcl_Interp *interp;         /* If not NULL, used for error reporting
                                 * if string is bogus. */
                                 * if string is bogus. */
    Tk_Window tkwin;            /* Tk window that does not yet have an
    Tk_Window tkwin;            /* Tk window that does not yet have an
                                 * associated X window. */
                                 * associated X window. */
    char *string;               /* String identifying an X window to use
    char *string;               /* String identifying an X window to use
                                 * for tkwin;  must be an integer value. */
                                 * for tkwin;  must be an integer value. */
{
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    int id;
    int id;
    HWND hwnd;
    HWND hwnd;
    Container *containerPtr;
    Container *containerPtr;
 
 
    if (winPtr->window != None) {
    if (winPtr->window != None) {
        panic("TkpUseWindow: Already assigned a window");
        panic("TkpUseWindow: Already assigned a window");
    }
    }
 
 
    if (Tcl_GetInt(interp, string, &id) != TCL_OK) {
    if (Tcl_GetInt(interp, string, &id) != TCL_OK) {
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
    hwnd = (HWND) id;
    hwnd = (HWND) id;
 
 
    /*
    /*
     * Check if the window is a valid handle. If it is invalid, return
     * Check if the window is a valid handle. If it is invalid, return
     * TCL_ERROR and potentially leave an error message in interp->result.
     * TCL_ERROR and potentially leave an error message in interp->result.
     */
     */
 
 
    if (!IsWindow(hwnd)) {
    if (!IsWindow(hwnd)) {
        if (interp != (Tcl_Interp *) NULL) {
        if (interp != (Tcl_Interp *) NULL) {
            Tcl_AppendResult(interp, "window \"", string,
            Tcl_AppendResult(interp, "window \"", string,
                    "\" doesn't exist", (char *) NULL);
                    "\" doesn't exist", (char *) NULL);
        }
        }
        return TCL_ERROR;
        return TCL_ERROR;
    }
    }
 
 
    /*
    /*
     * Store the parent window in the platform private data slot so
     * Store the parent window in the platform private data slot so
     * TkWmMapWindow can use it when creating the wrapper window.
     * TkWmMapWindow can use it when creating the wrapper window.
     */
     */
 
 
    winPtr->privatePtr = (struct TkWindowPrivate*) hwnd;
    winPtr->privatePtr = (struct TkWindowPrivate*) hwnd;
 
 
    /*
    /*
     * Create an event handler to clean up the Container structure when
     * Create an event handler to clean up the Container structure when
     * tkwin is eventually deleted.
     * tkwin is eventually deleted.
     */
     */
 
 
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc,
    Tk_CreateEventHandler(tkwin, StructureNotifyMask, EmbeddedEventProc,
            (ClientData) winPtr);
            (ClientData) winPtr);
 
 
    /*
    /*
     * If this is the first container, register an exit handler so that
     * If this is the first container, register an exit handler so that
     * things will get cleaned up at finalization.
     * things will get cleaned up at finalization.
     */
     */
 
 
    if (firstContainerPtr == (Container *) NULL) {
    if (firstContainerPtr == (Container *) NULL) {
        Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL);
        Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL);
    }
    }
 
 
    /*
    /*
     * Save information about the container and the embedded window
     * Save information about the container and the embedded window
     * in a Container structure.  If there is already an existing
     * in a Container structure.  If there is already an existing
     * Container structure, it means that both container and embedded
     * Container structure, it means that both container and embedded
     * app. are in the same process.
     * app. are in the same process.
     */
     */
 
 
    for (containerPtr = firstContainerPtr; containerPtr != NULL;
    for (containerPtr = firstContainerPtr; containerPtr != NULL;
            containerPtr = containerPtr->nextPtr) {
            containerPtr = containerPtr->nextPtr) {
        if (containerPtr->parentHWnd == hwnd) {
        if (containerPtr->parentHWnd == hwnd) {
            winPtr->flags |= TK_BOTH_HALVES;
            winPtr->flags |= TK_BOTH_HALVES;
            containerPtr->parentPtr->flags |= TK_BOTH_HALVES;
            containerPtr->parentPtr->flags |= TK_BOTH_HALVES;
            break;
            break;
        }
        }
    }
    }
    if (containerPtr == NULL) {
    if (containerPtr == NULL) {
        containerPtr = (Container *) ckalloc(sizeof(Container));
        containerPtr = (Container *) ckalloc(sizeof(Container));
        containerPtr->parentPtr = NULL;
        containerPtr->parentPtr = NULL;
        containerPtr->parentHWnd = hwnd;
        containerPtr->parentHWnd = hwnd;
        containerPtr->nextPtr = firstContainerPtr;
        containerPtr->nextPtr = firstContainerPtr;
        firstContainerPtr = containerPtr;
        firstContainerPtr = containerPtr;
    }
    }
 
 
    /*
    /*
     * embeddedHWnd is not created yet. It will be created by TkWmMapWindow(),
     * embeddedHWnd is not created yet. It will be created by TkWmMapWindow(),
     * which will send a TK_ATTACHWINDOW to the container window.
     * which will send a TK_ATTACHWINDOW to the container window.
     * TkWinEmbeddedEventProc will process this message and set the embeddedHWnd
     * TkWinEmbeddedEventProc will process this message and set the embeddedHWnd
     * variable
     * variable
     */
     */
 
 
    containerPtr->embeddedPtr = winPtr;
    containerPtr->embeddedPtr = winPtr;
    containerPtr->embeddedHWnd = NULL;
    containerPtr->embeddedHWnd = NULL;
 
 
    winPtr->flags |= TK_EMBEDDED;
    winPtr->flags |= TK_EMBEDDED;
    winPtr->flags &= (~(TK_MAPPED));
    winPtr->flags &= (~(TK_MAPPED));
 
 
    return TCL_OK;
    return TCL_OK;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpMakeContainer --
 * TkpMakeContainer --
 *
 *
 *      This procedure is called to indicate that a particular window will
 *      This procedure is called to indicate that a particular window will
 *      be a container for an embedded application. This changes certain
 *      be a container for an embedded application. This changes certain
 *      aspects of the window's behavior, such as whether it will receive
 *      aspects of the window's behavior, such as whether it will receive
 *      events anymore.
 *      events anymore.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
TkpMakeContainer(tkwin)
TkpMakeContainer(tkwin)
    Tk_Window tkwin;
    Tk_Window tkwin;
{
{
    TkWindow *winPtr = (TkWindow *) tkwin;
    TkWindow *winPtr = (TkWindow *) tkwin;
    Container *containerPtr;
    Container *containerPtr;
 
 
    /*
    /*
     * If this is the first container, register an exit handler so that
     * If this is the first container, register an exit handler so that
     * things will get cleaned up at finalization.
     * things will get cleaned up at finalization.
     */
     */
 
 
    if (firstContainerPtr == (Container *) NULL) {
    if (firstContainerPtr == (Container *) NULL) {
        Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL);
        Tcl_CreateExitHandler(CleanupContainerList, (ClientData) NULL);
    }
    }
 
 
    /*
    /*
     * Register the window as a container so that, for example, we can
     * Register the window as a container so that, for example, we can
     * find out later if the embedded app. is in the same process.
     * find out later if the embedded app. is in the same process.
     */
     */
 
 
    Tk_MakeWindowExist(tkwin);
    Tk_MakeWindowExist(tkwin);
    containerPtr = (Container *) ckalloc(sizeof(Container));
    containerPtr = (Container *) ckalloc(sizeof(Container));
    containerPtr->parentPtr = winPtr;
    containerPtr->parentPtr = winPtr;
    containerPtr->parentHWnd = Tk_GetHWND(Tk_WindowId(tkwin));
    containerPtr->parentHWnd = Tk_GetHWND(Tk_WindowId(tkwin));
    containerPtr->embeddedHWnd = NULL;
    containerPtr->embeddedHWnd = NULL;
    containerPtr->embeddedPtr = NULL;
    containerPtr->embeddedPtr = NULL;
    containerPtr->nextPtr = firstContainerPtr;
    containerPtr->nextPtr = firstContainerPtr;
    firstContainerPtr = containerPtr;
    firstContainerPtr = containerPtr;
    winPtr->flags |= TK_CONTAINER;
    winPtr->flags |= TK_CONTAINER;
 
 
    /*
    /*
     * Unlike in tkUnixEmbed.c, we don't make any requests for events
     * Unlike in tkUnixEmbed.c, we don't make any requests for events
     * in the embedded window here.  Now we just allow the embedding
     * in the embedded window here.  Now we just allow the embedding
     * of another TK application into TK windows. When the embedded
     * of another TK application into TK windows. When the embedded
     * window makes a request, that will be done by sending to the
     * window makes a request, that will be done by sending to the
     * container window a WM_USER message, which will be intercepted
     * container window a WM_USER message, which will be intercepted
     * by TkWinContainerProc.
     * by TkWinContainerProc.
     *
     *
     * We need to get structure events of the container itself, though.
     * We need to get structure events of the container itself, though.
     */
     */
 
 
    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
    Tk_CreateEventHandler(tkwin, StructureNotifyMask,
        ContainerEventProc, (ClientData) containerPtr);
        ContainerEventProc, (ClientData) containerPtr);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * EmbeddedEventProc --
 * EmbeddedEventProc --
 *
 *
 *      This procedure is invoked by the Tk event dispatcher when various
 *      This procedure is invoked by the Tk event dispatcher when various
 *      useful events are received for a window that is embedded in
 *      useful events are received for a window that is embedded in
 *      another application.
 *      another application.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Our internal state gets cleaned up when an embedded window is
 *      Our internal state gets cleaned up when an embedded window is
 *      destroyed.
 *      destroyed.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static void
static void
EmbeddedEventProc(clientData, eventPtr)
EmbeddedEventProc(clientData, eventPtr)
    ClientData clientData;              /* Token for container window. */
    ClientData clientData;              /* Token for container window. */
    XEvent *eventPtr;                   /* ResizeRequest event. */
    XEvent *eventPtr;                   /* ResizeRequest event. */
{
{
    TkWindow *winPtr = (TkWindow *) clientData;
    TkWindow *winPtr = (TkWindow *) clientData;
 
 
    if (eventPtr->type == DestroyNotify) {
    if (eventPtr->type == DestroyNotify) {
        EmbedWindowDeleted(winPtr);
        EmbedWindowDeleted(winPtr);
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkWinEmbeddedEventProc --
 * TkWinEmbeddedEventProc --
 *
 *
 *      This procedure is invoked by the Tk event dispatcher when
 *      This procedure is invoked by the Tk event dispatcher when
 *      various useful events are received for the *children* of a
 *      various useful events are received for the *children* of a
 *      container window. It forwards relevant information, such as
 *      container window. It forwards relevant information, such as
 *      geometry requests, from the events into the container's
 *      geometry requests, from the events into the container's
 *      application.
 *      application.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Depends on the event.  For example, when ConfigureRequest events
 *      Depends on the event.  For example, when ConfigureRequest events
 *      occur, geometry information gets set for the container window.
 *      occur, geometry information gets set for the container window.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
LRESULT
LRESULT
TkWinEmbeddedEventProc(hwnd, message, wParam, lParam)
TkWinEmbeddedEventProc(hwnd, message, wParam, lParam)
    HWND hwnd;
    HWND hwnd;
    UINT message;
    UINT message;
    WPARAM wParam;
    WPARAM wParam;
    LPARAM lParam;
    LPARAM lParam;
{
{
    Container *containerPtr;
    Container *containerPtr;
 
 
    /*
    /*
     * Find the Container structure associated with the parent window.
     * Find the Container structure associated with the parent window.
     */
     */
 
 
    for (containerPtr = firstContainerPtr;
    for (containerPtr = firstContainerPtr;
            containerPtr->parentHWnd != hwnd;
            containerPtr->parentHWnd != hwnd;
            containerPtr = containerPtr->nextPtr) {
            containerPtr = containerPtr->nextPtr) {
        if (containerPtr == NULL) {
        if (containerPtr == NULL) {
            panic("TkWinContainerProc couldn't find Container record");
            panic("TkWinContainerProc couldn't find Container record");
        }
        }
    }
    }
 
 
    switch (message) {
    switch (message) {
      case TK_ATTACHWINDOW:
      case TK_ATTACHWINDOW:
        /* An embedded window (either from this application or from
        /* An embedded window (either from this application or from
         * another application) is trying to attach to this container.
         * another application) is trying to attach to this container.
         * We attach it only if this container is not yet containing any
         * We attach it only if this container is not yet containing any
         * window.
         * window.
         */
         */
        if (containerPtr->embeddedHWnd == NULL) {
        if (containerPtr->embeddedHWnd == NULL) {
            containerPtr->embeddedHWnd = (HWND)wParam;
            containerPtr->embeddedHWnd = (HWND)wParam;
        } else {
        } else {
            return 0;
            return 0;
        }
        }
 
 
        break;
        break;
      case TK_GEOMETRYREQ:
      case TK_GEOMETRYREQ:
        EmbedGeometryRequest(containerPtr, wParam, lParam);
        EmbedGeometryRequest(containerPtr, wParam, lParam);
        break;
        break;
    }
    }
    return 1;
    return 1;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * EmbedGeometryRequest --
 * EmbedGeometryRequest --
 *
 *
 *      This procedure is invoked when an embedded application requests
 *      This procedure is invoked when an embedded application requests
 *      a particular size.  It processes the request (which may or may
 *      a particular size.  It processes the request (which may or may
 *      not actually resize the window) and reflects the results back
 *      not actually resize the window) and reflects the results back
 *      to the embedded application.
 *      to the embedded application.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      If we deny the child's size change request, a Configure event
 *      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
 *      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
 *      as it used to be.  Events get processed while we're waiting for
 *      the geometry managers to do their thing.
 *      the geometry managers to do their thing.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
EmbedGeometryRequest(containerPtr, width, height)
EmbedGeometryRequest(containerPtr, width, height)
    Container *containerPtr;    /* Information about the container window. */
    Container *containerPtr;    /* Information about the container window. */
    int width, height;          /* Size that the child has requested. */
    int width, height;          /* Size that the child has requested. */
{
{
    TkWindow * winPtr = containerPtr->parentPtr;
    TkWindow * winPtr = containerPtr->parentPtr;
 
 
    /*
    /*
     * Forward the requested size into our geometry management hierarchy
     * Forward the requested size into our geometry management hierarchy
     * via the container window.  We need to send a Configure event back
     * via the container window.  We need to send a Configure event back
     * to the embedded application even if we decide not to resize
     * to the embedded application even if we decide not to resize
     * the window;  to make this happen, process all idle event handlers
     * the window;  to make this happen, process all idle event handlers
     * synchronously here (so that the geometry managers have had a
     * synchronously here (so that the geometry managers have had a
     * chance to do whatever they want to do), and if the window's size
     * chance to do whatever they want to do), and if the window's size
     * didn't change then generate a configure event.
     * didn't change then generate a configure event.
     */
     */
    Tk_GeometryRequest((Tk_Window)winPtr, width, height);
    Tk_GeometryRequest((Tk_Window)winPtr, width, height);
 
 
    if (containerPtr->embeddedHWnd != NULL) {
    if (containerPtr->embeddedHWnd != NULL) {
        while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {
        while (Tcl_DoOneEvent(TCL_IDLE_EVENTS)) {
            /* Empty loop body. */
            /* Empty loop body. */
        }
        }
 
 
        SetWindowPos(containerPtr->embeddedHWnd, NULL,
        SetWindowPos(containerPtr->embeddedHWnd, NULL,
            0, 0, winPtr->changes.width, winPtr->changes.height, SWP_NOZORDER);
            0, 0, winPtr->changes.width, winPtr->changes.height, SWP_NOZORDER);
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * ContainerEventProc --
 * ContainerEventProc --
 *
 *
 *      This procedure is invoked by the Tk event dispatcher when
 *      This procedure is invoked by the Tk event dispatcher when
 *      various useful events are received for the container window.
 *      various useful events are received for the container window.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      Depends on the event.  For example, when ConfigureRequest events
 *      Depends on the event.  For example, when ConfigureRequest events
 *      occur, geometry information gets set for the container window.
 *      occur, geometry information gets set for the container window.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static void
static void
ContainerEventProc(clientData, eventPtr)
ContainerEventProc(clientData, eventPtr)
    ClientData clientData;              /* Token for container window. */
    ClientData clientData;              /* Token for container window. */
    XEvent *eventPtr;                   /* ResizeRequest event. */
    XEvent *eventPtr;                   /* ResizeRequest event. */
{
{
    Container *containerPtr = (Container *)clientData;
    Container *containerPtr = (Container *)clientData;
    Tk_Window tkwin = (Tk_Window)containerPtr->parentPtr;
    Tk_Window tkwin = (Tk_Window)containerPtr->parentPtr;
 
 
    if (eventPtr->type == ConfigureNotify) {
    if (eventPtr->type == ConfigureNotify) {
        if (containerPtr->embeddedPtr == NULL) {
        if (containerPtr->embeddedPtr == NULL) {
            return;
            return;
        }
        }
        /* Resize the embedded window, if there is any */
        /* Resize the embedded window, if there is any */
        if (containerPtr->embeddedHWnd) {
        if (containerPtr->embeddedHWnd) {
            SetWindowPos(containerPtr->embeddedHWnd, NULL,
            SetWindowPos(containerPtr->embeddedHWnd, NULL,
                0, 0, Tk_Width(tkwin), Tk_Height(tkwin), SWP_NOZORDER);
                0, 0, Tk_Width(tkwin), Tk_Height(tkwin), SWP_NOZORDER);
        }
        }
    } else if (eventPtr->type == DestroyNotify) {
    } else if (eventPtr->type == DestroyNotify) {
        /* The container is gone, remove it from the list */
        /* The container is gone, remove it from the list */
        EmbedWindowDeleted(containerPtr->parentPtr);
        EmbedWindowDeleted(containerPtr->parentPtr);
    }
    }
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpGetOtherWindow --
 * TkpGetOtherWindow --
 *
 *
 *      If both the container and embedded window are in the same
 *      If both the container and embedded window are in the same
 *      process, this procedure will return either one, given the other.
 *      process, this procedure will return either one, given the other.
 *
 *
 * Results:
 * Results:
 *      If winPtr is a container, the return value is the token for the
 *      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
 *      embedded window, and vice versa.  If the "other" window isn't in
 *      this process, NULL is returned.
 *      this process, NULL is returned.
 *
 *
 * Side effects:
 * Side effects:
 *      None.
 *      None.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
TkWindow *
TkWindow *
TkpGetOtherWindow(winPtr)
TkpGetOtherWindow(winPtr)
    TkWindow *winPtr;           /* Tk's structure for a container or
    TkWindow *winPtr;           /* Tk's structure for a container or
                                 * embedded window. */
                                 * embedded window. */
{
{
    Container *containerPtr;
    Container *containerPtr;
 
 
    for (containerPtr = firstContainerPtr; containerPtr != NULL;
    for (containerPtr = firstContainerPtr; containerPtr != NULL;
            containerPtr = containerPtr->nextPtr) {
            containerPtr = containerPtr->nextPtr) {
        if (containerPtr->embeddedPtr == winPtr) {
        if (containerPtr->embeddedPtr == winPtr) {
            return containerPtr->parentPtr;
            return containerPtr->parentPtr;
        } else if (containerPtr->parentPtr == winPtr) {
        } else if (containerPtr->parentPtr == winPtr) {
            return containerPtr->embeddedPtr;
            return containerPtr->embeddedPtr;
        }
        }
    }
    }
    panic("TkpGetOtherWindow couldn't find window");
    panic("TkpGetOtherWindow couldn't find window");
    return NULL;
    return NULL;
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpClaimFocus --
 * TkpClaimFocus --
 *
 *
 *      This procedure is invoked when someone asks or the input focus
 *      This procedure is invoked when someone asks or the input focus
 *      to be put on a window in an embedded application, but the
 *      to be put on a window in an embedded application, but the
 *      application doesn't currently have the focus.  It requests the
 *      application doesn't currently have the focus.  It requests the
 *      input focus from the container application.
 *      input focus from the container application.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      The input focus may change.
 *      The input focus may change.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
TkpClaimFocus(topLevelPtr, force)
TkpClaimFocus(topLevelPtr, force)
    TkWindow *topLevelPtr;              /* Top-level window containing desired
    TkWindow *topLevelPtr;              /* Top-level window containing desired
                                         * focus window; should be embedded. */
                                         * focus window; should be embedded. */
    int force;                          /* One means that the container should
    int force;                          /* One means that the container should
                                         * claim the focus if it doesn't
                                         * claim the focus if it doesn't
                                         * currently have it. */
                                         * currently have it. */
{
{
    HWND hwnd = GetParent(Tk_GetHWND(topLevelPtr->window));
    HWND hwnd = GetParent(Tk_GetHWND(topLevelPtr->window));
    SendMessage(hwnd, TK_CLAIMFOCUS, (WPARAM) force, 0);
    SendMessage(hwnd, TK_CLAIMFOCUS, (WPARAM) force, 0);
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * TkpRedirectKeyEvent --
 * TkpRedirectKeyEvent --
 *
 *
 *      This procedure is invoked when a key press or release event
 *      This procedure is invoked when a key press or release event
 *      arrives for an application that does not believe it owns the
 *      arrives for an application that does not believe it owns the
 *      input focus.  This can happen because of embedding; for example,
 *      input focus.  This can happen because of embedding; for example,
 *      X can send an event to an embedded application when the real
 *      X can send an event to an embedded application when the real
 *      focus window is in the container application and is an ancestor
 *      focus window is in the container application and is an ancestor
 *      of the container.  This procedure's job is to forward the event
 *      of the container.  This procedure's job is to forward the event
 *      back to the application where it really belongs.
 *      back to the application where it really belongs.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      The event may get sent to a different application.
 *      The event may get sent to a different application.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
void
void
TkpRedirectKeyEvent(winPtr, eventPtr)
TkpRedirectKeyEvent(winPtr, eventPtr)
    TkWindow *winPtr;           /* Window to which the event was originally
    TkWindow *winPtr;           /* Window to which the event was originally
                                 * reported. */
                                 * reported. */
    XEvent *eventPtr;           /* X event to redirect (should be KeyPress
    XEvent *eventPtr;           /* X event to redirect (should be KeyPress
                                 * or KeyRelease). */
                                 * or KeyRelease). */
{
{
    /* not implemented */
    /* not implemented */
}
}


/*
/*
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 *
 *
 * EmbedWindowDeleted --
 * EmbedWindowDeleted --
 *
 *
 *      This procedure is invoked when a window involved in embedding
 *      This procedure is invoked when a window involved in embedding
 *      (as either the container or the embedded application) is
 *      (as either the container or the embedded application) is
 *      destroyed.  It cleans up the Container structure for the window.
 *      destroyed.  It cleans up the Container structure for the window.
 *
 *
 * Results:
 * Results:
 *      None.
 *      None.
 *
 *
 * Side effects:
 * Side effects:
 *      A Container structure may be freed.
 *      A Container structure may be freed.
 *
 *
 *----------------------------------------------------------------------
 *----------------------------------------------------------------------
 */
 */
 
 
static void
static void
EmbedWindowDeleted(winPtr)
EmbedWindowDeleted(winPtr)
    TkWindow *winPtr;           /* Tk's information about window that
    TkWindow *winPtr;           /* Tk's information about window that
                                 * was deleted. */
                                 * was deleted. */
{
{
    Container *containerPtr, *prevPtr;
    Container *containerPtr, *prevPtr;
 
 
    /*
    /*
     * Find the Container structure for this window work.  Delete the
     * Find the Container structure for this window work.  Delete the
     * information about the embedded application and free the container's
     * information about the embedded application and free the container's
     * record.
     * record.
     */
     */
 
 
    prevPtr = NULL;
    prevPtr = NULL;
    containerPtr = firstContainerPtr;
    containerPtr = firstContainerPtr;
    while (1) {
    while (1) {
        if (containerPtr->embeddedPtr == winPtr) {
        if (containerPtr->embeddedPtr == winPtr) {
            containerPtr->embeddedHWnd = NULL;
            containerPtr->embeddedHWnd = NULL;
            containerPtr->embeddedPtr = NULL;
            containerPtr->embeddedPtr = NULL;
            break;
            break;
        }
        }
        if (containerPtr->parentPtr == winPtr) {
        if (containerPtr->parentPtr == winPtr) {
            containerPtr->parentPtr = NULL;
            containerPtr->parentPtr = NULL;
            break;
            break;
        }
        }
        prevPtr = containerPtr;
        prevPtr = containerPtr;
        containerPtr = containerPtr->nextPtr;
        containerPtr = containerPtr->nextPtr;
        if (containerPtr == NULL) {
        if (containerPtr == NULL) {
            panic("EmbedWindowDeleted couldn't find window");
            panic("EmbedWindowDeleted couldn't find window");
        }
        }
    }
    }
    if ((containerPtr->embeddedPtr == NULL)
    if ((containerPtr->embeddedPtr == NULL)
            && (containerPtr->parentPtr == NULL)) {
            && (containerPtr->parentPtr == NULL)) {
        if (prevPtr == NULL) {
        if (prevPtr == NULL) {
            firstContainerPtr = containerPtr->nextPtr;
            firstContainerPtr = containerPtr->nextPtr;
        } else {
        } else {
            prevPtr->nextPtr = containerPtr->nextPtr;
            prevPtr->nextPtr = containerPtr->nextPtr;
        }
        }
        ckfree((char *) containerPtr);
        ckfree((char *) containerPtr);
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.