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