]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dialog.cpp
Rework wxMotif font/color inheritance so it works
[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
cd17aeff 56#if TARGET_API_MAC_OSX
5e02e8e8 57 HIViewRef growBoxRef = 0 ;
efb064f7 58 OSStatus err = HIViewFindByID( HIViewGetRoot( (WindowRef)m_macWindow ), kHIViewWindowGrowBoxID, &growBoxRef );
5e02e8e8 59 if ( err == noErr && growBoxRef != 0 )
efb064f7 60 HIGrowBoxViewSetTransparent( growBoxRef, true ) ;
cd17aeff 61#endif
efb064f7 62
1aa7b427 63 return true;
e9576ca5
SC
64}
65
efb064f7 66void wxDialog::SetModal( bool flag )
e9576ca5 67{
e40298d5 68 if ( flag )
2f1ae414 69 {
2c326ada 70 m_isModalStyle = true;
eeacbb8c 71
efb064f7
DS
72 wxModelessWindows.DeleteObject( this );
73
643a0828 74#if TARGET_CARBON
efb064f7 75 SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
643a0828 76#endif
2f1ae414
SC
77 }
78 else
79 {
2c326ada 80 m_isModalStyle = false;
eeacbb8c 81
efb064f7 82 wxModelessWindows.Append( this );
2f1ae414 83 }
e9576ca5
SC
84}
85
86wxDialog::~wxDialog()
87{
1aa7b427
DS
88 m_isBeingDeleted = true;
89 Show(false);
e9576ca5
SC
90}
91
0be27418
VZ
92// On mac command-stop does the same thing as Esc, let the base class know
93// about it
94bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
e9576ca5 95{
0be27418
VZ
96 if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
97 return true;
efb064f7 98
0be27418 99 return wxDialogBase::IsEscapeKey(event);
e9576ca5
SC
100}
101
2f1ae414 102bool wxDialog::IsModal() const
51abe921 103{
285ce5a3
JS
104 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
105 // return m_isModalStyle;
51abe921
SC
106}
107
2f1ae414
SC
108
109bool wxDialog::IsModalShowing() const
51abe921 110{
2f1ae414 111 return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
51abe921
SC
112}
113
e9576ca5
SC
114bool wxDialog::Show(bool show)
115{
2f1ae414 116 if ( !wxDialogBase::Show(show) )
2f1ae414 117 // nothing to do
1aa7b427 118 return false;
e9576ca5 119
2f1ae414 120 if ( show )
2f1ae414
SC
121 // usually will result in TransferDataToWindow() being called
122 InitDialog();
e9576ca5 123
285ce5a3 124 if ( m_isModalStyle )
e7549107 125 {
2f1ae414
SC
126 if ( show )
127 {
128 DoShowModal();
129 }
130 else // end of modal dialog
131 {
1aa7b427 132 // this will cause IsModalShowing() return false and our local
2f1ae414
SC
133 // message loop will terminate
134 wxModalDialogs.DeleteObject(this);
135 }
136 }
e7549107 137
1aa7b427 138 return true;
e9576ca5
SC
139}
140
2726cac5
SC
141#if !TARGET_CARBON
142extern bool s_macIsInModalLoop ;
143#endif
144
2f1ae414 145void wxDialog::DoShowModal()
51abe921 146{
efb064f7 147 wxCHECK_RET( !IsModalShowing(), wxT("DoShowModal() called twice") );
51abe921 148
2f1ae414 149 wxModalDialogs.Append(this);
51abe921 150
90b78a56 151 SetFocus() ;
670f9935 152
2726cac5 153#if TARGET_CARBON
f697130e 154 BeginAppModalStateForWindow( (WindowRef) MacGetWindowRef()) ;
2726cac5 155#else
e40298d5
JS
156 // TODO : test whether parent gets disabled
157 bool formerModal = s_macIsInModalLoop ;
158 s_macIsInModalLoop = true ;
2726cac5 159#endif
efb064f7 160
e40298d5
JS
161 while ( IsModalShowing() )
162 {
163 wxTheApp->MacDoOneEvent() ;
164 // calls process idle itself
165 }
eeacbb8c 166
2726cac5 167#if TARGET_CARBON
f697130e 168 EndAppModalStateForWindow( (WindowRef) MacGetWindowRef() ) ;
2726cac5
SC
169#else
170 // TODO probably reenable the parent window if any
e40298d5 171 s_macIsInModalLoop = formerModal ;
2726cac5 172#endif
51abe921 173}
519cb848 174
2f1ae414 175
1aa7b427 176// Replacement for Show(true) for modal dialogs - returns return code
e9576ca5
SC
177int wxDialog::ShowModal()
178{
285ce5a3 179 if ( !m_isModalStyle )
1aa7b427 180 SetModal(true);
81b41c03 181
1aa7b427 182 Show(true);
efb064f7 183
e40298d5 184 return GetReturnCode();
e9576ca5
SC
185}
186
2f1ae414
SC
187// NB: this function (surprizingly) may be called for both modal and modeless
188// dialogs and should work for both of them
e9576ca5
SC
189void wxDialog::EndModal(int retCode)
190{
285ce5a3 191 SetReturnCode(retCode);
1aa7b427 192 Show(false);
285ce5a3 193 SetModal(false);
e9576ca5
SC
194}
195