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