]>
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 | |
8 | // Licence: wxWindows licence | |
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) | |
68 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
69 | EVT_SIZE(wxFrame::OnSize) | |
70 | END_EVENT_TABLE() | |
71 | ||
72 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
73 | ||
74 | wxFrame::wxFrame(void) | |
75 | { | |
76 | m_doingOnSize = FALSE; | |
77 | m_frameMenuBar = NULL; | |
78 | m_frameStatusBar = NULL; | |
79 | m_sizeSet = FALSE; | |
80 | wxTopLevelWindows.Insert( this ); | |
81 | }; | |
82 | ||
ed7a557b | 83 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
84 | const wxPoint &pos, const wxSize &size, |
85 | long style, const wxString &name ) | |
c801d85f KB |
86 | { |
87 | m_sizeSet = FALSE; | |
88 | Create( parent, id, title, pos, size, style, name ); | |
89 | wxTopLevelWindows.Insert( this ); | |
90 | }; | |
91 | ||
debe6624 | 92 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 93 | const wxPoint &pos, const wxSize &size, |
debe6624 | 94 | long style, const wxString &name ) |
c801d85f KB |
95 | { |
96 | m_needParent = FALSE; | |
97 | m_mainWindow = NULL; | |
98 | m_wxwindow = NULL; | |
ed7a557b | 99 | |
c801d85f KB |
100 | PreCreation( parent, id, pos, size, style, name ); |
101 | ||
102 | m_doingOnSize = FALSE; | |
ed7a557b | 103 | |
c801d85f | 104 | m_title = title; |
ed7a557b | 105 | |
c801d85f | 106 | m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL ); |
ed7a557b | 107 | if ((size.x != -1) && (size.y != -1)) |
c801d85f | 108 | gtk_widget_set_usize( m_widget, m_width, m_height ); |
ed7a557b | 109 | if ((pos.x != -1) && (pos.y != -1)) |
c801d85f | 110 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
ed7a557b | 111 | |
c801d85f KB |
112 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); |
113 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
ed7a557b | 114 | |
c801d85f | 115 | gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL); |
ed7a557b VZ |
116 | |
117 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", | |
c801d85f | 118 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); |
ed7a557b | 119 | |
c801d85f KB |
120 | m_mainWindow = gtk_myfixed_new(); |
121 | gtk_widget_show( m_mainWindow ); | |
122 | GTK_WIDGET_UNSET_FLAGS( m_mainWindow, GTK_CAN_FOCUS ); | |
ed7a557b | 123 | |
c801d85f KB |
124 | gtk_container_add( GTK_CONTAINER(m_widget), m_mainWindow ); |
125 | gtk_widget_set_uposition( m_mainWindow, 0, 0 ); | |
ed7a557b | 126 | |
c801d85f KB |
127 | m_wxwindow = gtk_myfixed_new(); |
128 | gtk_widget_show( m_wxwindow ); | |
129 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 130 | |
c801d85f | 131 | gtk_container_add( GTK_CONTAINER(m_mainWindow), m_wxwindow ); |
ed7a557b | 132 | |
c801d85f KB |
133 | m_frameMenuBar = NULL; |
134 | m_frameStatusBar = NULL; | |
ed7a557b VZ |
135 | |
136 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", | |
c801d85f | 137 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); |
ed7a557b | 138 | |
c801d85f | 139 | PostCreation(); |
ed7a557b | 140 | |
c801d85f | 141 | gtk_widget_realize( m_mainWindow ); |
ed7a557b | 142 | |
c801d85f KB |
143 | return TRUE; |
144 | }; | |
145 | ||
146 | wxFrame::~wxFrame(void) | |
147 | { | |
148 | if (m_frameMenuBar) delete m_frameMenuBar; | |
149 | if (m_frameStatusBar) delete m_frameStatusBar; | |
ed7a557b | 150 | |
c801d85f KB |
151 | // if (m_mainWindow) gtk_widget_destroy( m_mainWindow ); |
152 | ||
153 | wxTopLevelWindows.DeleteObject( this ); | |
154 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
155 | }; | |
ed7a557b | 156 | |
debe6624 | 157 | bool wxFrame::Show( bool show ) |
c801d85f KB |
158 | { |
159 | if (show) | |
160 | { | |
161 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
162 | m_sizeSet = FALSE; | |
163 | ProcessEvent( event ); | |
164 | }; | |
165 | return wxWindow::Show( show ); | |
166 | }; | |
167 | ||
debe6624 | 168 | void wxFrame::Enable( bool enable ) |
c801d85f KB |
169 | { |
170 | wxWindow::Enable( enable ); | |
171 | gtk_widget_set_sensitive( m_mainWindow, enable ); | |
172 | }; | |
173 | ||
174 | void wxFrame::OnCloseWindow( wxCloseEvent& WXUNUSED(event) ) | |
175 | { | |
176 | this->Destroy(); | |
177 | }; | |
178 | ||
179 | bool wxFrame::Destroy(void) | |
180 | { | |
181 | if (!wxPendingDelete.Member(this)) | |
182 | wxPendingDelete.Append(this); | |
ed7a557b | 183 | |
c801d85f KB |
184 | return TRUE; |
185 | } | |
186 | ||
187 | void wxFrame::GetClientSize( int *width, int *height ) const | |
188 | { | |
189 | wxWindow::GetClientSize( width, height ); | |
190 | if (height) | |
191 | { | |
192 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; | |
193 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
194 | }; | |
195 | }; | |
196 | ||
219f895a | 197 | void wxFrame::GtkOnSize( int x, int y, int width, int height ) |
c801d85f | 198 | { |
219f895a RR |
199 | m_x = x; |
200 | m_y = y; | |
201 | ||
c801d85f KB |
202 | if ((m_height == height) && (m_width == width) && |
203 | (m_sizeSet)) return; | |
204 | if (!m_mainWindow) return; | |
205 | if (!m_wxwindow) return; | |
206 | ||
207 | m_width = width; | |
208 | m_height = height; | |
ed7a557b | 209 | |
c801d85f | 210 | gtk_widget_set_usize( m_widget, width, height ); |
ed7a557b | 211 | |
c801d85f KB |
212 | int main_x = 0; |
213 | int main_y = 0; | |
214 | int main_height = height; | |
215 | int main_width = width; | |
ed7a557b | 216 | |
c801d85f KB |
217 | // This emulates Windows behaviour: |
218 | // The menu bar is part of the main window, but the status bar | |
219 | // is on the implementation side in the client area. The | |
220 | // function GetClientSize returns the size of the client area | |
221 | // minus the status bar height. Under wxGTK, the main window | |
222 | // is represented by m_mainWindow. The menubar is inserted | |
223 | // into m_mainWindow whereas the statusbar is insertes into | |
224 | // m_wxwindow just like any other window. | |
ed7a557b | 225 | |
c801d85f KB |
226 | // not really needed |
227 | gtk_widget_set_usize( m_mainWindow, width, height ); | |
ed7a557b | 228 | |
c801d85f KB |
229 | if (m_frameMenuBar) |
230 | { | |
231 | main_y = wxMENU_HEIGHT; | |
232 | main_height -= wxMENU_HEIGHT; | |
233 | }; | |
ed7a557b | 234 | |
c801d85f KB |
235 | gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow), main_x, main_y ); |
236 | gtk_widget_set_usize( GTK_WIDGET(m_wxwindow), main_width, main_height ); | |
ed7a557b | 237 | |
c801d85f KB |
238 | if (m_frameMenuBar) |
239 | { | |
240 | gtk_widget_set_uposition( m_frameMenuBar->m_widget, 1, 1 ); | |
241 | gtk_widget_set_usize( m_frameMenuBar->m_widget, width-2, wxMENU_HEIGHT-2 ); | |
242 | }; | |
ed7a557b | 243 | |
c801d85f KB |
244 | if (m_frameStatusBar) |
245 | { | |
246 | m_frameStatusBar->SetSize( 0, main_height-wxSTATUS_HEIGHT, width, wxSTATUS_HEIGHT ); | |
247 | }; | |
248 | ||
249 | m_sizeSet = TRUE; | |
ed7a557b | 250 | |
c801d85f KB |
251 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
252 | event.SetEventObject( this ); | |
253 | ProcessEvent( event ); | |
254 | }; | |
255 | ||
256 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
257 | { | |
ed7a557b VZ |
258 | if ( GetAutoLayout() ) |
259 | Layout(); | |
260 | else { | |
261 | // do we have exactly one child? | |
262 | wxWindow *child = NULL; | |
263 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
c801d85f | 264 | { |
ed7a557b VZ |
265 | wxWindow *win = (wxWindow *)node->Data(); |
266 | if (!win->IsKindOf(CLASSINFO(wxFrame)) && | |
267 | !win->IsKindOf(CLASSINFO(wxDialog)) | |
268 | #if 0 // not in m_children anyway | |
269 | && (win != m_frameMenuBar) && | |
270 | (win != m_frameStatusBar) | |
271 | #endif | |
272 | ) | |
273 | { | |
274 | if ( child ) // it's the second one: do nothing | |
275 | return; | |
276 | ||
277 | child = win; | |
278 | }; | |
c801d85f | 279 | }; |
c801d85f | 280 | |
ed7a557b | 281 | // yes: set it's size to fill all the frame |
c801d85f | 282 | int client_x, client_y; |
c801d85f | 283 | GetClientSize(&client_x, &client_y); |
c801d85f KB |
284 | child->SetSize( 1, 1, client_x-2, client_y); |
285 | } | |
c801d85f KB |
286 | }; |
287 | ||
288 | void SetInvokingWindow( wxMenu *menu, wxWindow *win ) | |
289 | { | |
290 | menu->SetInvokingWindow( win ); | |
291 | wxNode *node = menu->m_items.First(); | |
292 | while (node) | |
293 | { | |
294 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
295 | if (menuitem->m_isSubMenu) SetInvokingWindow( menuitem->m_subMenu, win ); | |
296 | node = node->Next(); | |
297 | }; | |
298 | }; | |
299 | ||
300 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
301 | { | |
302 | m_frameMenuBar = menuBar; | |
ed7a557b | 303 | |
c801d85f KB |
304 | wxNode *node = m_frameMenuBar->m_menus.First(); |
305 | while (node) | |
306 | { | |
307 | wxMenu *menu = (wxMenu*)node->Data(); | |
ed7a557b | 308 | SetInvokingWindow( menu, this ); |
c801d85f KB |
309 | node = node->Next(); |
310 | }; | |
ed7a557b | 311 | |
c801d85f | 312 | m_frameMenuBar->m_parent = this; |
ed7a557b | 313 | gtk_myfixed_put( GTK_MYFIXED(m_mainWindow), |
c801d85f | 314 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); |
ed7a557b | 315 | }; |
c801d85f | 316 | |
debe6624 | 317 | bool wxFrame::CreateStatusBar( int number ) |
c801d85f KB |
318 | { |
319 | if (m_frameStatusBar) | |
320 | delete m_frameStatusBar; | |
ed7a557b | 321 | |
c801d85f KB |
322 | m_frameStatusBar = new wxStatusBar( this, -1, wxPoint(0,0), wxSize(100,20) ); |
323 | ||
324 | m_frameStatusBar->SetFieldsCount( number ); | |
325 | return TRUE; | |
326 | }; | |
327 | ||
debe6624 | 328 | void wxFrame::SetStatusText( const wxString &text, int number ) |
c801d85f KB |
329 | { |
330 | if (m_frameStatusBar) m_frameStatusBar->SetStatusText( text, number ); | |
331 | }; | |
332 | ||
debe6624 | 333 | void wxFrame::SetStatusWidths( int n, int *width ) |
c801d85f KB |
334 | { |
335 | if (m_frameStatusBar) m_frameStatusBar->SetStatusWidths( n, width ); | |
336 | }; | |
337 | ||
338 | wxStatusBar *wxFrame::GetStatusBar(void) | |
339 | { | |
340 | return m_frameStatusBar; | |
341 | }; | |
342 | ||
343 | wxMenuBar *wxFrame::GetMenuBar(void) | |
344 | { | |
345 | return m_frameMenuBar; | |
346 | }; | |
347 | ||
348 | void wxFrame::SetTitle( const wxString &title ) | |
349 | { | |
350 | m_title = title; | |
351 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
352 | }; | |
353 | ||
354 | wxString wxFrame::GetTitle(void) const | |
355 | { | |
356 | return (wxString&)m_title; | |
357 | }; | |
358 |