]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
ambiguous ctor call resolved
[wxWidgets.git] / src / gtk / window.cpp
index ee398f439a8c5c03e6e6ee44a0f0609f0faa57a1..5b0eb48f98d048b9737a53170aa069944fe507bf 100644 (file)
@@ -132,7 +132,7 @@ extern bool       g_blockEventsOnDrag;
 extern bool       g_blockEventsOnScroll;
 extern wxCursor   g_globalCursor;
 static wxWindow  *g_captureWindow = (wxWindow*) NULL;
-static wxWindow  *g_focusWindow = (wxWindow*) NULL;
+       wxWindow  *g_focusWindow = (wxWindow*) NULL;
 
 /* hack: we need something to pass to gtk_menu_popup, so we store the time of
    the last click here */
@@ -146,7 +146,7 @@ static guint32 gs_timeLastClick = 0;
 
 static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
                                          GdkEvent *WXUNUSED(event),
-                                         const wxChar *name )
+                                         const wxChar *WXUNUSED(name) )
 {
 /*
     static bool s_done = FALSE;
@@ -661,7 +661,10 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU
 
 static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExpose *gdk_event, wxWindow *win )
 {
-    if ( !win->m_hasVMT )
+    if (!win->m_hasVMT)
+        return;
+
+    if (gdk_event->window != win->m_wxwindow->window)
         return;
 
     win->GetUpdateRegion().Union( gdk_event->area.x,
@@ -669,20 +672,23 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp
                                   gdk_event->area.width,
                                   gdk_event->area.height );
 
-    if ( gdk_event->count > 0 )
+    if (gdk_event->count > 0)
         return;
 
-/*
-    printf( "OnExpose from " );
-    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-        printf( win->GetClassInfo()->GetClassName() );
-    printf( ".\n" );
-*/
-
     wxPaintEvent event( win->GetId() );
     event.SetEventObject( win );
     win->GetEventHandler()->ProcessEvent( event );
 
+/*
+    wxPrintf( "OnExpose from " );
+    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+        wxPrintf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( " %d %d %d %d\n", (int)gdk_event->area.x,
+                                (int)gdk_event->area.y,
+                                (int)gdk_event->area.width,
+                                (int)gdk_event->area.height );
+*/
+
     win->GetUpdateRegion().Clear();
 }
 
@@ -703,6 +709,17 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle
 
     wxPaintEvent event( win->GetId() );
     event.SetEventObject( win );
+
+/*
+    wxPrintf( "OnDraw from " );
+    if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+        printf( win->GetClassInfo()->GetClassName() );
+    wxPrintf( " %d %d %d %d\n", (int)rect->x,
+                                (int)rect->y,
+                                (int)rect->width,
+                                (int)rect->height );
+*/
+
     win->GetEventHandler()->ProcessEvent( event );
 
     win->GetUpdateRegion().Clear();
@@ -795,7 +812,6 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
         ret = (ret || win->GetEventHandler()->ProcessEvent( event2 ));
     }
 
-
     /* win is a control: tab can be propagated up */
     if ( (!ret) &&
          ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab)) &&
@@ -1782,6 +1798,7 @@ void wxWindow::Init()
     m_insertCallback = (wxInsertChildFunction) NULL;
 
     m_isStaticBox = FALSE;
+    m_isRadioButton = FALSE;
     m_acceptsFocus = FALSE;
 }
 
@@ -1803,7 +1820,12 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
                        const wxPoint &pos, const wxSize &size,
                        long style, const wxString &name  )
 {
-    PreCreation( parent, id, pos, size, style, name );
+    if (!PreCreation( parent, pos, size ) ||
+        !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
+    {
+        wxFAIL_MSG( _T("wxWindow creation failed") );
+       return FALSE;
+    }
 
     m_insertCallback = wxInsertChildInWindow;
 
@@ -1984,27 +2006,22 @@ wxWindow::~wxWindow()
     }
 }
 
