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