]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dialog.cpp
non-pch build fix
[wxWidgets.git] / src / mac / carbon / dialog.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/mac/carbon/dialog.cpp
e9576ca5 3// Purpose: wxDialog class
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
670f9935 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/dialog.h"
670f9935
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/app.h"
de6185e2 18 #include "wx/utils.h"
76b49cf4 19 #include "wx/frame.h"
9eddec69 20 #include "wx/settings.h"
670f9935
WS
21#endif // WX_PRECOMP
22
d497dca4 23#include "wx/mac/uma.h"
519cb848 24
efb064f7 25
e9576ca5
SC
26// Lists to keep track of windows, so we can disable/enable them
27// for modal dialogs
28wxList wxModalDialogs;
efb064f7 29
a15eb0a5 30IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
e9576ca5 31
2c326ada 32void wxDialog::Init()
e9576ca5 33{
2c326ada 34 m_isModalStyle = false;
e9576ca5
SC
35}
36
efb064f7
DS
37bool 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 )
e9576ca5 44{
efb064f7 45 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
eeacbb8c 46
efb064f7 47 // All dialogs should really have this style...
facd6764 48 style |= wxTAB_TRAVERSAL;
eeacbb8c 49
efb064f7
DS
50 // ...but not these styles
51 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
52
53 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
1aa7b427 54 return false;
670f9935 55
1aa7b427 56 return true;
e9576ca5
SC
57}
58
efb064f7 59void wxDialog::SetModal( bool flag )
e9576ca5 60{
e40298d5 61 if ( flag )
2f1ae414 62 {
2c326ada 63 m_isModalStyle = true;
eeacbb8c 64
efb064f7
DS
65 wxModelessWindows.DeleteObject( this );
66
643a0828 67#if TARGET_CARBON
efb064f7 68 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
643a0828 69#endif
2f1ae414
SC
70 }
71 else
72 {
2c326ada 73 m_isModalStyle = false;
eeacbb8c 74
efb064f7 75 wxModelessWindows.Append( this );
2f1ae414 76 }
e9576ca5
SC
77}
78
79wxDialog::~wxDialog()
80{
1aa7b427
DS
81 m_isBeingDeleted = true;
82 Show(false);
e9576ca5
SC
83}
84
0be27418
VZ
85// On mac command-stop does the same thing as Esc, let the base class know
86// about it
87bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
e9576ca5 88{
0be27418
VZ
89 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
90 return true;
efb064f7 91
0be27418 92 return wxDialogBase::IsEscapeKey(event);
e9576ca5
SC
93}
94
2f1ae414 95bool wxDialog::IsModal() const
51abe921 96{
285ce5a3
JS
97 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
98 // return m_isModalStyle;
51abe921
SC
99}
100
2f1ae414 101
e9576ca5
SC
102bool wxDialog::Show(bool show)
103{
2f1ae414 104 if ( !wxDialogBase::Show(show) )
2f1ae414 105 // nothing to do
1aa7b427 106 return false;
e9576ca5 107
2f1ae414 108 if ( show )
2f1ae414
SC
109 // usually will result in TransferDataToWindow() being called
110 InitDialog();
e9576ca5 111
6239ee05
SC
112 HiliteMenu(0);
113
285ce5a3 114 if ( m_isModalStyle )
e7549107 115 {
2f1ae414
SC
116 if ( show )
117 {
118 DoShowModal();
119 }
120 else // end of modal dialog
121 {
1aa7b427 122 // this will cause IsModalShowing() return false and our local
2f1ae414
SC
123 // message loop will terminate
124 wxModalDialogs.DeleteObject(this);
125 }
126 }
e7549107 127
1aa7b427 128 return true;
e9576ca5
SC
129}
130
2726cac5
SC
131#if !TARGET_CARBON
132extern bool s_macIsInModalLoop ;
133#endif
134
2f1ae414 135void wxDialog::DoShowModal()
51abe921 136{
5a2b31a0 137 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
51abe921 138
2f1ae414 139 wxModalDialogs.Append(this);
51abe921 140
90b78a56 141 SetFocus() ;
670f9935 142
6239ee05
SC
143 WindowRef windowRef = (WindowRef) MacGetWindowRef();
144 WindowGroupRef windowGroup;
145 WindowGroupRef formerParentGroup;
146 bool resetGroupParent = false;
147
148 if ( GetParent() == NULL )
149 {
150 windowGroup = GetWindowGroup(windowRef) ;
151 formerParentGroup = GetWindowGroupParent( windowGroup );
152 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
153 resetGroupParent = true;
154 }
155 BeginAppModalStateForWindow(windowRef) ;
efb064f7 156
5a2b31a0 157 while ( IsModal() )
e40298d5
JS
158 {
159 wxTheApp->MacDoOneEvent() ;
160 // calls process idle itself
161 }
eeacbb8c 162
6239ee05
SC
163 EndAppModalStateForWindow(windowRef) ;
164 if ( resetGroupParent )
165 {
166 SetWindowGroupParent( windowGroup , formerParentGroup );
167 }
51abe921 168}
519cb848 169
2f1ae414 170
1aa7b427 171// Replacement for Show(true) for modal dialogs - returns return code
e9576ca5
SC
172int wxDialog::ShowModal()
173{
285ce5a3 174 if ( !m_isModalStyle )
1aa7b427 175 SetModal(true);
81b41c03 176
1aa7b427 177 Show(true);
efb064f7 178
e40298d5 179 return GetReturnCode();
e9576ca5
SC
180}
181
2f1ae414
SC
182// NB: this function (surprizingly) may be called for both modal and modeless
183// dialogs and should work for both of them
e9576ca5
SC
184void wxDialog::EndModal(int retCode)
185{
285ce5a3 186 SetReturnCode(retCode);
1aa7b427 187 Show(false);
285ce5a3 188 SetModal(false);
e9576ca5
SC
189}
190