]> git.saurik.com Git - wxWidgets.git/blame - src/mac/dialog.cpp
Files from a Drop were only added but the fileslist never cleard
[wxWidgets.git] / src / mac / dialog.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialog.cpp
3// Purpose: wxDialog class
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "dialog.h"
14#endif
15
16#include "wx/dialog.h"
17#include "wx/utils.h"
18#include "wx/frame.h"
19#include "wx/app.h"
20#include "wx/settings.h"
21
d497dca4 22#include "wx/mac/uma.h"
519cb848 23
e9576ca5
SC
24// Lists to keep track of windows, so we can disable/enable them
25// for modal dialogs
26wxList wxModalDialogs;
fe08e597 27//wxList wxModelessWindows; // Frames and modeless dialogs
e9576ca5
SC
28extern wxList wxPendingDelete;
29
2f1ae414 30#if !USE_SHARED_LIBRARY
a15eb0a5 31IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
e9576ca5 32
d491523b 33BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
e9576ca5
SC
34 EVT_BUTTON(wxID_OK, wxDialog::OnOK)
35 EVT_BUTTON(wxID_APPLY, wxDialog::OnApply)
36 EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel)
a15eb0a5 37
e9576ca5 38 EVT_CHAR_HOOK(wxDialog::OnCharHook)
a15eb0a5 39
e9576ca5 40 EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged)
a15eb0a5 41
e9576ca5
SC
42 EVT_CLOSE(wxDialog::OnCloseWindow)
43END_EVENT_TABLE()
44
2f1ae414 45#endif
e9576ca5
SC
46
47wxDialog::wxDialog()
48{
2f1ae414 49 m_isShown = FALSE;
a756f210 50 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
e9576ca5
SC
51}
52
53bool wxDialog::Create(wxWindow *parent, wxWindowID id,
54 const wxString& title,
55 const wxPoint& pos,
56 const wxSize& size,
57 long style,
58 const wxString& name)
59{
e9576ca5 60
a756f210 61 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
e9576ca5 62
e9576ca5 63
a15eb0a5
SC
64 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
65 return FALSE;
e9576ca5 66
2f1ae414 67 MacCreateRealWindow( title , pos , size , MacRemoveBordersFromStyle(style) , name ) ;
e9576ca5 68
4159f685 69 m_macWindowBackgroundTheme = kThemeBrushDialogBackgroundActive ;
2240c9ed 70 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
519cb848 71 return TRUE;
e9576ca5
SC
72}
73
74void wxDialog::SetModal(bool flag)
75{
2f1ae414
SC
76 if ( flag )
77 {
78 m_windowStyle |= wxDIALOG_MODAL;
79
80 wxModelessWindows.DeleteObject(this);
81 }
82 else
83 {
84 m_windowStyle &= ~wxDIALOG_MODAL;
85
86 wxModelessWindows.Append(this);
87 }
e9576ca5
SC
88}
89
90wxDialog::~wxDialog()
91{
e7549107 92 m_isBeingDeleted = TRUE ;
a15eb0a5 93 Show(FALSE);
e9576ca5
SC
94}
95
a15eb0a5 96// By default, pressing escape cancels the dialog , on mac command-stop does the same thing
e9576ca5
SC
97void wxDialog::OnCharHook(wxKeyEvent& event)
98{
a15eb0a5
SC
99 if (
100 ( event.m_keyCode == WXK_ESCAPE ||
101 ( event.m_keyCode == '.' && event.MetaDown() ) )
102 && FindWindow(wxID_CANCEL) )
e9576ca5
SC
103 {
104 // Behaviour changed in 2.0: we'll send a Cancel message
105 // to the dialog instead of Close.
106 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
107 cancelEvent.SetEventObject( this );
108 GetEventHandler()->ProcessEvent(cancelEvent);
109
110 return;
111 }
112 // We didn't process this event.
113 event.Skip();
114}
115
2f1ae414 116bool wxDialog::IsModal() const
51abe921 117{
2f1ae414 118 return (GetWindowStyleFlag() & wxDIALOG_MODAL) != 0;
51abe921
SC
119}
120
2f1ae414
SC
121
122bool wxDialog::IsModalShowing() const
51abe921 123{
2f1ae414 124 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
51abe921
SC
125}
126
e9576ca5
SC
127bool wxDialog::Show(bool show)
128{
2f1ae414
SC
129 if ( !wxDialogBase::Show(show) )
130 {
131 // nothing to do
132 return FALSE;
133 }
e9576ca5 134
2f1ae414
SC
135 if ( show )
136 {
137 // usually will result in TransferDataToWindow() being called
138 InitDialog();
139 }
e9576ca5 140
2f1ae414 141 if ( IsModal() )
e7549107 142 {
2f1ae414
SC
143 if ( show )
144 {
145 DoShowModal();
146 }
147 else // end of modal dialog
148 {
149 // this will cause IsModalShowing() return FALSE and our local
150 // message loop will terminate
151 wxModalDialogs.DeleteObject(this);
152 }
153 }
e7549107 154
2f1ae414 155 return TRUE;
e9576ca5
SC
156}
157
2726cac5
SC
158#if !TARGET_CARBON
159extern bool s_macIsInModalLoop ;
160#endif
161
2f1ae414 162void wxDialog::DoShowModal()
51abe921 163{
2f1ae414 164 wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
51abe921 165
2f1ae414 166 wxModalDialogs.Append(this);
51abe921 167
2f1ae414
SC
168 wxWindow *parent = GetParent();
169
170 // remember where the focus was
171 wxWindow *winFocus = FindFocus();
172 if ( !winFocus )
173 {
174 winFocus = parent;
175 }
176 if ( !winFocus )
177 {
178 winFocus = wxTheApp->GetTopWindow();
179 }
2726cac5
SC
180#if TARGET_CARBON
181 BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ;
182#else
2f1ae414 183 // TODO : test whether parent gets disabled
a49afa93 184 bool formerModal = s_macIsInModalLoop ;
2f1ae414 185 s_macIsInModalLoop = true ;
2726cac5 186#endif
2f1ae414
SC
187 while ( IsModalShowing() )
188 {
2f1ae414 189 wxTheApp->MacDoOneEvent() ;
2726cac5 190 // calls process idle itself
2f1ae414
SC
191 }
192
2726cac5
SC
193#if TARGET_CARBON
194 EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ;
195#else
196 // TODO probably reenable the parent window if any
a49afa93 197 s_macIsInModalLoop = formerModal ;
2726cac5 198#endif
51abe921 199
51abe921 200
2f1ae414
SC
201 // and restore focus
202 if ( winFocus )
203 {
204 winFocus->SetFocus();
205 }
51abe921 206}
519cb848 207
2f1ae414 208
e9576ca5
SC
209// Replacement for Show(TRUE) for modal dialogs - returns return code
210int wxDialog::ShowModal()
211{
81b41c03
SC
212 if ( !IsModal() )
213 {
214 SetModal(TRUE);
215 }
216
217 Show(TRUE);
218 return GetReturnCode();
e9576ca5
SC
219}
220
2f1ae414
SC
221// NB: this function (surprizingly) may be called for both modal and modeless
222// dialogs and should work for both of them
e9576ca5
SC
223void wxDialog::EndModal(int retCode)
224{
51abe921
SC
225 SetReturnCode(retCode);
226 Show(FALSE);
e9576ca5
SC
227}
228
229// Standard buttons
d208e641 230void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event))
e9576ca5 231{
51abe921
SC
232 if ( Validate() && TransferDataFromWindow() )
233 {
2f1ae414 234 EndModal(wxID_OK);
51abe921 235 }
e9576ca5
SC
236}
237
d208e641 238void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
e9576ca5 239{
51abe921
SC
240 if (Validate())
241 TransferDataFromWindow();
242 // TODO probably need to disable the Apply button until things change again
e9576ca5
SC
243}
244
d208e641 245void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
e9576ca5 246{
d208e641 247 EndModal(wxID_CANCEL);
7c74e7fe
SC
248}
249
d208e641 250void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
e9576ca5 251{
e3065973 252 // We'll send a Cancel message by default,
e9576ca5 253 // which may close the dialog.
e3065973
JS
254 // Check for looping if the Cancel event handler calls Close().
255
256 // Note that if a cancel button and handler aren't present in the dialog,
257 // nothing will happen when you close the dialog via the window manager, or
258 // via Close().
259 // We wouldn't want to destroy the dialog by default, since the dialog may have been
260 // created on the stack.
261 // However, this does mean that calling dialog->Close() won't delete the dialog
262 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
263 // sure to destroy the dialog.
264 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
e9576ca5
SC
265
266 static wxList closing;
51abe921 267
e9576ca5 268 if ( closing.Member(this) )
e3065973 269 return;
51abe921 270
e9576ca5 271 closing.Append(this);
51abe921 272
e3065973
JS
273 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
274 cancelEvent.SetEventObject( this );
275 GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog
e9576ca5
SC
276
277 closing.DeleteObject(this);
e9576ca5
SC
278}
279
d208e641 280void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
e9576ca5 281{
a756f210 282 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
e9576ca5
SC
283 Refresh();
284}
285