]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dialog.cpp
Corrected some wxMac images
[wxWidgets.git] / src / gtk / dialog.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/dialog.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#include "wx/dialog.h"
14
15#ifndef WX_PRECOMP
16 #include "wx/cursor.h"
17#endif // WX_PRECOMP
18
19#include "wx/evtloop.h"
20
21#include "wx/ptr_scpd.h"
22
23#include <gtk/gtk.h>
24
25// this is defined in src/gtk/toplevel.cpp
26extern int wxOpenModalDialogsCount;
27
28wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop);
29
30
31//-----------------------------------------------------------------------------
32// wxDialog
33//-----------------------------------------------------------------------------
34
35IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
36
37void wxDialog::Init()
38{
39 m_modalLoop = NULL;
40 m_returnCode = 0;
41 m_modalShowing = false;
42 m_themeEnabled = true;
43}
44
45wxDialog::wxDialog( wxWindow *parent,
46 wxWindowID id, const wxString &title,
47 const wxPoint &pos, const wxSize &size,
48 long style, const wxString &name )
49{
50 Init();
51
52 (void)Create( parent, id, title, pos, size, style, name );
53}
54
55bool wxDialog::Create( wxWindow *parent,
56 wxWindowID id, const wxString &title,
57 const wxPoint &pos, const wxSize &size,
58 long style, const wxString &name )
59{
60 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
61
62 // all dialogs should have tab traversal enabled
63 style |= wxTAB_TRAVERSAL;
64
65 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
66}
67
68bool wxDialog::Show( bool show )
69{
70 if (!show && IsModal())
71 {
72 EndModal( wxID_CANCEL );
73 }
74
75 if (show && CanDoLayoutAdaptation())
76 DoLayoutAdaptation();
77
78 bool ret = wxDialogBase::Show(show);
79
80 if (show)
81 InitDialog();
82
83 return ret;
84}
85
86wxDialog::~wxDialog()
87{
88 m_isBeingDeleted = true;
89
90 // if the dialog is modal, this will end its event loop
91 if ( IsModal() )
92 EndModal(wxID_CANCEL);
93}
94
95bool wxDialog::IsModal() const
96{
97 return m_modalShowing;
98}
99
100void wxDialog::SetModal( bool WXUNUSED(flag) )
101{
102 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
103}
104
105int wxDialog::ShowModal()
106{
107 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
108
109 // release the mouse if it's currently captured as the window having it
110 // will be disabled when this dialog is shown -- but will still keep the
111 // capture making it impossible to do anything in the modal dialog itself
112 wxWindow * const win = wxWindow::GetCapture();
113 if ( win )
114 win->GTKReleaseMouseAndNotify();
115
116 // use the apps top level window as parent if none given unless explicitly
117 // forbidden
118 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
119 {
120 wxWindow * const parent = GetParentForModalDialog();
121 if ( parent && parent != this )
122 {
123 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
124 GTK_WINDOW(parent->m_widget) );
125 }
126 }
127
128 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
129
130 Show( true );
131
132 m_modalShowing = true;
133
134 wxOpenModalDialogsCount++;
135
136 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
137 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
138
139 // Run modal dialog event loop.
140 {
141 wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
142 m_modalLoop->Run();
143 }
144
145 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
146
147 wxOpenModalDialogsCount--;
148
149 return GetReturnCode();
150}
151
152void wxDialog::EndModal( int retCode )
153{
154 SetReturnCode( retCode );
155
156 if (!IsModal())
157 {
158 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
159 return;
160 }
161
162 m_modalShowing = false;
163
164 // Ensure Exit() is only called once. The dialog's event loop may be terminated
165 // externally due to an uncaught exception.
166 if (m_modalLoop && m_modalLoop->IsRunning())
167 m_modalLoop->Exit();
168
169 Show( false );
170}