]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/notebook.cpp
0dcc82b7b66dcc1e57bba761ee15457e9e3f3f06
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "notebook.h"
15 #include "wx/notebook.h"
18 #include "wx/imaglist.h"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class wxNotebookPage
: public wxObject
34 GtkNotebookPage
*m_page
;
36 wxWindow
*m_clientPanel
;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
55 EVT_SIZE(wxNotebook::OnSize
)
58 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
,wxControl
)
60 wxNotebook::wxNotebook(void)
63 m_pages
.DeleteContents( TRUE
);
66 wxNotebook::wxNotebook( wxWindow
*parent
, const wxWindowID id
,
67 const wxPoint
& pos
, const wxSize
& size
,
68 const long style
, const wxString
& name
)
71 m_pages
.DeleteContents( TRUE
);
72 Create( parent
, id
, pos
, size
, style
, name
);
75 wxNotebook::~wxNotebook(void)
77 if (m_imageList
) delete m_imageList
;
81 bool wxNotebook::Create(wxWindow
*parent
, const wxWindowID id
,
82 const wxPoint
& pos
, const wxSize
& size
,
83 const long style
, const wxString
& name
)
87 PreCreation( parent
, id
, pos
, size
, style
, name
);
89 m_widget
= gtk_notebook_new();
98 int wxNotebook::GetSelection(void) const
100 if (m_pages
.Number() == 0) return -1;
102 GtkNotebookPage
*g_page
= GTK_NOTEBOOK(m_widget
)->cur_page
;
104 wxNotebookPage
*page
= NULL
;
106 wxNode
*node
= m_pages
.First();
109 page
= (wxNotebookPage
*)node
->Data();
110 if (page
->m_page
== g_page
) break;
114 if (!node
) wxFatalError( "Notebook error." );
119 wxImageList
* wxNotebook::GetImageList(void) const
124 int wxNotebook::GetPageCount(void) const
126 return m_pages
.Number();
129 int wxNotebook::GetRowCount(void) const
134 wxString
wxNotebook::GetPageText( const int page
) const
136 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
138 return nb_page
->m_text
;
143 int wxNotebook::GetPageImage( const int page
) const
145 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
147 return nb_page
->m_image
;
152 void* wxNotebook::GetPageData( const int page
) const
154 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
156 return nb_page
->m_clientData
;
161 wxNotebookPage
* wxNotebook::GetNotebookPage(int page
) const
163 wxNotebookPage
*nb_page
= NULL
;
165 wxNode
*node
= m_pages
.First();
168 nb_page
= (wxNotebookPage
*)node
->Data();
169 if (nb_page
->m_id
== page
) break;
172 if (!node
) return NULL
;
176 int wxNotebook::SetSelection( const int page
)
178 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
179 if (!nb_page
) return -1;
182 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
185 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
190 if (!child
) return -1;
192 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page_num
);
197 void wxNotebook::SetImageList( wxImageList
* imageList
)
199 m_imageList
= imageList
;
202 bool wxNotebook::SetPageText( const int page
, const wxString
&text
)
204 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
205 if (!nb_page
) return FALSE
;
207 nb_page
->m_text
= text
;
214 bool wxNotebook::SetPageImage( const int page
, const int image
)
216 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
220 nb_page
->m_image
= image
;
227 bool wxNotebook::SetPageData( const int page
, void* data
)
229 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
230 if (!nb_page
) return FALSE
;
232 nb_page
->m_clientData
= data
;
237 void wxNotebook::SetPageSize( const wxSize
&WXUNUSED(size
) )
241 void wxNotebook::SetPadding( const wxSize
&WXUNUSED(padding
) )
246 bool wxNotebook::DeleteAllPages(void)
248 wxNode
*page_node
= m_pages
.First();
251 wxNotebookPage
*page
= (wxNotebookPage
*)page_node
->Data();
253 DeletePage( page
->m_id
);
255 page_node
= m_pages
.First();
261 bool wxNotebook::DeletePage( const int page
)
263 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
264 if (!nb_page
) return FALSE
;
267 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
270 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
277 delete nb_page
->m_clientPanel
;
279 // Amazingly, this is not necessary
280 // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
282 m_pages
.DeleteObject( nb_page
);
287 bool wxNotebook::AddPage(wxWindow
* win
, const wxString
& text
, const int imageId
, void* data
)
289 // we've created the notebook page in AddChild(). Now we just have to set
290 // the caption for the page and set the others parameters.
292 // first, find the page
293 wxNotebookPage
*page
= NULL
;
295 wxNode
*node
= m_pages
.First();
298 page
= (wxNotebookPage
*)node
->Data();
299 if ( page
->m_clientPanel
== win
)
304 if ( page
== NULL
) {
305 wxFAIL_MSG("Can't add a page whose parent is not the notebook!");
310 // then set the attributes
312 if ( page
->m_text
.IsEmpty() )
314 page
->m_image
= imageId
;
315 page
->m_clientData
= data
;
316 gtk_label_set(page
->m_label
, page
->m_text
);
321 wxWindow
*wxNotebook::GetPageWindow( const int page
) const
323 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
324 if (!nb_page
) return NULL
;
326 return nb_page
->m_clientPanel
;
329 void wxNotebook::AddChild( wxWindow
*win
)
331 // @@@ normally done in wxWindow::AddChild but for some reason wxNotebook
332 // case is speicla there (Robert?)
333 m_children
.Append(win
);
335 wxNotebookPage
*page
= new wxNotebookPage();
337 page
->m_id
= GetPageCount();
338 page
->m_label
= (GtkLabel
*)gtk_label_new("no caption");
339 page
->m_clientPanel
= win
;
340 gtk_notebook_append_page(GTK_NOTEBOOK(m_widget
), win
->m_widget
,
341 (GtkWidget
*)page
->m_label
);
342 gtk_misc_set_alignment(GTK_MISC(page
->m_label
), 0.0, 0.5);
344 page
->m_page
= (GtkNotebookPage
*)
346 g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
351 wxLogFatalError( "Notebook page creation error" );
355 m_pages
.Append( page
);
358 void wxNotebook::OnSize(wxSizeEvent
& event
)
360 // forward this event to all pages
361 wxNode
*node
= m_pages
.First();
364 wxNotebookPage
*page
= (wxNotebookPage
*)node
->Data();
365 page
->m_clientPanel
->SetSize(event
.GetSize().GetX(), event
.GetSize().GetY());
371 //-----------------------------------------------------------------------------
373 //-----------------------------------------------------------------------------
375 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent
, wxCommandEvent
)
377 wxTabEvent::wxTabEvent( WXTYPE commandType
, int id
) :
378 wxCommandEvent(commandType
, id
)