]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dialog.cpp
Only send keypress events to focus widget, not its parents
[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/app.h"
17 #include "wx/frame.h"
18 #include "wx/cursor.h"
19#endif // WX_PRECOMP
20
21#include "wx/evtloop.h"
22
23#include <gdk/gdk.h>
24#include <gtk/gtk.h>
25#include <gdk/gdkkeysyms.h>
26
27#include "wx/gtk/win_gtk.h"
28
29//-----------------------------------------------------------------------------
30// global data
31//-----------------------------------------------------------------------------
32
33// Don't allow window closing if there are open dialogs
34int g_openDialogs;
35
36//-----------------------------------------------------------------------------
37// wxDialog
38//-----------------------------------------------------------------------------
39
40IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
41
42void wxDialog::Init()
43{
44 m_returnCode = 0;
45 m_sizeSet = false;
46 m_modalShowing = false;
47 m_themeEnabled = true;
48}
49
50wxDialog::wxDialog( wxWindow *parent,
51 wxWindowID id, const wxString &title,
52 const wxPoint &pos, const wxSize &size,
53 long style, const wxString &name )
54{
55 Init();
56
57 (void)Create( parent, id, title, pos, size, style, name );
58}
59
60bool wxDialog::Create( wxWindow *parent,
61 wxWindowID id, const wxString &title,
62 const wxPoint &pos, const wxSize &size,
63 long style, const wxString &name )
64{
65 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
66
67 // all dialogs should have tab traversal enabled
68 style |= wxTAB_TRAVERSAL;
69
70 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
71}
72
73bool wxDialog::Show( bool show )
74{
75 if (!show && IsModal())
76 {
77 EndModal( wxID_CANCEL );
78 }
79
80 if (show && !m_sizeSet)
81 {
82 /* by calling GtkOnSize here, we don't have to call
83 either after showing the frame, which would entail
84 much ugly flicker nor from within the size_allocate
85 handler, because GTK 1.1.X forbids that. */
86
87 GtkOnSize();
88 }
89
90 bool ret = wxWindow::Show( show );
91
92 if (show) InitDialog();
93
94 return ret;
95}
96
97bool wxDialog::IsModal() const
98{
99 return m_modalShowing;
100}
101
102void wxDialog::SetModal( bool WXUNUSED(flag) )
103{
104 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
105}
106
107int wxDialog::ShowModal()
108{
109 if (IsModal())
110 {
111 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
112 return GetReturnCode();
113 }
114
115 // release the mouse if it's currently captured as the window having it
116 // will be disabled when this dialog is shown -- but will still keep the
117 // capture making it impossible to do anything in the modal dialog itself
118 wxWindow * const win = wxWindow::GetCapture();
119 if ( win )
120 win->GTKReleaseMouseAndNotify();
121
122 // use the apps top level window as parent if none given unless explicitly
123 // forbidden
124 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
125 {
126 wxWindow * const parent = GetParentForModalDialog();
127 if ( parent && parent != this )
128 {
129 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
130 GTK_WINDOW(parent->m_widget) );
131 }
132 }
133
134 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
135
136 Show( true );
137
138 m_modalShowing = true;
139
140 g_openDialogs++;
141
142 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
143 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
144
145 wxGUIEventLoop().Run();
146
147 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
148
149 g_openDialogs--;
150
151 return GetReturnCode();
152}
153
154void wxDialog::EndModal( int retCode )
155{
156 SetReturnCode( retCode );
157
158 if (!IsModal())
159 {
160 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
161 return;
162 }
163
164 m_modalShowing = false;
165
166 gtk_main_quit();
167
168 Show( false );
169}