]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dialog.cpp
3 // Purpose: wxDialog class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/dialog.h"
20 #include "wx/settings.h"
23 #include "wx/mac/uma.h"
26 // Lists to keep track of windows, so we can disable/enable them
28 wxList wxModalDialogs
;
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog
, wxTopLevelWindow
)
34 m_isModalStyle
= false;
37 bool wxDialog::Create( wxWindow
*parent
,
39 const wxString
& title
,
43 const wxString
& name
)
45 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
47 // All dialogs should really have this style...
48 style
|= wxTAB_TRAVERSAL
;
50 // ...but not these styles
51 style
&= ~(wxYES
| wxOK
| wxNO
); // | wxCANCEL
53 if ( !wxTopLevelWindow::Create( parent
, id
, title
, pos
, size
, style
, name
) )
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 ) ;
66 void wxDialog::SetModal( bool flag
)
70 m_isModalStyle
= true;
72 wxModelessWindows
.DeleteObject( this );
75 SetWindowModality( (WindowRef
)MacGetWindowRef(), kWindowModalityAppModal
, NULL
) ;
80 m_isModalStyle
= false;
82 wxModelessWindows
.Append( this );
88 m_isBeingDeleted
= true;
92 // On mac command-stop does the same thing as Esc, let the base class know
94 bool wxDialog::IsEscapeKey(const wxKeyEvent
& event
)
96 if ( event
.GetKeyCode() == '.' && event
.GetModifiers() == wxMOD_CMD
)
99 return wxDialogBase::IsEscapeKey(event
);
102 bool wxDialog::IsModal() const
104 return wxModalDialogs
.Find((wxDialog
*)this) != NULL
; // const_cast
105 // return m_isModalStyle;
109 bool wxDialog::Show(bool show
)
111 if ( !wxDialogBase::Show(show
) )
116 // usually will result in TransferDataToWindow() being called
119 if ( m_isModalStyle
)
125 else // end of modal dialog
127 // this will cause IsModalShowing() return false and our local
128 // message loop will terminate
129 wxModalDialogs
.DeleteObject(this);
137 extern bool s_macIsInModalLoop
;
140 void wxDialog::DoShowModal()
142 wxCHECK_RET( !IsModalShowing(), wxT("DoShowModal() called twice") );
144 wxModalDialogs
.Append(this);
149 BeginAppModalStateForWindow( (WindowRef
) MacGetWindowRef()) ;
151 // TODO : test whether parent gets disabled
152 bool formerModal
= s_macIsInModalLoop
;
153 s_macIsInModalLoop
= true ;
156 while ( IsModalShowing() )
158 wxTheApp
->MacDoOneEvent() ;
159 // calls process idle itself
163 EndAppModalStateForWindow( (WindowRef
) MacGetWindowRef() ) ;
165 // TODO probably reenable the parent window if any
166 s_macIsInModalLoop
= formerModal
;
171 // Replacement for Show(true) for modal dialogs - returns return code
172 int wxDialog::ShowModal()
174 if ( !m_isModalStyle
)
179 return GetReturnCode();
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
)
186 SetReturnCode(retCode
);