]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
Improve wxMenu docs
[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
071a2d78 21#include <gtk/gtk.h>
5e014a0c 22
64c11164
VZ
23// this is defined in src/gtk/toplevel.cpp
24extern int wxOpenModalDialogsCount;
acfd422a 25
c801d85f
KB
26//-----------------------------------------------------------------------------
27// wxDialog
28//-----------------------------------------------------------------------------
29
7d9f12f3 30IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
c801d85f 31
68995f26 32void wxDialog::Init()
c801d85f 33{
f03fc89f 34 m_returnCode = 0;
91af0895
WS
35 m_modalShowing = false;
36 m_themeEnabled = true;
c33c4050 37}
c801d85f 38
2b854a32 39wxDialog::wxDialog( wxWindow *parent,
fb1585ae 40 wxWindowID id, const wxString &title,
2b854a32 41 const wxPoint &pos, const wxSize &size,
fb1585ae 42 long style, const wxString &name )
c801d85f 43{
68995f26
VZ
44 Init();
45
82c9f85c 46 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 47}
c801d85f
KB
48
49bool wxDialog::Create( wxWindow *parent,
fb1585ae 50 wxWindowID id, const wxString &title,
2b854a32 51 const wxPoint &pos, const wxSize &size,
fb1585ae 52 long style, const wxString &name )
c801d85f 53{
21f4383a 54 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 55
82c9f85c
VZ
56 // all dialogs should have tab traversal enabled
57 style |= wxTAB_TRAVERSAL;
58
7d9f12f3 59 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 60}
c801d85f 61
debe6624 62bool wxDialog::Show( bool show )
c801d85f 63{
fb1585ae
RR
64 if (!show && IsModal())
65 {
de8113d9 66 EndModal( wxID_CANCEL );
fb1585ae 67 }
c801d85f 68
3aa8e4ea
JS
69 if (show && CanDoLayoutAdaptation())
70 DoLayoutAdaptation();
71
8fb09a08 72 bool ret = wxDialogBase::Show(show);
e146b8c8 73
a9efc294
VS
74 if (show)
75 InitDialog();
2b854a32 76
739730ca 77 return ret;
c33c4050
RR
78}
79
a9efc294
VS
80wxDialog::~wxDialog()
81{
82 m_isBeingDeleted = true;
83
84 // if the dialog is modal, this will end its event loop
0af07cc2
VS
85 if ( IsModal() )
86 EndModal(wxID_CANCEL);
a9efc294
VS
87}
88
43a18898 89bool wxDialog::IsModal() const
e1e955e1 90{
fb1585ae 91 return m_modalShowing;
e1e955e1
RR
92}
93
94void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 95{
223d09f6 96 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 97}
c801d85f 98
43a18898 99int wxDialog::ShowModal()
c801d85f 100{
fb1585ae
RR
101 if (IsModal())
102 {
223d09f6 103 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
104 return GetReturnCode();
105 }
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
b3daa5a3
VZ
114 // use the apps top level window as parent if none given unless explicitly
115 // forbidden
116 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
f6bcfd97 117 {
31fdb8d9
VZ
118 wxWindow * const parent = GetParentForModalDialog();
119 if ( parent && parent != this )
f6bcfd97 120 {
31fdb8d9
VZ
121 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
122 GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
123 }
124 }
125
eebe4016 126 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
127
128 Show( true );
2b854a32 129
91af0895 130 m_modalShowing = true;
2b854a32 131
64c11164 132 wxOpenModalDialogsCount++;
304e5625 133
f36630af
VZ
134 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
135 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab 136
b46b1d59 137 wxGUIEventLoop().Run();
924b84ab 138
f36630af 139 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 140
64c11164 141 wxOpenModalDialogsCount--;
304e5625 142
fb1585ae 143 return GetReturnCode();
c33c4050 144}
c801d85f
KB
145
146void wxDialog::EndModal( int retCode )
147{
fb1585ae 148 SetReturnCode( retCode );
2b854a32 149
fb1585ae
RR
150 if (!IsModal())
151 {
dc409d37 152 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
fb1585ae
RR
153 return;
154 }
2b854a32 155
91af0895 156 m_modalShowing = false;
2b854a32 157
fb1585ae 158 gtk_main_quit();
2b854a32 159
91af0895 160 Show( false );
c33c4050 161}