]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
use m_ prefix for web_view member, and make it a WebKitWebView* to eliminate many...
[wxWidgets.git] / src / gtk / window.cpp
index 870b41845195be8aec0f508848c7d4b65d6290e8..f5d1fbb070bc4e7c121ecb6b548f389d1dae978d 100644 (file)
 #include "wx/gtk/private/event.h"
 using namespace wxGTKImpl;
 
+#ifdef GDK_WINDOWING_X11
 #include <gdk/gdkx.h>
+#else
+typedef guint KeySym;
+#endif
 
 #include <gdk/gdkkeysyms.h>
 #if GTK_CHECK_VERSION(3,0,0)
 #include <gdk/gdkkeysyms-compat.h>
 #endif
 
-#if wxUSE_GRAPHICS_CONTEXT
-#include "wx/graphics.h"
-#include "wx/scopedptr.h"
-#endif // wxUSE_GRAPHICS_CONTEXT
-
 // gdk_window_set_composited() is only supported since 2.12
 #define wxGTK_VERSION_REQUIRED_FOR_COMPOSITING 2,12,0
 #define wxGTK_HAS_COMPOSITING_SUPPORT GTK_CHECK_VERSION(2,12,0)
@@ -733,6 +732,7 @@ wxTranslateGTKKeyEventToWx(wxKeyEvent& event,
                 keysym = (KeySym)gdk_event->string[0];
             }
 
+#ifdef GDK_WINDOWING_X11
             // we want to always get the same key code when the same key is
             // pressed regardless of the state of the modifiers, i.e. on a
             // standard US keyboard pressing '5' or '%' ('5' key with
@@ -751,6 +751,9 @@ wxTranslateGTKKeyEventToWx(wxKeyEvent& event,
             // use the normalized, i.e. lower register, keysym if we've
             // got one
             key_code = keysymNormalized ? keysymNormalized : keysym;
+#else
+            key_code = keysym;
+#endif
 
             // as explained above, we want to have lower register key codes
             // normally but for the letter keys we want to have the upper ones
@@ -1146,7 +1149,7 @@ static void AdjustEventButtonState(wxMouseEvent& event)
     }
 }
 
-// find the window to send the mouse event too
+// find the window to send the mouse event to
 static
 wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y)
 {
@@ -1196,6 +1199,7 @@ wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y)
         else
         {
             if ((child->m_wxwindow == NULL) &&
+                win->IsClientAreaChild(child) &&
                 (child->m_x <= xx) &&
                 (child->m_y <= yy) &&
                 (child->m_x+child->m_width  >= xx) &&
@@ -2337,8 +2341,11 @@ bool wxWindowGTK::PreCreation( wxWindowGTK *parent, const wxPoint &pos,  const w
     m_width = WidthDefault(size.x) ;
     m_height = HeightDefault(size.y);
 
-    m_x = (int)pos.x;
-    m_y = (int)pos.y;
+    if (pos != wxDefaultPosition)
+    {
+        m_x = pos.x;
+        m_y = pos.y;
+    }
 
     return true;
 }
@@ -2696,8 +2703,6 @@ void wxWindowGTK::OnInternalIdle()
 
 void wxWindowGTK::DoGetSize( int *width, int *height ) const
 {
-    wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
-
     if (width) (*width) = m_width;
     if (height) (*height) = m_height;
 }
@@ -2792,39 +2797,17 @@ wxSize wxWindowGTK::DoGetBorderSize() const
 
 void wxWindowGTK::DoGetPosition( int *x, int *y ) const
 {
-    wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
-
     int dx = 0;
     int dy = 0;
-    if (!IsTopLevel() && m_parent && m_parent->m_wxwindow)
+    GtkWidget* parent = NULL;
+    if (m_widget)
+        parent = gtk_widget_get_parent(m_widget);
+    if (WX_IS_PIZZA(parent))
     {
-        wxPizza* pizza = WX_PIZZA(m_parent->m_wxwindow);
+        wxPizza* pizza = WX_PIZZA(parent);
         dx = pizza->m_scroll_x;
         dy = pizza->m_scroll_y;
     }
-
-    if (m_x == -1 && m_y == -1)
-    {
-        GdkWindow *source = NULL;
-        if (m_wxwindow)
-            source = gtk_widget_get_window(m_wxwindow);
-        else
-            source = gtk_widget_get_window(m_widget);
-
-        if (source)
-        {
-            int org_x = 0;
-            int org_y = 0;
-            gdk_window_get_origin( source, &org_x, &org_y );
-
-            if (m_parent)
-                m_parent->ScreenToClient(&org_x, &org_y);
-
-            const_cast<wxWindowGTK*>(this)->m_x = org_x;
-            const_cast<wxWindowGTK*>(this)->m_y = org_y;
-        }
-    }
-
     if (x) (*x) = m_x - dx;
     if (y) (*y) = m_y - dy;
 }
@@ -3583,11 +3566,13 @@ void wxWindowGTK::WarpPointer( int x, int y )
     GdkDeviceManager* manager = gdk_display_get_device_manager(display);
     gdk_device_warp(gdk_device_manager_get_client_pointer(manager), screen, x, y);
 #else
+#ifdef GDK_WINDOWING_X11
     XWarpPointer(GDK_DISPLAY_XDISPLAY(display),
         None,
         GDK_WINDOW_XID(gdk_screen_get_root_window(screen)),
         0, 0, 0, 0, x, y);
 #endif
+#endif
 }
 
 wxWindowGTK::ScrollDir wxWindowGTK::ScrollDirFromRange(GtkRange *range) const
@@ -3703,7 +3688,9 @@ void wxWindowGTK::GtkSendPaintEvents()
         m_updateRegion.Clear();
         return;
     }
