]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
Increase the number of index items shown by default in wxHTML.
[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
68995f26 35void wxDialog::Init()
c801d85f 36{
bfafa628 37 m_modalLoop = NULL;
f03fc89f 38 m_returnCode = 0;
91af0895
WS
39 m_modalShowing = false;
40 m_themeEnabled = true;
c33c4050 41}
c801d85f 42
2b854a32 43wxDialog::wxDialog( wxWindow *parent,
fb1585ae 44 wxWindowID id, const wxString &title,
2b854a32 45 const wxPoint &pos, const wxSize &size,
fb1585ae 46 long style, const wxString &name )
c801d85f 47{
68995f26
VZ
48 Init();
49
82c9f85c 50 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 51}
c801d85f
KB
52
53bool wxDialog::Create( wxWindow *parent,
fb1585ae 54 wxWindowID id, const wxString &title,
2b854a32 55 const wxPoint &pos, const wxSize &size,
fb1585ae 56 long style, const wxString &name )
c801d85f 57{
21f4383a 58 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 59
82c9f85c
VZ
60 // all dialogs should have tab traversal enabled
61 style |= wxTAB_TRAVERSAL;
62
7d9f12f3 63 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 64}
c801d85f 65
debe6624 66bool wxDialog::Show( bool show )
c801d85f 67{
fb1585ae
RR
68 if (!show && IsModal())
69 {
de8113d9 70 EndModal( wxID_CANCEL );
fb1585ae 71 }
c801d85f 72
3aa8e4ea
JS
73 if (show && CanDoLayoutAdaptation())
74 DoLayoutAdaptation();
75
8fb09a08 76 bool ret = wxDialogBase::Show(show);
e146b8c8 77
a9efc294
VS
78 if (show)
79 InitDialog();
2b854a32 80
739730ca 81 return ret;
c33c4050
RR
82}
83
a9efc294
VS
84wxDialog::~wxDialog()
85{
a9efc294 86 // if the dialog is modal, this will end its event loop
0af07cc2
VS
87 if ( IsModal() )
88 EndModal(wxID_CANCEL);
a9efc294
VS
89}
90
43a18898 91bool wxDialog::IsModal() const
e1e955e1 92{
fb1585ae 93 return m_modalShowing;
e1e955e1
RR
94}
95
96void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 97{
223d09f6 98 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 99}
c801d85f 100
43a18898 101int wxDialog::ShowModal()
c801d85f 102{
4e2a3778 103 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
e146b8c8 104
7738af59
VZ
105 // release the mouse if it's currently captured as the window having it
106 // will be disabled when this dialog is shown -- but will still keep the
107 // capture making it impossible to do anything in the modal dialog itself
108 wxWindow * const win = wxWindow::GetCapture();
109 if ( win )
110 win->GTKReleaseMouseAndNotify();
111
cdc48273 112 wxWindow * const parent = GetParentForModalDialog();
8bda0ec6 113 if ( parent )
f6bcfd97 114 {
8bda0ec6
VZ
115 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
116 GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
117 }
118
eebe4016 119 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
120
121 Show( true );
2b854a32 122
91af0895 123 m_modalShowing = true;
2b854a32 124
64c11164 125 wxOpenModalDialogsCount++;
304e5625 126
f36630af
VZ
127 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
128 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab 129
bfafa628
VZ
130 // Run modal dialog event loop.
131 {
132 wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
133 m_modalLoop->Run();
134 }
924b84ab 135
f36630af 136 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 137
64c11164 138 wxOpenModalDialogsCount--;
304e5625 139
fb1585ae 140 return GetReturnCode();
c33c4050 141}
c801d85f
KB
142
143void wxDialog::EndModal( int retCode )
144{
fb1585ae 145 SetReturnCode( retCode );
2b854a32 146
fb1585ae
RR
147 if (!IsModal())
148 {
dc409d37 149 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
fb1585ae
RR
150 return;
151 }
2b854a32 152
91af0895 153 m_modalShowing = false;
2b854a32 154
bfafa628
VZ
155 // Ensure Exit() is only called once. The dialog's event loop may be terminated
156 // externally due to an uncaught exception.
157 if (m_modalLoop && m_modalLoop->IsRunning())
158 m_modalLoop->Exit();
2b854a32 159
91af0895 160 Show( false );
c33c4050 161}