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