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