X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c978d36124197b5612a2cabefed7591ad0eea6e2..1978421a6d8b81c1f8a961da4b8ddf544fec7b1b:/src/x11/reparent.cpp?ds=inline diff --git a/src/x11/reparent.cpp b/src/x11/reparent.cpp index 349aea15e8..7e76d2334d 100644 --- a/src/x11/reparent.cpp +++ b/src/x11/reparent.cpp @@ -17,10 +17,14 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "reparent.h" #endif +#include "wx/setup.h" + +#if !wxUSE_NANOX + #include "wx/x11/reparent.h" #include "wx/evtloop.h" #include "wx/log.h" @@ -30,57 +34,6 @@ #include "wx/x11/private.h" #include "X11/Xatom.h" -/* - - Adapted from code by Mike Yang, as follows. - -From: Mike Yang (mikey@eukanuba.wpd.sgi.com) -Subject: Re: Wrapping new widget around existing windows -Newsgroups: comp.windows.x -View: Complete Thread (17 articles) | Original Format -Date: 1991-08-09 09:45:48 PST - - -Enough people asked, so here's my test program which reparents another -window. It's a single file (reparent.c), and will work with Motif or -Xaw. Xaw users should comment out the "#define MOTIF" line. - -The reparent program first prompts for the application name of the -client that it will reparent. If you're going to start the -application override_redirect (e.g. -xrm "*overrideRedirect: true"), -then this name is ignored and the first override_redirect window is -assumed to be the one. - -Input focus is supposed to be correctly handled, as is resizing with -window manager hints. If you have input focus problems, try launching -your application override_redirect instead. This method is preferred -anyway, since you can map it off-screen and then avoid the "window -flash" effect as the application's top-level window is reparented. - ------------------------------------------------------------------------ - Mike Yang Silicon Graphics, Inc. - mikey@sgi.com 415/335-1786 - - -------------------------------- cut here ------------------------------ -*/ - -/* - -Copyright 1991 by Mike Yang, mikey@sgi.com, Silicon Graphics, Inc. - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation, and that the name of SGI not be used in advertising or -publicity pertaining to distribution of the software without specific, -written prior permission. SGI makes no representations about the -suitability of this software for any purpose. It is provided "as is" -without express or implied warranty. - -*/ - /* * wxAdoptedWindow */ @@ -91,12 +44,13 @@ wxAdoptedWindow::wxAdoptedWindow() wxAdoptedWindow::wxAdoptedWindow(WXWindow window) { - m_mainWidget = window; + m_mainWindow = window; } wxAdoptedWindow::~wxAdoptedWindow() { } + /* * wxReparenter */ @@ -109,11 +63,10 @@ wxWindow* wxReparenter::sm_newParent = NULL; wxString wxReparenter::sm_name; bool wxReparenter::sm_exactMatch = FALSE; -static int -ErrorHandler(Display* dpy, XErrorEvent* event) +static int ErrorHandler(Display* dpy, XErrorEvent* event) { - Xerror = True; - return False; + Xerror = True; + return False; } // We assume that toReparent has had its X window set @@ -128,15 +81,15 @@ bool wxReparenter::Reparent(wxWindow* newParent, wxAdoptedWindow* toReparent) int parentOffset = 0; old = XSetErrorHandler(ErrorHandler); - XReparentWindow((Display*) newParent->GetXDisplay(), - (Window) toReparent->GetXWindow(), - (Window) newParent->GetXWindow(), - 0, 0); - - if (!XQueryTree((Display*) newParent->GetXDisplay(), - (Window) toReparent->GetXWindow(), - &returnroot, &returnparent, - &children, &numchildren) || Xerror) + XReparentWindow( wxGlobalDisplay(), + (Window) toReparent->GetMainWindow(), + (Window) newParent->GetMainWindow(), + 0, 0); + + if (!XQueryTree( wxGlobalDisplay(), + (Window) toReparent->GetMainWindow(), + &returnroot, &returnparent, + &children, &numchildren) || Xerror) { XSetErrorHandler(old); return TRUE; @@ -144,20 +97,27 @@ bool wxReparenter::Reparent(wxWindow* newParent, wxAdoptedWindow* toReparent) if (numchildren > 0) { - fprintf(stderr, "Reparenting %d children.\n", numchildren); + // TEST: see if we can get away with reparenting just + // first one + if (numchildren > 1) + { + wxLogDebug(wxT("Found %d, but only reparenting 1 child."), numchildren); + numchildren = 1; + } + wxLogDebug(wxT("Reparenting %d children."), numchildren); /* Stacking order is preserved since XQueryTree returns its children in bottommost to topmost order */ for (each=0; eachGetXDisplay(), - children[each], &xwa); + XGetWindowAttributes( wxGlobalDisplay(), + children[each], &xwa); fprintf(stderr, "Reparenting child at offset %d and position %d, %d.\n", parentOffset, parentOffset+xwa.x, parentOffset+xwa.y); - XReparentWindow((Display*) newParent->GetXDisplay(), - children[each], (Window) newParent->GetXWindow(), - xwa.x, xwa.y); + XReparentWindow( wxGlobalDisplay(), + children[each], (Window) newParent->GetMainWindow(), + xwa.x, xwa.y); } } @@ -177,7 +137,7 @@ bool wxReparenter::WaitAndReparent(wxWindow* newParent, wxAdoptedWindow* toRepar sm_exactMatch = exactMatch; sm_name = windowName; - Display* display = (Display*) newParent->GetXDisplay() ; + Display* display = wxGlobalDisplay(); XSelectInput(display, RootWindowOfScreen(DefaultScreenOfDisplay(display)), SubstructureNotifyMask); @@ -209,7 +169,7 @@ bool wxReparenter::WaitAndReparent(wxWindow* newParent, wxAdoptedWindow* toRepar { #if wxUSE_TIMER wxTimer::NotifyTimers(); - wxTheApp->SendIdleEvents(); + wxTheApp->ProcessIdle(); #endif } } @@ -256,67 +216,71 @@ bool wxReparenter::ProcessXEvent(WXEvent* event) WXWindow wxReparenter::FindAClientWindow(WXWindow window, const wxString& name) { - int rvalue, i; - Atom actualtype; - int actualformat; - unsigned long nitems, bytesafter; - unsigned char *propreturn; - Window *children; - unsigned int numchildren; - Window returnroot, returnparent; - Window result = 0; - XErrorHandler old; - char *clientName; - - Xerror = False; - old = XSetErrorHandler(ErrorHandler); - rvalue = XGetWindowProperty((Display*) wxGetDisplay(), - (Window) window, WM_STATE, - 0, 1, False, - AnyPropertyType, &actualtype, &actualformat, - &nitems, &bytesafter, &propreturn); - XSetErrorHandler(old); - if (!Xerror && rvalue == Success && actualtype != None) - { - if (rvalue == Success) - { - XFree((char *) propreturn); - } - XFetchName((Display*) wxGetDisplay(), (Window) window, &clientName); - - wxString str1(name); - wxString str2(clientName); - str1.Lower(); - str2.Lower(); - - bool matches; - if (sm_exactMatch) - matches = (name == clientName); - else - matches = (str1.Contains(str2) || str2.Contains(str1)); - - XFree(clientName); - - if (matches) - return (WXWindow) window; - else - return NULL; - } + int rvalue, i; + Atom actualtype; + int actualformat; + unsigned long nitems, bytesafter; + unsigned char *propreturn; + Window *children; + unsigned int numchildren; + Window returnroot, returnparent; + Window result = 0; + XErrorHandler old; + char *clientName; + + Xerror = False; + old = XSetErrorHandler(ErrorHandler); + rvalue = XGetWindowProperty((Display*) wxGetDisplay(), + (Window) window, WM_STATE, + 0, 1, False, + AnyPropertyType, &actualtype, &actualformat, + &nitems, &bytesafter, &propreturn); - old = XSetErrorHandler(ErrorHandler); - if (!XQueryTree((Display*) wxGetDisplay(), (Window) window, &returnroot, &returnparent, - &children, &numchildren) || Xerror) { XSetErrorHandler(old); - return NULL; - } - XSetErrorHandler(old); - result = 0; - for (i=0; i<(int)numchildren && !result ;i++) { - result = (Window) FindAClientWindow((WXWindow) children[i], name); - } - if (numchildren) { - XFree((char *) children); - } return (WXWindow) result; + if (!Xerror && rvalue == Success && actualtype != None) + { + if (rvalue == Success) + { + XFree((char *) propreturn); + } + XFetchName((Display*) wxGetDisplay(), (Window) window, &clientName); + + wxString str1(name); + wxString str2 = wxString::FromAscii(clientName); + str1.Lower(); + str2.Lower(); + + bool matches; + if (sm_exactMatch) + matches = (name == wxString::FromAscii(clientName)); + else + matches = (str1.Contains(str2) || str2.Contains(str1)); + + XFree(clientName); + + if (matches) + return (WXWindow) window; + else + return NULL; + } + + old = XSetErrorHandler(ErrorHandler); + if (!XQueryTree((Display*) wxGetDisplay(), (Window) window, &returnroot, &returnparent, + &children, &numchildren) || Xerror) + { + XSetErrorHandler(old); + return NULL; + } + XSetErrorHandler(old); + + result = 0; + for (i=0; i<(int)numchildren && !result ;i++) { + result = (Window) FindAClientWindow((WXWindow) children[i], name); + } + if (numchildren) { + XFree((char *) children); + } return (WXWindow) result; } +#endif