]> git.saurik.com Git - wxWidgets.git/blame - src/osx/dialog_osx.cpp
fix for GTK assert after r72696, a draw/expose_event signal may also be attached...
[wxWidgets.git] / src / osx / dialog_osx.cpp
CommitLineData
3ccc5735
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/dialog_osx.cpp
3// Purpose: wxDialog class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
3ccc5735
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/dialog.h"
62068535 15#include "wx/evtloop.h"
643e9cf9 16#include "wx/testing.h"
3ccc5735
SC
17
18#ifndef WX_PRECOMP
19 #include "wx/app.h"
20 #include "wx/utils.h"
21 #include "wx/frame.h"
22 #include "wx/settings.h"
23#endif // WX_PRECOMP
24
25#include "wx/osx/private.h"
26
445e564f
SC
27static int s_openDialogs = 0;
28bool wxDialog::OSXHasModalDialogsOpen()
29{
30 return s_openDialogs > 0;
31}
32
33void wxDialog::OSXBeginModalDialog()
34{
35 s_openDialogs++;
36}
37
38void wxDialog::OSXEndModalDialog()
39{
40 wxASSERT_MSG( s_openDialogs > 0, "incorrect internal modal dialog count");
41 s_openDialogs--;
42}
3ccc5735 43
3ccc5735
SC
44void wxDialog::Init()
45{
4d572a2c 46 m_modality = wxDIALOG_MODALITY_NONE;
62068535 47 m_eventLoop = NULL;
3ccc5735
SC
48}
49
50bool wxDialog::Create( wxWindow *parent,
51 wxWindowID id,
52 const wxString& title,
53 const wxPoint& pos,
54 const wxSize& size,
55 long style,
56 const wxString& name )
57{
58 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
59
60 // All dialogs should really have this style...
61 style |= wxTAB_TRAVERSAL;
62
63 // ...but not these styles
64 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
65
66 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
67 return false;
68
69 return true;
70}
71
3ccc5735
SC
72wxDialog::~wxDialog()
73{
c6212a0c 74 SendDestroyEvent();
3ccc5735
SC
75
76 // if the dialog is modal, this will end its event loop
77 Show(false);
78}
79
80// On mac command-stop does the same thing as Esc, let the base class know
81// about it
82bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
83{
3c5f6264 84 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CONTROL )
3ccc5735
SC
85 return true;
86
87 return wxDialogBase::IsEscapeKey(event);
88}
89
90bool wxDialog::IsModal() const
91{
4d572a2c 92 return m_modality != wxDIALOG_MODALITY_NONE;
3ccc5735
SC
93}
94
3ccc5735
SC
95bool wxDialog::Show(bool show)
96{
4d572a2c
SC
97 if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL )
98 {
99 if ( !wxWindow::Show(show) )
100 // nothing to do
101 return false;
102 }
ce00f59b 103 else
4d572a2c
SC
104 {
105 if ( !wxDialogBase::Show(show) )
106 // nothing to do
107 return false;
108 }
3ccc5735
SC
109
110 if (show && CanDoLayoutAdaptation())
111 DoLayoutAdaptation();
112
113 if ( show )
114 // usually will result in TransferDataToWindow() being called
115 InitDialog();
116
4d572a2c 117 if ( !show )
3ccc5735 118 {
4be7f29a
VZ
119 const int modalityOrig = m_modality;
120
121 // complete the 'hiding' before we send the event
122 m_modality = wxDIALOG_MODALITY_NONE;
123
124 switch ( modalityOrig )
3ccc5735 125 {
4d572a2c
SC
126 case wxDIALOG_MODALITY_WINDOW_MODAL:
127 EndWindowModal(); // OS X implementation method for cleanup
ce00f59b 128 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
4d572a2c
SC
129 break;
130 default:
131 break;
3ccc5735
SC
132 }
133 }
ce00f59b 134
3ccc5735
SC
135 return true;
136}
137
138// Replacement for Show(true) for modal dialogs - returns return code
139int wxDialog::ShowModal()
140{
643e9cf9
VS
141 WX_TESTING_SHOW_MODAL_HOOK();
142
bfa92264 143 m_modality = wxDIALOG_MODALITY_APP_MODAL;
ce00f59b 144
4d572a2c 145 Show();
3ccc5735 146
62068535
SC
147 wxModalEventLoop modalLoop(this);
148 m_eventLoop = &modalLoop;
ce00f59b 149
445e564f 150 wxDialog::OSXBeginModalDialog();
62068535 151 modalLoop.Run();
445e564f 152 wxDialog::OSXEndModalDialog();
ce00f59b 153
62068535 154 m_eventLoop = NULL;
ce00f59b 155
3ccc5735
SC
156 return GetReturnCode();
157}
158
4d572a2c
SC
159void wxDialog::ShowWindowModal()
160{
161 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
ce00f59b 162
4d572a2c 163 Show();
ce00f59b 164
4d572a2c
SC
165 DoShowWindowModal();
166}
167
168wxDialogModality wxDialog::GetModality() const
169{
170 return m_modality;
171}
172
cbab1556 173// NB: this function (surprisingly) may be called for both modal and modeless
3ccc5735
SC
174// dialogs and should work for both of them
175void wxDialog::EndModal(int retCode)
176{
62068535
SC
177 if ( m_eventLoop )
178 m_eventLoop->Exit(retCode);
ce00f59b 179
3ccc5735
SC
180 SetReturnCode(retCode);
181 Show(false);
3ccc5735
SC
182}
183