]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
setting correct 'default' for m_filterIndex, closes #11541
[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
664e1314 21#include "wx/scopedptr.h"
bfafa628 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
5c69ef61 28wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop)
bfafa628
VZ
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{
a9efc294 88 // if the dialog is modal, this will end its event loop
0af07cc2
VS
89 if ( IsModal() )
90 EndModal(wxID_CANCEL);
a9efc294
VS
91}
92
43a18898 93bool wxDialog::IsModal() const
e1e955e1 94{
fb1585ae 95 return m_modalShowing;
e1e955e1
RR
96}
97
98void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 99{
223d09f6 100 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 101}
c801d85f 102
43a18898 103int wxDialog::ShowModal()
c801d85f 104{
4e2a3778 105 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
e146b8c8 106
7738af59
VZ
107 // release the mouse if it's currently captured as the window having it
108 // will be disabled when this dialog is shown -- but will still keep the
109 // capture making it impossible to do anything in the modal dialog itself
110 wxWindow * const win = wxWindow::GetCapture();
111 if ( win )
112 win->GTKReleaseMouseAndNotify();
113
4f73f25c 114 wxWindow * const parent = GetParentForModalDialog(GetParent());
8bda0ec6 115 if ( parent )
f6bcfd97 116 {
8bda0ec6
VZ
117 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
118 GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
119 }
120
eebe4016 121 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
122
123 Show( true );
2b854a32 124
91af0895 125 m_modalShowing = true;
2b854a32 126
64c11164 127 wxOpenModalDialogsCount++;
304e5625 128
f36630af
VZ
129 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
130 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab 131
bfafa628
VZ
132 // Run modal dialog event loop.
133 {
134 wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
135 m_modalLoop->Run();
136 }
924b84ab 137
f36630af 138 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 139
64c11164 140 wxOpenModalDialogsCount--;
304e5625 141
fb1585ae 142 return GetReturnCode();
c33c4050 143}
c801d85f
KB
144
145void wxDialog::EndModal( int retCode )
146{
fb1585ae 147 SetReturnCode( retCode );
2b854a32 148
fb1585ae
RR
149 if (!IsModal())
150 {
dc409d37 151 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
fb1585ae
RR
152 return;
153 }
2b854a32 154
91af0895 155 m_modalShowing = false;
2b854a32 156
bfafa628
VZ
157 // Ensure Exit() is only called once. The dialog's event loop may be terminated
158 // externally due to an uncaught exception.
159 if (m_modalLoop && m_modalLoop->IsRunning())
160 m_modalLoop->Exit();
2b854a32 161
91af0895 162 Show( false );
c33c4050 163}