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