]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/toplevel.cpp
arg type warning fixes.
[wxWidgets.git] / src / gtk1 / toplevel.cpp
index 6484fa7f0090a0df223237b5ec2a98600be66ca5..0edae9fb0ee0ac288c6472c3d09c9e5e42a9db18 100644 (file)
 
 extern void wxapp_install_idle_handler();
 extern bool g_isIdle;
-extern int g_openDialogs;
-
-// ----------------------------------------------------------------------------
-// event tables
-// ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 // data
 // ----------------------------------------------------------------------------
 
-extern wxList wxPendingDelete;
-
-// ----------------------------------------------------------------------------
-// debug
-// ----------------------------------------------------------------------------
-
-#ifdef __WXDEBUG__
-
-extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window );
-
-#endif
-
-// ============================================================================
-// implementation
-// ============================================================================
+extern wxList         wxPendingDelete;
 
-// ----------------------------------------------------------------------------
-// GTK callbacks
-// ----------------------------------------------------------------------------
+extern int            g_openDialogs;
+extern wxWindowGTK   *g_delayedFocus;
 
 //-----------------------------------------------------------------------------
 // "focus" from m_window
@@ -131,7 +111,8 @@ static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WX
         wxapp_install_idle_handler();
 
     if (win->IsEnabled() &&
-        (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)))
+        (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
+         win->IsGrabbed()))
         win->Close();
 
     return TRUE;
@@ -172,7 +153,8 @@ gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WX
 // so we do this directly after realization
 
 static void
-gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), wxTopLevelWindowGTK *win )
+gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
+                             wxTopLevelWindowGTK *win )
 {
     if (g_isIdle)
         wxapp_install_idle_handler();
@@ -191,27 +173,11 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), wxTopLevelWindowGTK *
         gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1);
 
     // reset the icon
-    wxIcon iconOld = win->GetIcon();
-    if ( iconOld != wxNullIcon )
+    wxIconBundle iconsOld = win->GetIcons();
+    if ( iconsOld.GetIcon(-1).Ok() )
     {
-        wxIcon icon( iconOld );
         win->SetIcon( wxNullIcon );
-        win->SetIcon( icon );
-    }
-
-    // we set the focus to the child that accepts the focus. this
-    // doesn't really have to be done in "realize" but why not? 
-    wxWindowList::Node *node = win->GetChildren().GetFirst();
-    while (node)
-    {
-        wxWindow *child = node->GetData();
-        if (child->AcceptsFocus())
-        {
-            child->SetFocus();
-            break;
-        }
-
-        node = node->GetNext();
+        win->SetIcons( iconsOld );
     }
 }
 
@@ -262,6 +228,7 @@ static int gtk_window_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_ev
 // "draw" of m_client
 //-----------------------------------------------------------------------------
 
+#ifndef __WXGTK20__
 
 static void gtk_window_draw_callback( GtkWidget *widget, GdkRectangle *rect, wxWindow *win )
 {
@@ -276,6 +243,8 @@ static void gtk_window_draw_callback( GtkWidget *widget, GdkRectangle *rect, wxW
                         0, 0, -1, -1);
 }
 
+#endif // GTK+ 1.x
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowGTK itself
 // ----------------------------------------------------------------------------
@@ -330,11 +299,11 @@ void wxTopLevelWindowGTK::Init()
     m_miniTitle = 0;
     m_mainWidget = (GtkWidget*) NULL;
     m_insertInClientArea = TRUE;
-    m_isFrame = TRUE;
     m_isIconized = FALSE;
     m_fsIsShowing = FALSE;
     m_themeEnabled = TRUE;
     m_gdkDecor = m_gdkFunc = 0;
