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