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