]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 1998 Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "frame.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/frame.h" | |
15 | #include "wx/dialog.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/app.h" | |
18 | #include "wx/menu.h" | |
19 | #include "wx/toolbar.h" | |
20 | #include "wx/statusbr.h" | |
21 | #include "wx/dcclient.h" | |
22 | ||
23 | #include "glib.h" | |
24 | #include "gdk/gdk.h" | |
25 | #include "gtk/gtk.h" | |
26 | #include "wx/gtk/win_gtk.h" | |
27 | ||
28 | //----------------------------------------------------------------------------- | |
29 | // constants | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | const int wxMENU_HEIGHT = 27; | |
33 | const int wxSTATUS_HEIGHT = 25; | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
36 | // data | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
39 | extern wxList wxPendingDelete; | |
40 | ||
41 | //----------------------------------------------------------------------------- | |
42 | // "size_allocate" | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) | |
46 | { | |
47 | if (!win->HasVMT()) return; | |
48 | ||
49 | /* | |
50 | printf( "OnFrameResize from " ); | |
51 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
52 | printf( win->GetClassInfo()->GetClassName() ); | |
53 | printf( ".\n" ); | |
54 | */ | |
55 | ||
56 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) | |
57 | { | |
58 | win->m_sizeSet = FALSE; | |
59 | win->m_width = alloc->width; | |
60 | win->m_height = alloc->height; | |
61 | } | |
62 | } | |
63 | ||
64 | //----------------------------------------------------------------------------- | |
65 | // "delete_event" | |
66 | //----------------------------------------------------------------------------- | |
67 | ||
68 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) | |
69 | { | |
70 | /* | |
71 | printf( "OnDelete from " ); | |
72 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
73 | printf( win->GetClassInfo()->GetClassName() ); | |
74 | printf( ".\n" ); | |
75 | */ | |
76 | ||
77 | win->Close(); | |
78 | ||
79 | return TRUE; | |
80 | } | |
81 | ||
82 | //----------------------------------------------------------------------------- | |
83 | // "configure_event" | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) | |
87 | { | |
88 | if (!win->HasVMT()) return FALSE; | |
89 | ||
90 | win->m_x = event->x; | |
91 | win->m_y = event->y; | |
92 | ||
93 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); | |
94 | mevent.SetEventObject( win ); | |
95 | win->GetEventHandler()->ProcessEvent( mevent ); | |
96 | ||
97 | return FALSE; | |
98 | } | |
99 | ||
100 | //----------------------------------------------------------------------------- | |
101 | // wxFrame | |
102 | //----------------------------------------------------------------------------- | |
103 | ||
104 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
105 | EVT_SIZE(wxFrame::OnSize) | |
106 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
107 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) | |
108 | END_EVENT_TABLE() | |
109 | ||
110 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
111 | ||
112 | wxFrame::wxFrame() | |
113 | { | |
114 | m_frameMenuBar = (wxMenuBar *) NULL; | |
115 | m_mdiMenuBar = (wxMenuBar *) NULL; | |
116 | m_frameStatusBar = (wxStatusBar *) NULL; | |
117 | m_frameToolBar = (wxToolBar *) NULL; | |
118 | m_sizeSet = FALSE; | |
119 | m_miniEdge = 0; | |
120 | m_miniTitle = 0; | |
121 | } | |
122 | ||
123 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, | |
124 | const wxPoint &pos, const wxSize &size, | |
125 | long style, const wxString &name ) | |
126 | { | |
127 | m_frameMenuBar = (wxMenuBar *) NULL; | |
128 | m_mdiMenuBar = (wxMenuBar *) NULL; | |
129 | m_frameStatusBar = (wxStatusBar *) NULL; | |
130 | m_frameToolBar = (wxToolBar *) NULL; | |
131 | m_sizeSet = FALSE; | |
132 | m_miniEdge = 0; | |
133 | m_miniTitle = 0; | |
134 | Create( parent, id, title, pos, size, style, name ); | |
135 | } | |
136 | ||
137 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, | |
138 | const wxPoint &pos, const wxSize &size, | |
139 | long style, const wxString &name ) | |
140 | { | |
141 | wxTopLevelWindows.Append( this ); | |
142 | ||
143 | m_needParent = FALSE; | |
144 | ||
145 | PreCreation( parent, id, pos, size, style, name ); | |
146 | ||
147 | m_title = title; | |
148 | ||
149 | GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; | |
150 | if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; | |
151 | ||
152 | m_widget = gtk_window_new( win_type ); | |
153 | ||
154 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
155 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
156 | ||
157 | gtk_window_set_policy( GTK_WINDOW(m_widget), 1, 1, 0 ); | |
158 | ||
159 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
160 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
161 | ||
162 | m_wxwindow = gtk_myfixed_new(); | |
163 | gtk_widget_show( m_wxwindow ); | |
164 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
165 | ||
166 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); | |
167 | ||
168 | if (m_parent) m_parent->AddChild( this ); | |
169 | ||
170 | PostCreation(); | |
171 | ||
172 | gtk_widget_realize( m_widget ); | |
173 | ||
174 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", | |
175 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
176 | ||
177 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", | |
178 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
179 | ||
180 | return TRUE; | |
181 | } | |
182 | ||
183 | wxFrame::~wxFrame() | |
184 | { | |
185 | if (m_frameMenuBar) delete m_frameMenuBar; | |
186 | m_frameMenuBar = (wxMenuBar *) NULL; | |
187 | ||
188 | if (m_frameStatusBar) delete m_frameStatusBar; | |
189 | m_frameStatusBar = (wxStatusBar *) NULL; | |
190 | ||
191 | if (m_frameToolBar) delete m_frameToolBar; | |
192 | m_frameToolBar = (wxToolBar *) NULL; | |
193 | ||
194 | wxTopLevelWindows.DeleteObject( this ); | |
195 | ||
196 | if (wxTheApp->GetTopWindow() == this) | |
197 | { | |
198 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); | |
199 | } | |
200 | ||
201 | if (wxTopLevelWindows.Number() == 0) | |
202 | { | |
203 | wxTheApp->ExitMainLoop(); | |
204 | } | |
205 | } | |
206 | ||
207 | bool wxFrame::Show( bool show ) | |
208 | { | |
209 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
210 | ||
211 | if (show && !m_sizeSet) | |
212 | { | |
213 | /* by calling GtkOnSize here, we don't have to call | |
214 | either after showing the frame, which would entail | |
215 | much ugly flicker nor from within the size_allocate | |
216 | handler, because GTK 1.1.X forbids that. */ | |
217 | ||
218 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
219 | } | |
220 | ||
221 | return wxWindow::Show( show ); | |
222 | } | |
223 | ||
224 | bool wxFrame::Destroy() | |
225 | { | |
226 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
227 | ||
228 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); | |
229 | ||
230 | return TRUE; | |
231 | } | |
232 | ||
233 | wxPoint wxFrame::GetClientAreaOrigin() const | |
234 | { | |
235 | wxPoint pt( m_miniEdge, m_miniEdge + m_miniTitle ); | |
236 | if (m_frameMenuBar) | |
237 | { | |
238 | int h = 0; | |
239 | m_frameMenuBar->GetSize( (int*)NULL, &h ); | |
240 | pt.y += h; | |
241 | } | |
242 | if (m_frameToolBar) | |
243 | { | |
244 | int h = 0; | |
245 | m_frameToolBar->GetSize( (int*)NULL, &h ); | |
246 | pt.y += h; | |
247 | } | |
248 | return pt; | |
249 | } | |
250 | ||
251 | void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags ) | |
252 | { | |
253 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
254 | ||
255 | /* don't do anything for children of wxMDIChildFrame */ | |
256 | if (!m_wxwindow) return; | |
257 | ||
258 | if (m_resizing) return; // I don't like recursions | |
259 | m_resizing = TRUE; | |
260 | ||
261 | int old_x = m_x; | |
262 | int old_y = m_y; | |
263 | int old_width = m_width; | |
264 | int old_height = m_height; | |
265 | ||
266 | if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) | |
267 | { | |
268 | if (x != -1) m_x = x; | |
269 | if (y != -1) m_y = y; | |
270 | if (width != -1) m_width = width; | |
271 | if (height != -1) m_height = height; | |
272 | } | |
273 | else | |
274 | { | |
275 | m_x = x; | |
276 | m_y = y; | |
277 | m_width = width; | |
278 | m_height = height; | |
279 | } | |
280 | ||
281 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
282 | { | |
283 | if (width == -1) m_width = 80; | |
284 | } | |
285 | ||
286 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
287 | { | |
288 | if (height == -1) m_height = 26; | |
289 | } | |
290 | ||
291 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
292 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
293 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
294 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
295 | ||
296 | if ((m_x != -1) || (m_y != -1)) | |
297 | { | |
298 | if ((m_x != old_x) || (m_y != old_y)) | |
299 | { | |
300 | /* m_sizeSet = FALSE; */ | |
301 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
302 | } | |
303 | } | |
304 | ||
305 | if ((m_width != old_width) || (m_height != old_height)) | |
306 | { | |
307 | /* we set the size in GtkOnSize */ | |
308 | m_sizeSet = FALSE; | |
309 | } | |
310 | ||
311 | m_resizing = FALSE; | |
312 | } | |
313 | ||
314 | void wxFrame::Centre( int direction ) | |
315 | { | |
316 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
317 | ||
318 | int x = 0; | |
319 | int y = 0; | |
320 | ||
321 | if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; | |
322 | if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
323 | ||
324 | Move( x, y ); | |
325 | } | |
326 | ||
327 | void wxFrame::GetClientSize( int *width, int *height ) const | |
328 | { | |
329 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
330 | ||
331 | wxWindow::GetClientSize( width, height ); | |
332 | if (height) | |
333 | { | |
334 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; | |
335 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
336 | if (m_frameToolBar) | |
337 | { | |
338 | int y = 0; | |
339 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
340 | (*height) -= y; | |
341 | } | |
342 | (*height) -= m_miniEdge*2 + m_miniTitle; | |
343 | } | |
344 | if (width) | |
345 | { | |
346 | (*width) -= m_miniEdge*2; | |
347 | } | |
348 | } | |
349 | ||
350 | void wxFrame::DoSetClientSize( int width, int height ) | |
351 | { | |
352 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
353 | ||
354 | int h = height; | |
355 | if (m_frameMenuBar) h += wxMENU_HEIGHT; | |
356 | if (m_frameStatusBar) h += wxSTATUS_HEIGHT; | |
357 | if (m_frameToolBar) | |
358 | { | |
359 | int y = 0; | |
360 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
361 | h += y; | |
362 | } | |
363 | wxWindow::DoSetClientSize( width + m_miniEdge*2, h + m_miniEdge*2 + m_miniTitle ); | |
364 | } | |
365 | ||
366 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) | |
367 | { | |
368 | // due to a bug in gtk, x,y are always 0 | |
369 | // m_x = x; | |
370 | // m_y = y; | |
371 | ||
372 | if (m_resizing) return; | |
373 | m_resizing = TRUE; | |
374 | ||
375 | if (!m_wxwindow) return; | |
376 | ||
377 | m_width = width; | |
378 | m_height = height; | |
379 | ||
380 | /* check if size is in legal range */ | |
381 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; | |
382 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
383 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; | |
384 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
385 | ||
386 | /* this emulates the new wxMSW behaviour of placing all | |
387 | * frame-subwindows (menu, toolbar..) on one native window | |
388 | * this hurts in the eye, but I don't want to call SetSize() | |
389 | * because I don't want to call any non-native functions here. */ | |
390 | ||
391 | if (m_frameMenuBar) | |
392 | { | |
393 | int xx = m_miniEdge; | |
394 | int yy = m_miniEdge + m_miniTitle; | |
395 | int ww = m_width - 2*m_miniEdge; | |
396 | int hh = wxMENU_HEIGHT; | |
397 | m_frameMenuBar->m_x = xx; | |
398 | m_frameMenuBar->m_y = yy; | |
399 | m_frameMenuBar->m_width = ww; | |
400 | m_frameMenuBar->m_height = hh; | |
401 | ||
402 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, xx, yy ); | |
403 | gtk_widget_set_usize( m_frameMenuBar->m_widget, ww, hh ); | |
404 | } | |
405 | ||
406 | if (m_frameToolBar) | |
407 | { | |
408 | int xx = m_miniEdge; | |
409 | int yy = m_miniEdge + m_miniTitle; | |
410 | if ((m_frameMenuBar) || (m_mdiMenuBar)) yy += wxMENU_HEIGHT; | |
411 | int ww = m_width - 2*m_miniEdge; | |
412 | int hh = m_frameToolBar->m_height; | |
413 | ||
414 | m_frameToolBar->m_x = xx; | |
415 | m_frameToolBar->m_y = yy; | |
416 | m_frameToolBar->m_height = hh; | |
417 | m_frameToolBar->m_width = ww; | |
418 | ||
419 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, xx, yy ); | |
420 | gtk_widget_set_usize( m_frameToolBar->m_widget, ww, hh ); | |
421 | } | |
422 | ||
423 | if (m_frameStatusBar) | |
424 | { | |
425 | int xx = 0 + m_miniEdge; | |
426 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge; | |
427 | int ww = m_width - 2*m_miniEdge; | |
428 | int hh = wxSTATUS_HEIGHT; | |
429 | ||
430 | m_frameStatusBar->m_x = xx; | |
431 | m_frameStatusBar->m_y = yy; | |
432 | m_frameStatusBar->m_width = ww; | |
433 | m_frameStatusBar->m_height = hh; | |
434 | ||
435 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, xx, yy ); | |
436 | gtk_widget_set_usize( m_frameStatusBar->m_widget, ww, hh ); | |
437 | } | |
438 | ||
439 | /* we actually set the size of a frame here and no-where else */ | |
440 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
441 | ||
442 | m_sizeSet = TRUE; | |
443 | ||
444 | /* send size event to frame */ | |
445 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
446 | event.SetEventObject( this ); | |
447 | GetEventHandler()->ProcessEvent( event ); | |
448 | ||
449 | /* send size event to status bar */ | |
450 | if (m_frameStatusBar) | |
451 | { | |
452 | wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); | |
453 | event2.SetEventObject( m_frameStatusBar ); | |
454 | m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); | |
455 | } | |
456 | ||
457 | m_resizing = FALSE; | |
458 | } | |
459 | ||
460 | void wxFrame::OnInternalIdle() | |
461 | { | |
462 | if (!m_sizeSet) | |
463 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
464 | ||
465 | DoMenuUpdates(); | |
466 | } | |
467 | ||
468 | void wxFrame::OnCloseWindow( wxCloseEvent& event ) | |
469 | { | |
470 | // close the window if it wasn't vetoed by the application | |
471 | // if ( !event.GetVeto() ) // No, this isn't the interpretation of GetVeto. | |
472 | Destroy(); | |
473 | } | |
474 | ||
475 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
476 | { | |
477 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
478 | ||
479 | if (GetAutoLayout()) | |
480 | { | |
481 | Layout(); | |
482 | } | |
483 | else | |
484 | { | |
485 | // do we have exactly one child? | |
486 | wxWindow *child = (wxWindow *)NULL; | |
487 | for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) | |
488 | { | |
489 | wxWindow *win = (wxWindow *)node->Data(); | |
490 | if ( !wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) ) | |
491 | { | |
492 | if ( child ) | |
493 | { | |
494 | // it's the second one: do nothing | |
495 | return; | |
496 | } | |
497 | ||
498 | child = win; | |
499 | } | |
500 | } | |
501 | ||
502 | // no children at all? | |
503 | if ( child ) | |
504 | { | |
505 | // yes: set it's size to fill all the frame | |
506 | int client_x, client_y; | |
507 | GetClientSize( &client_x, &client_y ); | |
508 | child->SetSize( 1, 1, client_x-2, client_y-2 ); | |
509 | } | |
510 | } | |
511 | } | |
512 | ||
513 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) | |
514 | { | |
515 | menu->SetInvokingWindow( win ); | |
516 | wxNode *node = menu->GetItems().First(); | |
517 | while (node) | |
518 | { | |
519 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
520 | if (menuitem->IsSubMenu()) | |
521 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
522 | node = node->Next(); | |
523 | } | |
524 | } | |
525 | ||
526 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
527 | { | |
528 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
529 | wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); | |
530 | ||
531 | m_frameMenuBar = menuBar; | |
532 | ||
533 | if (m_frameMenuBar) | |
534 | { | |
535 | wxNode *node = m_frameMenuBar->GetMenus().First(); | |
536 | while (node) | |
537 | { | |
538 | wxMenu *menu = (wxMenu*)node->Data(); | |
539 | SetInvokingWindow( menu, this ); | |
540 | node = node->Next(); | |
541 | } | |
542 | ||
543 | if (m_frameMenuBar->m_parent != this) | |
544 | { | |
545 | m_frameMenuBar->m_parent = this; | |
546 | gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), | |
547 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); | |
548 | ||
549 | /* an mdi child menu bar might be underneath */ | |
550 | if (m_mdiMenuBar) | |
551 | m_frameMenuBar->Show( FALSE ); | |
552 | } | |
553 | } | |
554 | ||
555 | m_sizeSet = FALSE; | |
556 | } | |
557 | ||
558 | wxMenuBar *wxFrame::GetMenuBar() const | |
559 | { | |
560 | return m_frameMenuBar; | |
561 | } | |
562 | ||
563 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) | |
564 | { | |
565 | if (GetStatusBar()) | |
566 | { | |
567 | // if no help string found, we will clear the status bar text | |
568 | wxString helpString; | |
569 | ||
570 | int menuId = event.GetMenuId(); | |
571 | if ( menuId != -1 ) | |
572 | { | |
573 | wxMenuBar *menuBar = GetMenuBar(); | |
574 | if (menuBar) | |
575 | { | |
576 | helpString = menuBar->GetHelpString(menuId); | |
577 | } | |
578 | } | |
579 | ||
580 | SetStatusText(helpString); | |
581 | } | |
582 | } | |
583 | ||
584 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
585 | { | |
586 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
587 | ||
588 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" ); | |
589 | ||
590 | m_frameToolBar = OnCreateToolBar( style, id, name ); | |
591 | ||
592 | GetChildren().DeleteObject( m_frameToolBar ); | |
593 | ||
594 | m_sizeSet = FALSE; | |
595 | ||
596 | return m_frameToolBar; | |
597 | } | |
598 | ||
599 | wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name ) | |
600 | { | |
601 | return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); | |
602 | } | |
603 | ||
604 | wxToolBar *wxFrame::GetToolBar() const | |
605 | { | |
606 | return m_frameToolBar; | |
607 | } | |
608 | ||
609 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
610 | { | |
611 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
612 | ||
613 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, "recreating status bar in wxFrame" ); | |
614 | ||
615 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); | |
616 | ||
617 | m_sizeSet = FALSE; | |
618 | ||
619 | return m_frameStatusBar; | |
620 | } | |
621 | ||
622 | wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
623 | { | |
624 | wxStatusBar *statusBar = (wxStatusBar *) NULL; | |
625 | ||
626 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name); | |
627 | ||
628 | // Set the height according to the font and the border size | |
629 | wxClientDC dc(statusBar); | |
630 | dc.SetFont( statusBar->GetFont() ); | |
631 | ||
632 | long x, y; | |
633 | dc.GetTextExtent( "X", &x, &y ); | |
634 | ||
635 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); | |
636 | ||
637 | statusBar->SetSize( -1, -1, 100, height ); | |
638 | ||
639 | statusBar->SetFieldsCount( number ); | |
640 | return statusBar; | |
641 | } | |
642 | ||
643 | void wxFrame::Command( int id ) | |
644 | { | |
645 | wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id); | |
646 | commandEvent.SetInt( id ); | |
647 | commandEvent.SetEventObject( this ); | |
648 | ||
649 | wxMenuBar *bar = GetMenuBar(); | |
650 | if (!bar) return; | |
651 | ||
652 | wxMenuItem *item = bar->FindItemForId(id) ; | |
653 | if (item && item->IsCheckable()) | |
654 | { | |
655 | bar->Check(id,!bar->Checked(id)) ; | |
656 | } | |
657 | GetEventHandler()->ProcessEvent(commandEvent); | |
658 | } | |
659 | ||
660 | void wxFrame::SetStatusText(const wxString& text, int number) | |
661 | { | |
662 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
663 | ||
664 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); | |
665 | ||
666 | m_frameStatusBar->SetStatusText(text, number); | |
667 | } | |
668 | ||
669 | void wxFrame::SetStatusWidths(int n, const int widths_field[] ) | |
670 | { | |
671 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
672 | ||
673 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); | |
674 | ||
675 | m_frameStatusBar->SetStatusWidths(n, widths_field); | |
676 | } | |
677 | ||
678 | wxStatusBar *wxFrame::GetStatusBar() const | |
679 | { | |
680 | return m_frameStatusBar; | |
681 | } | |
682 | ||
683 | void wxFrame::SetTitle( const wxString &title ) | |
684 | { | |
685 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
686 | ||
687 | m_title = title; | |
688 | if (m_title.IsNull()) m_title = ""; | |
689 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
690 | } | |
691 | ||
692 | void wxFrame::SetIcon( const wxIcon &icon ) | |
693 | { | |
694 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); | |
695 | ||
696 | m_icon = icon; | |
697 | if (!icon.Ok()) return; | |
698 | ||
699 | wxMask *mask = icon.GetMask(); | |
700 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
701 | if (mask) bm = mask->GetBitmap(); | |
702 | ||
703 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); | |
704 | } | |
705 |