]>
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" | |
19 | #include "wx/gtk/win_gtk.h" | |
20 | ||
21 | const wxMENU_HEIGHT = 28; | |
22 | const wxSTATUS_HEIGHT = 25; | |
23 | ||
24 | extern wxList wxTopLevelWindows; | |
25 | extern wxList wxPendingDelete; | |
26 | ||
27 | //----------------------------------------------------------------------------- | |
28 | // wxFrame | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | //----------------------------------------------------------------------------- | |
32 | // size | |
33 | ||
34 | void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) | |
ed7a557b | 35 | { |
c801d85f KB |
36 | if (!win->HasVMT()) return; |
37 | ||
38 | /* | |
39 | printf( "OnFrameResize from " ); | |
40 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
41 | printf( win->GetClassInfo()->GetClassName() ); | |
42 | printf( ".\n" ); | |
43 | */ | |
ed7a557b | 44 | |
219f895a | 45 | win->GtkOnSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
c801d85f KB |
46 | }; |
47 | ||
48 | //----------------------------------------------------------------------------- | |
49 | // delete | |
50 | ||
51 | bool gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) | |
ed7a557b | 52 | { |
c801d85f KB |
53 | /* |
54 | printf( "OnDelete from " ); | |
55 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
56 | printf( win->GetClassInfo()->GetClassName() ); | |
57 | printf( ".\n" ); | |
58 | */ | |
ed7a557b | 59 | |
c801d85f KB |
60 | win->Close(); |
61 | ||
62 | return TRUE; | |
63 | }; | |
64 | ||
65 | //----------------------------------------------------------------------------- | |
66 | ||
67 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
c801d85f | 68 | EVT_SIZE(wxFrame::OnSize) |
716b7364 | 69 | EVT_CLOSE(wxFrame::OnCloseWindow) |
e2414cbe | 70 | EVT_IDLE(wxFrame::OnIdle) |
c801d85f KB |
71 | END_EVENT_TABLE() |
72 | ||
73 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
74 | ||
19717c50 | 75 | wxFrame::wxFrame() |
c801d85f KB |
76 | { |
77 | m_doingOnSize = FALSE; | |
78 | m_frameMenuBar = NULL; | |
79 | m_frameStatusBar = NULL; | |
80 | m_sizeSet = FALSE; | |
81 | wxTopLevelWindows.Insert( this ); | |
82 | }; | |
83 | ||
ed7a557b | 84 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
85 | const wxPoint &pos, const wxSize &size, |
86 | long style, const wxString &name ) | |
c801d85f KB |
87 | { |
88 | m_sizeSet = FALSE; | |
89 | Create( parent, id, title, pos, size, style, name ); | |
90 | wxTopLevelWindows.Insert( this ); | |
91 | }; | |
92 | ||
debe6624 | 93 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 94 | const wxPoint &pos, const wxSize &size, |
debe6624 | 95 | long style, const wxString &name ) |
c801d85f KB |
96 | { |
97 | m_needParent = FALSE; | |
98 | m_mainWindow = NULL; | |
99 | m_wxwindow = NULL; | |
ed7a557b | 100 | |
c801d85f KB |
101 | PreCreation( parent, id, pos, size, style, name ); |
102 | ||
103 | m_doingOnSize = FALSE; | |
ed7a557b | 104 | |
c801d85f | 105 | m_title = title; |
ed7a557b | 106 | |
c801d85f | 107 | m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
ed7a557b | 108 | if ((size.x != -1) && (size.y != -1)) |
c801d85f | 109 | gtk_widget_set_usize( m_widget, m_width, m_height ); |
ed7a557b | 110 | if ((pos.x != -1) && (pos.y != -1)) |
c801d85f | 111 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
ed7a557b | 112 | |
c801d85f KB |
113 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); |
114 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
ed7a557b | 115 | |
c801d85f | 116 | gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); |
ed7a557b VZ |
117 | |
118 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
c801d85f | 119 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); |
ed7a557b | 120 | |
c801d85f KB |
121 | m_mainWindow = gtk_myfixed_new(); |
122 | gtk_widget_show( m_mainWindow ); | |
123 | GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS ); | |
ed7a557b | 124 | |
c801d85f KB |
125 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow ); |
126 | gtk_widget_set_uposition( m_mainWindow, 0, 0 ); | |
ed7a557b | 127 | |
c801d85f KB |
128 | m_wxwindow = gtk_myfixed_new(); |
129 | gtk_widget_show( m_wxwindow ); | |
130 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 131 | |
c801d85f | 132 | gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow ); |
ed7a557b | 133 | |
c801d85f KB |
134 | m_frameMenuBar = NULL; |
135 | m_frameStatusBar = NULL; | |
ed7a557b VZ |
136 | |
137 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", | |
c801d85f | 138 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); |
ed7a557b | 139 | |
c801d85f | 140 | PostCreation(); |
ed7a557b | 141 | |
c801d85f | 142 | gtk_widget_realize( m_mainWindow ); |
ed7a557b | 143 | |
c801d85f KB |
144 | return TRUE; |
145 | }; | |
146 | ||
19717c50 | 147 | wxFrame::~wxFrame() |
c801d85f KB |
148 | { |
149 | if (m_frameMenuBar) delete m_frameMenuBar; | |
150 | if (m_frameStatusBar) delete m_frameStatusBar; | |
ed7a557b | 151 | |
c801d85f KB |
152 | // if (m_mainWindow) gtk_widget_destroy( m_mainWindow ); |
153 | ||
154 | wxTopLevelWindows.DeleteObject( this ); | |
155 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
156 | }; | |
ed7a557b | 157 | |
debe6624 | 158 | bool wxFrame::Show( bool show ) |
c801d85f KB |
159 | { |
160 | if (show) | |
161 | { | |
162 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
163 | m_sizeSet = FALSE; | |
164 | ProcessEvent( event ); | |
165 | }; | |
166 | return wxWindow::Show( show ); | |
167 | }; | |
168 | ||
debe6624 | 169 | void wxFrame::Enable( bool enable ) |
c801d85f KB |
170 | { |
171 | wxWindow::Enable( enable ); | |
172 | gtk_widget_set_sensitive( m_mainWindow, enable ); | |
173 | }; | |
174 | ||
716b7364 | 175 | void wxFrame::OnCloseWindow( wxCloseEvent &event ) |
c801d85f | 176 | { |
716b7364 RR |
177 | if ( GetEventHandler()->OnClose() || event.GetForce()) |
178 | { | |
179 | this->Destroy(); | |
180 | } | |
c801d85f KB |
181 | }; |
182 | ||
19717c50 | 183 | bool wxFrame::Destroy() |
c801d85f KB |
184 | { |
185 | if (!wxPendingDelete.Member(this)) | |
186 | wxPendingDelete.Append(this); | |
ed7a557b | 187 | |
c801d85f KB |
188 | return TRUE; |
189 | } | |
190 | ||
191 | void wxFrame::GetClientSize( int *width, int *height ) const | |
192 | { | |
193 | wxWindow::GetClientSize( width, height ); | |
194 | if (height) | |
195 | { | |
196 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; | |
197 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
198 | }; | |
199 | }; | |
200 | ||
219f895a | 201 | void wxFrame::GtkOnSize( int x, int y, int width, int height ) |
c801d85f | 202 | { |
219f895a RR |
203 | m_x = x; |
204 | m_y = y; | |
205 | ||
c801d85f KB |
206 | if ((m_height == height) && (m_width == width) && |
207 | (m_sizeSet)) return; | |
208 | if (!m_mainWindow) return; | |
209 | if (!m_wxwindow) return; | |
210 | ||
211 | m_width = width; | |
212 | m_height = height; | |
ed7a557b | 213 | |
c801d85f | 214 | gtk_widget_set_usize( m_widget, width, height ); |
ed7a557b | 215 | |
c801d85f KB |
216 | int main_x = 0; |
217 | int main_y = 0; | |
218 | int main_height = height; | |
219 | int main_width = width; | |
ed7a557b | 220 | |
c801d85f KB |
221 | // This emulates Windows behaviour: |
222 | // The menu bar is part of the main window, but the status bar | |
223 | // is on the implementation side in the client area. The | |
224 | // function GetClientSize returns the size of the client area | |
225 | // minus the status bar height. Under wxGTK, the main window | |
226 | // is represented by m_mainWindow. The menubar is inserted | |
227 | // into m_mainWindow whereas the statusbar is insertes into | |
228 | // m_wxwindow just like any other window. | |
ed7a557b | 229 | |
c801d85f KB |
230 | // not really needed |
231 | gtk_widget_set_usize( m_mainWindow, width, height ); | |
ed7a557b | 232 | |
c801d85f KB |
233 | if (m_frameMenuBar) |
234 | { | |
235 | main_y = wxMENU_HEIGHT; | |
236 | main_height -= wxMENU_HEIGHT; | |
237 | }; | |
ed7a557b | 238 | |
c801d85f KB |
239 | gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow), main_x, main_y ); |
240 | gtk_widget_set_usize( GTK_WIDGET(m_wxwindow), main_width, main_height ); | |
ed7a557b | 241 | |
c801d85f KB |
242 | if (m_frameMenuBar) |
243 | { | |
244 | gtk_widget_set_uposition( m_frameMenuBar->m_widget, 1, 1 ); | |
245 | gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 ); | |
246 | }; | |
ed7a557b | 247 | |
c801d85f KB |
248 | if (m_frameStatusBar) |
249 | { | |
250 | m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT ); | |
251 | }; | |
252 | ||
253 | m_sizeSet = TRUE; | |
ed7a557b | 254 | |
c801d85f KB |
255 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
256 | event.SetEventObject( this ); | |
257 | ProcessEvent( event ); | |
258 | }; | |
259 | ||
260 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
261 | { | |
ed7a557b VZ |
262 | if ( GetAutoLayout() ) |
263 | Layout(); | |
264 | else { | |
cf5f9c9c GL |
265 | // no child: go out ! |
266 | if (!GetChildren()->First()) | |
267 | return; | |
268 | ||
ed7a557b VZ |
269 | // do we have exactly one child? |
270 | wxWindow *child = NULL; | |
271 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
c801d85f | 272 | { |
ed7a557b VZ |
273 | wxWindow *win = (wxWindow *)node->Data(); |
274 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && | |
275 | !win->IsKindOf(CLASSINFO(wxDialog)) | |
276 | #if 0 // not in m_children anyway | |
277 | && (win != m_frameMenuBar) && | |
278 | (win != m_frameStatusBar) | |
279 | #endif | |
280 | ) | |
281 | { | |
282 | if ( child ) // it's the second one: do nothing | |
283 | return; | |
284 | ||
285 | child = win; | |
286 | }; | |
c801d85f | 287 | }; |
c801d85f | 288 | |
ed7a557b | 289 | // yes: set it's size to fill all the frame |
c801d85f | 290 | int client_x, client_y; |
c801d85f | 291 | GetClientSize(&client_x, &client_y); |
c801d85f KB |
292 | child->SetSize( 1, 1, client_x-2, client_y); |
293 | } | |
c801d85f KB |
294 | }; |
295 | ||
716b7364 | 296 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
c801d85f KB |
297 | { |
298 | menu->SetInvokingWindow( win ); | |
299 | wxNode *node = menu->m_items.First(); | |
300 | while (node) | |
301 | { | |
302 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
19717c50 VZ |
303 | if (menuitem->IsSubMenu()) |
304 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
c801d85f KB |
305 | node = node->Next(); |
306 | }; | |
307 | }; | |
308 | ||
309 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
310 | { | |
311 | m_frameMenuBar = menuBar; | |
716b7364 RR |
312 | |
313 | if (m_frameMenuBar) | |
c801d85f | 314 | { |
716b7364 RR |
315 | if (m_frameMenuBar->m_parent != this) |
316 | { | |
317 | wxNode *node = m_frameMenuBar->m_menus.First(); | |
318 | while (node) | |
319 | { | |
320 | wxMenu *menu = (wxMenu*)node->Data(); | |
321 | SetInvokingWindow( menu, this ); | |
322 | node = node->Next(); | |
323 | }; | |
324 | ||
325 | m_frameMenuBar->m_parent = this; | |
326 | gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), | |
327 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); | |
328 | } | |
329 | } | |
ed7a557b | 330 | }; |
c801d85f | 331 | |
debe6624 | 332 | bool wxFrame::CreateStatusBar( int number ) |
c801d85f KB |
333 | { |
334 | if (m_frameStatusBar) | |
335 | delete m_frameStatusBar; | |
ed7a557b | 336 | |
c801d85f KB |
337 | m_frameStatusBar = new wxStatusBar( this, -1, wxPoint(0,0), wxSize(100,20) ); |
338 | ||
339 | m_frameStatusBar->SetFieldsCount( number ); | |
340 | return TRUE; | |
341 | }; | |
342 | ||
debe6624 | 343 | void wxFrame::SetStatusText( const wxString &text, int number ) |
c801d85f KB |
344 | { |
345 | if (m_frameStatusBar) m_frameStatusBar->SetStatusText( text, number ); | |
346 | }; | |
347 | ||
debe6624 | 348 | void wxFrame::SetStatusWidths( int n, int *width ) |
c801d85f KB |
349 | { |
350 | if (m_frameStatusBar) m_frameStatusBar->SetStatusWidths( n, width ); | |
351 | }; | |
352 | ||
19717c50 | 353 | wxStatusBar *wxFrame::GetStatusBar() |
c801d85f KB |
354 | { |
355 | return m_frameStatusBar; | |
356 | }; | |
357 | ||
19717c50 | 358 | wxMenuBar *wxFrame::GetMenuBar() |
c801d85f KB |
359 | { |
360 | return m_frameMenuBar; | |
361 | }; | |
362 | ||
363 | void wxFrame::SetTitle( const wxString &title ) | |
364 | { | |
365 | m_title = title; | |
366 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
367 | }; | |
368 | ||
19717c50 | 369 | void wxFrame::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW) |
c801d85f | 370 | { |
19717c50 VZ |
371 | // VZ: I don't know a way to set the max size for the window in GTK and have |
372 | // no idea about what incW might be | |
373 | gtk_widget_set_usize(m_widget, minW, minH); | |
e2414cbe RR |
374 | } |
375 | ||
19717c50 | 376 | #include "../common/framecmn.cpp" |