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