]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
19717c50 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
fe4e9e6c | 11 | #pragma implementation "frame.h" |
c801d85f KB |
12 | #endif |
13 | ||
14 | #include "wx/frame.h" | |
15 | #include "wx/dialog.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/app.h" | |
cf4219e7 | 18 | #include "wx/menu.h" |
dcf924a3 | 19 | #if wxUSE_TOOLBAR |
cf4219e7 | 20 | #include "wx/toolbar.h" |
dcf924a3 RR |
21 | #endif |
22 | #if wxUSE_STATUSBAR | |
cf4219e7 | 23 | #include "wx/statusbr.h" |
dcf924a3 | 24 | #endif |
362c6693 | 25 | #include "wx/dcclient.h" |
83624f79 RR |
26 | |
27 | #include "glib.h" | |
28 | #include "gdk/gdk.h" | |
29 | #include "gtk/gtk.h" | |
c801d85f | 30 | #include "wx/gtk/win_gtk.h" |
801aa178 | 31 | #include "gdk/gdkkeysyms.h" |
cd25b18c | 32 | #include "gdk/gdkx.h" |
c801d85f | 33 | |
2f2aa628 RR |
34 | //----------------------------------------------------------------------------- |
35 | // constants | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
907789a0 | 38 | const int wxMENU_HEIGHT = 27; |
c67daf87 | 39 | const int wxSTATUS_HEIGHT = 25; |
41ca191f | 40 | const int wxPLACE_HOLDER = 0; |
c801d85f | 41 | |
acfd422a RR |
42 | //----------------------------------------------------------------------------- |
43 | // idle system | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | extern void wxapp_install_idle_handler(); | |
47 | extern bool g_isIdle; | |
48 | ||
2f2aa628 RR |
49 | //----------------------------------------------------------------------------- |
50 | // data | |
51 | //----------------------------------------------------------------------------- | |
52 | ||
c801d85f KB |
53 | extern wxList wxPendingDelete; |
54 | ||
2e563988 RR |
55 | //----------------------------------------------------------------------------- |
56 | // debug | |
57 | //----------------------------------------------------------------------------- | |
58 | ||
59 | #ifdef __WXDEBUG__ | |
60 | ||
61 | extern void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window ); | |
62 | ||
63 | #endif | |
64 | ||
c801d85f | 65 | //----------------------------------------------------------------------------- |
2f2aa628 | 66 | // "size_allocate" |
c801d85f | 67 | //----------------------------------------------------------------------------- |
c801d85f | 68 | |
2f2aa628 | 69 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) |
ed7a557b | 70 | { |
88ac883a | 71 | if (g_isIdle) |
121a3581 | 72 | wxapp_install_idle_handler(); |
acfd422a | 73 | |
54517652 RR |
74 | if (!win->m_hasVMT) |
75 | return; | |
8bbe427f | 76 | |
121a3581 RR |
77 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
78 | { | |
54517652 RR |
79 | /* |
80 | wxPrintf( "OnSize from " ); | |
81 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
82 | wxPrintf( win->GetClassInfo()->GetClassName() ); | |
83 | wxPrintf( " %d %d %d %d\n", (int)alloc->x, | |
84 | (int)alloc->y, | |
85 | (int)alloc->width, | |
86 | (int)alloc->height ); | |
87 | */ | |
121a3581 RR |
88 | win->m_width = alloc->width; |
89 | win->m_height = alloc->height; | |
90 | win->UpdateSize(); | |
91 | } | |
362c6693 | 92 | } |
c801d85f KB |
93 | |
94 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
95 | // "delete_event" |
96 | //----------------------------------------------------------------------------- | |
c801d85f | 97 | |
2f2aa628 | 98 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) |
ed7a557b | 99 | { |
88ac883a | 100 | if (g_isIdle) |
121a3581 | 101 | wxapp_install_idle_handler(); |
ed7a557b | 102 | |
fb1585ae | 103 | win->Close(); |
c801d85f | 104 | |
fb1585ae | 105 | return TRUE; |
362c6693 | 106 | } |
c801d85f | 107 | |
16bcc879 RR |
108 | //----------------------------------------------------------------------------- |
109 | // "child_attached" of menu bar | |
110 | //----------------------------------------------------------------------------- | |
111 | ||
112 | static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
113 | { | |
a2053b27 | 114 | if (!win->m_hasVMT) return; |
88ac883a | 115 | |
16bcc879 | 116 | win->m_menuBarDetached = FALSE; |
f03fc89f | 117 | win->UpdateSize(); |
16bcc879 RR |
118 | } |
119 | ||
120 | //----------------------------------------------------------------------------- | |
121 | // "child_detached" of menu bar | |
122 | //----------------------------------------------------------------------------- | |
123 | ||
124 | static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
125 | { | |
a2053b27 | 126 | if (!win->m_hasVMT) return; |
88ac883a | 127 | |
16bcc879 | 128 | win->m_menuBarDetached = TRUE; |
f03fc89f | 129 | win->UpdateSize(); |
16bcc879 RR |
130 | } |
131 | ||
88ac883a | 132 | #if wxUSE_TOOLBAR |
16bcc879 RR |
133 | //----------------------------------------------------------------------------- |
134 | // "child_attached" of tool bar | |
135 | //----------------------------------------------------------------------------- | |
136 | ||
137 | static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) | |
138 | { | |
a2053b27 | 139 | if (!win->m_hasVMT) return; |
88ac883a | 140 | |
16bcc879 | 141 | win->m_toolBarDetached = FALSE; |
88ac883a | 142 | |
f03fc89f | 143 | win->UpdateSize(); |
16bcc879 RR |
144 | } |
145 | ||
146 | //----------------------------------------------------------------------------- | |
147 | // "child_detached" of tool bar | |
148 | //----------------------------------------------------------------------------- | |
149 | ||
5e0201ea | 150 | static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win ) |
16bcc879 | 151 | { |
88ac883a | 152 | if (g_isIdle) |
801aa178 | 153 | wxapp_install_idle_handler(); |
acfd422a | 154 | |
a2053b27 | 155 | if (!win->m_hasVMT) return; |
88ac883a | 156 | |
16bcc879 | 157 | win->m_toolBarDetached = TRUE; |
f03fc89f | 158 | win->UpdateSize(); |
16bcc879 | 159 | } |
88ac883a | 160 | #endif // wxUSE_TOOLBAR |
16bcc879 | 161 | |
47908e25 | 162 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
163 | // "configure_event" |
164 | //----------------------------------------------------------------------------- | |
47908e25 | 165 | |
c693edf3 RR |
166 | static gint |
167 | #if (GTK_MINOR_VERSON > 0) | |
168 | gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxFrame *win ) | |
169 | #else | |
170 | gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) | |
171 | #endif | |
47908e25 | 172 | { |
c693edf3 | 173 | if (g_isIdle) |
121a3581 | 174 | wxapp_install_idle_handler(); |
acfd422a | 175 | |
a2053b27 | 176 | if (!win->m_hasVMT) return FALSE; |
88ac883a | 177 | |
c693edf3 | 178 | #if (GTK_MINOR_VERSON > 0) |
dfc3d7e0 RR |
179 | int x = 0; |
180 | int y = 0; | |
181 | gdk_window_get_root_origin( win->m_widget->window, &x, &y ); | |
dfc3d7e0 RR |
182 | win->m_x = x; |
183 | win->m_y = y; | |
c693edf3 RR |
184 | #else |
185 | win->m_x = event->x; | |
186 | win->m_y = event->y; | |
187 | #endif | |
8bbe427f | 188 | |
a2053b27 | 189 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); |
36b3b54a RR |
190 | mevent.SetEventObject( win ); |
191 | win->GetEventHandler()->ProcessEvent( mevent ); | |
192 | ||
fb1585ae | 193 | return FALSE; |
362c6693 | 194 | } |
47908e25 | 195 | |
2b07d713 RR |
196 | //----------------------------------------------------------------------------- |
197 | // "realize" from m_widget | |
198 | //----------------------------------------------------------------------------- | |
199 | ||
88ac883a | 200 | /* we cannot MWM hints and icons before the widget has been realized, |
2b07d713 RR |
201 | so we do this directly after realization */ |
202 | ||
88ac883a | 203 | static gint |
5e0201ea | 204 | gtk_frame_realized_callback( GtkWidget *WXUNUSED(widget), wxFrame *win ) |
2b07d713 | 205 | { |
88ac883a | 206 | if (g_isIdle) |
121a3581 | 207 | wxapp_install_idle_handler(); |
acfd422a | 208 | |
2b07d713 RR |
209 | /* all this is for Motif Window Manager "hints" and is supposed to be |
210 | recognized by other WM as well. not tested. */ | |
051b55ad KB |
211 | long decor = (long) GDK_DECOR_BORDER; |
212 | long func = (long) GDK_FUNC_MOVE; | |
88ac883a | 213 | |
f03fc89f VZ |
214 | if ((win->GetWindowStyle() & wxCAPTION) != 0) |
215 | decor |= GDK_DECOR_TITLE; | |
216 | if ((win->GetWindowStyle() & wxSYSTEM_MENU) != 0) | |
aa64626e KB |
217 | { |
218 | decor |= GDK_DECOR_MENU; | |
219 | func |= GDK_FUNC_CLOSE; | |
220 | } | |
f03fc89f | 221 | if ((win->GetWindowStyle() & wxMINIMIZE_BOX) != 0) |
15b24b14 | 222 | { |
f03fc89f VZ |
223 | func |= GDK_FUNC_MINIMIZE; |
224 | decor |= GDK_DECOR_MINIMIZE; | |
15b24b14 | 225 | } |
f03fc89f | 226 | if ((win->GetWindowStyle() & wxMAXIMIZE_BOX) != 0) |
15b24b14 | 227 | { |
f03fc89f VZ |
228 | func |= GDK_FUNC_MAXIMIZE; |
229 | decor |= GDK_DECOR_MAXIMIZE; | |
15b24b14 | 230 | } |
f03fc89f | 231 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) != 0) |
aa64626e KB |
232 | { |
233 | func |= GDK_FUNC_RESIZE; | |
234 | decor |= GDK_DECOR_RESIZEH; | |
aa64626e KB |
235 | } |
236 | ||
a2053b27 RR |
237 | gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); |
238 | gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); | |
88ac883a | 239 | |
2b07d713 | 240 | /* GTK's shrinking/growing policy */ |
f03fc89f | 241 | if ((win->GetWindowStyle() & wxRESIZE_BORDER) == 0) |
a2053b27 | 242 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); |
2b07d713 | 243 | else |
a2053b27 | 244 | gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); |
88ac883a | 245 | |
738f9e5a RR |
246 | /* set size hints */ |
247 | gint flag = GDK_HINT_POS; | |
248 | if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE; | |
249 | if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE; | |
250 | if (flag) | |
251 | { | |
252 | gdk_window_set_hints( win->m_widget->window, | |
253 | win->m_x, win->m_y, | |
254 | win->GetMinWidth(), win->GetMinHeight(), | |
255 | win->GetMaxWidth(), win->GetMaxHeight(), | |
256 | flag ); | |
257 | } | |
258 | ||
58dea4b0 RR |
259 | /* reset the icon */ |
260 | if (win->m_icon != wxNullIcon) | |
261 | { | |
262 | wxIcon icon( win->m_icon ); | |
263 | win->m_icon = wxNullIcon; | |
f03fc89f | 264 | win->SetIcon( icon ); |
58dea4b0 | 265 | } |
88ac883a | 266 | |
2e563988 RR |
267 | /* we set the focus to the child that accepts the focus. this |
268 | doesn't really have to be done in "realize" but why not? */ | |
f03fc89f | 269 | wxWindowList::Node *node = win->GetChildren().GetFirst(); |
2e563988 RR |
270 | while (node) |
271 | { | |
f03fc89f VZ |
272 | wxWindow *child = node->GetData(); |
273 | if (child->AcceptsFocus()) | |
274 | { | |
275 | child->SetFocus(); | |
276 | break; | |
277 | } | |
88ac883a | 278 | |
f03fc89f | 279 | node = node->GetNext(); |
2e563988 | 280 | } |
88ac883a | 281 | |
227e5e99 RR |
282 | return FALSE; |
283 | } | |
88ac883a | 284 | |
f362b96d RR |
285 | //----------------------------------------------------------------------------- |
286 | // InsertChild for wxFrame | |
287 | //----------------------------------------------------------------------------- | |
288 | ||
289 | /* Callback for wxFrame. This very strange beast has to be used because | |
290 | * C++ has no virtual methods in a constructor. We have to emulate a | |
291 | * virtual function here as wxWindows requires different ways to insert | |
292 | * a child in container classes. */ | |
293 | ||
6bc8a1c8 | 294 | static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child ) |
f362b96d | 295 | { |
5fd11f09 RR |
296 | wxASSERT( GTK_IS_WIDGET(child->m_widget) ); |
297 | ||
6bc8a1c8 | 298 | if (!parent->m_insertInClientArea) |
f362b96d RR |
299 | { |
300 | /* these are outside the client area */ | |
f03fc89f | 301 | wxFrame* frame = (wxFrame*) parent; |
f362b96d | 302 | gtk_myfixed_put( GTK_MYFIXED(frame->m_mainWidget), |
a2053b27 RR |
303 | GTK_WIDGET(child->m_widget), |
304 | child->m_x, | |
305 | child->m_y, | |
306 | child->m_width, | |
307 | child->m_height ); | |
88ac883a VZ |
308 | |
309 | #if wxUSE_TOOLBAR | |
f03fc89f VZ |
310 | /* we connect to these events for recalculating the client area |
311 | space when the toolbar is floating */ | |
312 | if (wxIS_KIND_OF(child,wxToolBar)) | |
313 | { | |
314 | wxToolBar *toolBar = (wxToolBar*) child; | |
315 | if (toolBar->GetWindowStyle() & wxTB_DOCKABLE) | |
316 | { | |
a2053b27 | 317 | gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_attached", |
41ca191f | 318 | GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback), (gpointer)parent ); |
88ac883a | 319 | |
a2053b27 | 320 | gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_detached", |
41ca191f | 321 | GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback), (gpointer)parent ); |
f03fc89f VZ |
322 | } |
323 | } | |
88ac883a | 324 | #endif // wxUSE_TOOLBAR |
f362b96d RR |
325 | } |
326 | else | |
327 | { | |
328 | /* these are inside the client area */ | |
a2053b27 RR |
329 | gtk_myfixed_put( GTK_MYFIXED(parent->m_wxwindow), |
330 | GTK_WIDGET(child->m_widget), | |
331 | child->m_x, | |
332 | child->m_y, | |
333 | child->m_width, | |
334 | child->m_height ); | |
f362b96d RR |
335 | } |
336 | ||
f362b96d | 337 | /* resize on OnInternalIdle */ |
f03fc89f | 338 | parent->UpdateSize(); |
f362b96d RR |
339 | } |
340 | ||
2f2aa628 RR |
341 | //----------------------------------------------------------------------------- |
342 | // wxFrame | |
c801d85f KB |
343 | //----------------------------------------------------------------------------- |
344 | ||
345 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
fb1585ae | 346 | EVT_SIZE(wxFrame::OnSize) |
54517652 | 347 | EVT_IDLE(wxFrame::OnIdle) |
fe4e9e6c | 348 | EVT_CLOSE(wxFrame::OnCloseWindow) |
342b6a2f | 349 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) |
c801d85f KB |
350 | END_EVENT_TABLE() |
351 | ||
352 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
353 | ||
ddb6bc71 | 354 | void wxFrame::Init() |
c801d85f | 355 | { |
fb1585ae | 356 | m_frameMenuBar = (wxMenuBar *) NULL; |
88ac883a | 357 | #if wxUSE_STATUSBAR |
fb1585ae | 358 | m_frameStatusBar = (wxStatusBar *) NULL; |
88ac883a VZ |
359 | #endif // wxUSE_STATUSBAR |
360 | #if wxUSE_TOOLBAR | |
fb1585ae | 361 | m_frameToolBar = (wxToolBar *) NULL; |
88ac883a | 362 | #endif // wxUSE_TOOLBAR |
fb1585ae | 363 | m_sizeSet = FALSE; |
b2b3ccc5 RR |
364 | m_miniEdge = 0; |
365 | m_miniTitle = 0; | |
ab2b3dd4 | 366 | m_mainWidget = (GtkWidget*) NULL; |
16bcc879 RR |
367 | m_menuBarDetached = FALSE; |
368 | m_toolBarDetached = FALSE; | |
6bc8a1c8 | 369 | m_insertInClientArea = TRUE; |
54517652 | 370 | m_isFrame = TRUE; |
362c6693 | 371 | } |
c801d85f | 372 | |
ed7a557b | 373 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
374 | const wxPoint &pos, const wxSize &size, |
375 | long style, const wxString &name ) | |
c801d85f | 376 | { |
ddb6bc71 | 377 | Init(); |
88ac883a | 378 | |
fb1585ae | 379 | Create( parent, id, title, pos, size, style, name ); |
362c6693 | 380 | } |
c801d85f | 381 | |
debe6624 | 382 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 383 | const wxPoint &pos, const wxSize &size, |
debe6624 | 384 | long style, const wxString &name ) |
c801d85f | 385 | { |
a802c3a1 | 386 | wxTopLevelWindows.Append( this ); |
8bbe427f | 387 | |
fb1585ae | 388 | m_needParent = FALSE; |
ed7a557b | 389 | |
4dcaf11a RR |
390 | if (!PreCreation( parent, pos, size ) || |
391 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
392 | { | |
223d09f6 | 393 | wxFAIL_MSG( wxT("wxFrame creation failed") ); |
4dcaf11a RR |
394 | return FALSE; |
395 | } | |
c801d85f | 396 | |
fb1585ae | 397 | m_title = title; |
88ac883a | 398 | |
6bc8a1c8 | 399 | m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame; |
ed7a557b | 400 | |
fb1585ae RR |
401 | GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; |
402 | if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; | |
8bbe427f | 403 | |
fb1585ae | 404 | m_widget = gtk_window_new( win_type ); |
88ac883a | 405 | |
de1c750f RR |
406 | if (!name.IsEmpty()) |
407 | gtk_window_set_wmclass( GTK_WINDOW(m_widget), name.mb_str(), name.mb_str() ); | |
8bbe427f | 408 | |
2e563988 | 409 | #ifdef __WXDEBUG__ |
223d09f6 | 410 | debug_focus_in( m_widget, wxT("wxFrame::m_widget"), name ); |
2e563988 RR |
411 | #endif |
412 | ||
ed9b9841 | 413 | gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() ); |
fb1585ae | 414 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); |
ed7a557b | 415 | |
fb1585ae RR |
416 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
417 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
ed7a557b | 418 | |
f362b96d RR |
419 | /* m_mainWidget holds the toolbar, the menubar and the client area */ |
420 | m_mainWidget = gtk_myfixed_new(); | |
421 | gtk_widget_show( m_mainWidget ); | |
422 | GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); | |
423 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); | |
88ac883a | 424 | |
2e563988 | 425 | #ifdef __WXDEBUG__ |
223d09f6 | 426 | debug_focus_in( m_mainWidget, wxT("wxFrame::m_mainWidget"), name ); |
2e563988 RR |
427 | #endif |
428 | ||
f362b96d | 429 | /* m_wxwindow only represents the client area without toolbar and menubar */ |
fb1585ae RR |
430 | m_wxwindow = gtk_myfixed_new(); |
431 | gtk_widget_show( m_wxwindow ); | |
f362b96d | 432 | gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); |
88ac883a | 433 | |
2e563988 | 434 | #ifdef __WXDEBUG__ |
223d09f6 | 435 | debug_focus_in( m_wxwindow, wxT("wxFrame::m_wxwindow"), name ); |
2e563988 RR |
436 | #endif |
437 | ||
438 | /* we donm't allow the frame to get the focus as otherwise | |
439 | the frame will grabit at arbitrary fcous changes. */ | |
440 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 441 | |
de8113d9 RR |
442 | if (m_parent) m_parent->AddChild( this ); |
443 | ||
54517652 RR |
444 | /* the user resized the frame by dragging etc. */ |
445 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", | |
446 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
447 | ||
de8113d9 RR |
448 | PostCreation(); |
449 | ||
58dea4b0 | 450 | /* we cannot set MWM hints and icons before the widget has |
2b07d713 RR |
451 | been realized, so we do this directly after realization */ |
452 | gtk_signal_connect( GTK_OBJECT(m_widget), "realize", | |
f03fc89f | 453 | GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); |
88ac883a | 454 | |
ab2b3dd4 | 455 | /* the only way to get the window size is to connect to this event */ |
fb1585ae RR |
456 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
457 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
8bbe427f | 458 | |
fb1585ae | 459 | return TRUE; |
362c6693 | 460 | } |
c801d85f | 461 | |
19717c50 | 462 | wxFrame::~wxFrame() |
c801d85f | 463 | { |
31c6b4fc | 464 | m_isBeingDeleted = TRUE; |
88ac883a | 465 | |
fb1585ae | 466 | if (m_frameMenuBar) delete m_frameMenuBar; |
e27ce4e9 | 467 | m_frameMenuBar = (wxMenuBar *) NULL; |
88ac883a VZ |
468 | |
469 | #if wxUSE_STATUSBAR | |
fb1585ae | 470 | if (m_frameStatusBar) delete m_frameStatusBar; |
e27ce4e9 | 471 | m_frameStatusBar = (wxStatusBar *) NULL; |
88ac883a VZ |
472 | #endif // wxUSE_STATUSBAR |
473 | ||
474 | #if wxUSE_TOOLBAR | |
fb1585ae | 475 | if (m_frameToolBar) delete m_frameToolBar; |
e27ce4e9 | 476 | m_frameToolBar = (wxToolBar *) NULL; |
88ac883a | 477 | #endif // wxUSE_TOOLBAR |
ed7a557b | 478 | |
fb1585ae | 479 | wxTopLevelWindows.DeleteObject( this ); |
2b854a32 | 480 | |
0d2a2b60 | 481 | if (wxTheApp->GetTopWindow() == this) |
0d2a2b60 | 482 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); |
2b854a32 | 483 | |
0d2a2b60 | 484 | if (wxTopLevelWindows.Number() == 0) |
0d2a2b60 | 485 | wxTheApp->ExitMainLoop(); |
362c6693 | 486 | } |
ed7a557b | 487 | |
debe6624 | 488 | bool wxFrame::Show( bool show ) |
c801d85f | 489 | { |
223d09f6 | 490 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 491 | |
35178437 | 492 | if (show && !m_sizeSet) |
fb1585ae | 493 | { |
e27ce4e9 RR |
494 | /* by calling GtkOnSize here, we don't have to call |
495 | either after showing the frame, which would entail | |
f362b96d | 496 | much ugly flicker or from within the size_allocate |
e27ce4e9 | 497 | handler, because GTK 1.1.X forbids that. */ |
8bbe427f | 498 | |
35178437 | 499 | GtkOnSize( m_x, m_y, m_width, m_height ); |
fb1585ae | 500 | } |
8bbe427f | 501 | |
fb1585ae | 502 | return wxWindow::Show( show ); |
362c6693 | 503 | } |
c801d85f | 504 | |
19717c50 | 505 | bool wxFrame::Destroy() |
c801d85f | 506 | { |
223d09f6 | 507 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 508 | |
fb1585ae | 509 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
ed7a557b | 510 | |
fb1585ae | 511 | return TRUE; |
c801d85f KB |
512 | } |
513 | ||
bfc6fde4 | 514 | void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 515 | { |
223d09f6 | 516 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 517 | |
ab2b3dd4 | 518 | /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */ |
223d09f6 | 519 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
88ac883a | 520 | |
ab2b3dd4 | 521 | /* avoid recursions */ |
88ac883a | 522 | if (m_resizing) return; |
fb1585ae RR |
523 | m_resizing = TRUE; |
524 | ||
525 | int old_x = m_x; | |
526 | int old_y = m_y; | |
527 | int old_width = m_width; | |
528 | int old_height = m_height; | |
8bbe427f | 529 | |
85ad5eb5 | 530 | if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) |
fb1585ae RR |
531 | { |
532 | if (x != -1) m_x = x; | |
533 | if (y != -1) m_y = y; | |
534 | if (width != -1) m_width = width; | |
535 | if (height != -1) m_height = height; | |
536 | } | |
537 | else | |
538 | { | |
539 | m_x = x; | |
540 | m_y = y; | |
541 | m_width = width; | |
542 | m_height = height; | |
543 | } | |
544 | ||
545 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
546 | { | |
547 | if (width == -1) m_width = 80; | |
548 | } | |
549 | ||
550 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
551 | { | |
552 | if (height == -1) m_height = 26; | |
553 | } | |
8bbe427f | 554 | |
fb1585ae RR |
555 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
556 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
557 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
558 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
fb1585ae RR |
559 | |
560 | if ((m_x != -1) || (m_y != -1)) | |
561 | { | |
8bbe427f | 562 | if ((m_x != old_x) || (m_y != old_y)) |
0138c2de | 563 | { |
f03fc89f | 564 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
0138c2de | 565 | } |
fb1585ae | 566 | } |
8bbe427f | 567 | |
fb1585ae RR |
568 | if ((m_width != old_width) || (m_height != old_height)) |
569 | { | |
ab2b3dd4 | 570 | /* we set the size in GtkOnSize, i.e. mostly the actual resizing is |
f03fc89f VZ |
571 | done either directly before the frame is shown or in idle time |
572 | so that different calls to SetSize() don't lead to flicker. */ | |
de8113d9 | 573 | m_sizeSet = FALSE; |
fb1585ae | 574 | } |
8bbe427f | 575 | |
fb1585ae | 576 | m_resizing = FALSE; |
903f689b RR |
577 | } |
578 | ||
579 | void wxFrame::Centre( int direction ) | |
580 | { | |
223d09f6 | 581 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 582 | |
43a18898 RR |
583 | int x = 0; |
584 | int y = 0; | |
8bbe427f | 585 | |
f5eafd0e RR |
586 | if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; |
587 | if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
8bbe427f | 588 | |
fb1585ae | 589 | Move( x, y ); |
903f689b RR |
590 | } |
591 | ||
f9241296 | 592 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
c801d85f | 593 | { |
223d09f6 | 594 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 595 | |
f9241296 | 596 | wxWindow::DoGetClientSize( width, height ); |
fb1585ae | 597 | if (height) |
46dc76ba | 598 | { |
41ca191f RR |
599 | /* menu bar */ |
600 | if (m_frameMenuBar) | |
f03fc89f | 601 | { |
88ac883a | 602 | if (!m_menuBarDetached) |
f03fc89f VZ |
603 | (*height) -= wxMENU_HEIGHT; |
604 | else | |
605 | (*height) -= wxPLACE_HOLDER; | |
606 | } | |
88ac883a | 607 | |
dcf924a3 | 608 | #if wxUSE_STATUSBAR |
f03fc89f | 609 | /* status bar */ |
fb1585ae | 610 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; |
dcf924a3 | 611 | #endif |
88ac883a | 612 | |
dcf924a3 | 613 | #if wxUSE_TOOLBAR |
f03fc89f | 614 | /* tool bar */ |
fb1585ae RR |
615 | if (m_frameToolBar) |
616 | { | |
f03fc89f VZ |
617 | if (!m_toolBarDetached) |
618 | { | |
41ca191f RR |
619 | int y = 0; |
620 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
621 | (*height) -= y; | |
f03fc89f VZ |
622 | } |
623 | else | |
41ca191f | 624 | (*height) -= wxPLACE_HOLDER; |
fb1585ae | 625 | } |
dcf924a3 | 626 | #endif |
88ac883a | 627 | |
f03fc89f | 628 | /* mini edge */ |
b2b3ccc5 RR |
629 | (*height) -= m_miniEdge*2 + m_miniTitle; |
630 | } | |
631 | if (width) | |
632 | { | |
633 | (*width) -= m_miniEdge*2; | |
46dc76ba | 634 | } |
362c6693 | 635 | } |
c801d85f | 636 | |
bfc6fde4 | 637 | void wxFrame::DoSetClientSize( int width, int height ) |
b593568e | 638 | { |
223d09f6 | 639 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 640 | |
41ca191f RR |
641 | /* menu bar */ |
642 | if (m_frameMenuBar) | |
f03fc89f | 643 | { |
88ac883a | 644 | if (!m_menuBarDetached) |
f03fc89f VZ |
645 | height += wxMENU_HEIGHT; |
646 | else | |
647 | height += wxPLACE_HOLDER; | |
648 | } | |
88ac883a | 649 | |
dcf924a3 | 650 | #if wxUSE_STATUSBAR |
f03fc89f | 651 | /* status bar */ |
41ca191f | 652 | if (m_frameStatusBar) height += wxSTATUS_HEIGHT; |
dcf924a3 | 653 | #endif |
88ac883a | 654 | |
dcf924a3 | 655 | #if wxUSE_TOOLBAR |
f03fc89f | 656 | /* tool bar */ |
41ca191f RR |
657 | if (m_frameToolBar) |
658 | { | |
f03fc89f VZ |
659 | if (!m_toolBarDetached) |
660 | { | |
41ca191f RR |
661 | int y = 0; |
662 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
663 | height += y; | |
f03fc89f VZ |
664 | } |
665 | else | |
41ca191f RR |
666 | height += wxPLACE_HOLDER; |
667 | } | |
dcf924a3 | 668 | #endif |
88ac883a | 669 | |
41ca191f | 670 | wxWindow::DoSetClientSize( width + m_miniEdge*2, height + m_miniEdge*2 + m_miniTitle ); |
362c6693 | 671 | } |
b593568e | 672 | |
47908e25 | 673 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
c801d85f | 674 | { |
f5368809 RR |
675 | // due to a bug in gtk, x,y are always 0 |
676 | // m_x = x; | |
677 | // m_y = y; | |
678 | ||
ab2b3dd4 | 679 | /* avoid recursions */ |
e52f60e6 RR |
680 | if (m_resizing) return; |
681 | m_resizing = TRUE; | |
8bbe427f | 682 | |
ab2b3dd4 | 683 | /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */ |
223d09f6 | 684 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); |
88ac883a | 685 | |
f5368809 RR |
686 | m_width = width; |
687 | m_height = height; | |
8bbe427f | 688 | |
ab2b3dd4 | 689 | /* space occupied by m_frameToolBar and m_frameMenuBar */ |
88ac883a | 690 | int client_area_y_offset = 0; |
8bbe427f | 691 | |
ab2b3dd4 RR |
692 | /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses |
693 | wxWindow::Create to create it's GTK equivalent. m_mainWidget is only | |
694 | set in wxFrame::Create so it is used to check what kind of frame we | |
695 | have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we | |
696 | skip the part which handles m_frameMenuBar, m_frameToolBar and (most | |
697 | importantly) m_mainWidget */ | |
88ac883a | 698 | |
ab2b3dd4 | 699 | if (m_mainWidget) |
f5368809 | 700 | { |
ab2b3dd4 RR |
701 | /* check if size is in legal range */ |
702 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
703 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
704 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
705 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
706 | ||
707 | /* I revert back to wxGTK's original behaviour. m_mainWidget holds the | |
708 | * menubar, the toolbar and the client area, which is represented by | |
709 | * m_wxwindow. | |
710 | * this hurts in the eye, but I don't want to call SetSize() | |
711 | * because I don't want to call any non-native functions here. */ | |
88ac883a | 712 | |
ab2b3dd4 RR |
713 | if (m_frameMenuBar) |
714 | { | |
715 | int xx = m_miniEdge; | |
716 | int yy = m_miniEdge + m_miniTitle; | |
717 | int ww = m_width - 2*m_miniEdge; | |
41ca191f | 718 | int hh = wxMENU_HEIGHT; |
f03fc89f | 719 | if (m_menuBarDetached) hh = wxPLACE_HOLDER; |
121a3581 RR |
720 | m_frameMenuBar->m_x = xx; |
721 | m_frameMenuBar->m_y = yy; | |
722 | m_frameMenuBar->m_width = ww; | |
723 | m_frameMenuBar->m_height = hh; | |
88ac883a VZ |
724 | gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget), |
725 | m_frameMenuBar->m_widget, | |
f03fc89f VZ |
726 | xx, yy, ww, hh ); |
727 | client_area_y_offset += hh; | |
ab2b3dd4 | 728 | } |
88ac883a | 729 | |
dcf924a3 | 730 | #if wxUSE_TOOLBAR |
ab2b3dd4 RR |
731 | if (m_frameToolBar) |
732 | { | |
733 | int xx = m_miniEdge; | |
734 | int yy = m_miniEdge + m_miniTitle; | |
41ca191f | 735 | if (m_frameMenuBar) |
f03fc89f | 736 | { |
88ac883a VZ |
737 | if (!m_menuBarDetached) |
738 | yy += wxMENU_HEIGHT; | |
739 | else | |
f03fc89f VZ |
740 | yy += wxPLACE_HOLDER; |
741 | } | |
ab2b3dd4 | 742 | int ww = m_width - 2*m_miniEdge; |
a2053b27 | 743 | int hh = m_frameToolBar->m_height; |
88ac883a | 744 | if (m_toolBarDetached) hh = wxPLACE_HOLDER; |
121a3581 RR |
745 | m_frameToolBar->m_x = xx; |
746 | m_frameToolBar->m_y = yy; | |
747 | /* m_frameToolBar->m_height = hh; don't change the toolbar's height */ | |
748 | m_frameToolBar->m_width = ww; | |
88ac883a VZ |
749 | gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget), |
750 | m_frameToolBar->m_widget, | |
f03fc89f VZ |
751 | xx, yy, ww, hh ); |
752 | client_area_y_offset += hh; | |
ab2b3dd4 | 753 | } |
dcf924a3 | 754 | #endif |
88ac883a | 755 | |
32a95f9f | 756 | int client_x = m_miniEdge; |
f03fc89f | 757 | int client_y = client_area_y_offset + m_miniEdge + m_miniTitle; |
32a95f9f | 758 | int client_w = m_width - 2*m_miniEdge; |
f03fc89f | 759 | int client_h = m_height - client_area_y_offset- 2*m_miniEdge - m_miniTitle; |
88ac883a VZ |
760 | gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget), |
761 | m_wxwindow, | |
f03fc89f | 762 | client_x, client_y, client_w, client_h ); |
32a95f9f RR |
763 | } |
764 | else | |
765 | { | |
766 | /* if there is no m_mainWidget between m_widget and m_wxwindow there | |
f03fc89f | 767 | is no need to set the size or position of m_wxwindow. */ |
f5368809 | 768 | } |
88ac883a | 769 | |
dcf924a3 | 770 | #if wxUSE_STATUSBAR |
f5368809 RR |
771 | if (m_frameStatusBar) |
772 | { | |
b2b3ccc5 | 773 | int xx = 0 + m_miniEdge; |
f362b96d | 774 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset; |
ac57418f RR |
775 | int ww = m_width - 2*m_miniEdge; |
776 | int hh = wxSTATUS_HEIGHT; | |
121a3581 RR |
777 | m_frameStatusBar->m_x = xx; |
778 | m_frameStatusBar->m_y = yy; | |
779 | m_frameStatusBar->m_width = ww; | |
780 | m_frameStatusBar->m_height = hh; | |
88ac883a VZ |
781 | gtk_myfixed_set_size( GTK_MYFIXED(m_wxwindow), |
782 | m_frameStatusBar->m_widget, | |
f03fc89f | 783 | xx, yy, ww, hh ); |
f5368809 | 784 | } |
dcf924a3 | 785 | #endif |
8bbe427f | 786 | |
de8113d9 RR |
787 | /* we actually set the size of a frame here and no-where else */ |
788 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
88ac883a | 789 | |
8bbe427f | 790 | |
54517652 RR |
791 | m_sizeSet = TRUE; |
792 | ||
793 | // send size event to frame | |
43a18898 RR |
794 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
795 | event.SetEventObject( this ); | |
e52f60e6 | 796 | GetEventHandler()->ProcessEvent( event ); |
8bbe427f | 797 | |
54517652 | 798 | // send size event to status bar |
5aa5e35a RR |
799 | if (m_frameStatusBar) |
800 | { | |
a2053b27 | 801 | wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); |
5aa5e35a RR |
802 | event2.SetEventObject( m_frameStatusBar ); |
803 | m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); | |
804 | } | |
884470b1 | 805 | |
e52f60e6 RR |
806 | m_resizing = FALSE; |
807 | } | |
808 | ||
ca26177c RR |
809 | void wxFrame::MakeModal( bool modal ) |
810 | { | |
811 | if (modal) | |
ca26177c | 812 | gtk_grab_add( m_widget ); |
ca26177c | 813 | else |
c25ccf85 | 814 | gtk_grab_remove( m_widget ); |
ca26177c RR |
815 | } |
816 | ||
9390a202 | 817 | void wxFrame::OnInternalIdle() |
e52f60e6 | 818 | { |
1b3667ab | 819 | if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow)) |
54517652 | 820 | { |
e52f60e6 | 821 | GtkOnSize( m_x, m_y, m_width, m_height ); |
54517652 RR |
822 | |
823 | // we'll come back later | |
824 | if (g_isIdle) | |
825 | wxapp_install_idle_handler(); | |
826 | return; | |
827 | } | |
88ac883a | 828 | |
082b2798 | 829 | if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); |
dcf924a3 | 830 | #if wxUSE_TOOLBAR |
082b2798 | 831 | if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); |
dcf924a3 RR |
832 | #endif |
833 | #if wxUSE_STATUSBAR | |
082b2798 | 834 | if (m_frameStatusBar) m_frameStatusBar->OnInternalIdle(); |
dcf924a3 | 835 | #endif |
5e014a0c RR |
836 | |
837 | wxWindow::OnInternalIdle(); | |
362c6693 | 838 | } |
c801d85f | 839 | |
6bc8a1c8 | 840 | void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) ) |
fe4e9e6c | 841 | { |
e3065973 | 842 | Destroy(); |
fe4e9e6c VZ |
843 | } |
844 | ||
c801d85f KB |
845 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) |
846 | { | |
223d09f6 | 847 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 848 | |
88ac883a | 849 | #if wxUSE_CONSTRAINTS |
f5368809 RR |
850 | if (GetAutoLayout()) |
851 | { | |
852 | Layout(); | |
853 | } | |
8bbe427f | 854 | else |
88ac883a | 855 | #endif // wxUSE_CONSTRAINTS |
c801d85f | 856 | { |
ab46dc18 | 857 | /* do we have exactly one child? */ |
0138c2de VZ |
858 | wxWindow *child = (wxWindow *)NULL; |
859 | for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) | |
f5368809 RR |
860 | { |
861 | wxWindow *win = (wxWindow *)node->Data(); | |
0138c2de | 862 | if ( !wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) ) |
f5368809 | 863 | { |
ab46dc18 | 864 | if (child) |
0138c2de | 865 | { |
ab46dc18 | 866 | /* it's the second one: do nothing */ |
0138c2de VZ |
867 | return; |
868 | } | |
869 | ||
f5368809 RR |
870 | child = win; |
871 | } | |
872 | } | |
ed7a557b | 873 | |
ab46dc18 RR |
874 | /* no children at all? */ |
875 | if (child) | |
0138c2de | 876 | { |
ab46dc18 | 877 | /* yes: set it's size to fill all the frame */ |
0138c2de | 878 | int client_x, client_y; |
326f9654 | 879 | DoGetClientSize( &client_x, &client_y ); |
0138c2de VZ |
880 | child->SetSize( 1, 1, client_x-2, client_y-2 ); |
881 | } | |
362c6693 | 882 | } |
362c6693 | 883 | } |
c801d85f | 884 | |
c801d85f KB |
885 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) |
886 | { | |
223d09f6 KB |
887 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
888 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); | |
8bbe427f | 889 | |
f5368809 | 890 | m_frameMenuBar = menuBar; |
8bbe427f | 891 | |
f5368809 | 892 | if (m_frameMenuBar) |
30dea054 | 893 | { |
5bd9e519 | 894 | m_frameMenuBar->SetInvokingWindow( this ); |
8bbe427f | 895 | |
f03fc89f | 896 | if (m_frameMenuBar->GetParent() != this) |
f5368809 | 897 | { |
f03fc89f | 898 | m_frameMenuBar->SetParent(this); |
f362b96d | 899 | gtk_myfixed_put( GTK_MYFIXED(m_mainWidget), |
88ac883a VZ |
900 | m_frameMenuBar->m_widget, |
901 | m_frameMenuBar->m_x, | |
a2053b27 RR |
902 | m_frameMenuBar->m_y, |
903 | m_frameMenuBar->m_width, | |
904 | m_frameMenuBar->m_height ); | |
88ac883a | 905 | |
f03fc89f VZ |
906 | if (menuBar->GetWindowStyle() & wxMB_DOCKABLE) |
907 | { | |
a2053b27 | 908 | gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_attached", |
16bcc879 | 909 | GTK_SIGNAL_FUNC(gtk_menu_attached_callback), (gpointer)this ); |
88ac883a | 910 | |
a2053b27 | 911 | gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_detached", |
16bcc879 | 912 | GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this ); |
f03fc89f | 913 | } |
5bd9e519 RR |
914 | |
915 | m_frameMenuBar->Show( TRUE ); | |
f5368809 | 916 | } |
716b7364 | 917 | } |
8bbe427f | 918 | |
1e133b7d | 919 | /* resize window in OnInternalIdle */ |
5b077d48 | 920 | m_sizeSet = FALSE; |
362c6693 | 921 | } |
c801d85f | 922 | |
8bbe427f | 923 | wxMenuBar *wxFrame::GetMenuBar() const |
46dc76ba | 924 | { |
f5368809 | 925 | return m_frameMenuBar; |
362c6693 | 926 | } |
46dc76ba | 927 | |
342b6a2f RR |
928 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) |
929 | { | |
88ac883a | 930 | #if wxUSE_STATUSBAR |
342b6a2f RR |
931 | if (GetStatusBar()) |
932 | { | |
0138c2de VZ |
933 | // if no help string found, we will clear the status bar text |
934 | wxString helpString; | |
935 | ||
936 | int menuId = event.GetMenuId(); | |
937 | if ( menuId != -1 ) | |
342b6a2f RR |
938 | { |
939 | wxMenuBar *menuBar = GetMenuBar(); | |
940 | if (menuBar) | |
941 | { | |
342b6a2f | 942 | helpString = menuBar->GetHelpString(menuId); |
342b6a2f RR |
943 | } |
944 | } | |
0138c2de VZ |
945 | |
946 | SetStatusText(helpString); | |
342b6a2f | 947 | } |
88ac883a | 948 | #endif // wxUSE_STATUSBAR |
342b6a2f RR |
949 | } |
950 | ||
88ac883a | 951 | #if wxUSE_TOOLBAR |
6bc8a1c8 | 952 | wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 953 | { |
223d09f6 | 954 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 955 | |
223d09f6 | 956 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, wxT("recreating toolbar in wxFrame") ); |
362c6693 | 957 | |
6bc8a1c8 | 958 | m_insertInClientArea = FALSE; |
88ac883a | 959 | |
f5368809 | 960 | m_frameToolBar = OnCreateToolBar( style, id, name ); |
8bbe427f | 961 | |
6bc8a1c8 | 962 | if (m_frameToolBar) GetChildren().DeleteObject( m_frameToolBar ); |
88ac883a | 963 | |
6bc8a1c8 | 964 | m_insertInClientArea = TRUE; |
8bbe427f | 965 | |
5b077d48 | 966 | m_sizeSet = FALSE; |
8bbe427f | 967 | |
f5368809 | 968 | return m_frameToolBar; |
362c6693 | 969 | } |
46dc76ba | 970 | |
362c6693 | 971 | wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 972 | { |
f5368809 | 973 | return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); |
362c6693 RR |
974 | } |
975 | ||
307f16e8 RR |
976 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
977 | { | |
978 | m_frameToolBar = toolbar; | |
979 | if (m_frameToolBar) | |
980 | { | |
981 | /* insert into toolbar area if not already there */ | |
982 | if (m_frameToolBar->m_widget->parent != m_mainWidget) | |
983 | { | |
984 | gtk_widget_ref( m_frameToolBar->m_widget ); | |
985 | gtk_widget_unparent( m_frameToolBar->m_widget ); | |
986 | ||
987 | m_insertInClientArea = TRUE; | |
988 | wxInsertChildInFrame( this, m_frameToolBar ); | |
989 | m_insertInClientArea = FALSE; | |
990 | ||
991 | gtk_widget_unref( m_frameToolBar->m_widget ); | |
992 | } | |
993 | } | |
994 | } | |
995 | ||
8bbe427f VZ |
996 | wxToolBar *wxFrame::GetToolBar() const |
997 | { | |
998 | return m_frameToolBar; | |
362c6693 | 999 | } |
88ac883a | 1000 | #endif // wxUSE_TOOLBAR |
46dc76ba | 1001 | |
88ac883a | 1002 | #if wxUSE_STATUSBAR |
e3e65dac | 1003 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) |
c801d85f | 1004 | { |
223d09f6 | 1005 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1006 | |
223d09f6 | 1007 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, wxT("recreating status bar in wxFrame") ); |
c801d85f | 1008 | |
f5368809 | 1009 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); |
8bbe427f | 1010 | |
5b077d48 | 1011 | m_sizeSet = FALSE; |
8bbe427f | 1012 | |
f5368809 | 1013 | return m_frameStatusBar; |
362c6693 RR |
1014 | } |
1015 | ||
1016 | wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
1017 | { | |
f5368809 | 1018 | wxStatusBar *statusBar = (wxStatusBar *) NULL; |
8bbe427f | 1019 | |
f5368809 | 1020 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name); |
8bbe427f | 1021 | |
f5368809 RR |
1022 | // Set the height according to the font and the border size |
1023 | wxClientDC dc(statusBar); | |
8bbe427f | 1024 | dc.SetFont( statusBar->GetFont() ); |
362c6693 | 1025 | |
f5368809 RR |
1026 | long x, y; |
1027 | dc.GetTextExtent( "X", &x, &y ); | |
362c6693 | 1028 | |
f5368809 | 1029 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); |
362c6693 | 1030 | |
f5368809 | 1031 | statusBar->SetSize( -1, -1, 100, height ); |
362c6693 | 1032 | |
f5368809 RR |
1033 | statusBar->SetFieldsCount( number ); |
1034 | return statusBar; | |
362c6693 | 1035 | } |
c801d85f | 1036 | |
88ac883a | 1037 | wxStatusBar *wxFrame::GetStatusBar() const |
30f1b5f3 | 1038 | { |
88ac883a | 1039 | return m_frameStatusBar; |
30f1b5f3 RR |
1040 | } |
1041 | ||
362c6693 | 1042 | void wxFrame::SetStatusText(const wxString& text, int number) |
c801d85f | 1043 | { |
223d09f6 | 1044 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1045 | |
223d09f6 | 1046 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set text for") ); |
c801d85f | 1047 | |
f5368809 | 1048 | m_frameStatusBar->SetStatusText(text, number); |
362c6693 RR |
1049 | } |
1050 | ||
1051 | void wxFrame::SetStatusWidths(int n, const int widths_field[] ) | |
c801d85f | 1052 | { |
223d09f6 | 1053 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1054 | |
223d09f6 | 1055 | wxCHECK_RET( m_frameStatusBar != NULL, wxT("no statusbar to set widths for") ); |
362c6693 | 1056 | |
f5368809 | 1057 | m_frameStatusBar->SetStatusWidths(n, widths_field); |
362c6693 | 1058 | } |
88ac883a | 1059 | #endif // wxUSE_STATUSBAR |
c801d85f | 1060 | |
88ac883a | 1061 | void wxFrame::Command( int id ) |
c801d85f | 1062 | { |
88ac883a VZ |
1063 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); |
1064 | commandEvent.SetInt( id ); | |
1065 | commandEvent.SetEventObject( this ); | |
1066 | ||
1067 | wxMenuBar *bar = GetMenuBar(); | |
1068 | if (!bar) return; | |
1069 | ||
1070 | wxMenuItem *item = bar->FindItemForId(id) ; | |
1071 | if (item && item->IsCheckable()) | |
1072 | { | |
1073 | bar->Check(id,!bar->Checked(id)) ; | |
1074 | } | |
1075 | ||
1076 | wxEvtHandler* evtHandler = GetEventHandler(); | |
1077 | ||
1078 | evtHandler->ProcessEvent(commandEvent); | |
362c6693 | 1079 | } |
c801d85f | 1080 | |
c801d85f KB |
1081 | void wxFrame::SetTitle( const wxString &title ) |
1082 | { | |
223d09f6 | 1083 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1084 | |
f5368809 | 1085 | m_title = title; |
223d09f6 | 1086 | if (m_title.IsNull()) m_title = wxT(""); |
ed9b9841 | 1087 | gtk_window_set_title( GTK_WINDOW(m_widget), title.mbc_str() ); |
362c6693 | 1088 | } |
c801d85f | 1089 | |
d355d3fe RR |
1090 | void wxFrame::SetIcon( const wxIcon &icon ) |
1091 | { | |
223d09f6 | 1092 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
8bbe427f | 1093 | |
f5368809 RR |
1094 | m_icon = icon; |
1095 | if (!icon.Ok()) return; | |
8bbe427f | 1096 | |
58dea4b0 RR |
1097 | if (!m_widget->window) return; |
1098 | ||
f5368809 RR |
1099 | wxMask *mask = icon.GetMask(); |
1100 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
1101 | if (mask) bm = mask->GetBitmap(); | |
8bbe427f | 1102 | |
f5368809 | 1103 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
d355d3fe | 1104 | } |
b2b3ccc5 | 1105 | |
cd25b18c RR |
1106 | void wxFrame::Maximize(bool WXUNUSED(maximize)) |
1107 | { | |
1108 | } | |
1109 | ||
1110 | void wxFrame::Restore() | |
1111 | { | |
1112 | } | |
1113 | ||
1114 | void wxFrame::Iconize( bool iconize ) | |
1115 | { | |
1116 | if (iconize) | |
1117 | { | |
1118 | XIconifyWindow( GDK_WINDOW_XDISPLAY( m_widget->window ), | |
1119 | GDK_WINDOW_XWINDOW( m_widget->window ), | |
1120 | DefaultScreen( GDK_DISPLAY() ) ); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | bool wxFrame::IsIconized() const | |
1125 | { | |
1126 | return FALSE; | |
1127 | } |