-void wxWindow::PreCreation( wxWindow *parent,
-                            wxWindowID id,
-                            const wxPoint &pos,
-                            const wxSize &size,
-                            long style,
-                            const wxString &name )
+bool wxWindow::PreCreation( wxWindow *parent, const wxPoint &pos,  const wxSize &size )
 {
-    wxASSERT_MSG( !m_needParent || parent, _T("Need complete parent.") );
-
-    if ( !CreateBase(parent, id, pos, size, style, name) )
-    {
-        wxFAIL_MSG(_T("window creation failed"));
-    }
+    wxCHECK_MSG( !m_needParent || parent, FALSE, _T("Need complete parent.") );
 
+    /* this turns -1 into 20 so that a minimal window is
+       visible even although -1,-1 has been given as the
+       size of the window. the same trick is used in other
+       ports and should make debugging easier */
     m_width = WidthDefault(size.x);
     m_height = HeightDefault(size.y);
 
     m_x = (int)pos.x;
     m_y = (int)pos.y;
 
-    if (!parent)  /* some reasonable defaults */
+    /* some reasonable defaults */
+    if (!parent)  
     {
         if (m_x == -1)
         {
@@ -2017,6 +2034,8 @@ void wxWindow::PreCreation( wxWindow *parent,
             if (m_y < 10) m_y = 10;
         }
     }
+    
+    return TRUE;
 }
 
 void wxWindow::PostCreation()
@@ -2191,18 +2210,33 @@ void wxWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags )
 
 void wxWindow::OnInternalIdle()
 {
-        GdkWindow *window = GetConnectWidget()->window;
-        if (window)
+    wxCursor cursor = m_cursor;
+    if (g_globalCursor.Ok()) cursor = g_globalCursor;
+
+    if (cursor.Ok() && m_currentGdkCursor != cursor)
+    {
+        m_currentGdkCursor = cursor;
+       
+        if (m_wxwindow)
         {
-            wxCursor cursor = m_cursor;
-            if (g_globalCursor.Ok()) cursor = g_globalCursor;
+            GdkWindow *window = m_wxwindow->window;
+            if (window)
+                gdk_window_set_cursor( window, cursor.GetCursor() );
 
-            if (cursor.Ok() && m_currentGdkCursor != cursor)
-            {
+            if (!g_globalCursor.Ok())
+                cursor = *wxSTANDARD_CURSOR;
+
+            window = m_widget->window;
+            if (window)
                 gdk_window_set_cursor( window, cursor.GetCursor() );
-                m_currentGdkCursor = cursor;
-            }
         }
+        else
+        {
+            GdkWindow *window = m_widget->window;
+            if (window)
+               gdk_window_set_cursor( window, cursor.GetCursor() );
+        }
+    }
 
     UpdateWindowUI();
 }
@@ -2228,32 +2262,34 @@ void wxWindow::DoSetClientSize( int width, int height )
         int dw = 0;
         int dh = 0;
 
-        if (!m_hasScrolling)
+#if (GTK_MINOR_VERSION == 0)
+        if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
         {
-            GtkStyleClass *window_class = m_wxwindow->style->klass;
-
-            if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
+            if (HasScrolling())
             {
-                dw += 2 * window_class->xthickness;
-                dh += 2 * window_class->ythickness;
-            }
-        }
-        else
-        {
-            GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
-            GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+                GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
+#if 0 // unused - if this is ok, just remove this line (VZ)
+                GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+#endif // 0
 
-#if (GTK_MINOR_VERSION == 0)
-            GtkWidget *viewport = scroll_window->viewport;
-            GtkStyleClass *viewport_class = viewport->style->klass;
+                GtkWidget *viewport = scroll_window->viewport;
+                GtkStyleClass *viewport_class = viewport->style->klass;
 
-            if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
-            {
                 dw += 2 * viewport_class->xthickness;
                 dh += 2 * viewport_class->ythickness;
             }
+        }
+#else
+        if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
+        {
+            /* when using GTK 1.2 we set the border size to 2 */
+            dw += 2 * 2;
+            dh += 2 * 2;
+        }
 #endif
 
