]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/mdi.cpp
cd4c7355f4a8675275a12e6441ffda8cf0342a6b
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"
22 #include "wx/gtk/win_gtk.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 const int wxMENU_HEIGHT
= 27;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 extern wxList wxPendingDelete
;
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 static void gtk_page_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxWindow
*win
)
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
) &&
51 win
->SetSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
54 //-----------------------------------------------------------------------------
55 // page change callback
56 //-----------------------------------------------------------------------------
58 static void gtk_page_change_callback( GtkNotebook
*WXUNUSED(widget
),
59 GtkNotebookPage
*page
,
61 wxMDIClientWindow
*client_win
)
63 wxNode
*node
= client_win
->m_children
.First();
66 wxMDIChildFrame
*child_frame
= (wxMDIChildFrame
*)node
->Data();
67 if (child_frame
->m_page
== page
)
69 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)client_win
->m_parent
;
70 mdi_frame
->m_currentChild
= child_frame
;
71 mdi_frame
->SetMDIMenuBar( child_frame
->m_menuBar
);
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame
,wxFrame
)
84 BEGIN_EVENT_TABLE(wxMDIParentFrame
, wxFrame
)
87 wxMDIParentFrame::wxMDIParentFrame(void)
89 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
90 m_currentChild
= (wxMDIChildFrame
*) NULL
;
91 m_parentFrameActive
= TRUE
;
94 wxMDIParentFrame::wxMDIParentFrame( wxWindow
*parent
,
95 wxWindowID id
, const wxString
& title
,
96 const wxPoint
& pos
, const wxSize
& size
,
97 long style
, const wxString
& name
)
99 m_clientWindow
= (wxMDIClientWindow
*) NULL
;
100 m_currentChild
= (wxMDIChildFrame
*) NULL
;
101 m_parentFrameActive
= TRUE
;
102 Create( parent
, id
, title
, pos
, size
, style
, name
);
105 wxMDIParentFrame::~wxMDIParentFrame(void)
109 bool wxMDIParentFrame::Create( wxWindow
*parent
,
110 wxWindowID id
, const wxString
& title
,
111 const wxPoint
& pos
, const wxSize
& size
,
112 long style
, const wxString
& name
)
114 wxFrame::Create( parent
, id
, title
, pos
, size
, style
, name
);
121 void wxMDIParentFrame::GtkOnSize( int x
, int y
, int width
, int height
)
123 wxFrame::GtkOnSize( x
, y
, width
, height
);
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
);
136 void wxMDIParentFrame::SetMDIMenuBar( wxMenuBar
*menu_bar
)
138 if (m_mdiMenuBar
) m_mdiMenuBar
->Show( FALSE
);
139 m_mdiMenuBar
= menu_bar
;
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
);
152 void wxMDIParentFrame::GetClientSize(int *width
, int *height
) const
154 wxFrame::GetClientSize( width
, height
);
157 wxMDIChildFrame
*wxMDIParentFrame::GetActiveChild(void) const
159 return m_currentChild
;
162 wxMDIClientWindow
*wxMDIParentFrame::GetClientWindow(void) const
164 return m_clientWindow
;
167 wxMDIClientWindow
*wxMDIParentFrame::OnCreateClient(void)
169 m_clientWindow
= new wxMDIClientWindow( this );
170 return m_clientWindow
;
173 void wxMDIParentFrame::ActivateNext(void)
176 gtk_notebook_next_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
179 void wxMDIParentFrame::ActivatePrevious(void)
182 gtk_notebook_prev_page( GTK_NOTEBOOK(m_clientWindow
->m_widget
) );
185 void wxMDIParentFrame::OnActivate( wxActivateEvent
& WXUNUSED(event
) )
189 void wxMDIParentFrame::OnSysColourChanged( wxSysColourChangedEvent
& WXUNUSED(event
) )
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
197 IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame
,wxFrame
)
199 BEGIN_EVENT_TABLE(wxMDIChildFrame
, wxFrame
)
200 EVT_ACTIVATE(wxMDIChildFrame::OnActivate
)
203 wxMDIChildFrame::wxMDIChildFrame(void)
205 m_menuBar
= (wxMenuBar
*) NULL
;
206 m_page
= (GtkNotebookPage
*) NULL
;
209 wxMDIChildFrame::wxMDIChildFrame( wxMDIParentFrame
*parent
,
210 wxWindowID id
, const wxString
& title
,
211 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
212 long style
, const wxString
& name
)
214 m_menuBar
= (wxMenuBar
*) NULL
;
215 m_page
= (GtkNotebookPage
*) NULL
;
216 Create( parent
, id
, title
, wxDefaultPosition
, size
, style
, name
);
219 wxMDIChildFrame::~wxMDIChildFrame(void)
223 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
224 if (mdi_frame
->m_currentChild
== this)
226 mdi_frame
->SetMDIMenuBar( (wxMenuBar
*) NULL
);
227 mdi_frame
->m_currentChild
= (wxMDIChildFrame
*) NULL
;
233 bool wxMDIChildFrame::Create( wxMDIParentFrame
*parent
,
234 wxWindowID id
, const wxString
& title
,
235 const wxPoint
& WXUNUSED(pos
), const wxSize
& size
,
236 long style
, const wxString
& name
)
240 return wxWindow::Create( parent
->GetClientWindow(), id
, wxDefaultPosition
, size
, style
, name
);
243 void wxMDIChildFrame::GetClientSize( int *width
, int *height
) const
245 wxWindow::GetClientSize( width
, height
);
248 void wxMDIChildFrame::AddChild( wxWindow
*child
)
250 wxWindow::AddChild( child
);
253 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
255 menu
->SetInvokingWindow( win
);
256 wxNode
*node
= menu
->m_items
.First();
259 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
260 if (menuitem
->IsSubMenu())
261 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
266 void wxMDIChildFrame::SetMenuBar( wxMenuBar
*menu_bar
)
268 m_menuBar
= menu_bar
;
272 wxMDIParentFrame
*mdi_frame
= (wxMDIParentFrame
*)m_parent
->m_parent
;
274 if (m_menuBar
->m_parent
!= this)
276 wxNode
*node
= m_menuBar
->m_menus
.First();
279 wxMenu
*menu
= (wxMenu
*)node
->Data();
280 SetInvokingWindow( menu
, this );
284 m_menuBar
->m_parent
= mdi_frame
;
286 mdi_frame
->SetMDIMenuBar( m_menuBar
);
288 gtk_myfixed_put( GTK_MYFIXED(mdi_frame
->m_wxwindow
),
289 m_menuBar
->m_widget
, m_menuBar
->m_x
, m_menuBar
->m_y
);
293 wxMenuBar
*wxMDIChildFrame::GetMenuBar()
298 void wxMDIChildFrame::Activate(void)
302 void wxMDIChildFrame::OnActivate( wxActivateEvent
&WXUNUSED(event
) )
306 //-----------------------------------------------------------------------------
307 // InsertChild callback for wxMDIClientWindow
308 //-----------------------------------------------------------------------------
310 static void wxInsertChildInMDI( wxMDIClientWindow
* parent
, wxMDIChildFrame
* child
)
312 wxString s
= child
->m_title
;
313 if (s
.IsNull()) s
= _("MDI child");
315 GtkWidget
*label_widget
= gtk_label_new( s
);
316 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
318 gtk_signal_connect( GTK_OBJECT(child
->m_widget
), "size_allocate",
319 GTK_SIGNAL_FUNC(gtk_page_size_callback
), (gpointer
)child
);
321 GtkNotebook
*notebook
= GTK_NOTEBOOK(parent
->m_widget
);
323 gtk_notebook_append_page( notebook
, child
->m_widget
, label_widget
);
325 child
->m_page
= (GtkNotebookPage
*) (g_list_last(notebook
->children
)->data
);
327 gtk_notebook_set_page( notebook
, parent
->m_children
.Number()-1 );
329 gtk_page_change_callback( (GtkNotebook
*) NULL
, child
->m_page
, 0, parent
);
332 //-----------------------------------------------------------------------------
334 //-----------------------------------------------------------------------------
336 IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow
,wxWindow
)
338 wxMDIClientWindow::wxMDIClientWindow(void)
342 wxMDIClientWindow::wxMDIClientWindow( wxMDIParentFrame
*parent
, long style
)
344 CreateClient( parent
, style
);
347 wxMDIClientWindow::~wxMDIClientWindow(void)
351 bool wxMDIClientWindow::CreateClient( wxMDIParentFrame
*parent
, long style
)
355 m_insertCallback
= (wxInsertChildFunction
)wxInsertChildInMDI
;
357 PreCreation( parent
, -1, wxPoint(10,10), wxSize(100,100), style
, "wxMDIClientWindow" );
359 m_widget
= gtk_notebook_new();
361 gtk_signal_connect( GTK_OBJECT(m_widget
), "switch_page",
362 GTK_SIGNAL_FUNC(gtk_page_change_callback
), (gpointer
)this );
364 gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget
), 1 );
366 m_parent
->AddChild( this );
368 (m_parent
->m_insertCallback
)( m_parent
, this );