]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toplevel.cpp
add full 32 bit range support to wxSpinButton/Ctrl
[wxWidgets.git] / src / gtk / toplevel.cpp
index 3bbb16f09838c2e5b30e94daf296eff502cea20b..534759fca72e488ae3bfdf05fba230ba484c4375 100644 (file)
 
 #include "wx/gtk/win_gtk.h"
 
+#include "wx/unix/utilsx11.h"
+
 // ----------------------------------------------------------------------------
 // idle system
 // ----------------------------------------------------------------------------
 
 extern void wxapp_install_idle_handler();
 extern bool g_isIdle;
-extern int g_openDialogs;
-
-// ----------------------------------------------------------------------------
-// event tables
-// ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 // data
 // ----------------------------------------------------------------------------
 
-extern wxList wxPendingDelete;
-
-// ----------------------------------------------------------------------------
-// debug
-// ----------------------------------------------------------------------------
-
-#ifdef __WXDEBUG__
+extern wxList         wxPendingDelete;
 
-extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window );
-
-#endif
-
-// ============================================================================
-// implementation
-// ============================================================================
-
-// ----------------------------------------------------------------------------
-// GTK callbacks
-// ----------------------------------------------------------------------------
+extern int            g_openDialogs;
+extern wxWindowGTK   *g_delayedFocus;
 
 //-----------------------------------------------------------------------------
 // "focus" from m_window
@@ -170,7 +152,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();
@@ -189,27 +172,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 );
     }
 }
 
@@ -260,6 +227,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 )
 {
@@ -274,6 +242,8 @@ static void gtk_window_draw_callback( GtkWidget *widget, GdkRectangle *rect, wxW
                         0, 0, -1, -1);
 }
 
+#endif // GTK+ 1.x
+
 // ----------------------------------------------------------------------------
 // wxTopLevelWindowGTK itself
 // ----------------------------------------------------------------------------
@@ -358,7 +328,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 ))
     {
@@ -376,7 +346,14 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
         win_type = GTK_WINDOW_POPUP;
 
     if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
+    {
+        // there is no more GTK_WINDOW_DIALOG in 2.0
+#ifdef __WXGTK20__
+        win_type = GTK_WINDOW_TOPLEVEL;
+#else
         win_type = GTK_WINDOW_DIALOG;
+#endif
+    }
 
     m_widget = gtk_window_new( win_type );
 
@@ -389,10 +366,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 );
 
@@ -408,11 +381,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
@@ -420,10 +391,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 );
@@ -438,7 +405,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
@@ -507,8 +474,12 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
 {
     m_isBeingDeleted = TRUE;
-    
-    gtk_window_set_focus( GTK_WINDOW(m_widget), NULL );
+
+    // it may also be GtkScrolledWindow in the case of an MDI child
+    if (GTK_IS_WINDOW(m_widget))
+    {
+        gtk_window_set_focus( GTK_WINDOW(m_widget), NULL );
+    }
 
     wxTopLevelWindows.DeleteObject( this );
 
@@ -787,10 +758,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
 // ----------------------------------------------------------------------------
@@ -803,13 +784,9 @@ void wxTopLevelWindowGTK::SetTitle( const wxString &title )
     gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
 }
 
-void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
+void wxTopLevelWindowGTK::DoSetIcon( const wxIcon &icon )
 {
-    wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
-
-    wxTopLevelWindowBase::SetIcon(icon);
-
-    if ( !m_icon.Ok() )
+    if ( !icon.Ok() )
         return;
 
     if (!m_widget->window)
@@ -822,6 +799,26 @@ void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
     gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
 }
 
+void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
+{
+    SetIcons( wxIconBundle( icon ) );
+}
+
+void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
+{
+    wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
+    GdkWindow* window = m_widget->window;
+
+    wxTopLevelWindowBase::SetIcons( icons );
+
+    DoSetIcon( icons.GetIcon( -1 ) );
+    if ( window )
+    {
+        wxSetIconsX11( (WXDisplay*)GDK_WINDOW_XDISPLAY( window ),
+                       (WXWindow)GDK_WINDOW_XWINDOW( window ), icons );
+    }
+}
+
 // ----------------------------------------------------------------------------
 // frame state: maximized/iconized/normal
 // ----------------------------------------------------------------------------