]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
Corrected some wxMac images
[wxWidgets.git] / src / gtk / dialog.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/gtk/dialog.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/dialog.h"
670f9935
WS
14
15#ifndef WX_PRECOMP
c8326d64 16 #include "wx/cursor.h"
670f9935
WS
17#endif // WX_PRECOMP
18
924b84ab 19#include "wx/evtloop.h"
83624f79 20
bfafa628
VZ
21#include "wx/ptr_scpd.h"
22
071a2d78 23#include <gtk/gtk.h>
5e014a0c 24
64c11164
VZ
25// this is defined in src/gtk/toplevel.cpp
26extern int wxOpenModalDialogsCount;
acfd422a 27
bfafa628
VZ
28wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop);
29
30
c801d85f
KB
31//-----------------------------------------------------------------------------
32// wxDialog
33//-----------------------------------------------------------------------------
34
7d9f12f3 35IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
c801d85f 36
68995f26 37void wxDialog::Init()
c801d85f 38{
bfafa628 39 m_modalLoop = NULL;
f03fc89f 40 m_returnCode = 0;
91af0895
WS
41 m_modalShowing = false;
42 m_themeEnabled = true;
c33c4050 43}
c801d85f 44
2b854a32 45wxDialog::wxDialog( wxWindow *parent,
fb1585ae 46 wxWindowID id, const wxString &title,
2b854a32 47 const wxPoint &pos, const wxSize &size,
fb1585ae 48 long style, const wxString &name )
c801d85f 49{
68995f26
VZ
50 Init();
51
82c9f85c 52 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 53}
c801d85f
KB
54
55bool wxDialog::Create( wxWindow *parent,
fb1585ae 56 wxWindowID id, const wxString &title,
2b854a32 57 const wxPoint &pos, const wxSize &size,
fb1585ae 58 long style, const wxString &name )
c801d85f 59{
21f4383a 60 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 61
82c9f85c
VZ
62 // all dialogs should have tab traversal enabled
63 style |= wxTAB_TRAVERSAL;
64
7d9f12f3 65 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 66}
c801d85f 67
debe6624 68bool wxDialog::Show( bool show )
c801d85f 69{
fb1585ae
RR
70 if (!show && IsModal())
71 {
de8113d9 72 EndModal( wxID_CANCEL );
fb1585ae 73 }
c801d85f 74
3aa8e4ea
JS
75 if (show && CanDoLayoutAdaptation())
76 DoLayoutAdaptation();
77
8fb09a08 78 bool ret = wxDialogBase::Show(show);
e146b8c8 79
a9efc294
VS
80 if (show)
81 InitDialog();
2b854a32 82
739730ca 83 return ret;
c33c4050
RR
84}
85
a9efc294
VS
86wxDialog::~wxDialog()
87{
88 m_isBeingDeleted = true;
89
90 // if the dialog is modal, this will end its event loop
0af07cc2
VS
91 if ( IsModal() )
92 EndModal(wxID_CANCEL);
a9efc294
VS
93}
94
43a18898 95bool wxDialog::IsModal() const
e1e955e1 96{
fb1585ae 97 return m_modalShowing;
e1e955e1
RR
98}
99
100void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 101{
223d09f6 102 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 103}
c801d85f 104
43a18898 105int wxDialog::ShowModal()
c801d85f 106{
4e2a3778 107 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
e146b8c8 108
7738af59
VZ
109 // release the mouse if it's currently captured as the window having it
110 // will be disabled when this dialog is shown -- but will still keep the
111 // capture making it impossible to do anything in the modal dialog itself
112 wxWindow * const win = wxWindow::GetCapture();
113 if ( win )
114 win->GTKReleaseMouseAndNotify();
115
b3daa5a3
VZ
116 // use the apps top level window as parent if none given unless explicitly
117 // forbidden
118 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
f6bcfd97 119 {
31fdb8d9
VZ
120 wxWindow * const parent = GetParentForModalDialog();
121 if ( parent && parent != this )
f6bcfd97 122 {
31fdb8d9
VZ
123 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
124 GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
125 }
126 }
127
eebe4016 128 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
129
130 Show( true );
2b854a32 131
91af0895 132 m_modalShowing = true;
2b854a32 133
64c11164 134 wxOpenModalDialogsCount++;
304e5625 135
f36630af
VZ
136 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
137 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab 138
bfafa628
VZ
139 // Run modal dialog event loop.
140 {
141 wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
142 m_modalLoop->Run();
143 }
924b84ab 144
f36630af 145 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 146
64c11164 147 wxOpenModalDialogsCount--;
304e5625 148
fb1585ae 149 return GetReturnCode();
c33c4050 150}
c801d85f
KB
151
152void wxDialog::EndModal( int retCode )
153{
fb1585ae 154 SetReturnCode( retCode );
2b854a32 155
fb1585ae
RR
156 if (!IsModal())
157 {
dc409d37 158 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
fb1585ae
RR
159 return;
160 }
2b854a32 161
91af0895 162 m_modalShowing = false;
2b854a32 163
bfafa628
VZ
164 // Ensure Exit() is only called once. The dialog's event loop may be terminated
165 // externally due to an uncaught exception.
166 if (m_modalLoop && m_modalLoop->IsRunning())
167 m_modalLoop->Exit();
2b854a32 168
91af0895 169 Show( false );
c33c4050 170}