]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/dialog.cpp
More comments about non-native GTH widgets.
[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
16 #include "wx/app.h"
76b49cf4 17 #include "wx/frame.h"
c8326d64 18 #include "wx/cursor.h"
670f9935
WS
19#endif // WX_PRECOMP
20
924b84ab 21#include "wx/evtloop.h"
83624f79 22
071a2d78
RR
23#include <gdk/gdk.h>
24#include <gtk/gtk.h>
25#include <gdk/gdkkeysyms.h>
26
c801d85f 27#include "wx/gtk/win_gtk.h"
5e014a0c 28
acfd422a 29//-----------------------------------------------------------------------------
91af0895 30// global data
acfd422a
RR
31//-----------------------------------------------------------------------------
32
2d68e1b4 33extern int g_openDialogs;
acfd422a 34
c801d85f
KB
35//-----------------------------------------------------------------------------
36// wxDialog
37//-----------------------------------------------------------------------------
38
7d9f12f3 39IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
c801d85f 40
68995f26 41void wxDialog::Init()
c801d85f 42{
f03fc89f 43 m_returnCode = 0;
91af0895
WS
44 m_sizeSet = false;
45 m_modalShowing = false;
46 m_themeEnabled = true;
c33c4050 47}
c801d85f 48
2b854a32 49wxDialog::wxDialog( 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{
68995f26
VZ
54 Init();
55
82c9f85c 56 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 57}
c801d85f
KB
58
59bool wxDialog::Create( wxWindow *parent,
fb1585ae 60 wxWindowID id, const wxString &title,
2b854a32 61 const wxPoint &pos, const wxSize &size,
fb1585ae 62 long style, const wxString &name )
c801d85f 63{
21f4383a 64 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 65
82c9f85c
VZ
66 // all dialogs should have tab traversal enabled
67 style |= wxTAB_TRAVERSAL;
68
7d9f12f3 69 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 70}
c801d85f 71
debe6624 72bool wxDialog::Show( bool show )
c801d85f 73{
fb1585ae
RR
74 if (!show && IsModal())
75 {
de8113d9 76 EndModal( wxID_CANCEL );
fb1585ae 77 }
c801d85f 78
de8113d9
RR
79 if (show && !m_sizeSet)
80 {
81 /* by calling GtkOnSize here, we don't have to call
82 either after showing the frame, which would entail
83 much ugly flicker nor from within the size_allocate
84 handler, because GTK 1.1.X forbids that. */
85
86 GtkOnSize( m_x, m_y, m_width, m_height );
87 }
2b854a32 88
739730ca 89 bool ret = wxWindow::Show( show );
e146b8c8 90
fb1585ae 91 if (show) InitDialog();
2b854a32 92
739730ca 93 return ret;
c33c4050
RR
94}
95
43a18898 96bool wxDialog::IsModal() const
e1e955e1 97{
fb1585ae 98 return m_modalShowing;
e1e955e1
RR
99}
100
101void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 102{
223d09f6 103 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 104}
c801d85f 105
43a18898 106int wxDialog::ShowModal()
c801d85f 107{
fb1585ae
RR
108 if (IsModal())
109 {
223d09f6 110 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
111 return GetReturnCode();
112 }
e146b8c8 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
BP
117 {
118 wxWindow *parent = wxTheApp->GetTopWindow();
39cc7a0b
VZ
119 if ( parent &&
120 parent != this &&
121 parent->IsBeingDeleted() &&
122 !(parent->GetExtraStyle() & wxWS_EX_TRANSIENT) )
f6bcfd97
BP
123 {
124 m_parent = parent;
125 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) );
126 }
127 }
128
eebe4016 129 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
130
131 Show( true );
2b854a32 132
91af0895 133 m_modalShowing = true;
2b854a32 134
304e5625
RR
135 g_openDialogs++;
136
f36630af
VZ
137 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
138 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
924b84ab
VS
139
140 wxEventLoop().Run();
141
f36630af 142 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
2b854a32 143
304e5625
RR
144 g_openDialogs--;
145
fb1585ae 146 return GetReturnCode();
c33c4050 147}
c801d85f
KB
148
149void wxDialog::EndModal( int retCode )
150{
fb1585ae 151 SetReturnCode( retCode );
2b854a32 152
fb1585ae
RR
153 if (!IsModal())
154 {
223d09f6 155 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
156 return;
157 }
2b854a32 158
91af0895 159 m_modalShowing = false;
2b854a32 160
fb1585ae 161 gtk_main_quit();
2b854a32 162
91af0895 163 Show( false );
c33c4050 164}