]> git.saurik.com Git - wxWidgets.git/blame - src/osx/dialog_osx.cpp
borders might have to be drawn differently
[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
7// RCS-ID: $Id: dialog.cpp 54820 2008-07-29 20:04:11Z 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"
3ccc5735
SC
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/utils.h"
20 #include "wx/frame.h"
21 #include "wx/settings.h"
22#endif // WX_PRECOMP
23
24#include "wx/osx/private.h"
25
3ccc5735
SC
26// Lists to keep track of windows, so we can disable/enable them
27// for modal dialogs
28
29wxList wxModalDialogs;
30
31IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
32
33void wxDialog::Init()
34{
4d572a2c 35 m_modality = wxDIALOG_MODALITY_NONE;
62068535 36 m_eventLoop = NULL;
3ccc5735
SC
37}
38
39bool wxDialog::Create( wxWindow *parent,
40 wxWindowID id,
41 const wxString& title,
42 const wxPoint& pos,
43 const wxSize& size,
44 long style,
45 const wxString& name )
46{
47 SetExtraStyle( GetExtraStyle() | wxTOPLEVEL_EX_DIALOG );
48
49 // All dialogs should really have this style...
50 style |= wxTAB_TRAVERSAL;
51
52 // ...but not these styles
53 style &= ~(wxYES | wxOK | wxNO); // | wxCANCEL
54
55 if ( !wxTopLevelWindow::Create( parent, id, title, pos, size, style, name ) )
56 return false;
57
58 return true;
59}
60
3ccc5735
SC
61wxDialog::~wxDialog()
62{
c6212a0c 63 SendDestroyEvent();
3ccc5735
SC
64
65 // if the dialog is modal, this will end its event loop
66 Show(false);
67}
68
69// On mac command-stop does the same thing as Esc, let the base class know
70// about it
71bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
72{
73 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
74 return true;
75
76 return wxDialogBase::IsEscapeKey(event);
77}
78
79bool wxDialog::IsModal() const
80{
4d572a2c 81 return m_modality != wxDIALOG_MODALITY_NONE;
3ccc5735
SC
82}
83
3ccc5735
SC
84bool wxDialog::Show(bool show)
85{
4d572a2c
SC
86 if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL )
87 {
88 if ( !wxWindow::Show(show) )
89 // nothing to do
90 return false;
91 }
92 else
93 {
94 if ( !wxDialogBase::Show(show) )
95 // nothing to do
96 return false;
97 }
3ccc5735
SC
98
99 if (show && CanDoLayoutAdaptation())
100 DoLayoutAdaptation();
101
102 if ( show )
103 // usually will result in TransferDataToWindow() being called
104 InitDialog();
105
4d572a2c 106 if ( !show )
3ccc5735 107 {
4d572a2c 108 switch( m_modality )
3ccc5735 109 {
4d572a2c
SC
110 case wxDIALOG_MODALITY_WINDOW_MODAL:
111 EndWindowModal(); // OS X implementation method for cleanup
112 SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
113 break;
114 default:
115 break;
3ccc5735 116 }
4d572a2c 117 m_modality = wxDIALOG_MODALITY_NONE;
3ccc5735 118 }
4d572a2c 119
3ccc5735
SC
120 return true;
121}
122
123// Replacement for Show(true) for modal dialogs - returns return code
124int wxDialog::ShowModal()
125{
bfa92264 126 m_modality = wxDIALOG_MODALITY_APP_MODAL;
4d572a2c
SC
127
128 Show();
3ccc5735 129
62068535
SC
130 wxModalEventLoop modalLoop(this);
131 m_eventLoop = &modalLoop;
132
133 modalLoop.Run();
134
135 m_eventLoop = NULL;
136
3ccc5735
SC
137 return GetReturnCode();
138}
139
4d572a2c
SC
140void wxDialog::ShowWindowModal()
141{
142 m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
143
144 Show();
145
146 DoShowWindowModal();
147}
148
149wxDialogModality wxDialog::GetModality() const
150{
151 return m_modality;
152}
153
cbab1556 154// NB: this function (surprisingly) may be called for both modal and modeless
3ccc5735
SC
155// dialogs and should work for both of them
156void wxDialog::EndModal(int retCode)
157{
62068535
SC
158 if ( m_eventLoop )
159 m_eventLoop->Exit(retCode);
160
3ccc5735
SC
161 SetReturnCode(retCode);
162 Show(false);
3ccc5735
SC
163}
164