]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/window.cpp
applied the workaround for XUnionRectWithRegion() returning ampty result if the rect...
[wxWidgets.git] / src / x11 / window.cpp
index ce08b9fd81c786eed722eac96b820e0e2218149f..ad5607f4d2e0c72d6cd4261d45ce75100c078f5a 100644 (file)
@@ -127,15 +127,6 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
 
     parent->AddChild(this);
 
-    int w = size.GetWidth();
-    int h = size.GetHeight();
-    int x = size.GetX();
-    int y = size.GetY();
-    if (w == -1) w = 20;
-    if (h == -1) h = 20;
-    if (x == -1) x = 0;
-    if (y == -1) y = 0;
-
     Display *xdisplay = (Display*) wxGlobalDisplay();
     int xscreen = DefaultScreen( xdisplay );
     Visual *xvisual = DefaultVisual( xdisplay, xscreen );
@@ -147,7 +138,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     m_foregroundColour = *wxBLACK;
     m_foregroundColour.CalcPixel( (WXColormap) cm ); 
 
-    Window xparent = (Window) parent->GetClientWindow();
+    Window xparent = (Window) parent->GetClientAreaWindow();
     
     // Add window's own scrollbars to main window, not to client window
     if (parent->GetInsertIntoMain())
@@ -156,20 +147,20 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
         xparent = (Window) parent->GetMainWindow();
     }
     
+    // Size (not including the border) must be nonzero (or a Value error results)!
+    // Note: The Xlib manual doesn't mention this restriction of XCreateWindow.
     wxSize size2(size);
-    if (size2.x == -1)
-       size2.x = 20;
-    if (size2.y == -1)
-       size2.y = 20;
+    if (size2.x <= 0)
+           size2.x = 20;
+    if (size2.y <= 0)
+           size2.y = 20;
 
     wxPoint pos2(pos);
     if (pos2.x == -1)
-       pos2.x = 0;
+           pos2.x = 0;
     if (pos2.y == -1)
-       pos2.y = 0;
+           pos2.y = 0;
     
-#if !wxUSE_NANOX
-
 #if wxUSE_TWO_WINDOWS
     bool need_two_windows = 
         ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
@@ -177,6 +168,9 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     bool need_two_windows = FALSE;
 #endif
 
+#if wxUSE_NANOX
+    long xattributes = 0;
+#else
     XSetWindowAttributes xattributes;
     long xattributes_mask = 0;
     
@@ -187,22 +181,41 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     xattributes.border_pixel = BlackPixel( xdisplay, xscreen );
     
     xattributes_mask |= CWEventMask;
+#endif
     
     if (need_two_windows)
     {
+#if wxUSE_NANOX
+        long backColor, foreColor;
+        backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
+        foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
+    
+        Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
+                                    0, 0, InputOutput, xvisual, backColor, foreColor);
+        XSelectInput( xdisplay, xwindow,
+          GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
+          ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
+          KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
+                      PropertyChangeMask );
+        
+#else
+        // Normal X11
         xattributes.event_mask = 
             ExposureMask | StructureNotifyMask | ColormapChangeMask;
 
         Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
             0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
-    
+
+#endif
+        
         XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
     
         m_mainWindow = (WXWindow) xwindow;
         wxAddWindowToTable( xwindow, (wxWindow*) this );
     
         XMapWindow( xdisplay, xwindow );
-    
+
+#if !wxUSE_NANOX    
         xattributes.event_mask = 
             ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
             ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
@@ -214,29 +227,51 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
             xattributes_mask |= CWBitGravity;
             xattributes.bit_gravity = StaticGravity;
         }
-
+#endif
+        
         if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
         {
             pos2.x = 2;
             pos2.y = 2;
             size2.x -= 4;
             size2.y -= 4;
-        } else
-        if (HasFlag( wxSIMPLE_BORDER ))
+        } 
+        else if (HasFlag( wxSIMPLE_BORDER ))
         {
             pos2.x = 1;
             pos2.y = 1;
             size2.x -= 2;
             size2.y -= 2;
-        } else
+        } 
+        else
         {
             pos2.x = 0;
             pos2.y = 0;
         }
+
+        // Make again sure the size is nonzero.
+        if (size2.x <= 0)
+            size2.x = 1;
+        if (size2.y <= 0)
+            size2.y = 1;
+
+#if wxUSE_NANOX        
+        backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
+        foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
+    
+        xwindow = XCreateWindowWithColor( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, 
+                                    0, 0, InputOutput, xvisual, backColor, foreColor);
+        XSelectInput( xdisplay, xwindow,
+          GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
+          ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
+          KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
+                      PropertyChangeMask );
         
+#else
         xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, 
             0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
-    
+#endif
+        
         XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
     
         m_clientWindow = (WXWindow) xwindow;
