From 7e4501ee3cc88ee8dd2b75e2964118e2897ec4a2 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 17 Feb 2002 21:09:04 +0000 Subject: [PATCH] wxX11: Corrected TLW positiong. Added experimental code for synthesizing focus events. Minor clean-ups. Added for-now unused code for default/focus widget. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14281 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/x11/toplevel.h | 12 ++++++-- include/wx/x11/window.h | 4 +++ src/gtk/window.cpp | 2 +- src/gtk1/window.cpp | 2 +- src/univ/themes/win32.cpp | 1 + src/x11/app.cpp | 32 +++++++++++-------- src/x11/toplevel.cpp | 25 +++++++++++---- src/x11/window.cpp | 65 ++++++++++++++++++--------------------- 8 files changed, 85 insertions(+), 58 deletions(-) diff --git a/include/wx/x11/toplevel.h b/include/wx/x11/toplevel.h index 4f66abbf4b..1488491844 100644 --- a/include/wx/x11/toplevel.h +++ b/include/wx/x11/toplevel.h @@ -67,6 +67,9 @@ public: // implementation from now on // -------------------------- + + void SetFocusWidget( wxWindow *focus ) { m_focusWidget = focus; } + wxWindow *GetFocusWidget() const { return m_focusWidget; } protected: // common part of all ctors @@ -83,19 +86,22 @@ protected: int sizeFlags = wxSIZE_AUTO); virtual void DoGetPosition( int *x, int *y ) const; - // is the frame currently iconized? + // Is the frame currently iconized? bool m_iconized; - // should the frame be maximized when it will be shown? set by Maximize() + // Should the frame be maximized when it will be shown? set by Maximize() // when it is called while the frame is hidden bool m_maximizeOnShow; // Data to save/restore when calling ShowFullScreen - long m_fsStyle; // Passed to ShowFullScreen + long m_fsStyle; // Passed to ShowFullScreen wxRect m_fsOldSize; bool m_fsIsMaximized; bool m_fsIsShowing; wxString m_title; + + // This widget gets the key input + wxWindow* m_focusWidget; }; // list of all frames and modeless dialogs diff --git a/include/wx/x11/window.h b/include/wx/x11/window.h index 5e747f150d..29b646cafe 100644 --- a/include/wx/x11/window.h +++ b/include/wx/x11/window.h @@ -145,6 +145,10 @@ public: // For compatibility across platforms (not in event table) void OnIdle(wxIdleEvent& WXUNUSED(event)) {} + // Go up to a toplevel window and query which window has the focus. + // May return NULL. + wxWindow *GetFocusWidget(); + protected: // Makes an adjustment to the window position (for example, a frame that has // a toolbar that it manages itself). diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index b2941feb0a..30fae11783 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1640,7 +1640,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, g_focusWindowLast = g_focusWindow = win; -#if 0 +#if 1 wxPrintf( "OnSetFocus from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) wxPrintf( win->GetClassInfo()->GetClassName() ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index b2941feb0a..30fae11783 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -1640,7 +1640,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, g_focusWindowLast = g_focusWindow = win; -#if 0 +#if 1 wxPrintf( "OnSetFocus from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) wxPrintf( win->GetClassInfo()->GetClassName() ); diff --git a/src/univ/themes/win32.cpp b/src/univ/themes/win32.cpp index e30f0b3ec0..56a353951f 100644 --- a/src/univ/themes/win32.cpp +++ b/src/univ/themes/win32.cpp @@ -3935,6 +3935,7 @@ bool wxWin32InputHandler::HandleMouse(wxInputConsumer *control, if ( event.ButtonDown() ) { wxWindow *win = control->GetInputWindow(); + if ( wxWindow::FindFocus() != control->GetInputWindow() ) { win->SetFocus(); diff --git a/src/x11/app.cpp b/src/x11/app.cpp index d2e082414b..511b5fb034 100644 --- a/src/x11/app.cpp +++ b/src/x11/app.cpp @@ -251,7 +251,7 @@ int wxEntryStart( int& argc, char *argv[] ) XSelectInput( xdisplay, XDefaultRootWindow(xdisplay), PropertyChangeMask); -// wxSetDetectableAutoRepeat( TRUE ); + wxSetDetectableAutoRepeat( TRUE ); if (!wxApp::Initialize()) return -1; @@ -484,8 +484,8 @@ void wxApp::ProcessXEvent(WXEvent* _event) if (win && !win->IsEnabled()) return; - Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True);; - Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True);; + Atom wm_delete_window = XInternAtom(wxGlobalDisplay(), "WM_DELETE_WINDOW", True); + Atom wm_protocols = XInternAtom(wxGlobalDisplay(), "WM_PROTOCOLS", True); if (event->xclient.message_type == wm_protocols) { @@ -555,9 +555,9 @@ void wxApp::ProcessXEvent(WXEvent* _event) { if (win) { - wxLogDebug( "GraphicsExpose from %s", win->GetName().c_str(), - event->xgraphicsexpose.x, event->xgraphicsexpose.y, - event->xgraphicsexpose.width, event->xgraphicsexpose.height); + // wxLogDebug( "GraphicsExpose from %s", win->GetName().c_str(), + // event->xgraphicsexpose.x, event->xgraphicsexpose.y, + // event->xgraphicsexpose.width, event->xgraphicsexpose.height); win->GetUpdateRegion().Union( event->xgraphicsexpose.x, event->xgraphicsexpose.y, event->xgraphicsexpose.width, event->xgraphicsexpose.height); @@ -577,15 +577,23 @@ void wxApp::ProcessXEvent(WXEvent* _event) case ButtonRelease: case MotionNotify: { - if (win && !win->IsEnabled()) + if (!win) return; - - if (win) + + if (!win->IsEnabled()) + return; + +#if 1 + if (event->type == ButtonPress) { - wxMouseEvent wxevent; - wxTranslateMouseEvent(wxevent, win, window, event); - win->GetEventHandler()->ProcessEvent( wxevent ); + if ((win != wxWindow::FindFocus()) && win->AcceptsFocus()) + win->SetFocus(); } +#endif + + wxMouseEvent wxevent; + wxTranslateMouseEvent(wxevent, win, window, event); + win->GetEventHandler()->ProcessEvent( wxevent ); return; } case FocusIn: diff --git a/src/x11/toplevel.cpp b/src/x11/toplevel.cpp index 5633dae559..2c81bc7cef 100644 --- a/src/x11/toplevel.cpp +++ b/src/x11/toplevel.cpp @@ -61,6 +61,8 @@ void wxTopLevelWindowX11::Init() m_fsStyle = 0; m_fsIsMaximized = FALSE; m_fsIsShowing = FALSE; + + m_focusWidget = NULL; } bool wxTopLevelWindowX11::Create(wxWindow *parent, @@ -111,6 +113,7 @@ bool wxTopLevelWindowX11::Create(wxWindow *parent, // TODO: if we want no border, caption etc., // I think we set this to True to remove decorations + // No. RR. xattributes.override_redirect = False; wxSize size2(size); @@ -144,10 +147,18 @@ bool wxTopLevelWindowX11::Create(wxWindow *parent, // background completely. XSetWindowBackgroundPixmap( xdisplay, xwindow, None ); - // Messes up window management - // XSetTransientForHint( xdisplay, xwindow, xparent ); + if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) + { + if (GetParent() && GetParent()->GetMainWindow()) + { + Window xparentwindow = (Window) GetParent()->GetMainWindow(); + XSetTransientForHint( xdisplay, xwindow, xparentwindow ); + } + } - size_hints.flags = PSize; + size_hints.flags = PSize | PPosition; + size_hints.x = pos2.x; + size_hints.y = pos2.y; size_hints.width = size2.x; size_hints.height = size2.y; XSetWMNormalHints( xdisplay, xwindow, &size_hints); @@ -157,10 +168,12 @@ bool wxTopLevelWindowX11::Create(wxWindow *parent, wm_hints.initial_state = NormalState; XSetWMHints( xdisplay, xwindow, &wm_hints); - Atom wm_delete_window = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False); - XSetWMProtocols( xdisplay, xwindow, &wm_delete_window, 1); + Atom wm_protocols[2]; + wm_protocols[0] = XInternAtom( xdisplay, "WM_DELETE_WINDOW", False ); + wm_protocols[1] = XInternAtom( xdisplay, "WM_TAKE_FOCUS", False ); + XSetWMProtocols( xdisplay, xwindow, wm_protocols, 2); - wxSetWMDecorations((Window) GetMainWindow(), style); + wxSetWMDecorations( xwindow, style); SetTitle(title); diff --git a/src/x11/window.cpp b/src/x11/window.cpp index 03a3006695..ed580bbb2e 100644 --- a/src/x11/window.cpp +++ b/src/x11/window.cpp @@ -125,6 +125,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, Display *xdisplay = (Display*) wxGlobalDisplay(); int xscreen = DefaultScreen( xdisplay ); + Visual *xvisual = DefaultVisual( xdisplay, xscreen ); Colormap cm = DefaultColormap( xdisplay, xscreen ); m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); @@ -133,35 +134,40 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id, m_foregroundColour = *wxBLACK; m_foregroundColour.CalcPixel( (WXColormap) cm ); - Window parentWindow = (Window) parent->GetMainWindow(); + Window xparent = (Window) parent->GetMainWindow(); + XSetWindowAttributes xattributes; + + long xattributes_mask = + CWEventMask | + CWBorderPixel | CWBackPixel; + + xattributes.background_pixel = m_backgroundColour.GetPixel(); + xattributes.border_pixel = BlackPixel( xdisplay, xscreen ); + + xattributes.event_mask = + ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | + ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | + KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | + PropertyChangeMask; + wxSize size2(size); if (size2.x == -1) - size2.x = 100; + size2.x = 20; if (size2.y == -1) - size2.y = 100; + size2.y = 20; wxPoint pos2(pos); if (pos2.x == -1) - pos2.x = 100; + pos2.x = 0; if (pos2.y == -1) - pos2.y = 100; + pos2.y = 0; - Window xwindow = XCreateSimpleWindow( - xdisplay, parentWindow, - pos2.x, pos2.y, size2.x, size2.y, 0, - m_backgroundColour.GetPixel(), - m_backgroundColour.GetPixel() ); + Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, + 0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes ); m_mainWidget = (WXWindow) xwindow; - // Select event types wanted - XSelectInput( xdisplay, xwindow, - ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | - KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask | - PropertyChangeMask); - wxAddWindowToTable( xwindow, (wxWindow*) this ); // Is a subwindow, so map immediately @@ -193,12 +199,7 @@ wxWindowX11::~wxWindowX11() m_isBeingDeleted = TRUE; // X11-specific actions first - Window main = (Window) m_mainWidget; - if ( main ) - { - // Removes event handlers - //DetachWidget(main); - } + Window xwindow = (Window) m_mainWidget; if (m_parent) m_parent->RemoveChild( this ); @@ -206,11 +207,11 @@ wxWindowX11::~wxWindowX11() DestroyChildren(); // Destroy the window - if (main) + if (xwindow) { - XSelectInput( wxGlobalDisplay(), main, NoEventMask); - wxDeleteWindowFromTable( main ); - XDestroyWindow( wxGlobalDisplay(), main ); + XSelectInput( wxGlobalDisplay(), xwindow, NoEventMask); + wxDeleteWindowFromTable( xwindow ); + XDestroyWindow( wxGlobalDisplay(), xwindow ); m_mainWidget = NULL; } } @@ -253,7 +254,6 @@ wxWindow *wxWindowBase::FindFocus() return NULL; } -#if 0 wxWindow *wxWindowX11::GetFocusWidget() { wxWindow *win = (wxWindow*) this; @@ -266,7 +266,6 @@ wxWindow *wxWindowX11::GetFocusWidget() return win; } -#endif // Enabling/disabling handled by event loop, and not sending events // if disabled. @@ -286,17 +285,13 @@ bool wxWindowX11::Show(bool show) Display *xdisp = (Display*) GetXDisplay(); if (show) { - wxString msg; - msg.Printf("Mapping window of type %s", GetClassInfo()->GetClassName()); - wxLogDebug(msg); + // wxLogDebug( "Mapping window of type %s", GetName().c_str() ); XMapWindow(xdisp, xwin); XSync(xdisp, False); } else { - wxString msg; - msg.Printf("Unmapping window of type %s", GetClassInfo()->GetClassName()); - wxLogDebug(msg); + // wxLogDebug( "Unmapping window of type %s", GetName().c_str() ); XUnmapWindow(xdisp, xwin); } -- 2.45.2