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