]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/window.cpp
Minor updates to build scripts
[wxWidgets.git] / src / x11 / window.cpp
index 3f186d493769f5e5d53e5a4f2ba2cbbf9c31415a..9fa7e4d83fc598d9ac8478990fed9f005d8a85f4 100644 (file)
@@ -40,6 +40,7 @@
 #include "wx/module.h"
 #include "wx/menuitem.h"
 #include "wx/log.h"
+#include "wx/univ/renderer.h"
 
 #if  wxUSE_DRAG_AND_DROP
     #include "wx/dnd.h"
@@ -62,6 +63,7 @@
 extern wxHashTable *wxWidgetHashTable;
 extern wxHashTable *wxClientWidgetHashTable;
 static wxWindow* g_captureWindow = NULL;
+static GC g_eraseGC;
 
 // ----------------------------------------------------------------------------
 // macros
@@ -102,6 +104,7 @@ void wxWindowX11::Init()
     m_mainWindow = (WXWindow) 0;
     m_clientWindow = (WXWindow) 0;
     m_insertIntoMain = FALSE;
+    m_updateNcArea = FALSE;
     
     m_winCaptured = FALSE;
     m_needsInputFocus = FALSE;
@@ -165,8 +168,6 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     if (pos2.y == -1)
        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);
@@ -174,6 +175,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;
     
@@ -184,22 +188,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 |
@@ -211,10 +234,43 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
             xattributes_mask |= CWBitGravity;
             xattributes.bit_gravity = StaticGravity;
         }
-
-        xwindow = XCreateWindow( xdisplay, xwindow, 0, 0, size2.x, size2.y, 
-            0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
+#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 ))
+        {
+            pos2.x = 1;
+            pos2.y = 1;
+            size2.x -= 2;
+            size2.y -= 2;
+        } else
+        {
+            pos2.x = 0;
+            pos2.y = 0;
+        }
+#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;
@@ -225,7 +281,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 |
@@ -235,12 +304,13 @@ 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, 
             0, DefaultDepth(xdisplay,xscreen), InputOutput, xvisual, xattributes_mask, &xattributes );
-            
+#endif
+        
         XSetWindowBackgroundPixmap( xdisplay, xwindow, None );
     
         m_mainWindow = (WXWindow) xwindow;
@@ -249,29 +319,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;
@@ -339,7 +386,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
@@ -358,6 +407,10 @@ wxWindow *wxWindowBase::FindFocus()
     if (xfocus)
     {
         wxWindow *win = wxGetWindowFromTable( xfocus );
+        if (!win)
+        {
+            win = wxGetClientWindowFromTable( xfocus );
+        }
 
         return win;
     }
@@ -796,12 +849,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)
@@ -818,15 +865,13 @@ void wxWindowX11::DoSetClientSize(int width, int height)
     {
         xwindow = (Window) m_clientWindow;
         
-        if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
-        {
-            width -= 4;
-            height -= 4;
-        } else
-        if (HasFlag( wxSIMPLE_BORDER ))
+        wxWindow *window = (wxWindow*) this;
+        wxRenderer *renderer = window->GetRenderer();
+        if (renderer)
         {
-            width -= 2;
-            height -= 2;
+            wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) );
+            width -= border.x + border.width;
+            height -= border.y + border.height;
         }
         
         XResizeWindow( wxGlobalDisplay(), xwindow, width, height );
@@ -853,26 +898,22 @@ void wxWindowX11::DoMoveWindow(int x, int y, int width, int height)
     {
         xwindow = (Window) m_clientWindow;
         
-        if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
-        {
-            x = 2;
-            y = 2;
-            width -= 4;
-            height -= 4;
-        } else
-        if (HasFlag( wxSIMPLE_BORDER ))
+        wxWindow *window = (wxWindow*) this;
+        wxRenderer *renderer = window->GetRenderer();
+        if (renderer)
         {
-            x = 1;
-            y = 1;
-            width -= 2;
-            height -= 2;
-        } else
+            wxRect border = renderer->GetBorderDimensions( (wxBorder)(m_windowStyle & wxBORDER_MASK) );
+            x = border.x;
+            y = border.y;
+            width -= border.x + border.width;
+            height -= border.y + border.height;
+        }
+        else
         {
             x = 0;
             y = 0;
         }
         
-        wxWindow *window = (wxWindow*) this;
         wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL );
         if (sb && sb->IsShown())
         {
@@ -886,7 +927,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 +1092,7 @@ void wxWindowX11::Update()
 {
     if (m_updateNcArea)
     {
+        // wxLogDebug("wxWindowX11::UpdateNC: %s", GetClassInfo()->GetClassName());
         // Send nc paint events.
         SendNcPaintEvents();
     }
@@ -1084,21 +1126,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();
@@ -1121,9 +1161,42 @@ void wxWindowX11::SendPaintEvents()
 
 void wxWindowX11::SendNcPaintEvents()
 {
+    wxWindow *window = (wxWindow*) this;
+
+    // All this for drawing the small square between the scrollbars.
+    int width = 0;
+    int height = 0;
+    int x = 0;
+    int y = 0;
+    wxScrollBar *sb = window->GetScrollbar( wxHORIZONTAL );
+    if (sb && sb->IsShown())
+    {
+        height = sb->GetSize().y;
+        y = sb->GetPosition().y;
+        
+        sb = window->GetScrollbar( wxVERTICAL );
+        if (sb && sb->IsShown())
+        {
+            width = sb->GetSize().x;
+            x = sb->GetPosition().x;
+
+            Display *xdisplay = wxGlobalDisplay();
+            Window xwindow = (Window) GetMainWindow();
+            Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() );
+            wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
+            colour.CalcPixel( (WXColormap) cm );
+            
+            XSetForeground( xdisplay, g_eraseGC, colour.GetPixel() );
+        
+            XFillRectangle( xdisplay, xwindow, g_eraseGC, x, y, width, height );
+        }
+    }
+        
     wxNcPaintEvent nc_paint_event( GetId() );
     nc_paint_event.SetEventObject( this );
     GetEventHandler()->ProcessEvent( nc_paint_event );
+    
+    m_updateNcArea = FALSE;
 }
 
 // ----------------------------------------------------------------------------
@@ -1149,6 +1222,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.
@@ -1161,8 +1237,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;
 }
 
 // ----------------------------------------------------------------------------
@@ -1426,19 +1511,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 +1580,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 );
+}
+
+