+    m_grabbed = FALSE;
 }
 
 bool wxTopLevelWindowGTK::Create( wxWindow *parent,
@@ -360,7 +329,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     wxTopLevelWindows.Append( this );
 
     m_needParent = FALSE;
-    
+
     if (!PreCreation( parent, pos, size ) ||
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
@@ -398,10 +367,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     if (!name.IsEmpty())
         gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() );
 
-#ifdef __WXDEBUG__
-    debug_focus_in( m_widget, wxT("wxTopLevelWindowGTK::m_widget"), name );
-#endif
-
     gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
     GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
 
@@ -417,11 +382,9 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     // for m_mainWidget themes
     gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
                 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
+#ifndef __WXGTK20__
     gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
                 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
-
-#ifdef __WXDEBUG__
-    debug_focus_in( m_mainWidget, wxT("wxTopLevelWindowGTK::m_mainWidget"), name );
 #endif
 
     // m_wxwindow only represents the client area without toolbar and menubar
@@ -429,10 +392,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     gtk_widget_show( m_wxwindow );
     gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
 
-#ifdef __WXDEBUG__
-    debug_focus_in( m_wxwindow, wxT("wxTopLevelWindowGTK::m_wxwindow"), name );
-#endif
-
     // we donm't allow the frame to get the focus as otherwise
     // the frame will grab it at arbitrary focus changes
     GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
@@ -447,7 +406,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
 
     if ((m_x != -1) || (m_y != -1))
         gtk_widget_set_uposition( m_widget, m_x, m_y );
-        
+
     gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height );
 
     //  we cannot set MWM hints and icons before the widget has
@@ -515,8 +474,14 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
 
 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
 {
-    m_isBeingDeleted = TRUE;
+    if (m_grabbed)
+    {
+        wxASSERT_MSG( FALSE, "Window still grabbed");
+        RemoveGrab();
+    }
     
+    m_isBeingDeleted = TRUE;
+
     // it may also be GtkScrolledWindow in the case of an MDI child
     if (GTK_IS_WINDOW(m_widget))
     {
@@ -800,10 +765,20 @@ void wxTopLevelWindowGTK::OnInternalIdle()
         return;
     }
 
+    // set the focus if not done yet and if we can already do it
+    if ( GTK_WIDGET_REALIZED(m_wxwindow) )
+    {
+        if ( g_delayedFocus &&
+             wxGetTopLevelParent((wxWindow*)g_delayedFocus) == this )
+        {
+            g_delayedFocus->SetFocus();
+            g_delayedFocus = NULL;
+        }
+    }
+
     wxWindow::OnInternalIdle();
 }
 
-
 // ----------------------------------------------------------------------------
 // frame title/icon
 // ----------------------------------------------------------------------------
@@ -840,13 +815,15 @@ void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
 {
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
     GdkWindow* window = m_widget->window;
-    wxCHECK_RET( window, _T("window not created yet - can't set icon") );
 
     wxTopLevelWindowBase::SetIcons( icons );
 
     DoSetIcon( icons.GetIcon( -1 ) );
-    wxSetIconsX11( (WXDisplay*)GDK_WINDOW_XDISPLAY( window ),
-                   (WXWindow)GDK_WINDOW_XWINDOW( window ), icons );
+    if ( window )
+    {
+        wxSetIconsX11( (WXDisplay*)GDK_WINDOW_XDISPLAY( window ),
+                       (WXWindow)GDK_WINDOW_XWINDOW( window ), icons );
+    }
 }
 
 // ----------------------------------------------------------------------------
@@ -900,3 +877,22 @@ void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
     }
 }
 
+void wxTopLevelWindowGTK::AddGrab()
+{
+    if (!m_grabbed)
+    {
+        m_grabbed = TRUE;
+        gtk_grab_add( m_widget );
+        gtk_main();
+        gtk_grab_remove( m_widget );
+    }
+}
+
+void wxTopLevelWindowGTK::RemoveGrab()
+{
+    if (m_grabbed)
+    {
+        gtk_main_quit();
+        m_grabbed = FALSE;
+    }
+}