]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
Invoke default action if dclick event after <ENTER> not handled in wxListBox, added...
[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
739730ca 72 bool ret = wxWindow::Show( show );
e146b8c8 73
fb1585ae 74 if (show) InitDialog();
2b854a32 75
739730ca 76 return ret;
c33c4050
RR
77}
78
43a18898 79bool wxDialog::IsModal() const
e1e955e1 80{
fb1585ae 81 return m_modalShowing;
e1e955e1
RR
82}
83
84void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 85{
223d09f6 86 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 87}
c801d85f 88
43a18898 89int wxDialog::ShowModal()
c801d85f 90{
fb1585ae
RR
91 if (IsModal())
92 {
223d09f6 93 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
94 return GetReturnCode();
95 }
e146b8c8 96
7738af59
VZ
97 // release the mouse if it's currently captured as the window having it
98 // will be disabled when this dialog is shown -- but will still keep the
99 // capture making it impossible to do anything in the modal dialog itself
100 wxWindow * const win = wxWindow::GetCapture();
101 if ( win )
102 win->GTKReleaseMouseAndNotify();
103
b3daa5a3
VZ
104 // use the apps top level window as parent if none given unless explicitly
105 // forbidden
106 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
f6bcfd97 107 {
31fdb8d9
VZ
108 wxWindow * const parent = GetParentForModalDialog();
109 if ( parent && parent != this )
f6bcfd97 110 {
31fdb8d9
VZ
111 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
112 GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
113 }
114 }
115
eebe4016 116 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
117
118 Show( true );
2b854a32 119
91af0895 120 m_modalShowing = true;
2b854a32 121
64c11164 122 wxOpenModalDialogsCount++;
304e5625 123
f36630af
VZ
124 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
125 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab 126
b46b1d59 127 wxGUIEventLoop().Run();
924b84ab 128
f36630af 129 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 130
64c11164 131 wxOpenModalDialogsCount--;
304e5625 132
fb1585ae 133 return GetReturnCode();
c33c4050 134}
c801d85f
KB
135
136void wxDialog::EndModal( int retCode )
137{
fb1585ae 138 SetReturnCode( retCode );
2b854a32 139
fb1585ae
RR
140 if (!IsModal())
141 {
223d09f6 142 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
143 return;
144 }
2b854a32 145
91af0895 146 m_modalShowing = false;
2b854a32 147
fb1585ae 148 gtk_main_quit();
2b854a32 149
91af0895 150 Show( false );
c33c4050 151}