]>
Commit | Line | Data |
---|---|---|
7d9f12f3 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: toplevel.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
7d9f12f3 VS |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | // ============================================================================ | |
11 | // declarations | |
12 | // ============================================================================ | |
13 | ||
14 | // ---------------------------------------------------------------------------- | |
15 | // headers | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
14f355c2 | 18 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
7d9f12f3 VS |
19 | #pragma implementation "toplevel.h" |
20 | #endif | |
21 | ||
14f355c2 VS |
22 | // For compilers that support precompilation, includes "wx.h". |
23 | #include "wx/wxprec.h" | |
24 | ||
7d9f12f3 VS |
25 | #ifdef __VMS |
26 | #define XIconifyWindow XICONIFYWINDOW | |
27 | #endif | |
28 | ||
29 | #include "wx/defs.h" | |
30 | ||
e1bf3ad3 | 31 | #include "wx/toplevel.h" |
2b5f62a0 | 32 | #include "wx/log.h" |
7d9f12f3 VS |
33 | #include "wx/dialog.h" |
34 | #include "wx/control.h" | |
35 | #include "wx/app.h" | |
36 | #include "wx/dcclient.h" | |
fab591c5 | 37 | #include "wx/gtk/private.h" |
8166ab43 | 38 | #include "wx/timer.h" |
ca06ee0d | 39 | #include "wx/settings.h" |
924b84ab | 40 | #include "wx/evtloop.h" |
7d9f12f3 VS |
41 | |
42 | #include <glib.h> | |
43 | #include <gdk/gdk.h> | |
44 | #include <gtk/gtk.h> | |
45 | #include <gdk/gdkkeysyms.h> | |
46 | #include <gdk/gdkx.h> | |
47 | ||
48 | #include "wx/gtk/win_gtk.h" | |
49 | ||
f618020a MB |
50 | #include "wx/unix/utilsx11.h" |
51 | ||
8a9650ea RR |
52 | // XA_CARDINAL |
53 | #include <X11/Xatom.h> | |
54 | ||
7d9f12f3 VS |
55 | // ---------------------------------------------------------------------------- |
56 | // idle system | |
57 | // ---------------------------------------------------------------------------- | |
58 | ||
59 | extern void wxapp_install_idle_handler(); | |
60 | extern bool g_isIdle; | |
7d9f12f3 | 61 | |
7d9f12f3 VS |
62 | // ---------------------------------------------------------------------------- |
63 | // data | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
06fda9e8 | 66 | extern wxList wxPendingDelete; |
d7fa7eaa | 67 | |
06fda9e8 RR |
68 | extern int g_openDialogs; |
69 | extern wxWindowGTK *g_delayedFocus; | |
70 | ||
71 | // the frame that is currently active (i.e. its child has focus). It is | |
72 | // used to generate wxActivateEvents | |
73 | static wxTopLevelWindowGTK *g_activeFrame = (wxTopLevelWindowGTK*) NULL; | |
74 | static wxTopLevelWindowGTK *g_lastActiveFrame = (wxTopLevelWindowGTK*) NULL; | |
75 | ||
76 | // if we detect that the app has got/lost the focus, we set this variable to | |
77 | // either TRUE or FALSE and an activate event will be sent during the next | |
78 | // OnIdle() call and it is reset to -1: this value means that we shouldn't | |
79 | // send any activate events at all | |
0a164d4c | 80 | static int g_sendActivateEvent = -1; |
06fda9e8 | 81 | |
dca92ddf MR |
82 | //----------------------------------------------------------------------------- |
83 | // RequestUserAttention related functions | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | extern "C" { | |
87 | static void wxgtk_window_set_urgency_hint (GtkWindow *win, | |
88 | gboolean setting) | |
89 | { | |
90 | wxASSERT_MSG( GTK_WIDGET_REALIZED(win), wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") ); | |
91 | GdkWindow *window = GTK_WIDGET(win)->window; | |
92 | XWMHints *wm_hints; | |
93 | ||
94 | wm_hints = XGetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window)); | |
95 | ||
96 | if (!wm_hints) | |
97 | wm_hints = XAllocWMHints(); | |
98 | ||
99 | if (setting) | |
100 | wm_hints->flags |= XUrgencyHint; | |
101 | else | |
102 | wm_hints->flags &= ~XUrgencyHint; | |
103 | ||
104 | XSetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window), wm_hints); | |
105 | XFree(wm_hints); | |
106 | } | |
107 | ||
108 | static gint gtk_frame_urgency_timer_callback( GtkWidget *win ) | |
109 | { | |
6925aa36 | 110 | #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2,7,0) |
dca92ddf MR |
111 | if(!gtk_check_version(2,7,0)) |
112 | gtk_window_set_urgency_hint(GTK_WINDOW( win ), FALSE); | |
113 | else | |
114 | #endif | |
115 | wxgtk_window_set_urgency_hint(GTK_WINDOW( win ), FALSE); | |
116 | ||
117 | //BCI: argument from GtkWidget* to wxTopLevelWindowGTK* && win->m_urgency_hint = -2; | |
118 | gtk_object_set_data(GTK_OBJECT(win), "m_urgency_hint", GINT_TO_POINTER(-2)); | |
119 | return FALSE; | |
120 | } | |
121 | } | |
122 | ||
06fda9e8 RR |
123 | //----------------------------------------------------------------------------- |
124 | // "focus_in_event" | |
125 | //----------------------------------------------------------------------------- | |
126 | ||
865bb325 | 127 | extern "C" { |
06fda9e8 RR |
128 | static gint gtk_frame_focus_in_callback( GtkWidget *widget, |
129 | GdkEvent *WXUNUSED(event), | |
130 | wxTopLevelWindowGTK *win ) | |
131 | { | |
132 | if (g_isIdle) | |
133 | wxapp_install_idle_handler(); | |
0a164d4c | 134 | |
06fda9e8 RR |
135 | switch ( g_sendActivateEvent ) |
136 | { | |
137 | case -1: | |
138 | // we've got focus from outside, synthetize wxActivateEvent | |
139 | g_sendActivateEvent = 1; | |
140 | break; | |
141 | ||
142 | case 0: | |
143 | // another our window just lost focus, it was already ours before | |
144 | // - don't send any wxActivateEvent | |
145 | g_sendActivateEvent = -1; | |
146 | break; | |
147 | } | |
148 | ||
149 | g_activeFrame = win; | |
150 | g_lastActiveFrame = g_activeFrame; | |
0a164d4c | 151 | |
06fda9e8 | 152 | // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() ); |
0a164d4c | 153 | |
dca92ddf MR |
154 | // MR: wxRequestUserAttention related block |
155 | //BCI: switch(win->m_urgency_hint) | |
156 | switch( GPOINTER_TO_INT(gtk_object_get_data( GTK_OBJECT(widget), "m_urgency_hint") ) ) | |
157 | { | |
158 | default: | |
159 | //BCI: | |
160 | gtk_timeout_remove( GPOINTER_TO_INT(gtk_object_get_data( GTK_OBJECT(widget), "m_urgency_hint") ) ); | |
161 | // no break, fallthrough to remove hint too | |
162 | case -1: | |
6925aa36 | 163 | #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2,7,0) |
dca92ddf MR |
164 | if(!gtk_check_version(2,7,0)) |
165 | gtk_window_set_urgency_hint(GTK_WINDOW( widget ), FALSE); | |
166 | else | |
167 | #endif | |
168 | { | |
169 | wxgtk_window_set_urgency_hint(GTK_WINDOW( widget ), FALSE); | |
170 | } | |
171 | ||
172 | //BCI: win->m_urgency_hint = -2; | |
173 | gtk_object_set_data( GTK_OBJECT(widget), "m_urgency_hint", GINT_TO_POINTER(-2) ); | |
174 | break; | |
175 | ||
176 | case -2: break; | |
177 | } | |
178 | ||
06fda9e8 | 179 | wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame); |
0a164d4c | 180 | wxActivateEvent event(wxEVT_ACTIVATE, true, g_activeFrame->GetId()); |
06fda9e8 RR |
181 | event.SetEventObject(g_activeFrame); |
182 | g_activeFrame->GetEventHandler()->ProcessEvent(event); | |
183 | ||
576f7127 | 184 | return FALSE; |
06fda9e8 | 185 | } |
865bb325 | 186 | } |
06fda9e8 RR |
187 | |
188 | //----------------------------------------------------------------------------- | |
189 | // "focus_out_event" | |
190 | //----------------------------------------------------------------------------- | |
191 | ||
865bb325 | 192 | extern "C" { |
0a164d4c WS |
193 | static gint gtk_frame_focus_out_callback( GtkWidget *widget, |
194 | GdkEventFocus *WXUNUSED(gdk_event), | |
06fda9e8 RR |
195 | wxTopLevelWindowGTK *win ) |
196 | { | |
197 | if (g_isIdle) | |
198 | wxapp_install_idle_handler(); | |
199 | ||
200 | // if the focus goes out of our app alltogether, OnIdle() will send | |
201 | // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset | |
202 | // g_sendActivateEvent to -1 | |
203 | g_sendActivateEvent = 0; | |
0a164d4c | 204 | |
06fda9e8 | 205 | // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") ); |
0a164d4c | 206 | |
06fda9e8 | 207 | // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() ); |
06fda9e8 | 208 | |
cc0c05cd JS |
209 | if (g_activeFrame) |
210 | { | |
211 | wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame); | |
0a164d4c | 212 | wxActivateEvent event(wxEVT_ACTIVATE, false, g_activeFrame->GetId()); |
cc0c05cd JS |
213 | event.SetEventObject(g_activeFrame); |
214 | g_activeFrame->GetEventHandler()->ProcessEvent(event); | |
215 | ||
216 | g_activeFrame = NULL; | |
217 | } | |
0a164d4c | 218 | |
576f7127 | 219 | return FALSE; |
06fda9e8 | 220 | } |
865bb325 | 221 | } |
7d9f12f3 | 222 | |
7d9f12f3 VS |
223 | //----------------------------------------------------------------------------- |
224 | // "focus" from m_window | |
225 | //----------------------------------------------------------------------------- | |
226 | ||
865bb325 | 227 | extern "C" { |
7d9f12f3 VS |
228 | static gint gtk_frame_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) ) |
229 | { | |
230 | if (g_isIdle) | |
231 | wxapp_install_idle_handler(); | |
232 | ||
233 | // This disables GTK's tab traversal | |
234 | gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" ); | |
235 | return TRUE; | |
236 | } | |
865bb325 | 237 | } |
7d9f12f3 VS |
238 | |
239 | //----------------------------------------------------------------------------- | |
240 | // "size_allocate" | |
241 | //----------------------------------------------------------------------------- | |
242 | ||
865bb325 | 243 | extern "C" { |
7d9f12f3 VS |
244 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxTopLevelWindowGTK *win ) |
245 | { | |
246 | if (g_isIdle) | |
247 | wxapp_install_idle_handler(); | |
248 | ||
249 | if (!win->m_hasVMT) | |
250 | return; | |
251 | ||
252 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) | |
253 | { | |
254 | /* | |
255 | wxPrintf( "OnSize from " ); | |
256 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
257 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
258 | wxPrintf( " %d %d %d %d\n", (int)alloc->x, | |
259 | (int)alloc->y, | |
260 | (int)alloc->width, | |
261 | (int)alloc->height ); | |
262 | */ | |
263 | ||
264 | win->m_width = alloc->width; | |
265 | win->m_height = alloc->height; | |
7d9f12f3 VS |
266 | win->GtkUpdateSize(); |
267 | } | |
268 | } | |
865bb325 | 269 | } |
7d9f12f3 VS |
270 | |
271 | //----------------------------------------------------------------------------- | |
272 | // "delete_event" | |
273 | //----------------------------------------------------------------------------- | |
274 | ||
865bb325 | 275 | extern "C" { |
7d9f12f3 VS |
276 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxTopLevelWindowGTK *win ) |
277 | { | |
278 | if (g_isIdle) | |
279 | wxapp_install_idle_handler(); | |
280 | ||
281 | if (win->IsEnabled() && | |
5152b0e5 JS |
282 | (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) || |
283 | win->IsGrabbed())) | |
7d9f12f3 VS |
284 | win->Close(); |
285 | ||
286 | return TRUE; | |
287 | } | |
865bb325 | 288 | } |
7d9f12f3 VS |
289 | |
290 | ||
291 | //----------------------------------------------------------------------------- | |
292 | // "configure_event" | |
293 | //----------------------------------------------------------------------------- | |
294 | ||
865bb325 | 295 | extern "C" { |
7d9f12f3 | 296 | static gint |
7d9f12f3 | 297 | gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxTopLevelWindowGTK *win ) |
7d9f12f3 VS |
298 | { |
299 | if (g_isIdle) | |
300 | wxapp_install_idle_handler(); | |
301 | ||
48f72114 | 302 | if (!win->m_hasVMT || !win->IsShown()) |
7d9f12f3 VS |
303 | return FALSE; |
304 | ||
32f2ebbf | 305 | |
7d9f12f3 VS |
306 | int x = 0; |
307 | int y = 0; | |
308 | gdk_window_get_root_origin( win->m_widget->window, &x, &y ); | |
309 | win->m_x = x; | |
310 | win->m_y = y; | |
7d9f12f3 VS |
311 | |
312 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); | |
313 | mevent.SetEventObject( win ); | |
314 | win->GetEventHandler()->ProcessEvent( mevent ); | |
315 | ||
316 | return FALSE; | |
317 | } | |
865bb325 | 318 | } |
7d9f12f3 VS |
319 | |
320 | //----------------------------------------------------------------------------- | |
321 | // "realize" from m_widget | |
322 | //----------------------------------------------------------------------------- | |
323 | ||
e1f14d22 RR |
324 | // we cannot MWM hints and icons before the widget has been realized, |
325 | // so we do this directly after realization | |
7d9f12f3 | 326 | |
865bb325 | 327 | extern "C" { |
7d9f12f3 | 328 | static void |
6aeb6f2a VZ |
329 | gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget), |
330 | wxTopLevelWindowGTK *win ) | |
7d9f12f3 VS |
331 | { |
332 | if (g_isIdle) | |
333 | wxapp_install_idle_handler(); | |
334 | ||
e1f14d22 RR |
335 | // All this is for Motif Window Manager "hints" and is supposed to be |
336 | // recognized by other WM as well. Not tested. | |
82c9f85c | 337 | gdk_window_set_decorations(win->m_widget->window, |
f819b4a3 | 338 | (GdkWMDecoration)win->m_gdkDecor); |
82c9f85c | 339 | gdk_window_set_functions(win->m_widget->window, |
f819b4a3 | 340 | (GdkWMFunction)win->m_gdkFunc); |
7d9f12f3 | 341 | |
e1f14d22 | 342 | // GTK's shrinking/growing policy |
f819b4a3 | 343 | if ((win->m_gdkFunc & GDK_FUNC_RESIZE) == 0) |
7d9f12f3 VS |
344 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); |
345 | else | |
346 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); | |
347 | ||
e1f14d22 | 348 | // reset the icon |
7efaed4d | 349 | wxIconBundle iconsOld = win->GetIcons(); |
6aeb6f2a | 350 | if ( iconsOld.GetIcon(-1).Ok() ) |
7d9f12f3 | 351 | { |
7d9f12f3 | 352 | win->SetIcon( wxNullIcon ); |
7efaed4d | 353 | win->SetIcons( iconsOld ); |
7d9f12f3 | 354 | } |
7d9f12f3 | 355 | } |
865bb325 | 356 | } |
7d9f12f3 VS |
357 | |
358 | //----------------------------------------------------------------------------- | |
359 | // "map_event" from m_widget | |
360 | //----------------------------------------------------------------------------- | |
361 | ||
865bb325 | 362 | extern "C" { |
7d9f12f3 VS |
363 | static void |
364 | gtk_frame_map_callback( GtkWidget * WXUNUSED(widget), | |
365 | GdkEvent * WXUNUSED(event), | |
366 | wxTopLevelWindow *win ) | |
367 | { | |
0a164d4c | 368 | win->SetIconizeState(false); |
7d9f12f3 | 369 | } |
865bb325 | 370 | } |
7d9f12f3 VS |
371 | |
372 | //----------------------------------------------------------------------------- | |
373 | // "unmap_event" from m_widget | |
374 | //----------------------------------------------------------------------------- | |
375 | ||
865bb325 | 376 | extern "C" { |
7d9f12f3 VS |
377 | static void |
378 | gtk_frame_unmap_callback( GtkWidget * WXUNUSED(widget), | |
379 | GdkEvent * WXUNUSED(event), | |
380 | wxTopLevelWindow *win ) | |
381 | { | |
382 | win->SetIconizeState(TRUE); | |
383 | } | |
865bb325 | 384 | } |
7d9f12f3 VS |
385 | |
386 | //----------------------------------------------------------------------------- | |
387 | // "expose_event" of m_client | |
388 | //----------------------------------------------------------------------------- | |
389 | ||
865bb325 | 390 | extern "C" { |
7d9f12f3 VS |
391 | static int gtk_window_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindow *win ) |
392 | { | |
393 | GtkPizza *pizza = GTK_PIZZA(widget); | |
394 | ||
90350682 VZ |
395 | gtk_paint_flat_box (win->m_widget->style, |
396 | pizza->bin_window, GTK_STATE_NORMAL, | |
397 | GTK_SHADOW_NONE, | |
398 | &gdk_event->area, | |
399 | win->m_widget, | |
400 | (char *)"base", | |
401 | 0, 0, -1, -1); | |
7d9f12f3 | 402 | |
cba9ef7f | 403 | return FALSE; |
7d9f12f3 | 404 | } |
865bb325 | 405 | } |
7d9f12f3 VS |
406 | |
407 | //----------------------------------------------------------------------------- | |
408 | // "draw" of m_client | |
409 | //----------------------------------------------------------------------------- | |
410 | ||
52d6235d | 411 | #ifndef __WXGTK20__ |
7d9f12f3 | 412 | |
865bb325 | 413 | extern "C" { |
7d9f12f3 VS |
414 | static void gtk_window_draw_callback( GtkWidget *widget, GdkRectangle *rect, wxWindow *win ) |
415 | { | |
416 | GtkPizza *pizza = GTK_PIZZA(widget); | |
417 | ||
90350682 VZ |
418 | gtk_paint_flat_box (win->m_widget->style, |
419 | pizza->bin_window, GTK_STATE_NORMAL, | |
420 | GTK_SHADOW_NONE, | |
421 | rect, | |
422 | win->m_widget, | |
423 | (char *)"base", | |
424 | 0, 0, -1, -1); | |
7d9f12f3 | 425 | } |
865bb325 | 426 | } |
7d9f12f3 | 427 | |
52d6235d VZ |
428 | #endif // GTK+ 1.x |
429 | ||
7d9f12f3 VS |
430 | // ---------------------------------------------------------------------------- |
431 | // wxTopLevelWindowGTK itself | |
432 | // ---------------------------------------------------------------------------- | |
433 | ||
434 | //----------------------------------------------------------------------------- | |
435 | // InsertChild for wxTopLevelWindowGTK | |
436 | //----------------------------------------------------------------------------- | |
437 | ||
438 | /* Callback for wxTopLevelWindowGTK. This very strange beast has to be used because | |
439 | * C++ has no virtual methods in a constructor. We have to emulate a | |
77ffb593 | 440 | * virtual function here as wxWidgets requires different ways to insert |
7d9f12f3 VS |
441 | * a child in container classes. */ |
442 | ||
443 | static void wxInsertChildInTopLevelWindow( wxTopLevelWindowGTK* parent, wxWindow* child ) | |
444 | { | |
445 | wxASSERT( GTK_IS_WIDGET(child->m_widget) ); | |
446 | ||
447 | if (!parent->m_insertInClientArea) | |
448 | { | |
e1f14d22 | 449 | // these are outside the client area |
7d9f12f3 VS |
450 | wxTopLevelWindowGTK* frame = (wxTopLevelWindowGTK*) parent; |
451 | gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget), | |
452 | GTK_WIDGET(child->m_widget), | |
453 | child->m_x, | |
454 | child->m_y, | |
455 | child->m_width, | |
456 | child->m_height ); | |
457 | } | |
458 | else | |
459 | { | |
e1f14d22 | 460 | // these are inside the client area |
7d9f12f3 VS |
461 | gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), |
462 | GTK_WIDGET(child->m_widget), | |
e4b7b2b0 VS |
463 | child->m_x, |
464 | child->m_y, | |
7d9f12f3 VS |
465 | child->m_width, |
466 | child->m_height ); | |
467 | } | |
468 | ||
e1f14d22 | 469 | // resize on OnInternalIdle |
7d9f12f3 VS |
470 | parent->GtkUpdateSize(); |
471 | } | |
472 | ||
473 | // ---------------------------------------------------------------------------- | |
474 | // wxTopLevelWindowGTK creation | |
475 | // ---------------------------------------------------------------------------- | |
476 | ||
477 | void wxTopLevelWindowGTK::Init() | |
478 | { | |
0a164d4c | 479 | m_sizeSet = false; |
7d9f12f3 VS |
480 | m_miniEdge = 0; |
481 | m_miniTitle = 0; | |
482 | m_mainWidget = (GtkWidget*) NULL; | |
0a164d4c WS |
483 | m_insertInClientArea = true; |
484 | m_isIconized = false; | |
485 | m_fsIsShowing = false; | |
486 | m_themeEnabled = true; | |
f819b4a3 | 487 | m_gdkDecor = m_gdkFunc = 0; |
0a164d4c | 488 | m_grabbed = false; |
dca92ddf MR |
489 | |
490 | //BCI: header wx/gtk/toplevel.h: | |
491 | // private gtk_timeout_add result for mimicing wxUSER_ATTENTION_INFO and | |
492 | // wxUSER_ATTENTION_ERROR difference, -2 for no hint, -1 for ERROR hint, rest for GtkTimeout handle. | |
493 | // int m_urgency_hint; | |
494 | ||
495 | //BCI: m_urgency_hint = -2; | |
7d9f12f3 VS |
496 | } |
497 | ||
498 | bool wxTopLevelWindowGTK::Create( wxWindow *parent, | |
f819b4a3 VS |
499 | wxWindowID id, |
500 | const wxString& title, | |
501 | const wxPoint& pos, | |
502 | const wxSize& sizeOrig, | |
503 | long style, | |
504 | const wxString &name ) | |
7d9f12f3 VS |
505 | { |
506 | // always create a frame of some reasonable, even if arbitrary, size (at | |
507 | // least for MSW compatibility) | |
508 | wxSize size = sizeOrig; | |
1111cedc | 509 | size.x = WidthDefault(size.x); |
66202a7e | 510 | size.y = HeightDefault(size.y); |
7d9f12f3 VS |
511 | |
512 | wxTopLevelWindows.Append( this ); | |
513 | ||
0a164d4c | 514 | m_needParent = false; |
6aeb6f2a | 515 | |
7d9f12f3 VS |
516 | if (!PreCreation( parent, pos, size ) || |
517 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
518 | { | |
519 | wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") ); | |
0a164d4c | 520 | return false; |
7d9f12f3 VS |
521 | } |
522 | ||
523 | m_title = title; | |
524 | ||
525 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInTopLevelWindow; | |
526 | ||
63c5efa3 VS |
527 | // NB: m_widget may be !=NULL if it was created by derived class' Create, |
528 | // e.g. in wxTaskBarIconAreaGTK | |
529 | if (m_widget == NULL) | |
530 | { | |
63c5efa3 VS |
531 | if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) |
532 | { | |
9e691f46 | 533 | #ifdef __WXGTK20__ |
4d8d6490 VS |
534 | m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
535 | // Tell WM that this is a dialog window and make it center | |
536 | // on parent by default (this is what GtkDialog ctor does): | |
537 | gtk_window_set_type_hint(GTK_WINDOW(m_widget), | |
538 | GDK_WINDOW_TYPE_HINT_DIALOG); | |
539 | gtk_window_set_position(GTK_WINDOW(m_widget), | |
540 | GTK_WIN_POS_CENTER_ON_PARENT); | |
9e691f46 | 541 | #else |
4d8d6490 | 542 | m_widget = gtk_window_new(GTK_WINDOW_DIALOG); |
9e691f46 | 543 | #endif |
63c5efa3 | 544 | } |
4d8d6490 VS |
545 | else |
546 | { | |
37780c64 | 547 | m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
606ce80c | 548 | #if GTK_CHECK_VERSION(2,1,0) |
caf3e97f | 549 | if (!gtk_check_version(2,1,0)) |
11475235 | 550 | { |
caf3e97f KH |
551 | if (style & wxFRAME_TOOL_WINDOW) |
552 | { | |
553 | gtk_window_set_type_hint(GTK_WINDOW(m_widget), | |
554 | GDK_WINDOW_TYPE_HINT_UTILITY); | |
0a164d4c | 555 | |
caf3e97f KH |
556 | // On some WMs, like KDE, a TOOL_WINDOW will still show |
557 | // on the taskbar, but on Gnome a TOOL_WINDOW will not. | |
0a164d4c | 558 | // For consistency between WMs and with Windows, we |
caf3e97f KH |
559 | // should set the NO_TASKBAR flag which will apply |
560 | // the set_skip_taskbar_hint if it is available, | |
561 | // ensuring no taskbar entry will appear. | |
562 | style |= wxFRAME_NO_TASKBAR; | |
563 | } | |
11475235 | 564 | } |
cf49c955 | 565 | #endif |
4d8d6490 | 566 | } |
63c5efa3 | 567 | } |
7d9f12f3 | 568 | |
dca92ddf MR |
569 | // BCI: |
570 | gtk_object_set_data( GTK_OBJECT(m_widget), "m_urgency_hint", GINT_TO_POINTER(-2) ); | |
571 | ||
e25c7537 VS |
572 | wxWindow *topParent = wxGetTopLevelParent(m_parent); |
573 | if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) && | |
0a164d4c WS |
574 | (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) || |
575 | (style & wxFRAME_FLOAT_ON_PARENT))) | |
7cd95599 | 576 | { |
e25c7537 VS |
577 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
578 | GTK_WINDOW(topParent->m_widget) ); | |
7cd95599 | 579 | } |
7d9f12f3 | 580 | |
2be125e6 | 581 | #if GTK_CHECK_VERSION(2,2,0) |
caf3e97f | 582 | if (!gtk_check_version(2,2,0)) |
2be125e6 | 583 | { |
caf3e97f KH |
584 | if (style & wxFRAME_NO_TASKBAR) |
585 | { | |
586 | gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE); | |
587 | } | |
2be125e6 VS |
588 | } |
589 | #endif | |
590 | ||
2fca39c9 | 591 | #if GTK_CHECK_VERSION(2,4,0) |
81a3313a | 592 | if (!gtk_check_version(2,4,0)) |
2fca39c9 | 593 | { |
81a3313a RR |
594 | if (style & wxSTAY_ON_TOP) |
595 | { | |
596 | gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE); | |
597 | } | |
2fca39c9 KH |
598 | } |
599 | #endif | |
600 | ||
0a164d4c | 601 | if (!name.empty()) |
fab591c5 | 602 | gtk_window_set_wmclass( GTK_WINDOW(m_widget), wxGTK_CONV( name ), wxGTK_CONV( name ) ); |
7d9f12f3 | 603 | |
fab591c5 | 604 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); |
7d9f12f3 VS |
605 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
606 | ||
607 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
608 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
609 | ||
e1f14d22 | 610 | // m_mainWidget holds the toolbar, the menubar and the client area |
7d9f12f3 VS |
611 | m_mainWidget = gtk_pizza_new(); |
612 | gtk_widget_show( m_mainWidget ); | |
613 | GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); | |
614 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); | |
615 | ||
cba9ef7f RR |
616 | if (m_miniEdge == 0) // wxMiniFrame has its own version. |
617 | { | |
618 | // For m_mainWidget themes | |
619 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event", | |
7d9f12f3 | 620 | GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this ); |
4e5a4c69 | 621 | #ifndef __WXGTK20__ |
cba9ef7f | 622 | gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw", |
7d9f12f3 | 623 | GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this ); |
4e5a4c69 | 624 | #endif |
cba9ef7f | 625 | } |
7d9f12f3 | 626 | |
e1f14d22 | 627 | // m_wxwindow only represents the client area without toolbar and menubar |
7d9f12f3 VS |
628 | m_wxwindow = gtk_pizza_new(); |
629 | gtk_widget_show( m_wxwindow ); | |
630 | gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); | |
631 | ||
e1f14d22 RR |
632 | // we donm't allow the frame to get the focus as otherwise |
633 | // the frame will grab it at arbitrary focus changes | |
7d9f12f3 VS |
634 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); |
635 | ||
636 | if (m_parent) m_parent->AddChild( this ); | |
637 | ||
e1f14d22 | 638 | // the user resized the frame by dragging etc. |
7d9f12f3 VS |
639 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
640 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
641 | ||
642 | PostCreation(); | |
643 | ||
644 | if ((m_x != -1) || (m_y != -1)) | |
645 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
6aeb6f2a | 646 | |
e1f14d22 | 647 | gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height ); |
7d9f12f3 | 648 | |
e1f14d22 RR |
649 | // we cannot set MWM hints and icons before the widget has |
650 | // been realized, so we do this directly after realization | |
7d9f12f3 VS |
651 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", |
652 | GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); | |
653 | ||
e1f14d22 | 654 | // the only way to get the window size is to connect to this event |
7d9f12f3 VS |
655 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
656 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
657 | ||
e1f14d22 | 658 | // map and unmap for iconized state |
7d9f12f3 VS |
659 | gtk_signal_connect( GTK_OBJECT(m_widget), "map_event", |
660 | GTK_SIGNAL_FUNC(gtk_frame_map_callback), (gpointer)this ); | |
661 | gtk_signal_connect( GTK_OBJECT(m_widget), "unmap_event", | |
662 | GTK_SIGNAL_FUNC(gtk_frame_unmap_callback), (gpointer)this ); | |
663 | ||
e1f14d22 | 664 | // the only way to get the window size is to connect to this event |
7d9f12f3 VS |
665 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
666 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
667 | ||
e1f14d22 | 668 | // disable native tab traversal |
7d9f12f3 VS |
669 | gtk_signal_connect( GTK_OBJECT(m_widget), "focus", |
670 | GTK_SIGNAL_FUNC(gtk_frame_focus_callback), (gpointer)this ); | |
671 | ||
06fda9e8 RR |
672 | // activation |
673 | gtk_signal_connect( GTK_OBJECT(m_widget), "focus_in_event", | |
674 | GTK_SIGNAL_FUNC(gtk_frame_focus_in_callback), (gpointer)this ); | |
675 | gtk_signal_connect( GTK_OBJECT(m_widget), "focus_out_event", | |
676 | GTK_SIGNAL_FUNC(gtk_frame_focus_out_callback), (gpointer)this ); | |
0a164d4c | 677 | |
e1f14d22 | 678 | // decorations |
f819b4a3 VS |
679 | if ((m_miniEdge > 0) || (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER)) |
680 | { | |
681 | m_gdkDecor = 0; | |
682 | m_gdkFunc = 0; | |
683 | } | |
684 | else | |
685 | { | |
686 | m_gdkDecor = (long) GDK_DECOR_BORDER; | |
687 | m_gdkFunc = (long) GDK_FUNC_MOVE; | |
82c9f85c | 688 | |
f819b4a3 | 689 | // All this is for Motif Window Manager "hints" and is supposed to be |
e1f14d22 | 690 | // recognized by other WMs as well. |
f819b4a3 | 691 | if ((style & wxCAPTION) != 0) |
c3d8ee42 | 692 | { |
f819b4a3 | 693 | m_gdkDecor |= GDK_DECOR_TITLE; |
c3d8ee42 | 694 | } |
850c6ed4 | 695 | if ((style & wxCLOSE_BOX) != 0) |
f819b4a3 VS |
696 | { |
697 | m_gdkFunc |= GDK_FUNC_CLOSE; | |
c3d8ee42 VS |
698 | } |
699 | if ((style & wxSYSTEM_MENU) != 0) | |
700 | { | |
f819b4a3 VS |
701 | m_gdkDecor |= GDK_DECOR_MENU; |
702 | } | |
703 | if ((style & wxMINIMIZE_BOX) != 0) | |
704 | { | |
705 | m_gdkFunc |= GDK_FUNC_MINIMIZE; | |
706 | m_gdkDecor |= GDK_DECOR_MINIMIZE; | |
707 | } | |
708 | if ((style & wxMAXIMIZE_BOX) != 0) | |
709 | { | |
710 | m_gdkFunc |= GDK_FUNC_MAXIMIZE; | |
711 | m_gdkDecor |= GDK_DECOR_MAXIMIZE; | |
712 | } | |
713 | if ((style & wxRESIZE_BORDER) != 0) | |
714 | { | |
715 | m_gdkFunc |= GDK_FUNC_RESIZE; | |
716 | m_gdkDecor |= GDK_DECOR_RESIZEH; | |
717 | } | |
718 | } | |
719 | ||
0a164d4c | 720 | return true; |
7d9f12f3 VS |
721 | } |
722 | ||
723 | wxTopLevelWindowGTK::~wxTopLevelWindowGTK() | |
724 | { | |
5152b0e5 JS |
725 | if (m_grabbed) |
726 | { | |
83afe211 | 727 | wxASSERT_MSG( FALSE, _T("Window still grabbed")); |
5152b0e5 JS |
728 | RemoveGrab(); |
729 | } | |
1cbee0b4 | 730 | |
0a164d4c | 731 | m_isBeingDeleted = true; |
6aeb6f2a | 732 | |
710968c3 VZ |
733 | // it may also be GtkScrolledWindow in the case of an MDI child |
734 | if (GTK_IS_WINDOW(m_widget)) | |
735 | { | |
736 | gtk_window_set_focus( GTK_WINDOW(m_widget), NULL ); | |
737 | } | |
0a164d4c | 738 | |
06fda9e8 RR |
739 | if (g_activeFrame == this) |
740 | g_activeFrame = NULL; | |
741 | if (g_lastActiveFrame == this) | |
742 | g_lastActiveFrame = NULL; | |
7d9f12f3 VS |
743 | } |
744 | ||
8a9650ea | 745 | |
8a9650ea | 746 | |
7d9f12f3 VS |
747 | bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long style ) |
748 | { | |
8a8997c3 | 749 | if (show == m_fsIsShowing) |
0a164d4c | 750 | return false; // return what? |
7d9f12f3 VS |
751 | |
752 | m_fsIsShowing = show; | |
0a164d4c | 753 | |
1542ea39 | 754 | wxX11FullScreenMethod method = |
8166ab43 VS |
755 | wxGetFullScreenMethodX11((WXDisplay*)GDK_DISPLAY(), |
756 | (WXWindow)GDK_ROOT_WINDOW()); | |
1542ea39 | 757 | |
feb1c9fb VS |
758 | #if GTK_CHECK_VERSION(2,2,0) |
759 | // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions | |
760 | // to switch to fullscreen, which is not always available. We must | |
761 | // check if WM supports the spec and use legacy methods if it | |
762 | // doesn't. | |
cc35003a | 763 | if ( (method == wxX11_FS_WMSPEC) && !gtk_check_version(2,2,0) ) |
7d9f12f3 | 764 | { |
feb1c9fb VS |
765 | if (show) |
766 | gtk_window_fullscreen( GTK_WINDOW( m_widget ) ); | |
767 | else | |
768 | gtk_window_unfullscreen( GTK_WINDOW( m_widget ) ); | |
7d9f12f3 VS |
769 | } |
770 | else | |
8a8997c3 | 771 | #endif // GTK+ >= 2.2.0 |
7d9f12f3 | 772 | { |
feb1c9fb VS |
773 | GdkWindow *window = m_widget->window; |
774 | ||
775 | if (show) | |
8166ab43 | 776 | { |
feb1c9fb VS |
777 | m_fsSaveFlag = style; |
778 | GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y ); | |
779 | GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height ); | |
780 | ||
781 | int screen_width,screen_height; | |
782 | wxDisplaySize( &screen_width, &screen_height ); | |
783 | ||
784 | gint client_x, client_y, root_x, root_y; | |
785 | gint width, height; | |
786 | ||
787 | if (method != wxX11_FS_WMSPEC) | |
788 | { | |
789 | // don't do it always, Metacity hates it | |
790 | m_fsSaveGdkFunc = m_gdkFunc; | |
791 | m_fsSaveGdkDecor = m_gdkDecor; | |
792 | m_gdkFunc = m_gdkDecor = 0; | |
793 | gdk_window_set_decorations(window, (GdkWMDecoration)0); | |
794 | gdk_window_set_functions(window, (GdkWMFunction)0); | |
795 | } | |
796 | ||
797 | gdk_window_get_origin (m_widget->window, &root_x, &root_y); | |
798 | gdk_window_get_geometry (m_widget->window, &client_x, &client_y, | |
799 | &width, &height, NULL); | |
800 | ||
801 | gdk_window_move_resize (m_widget->window, -client_x, -client_y, | |
802 | screen_width + 1, screen_height + 1); | |
803 | ||
804 | wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(), | |
805 | (WXWindow)GDK_ROOT_WINDOW(), | |
806 | (WXWindow)GDK_WINDOW_XWINDOW(window), | |
807 | show, &m_fsSaveFrame, method); | |
808 | } | |
3b2931fb | 809 | else // hide |
feb1c9fb VS |
810 | { |
811 | if (method != wxX11_FS_WMSPEC) | |
812 | { | |
813 | // don't do it always, Metacity hates it | |
814 | m_gdkFunc = m_fsSaveGdkFunc; | |
815 | m_gdkDecor = m_fsSaveGdkDecor; | |
816 | gdk_window_set_decorations(window, (GdkWMDecoration)m_gdkDecor); | |
817 | gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc); | |
818 | } | |
819 | ||
820 | wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(), | |
821 | (WXWindow)GDK_ROOT_WINDOW(), | |
822 | (WXWindow)GDK_WINDOW_XWINDOW(window), | |
823 | show, &m_fsSaveFrame, method); | |
824 | ||
825 | SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y, | |
826 | m_fsSaveFrame.width, m_fsSaveFrame.height); | |
8166ab43 | 827 | } |
7d9f12f3 | 828 | } |
8166ab43 | 829 | |
3b2931fb VZ |
830 | // documented behaviour is to show the window if it's still hidden when |
831 | // showing it full screen | |
832 | if ( show && !IsShown() ) | |
833 | Show(); | |
834 | ||
0a164d4c | 835 | return true; |
7d9f12f3 VS |
836 | } |
837 | ||
838 | // ---------------------------------------------------------------------------- | |
839 | // overridden wxWindow methods | |
840 | // ---------------------------------------------------------------------------- | |
841 | ||
842 | bool wxTopLevelWindowGTK::Show( bool show ) | |
843 | { | |
82b978d7 | 844 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7d9f12f3 VS |
845 | |
846 | if (show && !m_sizeSet) | |
847 | { | |
848 | /* by calling GtkOnSize here, we don't have to call | |
849 | either after showing the frame, which would entail | |
850 | much ugly flicker or from within the size_allocate | |
851 | handler, because GTK 1.1.X forbids that. */ | |
852 | ||
853 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
854 | } | |
0a164d4c | 855 | |
32f2ebbf RR |
856 | if (show) |
857 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
0a164d4c | 858 | |
7d9f12f3 VS |
859 | return wxWindow::Show( show ); |
860 | } | |
861 | ||
a2ac55f5 RR |
862 | void wxTopLevelWindowGTK::Raise() |
863 | { | |
864 | #ifdef __WXGTK20__ | |
865 | gtk_window_present( GTK_WINDOW( m_widget ) ); | |
866 | #else | |
867 | wxWindow::Raise(); | |
868 | #endif | |
869 | } | |
870 | ||
7d9f12f3 VS |
871 | void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) ) |
872 | { | |
873 | wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") ); | |
874 | } | |
875 | ||
876 | void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
877 | { | |
82b978d7 RD |
878 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
879 | ||
e1f14d22 | 880 | // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow |
7d9f12f3 VS |
881 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
882 | ||
e1f14d22 | 883 | // avoid recursions |
7d9f12f3 VS |
884 | if (m_resizing) |
885 | return; | |
0a164d4c | 886 | m_resizing = true; |
7d9f12f3 VS |
887 | |
888 | int old_x = m_x; | |
889 | int old_y = m_y; | |
890 | ||
891 | int old_width = m_width; | |
892 | int old_height = m_height; | |
893 | ||
894 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) | |
895 | { | |
896 | if (x != -1) m_x = x; | |
897 | if (y != -1) m_y = y; | |
7d9f12f3 VS |
898 | } |
899 | else | |
900 | { | |
901 | m_x = x; | |
902 | m_y = y; | |
7d9f12f3 | 903 | } |
d44c23ce RR |
904 | if (width != -1) m_width = width; |
905 | if (height != -1) m_height = height; | |
7d9f12f3 VS |
906 | |
907 | /* | |
908 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
909 | { | |
910 | if (width == -1) m_width = 80; | |
911 | } | |
912 | ||
913 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
914 | { | |
915 | if (height == -1) m_height = 26; | |
916 | } | |
917 | */ | |
918 | ||
e7dda1ff VS |
919 | int minWidth = GetMinWidth(), |
920 | minHeight = GetMinHeight(), | |
921 | maxWidth = GetMaxWidth(), | |
922 | maxHeight = GetMaxHeight(); | |
923 | ||
62be94e1 RR |
924 | #ifdef __WXGPE__ |
925 | // GPE's window manager doesn't like size hints | |
926 | // at all, esp. when the user has to use the | |
927 | // virtual keyboard. | |
928 | minWidth = -1; | |
929 | minHeight = -1; | |
930 | maxWidth = -1; | |
931 | maxHeight = -1; | |
932 | #endif | |
0a164d4c | 933 | |
e7dda1ff VS |
934 | if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth; |
935 | if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight; | |
936 | if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth; | |
937 | if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight; | |
7d9f12f3 VS |
938 | |
939 | if ((m_x != -1) || (m_y != -1)) | |
940 | { | |
941 | if ((m_x != old_x) || (m_y != old_y)) | |
942 | { | |
943 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
944 | } | |
945 | } | |
946 | ||
947 | if ((m_width != old_width) || (m_height != old_height)) | |
948 | { | |
e1f14d22 RR |
949 | if (m_widget->window) |
950 | gdk_window_resize( m_widget->window, m_width, m_height ); | |
951 | else | |
952 | gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height ); | |
7d9f12f3 VS |
953 | |
954 | /* we set the size in GtkOnSize, i.e. mostly the actual resizing is | |
955 | done either directly before the frame is shown or in idle time | |
956 | so that different calls to SetSize() don't lead to flicker. */ | |
0a164d4c | 957 | m_sizeSet = false; |
7d9f12f3 VS |
958 | } |
959 | ||
0a164d4c | 960 | m_resizing = false; |
7d9f12f3 VS |
961 | } |
962 | ||
963 | void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const | |
964 | { | |
82b978d7 RD |
965 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
966 | ||
7d9f12f3 VS |
967 | wxWindow::DoGetClientSize( width, height ); |
968 | if (height) | |
969 | { | |
e1f14d22 | 970 | // mini edge |
7d9f12f3 VS |
971 | *height -= m_miniEdge*2 + m_miniTitle; |
972 | } | |
973 | if (width) | |
974 | { | |
975 | *width -= m_miniEdge*2; | |
976 | } | |
977 | } | |
978 | ||
979 | void wxTopLevelWindowGTK::DoSetClientSize( int width, int height ) | |
980 | { | |
82b978d7 | 981 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7d9f12f3 | 982 | |
82c9f85c | 983 | DoSetSize(-1, -1, |
7d9f12f3 VS |
984 | width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0); |
985 | } | |
986 | ||
987 | void wxTopLevelWindowGTK::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), | |
82c9f85c | 988 | int width, int height ) |
7d9f12f3 VS |
989 | { |
990 | // due to a bug in gtk, x,y are always 0 | |
991 | // m_x = x; | |
992 | // m_y = y; | |
993 | ||
e1f14d22 | 994 | // avoid recursions |
7d9f12f3 | 995 | if (m_resizing) return; |
0a164d4c | 996 | m_resizing = true; |
7d9f12f3 VS |
997 | |
998 | if ( m_wxwindow == NULL ) return; | |
999 | ||
1000 | m_width = width; | |
1001 | m_height = height; | |
1002 | ||
0d53fc34 | 1003 | /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses |
7d9f12f3 | 1004 | wxWindow::Create to create it's GTK equivalent. m_mainWidget is only |
0d53fc34 | 1005 | set in wxFrame::Create so it is used to check what kind of frame we |
7d9f12f3 VS |
1006 | have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we |
1007 | skip the part which handles m_frameMenuBar, m_frameToolBar and (most | |
1008 | importantly) m_mainWidget */ | |
1009 | ||
e7dda1ff VS |
1010 | int minWidth = GetMinWidth(), |
1011 | minHeight = GetMinHeight(), | |
1012 | maxWidth = GetMaxWidth(), | |
1013 | maxHeight = GetMaxHeight(); | |
1014 | ||
62be94e1 RR |
1015 | #ifdef __WXGPE__ |
1016 | // GPE's window manager doesn't like size hints | |
1017 | // at all, esp. when the user has to use the | |
1018 | // virtual keyboard. | |
1019 | minWidth = -1; | |
1020 | minHeight = -1; | |
1021 | maxWidth = -1; | |
1022 | maxHeight = -1; | |
1023 | #endif | |
0a164d4c | 1024 | |
e7dda1ff VS |
1025 | if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth; |
1026 | if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight; | |
1027 | if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth; | |
1028 | if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight; | |
7d9f12f3 VS |
1029 | |
1030 | if (m_mainWidget) | |
1031 | { | |
e1f14d22 | 1032 | // set size hints |
801225c1 RL |
1033 | gint flag = 0; // GDK_HINT_POS; |
1034 | GdkGeometry geom; | |
1035 | ||
e7dda1ff VS |
1036 | if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE; |
1037 | if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE; | |
801225c1 | 1038 | |
e7dda1ff VS |
1039 | geom.min_width = minWidth; |
1040 | geom.min_height = minHeight; | |
801225c1 RL |
1041 | |
1042 | // Because of the way we set GDK_HINT_MAX_SIZE above, if either of | |
1043 | // maxHeight or maxWidth is set, we must set them both, else the | |
1044 | // remaining -1 will be taken literally. | |
1045 | ||
1046 | // I'm certain this also happens elsewhere, and is the probable | |
1047 | // cause of other such things as: | |
1048 | // Gtk-WARNING **: gtk_widget_size_allocate(): | |
1049 | // attempt to allocate widget with width 65535 and height 600 | |
1050 | // but I don't have time to track them all now.. | |
1cbee0b4 | 1051 | // |
801225c1 RL |
1052 | // Really we need to encapulate all this height/width business and |
1053 | // stop any old method from ripping at the members directly and | |
1054 | // scattering -1's without regard for who might resolve them later. | |
1055 | ||
1056 | geom.max_width = ( maxHeight == -1 ) ? maxWidth | |
1057 | : ( maxWidth == -1 ) ? wxGetDisplaySize().GetWidth() | |
1058 | : maxWidth ; | |
1059 | ||
1060 | geom.max_height = ( maxWidth == -1 ) ? maxHeight // ( == -1 here ) | |
1061 | : ( maxHeight == -1 ) ? wxGetDisplaySize().GetHeight() | |
1062 | : maxHeight ; | |
1063 | ||
7d9f12f3 VS |
1064 | gtk_window_set_geometry_hints( GTK_WINDOW(m_widget), |
1065 | (GtkWidget*) NULL, | |
1066 | &geom, | |
1067 | (GdkWindowHints) flag ); | |
1068 | ||
1069 | /* I revert back to wxGTK's original behaviour. m_mainWidget holds the | |
1070 | * menubar, the toolbar and the client area, which is represented by | |
1071 | * m_wxwindow. | |
1072 | * this hurts in the eye, but I don't want to call SetSize() | |
1073 | * because I don't want to call any non-native functions here. */ | |
1074 | ||
1075 | int client_x = m_miniEdge; | |
1076 | int client_y = m_miniEdge + m_miniTitle; | |
1077 | int client_w = m_width - 2*m_miniEdge; | |
1078 | int client_h = m_height - 2*m_miniEdge - m_miniTitle; | |
801225c1 | 1079 | |
7d9f12f3 VS |
1080 | gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), |
1081 | m_wxwindow, | |
1082 | client_x, client_y, client_w, client_h ); | |
1083 | } | |
1084 | else | |
1085 | { | |
e1f14d22 RR |
1086 | // If there is no m_mainWidget between m_widget and m_wxwindow there |
1087 | // is no need to set the size or position of m_wxwindow. | |
7d9f12f3 VS |
1088 | } |
1089 | ||
0a164d4c | 1090 | m_sizeSet = true; |
7d9f12f3 VS |
1091 | |
1092 | // send size event to frame | |
1093 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
1094 | event.SetEventObject( this ); | |
1095 | GetEventHandler()->ProcessEvent( event ); | |
1096 | ||
0a164d4c | 1097 | m_resizing = false; |
7d9f12f3 VS |
1098 | } |
1099 | ||
1100 | void wxTopLevelWindowGTK::OnInternalIdle() | |
1101 | { | |
1102 | if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) | |
1103 | { | |
1104 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
1105 | ||
1106 | // we'll come back later | |
1107 | if (g_isIdle) | |
1108 | wxapp_install_idle_handler(); | |
1109 | return; | |
1110 | } | |
1111 | ||
6aeb6f2a VZ |
1112 | // set the focus if not done yet and if we can already do it |
1113 | if ( GTK_WIDGET_REALIZED(m_wxwindow) ) | |
1114 | { | |
cc06fe74 MB |
1115 | if ( g_delayedFocus && |
1116 | wxGetTopLevelParent((wxWindow*)g_delayedFocus) == this ) | |
6aeb6f2a | 1117 | { |
2b5f62a0 VZ |
1118 | wxLogTrace(_T("focus"), |
1119 | _T("Setting focus from wxTLW::OnIdle() to %s(%s)"), | |
1120 | g_delayedFocus->GetClassInfo()->GetClassName(), | |
1121 | g_delayedFocus->GetLabel().c_str()); | |
1122 | ||
6aeb6f2a VZ |
1123 | g_delayedFocus->SetFocus(); |
1124 | g_delayedFocus = NULL; | |
1125 | } | |
1126 | } | |
1127 | ||
7d9f12f3 | 1128 | wxWindow::OnInternalIdle(); |
0a164d4c | 1129 | |
06fda9e8 RR |
1130 | // Synthetize activate events. |
1131 | if ( g_sendActivateEvent != -1 ) | |
1132 | { | |
1133 | bool activate = g_sendActivateEvent != 0; | |
0a164d4c | 1134 | |
576f7127 RR |
1135 | // if (!activate) wxPrintf( wxT("de") ); |
1136 | // wxPrintf( wxT("activate\n") ); | |
0a164d4c | 1137 | |
06fda9e8 RR |
1138 | // do it only once |
1139 | g_sendActivateEvent = -1; | |
1140 | ||
1141 | wxTheApp->SetActive(activate, (wxWindow *)g_lastActiveFrame); | |
1142 | } | |
7d9f12f3 VS |
1143 | } |
1144 | ||
7d9f12f3 VS |
1145 | // ---------------------------------------------------------------------------- |
1146 | // frame title/icon | |
1147 | // ---------------------------------------------------------------------------- | |
1148 | ||
1149 | void wxTopLevelWindowGTK::SetTitle( const wxString &title ) | |
1150 | { | |
82b978d7 RD |
1151 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
1152 | ||
7d9f12f3 | 1153 | m_title = title; |
fab591c5 | 1154 | gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) ); |
7d9f12f3 VS |
1155 | } |
1156 | ||
f618020a MB |
1157 | void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon ) |
1158 | { | |
1159 | SetIcons( wxIconBundle( icon ) ); | |
1160 | } | |
1161 | ||
1162 | void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons ) | |
1163 | { | |
82b978d7 | 1164 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
f618020a MB |
1165 | |
1166 | wxTopLevelWindowBase::SetIcons( icons ); | |
1167 | ||
87e53e2a VS |
1168 | #ifdef __WXGTK20__ |
1169 | GList *list = NULL; | |
1170 | size_t max = icons.m_icons.GetCount(); | |
1171 | ||
1172 | for (size_t i = 0; i < max; i++) | |
52d6235d | 1173 | { |
87e53e2a VS |
1174 | if (icons.m_icons[i].Ok()) |
1175 | { | |
1176 | list = g_list_prepend(list, icons.m_icons[i].GetPixbuf()); | |
1177 | } | |
1178 | } | |
1179 | gtk_window_set_icon_list(GTK_WINDOW(m_widget), list); | |
1180 | g_list_free(list); | |
0a164d4c | 1181 | |
87e53e2a VS |
1182 | #else // !__WXGTK20__ |
1183 | GdkWindow* window = m_widget->window; | |
1184 | if (!window) | |
1185 | return; | |
1186 | ||
1187 | wxIcon icon = icons.GetIcon(-1); | |
1188 | if (icon.Ok()) | |
1189 | { | |
1190 | wxMask *mask = icon.GetMask(); | |
1191 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
1192 | if (mask) bm = mask->GetBitmap(); | |
1193 | ||
1194 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); | |
52d6235d | 1195 | } |
87e53e2a VS |
1196 | |
1197 | wxSetIconsX11( (WXDisplay*)GDK_WINDOW_XDISPLAY( window ), | |
1198 | (WXWindow)GDK_WINDOW_XWINDOW( window ), icons ); | |
1199 | #endif // !__WXGTK20__ | |
f618020a MB |
1200 | } |
1201 | ||
7d9f12f3 VS |
1202 | // ---------------------------------------------------------------------------- |
1203 | // frame state: maximized/iconized/normal | |
1204 | // ---------------------------------------------------------------------------- | |
1205 | ||
8805e155 | 1206 | void wxTopLevelWindowGTK::Maximize(bool maximize) |
7d9f12f3 | 1207 | { |
8805e155 RR |
1208 | #ifdef __WXGTK20__ |
1209 | if (maximize) | |
1210 | gtk_window_maximize( GTK_WINDOW( m_widget ) ); | |
1211 | else | |
1212 | gtk_window_unmaximize( GTK_WINDOW( m_widget ) ); | |
1213 | #else | |
7d9f12f3 | 1214 | wxFAIL_MSG( _T("not implemented") ); |
8805e155 | 1215 | #endif |
7d9f12f3 VS |
1216 | } |
1217 | ||
1218 | bool wxTopLevelWindowGTK::IsMaximized() const | |
1219 | { | |
d8e1fe80 VS |
1220 | #ifdef __WXGTK20__ |
1221 | if(!m_widget->window) | |
1222 | return false; | |
1223 | ||
1224 | return gdk_window_get_state(m_widget->window) & GDK_WINDOW_STATE_MAXIMIZED; | |
1225 | #else | |
7d9f12f3 VS |
1226 | // wxFAIL_MSG( _T("not implemented") ); |
1227 | ||
1228 | // This is an approximation | |
0a164d4c | 1229 | return false; |
d8e1fe80 | 1230 | #endif |
7d9f12f3 VS |
1231 | } |
1232 | ||
1233 | void wxTopLevelWindowGTK::Restore() | |
1234 | { | |
387fd89d | 1235 | #ifdef __WXGTK20__ |
8805e155 RR |
1236 | // "Present" seems similar enough to "restore" |
1237 | gtk_window_present( GTK_WINDOW( m_widget ) ); | |
1238 | #else | |
7d9f12f3 | 1239 | wxFAIL_MSG( _T("not implemented") ); |
8805e155 | 1240 | #endif |
7d9f12f3 VS |
1241 | } |
1242 | ||
1243 | void wxTopLevelWindowGTK::Iconize( bool iconize ) | |
1244 | { | |
8805e155 RR |
1245 | #ifdef __WXGTK20__ |
1246 | if (iconize) | |
1247 | gtk_window_iconify( GTK_WINDOW( m_widget ) ); | |
1248 | else | |
1249 | gtk_window_deiconify( GTK_WINDOW( m_widget ) ); | |
1250 | #else | |
7d9f12f3 VS |
1251 | if (iconize) |
1252 | { | |
1253 | GdkWindow *window = m_widget->window; | |
1254 | ||
1255 | // you should do it later, for example from OnCreate() handler | |
1256 | wxCHECK_RET( window, _T("frame not created yet - can't iconize") ); | |
1257 | ||
1258 | XIconifyWindow( GDK_WINDOW_XDISPLAY( window ), | |
1259 | GDK_WINDOW_XWINDOW( window ), | |
1260 | DefaultScreen( GDK_DISPLAY() ) ); | |
1261 | } | |
8805e155 | 1262 | #endif |
7d9f12f3 VS |
1263 | } |
1264 | ||
1265 | bool wxTopLevelWindowGTK::IsIconized() const | |
1266 | { | |
1267 | return m_isIconized; | |
1268 | } | |
1269 | ||
1270 | void wxTopLevelWindowGTK::SetIconizeState(bool iconize) | |
1271 | { | |
1272 | if ( iconize != m_isIconized ) | |
1273 | { | |
1274 | m_isIconized = iconize; | |
1275 | (void)SendIconizeEvent(iconize); | |
1276 | } | |
1277 | } | |
1278 | ||
5152b0e5 JS |
1279 | void wxTopLevelWindowGTK::AddGrab() |
1280 | { | |
1281 | if (!m_grabbed) | |
1282 | { | |
0a164d4c | 1283 | m_grabbed = true; |
5152b0e5 | 1284 | gtk_grab_add( m_widget ); |
924b84ab | 1285 | wxEventLoop().Run(); |
5152b0e5 JS |
1286 | gtk_grab_remove( m_widget ); |
1287 | } | |
1288 | } | |
1289 | ||
1290 | void wxTopLevelWindowGTK::RemoveGrab() | |
1291 | { | |
1292 | if (m_grabbed) | |
1293 | { | |
1294 | gtk_main_quit(); | |
0a164d4c | 1295 | m_grabbed = false; |
5152b0e5 JS |
1296 | } |
1297 | } | |
801225c1 | 1298 | |
1542ea39 RD |
1299 | |
1300 | // helper | |
1301 | static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region) | |
1302 | { | |
1303 | if (window) | |
1304 | { | |
1305 | if (region.IsEmpty()) | |
1306 | { | |
1307 | gdk_window_shape_combine_mask(window, NULL, 0, 0); | |
1308 | } | |
1309 | else | |
1310 | { | |
1311 | #ifdef __WXGTK20__ | |
0a164d4c | 1312 | gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0); |
1542ea39 | 1313 | #else |
0a164d4c WS |
1314 | wxBitmap bmp = region.ConvertToBitmap(); |
1315 | bmp.SetMask(new wxMask(bmp, *wxBLACK)); | |
1316 | GdkBitmap* mask = bmp.GetMask()->GetBitmap(); | |
1317 | gdk_window_shape_combine_mask(window, mask, 0, 0); | |
1542ea39 | 1318 | #endif |
0a164d4c | 1319 | return true; |
1542ea39 RD |
1320 | } |
1321 | } | |
0a164d4c | 1322 | return false; |
1542ea39 RD |
1323 | } |
1324 | ||
1325 | ||
1326 | bool wxTopLevelWindowGTK::SetShape(const wxRegion& region) | |
1327 | { | |
0a164d4c | 1328 | wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, |
6a7e6411 RD |
1329 | _T("Shaped windows must be created with the wxFRAME_SHAPED style.")); |
1330 | ||
1542ea39 RD |
1331 | GdkWindow *window = NULL; |
1332 | if (m_wxwindow) | |
1333 | { | |
1334 | window = GTK_PIZZA(m_wxwindow)->bin_window; | |
1335 | do_shape_combine_region(window, region); | |
1336 | } | |
1337 | window = m_widget->window; | |
1338 | return do_shape_combine_region(window, region); | |
1339 | } | |
1340 | ||
6b30a44e | 1341 | bool wxTopLevelWindowGTK::IsActive() |
35ff90a0 | 1342 | { |
06fda9e8 | 1343 | return (this == (wxTopLevelWindowGTK*)g_activeFrame); |
35ff90a0 | 1344 | } |
dca92ddf MR |
1345 | |
1346 | void wxTopLevelWindowGTK::RequestUserAttention(int flags) | |
1347 | { | |
1348 | bool new_hint_value = false; | |
1349 | ||
1350 | // FIXME: This is a workaround to focus handling problem | |
1351 | // If RequestUserAttention is called for example right after a wxSleep, OnInternalIdle hasn't | |
1352 | // yet been processed, and the internal focus system is not up to date yet. | |
1353 | // wxYieldIfNeeded ensures the processing of it, but can have unwanted side effects - MR | |
1354 | ::wxYieldIfNeeded(); | |
1355 | ||
1356 | /*BCI: | |
1357 | if(m_urgency_hint >= 0) | |
1358 | gtk_timeout_remove(m_urgency_hint); | |
1359 | */ | |
1360 | int urgency_hint = GPOINTER_TO_INT( gtk_object_get_data( GTK_OBJECT(m_widget), "m_urgency_hint") ); | |
1361 | if(urgency_hint >= 0) | |
1362 | gtk_timeout_remove(urgency_hint); | |
1363 | //BCI: END | |
1364 | ||
1365 | //BCI: m_urgency_hint = -2; | |
1366 | gtk_object_set_data( GTK_OBJECT(m_widget), "m_urgency_hint", GINT_TO_POINTER(-2)); | |
1367 | ||
1368 | if( GTK_WIDGET_REALIZED(m_widget) && !IsActive() ) | |
1369 | { | |
1370 | new_hint_value = true; | |
1371 | ||
1372 | if (flags & wxUSER_ATTENTION_INFO) | |
1373 | { | |
1374 | //BCI: m_urgency_hint = gtk_timeout_add(5000, (GtkFunction)gtk_frame_urgency_timer_callback, this); | |
1375 | gtk_object_set_data( GTK_OBJECT(m_widget), "m_urgency_hint", | |
1376 | GINT_TO_POINTER( gtk_timeout_add(5000, | |
1377 | (GtkFunction)gtk_frame_urgency_timer_callback, | |
1378 | m_widget) ) ); | |
1379 | } else { | |
1380 | //BCI: m_urgency_hint = -1; | |
1381 | gtk_object_set_data( GTK_OBJECT(m_widget), "m_urgency_hint", GINT_TO_POINTER(-1) ); | |
1382 | } | |
1383 | } | |
1384 | ||
6925aa36 | 1385 | #if defined(__WXGTK20__) && GTK_CHECK_VERSION(2,7,0) |
dca92ddf MR |
1386 | if(!gtk_check_version(2,7,0)) |
1387 | gtk_window_set_urgency_hint(GTK_WINDOW( m_widget ), new_hint_value); | |
1388 | else | |
1389 | #endif | |
1390 | wxgtk_window_set_urgency_hint(GTK_WINDOW( m_widget ), new_hint_value); | |
1391 | } |