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