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