]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/mdi.cpp
no message
[wxWidgets.git] / src / gtk / mdi.cpp
CommitLineData
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
23extern wxList wxPendingDelete;
c801d85f
KB
24
25//-----------------------------------------------------------------------------
26// wxMDIParentFrame
27//-----------------------------------------------------------------------------
28
33d0b396 29static 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;
ff7b1510 37 }
a3622daa 38
33d0b396 39 win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
ff7b1510 40}
33d0b396 41
716b7364
RR
42// page change callback
43static 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;
ff7b1510 58 }
716b7364
RR
59 node = node->Next();
60 }
61}
62
33d0b396
RR
63//-----------------------------------------------------------------------------
64
c801d85f
KB
65IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame,wxFrame)
66
716b7364
RR
67BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame)
68END_EVENT_TABLE()
69
c801d85f
KB
70wxMDIParentFrame::wxMDIParentFrame(void)
71{
c67daf87
UR
72 m_clientWindow = (wxMDIClientWindow *) NULL;
73 m_currentChild = (wxMDIChildFrame *) NULL;
c801d85f 74 m_parentFrameActive = TRUE;
ff7b1510 75}
c801d85f
KB
76
77wxMDIParentFrame::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 81{
c67daf87
UR
82 m_clientWindow = (wxMDIClientWindow *) NULL;
83 m_currentChild = (wxMDIChildFrame *) NULL;
c801d85f
KB
84 m_parentFrameActive = TRUE;
85 Create( parent, id, title, pos, size, style, name );
ff7b1510 86}
c801d85f
KB
87
88wxMDIParentFrame::~wxMDIParentFrame(void)
89{
ff7b1510 90}
c801d85f
KB
91
92bool 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 101 return TRUE;
ff7b1510 102}
c801d85f 103
716b7364 104void 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 }
ff7b1510 115}
c801d85f 116
716b7364
RR
117void 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 }
ff7b1510 129}
716b7364
RR
130
131void wxMDIParentFrame::GetClientSize(int *width, int *height ) const
c801d85f 132{
716b7364 133 wxFrame::GetClientSize( width, height );
ff7b1510 134}
c801d85f 135
c801d85f
KB
136wxMDIChildFrame *wxMDIParentFrame::GetActiveChild(void) const
137{
138 return m_currentChild;
ff7b1510 139}
c801d85f
KB
140
141wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const
142{
143 return m_clientWindow;
ff7b1510 144}
c801d85f
KB
145
146wxMDIClientWindow *wxMDIParentFrame::OnCreateClient(void)
147{
148 m_clientWindow = new wxMDIClientWindow( this );
149 return m_clientWindow;
ff7b1510 150}
c801d85f
KB
151
152void wxMDIParentFrame::ActivateNext(void)
153{
716b7364
RR
154 if (m_clientWindow)
155 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
ff7b1510 156}
c801d85f
KB
157
158void wxMDIParentFrame::ActivatePrevious(void)
716b7364
RR
159{
160 if (m_clientWindow)
161 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow->m_widget) );
ff7b1510 162}
716b7364
RR
163
164void wxMDIParentFrame::OnActivate( wxActivateEvent& WXUNUSED(event) )
c801d85f 165{
ff7b1510 166}
c801d85f
KB
167
168void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent& WXUNUSED(event) )
169{
ff7b1510 170}
c801d85f
KB
171
172//-----------------------------------------------------------------------------
173// wxMDIChildFrame
174//-----------------------------------------------------------------------------
175
cf4219e7 176IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame,wxFrame)
c801d85f 177
cf4219e7 178BEGIN_EVENT_TABLE(wxMDIChildFrame, wxFrame)
9746a2ba 179 EVT_ACTIVATE(wxMDIChildFrame::OnActivate)
716b7364
RR
180END_EVENT_TABLE()
181
c801d85f
KB
182wxMDIChildFrame::wxMDIChildFrame(void)
183{
c67daf87
UR
184 m_menuBar = (wxMenuBar *) NULL;
185 m_page = (GtkNotebookPage *) NULL;
ff7b1510 186}
c801d85f
KB
187
188wxMDIChildFrame::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{
c67daf87
UR
193 m_menuBar = (wxMenuBar *) NULL;
194 m_page = (GtkNotebookPage *) NULL;
33d0b396 195 Create( parent, id, title, wxDefaultPosition, size, style, name );
ff7b1510 196}
c801d85f
KB
197
198wxMDIChildFrame::~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 {
c67daf87
UR
205 mdi_frame->SetMDIMenuBar( (wxMenuBar *) NULL );
206 mdi_frame->m_currentChild = (wxMDIChildFrame *) NULL;
ff7b1510 207 }
716b7364
RR
208 delete m_menuBar;
209 }
ff7b1510 210}
c801d85f
KB
211
212bool 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 );
ff7b1510 219}
c801d85f 220
cf4219e7 221void wxMDIChildFrame::GetClientSize( int *width, int *height ) const
c801d85f 222{
cf4219e7
RR
223 wxWindow::GetClientSize( width, height );
224}
9746a2ba 225
cf4219e7 226void wxMDIChildFrame::AddChild( wxWindow *child )
716b7364 227{
cf4219e7 228 wxWindow::AddChild( child );
716b7364 229}
cf4219e7 230
716b7364
RR
231static 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 240 node = node->Next();
ff7b1510
RR
241 }
242}
716b7364
RR
243
244void 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();
ff7b1510 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 }
ff7b1510 269}
cf4219e7
RR
270
271wxMenuBar *wxMDIChildFrame::GetMenuBar()
272{
273 return m_menuBar;
ff7b1510 274}
c801d85f
KB
275
276void wxMDIChildFrame::Activate(void)
277{
ff7b1510 278}
c801d85f 279
9746a2ba
RR
280void wxMDIChildFrame::OnActivate( wxActivateEvent &WXUNUSED(event) )
281{
ff7b1510 282}
9746a2ba 283
c801d85f
KB
284//-----------------------------------------------------------------------------
285// wxMDIClientWindow
286//-----------------------------------------------------------------------------
287
288IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow,wxWindow)
289
290wxMDIClientWindow::wxMDIClientWindow(void)
291{
ff7b1510 292}
c801d85f 293
debe6624 294wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame *parent, long style )
c801d85f
KB
295{
296 CreateClient( parent, style );
ff7b1510 297}
c801d85f
KB
298
299wxMDIClientWindow::~wxMDIClientWindow(void)
300{
ff7b1510 301}
c801d85f 302
debe6624 303bool 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 320 return TRUE;
ff7b1510 321}
c801d85f
KB
322
323void 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;
ff7b1510 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 350
c67daf87 351 gtk_page_change_callback( (GtkNotebook *) NULL, mdi_child->m_page, 0, this );
ff7b1510 352}
c801d85f
KB
353
354