]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/mdi.cpp
Changed setup.h so that global memory operators are switched off for GnuWin32;
[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 {
122 int x = 0;
123 int y = 0;
124 GetClientSize( &x, &y );
6ca41e57 125 m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS );
716b7364 126 }
ff7b1510 127}
c801d85f 128
716b7364
RR
129void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar *menu_bar )
130{
131 if (m_mdiMenuBar) m_mdiMenuBar->Show( FALSE );
132 m_mdiMenuBar = menu_bar;
133 if (m_mdiMenuBar)
134 {
135 int x = 0;
136 int y = 0;
137 GetClientSize( &x, &y );
6ca41e57 138 m_mdiMenuBar->SetSize( 1, 1, x-2, wxMENU_HEIGHT-2, wxSIZE_NO_ADJUSTMENTS );
716b7364
RR
139 m_mdiMenuBar->Show( TRUE );
140 }
ff7b1510 141}
716b7364
RR
142
143void wxMDIParentFrame::GetClientSize(int *width, int *height ) const
c801d85f 144{
716b7364 145 wxFrame::GetClientSize( width, height );
ff7b1510 146}
c801d85f 147
c801d85f
KB
148wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
149{
150 return m_currentChild;
ff7b1510 151}
c801d85f
KB
152
153wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const
154{
155 return m_clientWindow;
ff7b1510 156}
c801d85f
KB
157
158wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
159{
160 m_clientWindow = new wxMDIClientWindow( this );
161 return m_clientWindow;
ff7b1510 162}
c801d85f
KB
163
164void wxMDIParentFrame::ActivateNext(void)
165{
716b7364
RR
166 if (m_clientWindow)
167 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
ff7b1510 168}
c801d85f
KB
169
170void wxMDIParentFrame::ActivatePrevious(void)
716b7364
RR
171{
172 if (m_clientWindow)
173 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
ff7b1510 174}
716b7364
RR
175
176void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) )
c801d85f 177{
ff7b1510 178}
c801d85f
KB
179
180void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) )
181{
ff7b1510 182}
c801d85f
KB
183
184//-----------------------------------------------------------------------------
185// wxMDIChildFrame
186//-----------------------------------------------------------------------------
187
cf4219e7 188IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
c801d85f 189
cf4219e7 190BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
9746a2ba 191 EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
716b7364
RR
192END_EVENT_TABLE()
193
c801d85f
KB
194wxMDIChildFrame::wxMDIChildFrame(void)
195{
c67daf87
UR
196 m_menuBar = (wxMenuBar *) NULL;
197 m_page = (GtkNotebookPage *) NULL;
ff7b1510 198}
c801d85f
KB
199
200wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame *parent,
debe6624 201 wxWindowID id, const wxString& title,
33d0b396 202 const wxPoint& WXUNUSED(pos), const wxSize& size,
debe6624 203 long style, const wxString& name )
c801d85f 204{
c67daf87
UR
205 m_menuBar = (wxMenuBar *) NULL;
206 m_page = (GtkNotebookPage *) NULL;
33d0b396 207 Create( parent, id, title, wxDefaultPosition, size, style, name );
ff7b1510 208}
c801d85f
KB
209
210wxMDIChildFrame::~wxMDIChildFrame(void)
211{
716b7364
RR
212 if (m_menuBar)
213 {
214 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
215 if (mdi_frame->m_currentChild == this)
216 {
c67daf87
UR
217 mdi_frame->SetMDIMenuBar( (wxMenuBar *) NULL );
218 mdi_frame->m_currentChild = (wxMDIChildFrame *) NULL;
ff7b1510 219 }
716b7364
RR
220 delete m_menuBar;
221 }
ff7b1510 222}
c801d85f
KB
223
224bool wxMDIChildFrame::Create( wxMDIParentFrame *parent,
debe6624 225 wxWindowID id, const wxString& title,
33d0b396 226 const wxPoint& WXUNUSED(pos), const wxSize& size,
debe6624 227 long style, const wxString& name )
c801d85f
KB
228{
229 m_title = title;
6ca41e57 230
cf4219e7 231 return wxWindow::Create( parent->GetClientWindow(), id, wxDefaultPosition, size, style, name );
ff7b1510 232}
c801d85f 233
cf4219e7 234void wxMDIChildFrame::GetClientSize( int *width, int *height ) const
c801d85f 235{
cf4219e7
RR
236 wxWindow::GetClientSize( width, height );
237}
9746a2ba 238
cf4219e7 239void wxMDIChildFrame::AddChild( wxWindow *child )
716b7364 240{
cf4219e7 241 wxWindow::AddChild( child );
716b7364 242}
cf4219e7 243
716b7364
RR
244static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
245{
246 menu->SetInvokingWindow( win );
247 wxNode *node = menu->m_items.First();
248 while (node)
249 {
250 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
46dc76ba
RR
251 if (menuitem->IsSubMenu())
252 SetInvokingWindow( menuitem->GetSubMenu(), win );
716b7364 253 node = node->Next();
ff7b1510
RR
254 }
255}
716b7364
RR
256
257void wxMDIChildFrame::SetMenuBar( wxMenuBar *menu_bar )
258{
259 m_menuBar = menu_bar;
a3622daa 260
716b7364
RR
261 if (m_menuBar)
262 {
263 wxMDIParentFrame *mdi_frame = (wxMDIParentFrame*)m_parent->m_parent;
a3622daa 264
716b7364
RR
265 if (m_menuBar->m_parent != this)
266 {
267 wxNode *node = m_menuBar->m_menus.First();
268 while (node)
269 {
270 wxMenu *menu = (wxMenu*)node->Data();
271 SetInvokingWindow( menu, this );
272 node = node->Next();
ff7b1510 273 }
a3622daa 274
716b7364
RR
275 m_menuBar->m_parent = mdi_frame;
276 }
277 mdi_frame->SetMDIMenuBar( m_menuBar );
278
6ca41e57 279 gtk_myfixed_put( GTK_MYFIXED(mdi_frame->m_wxwindow),
716b7364
RR
280 m_menuBar->m_widget, m_menuBar->m_x, m_menuBar->m_y );
281 }
ff7b1510 282}
cf4219e7
RR
283
284wxMenuBar *wxMDIChildFrame::GetMenuBar()
285{
286 return m_menuBar;
ff7b1510 287}
c801d85f
KB
288
289void wxMDIChildFrame::Activate(void)
290{
ff7b1510 291}
c801d85f 292
9746a2ba
RR
293void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) )
294{
ff7b1510 295}
9746a2ba 296
6ca41e57
RR
297//-----------------------------------------------------------------------------
298// InsertChild callback for wxMDIClientWindow
299//-----------------------------------------------------------------------------
300
301static void wxInsertChildInMDI( wxMDIClientWindow* parent, wxMDIChildFrame* child )
302{
303 wxString s = child->m_title;
304 if (s.IsNull()) s = _("MDI child");
305
306 GtkWidget *label_widget = gtk_label_new( s );
307 gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
308
309 gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
310 GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
311
312 GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
313
314 gtk_notebook_append_page( notebook, child->m_widget, label_widget );
315
316 child->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
317
318 gtk_notebook_set_page( notebook, parent->m_children.Number()-1 );
319
320 gtk_page_change_callback( (GtkNotebook *) NULL, child->m_page, 0, parent );
321}
322
c801d85f
KB
323//-----------------------------------------------------------------------------
324// wxMDIClientWindow
325//-----------------------------------------------------------------------------
326
327IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow)
328
329wxMDIClientWindow::wxMDIClientWindow(void)
330{
ff7b1510 331}
c801d85f 332
debe6624 333wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style )
c801d85f
KB
334{
335 CreateClient( parent, style );
ff7b1510 336}
c801d85f
KB
337
338wxMDIClientWindow::~wxMDIClientWindow(void)
339{
ff7b1510 340}
c801d85f 341
debe6624 342bool wxMDIClientWindow::CreateClient( wxMDIParentFrame *parent, long style )
c801d85f
KB
343{
344 m_needParent = TRUE;
6ca41e57
RR
345
346 m_insertCallback = (wxInsertChildFunction)wxInsertChildInMDI;
a3622daa 347
c801d85f
KB
348 PreCreation( parent, -1, wxPoint(10,10), wxSize(100,100), style, "wxMDIClientWindow" );
349
350 m_widget = gtk_notebook_new();
a3622daa 351
716b7364
RR
352 gtk_signal_connect( GTK_OBJECT(m_widget), "switch_page",
353 GTK_SIGNAL_FUNC(gtk_page_change_callback), (gpointer)this );
a3622daa 354
716b7364 355 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
a3622daa 356
6ca41e57
RR
357 gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x, m_y );
358
c801d85f 359 PostCreation();
a3622daa 360
c801d85f 361 Show( TRUE );
a3622daa 362
c801d85f 363 return TRUE;
ff7b1510 364}
c801d85f 365
c801d85f
KB
366
367