]> git.saurik.com Git - wxWidgets.git/commitdiff
wxX11:
authorRobert Roebling <robert@roebling.de>
Sun, 17 Feb 2002 21:09:04 +0000 (21:09 +0000)
committerRobert Roebling <robert@roebling.de>
Sun, 17 Feb 2002 21:09:04 +0000 (21:09 +0000)
    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
include/wx/x11/window.h
src/gtk/window.cpp
src/gtk1/window.cpp
src/univ/themes/win32.cpp
src/x11/app.cpp
src/x11/toplevel.cpp
src/x11/window.cpp

index 4f66abbf4b7c29b39c6d6b31c6d6f05e448da557..1488491844ddc4341e415f6076e49dd1363a69b9 100644 (file)
@@ -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
index 5e747f150d57b5419dc03b9af61092de11e736ca..29b646cafe7fff6f56d1922d83c88c60fe7185cd 100644 (file)
@@ -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).
index b2941feb0a3e4cf27b0fa462099cb00df48acae0..30fae11783dc31138d400db68cabbb74b8aaa946 100644 (file)
@@ -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() );
index b2941feb0a3e4cf27b0fa462099cb00df48acae0..30fae11783dc31138d400db68cabbb74b8aaa946 100644 (file)
@@ -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() );
index e30f0b3ec0c2287a6908134585834688c3e3f0f4..56a353951fab8d0cb0b55f661b95db60d2d4f2f1 100644 (file)
@@ -3935,6 +3935,7 @@ bool wxWin32InputHandler::HandleMouse(wxInputConsumer *control,
     if ( event.ButtonDown() )
     {
         wxWindow *win = control->GetInputWindow();
+        
         if ( wxWindow::FindFocus() != control->GetInputWindow() )
         {
             win->SetFocus();
index d2e082414b474a584e32b0b82127c766d6d3e425..511b5fb034717810252b868c3426f87f864bdfb9 100644 (file)
@@ -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:
index 5633dae559782b67e90ac0a99f1f2c34049ca1ed..2c81bc7cef6d9ff87ced0cc7b442b67d36243b91 100644 (file)
@@ -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);
     
index 03a3006695c0a71915ab8111acb33a09ff9cbd4d..ed580bbb2eb0bb29355461f97a6b79f444b95e5b 100644 (file)
@@ -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);
     }