+        if (HasScrolling())
+        {
 /*
             GtkWidget *hscrollbar = scroll_window->hscrollbar;
             GtkWidget *vscrollbar = scroll_window->vscrollbar;
@@ -2261,6 +2297,9 @@ void wxWindow::DoSetClientSize( int width, int height )
             we use this instead:  range.slider_width = 11 + 2*2pts edge
 */
 
+            GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
+            GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+
             if (scroll_window->vscrollbar_visible)
             {
                 dw += 15;   /* dw += vscrollbar->allocation.width; */
@@ -2292,31 +2331,33 @@ void wxWindow::DoGetClientSize( int *width, int *height ) const
         int dw = 0;
         int dh = 0;
 
-        if (!m_hasScrolling)
+#if (GTK_MINOR_VERSION == 0)
+        if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
         {
-            GtkStyleClass *window_class = m_wxwindow->style->klass;
-
-            if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
+            if (HasScrolling())
             {
-                dw += 2 * window_class->xthickness;
-                dh += 2 * window_class->ythickness;
-            }
-        }
-        else
-        {
-            GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
-            GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+                GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
+#if 0 // unused - if this is ok, just remove this line (VZ)
+                GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+#endif // 0
 
-#if (GTK_MINOR_VERSION == 0)
-            GtkWidget *viewport = scroll_window->viewport;
-            GtkStyleClass *viewport_class = viewport->style->klass;
+                GtkWidget *viewport = scroll_window->viewport;
+                GtkStyleClass *viewport_class = viewport->style->klass;
 
-            if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) )
-            {
                 dw += 2 * viewport_class->xthickness;
                 dh += 2 * viewport_class->ythickness;
             }
+        }
+#else
+        if (HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER))
+        {
+            /* when using GTK 1.2 we set the border size to 2 */
+            dw += 2 * 2;
+            dh += 2 * 2;
+        }
 #endif
+        if (HasScrolling())
+        {
 /*
             GtkWidget *hscrollbar = scroll_window->hscrollbar;
             GtkWidget *vscrollbar = scroll_window->vscrollbar;
@@ -2324,6 +2365,9 @@ void wxWindow::DoGetClientSize( int *width, int *height ) const
             we use this instead:  range.slider_width = 11 + 2*2pts edge
 */
 
+            GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
+            GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
+
             if (scroll_window->vscrollbar_visible)
             {
                 dw += 15;   /* dw += vscrollbar->allocation.width; */
@@ -2804,6 +2848,15 @@ void wxWindow::ApplyWidgetStyle()
 {
 }
 
+//-----------------------------------------------------------------------------
+// Pop-up menu stuff
+//-----------------------------------------------------------------------------
+
+static void gtk_pop_hide_callback( GtkWidget *WXUNUSED(widget), bool* is_waiting  )
+{
+    *is_waiting = FALSE;
+}
+
 static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
 {
     menu->SetInvokingWindow( win );
@@ -2831,7 +2884,7 @@ static void pop_pos_callback( GtkMenu * WXUNUSED(menu),
     *y = gs_pop_y;
 }
 
-bool wxWindow::PopupMenu( wxMenu *menu, int x, int y )
+bool wxWindow::DoPopupMenu( wxMenu *menu, int x, int y )
 {
     wxCHECK_MSG( m_widget != NULL, FALSE, _T("invalid window") );
 
@@ -2844,6 +2897,11 @@ bool wxWindow::PopupMenu( wxMenu *menu, int x, int y )
     gs_pop_x = x;
     gs_pop_y = y;
 
+    bool is_waiting = TRUE;
+    
+    gtk_signal_connect( GTK_OBJECT(menu->m_menu), "hide",
+      GTK_SIGNAL_FUNC(gtk_pop_hide_callback), (gpointer)&is_waiting );
+
     gtk_menu_popup(
                   GTK_MENU(menu->m_menu),
                   (GtkWidget *) NULL,          // parent menu shell
@@ -2853,6 +2911,13 @@ bool wxWindow::PopupMenu( wxMenu *menu, int x, int y )
                   0,                           // button used to activate it
                   0 //gs_timeLastClick         // the time of activation
                 );
+               
+    while (is_waiting)
+    {
+        while (gtk_events_pending())
+            gtk_main_iteration();
+    }
+
     return TRUE;
 }