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