]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dialog.cpp
cleanup, fixing exports
[wxWidgets.git] / src / mac / 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/mac/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 wxModelessWindows.DeleteObject( this );
66
67 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
68 }
69 else
70 {
71 m_isModalStyle = false;
72
73 wxModelessWindows.Append( this );
74 }
75 }
76
77 wxDialog::~wxDialog()
78 {
79 m_isBeingDeleted = true;
80 Show(false);
81 }
82
83 // On mac command-stop does the same thing as Esc, let the base class know
84 // about it
85 bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
86 {
87 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
88 return true;
89
90 return wxDialogBase::IsEscapeKey(event);
91 }
92
93 bool wxDialog::IsModal() const
94 {
95 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
96 // return m_isModalStyle;
97 }
98
99
100 bool wxDialog::Show(bool show)
101 {
102 if ( !wxDialogBase::Show(show) )
103 // nothing to do
104 return false;
105
106 if ( show )
107 // usually will result in TransferDataToWindow() being called
108 InitDialog();
109
110 HiliteMenu(0);
111
112 if ( m_isModalStyle )
113 {
114 if ( show )
115 {
116 DoShowModal();
117 }
118 else // end of modal dialog
119 {
120 // this will cause IsModalShowing() return false and our local
121 // message loop will terminate
122 wxModalDialogs.DeleteObject(this);
123 }
124 }
125
126 return true;
127 }
128
129 void wxDialog::DoShowModal()
130 {
131 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
132
133 wxModalDialogs.Append(this);
134
135 SetFocus() ;
136
137 WindowRef windowRef = (WindowRef) MacGetWindowRef();
138 WindowGroupRef windowGroup;
139 WindowGroupRef formerParentGroup;
140 bool resetGroupParent = false;
141
142 if ( GetParent() == NULL )
143 {
144 windowGroup = GetWindowGroup(windowRef) ;
145 formerParentGroup = GetWindowGroupParent( windowGroup );
146 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
147 resetGroupParent = true;
148 }
149 BeginAppModalStateForWindow(windowRef) ;
150
151 while ( IsModal() )
152 {
153 wxTheApp->MacDoOneEvent() ;
154 // calls process idle itself
155 }
156
157 EndAppModalStateForWindow(windowRef) ;
158 if ( resetGroupParent )
159 {
160 SetWindowGroupParent( windowGroup , formerParentGroup );
161 }
162 }
163
164
165 // Replacement for Show(true) for modal dialogs - returns return code
166 int wxDialog::ShowModal()
167 {
168 if ( !m_isModalStyle )
169 SetModal(true);
170
171 Show(true);
172
173 return GetReturnCode();
174 }
175
176 // NB: this function (surprizingly) may be called for both modal and modeless
177 // dialogs and should work for both of them
178 void wxDialog::EndModal(int retCode)
179 {
180 SetReturnCode(retCode);
181 Show(false);
182 SetModal(false);
183 }
184