@@ -247,7 +282,20 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     else
     {
         // wxLogDebug( "No two windows needed %s", GetName().c_str() );
+#if wxUSE_NANOX
+        long backColor, foreColor;
+        backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
+        foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
     
+        Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
+                                    0, 0, InputOutput, xvisual, backColor, foreColor);
+        XSelectInput( xdisplay, xwindow,
+          GR_EVENT_MASK_CLOSE_REQ | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
+          ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
+          KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
+                      PropertyChangeMask );
+        
+#else
         xattributes.event_mask = 
             ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
             ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
@@ -262,7 +310,8 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
 
         Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
             0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
-            
+#endif
+        
         XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
     
         m_mainWindow = (WXWindow) xwindow;
@@ -271,29 +320,6 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
         
         XMapWindow( xdisplay, xwindow );
     }
-#else
-
-    int extraFlags = GR_EVENT_MASK_CLOSE_REQ;
-
-    long backColor, foreColor;
-    backColor = GR_RGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue());
-    foreColor = GR_RGB(m_foregroundColour.Red(), m_foregroundColour.Green(), m_foregroundColour.Blue());
-    
-    Window xwindow = XCreateWindowWithColor( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
-                                    0, 0, InputOutput, xvisual, backColor, foreColor);
-    XSelectInput( xdisplay, xwindow,
-        extraFlags | ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
-        ButtonMotionMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask |
-        KeymapStateMask | FocusChangeMask | ColormapChangeMask | StructureNotifyMask |
-        PropertyChangeMask );
-    
-    XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
-    
-    m_mainWindow = (WXWindow) xwindow;
-    wxAddWindowToTable( xwindow, (wxWindow*) this );
-    
-    XMapWindow( xdisplay, xwindow );
-#endif
 
     // Is a subwindow, so map immediately
     m_isShown = TRUE;
@@ -361,7 +387,9 @@ void wxWindowX11::SetFocus()
     
     if (wxWindowIsVisible(xwindow))
     {
-        XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
+        wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
+        //        XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
+        XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToNone, CurrentTime );
         m_needsInputFocus = FALSE;
     }
     else
@@ -575,7 +603,7 @@ void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
         m_clearRegion.Intersect( 0, 0, cw, ch );
     }
     
-    Window xwindow = (Window) GetClientWindow();
+    Window xwindow = (Window) GetClientAreaWindow();
 
     wxCHECK_RET( xwindow, wxT("invalid window") );
 
@@ -1102,7 +1130,7 @@ void wxWindowX11::SendEraseEvents()
     if (!GetEventHandler()->ProcessEvent(erase_event) )
     {
         Display *xdisplay = wxGlobalDisplay();
-        Window xwindow = (Window) GetClientWindow();
+        Window xwindow = (Window) GetClientAreaWindow();
         XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() );
         
         wxRegionIterator upd( m_clearRegion );
@@ -1195,6 +1223,9 @@ void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
     }
 }
 
+// See handler for InFocus case in app.cpp for details.
+wxWindow* g_GettingFocus = NULL;
+
 void wxWindowX11::OnInternalIdle()
 {
     // Update invalidated regions.
@@ -1207,8 +1238,17 @@ void wxWindowX11::OnInternalIdle()
     // Set the input focus if couldn't do it before
     if (m_needsInputFocus)
     {
+#if 0
+        wxString msg;
+        msg.Printf("Setting focus for %s from OnInternalIdle\n", GetClassInfo()->GetClassName());
+        printf(msg.c_str());
+#endif        
        SetFocus();
+        // If it couldn't set the focus now, there's
+        // no point in trying again.
+        m_needsInputFocus = FALSE;
     }
+    g_GettingFocus = NULL;
 }
 
 // ----------------------------------------------------------------------------
@@ -1228,7 +1268,7 @@ bool wxAddWindowToTable(Window w, wxWindow *win)
     wxWidgetHashTable->Put((long) w, win);
 
     wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
-               w, win, win->GetClassInfo()->GetClassName());
+               (unsigned int) w, win, win->GetClassInfo()->GetClassName());
 
     return TRUE;
 }
@@ -1260,7 +1300,7 @@ bool wxAddClientWindowToTable(Window w, wxWindow *win)
     wxClientWidgetHashTable->Put((long) w, win);
 
     wxLogTrace("widget", "XWindow 0x%08x <-> window %p (%s)",
-               w, win, win->GetClassInfo()->GetClassName());
+               (unsigned int) w, win, win->GetClassInfo()->GetClassName());
 
     return TRUE;
 }
@@ -1288,7 +1328,7 @@ WXWindow wxWindowX11::GetMainWindow() const
     return m_mainWindow;
 }
 
-WXWindow wxWindowX11::GetClientWindow() const
+WXWindow wxWindowX11::GetClientAreaWindow() const
 {
     return m_clientWindow;
 }