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