]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/window.cpp
Put some life into GTK 2.0 drawing.
[wxWidgets.git] / src / x11 / window.cpp
index 3f186d493769f5e5d53e5a4f2ba2cbbf9c31415a..18aad1d21288deed199a117eabd156c1565e6132 100644 (file)
@@ -62,6 +62,7 @@
 extern wxHashTable *wxWidgetHashTable;
 extern wxHashTable *wxClientWidgetHashTable;
 static wxWindow* g_captureWindow = NULL;
+static GC g_eraseGC;
 
 // ----------------------------------------------------------------------------
 // macros
@@ -102,6 +103,7 @@ void wxWindowX11::Init()
     m_mainWindow = (WXWindow) 0;
     m_clientWindow = (WXWindow) 0;
     m_insertIntoMain = FALSE;
+    m_updateNcArea = FALSE;
     
     m_winCaptured = FALSE;
     m_needsInputFocus = FALSE;
@@ -212,7 +214,26 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
             xattributes.bit_gravity = StaticGravity;
         }
 
-        xwindow = XCreateWindow( xdisplay, xwindow, 0, 0, size2.x, size2.y, 
+        if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
+        {
+            pos2.x = 2;
+            pos2.y = 2;
+            size2.x -= 4;
+            size2.y -= 4;
+        } else
+        if (HasFlag( wxSIMPLE_BORDER ))
+        {
+            pos2.x = 1;
+            pos2.y = 1;
+            size2.x -= 2;
+            size2.y -= 2;
+        } else
+        {
+            pos2.x = 0;
+            pos2.y = 0;
+        }
+        
+        xwindow = XCreateWindow( xdisplay, xwindow, pos2.x, pos2.y, size2.x, size2.y, 
             0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
     
         XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
@@ -235,7 +256,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
         if (HasFlag( wxNO_FULL_REPAINT_ON_RESIZE ))
         {
             xattributes_mask |= CWBitGravity;
-            xattributes.bit_gravity = StaticGravity;
+            xattributes.bit_gravity = NorthWestGravity;
         }
 
         Window xwindow = XCreateWindow( xdisplay, xparent, pos2.x, pos2.y, size2.x, size2.y, 
@@ -358,6 +379,10 @@ wxWindow *wxWindowBase::FindFocus()
     if (xfocus)
     {
         wxWindow *win = wxGetWindowFromTable( xfocus );
+        if (!win)
+        {
+            win = wxGetClientWindowFromTable( xfocus );
+        }
 
         return win;
     }
@@ -796,12 +821,6 @@ void wxWindowX11::DoSetSize(int x, int y, int width, int height, int sizeFlags)
     }
     
     DoMoveWindow( new_x, new_y, new_w, new_h );
-
-#if 0
-    wxSizeEvent event(wxSize(new_w, new_h), GetId());
-    event.SetEventObject(this);
-    GetEventHandler()->ProcessEvent(event);
-#endif
 }
 
 void wxWindowX11::DoSetClientSize(int width, int height)
@@ -886,7 +905,7 @@ void wxWindowX11::DoMoveWindow(int x, int y, int width, int height)
             width -= size.x;
         }
         
-        XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, width, height );
+        XMoveResizeWindow( wxGlobalDisplay(), xwindow, x, y, wxMax(1, width), wxMax(1, height) );
     }
     
 #else    
@@ -1051,6 +1070,7 @@ void wxWindowX11::Update()
 {
     if (m_updateNcArea)
     {
+        // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
         // Send nc paint events.
         SendNcPaintEvents();
     }
@@ -1084,21 +1104,19 @@ void wxWindowX11::SendEraseEvents()
     wxEraseEvent erase_event( GetId(), &dc );
     erase_event.SetEventObject( this );
 
-    if (!GetEventHandler()->ProcessEvent(erase_event))
+    if (!GetEventHandler()->ProcessEvent(erase_event) )
     {
-        Window xwindow = (Window) m_clientWindow;
         Display *xdisplay = wxGlobalDisplay();
-        GC xgc = XCreateGC( xdisplay, xwindow, 0, NULL );
-        XSetFillStyle( xdisplay, xgc, FillSolid );
-        XSetForeground( xdisplay, xgc, m_backgroundColour.GetPixel() );
+        Window xwindow = (Window) GetClientWindow();
+        XSetForeground( xdisplay, g_eraseGC, m_backgroundColour.GetPixel() );
+        
         wxRegionIterator upd( m_clearRegion );
         while (upd)
         {
-            XFillRectangle( xdisplay, xwindow, xgc,
+            XFillRectangle( xdisplay, xwindow, g_eraseGC,
                             upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
             upd ++;
         }
-        XFreeGC( xdisplay, xgc );
     }
     
     m_clearRegion.Clear();
@@ -1124,6 +1142,8 @@ void wxWindowX11::SendNcPaintEvents()
     wxNcPaintEvent nc_paint_event( GetId() );
     nc_paint_event.SetEventObject( this );
     GetEventHandler()->ProcessEvent( nc_paint_event );
+    
+    m_updateNcArea = FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -1426,19 +1446,10 @@ bool wxWindowX11::SetBackgroundColour(const wxColour& col)
 
     m_backgroundColour.CalcPixel( (WXColormap) cm );
     
-    if (!GetMainWindow())
-        return FALSE;
-
-/*
-    XSetWindowAttributes attrib;
-    attrib.background_pixel = colour.GetPixel();
-
-    XChangeWindowAttributes(wxGlobalDisplay(),
-        (Window) GetMainWindow(),
-        CWBackPixel,
-        & attrib);
-*/
-
+    // We don't set the background colour as we paint
+    // the background ourselves.
+    // XSetWindowBackground( xdisplay, (Window) m_clientWindow, m_backgroundColour.GetPixel() );
+    
     return TRUE;
 }
 
@@ -1504,3 +1515,38 @@ wxPoint wxGetMousePosition()
 
 int wxNoOptimize::ms_count = 0;
 
+
+// ----------------------------------------------------------------------------
+// wxDCModule
+// ----------------------------------------------------------------------------
+
+class wxWinModule : public wxModule
+{
+public:
+    bool OnInit();
+    void OnExit();
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxWinModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxWinModule, wxModule)
+
+bool wxWinModule::OnInit()
+{
+    Display *xdisplay = wxGlobalDisplay();
+    int xscreen = DefaultScreen( xdisplay );
+    Window xroot = RootWindow( xdisplay, xscreen );
+    g_eraseGC = XCreateGC( xdisplay, xroot, 0, NULL );
+    XSetFillStyle( xdisplay, g_eraseGC, FillSolid );
+    
+    return TRUE;
+}
+
+void wxWinModule::OnExit()
+{
+    Display *xdisplay = wxGlobalDisplay();
+    XFreeGC( xdisplay, g_eraseGC );
+}
+
+