]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dialog.cpp
Invoke default action if dclick event after <ENTER> not handled in wxListBox, added...
[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 <gtk/gtk.h>
22
23// this is defined in src/gtk/toplevel.cpp
24extern int wxOpenModalDialogsCount;
25
26//-----------------------------------------------------------------------------
27// wxDialog
28//-----------------------------------------------------------------------------
29
30IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
31
32void wxDialog::Init()
33{
34 m_returnCode = 0;
35 m_modalShowing = false;
36 m_themeEnabled = true;
37}
38
39wxDialog::wxDialog( wxWindow *parent,
40 wxWindowID id, const wxString &title,
41 const wxPoint &pos, const wxSize &size,
42 long style, const wxString &name )
43{
44 Init();
45
46 (void)Create( parent, id, title, pos, size, style, name );
47}
48
49bool wxDialog::Create( wxWindow *parent,
50 wxWindowID id, const wxString &title,
51 const wxPoint &pos, const wxSize &size,
52 long style, const wxString &name )
53{
54 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
55
56 // all dialogs should have tab traversal enabled
57 style |= wxTAB_TRAVERSAL;
58
59 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
60}
61
62bool wxDialog::Show( bool show )
63{
64 if (!show && IsModal())
65 {
66 EndModal( wxID_CANCEL );
67 }
68
69 if (show && CanDoLayoutAdaptation())
70 DoLayoutAdaptation();
71
72 bool ret = wxWindow::Show( show );
73
74 if (show) InitDialog();
75
76 return ret;
77}
78
79bool wxDialog::IsModal() const
80{
81 return m_modalShowing;
82}
83
84void wxDialog::SetModal( bool WXUNUSED(flag) )
85{
86 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
87}
88
89int wxDialog::ShowModal()
90{
91 if (IsModal())
92 {
93 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
94 return GetReturnCode();
95 }
96
97 // release the mouse if it's currently captured as the window having it
98 // will be disabled when this dialog is shown -- but will still keep the
99 // capture making it impossible to do anything in the modal dialog itself
100 wxWindow * const win = wxWindow::GetCapture();
101 if ( win )
102 win->GTKReleaseMouseAndNotify();
103
104 // use the apps top level window as parent if none given unless explicitly
105 // forbidden
106 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
107 {
108 wxWindow * const parent = GetParentForModalDialog();
109 if ( parent && parent != this )
110 {
111 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
112 GTK_WINDOW(parent->m_widget) );
113 }
114 }
115
116 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
117
118 Show( true );
119
120 m_modalShowing = true;
121
122 wxOpenModalDialogsCount++;
123
124 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
125 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
126
127 wxGUIEventLoop().Run();
128
129 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
130
131 wxOpenModalDialogsCount--;
132
133 return GetReturnCode();
134}
135
136void wxDialog::EndModal( int retCode )
137{
138 SetReturnCode( retCode );
139
140 if (!IsModal())
141 {
142 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
143 return;
144 }
145
146 m_modalShowing = false;
147
148 gtk_main_quit();
149
150 Show( false );
151}