]> git.saurik.com Git - wxWidgets.git/blob - src/osx/dialog_osx.cpp
Get ShowWindowModal behavior working under OS X Cocoa for file, dir and message dialogs.
[wxWidgets.git] / src / osx / dialog_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/dialog_osx.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/dialog.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #include "wx/utils.h"
19 #include "wx/frame.h"
20 #include "wx/settings.h"
21 #endif // WX_PRECOMP
22
23 #include "wx/osx/private.h"
24
25
26 // Lists to keep track of windows, so we can disable/enable them
27 // for modal dialogs
28
29 wxList wxModalDialogs;
30
31 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
32
33 void wxDialog::Init()
34 {
35 m_modality = wxDIALOG_MODALITY_NONE;
36 }
37
38 bool wxDialog::Create( wxWindow *parent,
39 wxWindowID id,
40 const wxString& title,
41 const wxPoint& pos,
42 const wxSize& size,
43 long style,
44 const wxString& name )
45 {
46 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
47
48 // All dialogs should really have this style...
49 style |= wxTAB_TRAVERSAL;
50
51 // ...but not these styles
52 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
53
54 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
55 return false;
56
57 return true;
58 }
59
60 wxDialog::~wxDialog()
61 {
62 SendDestroyEvent();
63
64 // if the dialog is modal, this will end its event loop
65 Show(false);
66 }
67
68 // On mac command-stop does the same thing as Esc, let the base class know
69 // about it
70 bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
71 {
72 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
73 return true;
74
75 return wxDialogBase::IsEscapeKey(event);
76 }
77
78 bool wxDialog::IsModal() const
79 {
80 return m_modality != wxDIALOG_MODALITY_NONE;
81 }
82
83 bool wxDialog::Show(bool show)
84 {
85 if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL )
86 {
87 if ( !wxWindow::Show(show) )
88 // nothing to do
89 return false;
90 }
91 else
92 {
93 if ( !wxDialogBase::Show(show) )
94 // nothing to do
95 return false;
96 }
97
98 if (show && CanDoLayoutAdaptation())
99 DoLayoutAdaptation();
100
101 if ( show )
102 // usually will result in TransferDataToWindow() being called
103 InitDialog();
104
105 if ( !show )
106 {
107 switch( m_modality )
108 {
109 case wxDIALOG_MODALITY_WINDOW_MODAL:
110 EndWindowModal(); // OS X implementation method for cleanup
111 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
112 break;
113 default:
114 break;
115 }
116 m_modality = wxDIALOG_MODALITY_NONE;
117 }
118
119 return true;
120 }
121
122 // Replacement for Show(true) for modal dialogs - returns return code
123 int wxDialog::ShowModal()
124 {
125 m_modality = wxDIALOG_MODALITY_APP_MODAL;
126
127 Show();
128
129 DoShowModal();
130
131 return GetReturnCode();
132 }
133
134 void wxDialog::ShowWindowModal()
135 {
136 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
137
138 Show();
139
140 DoShowWindowModal();
141 }
142
143 wxDialogModality wxDialog::GetModality() const
144 {
145 return m_modality;
146 }
147
148 // NB: this function (surprisingly) may be called for both modal and modeless
149 // dialogs and should work for both of them
150 void wxDialog::EndModal(int retCode)
151 {
152 SetReturnCode(retCode);
153 Show(false);
154 }
155