X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e14e49f384b19c88a98796a6bc3a911d9cffdf3..5a41989248f5af10f67bcd526970968c0ba7439d:/src/gtk/dialog.cpp diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index fb8e676622..a4532f5d19 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -14,16 +14,13 @@ #include "wx/dialog.h" #include "wx/frame.h" #include "wx/app.h" - -#include "gdk/gdk.h" -#include "gtk/gtk.h" -#include "wx/gtk/win_gtk.h" #include "wx/cursor.h" -/* -#include "gdk/gdkprivate.h" -#include "gdk/gdkx.h" -*/ +#include +#include +#include + +#include "wx/gtk/win_gtk.h" //----------------------------------------------------------------------------- // idle system @@ -31,6 +28,7 @@ extern void wxapp_install_idle_handler(); extern bool g_isIdle; +extern int g_openDialogs; //----------------------------------------------------------------------------- // data @@ -38,6 +36,20 @@ extern bool g_isIdle; extern wxList wxPendingDelete; +//----------------------------------------------------------------------------- +// "focus" from m_window +//----------------------------------------------------------------------------- + +static gint gtk_dialog_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) ) +{ + if (g_isIdle) + wxapp_install_idle_handler(); + + // This disables GTK's tab traversal + gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" ); + return TRUE; +} + //----------------------------------------------------------------------------- // "delete_event" //----------------------------------------------------------------------------- @@ -47,7 +59,8 @@ bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED if (g_isIdle) wxapp_install_idle_handler(); - win->Close(); + if (win->IsEnabled()) + win->Close(); return TRUE; } @@ -67,7 +80,7 @@ static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation { win->m_width = alloc->width; win->m_height = alloc->height; - win->UpdateSize(); + win->GtkUpdateSize(); } } @@ -76,7 +89,7 @@ static void gtk_dialog_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation //----------------------------------------------------------------------------- static gint -#if (GTK_MINOR_VERSON > 0) +#if (GTK_MINOR_VERSION > 0) gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxDialog *win ) #else gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxDialog *win ) @@ -87,7 +100,7 @@ gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *e if (!win->m_hasVMT) return FALSE; -#if (GTK_MINOR_VERSON > 0) +#if (GTK_MINOR_VERSION > 0) int x = 0; int y = 0; gdk_window_get_root_origin( win->m_widget->window, &x, &y ); @@ -113,19 +126,11 @@ gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *e so we do this directly after realization */ static gint -gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) +gtk_dialog_realized_callback( GtkWidget * WXUNUSED(widget), wxDialog *win ) { if (g_isIdle) wxapp_install_idle_handler(); - // FIXME I don't know when does it appear, but it's not in 1.2.2 -#if GTK_CHECK_VERSION(1, 2, 3) - /* I haven't been able to set the position of - the dialog before it is shown, so I set the - position in "realize" */ - gtk_window_reposition( GTK_WINDOW(widget), win->m_x, win->m_y ); -#endif // GTK > 1.2.2 - /* all this is for Motif Window Manager "hints" and is supposed to be recognized by other WM as well. not tested. */ long decor = (long) GDK_DECOR_BORDER; @@ -170,19 +175,6 @@ gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win ) else gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); - /* set size hints */ - gint flag = GDK_HINT_POS; - if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE; - if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE; - if (flag) - { - gdk_window_set_hints( win->m_widget->window, - win->m_x, win->m_y, - win->GetMinWidth(), win->GetMinHeight(), - win->GetMaxWidth(), win->GetMaxHeight(), - flag ); - } - /* reset the icon */ if (win->m_icon != wxNullIcon) { @@ -239,7 +231,7 @@ void wxDialog::Init() m_returnCode = 0; m_sizeSet = FALSE; m_modalShowing = FALSE; - m_isFrame = TRUE; + m_themeEnabled = TRUE; } wxDialog::wxDialog( wxWindow *parent, @@ -265,9 +257,12 @@ bool wxDialog::Create( wxWindow *parent, !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) { wxFAIL_MSG( wxT("wxDialog creation failed") ); - return FALSE; + return FALSE; } + // All dialogs should really have this style + m_windowStyle |= wxTAB_TRAVERSAL; + m_insertCallback = (wxInsertChildFunction) wxInsertChildInDialog; m_widget = gtk_window_new( GTK_WINDOW_DIALOG ); @@ -295,6 +290,10 @@ bool wxDialog::Create( wxWindow *parent, PostCreation(); + if ((m_x != -1) || (m_y != -1)) + gtk_widget_set_uposition( m_widget, m_x, m_y ); + gtk_widget_set_usize( m_widget, m_width, m_height ); + /* we cannot set MWM hints before the widget has been realized, so we do this directly after realization */ gtk_signal_connect( GTK_OBJECT(m_widget), "realize", @@ -307,21 +306,19 @@ bool wxDialog::Create( wxWindow *parent, gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", GTK_SIGNAL_FUNC(gtk_dialog_configure_callback), (gpointer)this ); + /* disable native tab traversal */ + gtk_signal_connect( GTK_OBJECT(m_widget), "focus", + GTK_SIGNAL_FUNC(gtk_dialog_focus_callback), (gpointer)this ); + return TRUE; } wxDialog::~wxDialog() { - m_isBeingDeleted = TRUE; - - wxTopLevelWindows.DeleteObject( this ); - - if (wxTheApp->GetTopWindow() == this) - { - wxTheApp->SetTopWindow( (wxWindow*) NULL ); - } + CleanUp(); - if (wxTopLevelWindows.Number() == 0) + if ((wxTopLevelWindows.Number() == 0) && + (wxTheApp->GetExitOnFrameDelete())) { wxTheApp->ExitMainLoop(); } @@ -330,13 +327,12 @@ wxDialog::~wxDialog() void wxDialog::SetTitle( const wxString& title ) { m_title = title; - if (m_title.IsNull()) m_title = wxT(""); gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); } wxString wxDialog::GetTitle() const { - return (wxString&)m_title; + return m_title; } void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) @@ -368,7 +364,7 @@ void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) ) else { SetReturnCode(wxID_OK); - this->Show(FALSE); + Show(FALSE); } } } @@ -409,11 +405,31 @@ void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) bool wxDialog::Destroy() { - if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); + // schedule the dialog for the deletion + if ( !wxPendingDelete.Member(this) ) + { + wxPendingDelete.Append(this); + } + + // don't leave a dangling pointer as the app top window, we can be deleted + // any moment at all now! + CleanUp(); return TRUE; } +void wxDialog::CleanUp() +{ + m_isBeingDeleted = TRUE; + + if ( wxTheApp->GetTopWindow() == this ) + { + wxTheApp->SetTopWindow( (wxWindow*) NULL ); + } + + wxTopLevelWindows.DeleteObject( this ); +} + void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") ); @@ -449,6 +465,11 @@ void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) } } +void wxDialog::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) ) +{ + wxFAIL_MSG( wxT("DoMoveWindow called for wxDialog") ); +} + void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags ) { wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") ); @@ -459,6 +480,7 @@ void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags ) int old_x = m_x; int old_y = m_y; + int old_width = m_width; int old_height = m_height; @@ -494,21 +516,20 @@ void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags ) if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; - // FIXME I don't know when does it appear, but it's not in 1.2.2 -#if GTK_CHECK_VERSION(1, 2, 3) if ((m_x != -1) || (m_y != -1)) { if ((m_x != old_x) || (m_y != old_y)) { /* we set the position here and when showing the dialog for the first time in idle time */ - gtk_window_reposition( GTK_WINDOW(m_widget), m_x, m_y ); + gtk_widget_set_uposition( m_widget, m_x, m_y ); } } -#endif // GTK > 1.2.2 if ((m_width != old_width) || (m_height != old_height)) { + gtk_widget_set_usize( m_widget, m_width, m_height ); + /* actual resizing is deferred to GtkOnSize in idle time and when showing the dialog */ m_sizeSet = FALSE; @@ -534,8 +555,19 @@ void wxDialog::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int heigh if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; - /* we actually set the size of a frame here and no-where else */ - gtk_widget_set_usize( m_widget, m_width, m_height ); + /* set size hints */ + gint flag = 0; // GDK_HINT_POS; + if ((m_minWidth != -1) || (m_minHeight != -1)) flag |= GDK_HINT_MIN_SIZE; + if ((m_maxWidth != -1) || (m_maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE; + GdkGeometry geom; + geom.min_width = m_minWidth; + geom.min_height = m_minHeight; + geom.max_width = m_maxWidth; + geom.max_height = m_maxHeight; + gtk_window_set_geometry_hints( GTK_WINDOW(m_widget), + (GtkWidget*) NULL, + &geom, + (GdkWindowHints) flag ); m_sizeSet = TRUE; @@ -600,16 +632,32 @@ int wxDialog::ShowModal() return GetReturnCode(); } + // use the apps top level window as parent if none given unless explicitly + // forbidden + if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) + { + wxWindow *parent = wxTheApp->GetTopWindow(); + if ( parent && parent != this ) + { + m_parent = parent; + gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) ); + } + } + wxBusyCursorSuspender cs; // temporarily suppress the busy cursor Show( TRUE ); m_modalShowing = TRUE; + g_openDialogs++; + gtk_grab_add( m_widget ); gtk_main(); gtk_grab_remove( m_widget ); + g_openDialogs--; + return GetReturnCode(); }