1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation "dialog.h" 
  14 #include "wx/dialog.h" 
  17 #include "wx/cursor.h" 
  21 #include <gdk/gdkkeysyms.h> 
  23 #include "wx/gtk/win_gtk.h" 
  25 //----------------------------------------------------------------------------- 
  27 //----------------------------------------------------------------------------- 
  29 extern void wxapp_install_idle_handler(); 
  31 extern int g_openDialogs
; 
  35 //----------------------------------------------------------------------------- 
  37 //----------------------------------------------------------------------------- 
  39 BEGIN_EVENT_TABLE(wxDialog
,wxDialogBase
) 
  40     EVT_BUTTON  (wxID_OK
,       wxDialog::OnOK
) 
  41     EVT_BUTTON  (wxID_CANCEL
,   wxDialog::OnCancel
) 
  42     EVT_BUTTON  (wxID_APPLY
,    wxDialog::OnApply
) 
  43     EVT_CLOSE   (wxDialog::OnCloseWindow
) 
  46 IMPLEMENT_DYNAMIC_CLASS(wxDialog
,wxTopLevelWindow
) 
  52     m_modalShowing 
= FALSE
; 
  53     m_themeEnabled 
= TRUE
; 
  56 wxDialog::wxDialog( wxWindow 
*parent
, 
  57                     wxWindowID id
, const wxString 
&title
, 
  58                     const wxPoint 
&pos
, const wxSize 
&size
, 
  59                     long style
, const wxString 
&name 
) 
  63     (void)Create( parent
, id
, title
, pos
, size
, style
, name 
); 
  66 bool wxDialog::Create( wxWindow 
*parent
, 
  67                        wxWindowID id
, const wxString 
&title
, 
  68                        const wxPoint 
&pos
, const wxSize 
&size
, 
  69                        long style
, const wxString 
&name 
) 
  71     SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
); 
  73     // all dialogs should have tab traversal enabled 
  74     style 
|= wxTAB_TRAVERSAL
; 
  76     return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
); 
  79 void wxDialog::OnApply( wxCommandEvent 
&WXUNUSED(event
) ) 
  82         TransferDataFromWindow(); 
  85 void wxDialog::OnCancel( wxCommandEvent 
&WXUNUSED(event
) ) 
  89         EndModal(wxID_CANCEL
); 
  93         SetReturnCode(wxID_CANCEL
); 
  98 void wxDialog::OnOK( wxCommandEvent 
&WXUNUSED(event
) ) 
 100     if (Validate() && TransferDataFromWindow()) 
 108             SetReturnCode(wxID_OK
); 
 114 void wxDialog::OnPaint( wxPaintEvent
& WXUNUSED(event
) ) 
 119 void wxDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
)) 
 121     // We'll send a Cancel message by default, 
 122     // which may close the dialog. 
 123     // Check for looping if the Cancel event handler calls Close(). 
 125     // Note that if a cancel button and handler aren't present in the dialog, 
 126     // nothing will happen when you close the dialog via the window manager, or 
 128     // We wouldn't want to destroy the dialog by default, since the dialog may have been 
 129     // created on the stack. 
 130     // However, this does mean that calling dialog->Close() won't delete the dialog 
 131     // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be 
 132     // sure to destroy the dialog. 
 133     // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog. 
 135     static wxList s_closing
; 
 137     if (s_closing
.Member(this)) 
 140     s_closing
.Append(this); 
 142     wxCommandEvent 
cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED
, wxID_CANCEL
); 
 143     cancelEvent
.SetEventObject( this ); 
 144     GetEventHandler()->ProcessEvent(cancelEvent
); 
 145     s_closing
.DeleteObject(this); 
 148 bool wxDialog::Show( bool show 
) 
 150     if (!show 
&& IsModal()) 
 152         EndModal( wxID_CANCEL 
); 
 155     if (show 
&& !m_sizeSet
) 
 157         /* by calling GtkOnSize here, we don't have to call 
 158            either after showing the frame, which would entail 
 159            much ugly flicker nor from within the size_allocate 
 160            handler, because GTK 1.1.X forbids that. */ 
 162         GtkOnSize( m_x
, m_y
, m_width
, m_height 
); 
 165     bool ret 
= wxWindow::Show( show 
); 
 167     if (show
) InitDialog(); 
 172 bool wxDialog::IsModal() const 
 174     return m_modalShowing
; 
 177 void wxDialog::SetModal( bool WXUNUSED(flag
) ) 
 181     m_windowStyle |= wxDIALOG_MODAL; 
 183     if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL; 
 185     wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); 
 188 int wxDialog::ShowModal() 
 192        wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") ); 
 193        return GetReturnCode(); 
 196     // use the apps top level window as parent if none given unless explicitly 
 198     if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT
) ) 
 200         wxWindow 
*parent 
= wxTheApp
->GetTopWindow(); 
 201         if ( parent 
&& parent 
!= this ) 
 204             gtk_window_set_transient_for( GTK_WINDOW(m_widget
), GTK_WINDOW(parent
->m_widget
) ); 
 208     wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor 
 212     m_modalShowing 
= TRUE
; 
 216     gtk_grab_add( m_widget 
); 
 218     gtk_grab_remove( m_widget 
); 
 222     return GetReturnCode(); 
 225 void wxDialog::EndModal( int retCode 
) 
 227     SetReturnCode( retCode 
); 
 231         wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); 
 235     m_modalShowing 
= FALSE
;