]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dialog.cpp
splitted wxApp docs in wxApp+wxAppConsole docs; fix the signature of the documented...
[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
efb064f7 67 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
2f1ae414
SC
68 }
69 else
70 {
2c326ada 71 m_isModalStyle = false;
eeacbb8c 72
efb064f7 73 wxModelessWindows.Append( this );
2f1ae414 74 }
e9576ca5
SC
75}
76
77wxDialog::~wxDialog()
78{
1aa7b427 79 m_isBeingDeleted = true;
a9efc294
VS
80
81 // if the dialog is modal, this will end its event loop
1aa7b427 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
3aa8e4ea
JS
108 if (show && CanDoLayoutAdaptation())
109 DoLayoutAdaptation();
110
2f1ae414 111 if ( show )
2f1ae414
SC
112 // usually will result in TransferDataToWindow() being called
113 InitDialog();
e9576ca5 114
6239ee05
SC
115 HiliteMenu(0);
116
285ce5a3 117 if ( m_isModalStyle )
e7549107 118 {
2f1ae414
SC
119 if ( show )
120 {
121 DoShowModal();
122 }
123 else // end of modal dialog
124 {
1aa7b427 125 // this will cause IsModalShowing() return false and our local
2f1ae414
SC
126 // message loop will terminate
127 wxModalDialogs.DeleteObject(this);
128 }
129 }
e7549107 130
1aa7b427 131 return true;
e9576ca5
SC
132}
133
2f1ae414 134void wxDialog::DoShowModal()
51abe921 135{
5a2b31a0 136 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
51abe921 137
2f1ae414 138 wxModalDialogs.Append(this);
51abe921 139
90b78a56 140 SetFocus() ;
670f9935 141
6239ee05
SC
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) ;
efb064f7 155
5a2b31a0 156 while ( IsModal() )
e40298d5
JS
157 {
158 wxTheApp->MacDoOneEvent() ;
159 // calls process idle itself
160 }
eeacbb8c 161
6239ee05
SC
162 EndAppModalStateForWindow(windowRef) ;
163 if ( resetGroupParent )
164 {
165 SetWindowGroupParent( windowGroup , formerParentGroup );
166 }
51abe921 167}
519cb848 168
2f1ae414 169
1aa7b427 170// Replacement for Show(true) for modal dialogs - returns return code
e9576ca5
SC
171int wxDialog::ShowModal()
172{
285ce5a3 173 if ( !m_isModalStyle )
1aa7b427 174 SetModal(true);
81b41c03 175
1aa7b427 176 Show(true);
efb064f7 177
e40298d5 178 return GetReturnCode();
e9576ca5
SC
179}
180
2f1ae414
SC
181// NB: this function (surprizingly) may be called for both modal and modeless
182// dialogs and should work for both of them
e9576ca5
SC
183void wxDialog::EndModal(int retCode)
184{
285ce5a3 185 SetReturnCode(retCode);
1aa7b427 186 Show(false);
285ce5a3 187 SetModal(false);
e9576ca5
SC
188}
189