]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mdi.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 | |
a3622daa | 8 | // Licence: wxWindows licence |
c801d85f KB |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "mdi.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/mdi.h" | |
e3e65dac | 16 | #include "wx/dialog.h" |
cf4219e7 | 17 | #include "wx/menu.h" |
716b7364 RR |
18 | #include "wx/gtk/win_gtk.h" |
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | extern wxList wxPendingDelete; | |
c801d85f KB |
23 | |
24 | //----------------------------------------------------------------------------- | |
25 | // wxMDIParentFrame | |
26 | //----------------------------------------------------------------------------- | |
27 | ||
33d0b396 | 28 | static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) |
a3622daa | 29 | { |
33d0b396 RR |
30 | if ((win->m_x == alloc->x) && |
31 | (win->m_y == alloc->y) && | |
32 | (win->m_width == alloc->width) && | |
33 | (win->m_height == alloc->height)) | |
34 | { | |
35 | return; | |
36 | }; | |
a3622daa | 37 | |
33d0b396 RR |
38 | win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); |
39 | }; | |
40 | ||
716b7364 RR |
41 | // page change callback |
42 | static void gtk_page_change_callback( GtkNotebook *WXUNUSED(widget), | |
43 | GtkNotebookPage *page, | |
44 | gint WXUNUSED(nPage), | |
45 | wxMDIClientWindow *client_win ) | |
46 | { | |
47 | wxNode *node = client_win->m_children.First(); | |
48 | while (node) | |
49 | { | |
50 | wxMDIChildFrame *child_frame = (wxMDIChildFrame *)node->Data(); | |
51 | if (child_frame->m_page == page) | |
52 | { | |
53 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)client_win->m_parent; | |
54 | mdi_frame->m_currentChild = child_frame; | |
55 | mdi_frame->SetMDIMenuBar( child_frame->m_menuBar ); | |
56 | return; | |
57 | }; | |
58 | node = node->Next(); | |
59 | } | |
60 | } | |
61 | ||
33d0b396 RR |
62 | //----------------------------------------------------------------------------- |
63 | ||
c801d85f KB |
64 | IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame) |
65 | ||
716b7364 RR |
66 | BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) |
67 | END_EVENT_TABLE() | |
68 | ||
c801d85f KB |
69 | wxMDIParentFrame::wxMDIParentFrame(void) |
70 | { | |
71 | m_clientWindow = NULL; | |
72 | m_currentChild = NULL; | |
73 | m_parentFrameActive = TRUE; | |
74 | }; | |
75 | ||
76 | wxMDIParentFrame::wxMDIParentFrame( wxWindow *parent, | |
debe6624 | 77 | wxWindowID id, const wxString& title, |
c801d85f | 78 | const wxPoint& pos, const wxSize& size, |
debe6624 | 79 | long style, const wxString& name ) |
c801d85f KB |
80 | { |
81 | m_clientWindow = NULL; | |
82 | m_currentChild = NULL; | |
83 | m_parentFrameActive = TRUE; | |
84 | Create( parent, id, title, pos, size, style, name ); | |
85 | }; | |
86 | ||
87 | wxMDIParentFrame::~wxMDIParentFrame(void) | |
88 | { | |
89 | }; | |
90 | ||
91 | bool wxMDIParentFrame::Create( wxWindow *parent, | |
debe6624 | 92 | wxWindowID id, const wxString& title, |
c801d85f | 93 | const wxPoint& pos, const wxSize& size, |
debe6624 | 94 | long style, const wxString& name ) |
c801d85f KB |
95 | { |
96 | wxFrame::Create( parent, id, title, pos, size, style, name ); | |
a3622daa | 97 | |
c801d85f | 98 | OnCreateClient(); |
a3622daa | 99 | |
c801d85f KB |
100 | return TRUE; |
101 | }; | |
102 | ||
716b7364 | 103 | void wxMDIParentFrame::GtkOnSize( int x, int y, int width, int height ) |
c801d85f | 104 | { |
716b7364 | 105 | wxFrame::GtkOnSize( x, y, width, height ); |
a3622daa | 106 | |
716b7364 RR |
107 | if (m_mdiMenuBar) |
108 | { | |
109 | int x = 0; | |
110 | int y = 0; | |
111 | GetClientSize( &x, &y ); | |
a3622daa | 112 | m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); |
716b7364 | 113 | } |
c801d85f KB |
114 | }; |
115 | ||
716b7364 RR |
116 | void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar ) |
117 | { | |
118 | if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE ); | |
119 | m_mdiMenuBar = menu_bar; | |
120 | if (m_mdiMenuBar) | |
121 | { | |
122 | int x = 0; | |
123 | int y = 0; | |
124 | GetClientSize( &x, &y ); | |
a3622daa | 125 | m_mdiMenuBar->SetSize( 1, 1, x-2, 26 ); |
716b7364 RR |
126 | m_mdiMenuBar->Show( TRUE ); |
127 | } | |
128 | }; | |
129 | ||
130 | void wxMDIParentFrame::GetClientSize(int *width, int *height ) const | |
c801d85f | 131 | { |
716b7364 | 132 | wxFrame::GetClientSize( width, height ); |
c801d85f KB |
133 | }; |
134 | ||
c801d85f KB |
135 | wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const |
136 | { | |
137 | return m_currentChild; | |
138 | }; | |
139 | ||
140 | wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const | |
141 | { | |
142 | return m_clientWindow; | |
143 | }; | |
144 | ||
145 | wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void) | |
146 | { | |
147 | m_clientWindow = new wxMDIClientWindow( this ); | |
148 | return m_clientWindow; | |
149 | }; | |
150 | ||
151 | void wxMDIParentFrame::ActivateNext(void) | |
152 | { | |
716b7364 RR |
153 | if (m_clientWindow) |
154 | gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) ); | |
c801d85f KB |
155 | }; |
156 | ||
157 | void wxMDIParentFrame::ActivatePrevious(void) | |
716b7364 RR |
158 | { |
159 | if (m_clientWindow) | |
160 | gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) ); | |
161 | }; | |
162 | ||
163 | void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) ) | |
c801d85f KB |
164 | { |
165 | }; | |
166 | ||
167 | void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) ) | |
168 | { | |
169 | }; | |
170 | ||
171 | //----------------------------------------------------------------------------- | |
172 | // wxMDIChildFrame | |
173 | //----------------------------------------------------------------------------- | |
174 | ||
cf4219e7 | 175 | IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame) |
c801d85f | 176 | |
cf4219e7 | 177 | BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame) |
9746a2ba | 178 | EVT_ACTIVATE(wxMDIChildFrame::OnActivate) |
716b7364 RR |
179 | END_EVENT_TABLE() |
180 | ||
c801d85f KB |
181 | wxMDIChildFrame::wxMDIChildFrame(void) |
182 | { | |
716b7364 RR |
183 | m_menuBar = NULL; |
184 | m_page = NULL; | |
c801d85f KB |
185 | }; |
186 | ||
187 | wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame *parent, | |
debe6624 | 188 | wxWindowID id, const wxString& title, |
33d0b396 | 189 | const wxPoint& WXUNUSED(pos), const wxSize& size, |
debe6624 | 190 | long style, const wxString& name ) |
c801d85f | 191 | { |
716b7364 RR |
192 | m_menuBar = NULL; |
193 | m_page = NULL; | |
33d0b396 | 194 | Create( parent, id, title, wxDefaultPosition, size, style, name ); |
c801d85f KB |
195 | }; |
196 | ||
197 | wxMDIChildFrame::~wxMDIChildFrame(void) | |
198 | { | |
716b7364 RR |
199 | if (m_menuBar) |
200 | { | |
201 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent; | |
202 | if (mdi_frame->m_currentChild == this) | |
203 | { | |
204 | mdi_frame->SetMDIMenuBar( NULL ); | |
205 | mdi_frame->m_currentChild = NULL; | |
206 | }; | |
207 | delete m_menuBar; | |
208 | } | |
c801d85f KB |
209 | }; |
210 | ||
211 | bool wxMDIChildFrame::Create( wxMDIParentFrame *parent, | |
debe6624 | 212 | wxWindowID id, const wxString& title, |
33d0b396 | 213 | const wxPoint& WXUNUSED(pos), const wxSize& size, |
debe6624 | 214 | long style, const wxString& name ) |
c801d85f KB |
215 | { |
216 | m_title = title; | |
cf4219e7 | 217 | return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name ); |
c801d85f KB |
218 | }; |
219 | ||
cf4219e7 | 220 | void wxMDIChildFrame::GetClientSize( int *width, int *height ) const |
c801d85f | 221 | { |
cf4219e7 RR |
222 | wxWindow::GetClientSize( width, height ); |
223 | } | |
9746a2ba | 224 | |
cf4219e7 | 225 | void wxMDIChildFrame::AddChild( wxWindow *child ) |
716b7364 | 226 | { |
cf4219e7 | 227 | wxWindow::AddChild( child ); |
716b7364 | 228 | } |
cf4219e7 | 229 | |
716b7364 RR |
230 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
231 | { | |
232 | menu->SetInvokingWindow( win ); | |
233 | wxNode *node = menu->m_items.First(); | |
234 | while (node) | |
235 | { | |
236 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
46dc76ba RR |
237 | if (menuitem->IsSubMenu()) |
238 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
716b7364 RR |
239 | node = node->Next(); |
240 | }; | |
241 | }; | |
242 | ||
243 | void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar ) | |
244 | { | |
245 | m_menuBar = menu_bar; | |
a3622daa | 246 | |
716b7364 RR |
247 | if (m_menuBar) |
248 | { | |
249 | wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent; | |
a3622daa | 250 | |
716b7364 RR |
251 | if (m_menuBar->m_parent != this) |
252 | { | |
253 | wxNode *node = m_menuBar->m_menus.First(); | |
254 | while (node) | |
255 | { | |
256 | wxMenu *menu = (wxMenu*)node->Data(); | |
257 | SetInvokingWindow( menu, this ); | |
258 | node = node->Next(); | |
259 | }; | |
a3622daa | 260 | |
716b7364 RR |
261 | m_menuBar->m_parent = mdi_frame; |
262 | } | |
263 | mdi_frame->SetMDIMenuBar( m_menuBar ); | |
264 | ||
265 | gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_mainWindow), | |
266 | m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y ); | |
267 | } | |
cf4219e7 RR |
268 | }; |
269 | ||
270 | wxMenuBar *wxMDIChildFrame::GetMenuBar() | |
271 | { | |
272 | return m_menuBar; | |
c801d85f KB |
273 | }; |
274 | ||
275 | void wxMDIChildFrame::Activate(void) | |
276 | { | |
277 | }; | |
278 | ||
9746a2ba RR |
279 | void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) ) |
280 | { | |
281 | }; | |
282 | ||
c801d85f KB |
283 | //----------------------------------------------------------------------------- |
284 | // wxMDIClientWindow | |
285 | //----------------------------------------------------------------------------- | |
286 | ||
287 | IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow) | |
288 | ||
289 | wxMDIClientWindow::wxMDIClientWindow(void) | |
290 | { | |
291 | }; | |
292 | ||
debe6624 | 293 | wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style ) |
c801d85f KB |
294 | { |
295 | CreateClient( parent, style ); | |
296 | }; | |
297 | ||
298 | wxMDIClientWindow::~wxMDIClientWindow(void) | |
299 | { | |
300 | }; | |
301 | ||
debe6624 | 302 | bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style ) |
c801d85f KB |
303 | { |
304 | m_needParent = TRUE; | |
a3622daa | 305 | |
c801d85f KB |
306 | PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" ); |
307 | ||
308 | m_widget = gtk_notebook_new(); | |
a3622daa | 309 | |
716b7364 RR |
310 | gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page", |
311 | GTK_SIGNAL_FUNC(gtk_page_change_callback), (gpointer)this ); | |
a3622daa | 312 | |
716b7364 | 313 | gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); |
a3622daa | 314 | |
c801d85f | 315 | PostCreation(); |
a3622daa | 316 | |
c801d85f | 317 | Show( TRUE ); |
a3622daa | 318 | |
c801d85f KB |
319 | return TRUE; |
320 | }; | |
321 | ||
322 | void wxMDIClientWindow::AddChild( wxWindow *child ) | |
323 | { | |
716b7364 | 324 | if (!child->IsKindOf(CLASSINFO(wxMDIChildFrame))) |
c801d85f | 325 | { |
716b7364 RR |
326 | wxFAIL_MSG("wxNotebook::AddChild: Child has to be wxMDIChildFrame"); |
327 | return; | |
c801d85f | 328 | }; |
a3622daa | 329 | |
716b7364 | 330 | m_children.Append( child ); |
a3622daa | 331 | |
716b7364 RR |
332 | wxString s; |
333 | wxMDIChildFrame* mdi_child = (wxMDIChildFrame*) child; | |
334 | s = mdi_child->m_title; | |
c801d85f | 335 | if (s.IsNull()) s = "MDI child"; |
a3622daa | 336 | |
c801d85f KB |
337 | GtkWidget *label_widget; |
338 | label_widget = gtk_label_new( s ); | |
339 | gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 ); | |
a3622daa | 340 | |
33d0b396 RR |
341 | gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", |
342 | GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); | |
46dc76ba | 343 | |
c801d85f | 344 | gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), child->m_widget, label_widget ); |
a3622daa | 345 | |
716b7364 | 346 | mdi_child->m_page = (GtkNotebookPage*) (g_list_last(GTK_NOTEBOOK(m_widget)->children)->data); |
a3622daa | 347 | |
716b7364 | 348 | gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), m_children.Number()-1 ); |
7b5408ea RR |
349 | |
350 | gtk_page_change_callback( NULL, mdi_child->m_page, 0, this ); | |
c801d85f KB |
351 | }; |
352 | ||
353 |