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