]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/dialog.cpp
implement flag for Unix-like behaviour in wxCmdLineParser::ConverStringToArgs()
[wxWidgets.git] / src / osx / carbon / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
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/uma.h"
24
25
26 // Lists to keep track of windows, so we can disable/enable them
27 // for modal dialogs
28 wxList wxModalDialogs;
29
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
31
32 void wxDialog::Init()
33 {
34 m_isModalStyle = false;
35 }
36
37 bool wxDialog::Create( wxWindow *parent,
38 wxWindowID id,
39 const wxString& title,
40 const wxPoint& pos,
41 const wxSize& size,
42 long style,
43 const wxString& name )
44 {
45 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
46
47 // All dialogs should really have this style...
48 style |= wxTAB_TRAVERSAL;
49
50 // ...but not these styles
51 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
52
53 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
54 return false;
55
56 return true;
57 }
58
59 void wxDialog::SetModal( bool flag )
60 {
61 if ( flag )
62 {
63 m_isModalStyle = true;
64
65 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
66 }
67 else
68 {
69 m_isModalStyle = false;
70 }
71 }
72
73 wxDialog::~wxDialog()
74 {
75 m_isBeingDeleted = true;
76
77 // if the dialog is modal, this will end its event loop
78 Show(false);
79 }
80
81 // On mac command-stop does the same thing as Esc, let the base class know
82 // about it
83 bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
84 {
85 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
86 return true;
87
88 return wxDialogBase::IsEscapeKey(event);
89 }
90
91 bool wxDialog::IsModal() const
92 {
93 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
94 // return m_isModalStyle;
95 }
96
97
98 bool wxDialog::Show(bool show)
99 {
100 if ( !wxDialogBase::Show(show) )
101 // nothing to do
102 return false;
103
104 if (show && CanDoLayoutAdaptation())
105 DoLayoutAdaptation();
106
107 if ( show )
108 // usually will result in TransferDataToWindow() being called
109 InitDialog();
110
111 HiliteMenu(0);
112
113 if ( m_isModalStyle )
114 {
115 if ( show )
116 {
117 DoShowModal();
118 }
119 else // end of modal dialog
120 {
121 // this will cause IsModalShowing() return false and our local
122 // message loop will terminate
123 wxModalDialogs.DeleteObject(this);
124 }
125 }
126
127 return true;
128 }
129
130 void wxDialog::DoShowModal()
131 {
132 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
133
134 wxModalDialogs.Append(this);
135
136 SetFocus() ;
137
138 WindowRef windowRef = (WindowRef) MacGetWindowRef();
139 WindowGroupRef windowGroup;
140 WindowGroupRef formerParentGroup;
141 bool resetGroupParent = false;
142
143 if ( GetParent() == NULL )
144 {
145 windowGroup = GetWindowGroup(windowRef) ;
146 formerParentGroup = GetWindowGroupParent( windowGroup );
147 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
148 resetGroupParent = true;
149 }
150 BeginAppModalStateForWindow(windowRef) ;
151
152 while ( IsModal() )
153 {
154 wxTheApp->MacDoOneEvent() ;
155 // calls process idle itself
156 }
157
158 EndAppModalStateForWindow(windowRef) ;
159 if ( resetGroupParent )
160 {
161 SetWindowGroupParent( windowGroup , formerParentGroup );
162 }
163 }
164
165
166 // Replacement for Show(true) for modal dialogs - returns return code
167 int wxDialog::ShowModal()
168 {
169 if ( !m_isModalStyle )
170 SetModal(true);
171
172 if ( IsShown() )
173 DoShowModal();
174 else
175 Show(true);
176
177 return GetReturnCode();
178 }
179
180 // NB: this function (surprizingly) may be called for both modal and modeless
181 // dialogs and should work for both of them
182 void wxDialog::EndModal(int retCode)
183 {
184 SetReturnCode(retCode);
185 Show(false);
186 SetModal(false);
187 }
188