]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dialog.cpp
added wxGLCanvas::IsDisplaySupported() (patch 1879906)
[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 && CanDoLayoutAdaptation())
107 DoLayoutAdaptation();
108
109 if ( show )
110 // usually will result in TransferDataToWindow() being called
111 InitDialog();
112
113 HiliteMenu(0);
114
115 if ( m_isModalStyle )
116 {
117 if ( show )
118 {
119 DoShowModal();
120 }
121 else // end of modal dialog
122 {
123 // this will cause IsModalShowing() return false and our local
124 // message loop will terminate
125 wxModalDialogs.DeleteObject(this);
126 }
127 }
128
129 return true;
130 }
131
132 void wxDialog::DoShowModal()
133 {
134 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
135
136 wxModalDialogs.Append(this);
137
138 SetFocus() ;
139
140 WindowRef windowRef = (WindowRef) MacGetWindowRef();
141 WindowGroupRef windowGroup;
142 WindowGroupRef formerParentGroup;
143 bool resetGroupParent = false;
144
145 if ( GetParent() == NULL )
146 {
147 windowGroup = GetWindowGroup(windowRef) ;
148 formerParentGroup = GetWindowGroupParent( windowGroup );
149 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
150 resetGroupParent = true;
151 }
152 BeginAppModalStateForWindow(windowRef) ;
153
154 while ( IsModal() )
155 {
156 wxTheApp->MacDoOneEvent() ;
157 // calls process idle itself
158 }
159
160 EndAppModalStateForWindow(windowRef) ;
161 if ( resetGroupParent )
162 {
163 SetWindowGroupParent( windowGroup , formerParentGroup );
164 }
165 }
166
167
168 // Replacement for Show(true) for modal dialogs - returns return code
169 int wxDialog::ShowModal()
170 {
171 if ( !m_isModalStyle )
172 SetModal(true);
173
174 Show(true);
175
176 return GetReturnCode();
177 }
178
179 // NB: this function (surprizingly) may be called for both modal and modeless
180 // dialogs and should work for both of them
181 void wxDialog::EndModal(int retCode)
182 {
183 SetReturnCode(retCode);
184 Show(false);
185 SetModal(false);
186 }
187