]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
   1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/dialog.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  10 // For compilers that support precompilation, includes "wx.h". 
  11 #include "wx/wxprec.h" 
  13 #include "wx/dialog.h" 
  16     #include "wx/cursor.h" 
  19 #include "wx/evtloop.h" 
  21 #include "wx/scopedptr.h" 
  25 // this is defined in src/gtk/toplevel.cpp 
  26 extern int wxOpenModalDialogsCount
; 
  28 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop
) 
  31 //----------------------------------------------------------------------------- 
  33 //----------------------------------------------------------------------------- 
  35 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
) 
  41     m_modalShowing 
= false; 
  42     m_themeEnabled 
= true; 
  45 wxDialog::wxDialog( wxWindow 
*parent
, 
  46                     wxWindowID id
, const wxString 
&title
, 
  47                     const wxPoint 
&pos
, const wxSize 
&size
, 
  48                     long style
, const wxString 
&name 
) 
  52     (void)Create( parent
, id
, title
, pos
, size
, style
, name 
); 
  55 bool wxDialog::Create( wxWindow 
*parent
, 
  56                        wxWindowID id
, const wxString 
&title
, 
  57                        const wxPoint 
&pos
, const wxSize 
&size
, 
  58                        long style
, const wxString 
&name 
) 
  60     SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
); 
  62     // all dialogs should have tab traversal enabled 
  63     style 
|= wxTAB_TRAVERSAL
; 
  65     return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
); 
  68 bool wxDialog::Show( bool show 
) 
  70     if (!show 
&& IsModal()) 
  72         EndModal( wxID_CANCEL 
); 
  75     if (show 
&& CanDoLayoutAdaptation()) 
  78     bool ret 
= wxDialogBase::Show(show
); 
  88     // if the dialog is modal, this will end its event loop 
  90         EndModal(wxID_CANCEL
); 
  93 bool wxDialog::IsModal() const 
  95     return m_modalShowing
; 
  98 void wxDialog::SetModal( bool WXUNUSED(flag
) ) 
 100     wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); 
 103 int wxDialog::ShowModal() 
 105     wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" ); 
 107     // release the mouse if it's currently captured as the window having it 
 108     // will be disabled when this dialog is shown -- but will still keep the 
 109     // capture making it impossible to do anything in the modal dialog itself 
 110     wxWindow 
* const win 
= wxWindow::GetCapture(); 
 112         win
->GTKReleaseMouseAndNotify(); 
 114     wxWindow 
* const parent 
= GetParentForModalDialog(GetParent()); 
 117         gtk_window_set_transient_for( GTK_WINDOW(m_widget
), 
 118                                       GTK_WINDOW(parent
->m_widget
) ); 
 121     wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor 
 125     m_modalShowing 
= true; 
 127     wxOpenModalDialogsCount
++; 
 129     // NOTE: gtk_window_set_modal internally calls gtk_grab_add() ! 
 130     gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
); 
 132     // Run modal dialog event loop. 
 134         wxGUIEventLoopTiedPtr 
modal(&m_modalLoop
, new wxGUIEventLoop()); 
 138     gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
); 
 140     wxOpenModalDialogsCount
--; 
 142     return GetReturnCode(); 
 145 void wxDialog::EndModal( int retCode 
) 
 147     SetReturnCode( retCode 
); 
 151         wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" ); 
 155     m_modalShowing 
= false; 
 157     // Ensure Exit() is only called once. The dialog's event loop may be terminated 
 158     // externally due to an uncaught exception. 
 159     if (m_modalLoop 
&& m_modalLoop
->IsRunning())