]>
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
= 30;
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
))
46 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
49 //-----------------------------------------------------------------------------
50 // page change callback
51 //-----------------------------------------------------------------------------
53 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
54 GtkNotebookPage
*page
,
56 wxMDIClientWindow
*client_win
)
58 wxNode
*node
= client_win
->m_children
.First();
61 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
62 if (child_frame
->m_page
== page
)
64 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
65 mdi_frame
->m_currentChild
= child_frame
;
66 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
79 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
82 wxMDIParentFrame::wxMDIParentFrame(void)
84 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
85 m_currentChild
= (wxMDIChildFrame
*) NULL
;
86 m_parentFrameActive
= TRUE
;
89 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
90 wxWindowID id
, const wxString
& title
,
91 const wxPoint
& pos
, const wxSize
& size
,
92 long style
, const wxString
& name
)
94 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
95 m_currentChild
= (wxMDIChildFrame
*) NULL
;
96 m_parentFrameActive
= TRUE
;
97 Create( parent
, id
, title
, pos
, size
, style
, name
);
100 wxMDIParentFrame::~wxMDIParentFrame(void)
104 bool wxMDIParentFrame::Create( wxWindow
*parent
,
105 wxWindowID id
, const wxString
& title
,
106 const wxPoint
& pos
, const wxSize
& size
,
107 long style
, const wxString
& name
)
109 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
116 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
118 wxFrame::GtkOnSize( x
, y
, width
, height
);
124 GetClientSize( &x
, &y
);
125 m_mdiMenuBar
->SetSize( 1, 1, x
-2, wxMENU_HEIGHT
-2, wxSIZE_NO_ADJUSTMENTS
);
129 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
131 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
132 m_mdiMenuBar
= menu_bar
;
137 GetClientSize( &x
, &y
);
138 m_mdiMenuBar
->SetSize( 1, 1, x
-2, wxMENU_HEIGHT
-2, wxSIZE_NO_ADJUSTMENTS
);
139 m_mdiMenuBar
->Show( TRUE
);
143 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
145 wxFrame::GetClientSize( width
, height
);
148 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
150 return m_currentChild
;
153 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
155 return m_clientWindow
;
158 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
160 m_clientWindow
= new wxMDIClientWindow( this );
161 return m_clientWindow
;
164 void wxMDIParentFrame::ActivateNext(void)
167 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
170 void wxMDIParentFrame::ActivatePrevious(void)
173 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
176 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
180 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
184 //-----------------------------------------------------------------------------
186 //-----------------------------------------------------------------------------
188 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
190 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
191 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
194 wxMDIChildFrame::wxMDIChildFrame(void)
196 m_menuBar
= (wxMenuBar
*) NULL
;
197 m_page
= (GtkNotebookPage
*) NULL
;
200 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
201 wxWindowID id
, const wxString
& title
,
202 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
203 long style
, const wxString
& name
)
205 m_menuBar
= (wxMenuBar
*) NULL
;
206 m_page
= (GtkNotebookPage
*) NULL
;
207 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
210 wxMDIChildFrame::~wxMDIChildFrame(void)
214 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
215 if (mdi_frame
->m_currentChild
== this)
217 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
218 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
224 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
225 wxWindowID id
, const wxString
& title
,
226 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
227 long style
, const wxString
& name
)
231 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
234 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
236 wxWindow::GetClientSize( width
, height
);
239 void wxMDIChildFrame::AddChild( wxWindow
*child
)
241 wxWindow::AddChild( child
);
244 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
246 menu
->SetInvokingWindow( win
);
247 wxNode
*node
= menu
->m_items
.First();
250 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
251 if (menuitem
->IsSubMenu())
252 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
257 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
259 m_menuBar
= menu_bar
;
263 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
265 if (m_menuBar
->m_parent
!= this)
267 wxNode
*node
= m_menuBar
->m_menus
.First();
270 wxMenu
*menu
= (wxMenu
*)node
->Data();
271 SetInvokingWindow( menu
, this );
275 m_menuBar
->m_parent
= mdi_frame
;
277 mdi_frame
->SetMDIMenuBar( m_menuBar
);
279 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_wxwindow
),
280 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
284 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
289 void wxMDIChildFrame::Activate(void)
293 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
297 //-----------------------------------------------------------------------------
298 // InsertChild callback for wxMDIClientWindow
299 //-----------------------------------------------------------------------------
301 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
303 wxString s
= child
->m_title
;
304 if (s
.IsNull()) s
= _("MDI child");
306 GtkWidget
*label_widget
= gtk_label_new( s
);
307 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
309 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
310 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
312 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
314 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
316 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
318 gtk_notebook_set_page( notebook
, parent
->m_children
.Number()-1 );
320 gtk_page_change_callback( (GtkNotebook
*) NULL
, child
->m_page
, 0, parent
);
323 //-----------------------------------------------------------------------------
325 //-----------------------------------------------------------------------------
327 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
329 wxMDIClientWindow::wxMDIClientWindow(void)
333 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
335 CreateClient( parent
, style
);
338 wxMDIClientWindow::~wxMDIClientWindow(void)
342 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
346 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
348 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
350 m_widget
= gtk_notebook_new();
352 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
353 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
355 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
357 gtk_myfixed_put( GTK_MYFIXED(m_parent
->m_wxwindow
), m_widget
, m_x
, m_y
);