From 3a0b23eb745d4159dcb2ed5f1710444d98807ccf Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 14 Feb 2002 18:06:50 +0000 Subject: [PATCH] Added some XSyncs to help size calculations, but positioning dialog remains a mystery git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/motif/private.h | 31 +------------- include/wx/x11/privx.h | 15 ++----- include/wx/x11/toplevel.h | 4 ++ include/wx/x11/window.h | 3 +- src/univ/renderer.cpp | 1 + src/x11/app.cpp | 17 +++----- src/x11/toplevel.cpp | 88 ++++++++++++++++++++++++++++++++++++++ src/x11/utils.cpp | 8 ++++ src/x11/window.cpp | 25 ++++++++--- 9 files changed, 131 insertions(+), 61 deletions(-) diff --git a/include/wx/motif/private.h b/include/wx/motif/private.h index 9f0c237bf3..ec1f7efa65 100644 --- a/include/wx/motif/private.h +++ b/include/wx/motif/private.h @@ -15,8 +15,7 @@ #include "wx/defs.h" #include "X11/Xlib.h" -class wxMouseEvent; -class wxKeyEvent; +#include "wx/x11/privx.h" // Put any private declarations here: native Motif types may be used because // this header is included after Xm/Xm.h @@ -49,21 +48,12 @@ extern char wxFindMnemonic(const char* s); extern char * wxFindAccelerator (const char *s); extern XmString wxFindAcceleratorText (const char *s); -extern int wxCharCodeXToWX(KeySym keySym); -extern KeySym wxCharCodeWXToX(int id); - // ---------------------------------------------------------------------------- // TranslateXXXEvent() functions - translate Motif event to wxWindow one // ---------------------------------------------------------------------------- extern bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent); extern bool wxTranslateKeyEvent(wxKeyEvent& wxevent, wxWindow *win, Widget widget, XEvent *xevent); -int wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap); -Pixmap XCreateInsensitivePixmap( Display *display, Pixmap pixmap ); - -extern XColor g_itemColors[]; -extern int wxComputeColours (Display *display, wxColour * back, wxColour * fore); - extern void wxDoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour); extern void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, bool changeArmColour = FALSE); @@ -117,24 +107,5 @@ private: extern "C" XtAppContext wxGetAppContext(); -#define wxMAX_RGB 0xff -#define wxMAX_SV 1000 -#define wxSIGN(x) ((x < 0) ? -x : x) -#define wxH_WEIGHT 4 -#define wxS_WEIGHT 1 -#define wxV_WEIGHT 2 - -typedef struct wx_hsv { - int h,s,v; - } wxHSV; - -#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z)) -#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z)) - -void wxHSVToXColor(wxHSV *hsv,XColor *xcolor); -void wxXColorToHSV(wxHSV *hsv,XColor *xcolor); -void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor); -void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor); - #endif // _WX_PRIVATE_H_ diff --git a/include/wx/x11/privx.h b/include/wx/x11/privx.h index a55f980277..5314cda202 100644 --- a/include/wx/x11/privx.h +++ b/include/wx/x11/privx.h @@ -38,18 +38,6 @@ extern int wxComputeColours (Display *display, wxColour * back, wxColour * fore) // For convenience inline Display* wxGlobalDisplay() { return (Display*) wxGetDisplay(); } -#define wxNO_COLORS 0x00 -#define wxBACK_COLORS 0x01 -#define wxFORE_COLORS 0x02 - -extern XColor itemColors[5] ; - -#define wxBACK_INDEX 0 -#define wxFORE_INDEX 1 -#define wxSELE_INDEX 2 -#define wxTOPS_INDEX 3 -#define wxBOTS_INDEX 4 - #define wxMAX_RGB 0xff #define wxMAX_SV 1000 #define wxSIGN(x) ((x < 0) ? -x : x) @@ -74,5 +62,8 @@ void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor); wxString wxGetXEventName(XEvent& event); #endif +// Is the window visible? +bool wxWindowIsVisible(Window win); + #endif // _WX_PRIVX_H_ diff --git a/include/wx/x11/toplevel.h b/include/wx/x11/toplevel.h index de89221ca1..4f66abbf4b 100644 --- a/include/wx/x11/toplevel.h +++ b/include/wx/x11/toplevel.h @@ -78,6 +78,10 @@ protected: virtual void DoGetClientSize( int *width, int *height ) const; virtual void DoSetClientSize(int width, int height); + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); + virtual void DoGetPosition( int *x, int *y ) const; // is the frame currently iconized? bool m_iconized; diff --git a/include/wx/x11/window.h b/include/wx/x11/window.h index f79d378d50..426505a5fd 100644 --- a/include/wx/x11/window.h +++ b/include/wx/x11/window.h @@ -156,11 +156,10 @@ protected: protected: WXWindow m_mainWidget; - wxRegion m_clearRegion; bool m_clipPaintRegion; - bool m_winCaptured; // ???? + bool m_needsInputFocus; // Input focus set in OnIdle // implement the base class pure virtuals virtual void DoClientToScreen( int *x, int *y ) const; diff --git a/src/univ/renderer.cpp b/src/univ/renderer.cpp index 16c2c2de04..4053fbf68f 100644 --- a/src/univ/renderer.cpp +++ b/src/univ/renderer.cpp @@ -417,6 +417,7 @@ wxControlRenderer::wxControlRenderer(wxWindow *window, void wxControlRenderer::DrawLabel(const wxBitmap& bitmap, wxCoord marginX, wxCoord marginY) { + m_dc.SetBackgroundMode(wxTRANSPARENT); m_dc.SetFont(m_window->GetFont()); m_dc.SetTextForeground(m_window->GetForegroundColour()); diff --git a/src/x11/app.cpp b/src/x11/app.cpp index 232b4ec21c..4d43a26b17 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -66,14 +66,6 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) EVT_IDLE(wxApp::OnIdle) END_EVENT_TABLE() -static const wxCmdLineEntryDesc g_cmdLineDesc[] = -{ - { wxCMD_LINE_SWITCH, "sync", "sync", "synchronize the display" }, - { wxCMD_LINE_OPTION, "display", "display", "use the given display", wxCMD_LINE_VAL_STRING }, - - { wxCMD_LINE_NONE } -}; - #ifdef __WXDEBUG__ typedef int (*XErrorHandlerFunc)(Display *, XErrorEvent *); @@ -179,9 +171,7 @@ int wxEntryStart( int& argc, char *argv[] ) /// TODO #if 0 - // Parse the arguments. Is it OK to use the command line - // parser before calling Initialize? - wxCmdLineParser cmdLine(argv, argv); + // Parse the arguments. #endif Display* xdisplay = XOpenDisplay(NULL); @@ -413,7 +403,10 @@ void wxApp::ProcessXEvent(WXEvent* _event) return; } case ClientMessage: - { + { + if (win && !win->IsEnabled()) + return; + Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);; Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);; diff --git a/src/x11/toplevel.cpp b/src/x11/toplevel.cpp index 68e4ef5aa3..632a4e48b7 100644 --- a/src/x11/toplevel.cpp +++ b/src/x11/toplevel.cpp @@ -457,6 +457,7 @@ void wxTopLevelWindowX11::DoGetClientSize( int *width, int *height ) const void wxTopLevelWindowX11::DoSetClientSize(int width, int height) { wxWindowX11::DoSetClientSize(width, height); + #if 0 if (!GetMainWindow()) return; @@ -478,3 +479,90 @@ void wxTopLevelWindowX11::DoSetClientSize(int width, int height) valueMask, & windowChanges); #endif } + +void wxTopLevelWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) +{ + wxString msg; + msg.Printf("Setting pos: %d, %d", x, y); + wxLogDebug(msg); + wxWindowX11::DoSetSize(x, y, width, height, sizeFlags); + + wxPoint pt = GetPosition(); + msg.Printf("After, pos: %d, %d", pt.x, pt.y); + wxLogDebug(msg); +#if 0 + XSync(wxGlobalDisplay(), False); + int w, h; + GetSize(& w, & h); + wxString msg; + msg.Printf("Before setting size: %d, %d", w, h); + wxLogDebug(msg); + if (!GetMainWindow()) + return; + + XWindowChanges windowChanges; + int valueMask = 0; + + if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + { + int yy = 0; + AdjustForParentClientOrigin( x, yy, sizeFlags); + windowChanges.x = x; + valueMask |= CWX; + } + if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + { + int xx = 0; + AdjustForParentClientOrigin( xx, y, sizeFlags); + windowChanges.y = y; + valueMask |= CWY; + } + if (width != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + { + windowChanges.width = width /* - m_borderSize*2 */; + valueMask |= CWWidth; + } + if (height != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) + { + windowChanges.height = height /* -m_borderSize*2*/; + valueMask |= CWHeight; + } + + XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), + valueMask, & windowChanges); + XSync(wxGlobalDisplay(), False); + GetSize(& w, & h); + msg.Printf("Tried to set to %d, %d. After setting size: %d, %d", width, height, w, h); + wxLogDebug(msg); +#endif +} + +void wxTopLevelWindowX11::DoGetPosition(int *x, int *y) const +{ + XSync(wxGlobalDisplay(), False); + Window window = (Window) m_mainWidget; + if (window) + { + int offsetX = 0; + int offsetY = 0; + + wxLogDebug("Translating..."); + Window childWindow; + XTranslateCoordinates(wxGlobalDisplay(), window, XDefaultRootWindow(wxGlobalDisplay()), + 0, 0, & offsetX, & offsetY, & childWindow); + + wxString msg; + msg.Printf("Offset: %d, %d", offsetX, offsetY); + wxLogDebug(msg); + + XWindowAttributes attr; + Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); + wxASSERT(status); + + if (status) + { + *x = attr.x + offsetX; + *y = attr.y + offsetY; + } + } +} diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 7d6e1f93ba..c85fcac9ef 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -1231,3 +1231,11 @@ void wxDoChangeBackgroundColour(WXWidget widget, wxColour& backgroundColour, boo #endif // __WXMOTIF__ + +bool wxWindowIsVisible(Window win) +{ + XWindowAttributes wa; + XGetWindowAttributes(wxGlobalDisplay(), win, &wa); + + return (wa.map_state == IsViewable); +} diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 3e2f313bae..14e0a315f9 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -93,12 +93,10 @@ void wxWindowX11::Init() // X11-specific m_mainWidget = (WXWindow) 0; - m_winCaptured = FALSE; - + m_needsInputFocus = FALSE; m_isShown = TRUE; m_isBeingDeleted = FALSE; - m_lastTS = 0; m_lastButton = 0; } @@ -209,8 +207,16 @@ void wxWindowX11::SetFocus() Window xwindow = (Window) GetMainWindow(); wxCHECK_RET( xwindow, wxT("invalid window") ); - - XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); + + if (wxWindowIsVisible(xwindow)) + { + XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime ); + m_needsInputFocus = FALSE; + } + else + { + m_needsInputFocus = TRUE; + } } // Get the window with the focus @@ -651,6 +657,7 @@ void wxWindowX11::DoGetSize(int *x, int *y) const wxCHECK_RET( xwindow, wxT("invalid window") ); + XSync(wxGlobalDisplay(), False); XWindowAttributes attr; Status status = XGetWindowAttributes( wxGlobalDisplay(), xwindow, &attr ); wxASSERT(status); @@ -667,6 +674,7 @@ void wxWindowX11::DoGetPosition(int *x, int *y) const Window window = (Window) m_mainWidget; if (window) { + XSync(wxGlobalDisplay(), False); XWindowAttributes attr; Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); wxASSERT(status); @@ -720,6 +728,7 @@ void wxWindowX11::DoGetClientSize(int *x, int *y) const if (window) { + XSync(wxGlobalDisplay(), False); XWindowAttributes attr; Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr ); wxASSERT(status); @@ -767,6 +776,7 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags) XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), valueMask, & windowChanges); + XSync(wxGlobalDisplay(), False); } void wxWindowX11::DoSetClientSize(int width, int height) @@ -789,6 +799,7 @@ void wxWindowX11::DoSetClientSize(int width, int height) } XConfigureWindow(wxGlobalDisplay(), (Window) GetMainWindow(), valueMask, & windowChanges); + XSync(wxGlobalDisplay(), False); } // For implementation purposes - sometimes decorations make the client area @@ -1040,6 +1051,10 @@ void wxWindowX11::OnInternalIdle() // This calls the UI-update mechanism (querying windows for // menu/toolbar/control state information) UpdateWindowUI(); + + // Set the input focus if couldn't do it before + if (m_needsInputFocus) + SetFocus(); } // ---------------------------------------------------------------------------- -- 2.45.2