-
+#if wxGTK_HAS_COMPOSITING_SUPPORT
+    cairo_t* cr = NULL;
+#endif
     // Clip to paint region in wxClientDC
     m_clipPaintRegion = true;
 
@@ -3735,23 +3722,26 @@ void wxWindowGTK::GtkSendPaintEvents()
 
     switch ( GetBackgroundStyle() )
     {
-#if wxUSE_GRAPHICS_CONTEXT
         case wxBG_STYLE_TRANSPARENT:
+#if wxGTK_HAS_COMPOSITING_SUPPORT
+            if (IsTransparentBackgroundSupported())
             {
                 // Set a transparent background, so that overlaying in parent
                 // might indeed let see through where this child did not
                 // explicitly paint.
                 // NB: it works also for top level windows (but this is the
                 // windows manager which then does the compositing job)
-                wxScopedPtr<wxGraphicsContext> gc (wxGraphicsContext::Create( this ));
-                cairo_t *cairo_context = (cairo_t *)gc->GetNativeContext();
-
-                gc->Clip (m_nativeUpdateRegion);
-                cairo_set_operator (cairo_context, CAIRO_OPERATOR_CLEAR);
-                cairo_paint (cairo_context);
-                break;
+                cr = gdk_cairo_create(m_wxwindow->window);
+                gdk_cairo_region(cr, m_nativeUpdateRegion.GetRegion());
+                cairo_clip(cr);
+
+                cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
+                cairo_paint(cr);
+                cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
+                cairo_surface_flush(cairo_get_target(cr));
             }
-#endif // wxUSE_GRAPHICS_CONTEXT
+#endif // wxGTK_HAS_COMPOSITING_SUPPORT
+            break;
 
         case wxBG_STYLE_ERASE:
             {
@@ -3829,11 +3819,9 @@ void wxWindowGTK::GtkSendPaintEvents()
     paint_event.SetEventObject( this );
     HandleWindowEvent( paint_event );
 
-#if wxUSE_GRAPHICS_CONTEXT
+#if wxGTK_HAS_COMPOSITING_SUPPORT
+    if (IsTransparentBackgroundSupported())
     { // now composite children which need it
-        wxScopedPtr<wxGraphicsContext> gc (wxGraphicsContext::Create( this ));
-        cairo_t *cairo_context = (cairo_t *)gc->GetNativeContext();
-
         // Overlay all our composite children on top of the painted area
         wxWindowList::compatibility_iterator node;
         for ( node = m_children.GetFirst(); node ; node = node->GetNext() )
@@ -3841,26 +3829,28 @@ void wxWindowGTK::GtkSendPaintEvents()
             wxWindow *compositeChild = node->GetData();
             if (compositeChild->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT)
             {
+                if (cr == NULL)
+                {
+                    cr = gdk_cairo_create(m_wxwindow->window);
+                    gdk_cairo_region(cr, m_nativeUpdateRegion.GetRegion());
+                    cairo_clip(cr);
+                }
+
                 GtkWidget *child = compositeChild->m_wxwindow;
+                GtkAllocation alloc;
+                gtk_widget_get_allocation(child, &alloc);
 
                 // The source data is the (composited) child
-                gdk_cairo_set_source_pixmap (cairo_context, child->window,
-                                            child->allocation.x,
-                                            child->allocation.y);
+                gdk_cairo_set_source_window(
+                    cr, gtk_widget_get_window(child), alloc.x, alloc.y);
 
-                // Draw no more than our expose event intersects our child
-                gc->Clip (m_nativeUpdateRegion);
-                gc->Clip (child->allocation.x, child->allocation.y,
-                    child->allocation.width, child->allocation.height);
-
-                cairo_set_operator (cairo_context, CAIRO_OPERATOR_OVER);
-                cairo_paint (cairo_context);
-
-                gc->ResetClip ();
+                cairo_paint(cr);
             }
         }
+        if (cr)
+            cairo_destroy(cr);
     }
-#endif // wxUSE_GRAPHICS_CONTEXT
+#endif // wxGTK_HAS_COMPOSITING_SUPPORT
 
     m_clipPaintRegion = false;
 
@@ -4087,7 +4077,7 @@ bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style)
         {
             // Make sure GDK/X11 doesn't refresh the window
             // automatically.
-            gdk_window_set_back_pixmap( window, None, False );
+            gdk_window_set_back_pixmap( window, NULL, FALSE );
             m_needsStyleChange = false;
         }
         else // window not realized yet
@@ -4110,7 +4100,7 @@ bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style)
 
 bool wxWindowGTK::IsTransparentBackgroundSupported(wxString* reason) const
 {
-#if wxGTK_HAS_COMPOSITING_SUPPORT && wxUSE_GRAPHICS_CONTEXT
+#if wxGTK_HAS_COMPOSITING_SUPPORT
     if (gtk_check_version(wxGTK_VERSION_REQUIRED_FOR_COMPOSITING) != NULL)
     {
         if (reason)
@@ -4140,18 +4130,12 @@ bool wxWindowGTK::IsTransparentBackgroundSupported(wxString* reason) const
     }
 
     return true;
-#elif !wxGTK_HAS_COMPOSITING_SUPPORT
+#else
     if (reason)
     {
         *reason = _("This program was compiled with a too old version of GTK+, "
                     "please rebuild with GTK+ 2.12 or newer.");
     }
-#elif !wxUSE_GRAPHICS_CONTEXT
-    if (reason)
-    {
-        *reason = _("wxUSE_GRAPHICS_CONTEXT required for compositing window, "
-                    "please rebuild wxWidgets with support for it.");
-    }
 #endif // wxGTK_HAS_COMPOSITING_SUPPORT/!wxGTK_HAS_COMPOSITING_SUPPORT
 
     return false;