]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/toplevel.cpp
Added DoSetSize and DoMoveWindow to generic wxStaticLine.
[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 #ifdef __GNUG__
19 #pragma implementation "toplevel.h"
20 #endif
21
22 #ifdef __VMS
23 #define XIconifyWindow XICONIFYWINDOW
24 #endif
25
26 #include "wx/defs.h"
27
28 #include "wx/dialog.h"
29 #include "wx/control.h"
30 #include "wx/app.h"
31 #include "wx/dcclient.h"
32
33 #include <glib.h>
34 #include <gdk/gdk.h>
35 #include <gtk/gtk.h>
36 #include <gdk/gdkkeysyms.h>
37 #include <gdk/gdkx.h>
38
39 #include "wx/gtk/win_gtk.h"
40
41 #include "wx/unix/utilsx11.h"
42
43 // ----------------------------------------------------------------------------
44 // idle system
45 // ----------------------------------------------------------------------------
46
47 extern void wxapp_install_idle_handler();
48 extern bool g_isIdle;
49
50 // ----------------------------------------------------------------------------
51 // data
52 // ----------------------------------------------------------------------------
53
54 extern wxList wxPendingDelete;
55
56 extern int g_openDialogs;
57 extern wxWindowGTK *g_delayedFocus;
58
59 //-----------------------------------------------------------------------------
60 // "focus" from m_window
61 //-----------------------------------------------------------------------------
62
63 static gint gtk_frame_focus_callback( GtkWidget *widget, GtkDirectionType WXUNUSED(d), wxWindow *WXUNUSED(win) )
64 {
65 if (g_isIdle)
66 wxapp_install_idle_handler();
67
68 // This disables GTK's tab traversal
69 gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus" );
70 return TRUE;
71 }
72
73 //-----------------------------------------------------------------------------
74 // "size_allocate"
75 //-----------------------------------------------------------------------------
76
77 static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxTopLevelWindowGTK *win )
78 {
79 if (g_isIdle)
80 wxapp_install_idle_handler();
81
82 if (!win->m_hasVMT)
83 return;
84
85 if ((win->m_width != alloc->width) || (win->m_height != alloc->height))
86 {
87 /*
88 wxPrintf( "OnSize from " );
89 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
90 wxPrintf( win->GetClassInfo()->GetClassName() );
91 wxPrintf( " %d %d %d %d\n", (int)alloc->x,
92 (int)alloc->y,
93 (int)alloc->width,
94 (int)alloc->height );
95 */
96
97 win->m_width = alloc->width;
98 win->m_height = alloc->height;
99 win->m_queuedFullRedraw = TRUE;
100 win->GtkUpdateSize();
101 }
102 }
103
104 //-----------------------------------------------------------------------------
105 // "delete_event"
106 //-----------------------------------------------------------------------------
107
108 static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxTopLevelWindowGTK *win )
109 {
110 if (g_isIdle)
111 wxapp_install_idle_handler();
112
113 if (win->IsEnabled() &&
114 (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
115 win->IsGrabbed()))
116 win->Close();
117
118 return TRUE;
119 }
120
121
122 //-----------------------------------------------------------------------------
123 // "configure_event"
124 //-----------------------------------------------------------------------------
125
126 static gint
127 gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxTopLevelWindowGTK *win )
128 {
129 if (g_isIdle)
130 wxapp_install_idle_handler();
131
132 if (!win->m_hasVMT || !win->IsShown())
133 return FALSE;
134
135 int x = 0;
136 int y = 0;
137 gdk_window_get_root_origin( win->m_widget->window, &x, &y );
138 win->m_x = x;
139 win->m_y = y;
140
141 wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() );
142 mevent.SetEventObject( win );
143 win->GetEventHandler()->ProcessEvent( mevent );
144
145 return FALSE;
146 }
147
148 //-----------------------------------------------------------------------------
149 // "realize" from m_widget
150 //-----------------------------------------------------------------------------
151
152 // we cannot MWM hints and icons before the widget has been realized,
153 // so we do this directly after realization
154
155 static void
156 gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
157 wxTopLevelWindowGTK *win )
158 {
159 if (g_isIdle)
160 wxapp_install_idle_handler();
161
162 // All this is for Motif Window Manager "hints" and is supposed to be
163 // recognized by other WM as well. Not tested.
164 gdk_window_set_decorations(win->m_widget->window,
165 (GdkWMDecoration)win->m_gdkDecor);
166 gdk_window_set_functions(win->m_widget->window,
167 (GdkWMFunction)win->m_gdkFunc);
168
169 // GTK's shrinking/growing policy
170 if ((win->m_gdkFunc & GDK_FUNC_RESIZE) == 0)
171 gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1);
172 else
173 gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1);
174
175 // reset the icon
176 wxIconBundle iconsOld = win->GetIcons();
177 if ( iconsOld.GetIcon(-1).Ok() )
178 {
179 win->SetIcon( wxNullIcon );
180 win->SetIcons( iconsOld );
181 }
182 }
183
184 //-----------------------------------------------------------------------------
185 // "map_event" from m_widget
186 //-----------------------------------------------------------------------------
187
188 static void
189 gtk_frame_map_callback( GtkWidget * WXUNUSED(widget),
190 GdkEvent * WXUNUSED(event),
191 wxTopLevelWindow *win )
192 {
193 win->SetIconizeState(FALSE);
194 }
195
196 //-----------------------------------------------------------------------------
197 // "unmap_event" from m_widget
198 //-----------------------------------------------------------------------------
199
200 static void
201 gtk_frame_unmap_callback( GtkWidget * WXUNUSED(widget),
202 GdkEvent * WXUNUSED(event),
203 wxTopLevelWindow *win )
204 {
205 win->SetIconizeState(TRUE);
206 }
207
208 //-----------------------------------------------------------------------------
209 // "expose_event" of m_client
210 //-----------------------------------------------------------------------------
211
212 static int gtk_window_expose_callback( GtkWidget *widget, GdkEventExpose *gdk_event, wxWindow *win )
213 {
214 GtkPizza *pizza = GTK_PIZZA(widget);
215
216 gtk_paint_flat_box (win->m_widget->style,
217 pizza->bin_window, GTK_STATE_NORMAL,
218 GTK_SHADOW_NONE,
219 &gdk_event->area,
220 win->m_widget,
221 (char *)"base",
222 0, 0, -1, -1);
223
224 return TRUE;
225 }
226
227 //-----------------------------------------------------------------------------
228 // "draw" of m_client
229 //-----------------------------------------------------------------------------
230
231 #ifndef __WXGTK20__
232
233 static void gtk_window_draw_callback( GtkWidget *widget, GdkRectangle *rect, wxWindow *win )
234 {
235 GtkPizza *pizza = GTK_PIZZA(widget);
236
237 gtk_paint_flat_box (win->m_widget->style,
238 pizza->bin_window, GTK_STATE_NORMAL,
239 GTK_SHADOW_NONE,
240 rect,
241 win->m_widget,
242 (char *)"base",
243 0, 0, -1, -1);
244 }
245
246 #endif // GTK+ 1.x
247
248 // ----------------------------------------------------------------------------
249 // wxTopLevelWindowGTK itself
250 // ----------------------------------------------------------------------------
251
252 //-----------------------------------------------------------------------------
253 // InsertChild for wxTopLevelWindowGTK
254 //-----------------------------------------------------------------------------
255
256 /* Callback for wxTopLevelWindowGTK. This very strange beast has to be used because
257 * C++ has no virtual methods in a constructor. We have to emulate a
258 * virtual function here as wxWindows requires different ways to insert
259 * a child in container classes. */
260
261 static void wxInsertChildInTopLevelWindow( wxTopLevelWindowGTK* parent, wxWindow* child )
262 {
263 wxASSERT( GTK_IS_WIDGET(child->m_widget) );
264
265 if (!parent->m_insertInClientArea)
266 {
267 // these are outside the client area
268 wxTopLevelWindowGTK* frame = (wxTopLevelWindowGTK*) parent;
269 gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget),
270 GTK_WIDGET(child->m_widget),
271 child->m_x,
272 child->m_y,
273 child->m_width,
274 child->m_height );
275 }
276 else
277 {
278 // these are inside the client area
279 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
280 GTK_WIDGET(child->m_widget),
281 child->m_x,
282 child->m_y,
283 child->m_width,
284 child->m_height );
285 }
286
287 // resize on OnInternalIdle
288 parent->GtkUpdateSize();
289 }
290
291 // ----------------------------------------------------------------------------
292 // wxTopLevelWindowGTK creation
293 // ----------------------------------------------------------------------------
294
295 void wxTopLevelWindowGTK::Init()
296 {
297 m_sizeSet = FALSE;
298 m_miniEdge = 0;
299 m_miniTitle = 0;
300 m_mainWidget = (GtkWidget*) NULL;
301 m_insertInClientArea = TRUE;
302 m_isIconized = FALSE;
303 m_fsIsShowing = FALSE;
304 m_themeEnabled = TRUE;
305 m_gdkDecor = m_gdkFunc = 0;
306 m_grabbed = FALSE;
307 }
308
309 bool wxTopLevelWindowGTK::Create( wxWindow *parent,
310 wxWindowID id,
311 const wxString& title,
312 const wxPoint& pos,
313 const wxSize& sizeOrig,
314 long style,
315 const wxString &name )
316 {
317 // always create a frame of some reasonable, even if arbitrary, size (at
318 // least for MSW compatibility)
319 wxSize size = sizeOrig;
320 if ( size.x == -1 || size.y == -1 )
321 {
322 wxSize sizeDpy = wxGetDisplaySize();
323 if ( size.x == -1 )
324 size.x = sizeDpy.x / 3;
325 if ( size.y == -1 )
326 size.y = sizeDpy.y / 5;
327 }
328
329 wxTopLevelWindows.Append( this );
330
331 m_needParent = FALSE;
332
333 if (!PreCreation( parent, pos, size ) ||
334 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
335 {
336 wxFAIL_MSG( wxT("wxTopLevelWindowGTK creation failed") );
337 return FALSE;
338 }
339
340 m_title = title;
341
342 m_insertCallback = (wxInsertChildFunction) wxInsertChildInTopLevelWindow;
343
344 GtkWindowType win_type = GTK_WINDOW_TOPLEVEL;
345
346 if (style & wxFRAME_TOOL_WINDOW)
347 win_type = GTK_WINDOW_POPUP;
348
349 if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG)
350 {
351 // there is no more GTK_WINDOW_DIALOG in 2.0
352 #ifdef __WXGTK20__
353 win_type = GTK_WINDOW_TOPLEVEL;
354 #else
355 win_type = GTK_WINDOW_DIALOG;
356 #endif
357 }
358
359 m_widget = gtk_window_new( win_type );
360
361 if (m_parent && (GTK_IS_WINDOW(m_parent->m_widget)) &&
362 (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG))
363 {
364 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(m_parent->m_widget) );
365 }
366
367 if (!name.IsEmpty())
368 gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() );
369
370 gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
371 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
372
373 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
374 GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this );
375
376 // m_mainWidget holds the toolbar, the menubar and the client area
377 m_mainWidget = gtk_pizza_new();
378 gtk_widget_show( m_mainWidget );
379 GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS );
380 gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget );
381
382 // for m_mainWidget themes
383 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
384 GTK_SIGNAL_FUNC(gtk_window_expose_callback), (gpointer)this );
385 #ifndef __WXGTK20__
386 gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
387 GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
388 #endif
389
390 // m_wxwindow only represents the client area without toolbar and menubar
391 m_wxwindow = gtk_pizza_new();
392 gtk_widget_show( m_wxwindow );
393 gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
394
395 // we donm't allow the frame to get the focus as otherwise
396 // the frame will grab it at arbitrary focus changes
397 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
398
399 if (m_parent) m_parent->AddChild( this );
400
401 // the user resized the frame by dragging etc.
402 gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",
403 GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this );
404
405 PostCreation();
406
407 if ((m_x != -1) || (m_y != -1))
408 gtk_widget_set_uposition( m_widget, m_x, m_y );
409
410 gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height );
411
412 // we cannot set MWM hints and icons before the widget has
413 // been realized, so we do this directly after realization
414 gtk_signal_connect( GTK_OBJECT(m_widget), "realize",
415 GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this );
416
417 // the only way to get the window size is to connect to this event
418 gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event",
419 GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this );
420
421 // map and unmap for iconized state
422 gtk_signal_connect( GTK_OBJECT(m_widget), "map_event",
423 GTK_SIGNAL_FUNC(gtk_frame_map_callback), (gpointer)this );
424 gtk_signal_connect( GTK_OBJECT(m_widget), "unmap_event",
425 GTK_SIGNAL_FUNC(gtk_frame_unmap_callback), (gpointer)this );
426
427 // the only way to get the window size is to connect to this event
428 gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event",
429 GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this );
430
431 // disable native tab traversal
432 gtk_signal_connect( GTK_OBJECT(m_widget), "focus",
433 GTK_SIGNAL_FUNC(gtk_frame_focus_callback), (gpointer)this );
434
435 // decorations
436 if ((m_miniEdge > 0) || (style & wxSIMPLE_BORDER) || (style & wxNO_BORDER))
437 {
438 m_gdkDecor = 0;
439 m_gdkFunc = 0;
440 }
441 else
442 {
443 m_gdkDecor = (long) GDK_DECOR_BORDER;
444 m_gdkFunc = (long) GDK_FUNC_MOVE;
445
446 // All this is for Motif Window Manager "hints" and is supposed to be
447 // recognized by other WMs as well.
448 if ((style & wxCAPTION) != 0)
449 m_gdkDecor |= GDK_DECOR_TITLE;
450 if ((style & wxSYSTEM_MENU) != 0)
451 {
452 m_gdkFunc |= GDK_FUNC_CLOSE;
453 m_gdkDecor |= GDK_DECOR_MENU;
454 }
455 if ((style & wxMINIMIZE_BOX) != 0)
456 {
457 m_gdkFunc |= GDK_FUNC_MINIMIZE;
458 m_gdkDecor |= GDK_DECOR_MINIMIZE;
459 }
460 if ((style & wxMAXIMIZE_BOX) != 0)
461 {
462 m_gdkFunc |= GDK_FUNC_MAXIMIZE;
463 m_gdkDecor |= GDK_DECOR_MAXIMIZE;
464 }
465 if ((style & wxRESIZE_BORDER) != 0)
466 {
467 m_gdkFunc |= GDK_FUNC_RESIZE;
468 m_gdkDecor |= GDK_DECOR_RESIZEH;
469 }
470 }
471
472 return TRUE;
473 }
474
475 wxTopLevelWindowGTK::~wxTopLevelWindowGTK()
476 {
477 if (m_grabbed)
478 {
479 wxASSERT_MSG( FALSE, "Window still grabbed");
480 RemoveGrab();
481 }
482
483 m_isBeingDeleted = TRUE;
484
485 // it may also be GtkScrolledWindow in the case of an MDI child
486 if (GTK_IS_WINDOW(m_widget))
487 {
488 gtk_window_set_focus( GTK_WINDOW(m_widget), NULL );
489 }
490
491 wxTopLevelWindows.DeleteObject( this );
492
493 if (wxTheApp->GetTopWindow() == this)
494 wxTheApp->SetTopWindow( (wxWindow*) NULL );
495
496 if ((wxTopLevelWindows.Number() == 0) &&
497 (wxTheApp->GetExitOnFrameDelete()))
498 {
499 wxTheApp->ExitMainLoop();
500 }
501 }
502
503 bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long style )
504 {
505 if (show == m_fsIsShowing) return FALSE; // return what?
506
507 m_fsIsShowing = show;
508
509 if (show)
510 {
511 m_fsSaveGdkFunc = m_gdkFunc;
512 m_fsSaveGdkDecor = m_gdkDecor;
513 m_fsSaveFlag = style;
514 GetPosition( &m_fsSaveFrame.x, &m_fsSaveFrame.y );
515 GetSize( &m_fsSaveFrame.width, &m_fsSaveFrame.height );
516
517 gtk_widget_hide( m_widget );
518 gtk_widget_unrealize( m_widget );
519
520 m_gdkDecor = (long) GDK_DECOR_BORDER;
521 m_gdkFunc = (long) GDK_FUNC_MOVE;
522
523 int x;
524 int y;
525 wxDisplaySize( &x, &y );
526 SetSize( 0, 0, x, y );
527
528 gtk_widget_realize( m_widget );
529 gtk_widget_show( m_widget );
530 }
531 else
532 {
533 gtk_widget_hide( m_widget );
534 gtk_widget_unrealize( m_widget );
535
536 m_gdkFunc = m_fsSaveGdkFunc;
537 m_gdkDecor = m_fsSaveGdkDecor;
538
539 SetSize( m_fsSaveFrame.x, m_fsSaveFrame.y, m_fsSaveFrame.width, m_fsSaveFrame.height );
540
541 gtk_widget_realize( m_widget );
542 gtk_widget_show( m_widget );
543 }
544
545 return TRUE;
546 }
547
548 // ----------------------------------------------------------------------------
549 // overridden wxWindow methods
550 // ----------------------------------------------------------------------------
551
552 bool wxTopLevelWindowGTK::Show( bool show )
553 {
554 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
555
556 if (show && !m_sizeSet)
557 {
558 /* by calling GtkOnSize here, we don't have to call
559 either after showing the frame, which would entail
560 much ugly flicker or from within the size_allocate
561 handler, because GTK 1.1.X forbids that. */
562
563 GtkOnSize( m_x, m_y, m_width, m_height );
564 }
565
566 return wxWindow::Show( show );
567 }
568
569 void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(width), int WXUNUSED(height) )
570 {
571 wxFAIL_MSG( wxT("DoMoveWindow called for wxTopLevelWindowGTK") );
572 }
573
574 void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
575 {
576 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
577
578 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
579 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
580
581 // avoid recursions
582 if (m_resizing)
583 return;
584 m_resizing = TRUE;
585
586 int old_x = m_x;
587 int old_y = m_y;
588
589 int old_width = m_width;
590 int old_height = m_height;
591
592 if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0)
593 {
594 if (x != -1) m_x = x;
595 if (y != -1) m_y = y;
596 }
597 else
598 {
599 m_x = x;
600 m_y = y;
601 }
602 if (width != -1) m_width = width;
603 if (height != -1) m_height = height;
604
605 /*
606 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
607 {
608 if (width == -1) m_width = 80;
609 }
610
611 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
612 {
613 if (height == -1) m_height = 26;
614 }
615 */
616
617 int minWidth = GetMinWidth(),
618 minHeight = GetMinHeight(),
619 maxWidth = GetMaxWidth(),
620 maxHeight = GetMaxHeight();
621
622 if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
623 if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
624 if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
625 if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
626
627 if ((m_x != -1) || (m_y != -1))
628 {
629 if ((m_x != old_x) || (m_y != old_y))
630 {
631 gtk_widget_set_uposition( m_widget, m_x, m_y );
632 }
633 }
634
635 if ((m_width != old_width) || (m_height != old_height))
636 {
637 if (m_widget->window)
638 gdk_window_resize( m_widget->window, m_width, m_height );
639 else
640 gtk_window_set_default_size( GTK_WINDOW(m_widget), m_width, m_height );
641
642 /* we set the size in GtkOnSize, i.e. mostly the actual resizing is
643 done either directly before the frame is shown or in idle time
644 so that different calls to SetSize() don't lead to flicker. */
645 m_sizeSet = FALSE;
646 }
647
648 m_resizing = FALSE;
649 }
650
651 void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const
652 {
653 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
654
655 wxWindow::DoGetClientSize( width, height );
656 if (height)
657 {
658 // mini edge
659 *height -= m_miniEdge*2 + m_miniTitle;
660 }
661 if (width)
662 {
663 *width -= m_miniEdge*2;
664 }
665 }
666
667 void wxTopLevelWindowGTK::DoSetClientSize( int width, int height )
668 {
669 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
670
671 DoSetSize(-1, -1,
672 width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle, 0);
673 }
674
675 void wxTopLevelWindowGTK::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y),
676 int width, int height )
677 {
678 // due to a bug in gtk, x,y are always 0
679 // m_x = x;
680 // m_y = y;
681
682 // avoid recursions
683 if (m_resizing) return;
684 m_resizing = TRUE;
685
686 if ( m_wxwindow == NULL ) return;
687
688 m_width = width;
689 m_height = height;
690
691 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
692 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
693 set in wxFrame::Create so it is used to check what kind of frame we
694 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
695 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
696 importantly) m_mainWidget */
697
698 int minWidth = GetMinWidth(),
699 minHeight = GetMinHeight(),
700 maxWidth = GetMaxWidth(),
701 maxHeight = GetMaxHeight();
702
703 if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
704 if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
705 if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
706 if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
707
708 if (m_mainWidget)
709 {
710 // set size hints
711 gint flag = 0; // GDK_HINT_POS;
712 GdkGeometry geom;
713
714 if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
715 if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
716
717 geom.min_width = minWidth;
718 geom.min_height = minHeight;
719
720 // Because of the way we set GDK_HINT_MAX_SIZE above, if either of
721 // maxHeight or maxWidth is set, we must set them both, else the
722 // remaining -1 will be taken literally.
723
724 // I'm certain this also happens elsewhere, and is the probable
725 // cause of other such things as:
726 // Gtk-WARNING **: gtk_widget_size_allocate():
727 // attempt to allocate widget with width 65535 and height 600
728 // but I don't have time to track them all now..
729 //
730 // Really we need to encapulate all this height/width business and
731 // stop any old method from ripping at the members directly and
732 // scattering -1's without regard for who might resolve them later.
733
734 geom.max_width = ( maxHeight == -1 ) ? maxWidth
735 : ( maxWidth == -1 ) ? wxGetDisplaySize().GetWidth()
736 : maxWidth ;
737
738 geom.max_height = ( maxWidth == -1 ) ? maxHeight // ( == -1 here )
739 : ( maxHeight == -1 ) ? wxGetDisplaySize().GetHeight()
740 : maxHeight ;
741
742 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
743 (GtkWidget*) NULL,
744 &geom,
745 (GdkWindowHints) flag );
746
747 /* I revert back to wxGTK's original behaviour. m_mainWidget holds the
748 * menubar, the toolbar and the client area, which is represented by
749 * m_wxwindow.
750 * this hurts in the eye, but I don't want to call SetSize()
751 * because I don't want to call any non-native functions here. */
752
753 int client_x = m_miniEdge;
754 int client_y = m_miniEdge + m_miniTitle;
755 int client_w = m_width - 2*m_miniEdge;
756 int client_h = m_height - 2*m_miniEdge - m_miniTitle;
757
758 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
759 m_wxwindow,
760 client_x, client_y, client_w, client_h );
761 }
762 else
763 {
764 // If there is no m_mainWidget between m_widget and m_wxwindow there
765 // is no need to set the size or position of m_wxwindow.
766 }
767
768 m_sizeSet = TRUE;
769
770 // send size event to frame
771 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
772 event.SetEventObject( this );
773 GetEventHandler()->ProcessEvent( event );
774
775 m_resizing = FALSE;
776 }
777
778 void wxTopLevelWindowGTK::OnInternalIdle()
779 {
780 if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow))
781 {
782 GtkOnSize( m_x, m_y, m_width, m_height );
783
784 // we'll come back later
785 if (g_isIdle)
786 wxapp_install_idle_handler();
787 return;
788 }
789
790 // set the focus if not done yet and if we can already do it
791 if ( GTK_WIDGET_REALIZED(m_wxwindow) )
792 {
793 if ( g_delayedFocus &&
794 wxGetTopLevelParent((wxWindow*)g_delayedFocus) == this )
795 {
796 g_delayedFocus->SetFocus();
797 g_delayedFocus = NULL;
798 }
799 }
800
801 wxWindow::OnInternalIdle();
802 }
803
804 // ----------------------------------------------------------------------------
805 // frame title/icon
806 // ----------------------------------------------------------------------------
807
808 void wxTopLevelWindowGTK::SetTitle( const wxString &title )
809 {
810 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
811
812 m_title = title;
813 gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() );
814 }
815
816 void wxTopLevelWindowGTK::DoSetIcon( const wxIcon &icon )
817 {
818 if ( !icon.Ok() )
819 return;
820
821 if (!m_widget->window)
822 return;
823
824 wxMask *mask = icon.GetMask();
825 GdkBitmap *bm = (GdkBitmap *) NULL;
826 if (mask) bm = mask->GetBitmap();
827
828 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
829 }
830
831 void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
832 {
833 SetIcons( wxIconBundle( icon ) );
834 }
835
836 void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
837 {
838 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
839 GdkWindow* window = m_widget->window;
840
841 wxTopLevelWindowBase::SetIcons( icons );
842
843 DoSetIcon( icons.GetIcon( -1 ) );
844 if ( window )
845 {
846 wxSetIconsX11( (WXDisplay*)GDK_WINDOW_XDISPLAY( window ),
847 (WXWindow)GDK_WINDOW_XWINDOW( window ), icons );
848 }
849 }
850
851 // ----------------------------------------------------------------------------
852 // frame state: maximized/iconized/normal
853 // ----------------------------------------------------------------------------
854
855 void wxTopLevelWindowGTK::Maximize(bool WXUNUSED(maximize))
856 {
857 wxFAIL_MSG( _T("not implemented") );
858 }
859
860 bool wxTopLevelWindowGTK::IsMaximized() const
861 {
862 // wxFAIL_MSG( _T("not implemented") );
863
864 // This is an approximation
865 return FALSE;
866 }
867
868 void wxTopLevelWindowGTK::Restore()
869 {
870 wxFAIL_MSG( _T("not implemented") );
871 }
872
873 void wxTopLevelWindowGTK::Iconize( bool iconize )
874 {
875 if (iconize)
876 {
877 GdkWindow *window = m_widget->window;
878
879 // you should do it later, for example from OnCreate() handler
880 wxCHECK_RET( window, _T("frame not created yet - can't iconize") );
881
882 XIconifyWindow( GDK_WINDOW_XDISPLAY( window ),
883 GDK_WINDOW_XWINDOW( window ),
884 DefaultScreen( GDK_DISPLAY() ) );
885 }
886 }
887
888 bool wxTopLevelWindowGTK::IsIconized() const
889 {
890 return m_isIconized;
891 }
892
893 void wxTopLevelWindowGTK::SetIconizeState(bool iconize)
894 {
895 if ( iconize != m_isIconized )
896 {
897 m_isIconized = iconize;
898 (void)SendIconizeEvent(iconize);
899 }
900 }
901
902 void wxTopLevelWindowGTK::AddGrab()
903 {
904 if (!m_grabbed)
905 {
906 m_grabbed = TRUE;
907 gtk_grab_add( m_widget );
908 gtk_main();
909 gtk_grab_remove( m_widget );
910 }
911 }
912
913 void wxTopLevelWindowGTK::RemoveGrab()
914 {
915 if (m_grabbed)
916 {
917 gtk_main_quit();
918 m_grabbed = FALSE;
919 }
920 }
921
922 // vi:sts=4:sw=4:et