]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
19717c50 | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "frame.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/frame.h" | |
16 | #include "wx/dialog.h" | |
17 | #include "wx/control.h" | |
18 | #include "wx/app.h" | |
cf4219e7 RR |
19 | #include "wx/menu.h" |
20 | #include "wx/toolbar.h" | |
21 | #include "wx/statusbr.h" | |
d4c99d6f | 22 | #include "wx/mdi.h" |
c801d85f KB |
23 | #include "wx/gtk/win_gtk.h" |
24 | ||
25 | const wxMENU_HEIGHT = 28; | |
26 | const wxSTATUS_HEIGHT = 25; | |
27 | ||
28 | extern wxList wxTopLevelWindows; | |
29 | extern wxList wxPendingDelete; | |
30 | ||
31 | //----------------------------------------------------------------------------- | |
32 | // wxFrame | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | //----------------------------------------------------------------------------- | |
47908e25 | 36 | // set size |
c801d85f KB |
37 | |
38 | void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) | |
ed7a557b | 39 | { |
c801d85f KB |
40 | if (!win->HasVMT()) return; |
41 | ||
42 | /* | |
43 | printf( "OnFrameResize from " ); | |
44 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
45 | printf( win->GetClassInfo()->GetClassName() ); | |
46 | printf( ".\n" ); | |
47 | */ | |
ed7a557b | 48 | |
219f895a | 49 | win->GtkOnSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
c801d85f KB |
50 | }; |
51 | ||
52 | //----------------------------------------------------------------------------- | |
53 | // delete | |
54 | ||
55 | bool gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) | |
ed7a557b | 56 | { |
c801d85f KB |
57 | /* |
58 | printf( "OnDelete from " ); | |
59 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
60 | printf( win->GetClassInfo()->GetClassName() ); | |
61 | printf( ".\n" ); | |
62 | */ | |
ed7a557b | 63 | |
c801d85f KB |
64 | win->Close(); |
65 | ||
66 | return TRUE; | |
67 | }; | |
68 | ||
47908e25 RR |
69 | //----------------------------------------------------------------------------- |
70 | // configure | |
71 | ||
72 | gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) | |
73 | { | |
74 | if (!win->HasVMT()) return FALSE; | |
75 | ||
76 | win->m_x = event->x; | |
77 | win->m_y = event->y; | |
78 | ||
79 | return FALSE; | |
80 | }; | |
81 | ||
c801d85f KB |
82 | //----------------------------------------------------------------------------- |
83 | ||
84 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
c801d85f | 85 | EVT_SIZE(wxFrame::OnSize) |
716b7364 | 86 | EVT_CLOSE(wxFrame::OnCloseWindow) |
e2414cbe | 87 | EVT_IDLE(wxFrame::OnIdle) |
c801d85f KB |
88 | END_EVENT_TABLE() |
89 | ||
90 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
91 | ||
19717c50 | 92 | wxFrame::wxFrame() |
c801d85f | 93 | { |
c801d85f KB |
94 | m_frameMenuBar = NULL; |
95 | m_frameStatusBar = NULL; | |
46dc76ba | 96 | m_frameToolBar = NULL; |
c801d85f | 97 | m_sizeSet = FALSE; |
46dc76ba | 98 | m_addPrivateChild = FALSE; |
cf4219e7 RR |
99 | m_wxwindow = NULL; |
100 | m_mainWindow = NULL; | |
c801d85f KB |
101 | wxTopLevelWindows.Insert( this ); |
102 | }; | |
103 | ||
ed7a557b | 104 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
105 | const wxPoint &pos, const wxSize &size, |
106 | long style, const wxString &name ) | |
c801d85f | 107 | { |
46dc76ba RR |
108 | m_frameMenuBar = NULL; |
109 | m_frameStatusBar = NULL; | |
110 | m_frameToolBar = NULL; | |
c801d85f | 111 | m_sizeSet = FALSE; |
46dc76ba | 112 | m_addPrivateChild = FALSE; |
cf4219e7 RR |
113 | m_wxwindow = NULL; |
114 | m_mainWindow = NULL; | |
c801d85f KB |
115 | Create( parent, id, title, pos, size, style, name ); |
116 | wxTopLevelWindows.Insert( this ); | |
117 | }; | |
118 | ||
debe6624 | 119 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 120 | const wxPoint &pos, const wxSize &size, |
debe6624 | 121 | long style, const wxString &name ) |
c801d85f KB |
122 | { |
123 | m_needParent = FALSE; | |
ed7a557b | 124 | |
c801d85f KB |
125 | PreCreation( parent, id, pos, size, style, name ); |
126 | ||
c801d85f | 127 | m_title = title; |
ed7a557b | 128 | |
c801d85f | 129 | m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
ed7a557b | 130 | if ((size.x != -1) && (size.y != -1)) |
c801d85f | 131 | gtk_widget_set_usize( m_widget, m_width, m_height ); |
ed7a557b | 132 | if ((pos.x != -1) && (pos.y != -1)) |
c801d85f | 133 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
ed7a557b | 134 | |
c801d85f KB |
135 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); |
136 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
ed7a557b | 137 | |
c801d85f | 138 | gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); |
ed7a557b VZ |
139 | |
140 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
c801d85f | 141 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); |
ed7a557b | 142 | |
c801d85f KB |
143 | m_mainWindow = gtk_myfixed_new(); |
144 | gtk_widget_show( m_mainWindow ); | |
145 | GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS ); | |
ed7a557b | 146 | |
c801d85f KB |
147 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow ); |
148 | gtk_widget_set_uposition( m_mainWindow, 0, 0 ); | |
ed7a557b | 149 | |
c801d85f KB |
150 | m_wxwindow = gtk_myfixed_new(); |
151 | gtk_widget_show( m_wxwindow ); | |
152 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 153 | |
c801d85f | 154 | gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow ); |
ed7a557b | 155 | |
ed7a557b | 156 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
c801d85f | 157 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); |
ed7a557b | 158 | |
47908e25 RR |
159 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
160 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
161 | ||
c801d85f | 162 | PostCreation(); |
ed7a557b | 163 | |
c801d85f | 164 | gtk_widget_realize( m_mainWindow ); |
ed7a557b | 165 | |
c801d85f KB |
166 | return TRUE; |
167 | }; | |
168 | ||
19717c50 | 169 | wxFrame::~wxFrame() |
c801d85f KB |
170 | { |
171 | if (m_frameMenuBar) delete m_frameMenuBar; | |
172 | if (m_frameStatusBar) delete m_frameStatusBar; | |
ed7a557b | 173 | |
c801d85f KB |
174 | // if (m_mainWindow) gtk_widget_destroy( m_mainWindow ); |
175 | ||
176 | wxTopLevelWindows.DeleteObject( this ); | |
177 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
178 | }; | |
ed7a557b | 179 | |
debe6624 | 180 | bool wxFrame::Show( bool show ) |
c801d85f KB |
181 | { |
182 | if (show) | |
183 | { | |
184 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
185 | m_sizeSet = FALSE; | |
186 | ProcessEvent( event ); | |
187 | }; | |
188 | return wxWindow::Show( show ); | |
189 | }; | |
190 | ||
debe6624 | 191 | void wxFrame::Enable( bool enable ) |
c801d85f KB |
192 | { |
193 | wxWindow::Enable( enable ); | |
194 | gtk_widget_set_sensitive( m_mainWindow, enable ); | |
195 | }; | |
196 | ||
716b7364 | 197 | void wxFrame::OnCloseWindow( wxCloseEvent &event ) |
c801d85f | 198 | { |
716b7364 RR |
199 | if ( GetEventHandler()->OnClose() || event.GetForce()) |
200 | { | |
201 | this->Destroy(); | |
202 | } | |
c801d85f KB |
203 | }; |
204 | ||
19717c50 | 205 | bool wxFrame::Destroy() |
c801d85f KB |
206 | { |
207 | if (!wxPendingDelete.Member(this)) | |
208 | wxPendingDelete.Append(this); | |
ed7a557b | 209 | |
c801d85f KB |
210 | return TRUE; |
211 | } | |
212 | ||
213 | void wxFrame::GetClientSize( int *width, int *height ) const | |
214 | { | |
215 | wxWindow::GetClientSize( width, height ); | |
216 | if (height) | |
217 | { | |
218 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; | |
219 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
46dc76ba RR |
220 | if (m_frameToolBar) |
221 | { | |
222 | int y = 0; | |
223 | m_frameToolBar->GetSize( NULL, &y ); | |
224 | (*height) -= y; | |
225 | } | |
c801d85f KB |
226 | }; |
227 | }; | |
228 | ||
47908e25 | 229 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
c801d85f | 230 | { |
47908e25 RR |
231 | // due to a bug in gtk, x,y are always 0 |
232 | // m_x = x; | |
233 | // m_y = y; | |
219f895a | 234 | |
c801d85f KB |
235 | if ((m_height == height) && (m_width == width) && |
236 | (m_sizeSet)) return; | |
237 | if (!m_mainWindow) return; | |
238 | if (!m_wxwindow) return; | |
239 | ||
240 | m_width = width; | |
241 | m_height = height; | |
ed7a557b | 242 | |
c801d85f | 243 | gtk_widget_set_usize( m_widget, width, height ); |
ed7a557b | 244 | |
c801d85f KB |
245 | int main_x = 0; |
246 | int main_y = 0; | |
247 | int main_height = height; | |
248 | int main_width = width; | |
ed7a557b | 249 | |
c801d85f KB |
250 | // This emulates Windows behaviour: |
251 | // The menu bar is part of the main window, but the status bar | |
252 | // is on the implementation side in the client area. The | |
253 | // function GetClientSize returns the size of the client area | |
254 | // minus the status bar height. Under wxGTK, the main window | |
255 | // is represented by m_mainWindow. The menubar is inserted | |
256 | // into m_mainWindow whereas the statusbar is insertes into | |
257 | // m_wxwindow just like any other window. | |
ed7a557b | 258 | |
c801d85f | 259 | // not really needed |
47908e25 | 260 | // gtk_widget_set_usize( m_mainWindow, width, height ); |
ed7a557b | 261 | |
c801d85f KB |
262 | if (m_frameMenuBar) |
263 | { | |
264 | main_y = wxMENU_HEIGHT; | |
265 | main_height -= wxMENU_HEIGHT; | |
266 | }; | |
ed7a557b | 267 | |
46dc76ba RR |
268 | int toolbar_height = 0; |
269 | if (m_frameToolBar) m_frameToolBar->GetSize( NULL, &toolbar_height ); | |
270 | ||
271 | main_y += toolbar_height; | |
272 | main_height -= toolbar_height; | |
273 | ||
d4c99d6f RR |
274 | gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_wxwindow, main_x, main_y ); |
275 | gtk_widget_set_usize( m_wxwindow, main_width, main_height ); | |
ed7a557b | 276 | |
c801d85f KB |
277 | if (m_frameMenuBar) |
278 | { | |
d4c99d6f | 279 | gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameMenuBar->m_widget, 1, 1 ); |
c801d85f KB |
280 | gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 ); |
281 | }; | |
ed7a557b | 282 | |
46dc76ba RR |
283 | if (m_frameToolBar) |
284 | { | |
d4c99d6f | 285 | gtk_myfixed_move( GTK_MYFIXED(m_mainWindow), m_frameToolBar->m_widget, 1, wxMENU_HEIGHT ); |
46dc76ba RR |
286 | gtk_widget_set_usize( m_frameToolBar->m_widget, width-2, toolbar_height ); |
287 | }; | |
288 | ||
c801d85f KB |
289 | if (m_frameStatusBar) |
290 | { | |
291 | m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT ); | |
292 | }; | |
293 | ||
294 | m_sizeSet = TRUE; | |
ed7a557b | 295 | |
c801d85f KB |
296 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
297 | event.SetEventObject( this ); | |
298 | ProcessEvent( event ); | |
299 | }; | |
300 | ||
301 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
302 | { | |
ed7a557b VZ |
303 | if ( GetAutoLayout() ) |
304 | Layout(); | |
305 | else { | |
cf5f9c9c GL |
306 | // no child: go out ! |
307 | if (!GetChildren()->First()) | |
308 | return; | |
46dc76ba | 309 | |
ed7a557b VZ |
310 | // do we have exactly one child? |
311 | wxWindow *child = NULL; | |
312 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
c801d85f | 313 | { |
ed7a557b | 314 | wxWindow *win = (wxWindow *)node->Data(); |
e3e65dac | 315 | if (!IS_KIND_OF(win,wxFrame) && !IS_KIND_OF(win,wxDialog) |
46dc76ba | 316 | #if 0 // not in m_children anyway |
ed7a557b | 317 | && (win != m_frameMenuBar) && |
46dc76ba | 318 | (win != m_frameToolBar) && |
ed7a557b VZ |
319 | (win != m_frameStatusBar) |
320 | #endif | |
321 | ) | |
322 | { | |
323 | if ( child ) // it's the second one: do nothing | |
324 | return; | |
325 | ||
326 | child = win; | |
327 | }; | |
c801d85f | 328 | }; |
c801d85f | 329 | |
ed7a557b | 330 | // yes: set it's size to fill all the frame |
c801d85f | 331 | int client_x, client_y; |
c801d85f | 332 | GetClientSize(&client_x, &client_y); |
c801d85f KB |
333 | child->SetSize( 1, 1, client_x-2, client_y); |
334 | } | |
c801d85f KB |
335 | }; |
336 | ||
46dc76ba RR |
337 | void wxFrame::AddChild( wxWindow *child ) |
338 | { | |
e3e65dac RR |
339 | // wxFrame and wxDialog as children aren't placed into the parents |
340 | ||
d4c99d6f RR |
341 | if (IS_KIND_OF(child,wxMDIChildFrame)) printf( "wxFrame::AddChild error.\n" ); |
342 | ||
343 | if ( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog)) | |
e3e65dac RR |
344 | { |
345 | m_children.Append( child ); | |
346 | ||
347 | if ((child->m_x != -1) && (child->m_y != -1)) | |
348 | gtk_widget_set_uposition( child->m_widget, child->m_x, child->m_y ); | |
349 | ||
350 | return; | |
351 | } | |
352 | ||
46dc76ba RR |
353 | if (m_addPrivateChild) |
354 | { | |
355 | gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), child->m_widget, child->m_x, child->m_y ); | |
356 | ||
357 | gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); | |
358 | } | |
359 | else | |
360 | { | |
361 | m_children.Append( child ); | |
362 | ||
363 | if (m_wxwindow) | |
364 | gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), child->m_widget, child->m_x, child->m_y ); | |
365 | ||
366 | gtk_widget_set_usize( child->m_widget, child->m_width, child->m_height ); | |
367 | } | |
368 | }; | |
369 | ||
716b7364 | 370 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
c801d85f KB |
371 | { |
372 | menu->SetInvokingWindow( win ); | |
373 | wxNode *node = menu->m_items.First(); | |
374 | while (node) | |
375 | { | |
376 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
19717c50 VZ |
377 | if (menuitem->IsSubMenu()) |
378 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
c801d85f KB |
379 | node = node->Next(); |
380 | }; | |
381 | }; | |
382 | ||
383 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
384 | { | |
385 | m_frameMenuBar = menuBar; | |
716b7364 RR |
386 | |
387 | if (m_frameMenuBar) | |
c801d85f | 388 | { |
716b7364 RR |
389 | if (m_frameMenuBar->m_parent != this) |
390 | { | |
391 | wxNode *node = m_frameMenuBar->m_menus.First(); | |
392 | while (node) | |
393 | { | |
394 | wxMenu *menu = (wxMenu*)node->Data(); | |
395 | SetInvokingWindow( menu, this ); | |
396 | node = node->Next(); | |
397 | }; | |
398 | ||
399 | m_frameMenuBar->m_parent = this; | |
400 | gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), | |
401 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); | |
402 | } | |
403 | } | |
ed7a557b | 404 | }; |
c801d85f | 405 | |
46dc76ba RR |
406 | wxMenuBar *wxFrame::GetMenuBar(void) |
407 | { | |
408 | return m_frameMenuBar; | |
409 | }; | |
410 | ||
e3e65dac | 411 | wxToolBar *wxFrame::CreateToolBar( long style , wxWindowID id, const wxString& name ) |
46dc76ba RR |
412 | { |
413 | m_addPrivateChild = TRUE; | |
414 | ||
e3e65dac | 415 | m_frameToolBar = new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); |
46dc76ba RR |
416 | |
417 | m_addPrivateChild = FALSE; | |
418 | ||
419 | return m_frameToolBar; | |
420 | }; | |
421 | ||
422 | wxToolBar *wxFrame::GetToolBar(void) | |
423 | { | |
424 | return m_frameToolBar; | |
425 | }; | |
426 | ||
e3e65dac | 427 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) |
c801d85f KB |
428 | { |
429 | if (m_frameStatusBar) | |
430 | delete m_frameStatusBar; | |
ed7a557b | 431 | |
e3e65dac | 432 | m_frameStatusBar = new wxStatusBar( this, id, wxPoint(0,0), wxSize(100,20), style, name ); |
c801d85f KB |
433 | |
434 | m_frameStatusBar->SetFieldsCount( number ); | |
e3e65dac RR |
435 | |
436 | return m_frameStatusBar; | |
c801d85f KB |
437 | }; |
438 | ||
debe6624 | 439 | void wxFrame::SetStatusText( const wxString &text, int number ) |
c801d85f KB |
440 | { |
441 | if (m_frameStatusBar) m_frameStatusBar->SetStatusText( text, number ); | |
442 | }; | |
443 | ||
debe6624 | 444 | void wxFrame::SetStatusWidths( int n, int *width ) |
c801d85f KB |
445 | { |
446 | if (m_frameStatusBar) m_frameStatusBar->SetStatusWidths( n, width ); | |
447 | }; | |
448 | ||
46dc76ba | 449 | wxStatusBar *wxFrame::GetStatusBar(void) |
c801d85f KB |
450 | { |
451 | return m_frameStatusBar; | |
452 | }; | |
453 | ||
c801d85f KB |
454 | void wxFrame::SetTitle( const wxString &title ) |
455 | { | |
456 | m_title = title; | |
457 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
458 | }; | |
459 | ||
46dc76ba | 460 | void wxFrame::SetSizeHints(int minW, int minH, int maxW, int maxH, int WXUNUSED(incW) ) |
c801d85f | 461 | { |
46dc76ba RR |
462 | if (m_wxwindow) |
463 | gdk_window_set_hints( m_wxwindow->window, -1, -1, | |
464 | minW, minH, maxW, maxH, GDK_HINT_MIN_SIZE | GDK_HINT_MIN_SIZE ); | |
e2414cbe | 465 | } |
d355d3fe RR |
466 | |
467 | void wxFrame::SetIcon( const wxIcon &icon ) | |
468 | { | |
469 | m_icon = icon; | |
470 | if (!icon.Ok()) return; | |
471 | ||
472 | wxMask *mask = icon.GetMask(); | |
473 | GdkBitmap *bm = NULL; | |
474 | if (mask) bm = mask->GetBitmap(); | |
475 | ||
476 | gdk_window_set_icon( m_widget->window, NULL, icon.GetPixmap(), bm ); | |
477 | } | |
478 |