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