]>
Commit | Line | Data |
---|---|---|
9f41d601 | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/gtk/popupwin.cpp |
9f41d601 RR |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
9f41d601 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
f3ecfad1 VS |
12 | |
13 | #if wxUSE_POPUPWIN | |
14 | ||
9f41d601 | 15 | #include "wx/popupwin.h" |
670f9935 WS |
16 | |
17 | #ifndef WX_PRECOMP | |
670f9935 WS |
18 | #endif // WX_PRECOMP |
19 | ||
9f41d601 | 20 | #include <gtk/gtk.h> |
9f41d601 | 21 | |
bbd92d1d | 22 | #include "wx/gtk/private/win_gtk.h" |
9f41d601 | 23 | |
f7204798 RR |
24 | //----------------------------------------------------------------------------- |
25 | // "button_press" | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
865bb325 | 28 | extern "C" { |
f7204798 RR |
29 | static gint gtk_popup_button_press (GtkWidget *widget, GdkEvent *gdk_event, wxPopupWindow* win ) |
30 | { | |
31 | GtkWidget *child = gtk_get_event_widget (gdk_event); | |
32 | ||
33c0d0ed RR |
33 | /* Ignore events sent out before we connected to the signal */ |
34 | if (win->m_time >= ((GdkEventButton*)gdk_event)->time) | |
35 | return FALSE; | |
36 | ||
37 | /* We don't ask for button press events on the grab widget, so | |
38 | * if an event is reported directly to the grab widget, it must | |
39 | * be on a window outside the application (and thus we remove | |
40 | * the popup window). Otherwise, we check if the widget is a child | |
41 | * of the grab widget, and only remove the popup window if it | |
42 | * is not. */ | |
f7204798 RR |
43 | if (child != widget) |
44 | { | |
45 | while (child) | |
88d19775 MR |
46 | { |
47 | if (child == widget) | |
48 | return FALSE; | |
385e8575 | 49 | child = gtk_widget_get_parent(child); |
f7204798 RR |
50 | } |
51 | } | |
52 | ||
53 | wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); | |
54 | event.SetEventObject( win ); | |
55 | ||
937013e0 | 56 | (void)win->HandleWindowEvent( event ); |
f7204798 RR |
57 | |
58 | return TRUE; | |
59 | } | |
865bb325 | 60 | } |
f7204798 | 61 | |
9f41d601 RR |
62 | //----------------------------------------------------------------------------- |
63 | // "delete_event" | |
64 | //----------------------------------------------------------------------------- | |
65 | ||
865bb325 | 66 | extern "C" { |
9f41d601 RR |
67 | bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxPopupWindow *win ) |
68 | { | |
9f41d601 RR |
69 | if (win->IsEnabled()) |
70 | win->Close(); | |
71 | ||
72 | return TRUE; | |
73 | } | |
865bb325 | 74 | } |
9f41d601 | 75 | |
9f41d601 RR |
76 | //----------------------------------------------------------------------------- |
77 | // wxPopupWindow | |
78 | //----------------------------------------------------------------------------- | |
79 | ||
8f0db49c | 80 | #ifdef __WXUNIVERSAL__ |
cca410b3 | 81 | BEGIN_EVENT_TABLE(wxPopupWindow,wxPopupWindowBase) |
6522713c | 82 | EVT_SIZE(wxPopupWindow::OnSize) |
9f41d601 | 83 | END_EVENT_TABLE() |
cca410b3 | 84 | #endif |
9f41d601 | 85 | |
ad9fb033 RR |
86 | wxPopupWindow::~wxPopupWindow() |
87 | { | |
ad9fb033 RR |
88 | } |
89 | ||
9f41d601 RR |
90 | bool wxPopupWindow::Create( wxWindow *parent, int style ) |
91 | { | |
9f41d601 | 92 | if (!PreCreation( parent, wxDefaultPosition, wxDefaultSize ) || |
2b5f62a0 | 93 | !CreateBase( parent, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("popup") )) |
9f41d601 RR |
94 | { |
95 | wxFAIL_MSG( wxT("wxPopupWindow creation failed") ); | |
670f9935 | 96 | return false; |
9f41d601 RR |
97 | } |
98 | ||
da19de36 RR |
99 | // Unlike windows, top level windows are created hidden by default. |
100 | m_isShown = false; | |
88d19775 | 101 | |
9f41d601 RR |
102 | // All dialogs should really have this style |
103 | m_windowStyle |= wxTAB_TRAVERSAL; | |
104 | ||
9f41d601 | 105 | m_widget = gtk_window_new( GTK_WINDOW_POPUP ); |
3591d10f | 106 | g_object_ref( m_widget ); |
9f41d601 | 107 | |
3591d10f | 108 | gtk_widget_set_name( m_widget, "wxPopupWindow" ); |
62d934aa RR |
109 | // wxPopupWindow is used for different windows as well |
110 | // gtk_window_set_type_hint( GTK_WINDOW(m_widget), GDK_WINDOW_TYPE_HINT_COMBO ); | |
9f41d601 | 111 | |
b561290c VZ |
112 | // Popup windows can be created without parent, so handle this correctly. |
113 | if (parent) | |
3591d10f | 114 | { |
b561290c VZ |
115 | GtkWidget *toplevel = gtk_widget_get_toplevel( parent->m_widget ); |
116 | if (GTK_IS_WINDOW (toplevel)) | |
117 | { | |
451673f7 | 118 | #if GTK_CHECK_VERSION(2,10,0) |
9dc44eff | 119 | #ifndef __WXGTK3__ |
b561290c | 120 | if (!gtk_check_version(2,10,0)) |
9dc44eff | 121 | #endif |
b561290c VZ |
122 | { |
123 | gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW (m_widget)); | |
124 | } | |
451673f7 | 125 | #endif |
b561290c VZ |
126 | gtk_window_set_transient_for (GTK_WINDOW (m_widget), GTK_WINDOW (toplevel)); |
127 | } | |
128 | gtk_window_set_screen (GTK_WINDOW (m_widget), gtk_widget_get_screen (GTK_WIDGET (parent->m_widget))); | |
3591d10f | 129 | } |
b561290c | 130 | |
3591d10f | 131 | gtk_window_set_resizable (GTK_WINDOW (m_widget), FALSE); |
9f41d601 | 132 | |
9fa72bd2 MR |
133 | g_signal_connect (m_widget, "delete_event", |
134 | G_CALLBACK (gtk_dialog_delete_callback), this); | |
9f41d601 | 135 | |
9dc44eff | 136 | m_wxwindow = wxPizza::New(); |
9f41d601 | 137 | gtk_widget_show( m_wxwindow ); |
9f41d601 RR |
138 | |
139 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); | |
140 | ||
141 | if (m_parent) m_parent->AddChild( this ); | |
142 | ||
143 | PostCreation(); | |
144 | ||
33c0d0ed RR |
145 | m_time = gtk_get_current_event_time(); |
146 | ||
9fa72bd2 MR |
147 | g_signal_connect (m_widget, "button_press_event", |
148 | G_CALLBACK (gtk_popup_button_press), this); | |
88d19775 | 149 | |
670f9935 | 150 | return true; |
9f41d601 RR |
151 | } |
152 | ||
153 | void wxPopupWindow::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) ) | |
154 | { | |
155 | wxFAIL_MSG( wxT("DoMoveWindow called for wxPopupWindow") ); | |
156 | } | |
157 | ||
158 | void wxPopupWindow::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
159 | { | |
160 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid dialog") ); | |
161 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid dialog") ); | |
162 | ||
9f41d601 RR |
163 | int old_x = m_x; |
164 | int old_y = m_y; | |
165 | ||
166 | int old_width = m_width; | |
167 | int old_height = m_height; | |
168 | ||
cca410b3 | 169 | if (x != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
9f41d601 | 170 | m_x = x; |
cca410b3 | 171 | if (y != -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
9f41d601 | 172 | m_y = y; |
cca410b3 | 173 | if (width != -1) |
9f41d601 | 174 | m_width = width; |
cca410b3 | 175 | if (height != -1) |
9f41d601 | 176 | m_height = height; |
9f41d601 | 177 | |
82008f15 | 178 | ConstrainSize(); |
9f41d601 RR |
179 | |
180 | if ((m_x != -1) || (m_y != -1)) | |
181 | { | |
182 | if ((m_x != old_x) || (m_y != old_y)) | |
183 | { | |
cd6645a2 | 184 | gtk_window_move( GTK_WINDOW(m_widget), m_x, m_y ); |
9f41d601 RR |
185 | } |
186 | } | |
187 | ||
188 | if ((m_width != old_width) || (m_height != old_height)) | |
189 | { | |
cca410b3 | 190 | // gtk_window_resize does not work for GTK_WINDOW_POPUP |
370dc79c | 191 | gtk_widget_set_size_request( m_widget, m_width, m_height ); |
cca410b3 PC |
192 | wxSizeEvent event(GetSize(), GetId()); |
193 | event.SetEventObject(this); | |
937013e0 | 194 | HandleWindowEvent(event); |
9f41d601 | 195 | } |
9f41d601 RR |
196 | } |
197 | ||
3591d10f RR |
198 | void wxPopupWindow::SetFocus() |
199 | { | |
200 | // set the focus to the first child who wants it | |
201 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); | |
202 | while ( node ) | |
203 | { | |
204 | wxWindow *child = node->GetData(); | |
205 | node = node->GetNext(); | |
206 | ||
207 | if ( child->CanAcceptFocus() && !child->IsTopLevel() ) | |
208 | { | |
209 | child->SetFocus(); | |
210 | return; | |
211 | } | |
212 | } | |
03647350 | 213 | |
3591d10f RR |
214 | wxPopupWindowBase::SetFocus(); |
215 | } | |
216 | ||
9f41d601 RR |
217 | bool wxPopupWindow::Show( bool show ) |
218 | { | |
cca410b3 | 219 | if (show && !IsShown()) |
9f41d601 | 220 | { |
cca410b3 PC |
221 | wxSizeEvent event(GetSize(), GetId()); |
222 | event.SetEventObject(this); | |
937013e0 | 223 | HandleWindowEvent(event); |
9f41d601 | 224 | } |
88d19775 | 225 | |
9f41d601 | 226 | bool ret = wxWindow::Show( show ); |
88d19775 | 227 | |
9f41d601 RR |
228 | return ret; |
229 | } | |
230 | ||
f3ecfad1 | 231 | #endif // wxUSE_POPUPWIN |