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