]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/window.cpp
Correct Mac OX/iPhone check in libpng.
[wxWidgets.git] / src / x11 / window.cpp
index c2021f016256b1f4a5e17d196005ddb9b6156a95..7c2e5ae15b16978a61923ae1049b863f8cca598d 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/x11/windows.cpp
+// Name:        src/x11/window.cpp
 // Purpose:     wxWindow
 // Author:      Julian Smart
 // Modified by:
@@ -13,7 +13,7 @@
 #include "wx/wxprec.h"
 
 #if defined(__BORLANDC__)
-#pragma hdrstop
+    #pragma hdrstop
 #endif
 
 // ============================================================================
 // headers
 // ----------------------------------------------------------------------------
 
-#include "wx/menu.h"
-#include "wx/dc.h"
-#include "wx/dcclient.h"
-#include "wx/utils.h"
-#include "wx/app.h"
-#include "wx/panel.h"
-#include "wx/layout.h"
-#include "wx/dialog.h"
-#include "wx/listbox.h"
-#include "wx/button.h"
-#include "wx/settings.h"
-#include "wx/msgdlg.h"
-#include "wx/frame.h"
-#include "wx/scrolwin.h"
-#include "wx/scrolbar.h"
-#include "wx/module.h"
-#include "wx/menuitem.h"
-#include "wx/log.h"
+#include "wx/window.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/hash.h"
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/utils.h"
+    #include "wx/panel.h"
+    #include "wx/frame.h"
+    #include "wx/dc.h"
+    #include "wx/dcclient.h"
+    #include "wx/button.h"
+    #include "wx/menu.h"
+    #include "wx/dialog.h"
+    #include "wx/timer.h"
+    #include "wx/settings.h"
+    #include "wx/msgdlg.h"
+    #include "wx/scrolbar.h"
+    #include "wx/listbox.h"
+    #include "wx/scrolwin.h"
+    #include "wx/layout.h"
+    #include "wx/menuitem.h"
+    #include "wx/module.h"
+#endif
+
 #include "wx/fontutil.h"
 #include "wx/univ/renderer.h"
-#include "wx/hash.h"
 
 #if  wxUSE_DRAG_AND_DROP
     #include "wx/dnd.h"
 #endif
 
+#include "wx/unix/utilsx11.h"
+
 #include "wx/x11/private.h"
 #include "X11/Xutil.h"
 
-#if wxUSE_NANOX
-// For wxGetLocalTime, used by XButtonEventGetTime
-#include "wx/timer.h"
-#endif
-
 #include <string.h>
 
 // ----------------------------------------------------------------------------
