]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/toplevel.cpp
making things compile and build again ...
[wxWidgets.git] / src / gtk / toplevel.cpp
CommitLineData
7d9f12f3 1/////////////////////////////////////////////////////////////////////////////
cb8cc250 2// Name: src/gtk/toplevel.cpp
7d9f12f3
VS
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
7d9f12f3
VS
8/////////////////////////////////////////////////////////////////////////////
9
93763ad5
WS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
7d9f12f3
VS
13// ============================================================================
14// declarations
15// ============================================================================
16
17// ----------------------------------------------------------------------------
18// headers
19// ----------------------------------------------------------------------------
20
7d9f12f3
VS
21#ifdef __VMS
22#define XIconifyWindow XICONIFYWINDOW
23#endif
24
e1bf3ad3 25#include "wx/toplevel.h"
e4db172a
WS
26
27#ifndef WX_PRECOMP
d281df50
PC
28 #include "wx/frame.h"
29 #include "wx/icon.h"
e4db172a 30 #include "wx/log.h"
670f9935 31 #include "wx/app.h"
e4db172a
WS
32#endif
33
fab591c5 34#include "wx/gtk/private.h"
924b84ab 35#include "wx/evtloop.h"
a95a6eb4 36#include "wx/sysopt.h"
7d9f12f3 37
7d9f12f3 38#include <gtk/gtk.h>
7d9f12f3
VS
39#include <gdk/gdkx.h>
40
41#include "wx/gtk/win_gtk.h"
42
f618020a
MB
43#include "wx/unix/utilsx11.h"
44
8a9650ea
RR
45// XA_CARDINAL
46#include <X11/Xatom.h>
47
7d9f12f3
VS
48// ----------------------------------------------------------------------------
49// data
50// ----------------------------------------------------------------------------
51
06fda9e8
RR
52extern int g_openDialogs;
53extern wxWindowGTK *g_delayedFocus;
54
55// the frame that is currently active (i.e. its child has focus). It is
56// used to generate wxActivateEvents
57static wxTopLevelWindowGTK *g_activeFrame = (wxTopLevelWindowGTK*) NULL;
58static wxTopLevelWindowGTK *g_lastActiveFrame = (wxTopLevelWindowGTK*) NULL;
59
60// if we detect that the app has got/lost the focus, we set this variable to
61// either TRUE or FALSE and an activate event will be sent during the next
62// OnIdle() call and it is reset to -1: this value means that we shouldn't
63// send any activate events at all
0a164d4c 64static int g_sendActivateEvent = -1;
06fda9e8 65
dca92ddf
MR
66//-----------------------------------------------------------------------------
67// RequestUserAttention related functions
68//-----------------------------------------------------------------------------
69
70extern "C" {
71static void wxgtk_window_set_urgency_hint (GtkWindow *win,
72 gboolean setting)
73{
74 wxASSERT_MSG( GTK_WIDGET_REALIZED(win), wxT("wxgtk_window_set_urgency_hint: GdkWindow not realized") );
75 GdkWindow *window = GTK_WIDGET(win)->window;
76 XWMHints *wm_hints;
77
78 wm_hints = XGetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window));
79
80 if (!wm_hints)
81 wm_hints = XAllocWMHints();
82
83 if (setting)
84 wm_hints->flags |= XUrgencyHint;
85 else
86 wm_hints->flags &= ~XUrgencyHint;
87
88 XSetWMHints(GDK_WINDOW_XDISPLAY(window), GDK_WINDOW_XWINDOW(window), wm_hints);
89 XFree(wm_hints);
90}
91
92ed8bec 92static gboolean gtk_frame_urgency_timer_callback( wxTopLevelWindowGTK *win )
dca92ddf 93{
2ec371fd 94#if GTK_CHECK_VERSION(2,7,0)
dca92ddf 95 if(!gtk_check_version(2,7,0))
ef1a9be4 96 gtk_window_set_urgency_hint(GTK_WINDOW( win->m_widget ), FALSE);
dca92ddf
MR
97 else
98#endif
ef1a9be4 99 wxgtk_window_set_urgency_hint(GTK_WINDOW( win->m_widget ), FALSE);
dca92ddf 100
ef1a9be4 101 win->m_urgency_hint = -2;
dca92ddf
MR
102 return FALSE;
103}
104}
105
06fda9e8
RR
106//-----------------------------------------------------------------------------
107// "focus_in_event"
108//-----------------------------------------------------------------------------
109
865bb325 110extern "C" {
4c20ee63 111static gboolean gtk_frame_focus_in_callback( GtkWidget *widget,
06fda9e8
RR
112 GdkEvent *WXUNUSED(event),
113 wxTopLevelWindowGTK *win )
114{
06fda9e8
RR
115 switch ( g_sendActivateEvent )
116 {
117 case -1:
118 // we've got focus from outside, synthetize wxActivateEvent
119 g_sendActivateEvent = 1;
120 break;
121
122 case 0:
123 // another our window just lost focus, it was already ours before
124 // - don't send any wxActivateEvent
125 g_sendActivateEvent = -1;
126 break;
127 }
128
129 g_activeFrame = win;
130 g_lastActiveFrame = g_activeFrame;
0a164d4c 131
06fda9e8 132 // wxPrintf( wxT("active: %s\n"), win->GetTitle().c_str() );
0a164d4c 133
dca92ddf 134 // MR: wxRequestUserAttention related block
ef1a9be4 135 switch( win->m_urgency_hint )
dca92ddf
MR
136 {
137 default:
92ed8bec 138 g_source_remove( win->m_urgency_hint );
dca92ddf
MR
139 // no break, fallthrough to remove hint too
140 case -1:
2ec371fd 141#if GTK_CHECK_VERSION(2,7,0)
dca92ddf
MR
142 if(!gtk_check_version(2,7,0))
143 gtk_window_set_urgency_hint(GTK_WINDOW( widget ), FALSE);
144 else
145#endif
146 {
147 wxgtk_window_set_urgency_hint(GTK_WINDOW( widget ), FALSE);
148 }
149
ef1a9be4 150 win->m_urgency_hint = -2;
dca92ddf
MR
151 break;
152
153 case -2: break;
154 }
155
06fda9e8 156 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame);
0a164d4c 157 wxActivateEvent event(wxEVT_ACTIVATE, true, g_activeFrame->GetId());
06fda9e8
RR
158 event.SetEventObject(g_activeFrame);
159 g_activeFrame->GetEventHandler()->ProcessEvent(event);
160
4c20ee63 161 return FALSE;
06fda9e8 162}
865bb325 163}
06fda9e8
RR
164
165//-----------------------------------------------------------------------------
166// "focus_out_event"
167//-----------------------------------------------------------------------------
168
865bb325 169extern "C" {
4c20ee63 170static gboolean gtk_frame_focus_out_callback( GtkWidget *widget,
0a164d4c 171 GdkEventFocus *WXUNUSED(gdk_event),
06fda9e8
RR
172 wxTopLevelWindowGTK *win )
173{
06fda9e8
RR
174 // if the focus goes out of our app alltogether, OnIdle() will send
175 // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
176 // g_sendActivateEvent to -1
177 g_sendActivateEvent = 0;
0a164d4c 178
06fda9e8 179 // wxASSERT_MSG( (g_activeFrame == win), wxT("TLW deactivatd although it wasn't active") );
0a164d4c 180
06fda9e8 181 // wxPrintf( wxT("inactive: %s\n"), win->GetTitle().c_str() );
06fda9e8 182
cc0c05cd
JS
183 if (g_activeFrame)
184 {
185 wxLogTrace(wxT("activate"), wxT("Activating frame %p (from focus_in)"), g_activeFrame);
0a164d4c 186 wxActivateEvent event(wxEVT_ACTIVATE, false, g_activeFrame->GetId());
cc0c05cd
JS
187 event.SetEventObject(g_activeFrame);
188 g_activeFrame->GetEventHandler()->ProcessEvent(event);
189
190 g_activeFrame = NULL;
191 }
0a164d4c 192
4c20ee63 193 return FALSE;
06fda9e8 194}
865bb325 195}
7d9f12f3 196
290cd301
PC
197//-----------------------------------------------------------------------------
198
199// Get cached size of WM decorations for given GdkWMDecoration.
200static wxSize& GetDecorSize(int decor)
201{
202 // In testing, only the title bar and GDK_DECOR_BORDER made a difference.
203 // 4 possible combinations of title bar and border
204 static wxSize size[4];
205
206 int index = 0;
207 // title bar
208 if (decor & (GDK_DECOR_MENU | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE | GDK_DECOR_TITLE))
209 index = 1;
210 // border
211 if (decor & GDK_DECOR_BORDER)
212 index |= 2;
213 return size[index];
214}
215
7d9f12f3
VS
216//-----------------------------------------------------------------------------
217// "size_allocate"
218//-----------------------------------------------------------------------------
219
865bb325 220extern "C" {
7d9f12f3
VS
221static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxTopLevelWindowGTK *win )
222{
7d9f12f3
VS
223 if (!win->m_hasVMT)
224 return;
225
290cd301
PC
226 wxSize sizeDecor;
227 if (!win->IsFullScreen())
228 sizeDecor = GetDecorSize(win->m_gdkDecor);
229 const int w = alloc->width + sizeDecor.x;
230 const int h = alloc->height + sizeDecor.y;
231
232 if (win->m_width != w || win->m_height != h)
7d9f12f3 233 {
290cd301
PC
234 win->m_width = w;
235 win->m_height = h;
a6cdd521 236
7d9f12f3
VS
237 win->GtkUpdateSize();
238 }
239}
865bb325 240}
7d9f12f3 241
6e264997
VZ
242// ----------------------------------------------------------------------------
243// "size_request"
244// ----------------------------------------------------------------------------
245
246extern "C" {
290cd301 247static
6e264997
VZ
248void wxgtk_tlw_size_request_callback(GtkWidget * WXUNUSED(widget),
249 GtkRequisition *requisition,
250 wxTopLevelWindowGTK *win)
251{
252 // we must return the size of the window without WM decorations, otherwise
253 // GTK+ gets confused, so don't call just GetSize() here
290cd301 254 win->GTKDoGetSize(&requisition->width, &requisition->height);
6e264997
VZ
255}
256}
290cd301 257
7d9f12f3
VS
258//-----------------------------------------------------------------------------
259// "delete_event"
260//-----------------------------------------------------------------------------
261
865bb325 262extern "C" {
5d4c0833
MR
263static gboolean
264gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget),
265 GdkEvent *WXUNUSED(event),
266 wxTopLevelWindowGTK *win )
7d9f12f3 267{
7d9f12f3 268 if (win->IsEnabled() &&
5152b0e5
JS
269 (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
270 win->IsGrabbed()))
7d9f12f3
VS
271 win->Close();
272
273 return TRUE;
274}
865bb325 275}
7d9f12f3
VS
276
277
278//-----------------------------------------------------------------------------
279// "configure_event"
280//-----------------------------------------------------------------------------
281
865bb325 282extern "C" {
5d4c0833 283static gboolean
dc89b7bf 284gtk_frame_configure_callback( GtkWidget* widget,
5d4c0833
MR
285 GdkEventConfigure *WXUNUSED(event),
286 wxTopLevelWindowGTK *win )
7d9f12f3 287{
48f72114 288 if (!win->m_hasVMT || !win->IsShown())
7d9f12f3
VS
289 return FALSE;
290
dc89b7bf
PC
291 wxPoint point;
292 gtk_window_get_position((GtkWindow*)widget, &point.x, &point.y);
32f2ebbf 293
afde1667
PC
294 win->m_x = point.x;
295 win->m_y = point.y;
296 wxMoveEvent mevent(point, win->GetId());
297 mevent.SetEventObject( win );
298 win->GetEventHandler()->ProcessEvent( mevent );
7d9f12f3
VS
299
300 return FALSE;
301}
865bb325 302}
7d9f12f3
VS
303
304//-----------------------------------------------------------------------------
305// "realize" from m_widget
306//-----------------------------------------------------------------------------
307
e1f14d22
RR
308// we cannot MWM hints and icons before the widget has been realized,
309// so we do this directly after realization
7d9f12f3 310
865bb325 311extern "C" {
7d9f12f3 312static void
6aeb6f2a
VZ
313gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
314 wxTopLevelWindowGTK *win )
7d9f12f3 315{
e1f14d22
RR
316 // All this is for Motif Window Manager "hints" and is supposed to be
317 // recognized by other WM as well. Not tested.
82c9f85c 318 gdk_window_set_decorations(win->m_widget->window,
f819b4a3 319 (GdkWMDecoration)win->m_gdkDecor);
82c9f85c 320 gdk_window_set_functions(win->m_widget->window,
f819b4a3 321 (GdkWMFunction)win->m_gdkFunc);
7d9f12f3 322
e1f14d22 323 // GTK's shrinking/growing policy
f819b4a3 324 if ((win->m_gdkFunc & GDK_FUNC_RESIZE) == 0)
43a52404 325 gtk_window_set_resizable(GTK_WINDOW(win->m_widget), FALSE);
7d9f12f3 326 else
8e729eb4 327 gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1);
7d9f12f3 328
e1f14d22 329 // reset the icon
7efaed4d 330 wxIconBundle iconsOld = win->GetIcons();
5a5cdd31 331 if ( !iconsOld.IsEmpty() )
7d9f12f3 332 {
7d9f12f3 333 win->SetIcon( wxNullIcon );
7efaed4d 334 win->SetIcons( iconsOld );
7d9f12f3 335 }
7d9f12f3 336}
865bb325 337}
7d9f12f3
VS
338
339//-----------------------------------------------------------------------------
340// "map_event" from m_widget
341//-----------------------------------------------------------------------------
342
865bb325 343extern "C" {
0e795b05 344static gboolean
290cd301 345gtk_frame_map_callback( GtkWidget* widget,
7d9f12f3
VS
346 GdkEvent * WXUNUSED(event),
347 wxTopLevelWindow *win )
348{
290cd301
PC
349 // Calculate size of WM decorations.
350 // Done here in case WM does not support the _NET_FRAME_EXTENTS property.
351 if (win->IsDecorCacheable() && !win->IsFullScreen())
352 {
353 GdkRectangle rect;
354 gdk_window_get_frame_extents(widget->window, &rect);
355 int w, h;
356 gdk_drawable_get_size(widget->window, &w, &h);
357 wxSize& decorSize = GetDecorSize(win->m_gdkDecor);
358 const wxSize size = wxSize(rect.width - w, rect.height - h);
359 if (decorSize.x != size.x || decorSize.y != size.y)
360 {
361 // Update window size and frame extents cache
362 win->m_width = rect.width;
363 win->m_height = rect.height;
364 win->GtkUpdateSize();
365 decorSize = size;
366 }
367 }
368
0a164d4c 369 win->SetIconizeState(false);
0e795b05 370 return false;
7d9f12f3 371}
865bb325 372}
7d9f12f3
VS
373
374//-----------------------------------------------------------------------------
375// "unmap_event" from m_widget
376//-----------------------------------------------------------------------------
377
865bb325 378extern "C" {
0e795b05 379static gboolean
7d9f12f3
VS
380gtk_frame_unmap_callback( GtkWidget * WXUNUSED(widget),
381 GdkEvent * WXUNUSED(event),
382 wxTopLevelWindow *win )
383{
cb8cc250 384 win->SetIconizeState(true);
0e795b05 385 return false;
7d9f12f3 386}
865bb325 387}
7d9f12f3 388
290cd301
PC
389//-----------------------------------------------------------------------------
390// "property_notify_event" from m_widget
391//-----------------------------------------------------------------------------
392
393extern "C" {
394static gboolean property_notify_event(
395 GtkWidget*, GdkEventProperty* event, wxTopLevelWindowGTK* win)
396{
397 // Watch for changes to _NET_FRAME_EXTENTS property
398 static GdkAtom property = gdk_atom_intern("_NET_FRAME_EXTENTS", false);
399 if (event->state == GDK_PROPERTY_NEW_VALUE && event->atom == property &&
400 win->IsDecorCacheable() && !win->IsFullScreen())
401 {
402 Atom xproperty;
403#if GTK_CHECK_VERSION(2, 2, 0)
404 if (gtk_check_version(2, 2, 0) == NULL)
405 {
406 xproperty = gdk_x11_atom_to_xatom_for_display(
407 gdk_drawable_get_display(event->window), property);
408 }
409 else
410#endif
411 {
412 xproperty = gdk_x11_atom_to_xatom(property);
413 }
414 Atom type;
415 int format;
416 gulong nitems, bytes_after;
417 long* data = NULL;
418 Status status = XGetWindowProperty(
419 gdk_x11_drawable_get_xdisplay(event->window),
420 gdk_x11_drawable_get_xid(event->window),
421 xproperty,
422 0, 4, false, XA_CARDINAL,
423 &type, &format, &nitems, &bytes_after, (guchar**)&data);
424 if (status == Success && data && nitems == 4)
425 {
426 wxSize& decorSize = GetDecorSize(win->m_gdkDecor);
427 const wxSize size =
428 wxSize(int(data[0] + data[1]), int(data[2] + data[3]));
429 if (decorSize.x != size.x || decorSize.y != size.y)
430 {
431 // Update window size and frame extents cache
432 win->m_width += size.x - decorSize.x;
433 win->m_height += size.y - decorSize.y;
434 if (win->m_width < 0) win->m_width = 0;
435 if (win->m_height < 0) win->m_height = 0;
436 win->GtkUpdateSize();
437 decorSize = size;
438 }
439 }
440 if (data)
441 XFree(data);
442 }
443 return false;
444}
445}
446
7d9f12f3
VS
447// ----------------------------------------------------------------------------
448// wxTopLevelWindowGTK creation
449// ----------------------------------------------------------------------------
450
451void wxTopLevelWindowGTK::Init()
452{
0a164d4c 453 m_sizeSet = false;
7d9f12f3
VS
454 m_miniEdge = 0;
455 m_miniTitle = 0;
456 m_mainWidget = (GtkWidget*) NULL;
0a164d4c
WS
457 m_isIconized = false;
458 m_fsIsShowing = false;
459 m_themeEnabled = true;
f819b4a3 460 m_gdkDecor = m_gdkFunc = 0;
0a164d4c 461 m_grabbed = false;
dca92ddf 462
ef1a9be4 463 m_urgency_hint = -2;
7d9f12f3
VS
464}
465
466bool wxTopLevelWindowGTK::Create( wxWindow *parent,
f819b4a3
VS
467 wxWindowID id,
468 const wxString& title,
469 const wxPoint& pos,
470 const wxSize& sizeOrig,
471 long style,
472 const wxString &name )
7d9f12f3
VS
473{
474 // always create a frame of some reasonable, even if arbitrary, size (at
475 // least for MSW compatibility)
476 wxSize size = sizeOrig;
1111cedc 477 size.x = WidthDefault(size.x);
66202a7e 478 size.y = HeightDefault(size.y);
7d9f12f3
VS
479
480 wxTopLevelWindows.Append( this );
481
7d9f12f3
VS
482 if (!PreCreation( parent, pos, size ) ||
483 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
484 {
485 wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") );
0a164d4c 486 return false;
7d9f12f3
VS
487 }
488
489 m_title = title;
490
63c5efa3
VS
491 // NB: m_widget may be !=NULL if it was created by derived class' Create,
492 // e.g. in wxTaskBarIconAreaGTK
493 if (m_widget == NULL)
494 {
63c5efa3
VS
495 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
496 {
4d8d6490
VS
497 m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
498 // Tell WM that this is a dialog window and make it center
499 // on parent by default (this is what GtkDialog ctor does):
500 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
501 GDK_WINDOW_TYPE_HINT_DIALOG);
502 gtk_window_set_position(GTK_WINDOW(m_widget),
503 GTK_WIN_POS_CENTER_ON_PARENT);
63c5efa3 504 }
4d8d6490
VS
505 else
506 {
37780c64 507 m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
606ce80c 508#if GTK_CHECK_VERSION(2,1,0)
caf3e97f 509 if (!gtk_check_version(2,1,0))
11475235 510 {
caf3e97f
KH
511 if (style & wxFRAME_TOOL_WINDOW)
512 {
513 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
514 GDK_WINDOW_TYPE_HINT_UTILITY);
0a164d4c 515
caf3e97f
KH
516 // On some WMs, like KDE, a TOOL_WINDOW will still show
517 // on the taskbar, but on Gnome a TOOL_WINDOW will not.
0a164d4c 518 // For consistency between WMs and with Windows, we
caf3e97f
KH
519 // should set the NO_TASKBAR flag which will apply
520 // the set_skip_taskbar_hint if it is available,
521 // ensuring no taskbar entry will appear.
522 style |= wxFRAME_NO_TASKBAR;
523 }
11475235 524 }
cf49c955 525#endif
4d8d6490 526 }
63c5efa3 527 }
7d9f12f3 528
e25c7537
VS
529 wxWindow *topParent = wxGetTopLevelParent(m_parent);
530 if (topParent && (((GTK_IS_WINDOW(topParent->m_widget)) &&
0a164d4c
WS
531 (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)) ||
532 (style & wxFRAME_FLOAT_ON_PARENT)))
7cd95599 533 {
e25c7537
VS
534 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
535 GTK_WINDOW(topParent->m_widget) );
7cd95599 536 }
7d9f12f3 537
2be125e6 538#if GTK_CHECK_VERSION(2,2,0)
caf3e97f 539 if (!gtk_check_version(2,2,0))
2be125e6 540 {
caf3e97f
KH
541 if (style & wxFRAME_NO_TASKBAR)
542 {
543 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), TRUE);
544 }
2be125e6
VS
545 }
546#endif
547
015dca24 548#ifdef __WXGTK24__
81a3313a 549 if (!gtk_check_version(2,4,0))
2fca39c9 550 {
81a3313a
RR
551 if (style & wxSTAY_ON_TOP)
552 {
553 gtk_window_set_keep_above(GTK_WINDOW(m_widget), TRUE);
554 }
2fca39c9
KH
555 }
556#endif
557
5503a51c 558#if 0
0a164d4c 559 if (!name.empty())
5503a51c
MR
560 gtk_window_set_role( GTK_WINDOW(m_widget), wxGTK_CONV( name ) );
561#endif
7d9f12f3 562
fab591c5 563 gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) );
7d9f12f3
VS
564 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
565
9fa72bd2
MR
566 g_signal_connect (m_widget, "delete_event",
567 G_CALLBACK (gtk_frame_delete_callback), this);
7d9f12f3 568
e1f14d22 569 // m_mainWidget holds the toolbar, the menubar and the client area
7d9f12f3
VS
570 m_mainWidget = gtk_pizza_new();
571 gtk_widget_show( m_mainWidget );
572 GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS );
573 gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget );
574
e1f14d22 575 // m_wxwindow only represents the client area without toolbar and menubar
7d9f12f3
VS
576 m_wxwindow = gtk_pizza_new();
577 gtk_widget_show( m_wxwindow );
578 gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
579
e1f14d22
RR
580 // we donm't allow the frame to get the focus as otherwise
581 // the frame will grab it at arbitrary focus changes
7d9f12f3
VS
582 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
583
584 if (m_parent) m_parent->AddChild( this );
585
e1f14d22 586 // the user resized the frame by dragging etc.
9fa72bd2
MR
587 g_signal_connect (m_widget, "size_allocate",
588 G_CALLBACK (gtk_frame_size_callback), this);
7d9f12f3 589
6e264997
VZ
590 g_signal_connect (m_widget, "size_request",
591 G_CALLBACK (wxgtk_tlw_size_request_callback), this);
7d9f12f3
VS
592 PostCreation();
593
594 if ((m_x != -1) || (m_y != -1))
595 gtk_widget_set_uposition( m_widget, m_x, m_y );
6aeb6f2a 596
e1f14d22
RR
597 // we cannot set MWM hints and icons before the widget has
598 // been realized, so we do this directly after realization
9fa72bd2
MR
599 g_signal_connect (m_widget, "realize",
600 G_CALLBACK (gtk_frame_realized_callback), this);
7d9f12f3 601
e1f14d22 602 // map and unmap for iconized state
9fa72bd2
MR
603 g_signal_connect (m_widget, "map_event",
604 G_CALLBACK (gtk_frame_map_callback), this);
605 g_signal_connect (m_widget, "unmap_event",
606 G_CALLBACK (gtk_frame_unmap_callback), this);
7d9f12f3 607
dc89b7bf 608 // for wxMoveEvent
9fa72bd2
MR
609 g_signal_connect (m_widget, "configure_event",
610 G_CALLBACK (gtk_frame_configure_callback), this);
7d9f12f3 611
06fda9e8 612 // activation
4c20ee63 613 g_signal_connect_after (m_widget, "focus_in_event",
9fa72bd2 614 G_CALLBACK (gtk_frame_focus_in_callback), this);
4c20ee63 615 g_signal_connect_after (m_widget, "focus_out_event",
9fa72bd2 616 G_CALLBACK (gtk_frame_focus_out_callback), this);
0a164d4c 617
290cd301
PC
618 gtk_widget_add_events(m_widget, GDK_PROPERTY_CHANGE_MASK);
619 g_signal_connect(m_widget, "property_notify_event",
620 G_CALLBACK(property_notify_event), this);
621
e1f14d22 622 // decorations
85a0a12a 623 if ((style & wxSIMPLE_BORDER) || (style & wxNO_BORDER))
f819b4a3
VS
624 {
625 m_gdkDecor = 0;
626 m_gdkFunc = 0;
627 }
628 else
85a0a12a
RR
629 if (m_miniEdge > 0)
630 {
631 m_gdkDecor = 0;
632 m_gdkFunc = 0;
a6cdd521 633
85a0a12a
RR
634 if ((style & wxRESIZE_BORDER) != 0)
635 m_gdkFunc |= GDK_FUNC_RESIZE;
636 }
637 else
f819b4a3 638 {
290cd301
PC
639 m_gdkDecor = GDK_DECOR_BORDER;
640 m_gdkFunc = GDK_FUNC_MOVE;
82c9f85c 641
f819b4a3 642 // All this is for Motif Window Manager "hints" and is supposed to be
e1f14d22 643 // recognized by other WMs as well.
f819b4a3 644 if ((style & wxCAPTION) != 0)
c3d8ee42 645 {
f819b4a3 646 m_gdkDecor |= GDK_DECOR_TITLE;
c3d8ee42 647 }
850c6ed4 648 if ((style & wxCLOSE_BOX) != 0)
f819b4a3
VS
649 {
650 m_gdkFunc |= GDK_FUNC_CLOSE;
c3d8ee42
VS
651 }
652 if ((style & wxSYSTEM_MENU) != 0)
653 {
f819b4a3
VS
654 m_gdkDecor |= GDK_DECOR_MENU;
655 }
656 if ((style & wxMINIMIZE_BOX) != 0)
657 {
658 m_gdkFunc |= GDK_FUNC_MINIMIZE;
659 m_gdkDecor |= GDK_DECOR_MINIMIZE;
660 }
661 if ((style & wxMAXIMIZE_BOX) != 0)
662 {
663 m_gdkFunc |= GDK_FUNC_MAXIMIZE;
664 m_gdkDecor |= GDK_DECOR_MAXIMIZE;
665 }
666 if ((style & wxRESIZE_BORDER) != 0)
667 {
668 m_gdkFunc |= GDK_FUNC_RESIZE;
669 m_gdkDecor |= GDK_DECOR_RESIZEH;
670 }
671 }
672
290cd301
PC
673 // m_gdkDecor needs to be set before calling GTKDoGetSize
674 int w, h;
675 GTKDoGetSize(&w, &h);
676 gtk_window_set_default_size(GTK_WINDOW(m_widget), w, h);
677
0a164d4c 678 return true;
7d9f12f3
VS
679}
680
681wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
682{
5152b0e5
JS
683 if (m_grabbed)
684 {
4362c705 685 wxFAIL_MSG(_T("Window still grabbed"));
5152b0e5
JS
686 RemoveGrab();
687 }
1cbee0b4 688
0a164d4c 689 m_isBeingDeleted = true;
6aeb6f2a 690
710968c3
VZ
691 // it may also be GtkScrolledWindow in the case of an MDI child
692 if (GTK_IS_WINDOW(m_widget))
693 {
694 gtk_window_set_focus( GTK_WINDOW(m_widget), NULL );
695 }
0a164d4c 696
06fda9e8
RR
697 if (g_activeFrame == this)
698 g_activeFrame = NULL;
699 if (g_lastActiveFrame == this)
700 g_lastActiveFrame = NULL;
7d9f12f3
VS
701}
702
0d635035
RR
703bool wxTopLevelWindowGTK::EnableCloseButton( bool enable )
704{
705 if (enable)
706 m_gdkFunc |= GDK_FUNC_CLOSE;
707 else
708 m_gdkFunc &= ~GDK_FUNC_CLOSE;
a6cdd521 709
0d635035
RR
710 if (GTK_WIDGET_REALIZED(m_widget) && (m_widget->window))
711 gdk_window_set_functions( m_widget->window, (GdkWMFunction)m_gdkFunc );
a6cdd521 712
0d635035
RR
713 return true;
714}
8a9650ea 715
1529bc41 716bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long)
7d9f12f3 717{
8a8997c3 718 if (show == m_fsIsShowing)
0a164d4c 719 return false; // return what?
7d9f12f3
VS
720
721 m_fsIsShowing = show;
0a164d4c 722
1542ea39 723 wxX11FullScreenMethod method =
8166ab43
VS
724 wxGetFullScreenMethodX11((WXDisplay*)GDK_DISPLAY(),
725 (WXWindow)GDK_ROOT_WINDOW());
1542ea39 726
feb1c9fb
VS
727#if GTK_CHECK_VERSION(2,2,0)
728 // NB: gtk_window_fullscreen() uses freedesktop.org's WMspec extensions
729 // to switch to fullscreen, which is not always available. We must
730 // check if WM supports the spec and use legacy methods if it
731 // doesn't.
cc35003a 732 if ( (method == wxX11_FS_WMSPEC) && !gtk_check_version(2,2,0) )
7d9f12f3 733 {
feb1c9fb
VS
734 if (show)
735 gtk_window_fullscreen( GTK_WINDOW( m_widget ) );
736 else
737 gtk_window_unfullscreen( GTK_WINDOW( m_widget ) );
7d9f12f3
VS
738 }
739 else
8a8997c3 740#endif // GTK+ >= 2.2.0
7d9f12f3 741 {
feb1c9fb
VS
742 GdkWindow *window = m_widget->window;
743
744 if (show)
8166ab43 745 {
feb1c9fb
VS
746 GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y );
747 GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height );
748
749 int screen_width,screen_height;
750 wxDisplaySize( &screen_width, &screen_height );
751
752 gint client_x, client_y, root_x, root_y;
753 gint width, height;
754
755 if (method != wxX11_FS_WMSPEC)
756 {
757 // don't do it always, Metacity hates it
758 m_fsSaveGdkFunc = m_gdkFunc;
759 m_fsSaveGdkDecor = m_gdkDecor;
760 m_gdkFunc = m_gdkDecor = 0;
761 gdk_window_set_decorations(window, (GdkWMDecoration)0);
762 gdk_window_set_functions(window, (GdkWMFunction)0);
763 }
764
765 gdk_window_get_origin (m_widget->window, &root_x, &root_y);
766 gdk_window_get_geometry (m_widget->window, &client_x, &client_y,
767 &width, &height, NULL);
768
769 gdk_window_move_resize (m_widget->window, -client_x, -client_y,
770 screen_width + 1, screen_height + 1);
771
772 wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(),
773 (WXWindow)GDK_ROOT_WINDOW(),
774 (WXWindow)GDK_WINDOW_XWINDOW(window),
775 show, &m_fsSaveFrame, method);
776 }
3b2931fb 777 else // hide
feb1c9fb
VS
778 {
779 if (method != wxX11_FS_WMSPEC)
780 {
781 // don't do it always, Metacity hates it
782 m_gdkFunc = m_fsSaveGdkFunc;
783 m_gdkDecor = m_fsSaveGdkDecor;
784 gdk_window_set_decorations(window, (GdkWMDecoration)m_gdkDecor);
785 gdk_window_set_functions(window, (GdkWMFunction)m_gdkFunc);
786 }
787
788 wxSetFullScreenStateX11((WXDisplay*)GDK_DISPLAY(),
789 (WXWindow)GDK_ROOT_WINDOW(),
790 (WXWindow)GDK_WINDOW_XWINDOW(window),
791 show, &m_fsSaveFrame, method);
792
793 SetSize(m_fsSaveFrame.x, m_fsSaveFrame.y,
794 m_fsSaveFrame.width, m_fsSaveFrame.height);
8166ab43 795 }
7d9f12f3 796 }
8166ab43 797
3b2931fb
VZ
798 // documented behaviour is to show the window if it's still hidden when
799 // showing it full screen
1529bc41 800 if (show)
3b2931fb
VZ
801 Show();
802
0a164d4c 803 return true;
7d9f12f3
VS
804}
805
806// ----------------------------------------------------------------------------
807// overridden wxWindow methods
808// ----------------------------------------------------------------------------
809
810bool wxTopLevelWindowGTK::Show( bool show )
811{
82b978d7 812 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
7d9f12f3 813
416d721d 814 if (show == IsShown())
3c95c710 815 return false;
416d721d 816
aa34396c 817 if (show && !m_sizeSet)
7d9f12f3
VS
818 {
819 /* by calling GtkOnSize here, we don't have to call
820 either after showing the frame, which would entail
821 much ugly flicker or from within the size_allocate
822 handler, because GTK 1.1.X forbids that. */
823
b5e31cc8 824 GtkOnSize();
7d9f12f3 825 }
0a164d4c 826
aa34396c
PC
827 wxTopLevelWindowBase::Show(show);
828
829 if (!show)
830 {
831 // make sure window has a non-default position, so when it is shown
832 // again, it won't be repositioned by WM as if it were a new window
833 // Note that this must be done _after_ the window is hidden.
834 gtk_window_move((GtkWindow*)m_widget, m_x, m_y);
835 }
836
837 return true;
7d9f12f3
VS
838}
839
a2ac55f5
RR
840void wxTopLevelWindowGTK::Raise()
841{
a2ac55f5 842 gtk_window_present( GTK_WINDOW( m_widget ) );
a2ac55f5
RR
843}
844
7d9f12f3
VS
845void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
846{
847 wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") );
848}
849
a6cdd521
VZ
850// ----------------------------------------------------------------------------
851// window geometry
852// ----------------------------------------------------------------------------
853
6e264997
VZ
854void wxTopLevelWindowGTK::GTKDoGetSize(int *width, int *height) const
855{
290cd301
PC
856 wxSize size(m_width, m_height);
857 if (!IsFullScreen())
a6cdd521 858 {
290cd301
PC
859 size -= GetDecorSize(m_gdkDecor);
860 if (size.x < 0) size.x = 0;
861 if (size.y < 0) size.y = 0;
a6cdd521 862 }
290cd301
PC
863 if (width) *width = size.x;
864 if (height) *height = size.y;
a6cdd521
VZ
865}
866
7d9f12f3
VS
867void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
868{
a6cdd521 869 wxCHECK_RET( m_widget, wxT("invalid frame") );
82b978d7 870
e1f14d22 871 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
7d9f12f3
VS
872 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
873
7d9f12f3 874
a6cdd521 875 // deal with the position first
7d9f12f3
VS
876 int old_x = m_x;
877 int old_y = m_y;
878
a6cdd521 879 if ( !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
7d9f12f3 880 {
a6cdd521
VZ
881 // -1 means "use existing" unless the flag above is specified
882 if ( x != -1 )
883 m_x = x;
884 if ( y != -1 )
885 m_y = y;
7d9f12f3 886 }
a6cdd521 887 else // wxSIZE_ALLOW_MINUS_ONE
7d9f12f3
VS
888 {
889 m_x = x;
890 m_y = y;
7d9f12f3 891 }
7d9f12f3 892
a6cdd521 893 if ( m_x != old_x || m_y != old_y )
7d9f12f3 894 {
a6cdd521 895 gtk_window_move( GTK_WINDOW(m_widget), m_x, m_y );
7d9f12f3 896 }
7d9f12f3 897
290cd301 898 m_resizing = true;
e7dda1ff 899
290cd301
PC
900 const wxSize oldSize(m_width, m_height);
901 if (width >= 0)
902 m_width = width;
903 if (height >= 0)
904 m_height = height;
905 ConstrainSize();
906 if (m_width != oldSize.x || m_height != oldSize.y)
a6cdd521 907 {
290cd301
PC
908 int w, h;
909 GTKDoGetSize(&w, &h);
910 gtk_window_resize(GTK_WINDOW(m_widget), w, h);
911 GtkUpdateSize();
7d9f12f3 912 }
290cd301 913 m_resizing = false;
7d9f12f3
VS
914}
915
916void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const
917{
bb596005
VZ
918 if ( IsIconized() )
919 {
920 // for consistency with wxMSW, client area is supposed to be empty for
921 // the iconized windows
922 if ( width )
923 *width = 0;
924 if ( height )
925 *height = 0;
926
927 return;
928 }
929
82b978d7
RD
930 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
931
290cd301
PC
932 int w, h;
933 GTKDoGetSize(&w, &h);
7d9f12f3
VS
934 if (width)
935 {
290cd301 936 *width = w - 2 * m_miniEdge;
69346023
PC
937 if (*width < 0)
938 *width = 0;
7d9f12f3 939 }
290cd301
PC
940 if (height)
941 {
942 *height = h - 2 * m_miniEdge - m_miniTitle;
943 if (*height < 0)
944 *height = 0;
945 }
7d9f12f3
VS
946}
947
9379c0d7
RR
948void wxTopLevelWindowGTK::DoSetSizeHints( int minW, int minH,
949 int maxW, int maxH,
950 int incW, int incH )
7d9f12f3 951{
9379c0d7 952 wxTopLevelWindowBase::DoSetSizeHints( minW, minH, maxW, maxH, incW, incH );
d6c11fa9
PC
953
954 const wxSize minSize = GetMinSize();
955 const wxSize maxSize = GetMaxSize();
956 GdkGeometry hints;
957 int hints_mask = 0;
290cd301 958 const wxSize sizeDecor = GetDecorSize(m_gdkDecor);
d6c11fa9
PC
959 if (minSize.x > 0 || minSize.y > 0)
960 {
961 hints_mask |= GDK_HINT_MIN_SIZE;
290cd301
PC
962 hints.min_width = minSize.x - sizeDecor.x;
963 if (hints.min_width < 0)
964 hints.min_width = 0;
965 hints.min_height = minSize.y - sizeDecor.y;
966 if (hints.min_height < 0)
967 hints.min_height = 0;
d6c11fa9
PC
968 }
969 if (maxSize.x > 0 || maxSize.y > 0)
970 {
971 hints_mask |= GDK_HINT_MAX_SIZE;
290cd301
PC
972 hints.max_width = maxSize.x - sizeDecor.x;
973 if (hints.max_width < 0)
974 hints.max_width = INT_MAX;
975 hints.max_height = maxSize.y - sizeDecor.y;
976 if (hints.max_height < 0)
977 hints.max_height = INT_MAX;
d6c11fa9
PC
978 }
979 if (incW > 0 || incH > 0)
7d9f12f3 980 {
d6c11fa9
PC
981 hints_mask |= GDK_HINT_RESIZE_INC;
982 hints.width_inc = incW > 0 ? incW : 1;
983 hints.height_inc = incH > 0 ? incH : 1;
9379c0d7 984 }
d6c11fa9
PC
985 gtk_window_set_geometry_hints(
986 (GtkWindow*)m_widget, NULL, &hints, (GdkWindowHints)hints_mask);
9379c0d7 987}
7d9f12f3 988
9379c0d7
RR
989void wxTopLevelWindowGTK::GtkOnSize()
990{
991 // avoid recursions
992 if (m_resizing) return;
993 m_resizing = true;
994
995 if ( m_wxwindow == NULL ) return;
996
82008f15 997 ConstrainSize();
9379c0d7
RR
998
999 if (m_mainWidget)
1000 {
290cd301
PC
1001 int w, h;
1002 GTKDoGetSize(&w, &h);
7d9f12f3
VS
1003 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
1004 m_wxwindow,
290cd301 1005 0, 0, w, h);
7d9f12f3
VS
1006 }
1007
0a164d4c 1008 m_sizeSet = true;
7d9f12f3
VS
1009
1010 // send size event to frame
1011 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
1012 event.SetEventObject( this );
1013 GetEventHandler()->ProcessEvent( event );
1014
0a164d4c 1015 m_resizing = false;
7d9f12f3
VS
1016}
1017
290cd301
PC
1018bool wxTopLevelWindowGTK::IsDecorCacheable() const
1019{
1020 return true;
1021}
1022
7d9f12f3
VS
1023void wxTopLevelWindowGTK::OnInternalIdle()
1024{
1025 if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow))
1026 {
b5e31cc8 1027 GtkOnSize();
7d9f12f3
VS
1028
1029 // we'll come back later
7d9f12f3
VS
1030 return;
1031 }
1032
6aeb6f2a
VZ
1033 // set the focus if not done yet and if we can already do it
1034 if ( GTK_WIDGET_REALIZED(m_wxwindow) )
1035 {
cc06fe74
MB
1036 if ( g_delayedFocus &&
1037 wxGetTopLevelParent((wxWindow*)g_delayedFocus) == this )
6aeb6f2a 1038 {
2b5f62a0
VZ
1039 wxLogTrace(_T("focus"),
1040 _T("Setting focus from wxTLW::OnIdle() to %s(%s)"),
1041 g_delayedFocus->GetClassInfo()->GetClassName(),
1042 g_delayedFocus->GetLabel().c_str());
1043
6aeb6f2a
VZ
1044 g_delayedFocus->SetFocus();
1045 g_delayedFocus = NULL;
1046 }
1047 }
1048
7d9f12f3 1049 wxWindow::OnInternalIdle();
0a164d4c 1050
06fda9e8
RR
1051 // Synthetize activate events.
1052 if ( g_sendActivateEvent != -1 )
1053 {
1054 bool activate = g_sendActivateEvent != 0;
0a164d4c 1055
576f7127
RR
1056 // if (!activate) wxPrintf( wxT("de") );
1057 // wxPrintf( wxT("activate\n") );
0a164d4c 1058
06fda9e8
RR
1059 // do it only once
1060 g_sendActivateEvent = -1;
1061
1062 wxTheApp->SetActive(activate, (wxWindow *)g_lastActiveFrame);
1063 }
7d9f12f3
VS
1064}
1065
7d9f12f3
VS
1066// ----------------------------------------------------------------------------
1067// frame title/icon
1068// ----------------------------------------------------------------------------
1069
1070void wxTopLevelWindowGTK::SetTitle( const wxString &title )
1071{
82b978d7
RD
1072 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
1073
cb8cc250
WS
1074 if ( title == m_title )
1075 return;
1076
7d9f12f3 1077 m_title = title;
cb8cc250 1078
fab591c5 1079 gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) );
7d9f12f3
VS
1080}
1081
f618020a
MB
1082void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
1083{
82b978d7 1084 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
f618020a
MB
1085
1086 wxTopLevelWindowBase::SetIcons( icons );
1087
87e53e2a 1088 GList *list = NULL;
87e53e2a 1089
52734360
VZ
1090 const size_t numIcons = icons.GetIconCount();
1091 for ( size_t i = 0; i < numIcons; i++ )
52d6235d 1092 {
52734360 1093 list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf());
87e53e2a 1094 }
52734360 1095
87e53e2a
VS
1096 gtk_window_set_icon_list(GTK_WINDOW(m_widget), list);
1097 g_list_free(list);
f618020a
MB
1098}
1099
7d9f12f3
VS
1100// ----------------------------------------------------------------------------
1101// frame state: maximized/iconized/normal
1102// ----------------------------------------------------------------------------
1103
8805e155 1104void wxTopLevelWindowGTK::Maximize(bool maximize)
7d9f12f3 1105{
8805e155
RR
1106 if (maximize)
1107 gtk_window_maximize( GTK_WINDOW( m_widget ) );
1108 else
1109 gtk_window_unmaximize( GTK_WINDOW( m_widget ) );
7d9f12f3
VS
1110}
1111
1112bool wxTopLevelWindowGTK::IsMaximized() const
1113{
d8e1fe80
VS
1114 if(!m_widget->window)
1115 return false;
1116
1117 return gdk_window_get_state(m_widget->window) & GDK_WINDOW_STATE_MAXIMIZED;
7d9f12f3
VS
1118}
1119
1120void wxTopLevelWindowGTK::Restore()
1121{
8805e155
RR
1122 // "Present" seems similar enough to "restore"
1123 gtk_window_present( GTK_WINDOW( m_widget ) );
7d9f12f3
VS
1124}
1125
1126void wxTopLevelWindowGTK::Iconize( bool iconize )
1127{
8805e155
RR
1128 if (iconize)
1129 gtk_window_iconify( GTK_WINDOW( m_widget ) );
1130 else
1131 gtk_window_deiconify( GTK_WINDOW( m_widget ) );
7d9f12f3
VS
1132}
1133
1134bool wxTopLevelWindowGTK::IsIconized() const
1135{
1136 return m_isIconized;
1137}
1138
1139void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
1140{
1141 if ( iconize != m_isIconized )
1142 {
1143 m_isIconized = iconize;
1144 (void)SendIconizeEvent(iconize);
1145 }
1146}
1147
5152b0e5
JS
1148void wxTopLevelWindowGTK::AddGrab()
1149{
1150 if (!m_grabbed)
1151 {
0a164d4c 1152 m_grabbed = true;
5152b0e5 1153 gtk_grab_add( m_widget );
b46b1d59 1154 wxGUIEventLoop().Run();
5152b0e5
JS
1155 gtk_grab_remove( m_widget );
1156 }
1157}
1158
1159void wxTopLevelWindowGTK::RemoveGrab()
1160{
1161 if (m_grabbed)
1162 {
1163 gtk_main_quit();
0a164d4c 1164 m_grabbed = false;
5152b0e5
JS
1165 }
1166}
801225c1 1167
1542ea39
RD
1168
1169// helper
1170static bool do_shape_combine_region(GdkWindow* window, const wxRegion& region)
1171{
1172 if (window)
1173 {
1174 if (region.IsEmpty())
1175 {
1176 gdk_window_shape_combine_mask(window, NULL, 0, 0);
1177 }
1178 else
1179 {
0a164d4c 1180 gdk_window_shape_combine_region(window, region.GetRegion(), 0, 0);
0a164d4c 1181 return true;
1542ea39
RD
1182 }
1183 }
0a164d4c 1184 return false;
1542ea39
RD
1185}
1186
1187
1188bool wxTopLevelWindowGTK::SetShape(const wxRegion& region)
1189{
0a164d4c 1190 wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false,
6a7e6411
RD
1191 _T("Shaped windows must be created with the wxFRAME_SHAPED style."));
1192
1542ea39
RD
1193 GdkWindow *window = NULL;
1194 if (m_wxwindow)
1195 {
1196 window = GTK_PIZZA(m_wxwindow)->bin_window;
1197 do_shape_combine_region(window, region);
1198 }
1199 window = m_widget->window;
1200 return do_shape_combine_region(window, region);
1201}
1202
6b30a44e 1203bool wxTopLevelWindowGTK::IsActive()
35ff90a0 1204{
06fda9e8 1205 return (this == (wxTopLevelWindowGTK*)g_activeFrame);
35ff90a0 1206}
dca92ddf
MR
1207
1208void wxTopLevelWindowGTK::RequestUserAttention(int flags)
1209{
1210 bool new_hint_value = false;
1211
1212 // FIXME: This is a workaround to focus handling problem
1213 // If RequestUserAttention is called for example right after a wxSleep, OnInternalIdle hasn't
1214 // yet been processed, and the internal focus system is not up to date yet.
1215 // wxYieldIfNeeded ensures the processing of it, but can have unwanted side effects - MR
1216 ::wxYieldIfNeeded();
1217
dca92ddf 1218 if(m_urgency_hint >= 0)
92ed8bec 1219 g_source_remove(m_urgency_hint);
dca92ddf 1220
ef1a9be4 1221 m_urgency_hint = -2;
dca92ddf
MR
1222
1223 if( GTK_WIDGET_REALIZED(m_widget) && !IsActive() )
1224 {
1225 new_hint_value = true;
1226
1227 if (flags & wxUSER_ATTENTION_INFO)
1228 {
92ed8bec 1229 m_urgency_hint = g_timeout_add(5000, (GSourceFunc)gtk_frame_urgency_timer_callback, this);
dca92ddf 1230 } else {
ef1a9be4 1231 m_urgency_hint = -1;
dca92ddf
MR
1232 }
1233 }
1234
2ec371fd 1235#if GTK_CHECK_VERSION(2,7,0)
dca92ddf
MR
1236 if(!gtk_check_version(2,7,0))
1237 gtk_window_set_urgency_hint(GTK_WINDOW( m_widget ), new_hint_value);
1238 else
1239#endif
1240 wxgtk_window_set_urgency_hint(GTK_WINDOW( m_widget ), new_hint_value);
1241}
015dca24
MR
1242
1243void wxTopLevelWindowGTK::SetWindowStyleFlag( long style )
1244{
7e3edf92 1245#if defined(__WXGTK24__) || GTK_CHECK_VERSION(2,2,0)
015dca24
MR
1246 // Store which styles were changed
1247 long styleChanges = style ^ m_windowStyle;
7e3edf92 1248#endif
015dca24
MR
1249
1250 // Process wxWindow styles. This also updates the internal variable
1251 // Therefore m_windowStyle bits carry now the _new_ style values
1252 wxWindow::SetWindowStyleFlag(style);
1253
1254 // just return for now if widget does not exist yet
1255 if (!m_widget)
1256 return;
1257
1258#ifdef __WXGTK24__
1259 if ( (styleChanges & wxSTAY_ON_TOP) && !gtk_check_version(2,4,0) )
1260 gtk_window_set_keep_above(GTK_WINDOW(m_widget), m_windowStyle & wxSTAY_ON_TOP);
defdd888 1261#endif // GTK+ 2.4
8fb82418
MR
1262#if GTK_CHECK_VERSION(2,2,0)
1263 if ( (styleChanges & wxFRAME_NO_TASKBAR) && !gtk_check_version(2,2,0) )
1264 {
1265 gtk_window_set_skip_taskbar_hint(GTK_WINDOW(m_widget), m_windowStyle & wxFRAME_NO_TASKBAR);
1266 }
defdd888 1267#endif // GTK+ 2.2
015dca24 1268}
07e49707 1269
07e49707
MR
1270/* Get the X Window between child and the root window.
1271 This should usually be the WM managed XID */
1272static Window wxGetTopmostWindowX11(Display *dpy, Window child)
1273{
1274 Window root, parent;
1275 Window* children;
1276 unsigned int nchildren;
1277
1278 XQueryTree(dpy, child, &root, &parent, &children, &nchildren);
1279 XFree(children);
1280
1281 while (parent != root) {
1282 child = parent;
1283 XQueryTree(dpy, child, &root, &parent, &children, &nchildren);
1284 XFree(children);
1285 }
1286
1287 return child;
1288}
1289
1290bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha)
1291{
3eecbda8 1292 if (!m_widget || !m_widget->window)
07e49707
MR
1293 return false;
1294
1295 Display* dpy = GDK_WINDOW_XDISPLAY (m_widget->window);
1296 // We need to get the X Window that has the root window as the immediate parent
1297 // and m_widget->window as a child. This should be the X Window that the WM manages and
1298 // from which the opacity property is checked from.
1299 Window win = wxGetTopmostWindowX11(dpy, GDK_WINDOW_XID (m_widget->window));
1300
07e49707
MR
1301
1302 // Using pure Xlib to not have a GTK version check mess due to gtk2.0 not having GdkDisplay
1303 if (alpha == 0xff)
1304 XDeleteProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False));
1305 else
d48687a0
PC
1306 {
1307 long opacity = alpha * 0x1010101L;
07e49707
MR
1308 XChangeProperty(dpy, win, XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False),
1309 XA_CARDINAL, 32, PropModeReplace,
1310 (unsigned char *) &opacity, 1L);
d48687a0 1311 }
07e49707
MR
1312 XSync(dpy, False);
1313 return true;
1314}
1315
1316bool wxTopLevelWindowGTK::CanSetTransparent()
1317{
a95a6eb4
VZ
1318 // allow to override automatic detection as it's far from perfect
1319 static const wxChar *SYSOPT_TRANSPARENT = wxT("gtk.tlw.can-set-transparent");
1320 if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT) )
1321 {
1322 return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT) != 0;
1323 }
1324
60169b7a
MR
1325#if GTK_CHECK_VERSION(2,10,0)
1326 if (!gtk_check_version(2,10,0))
1327 {
0b241226 1328 return (gtk_widget_is_composited (m_widget));
60169b7a
MR
1329 }
1330 else
1331#endif // In case of lower versions than gtk+-2.10.0 we could look for _NET_WM_CM_Sn ourselves
1332 {
1333 return false;
1334 }
1335
1336#if 0 // Don't be optimistic here for the sake of wxAUI
07e49707
MR
1337 int opcode, event, error;
1338 // Check for the existence of a RGBA visual instead?
1339 return XQueryExtension(gdk_x11_get_default_xdisplay (),
1340 "Composite", &opcode, &event, &error);
60169b7a 1341#endif
07e49707 1342}