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