@@ -121,6 +124,11 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
 {
     wxCHECK_MSG( parent, false, wxT("can't create wxWindow without parent") );
 
+    // Get default border
+    wxBorder border = GetBorder(style);
+    style &= ~wxBORDER_MASK;
+    style |= border;
+
     CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
 
     parent->AddChild(this);
@@ -142,7 +150,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     if (parent->GetInsertIntoMain())
     {
         // wxLogDebug( "Inserted into main: %s", GetName().c_str() );
-        xparent = (Window) parent->GetMainWindow();
+        xparent = (Window) parent->X11GetMainWindow();
     }
 
     // Size (not including the border) must be nonzero (or a Value error results)!
@@ -159,9 +167,11 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
     if (pos2.y == wxDefaultCoord)
         pos2.y = 0;
 
+    AdjustForParentClientOrigin(pos2.x, pos2.y);
+
 #if wxUSE_TWO_WINDOWS
     bool need_two_windows =
-        ((( wxSUNKEN_BORDER | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
+        ((( wxSUNKEN_BORDER | wxBORDER_THEME | wxRAISED_BORDER | wxSIMPLE_BORDER | wxHSCROLL | wxVSCROLL ) & m_windowStyle) != 0);
 #else
     bool need_two_windows = false;
 #endif
@@ -227,7 +237,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
         }
 #endif
 
-        if (HasFlag( wxSUNKEN_BORDER) || HasFlag( wxRAISED_BORDER))
+        if (HasFlag(wxSUNKEN_BORDER) || HasFlag(wxRAISED_BORDER) || HasFlag(wxBORDER_THEME))
         {
             pos2.x = 2;
             pos2.y = 2;
@@ -342,8 +352,6 @@ wxWindowX11::~wxWindowX11()
     if (g_captureWindow == this)
         g_captureWindow = NULL;
 
-    m_isBeingDeleted = true;
-
     DestroyChildren();
 
     if (m_clientWindow != m_mainWindow)
@@ -356,10 +364,13 @@ wxWindowX11::~wxWindowX11()
     }
 
     // Destroy the window
-    Window xwindow = (Window) m_mainWindow;
-    wxDeleteWindowFromTable( xwindow );
-    XDestroyWindow( wxGlobalDisplay(), xwindow );
-    m_mainWindow = NULL;
+    if ( m_mainWindow )
+    {
+        Window xwindow = (Window) m_mainWindow;
+        wxDeleteWindowFromTable( xwindow );
+        XDestroyWindow( wxGlobalDisplay(), xwindow );
+        m_mainWindow = NULL;
+    }
 }
 
 // ---------------------------------------------------------------------------
@@ -388,7 +399,7 @@ void wxWindowX11::SetFocus()
 
     if (wxWindowIsVisible(xwindow))
     {
-        wxLogTrace( _T("focus"), _T("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
+        wxLogTrace( wxT("focus"), wxT("wxWindowX11::SetFocus: %s"), GetClassInfo()->GetClassName());
         //        XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToParent, CurrentTime );
         XSetInputFocus( wxGlobalDisplay(), xwindow, RevertToNone, CurrentTime );
         m_needsInputFocus = false;
@@ -479,7 +490,7 @@ void wxWindowX11::DoCaptureMouse()
 {
     if ((g_captureWindow != NULL) && (g_captureWindow != this))
     {
-        wxASSERT_MSG(false, wxT("Trying to capture before mouse released."));
+        wxFAIL_MSG(wxT("Trying to capture before mouse released."));
 
         // Core dump now
         int *tmp = NULL;
@@ -513,7 +524,9 @@ void wxWindowX11::DoCaptureMouse()
             msg.Printf(wxT("Failed to grab pointer for window %s"), this->GetClassInfo()->GetClassName());
             wxLogDebug(msg);
             if (res == GrabNotViewable)
+            {
                 wxLogDebug( wxT("This is not a viewable window - perhaps not shown yet?") );
+            }
 
             g_captureWindow = NULL;
             return;
@@ -670,8 +683,8 @@ void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
 
         if (dx < 0) s_x += -dx;
         if (dy < 0) s_y += -dy;
-        if (dx > 0) d_x = dx + offset.x;
-        if (dy > 0) d_y = dy + offset.y;
+        if (dx > 0) d_x += dx + offset.x;
+        if (dy > 0) d_y += dy + offset.y;
 
         XCopyArea( xdisplay, xwindow, xwindow, xgc, s_x, s_y, w, h, d_x, d_y );
 
@@ -801,9 +814,11 @@ void wxWindowX11::DoScreenToClient(int *x, int *y) const
     Window thisWindow = (Window) m_clientWindow;
 
     Window childWindow;
-    int xx = *x;
-    int yy = *y;
-    XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
+    int xx = x ? *x : 0;
+    int yy = y ? *y : 0;
+    XTranslateCoordinates(display, rootWindow, thisWindow,
+                          xx, yy, x ? x : &xx, y ? y : &yy,
+                          &childWindow);
 }
 
 void wxWindowX11::DoClientToScreen(int *x, int *y) const
@@ -813,9 +828,11 @@ void wxWindowX11::DoClientToScreen(int *x, int *y) const
     Window thisWindow = (Window) m_clientWindow;
 
     Window childWindow;
-    int xx = *x;
-    int yy = *y;
-    XTranslateCoordinates(display, thisWindow, rootWindow, xx, yy, x, y, &childWindow);
+    int xx = x ? *x : 0;
+    int yy = y ? *y : 0;
+    XTranslateCoordinates(display, thisWindow, rootWindow,
+                          xx, yy, x ? x : &xx, y ? y : &yy,
+                          &childWindow);
 }
 
 
@@ -1063,10 +1080,11 @@ int wxWindowX11::GetCharWidth() const
 #endif
 }
 
-void wxWindowX11::GetTextExtent(const wxString& string,
-                                int *x, int *y,
-                                int *descent, int *externalLeading,
-                                const wxFont *theFont) const
+void wxWindowX11::DoGetTextExtent(const wxString& string,
+                                  int *x, int *y,
+                                  int *descent,
+                                  int *externalLeading,
+                                  const wxFont *theFont) const
 {
     wxFont fontToUse = GetFont();
     if (theFont) fontToUse = *theFont;
@@ -1110,9 +1128,9 @@ void wxWindowX11::GetTextExtent(const wxString& string,
 
     int direction, ascent, descent2;
     XCharStruct overall;
-    int slen = string.Len();
+    int slen = string.length();
 
-    XTextExtents((XFontStruct*) pFontStruct, (char*) string.c_str(), slen,
+    XTextExtents((XFontStruct*) pFontStruct, (const char*) string.c_str(), slen,
                  &direction, &ascent, &descent2, &overall);
 
     if ( x )
@@ -1191,12 +1209,12 @@ void wxWindowX11::SendEraseEvents()
     if (m_clearRegion.IsEmpty()) return;
 
     wxClientDC dc( (wxWindow*)this );
-    dc.SetClippingRegion( m_clearRegion );
+    dc.SetDeviceClippingRegion( m_clearRegion );
 
     wxEraseEvent erase_event( GetId(), &dc );
     erase_event.SetEventObject( this );
 
-    if (!GetEventHandler()->ProcessEvent(erase_event) )
+    if (!HandleWindowEvent(erase_event) )
     {
         Display *xdisplay = wxGlobalDisplay();
         Window xwindow = (Window) GetClientAreaWindow();
@@ -1222,7 +1240,7 @@ void wxWindowX11::SendPaintEvents()
 
     wxPaintEvent paint_event( GetId() );
     paint_event.SetEventObject( this );
-    GetEventHandler()->ProcessEvent( paint_event );
+    HandleWindowEvent( paint_event );
 
     m_updateRegion.Clear();
 
@@ -1251,7 +1269,7 @@ void wxWindowX11::SendNcPaintEvents()
             x = sb->GetPosition().x;
 
             Display *xdisplay = wxGlobalDisplay();
-            Window xwindow = (Window) GetMainWindow();
+            Window xwindow = (Window) X11GetMainWindow();
             Colormap cm = (Colormap) wxTheApp->GetMainColormap( wxGetDisplay() );
             wxColour colour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
             colour.CalcPixel( (WXColormap) cm );
@@ -1264,7 +1282,7 @@ void wxWindowX11::SendNcPaintEvents()
 
     wxNcPaintEvent nc_paint_event( GetId() );
     nc_paint_event.SetEventObject( this );
-    GetEventHandler()->ProcessEvent( nc_paint_event );
+    HandleWindowEvent( nc_paint_event );
 
     m_updateNcArea = false;
 }
@@ -1285,7 +1303,7 @@ void wxWindowX11::OnSysColourChanged(wxSysColourChangedEvent& event)
         {
             wxSysColourChangedEvent event2;
             event.SetEventObject(win);
-            win->GetEventHandler()->ProcessEvent(event2);
+            win->HandleWindowEvent(event2);
         }
 
         node = node->GetNext();
@@ -1302,7 +1320,7 @@ void wxWindowX11::OnInternalIdle()
 
     // This calls the UI-update mechanism (querying windows for
     // menu/toolbar/control state information)
-    if (wxUpdateUIEvent::CanUpdate((wxWindow*) this))
+    if (wxUpdateUIEvent::CanUpdate((wxWindow*) this) && IsShownOnScreen())
         UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
 
     // Set the input focus if couldn't do it before
@@ -1392,7 +1410,7 @@ void wxDeleteClientWindowFromTable(Window w)
 // X11-specific accessors
 // ----------------------------------------------------------------------------
 
-WXWindow wxWindowX11::GetMainWindow() const
+WXWindow wxWindowX11::X11GetMainWindow() const
 {
     return m_mainWindow;
 }
@@ -1406,7 +1424,10 @@ WXWindow wxWindowX11::GetClientAreaWindow() const
 // TranslateXXXEvent() functions
 // ----------------------------------------------------------------------------
 
-bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window, XEvent *xevent)
+bool wxTranslateMouseEvent(wxMouseEvent& wxevent,
+                           wxWindow *win,
+                           Window WXUNUSED(window),
+                           XEvent *xevent)
 {
     switch (XEventGetType(xevent))
     {
@@ -1455,6 +1476,22 @@ bool wxTranslateMouseEvent(wxMouseEvent& wxevent, wxWindow *win, Window window,
                     eventType = wxEVT_RIGHT_DOWN;
                     button = 3;
                 }
+                else if ( xevent->xbutton.button == Button4 ||
+                            xevent->xbutton.button == Button5 )
+                {
+                    // this is the same value as used under wxMSW
+                    static const int WHEEL_DELTA = 120;
+
+                    eventType = wxEVT_MOUSEWHEEL;
+                    button = xevent->xbutton.button;
+
+                    wxevent.m_linesPerAction = 3;
+                    wxevent.m_wheelDelta = WHEEL_DELTA;
+
+                    // Button 4 means mousewheel up, 5 means down
+                    wxevent.m_wheelRotation = button == Button4 ? WHEEL_DELTA
+                                                                : -WHEEL_DELTA;
+                }
 
                 // check for a double click
                 // TODO: where can we get this value from?
@@ -1606,9 +1643,7 @@ bool wxWindowX11::SetForegroundColour(const wxColour& col)
 
 wxWindow *wxGetActiveWindow()
 {
-    // TODO
-    wxFAIL_MSG(wxT("Not implemented"));
-    return NULL;
+    return wxGetTopLevelParent(wxWindow::FindFocus());
 }
 
 /* static */
@@ -1622,31 +1657,63 @@ wxWindow *wxWindowBase::GetCapture()
 // position.
 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
 {
-    return wxFindWindowAtPoint(wxGetMousePosition());
+    pt = wxGetMousePosition();
+    return wxFindWindowAtPoint(pt);
 }
 
-// Get the current mouse position.
-wxPoint wxGetMousePosition()
+void wxGetMouseState(int& rootX, int& rootY, unsigned& maskReturn)
 {
 #if wxUSE_NANOX
     /* TODO */
-    return wxPoint(0, 0);
+    rootX = rootY = 0;
+    maskReturn = 0;
 #else
     Display *display = wxGlobalDisplay();
     Window rootWindow = RootWindowOfScreen (DefaultScreenOfDisplay(display));
     Window rootReturn, childReturn;
-    int rootX, rootY, winX, winY;
-    unsigned int maskReturn;
+    int winX, winY;
 
     XQueryPointer (display,
                    rootWindow,
                    &rootReturn,
                    &childReturn,
                    &rootX, &rootY, &winX, &winY, &maskReturn);
-    return wxPoint(rootX, rootY);
 #endif
 }
 
+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+    int x, y;
+    unsigned mask;
+
+    wxGetMouseState(x, y, mask);
+    return wxPoint(x, y);
+}
+
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+    int x, y;
+    unsigned mask;
+
+    wxGetMouseState(x, y, mask);
+
+    ms.SetX(x);
+    ms.SetY(y);
+
+    ms.SetLeftDown(mask & Button1Mask);
+    ms.SetMiddleDown(mask & Button2Mask);
+    ms.SetRightDown(mask & Button3Mask);
+
+    ms.SetControlDown(mask & ControlMask);
+    ms.SetShiftDown(mask & ShiftMask);
+    ms.SetAltDown(mask & Mod3Mask);
+    ms.SetMetaDown(mask & Mod1Mask);
+
+    return ms;
+}
+
 
 // ----------------------------------------------------------------------------
 // wxNoOptimize: switch off size optimization
@@ -1662,8 +1729,14 @@ int wxNoOptimize::ms_count = 0;
 class wxWinModule : public wxModule
 {
 public:
-    bool OnInit();
-    void OnExit();
+    wxWinModule()
+    {
+        // we must be cleaned up before the display is closed
+        AddDependency(wxClassInfo::FindClass(wxT("wxX11DisplayModule")));
+    }
+
+    virtual bool OnInit();
+    virtual void OnExit();
 
 private:
     DECLARE_DYNAMIC_CLASS(wxWinModule)