]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/mdi.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "mdi.h"
15 #include "wx/dialog.h"
17 #include "wx/gtk/win_gtk.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 const int wxMENU_HEIGHT
= 27;
26 //-----------------------------------------------------------------------------
28 //-----------------------------------------------------------------------------
30 extern wxList wxPendingDelete
;
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
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
) &&
47 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
50 //-----------------------------------------------------------------------------
51 // page change callback
52 //-----------------------------------------------------------------------------
54 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
55 GtkNotebookPage
*page
,
57 wxMDIClientWindow
*client_win
)
59 wxNode
*node
= client_win
->m_children
.First();
62 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
63 if (child_frame
->m_page
== page
)
65 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
66 mdi_frame
->m_currentChild
= child_frame
;
67 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
74 //-----------------------------------------------------------------------------
76 //-----------------------------------------------------------------------------
78 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
80 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
83 wxMDIParentFrame::wxMDIParentFrame(void)
85 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
86 m_currentChild
= (wxMDIChildFrame
*) NULL
;
87 m_parentFrameActive
= TRUE
;
90 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
91 wxWindowID id
, const wxString
& title
,
92 const wxPoint
& pos
, const wxSize
& size
,
93 long style
, const wxString
& name
)
95 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
96 m_currentChild
= (wxMDIChildFrame
*) NULL
;
97 m_parentFrameActive
= TRUE
;
98 Create( parent
, id
, title
, pos
, size
, style
, name
);
101 wxMDIParentFrame::~wxMDIParentFrame(void)
105 bool wxMDIParentFrame::Create( wxWindow
*parent
,
106 wxWindowID id
, const wxString
& title
,
107 const wxPoint
& pos
, const wxSize
& size
,
108 long style
, const wxString
& name
)
110 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
117 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
119 wxFrame::GtkOnSize( x
, y
, width
, height
);
123 m_mdiMenuBar
->m_x
= 0;
124 m_mdiMenuBar
->m_y
= 0;
125 m_mdiMenuBar
->m_width
= m_width
;
126 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
;
127 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 0, 0 );
128 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
, wxMENU_HEIGHT
);
132 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
134 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
135 m_mdiMenuBar
= menu_bar
;
138 m_mdiMenuBar
->m_x
= 0;
139 m_mdiMenuBar
->m_y
= 0;
140 m_mdiMenuBar
->m_width
= m_width
;
141 m_mdiMenuBar
->m_height
= wxMENU_HEIGHT
;
142 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_mdiMenuBar
->m_widget
, 0, 0 );
143 gtk_widget_set_usize( m_mdiMenuBar
->m_widget
, m_width
, wxMENU_HEIGHT
);
144 m_mdiMenuBar
->Show( TRUE
);
148 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
150 wxFrame::GetClientSize( width
, height
);
153 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
155 return m_currentChild
;
158 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
160 return m_clientWindow
;
163 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
165 m_clientWindow
= new wxMDIClientWindow( this );
166 return m_clientWindow
;
169 void wxMDIParentFrame::ActivateNext(void)
172 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
175 void wxMDIParentFrame::ActivatePrevious(void)
178 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
181 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
185 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
189 //-----------------------------------------------------------------------------
191 //-----------------------------------------------------------------------------
193 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
195 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
196 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
199 wxMDIChildFrame::wxMDIChildFrame(void)
201 m_menuBar
= (wxMenuBar
*) NULL
;
202 m_page
= (GtkNotebookPage
*) NULL
;
205 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
206 wxWindowID id
, const wxString
& title
,
207 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
208 long style
, const wxString
& name
)
210 m_menuBar
= (wxMenuBar
*) NULL
;
211 m_page
= (GtkNotebookPage
*) NULL
;
212 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
215 wxMDIChildFrame::~wxMDIChildFrame(void)
219 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
220 if (mdi_frame
->m_currentChild
== this)
222 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
223 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
229 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
230 wxWindowID id
, const wxString
& title
,
231 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
232 long style
, const wxString
& name
)
236 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
239 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
241 wxWindow::GetClientSize( width
, height
);
244 void wxMDIChildFrame::AddChild( wxWindow
*child
)
246 wxWindow::AddChild( child
);
249 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
251 menu
->SetInvokingWindow( win
);
252 wxNode
*node
= menu
->m_items
.First();
255 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
256 if (menuitem
->IsSubMenu())
257 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
262 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
264 m_menuBar
= menu_bar
;
268 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
270 if (m_menuBar
->m_parent
!= this)
272 wxNode
*node
= m_menuBar
->m_menus
.First();
275 wxMenu
*menu
= (wxMenu
*)node
->Data();
276 SetInvokingWindow( menu
, this );
280 m_menuBar
->m_parent
= mdi_frame
;
282 mdi_frame
->SetMDIMenuBar( m_menuBar
);
284 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_wxwindow
),
285 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
289 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
294 void wxMDIChildFrame::Activate(void)
298 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
302 //-----------------------------------------------------------------------------
303 // InsertChild callback for wxMDIClientWindow
304 //-----------------------------------------------------------------------------
306 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
308 wxString s
= child
->m_title
;
309 if (s
.IsNull()) s
= _("MDI child");
311 GtkWidget
*label_widget
= gtk_label_new( s
);
312 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
314 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
315 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
317 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
319 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
321 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
323 gtk_notebook_set_page( notebook
, parent
->m_children
.Number()-1 );
325 gtk_page_change_callback( (GtkNotebook
*) NULL
, child
->m_page
, 0, parent
);
328 //-----------------------------------------------------------------------------
330 //-----------------------------------------------------------------------------
332 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
334 wxMDIClientWindow::wxMDIClientWindow(void)
338 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
340 CreateClient( parent
, style
);
343 wxMDIClientWindow::~wxMDIClientWindow(void)
347 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
351 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
353 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
355 m_widget
= gtk_notebook_new();
357 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
358 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
360 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
362 m_parent
->AddChild( this );
364 (m_parent
->m_insertCallback
)( m_parent
, this );