]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dialog.cpp
rebaked after timer/socket changes
[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
DS
79 m_isBeingDeleted = true;
80 Show(false);
e9576ca5
SC
81}
82
0be27418
VZ
83// On mac command-stop does the same thing as Esc, let the base class know
84// about it
85bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
e9576ca5 86{
0be27418
VZ
87 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
88 return true;
efb064f7 89
0be27418 90 return wxDialogBase::IsEscapeKey(event);
e9576ca5
SC
91}
92
2f1ae414 93bool wxDialog::IsModal() const
51abe921 94{
285ce5a3
JS
95 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
96 // return m_isModalStyle;
51abe921
SC
97}
98
2f1ae414 99
e9576ca5
SC
100bool wxDialog::Show(bool show)
101{
2f1ae414 102 if ( !wxDialogBase::Show(show) )
2f1ae414 103 // nothing to do
1aa7b427 104 return false;
e9576ca5 105
2f1ae414 106 if ( show )
2f1ae414
SC
107 // usually will result in TransferDataToWindow() being called
108 InitDialog();
e9576ca5 109
6239ee05
SC
110 HiliteMenu(0);
111
285ce5a3 112 if ( m_isModalStyle )
e7549107 113 {
2f1ae414
SC
114 if ( show )
115 {
116 DoShowModal();
117 }
118 else // end of modal dialog
119 {
1aa7b427 120 // this will cause IsModalShowing() return false and our local
2f1ae414
SC
121 // message loop will terminate
122 wxModalDialogs.DeleteObject(this);
123 }
124 }
e7549107 125
1aa7b427 126 return true;
e9576ca5
SC
127}
128
2f1ae414 129void wxDialog::DoShowModal()
51abe921 130{
5a2b31a0 131 wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
51abe921 132
2f1ae414 133 wxModalDialogs.Append(this);
51abe921 134
90b78a56 135 SetFocus() ;
670f9935 136
6239ee05
SC
137 WindowRef windowRef = (WindowRef) MacGetWindowRef();
138 WindowGroupRef windowGroup;
139 WindowGroupRef formerParentGroup;
140 bool resetGroupParent = false;
141
142 if ( GetParent() == NULL )
143 {
144 windowGroup = GetWindowGroup(windowRef) ;
145 formerParentGroup = GetWindowGroupParent( windowGroup );
146 SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
147 resetGroupParent = true;
148 }
149 BeginAppModalStateForWindow(windowRef) ;
efb064f7 150
5a2b31a0 151 while ( IsModal() )
e40298d5
JS
152 {
153 wxTheApp->MacDoOneEvent() ;
154 // calls process idle itself
155 }
eeacbb8c 156
6239ee05
SC
157 EndAppModalStateForWindow(windowRef) ;
158 if ( resetGroupParent )
159 {
160 SetWindowGroupParent( windowGroup , formerParentGroup );
161 }
51abe921 162}
519cb848 163
2f1ae414 164
1aa7b427 165// Replacement for Show(true) for modal dialogs - returns return code
e9576ca5
SC
166int wxDialog::ShowModal()
167{
285ce5a3 168 if ( !m_isModalStyle )
1aa7b427 169 SetModal(true);
81b41c03 170
1aa7b427 171 Show(true);
efb064f7 172
e40298d5 173 return GetReturnCode();
e9576ca5
SC
174}
175
2f1ae414
SC
176// NB: this function (surprizingly) may be called for both modal and modeless
177// dialogs and should work for both of them
e9576ca5
SC
178void wxDialog::EndModal(int retCode)
179{
285ce5a3 180 SetReturnCode(retCode);
1aa7b427 181 Show(false);
285ce5a3 182 SetModal(false);
e9576ca5
SC
183}
184