]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/notebook.cpp
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"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class wxNotebookPage
: public wxObject
32 GtkNotebookPage
*m_page
;
33 wxPanel
*m_clientPanel
;
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
54 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
,wxControl
)
56 wxNotebook::wxNotebook(void)
60 m_pages
.DeleteContents( TRUE
);
63 wxNotebook::wxNotebook( wxWindow
*parent
, const wxWindowID id
,
64 const wxPoint
& pos
, const wxSize
& size
,
65 const long style
, const wxString
& name
)
69 m_pages
.DeleteContents( TRUE
);
70 Create( parent
, id
, pos
, size
, style
, name
);
73 wxNotebook::~wxNotebook(void)
75 if (m_imageList
) delete m_imageList
;
79 bool wxNotebook::Create(wxWindow
*parent
, const wxWindowID id
,
80 const wxPoint
& pos
, const wxSize
& size
,
81 const long style
, const wxString
& name
)
85 PreCreation( parent
, id
, pos
, size
, style
, name
);
87 m_widget
= gtk_notebook_new();
96 int wxNotebook::GetSelection(void) const
98 if (m_pages
.Number() == 0) return -1;
100 GtkNotebookPage
*g_page
= GTK_NOTEBOOK(m_widget
)->cur_page
;
102 wxNotebookPage
*page
= NULL
;
104 wxNode
*node
= m_pages
.First();
107 page
= (wxNotebookPage
*)node
->Data();
108 if (page
->m_page
== g_page
) break;
112 if (!node
) wxFatalError( "Notebook error." );
117 wxImageList
* wxNotebook::GetImageList(void) const
122 int wxNotebook::GetPageCount(void) const
124 return m_pages
.Number();
127 int wxNotebook::GetRowCount(void) const
132 wxString
wxNotebook::GetPageText( const int page
) const
134 wxNotebookPage
*nb_page
= NULL
;
136 wxNode
*node
= m_pages
.First();
139 nb_page
= (wxNotebookPage
*)node
->Data();
140 if (nb_page
->m_id
== page
) break;
143 if (!node
) return "";
145 return nb_page
->m_text
;
148 int wxNotebook::GetPageImage( const int page
) const
150 wxNotebookPage
*nb_page
= NULL
;
152 wxNode
*node
= m_pages
.First();
155 nb_page
= (wxNotebookPage
*)node
->Data();
156 if (nb_page
->m_id
== page
) break;
159 if (!node
) return -1;
161 return nb_page
->m_image
;
164 void* wxNotebook::GetPageData( const int page
) const
166 wxNotebookPage
*nb_page
= NULL
;
168 wxNode
*node
= m_pages
.First();
171 nb_page
= (wxNotebookPage
*)node
->Data();
172 if (nb_page
->m_id
== page
) break;
175 if (!node
) return NULL
;
177 return nb_page
->m_clientData
;
180 int wxNotebook::SetSelection( const int page
)
182 wxNotebookPage
*nb_page
= NULL
;
184 wxNode
*node
= m_pages
.First();
187 nb_page
= (wxNotebookPage
*)node
->Data();
188 if (nb_page
->m_id
== page
) break;
191 if (!node
) return -1;
194 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
197 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
202 if (!child
) return -1;
204 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page_num
);
209 void wxNotebook::SetImageList( wxImageList
* imageList
)
211 m_imageList
= imageList
;
214 bool wxNotebook::SetPageText( const int page
, const wxString
&text
)
216 wxNotebookPage
*nb_page
= NULL
;
218 wxNode
*node
= m_pages
.First();
221 nb_page
= (wxNotebookPage
*)node
->Data();
222 if (nb_page
->m_id
== page
) break;
225 if (!node
) return FALSE
;
227 nb_page
->m_text
= text
;
234 bool wxNotebook::SetPageImage( const int page
, const int image
)
236 wxNotebookPage
*nb_page
= NULL
;
238 wxNode
*node
= m_pages
.First();
241 nb_page
= (wxNotebookPage
*)node
->Data();
242 if (nb_page
->m_id
== page
) break;
245 if (!node
) return FALSE
;
247 nb_page
->m_image
= image
;
254 bool wxNotebook::SetPageData( const int page
, void* data
)
256 wxNotebookPage
*nb_page
= NULL
;
258 wxNode
*node
= m_pages
.First();
261 nb_page
= (wxNotebookPage
*)node
->Data();
262 if (nb_page
->m_id
== page
) break;
265 if (!node
) return FALSE
;
267 nb_page
->m_clientData
= data
;
272 void wxNotebook::SetPageSize( const wxSize
&WXUNUSED(size
) )
276 void wxNotebook::SetPadding( const wxSize
&WXUNUSED(padding
) )
281 bool wxNotebook::DeleteAllPages(void)
283 wxNode
*page_node
= m_pages
.First();
286 wxNotebookPage
*page
= (wxNotebookPage
*)page_node
->Data();
288 DeletePage( page
->m_id
);
290 page_node
= m_pages
.First();
296 bool wxNotebook::DeletePage( const int page
)
298 wxNotebookPage
*nb_page
= NULL
;
300 wxNode
*node
= m_pages
.First();
303 nb_page
= (wxNotebookPage
*)node
->Data();
304 if (nb_page
->m_id
== page
) break;
307 if (!node
) return FALSE
;
310 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
313 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
320 delete nb_page
->m_clientPanel
;
322 // Amazingly, this is not necessary
323 // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
325 m_pages
.DeleteObject( nb_page
);
330 wxPanel
*wxNotebook::CreatePage( const int item
, const wxString
&text
, const int imageId
, void* data
)
332 wxNotebookPage
*page
= new wxNotebookPage
;
335 if (page
->m_text
.IsNull()) page
->m_text
= "";
337 page
->m_image
= imageId
;
338 page
->m_clientData
= data
;
340 m_frame
= gtk_label_new( page
->m_text
);
341 gtk_misc_set_alignment( GTK_MISC(m_frame
), 0.0, 0.5 );
343 page
->m_clientPanel
= new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) );
347 page
->m_page
= (GtkNotebookPage
*)( g_list_last( GTK_NOTEBOOK(m_widget
)->children
)->data
);
349 if (!page
->m_page
) wxFatalError( "Notebook page creation error" );
351 m_pages
.Append( page
);
353 return page
->m_clientPanel
;
356 wxPanel
*wxNotebook::GetPanel( const int page
)
358 wxNotebookPage
*nb_page
= NULL
;
360 wxNode
*node
= m_pages
.First();
363 nb_page
= (wxNotebookPage
*)node
->Data();
364 if (nb_page
->m_id
== page
) break;
367 if (!node
) return NULL
;
369 return nb_page
->m_clientPanel
;
372 void wxNotebook::AddChild( wxWindow
*win
)
374 if (!m_frame
) wxFatalError( "Notebook::Addchild() must not be called directly." );
376 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), win
->m_widget
, m_frame
);
379 //-----------------------------------------------------------------------------
381 //-----------------------------------------------------------------------------
383 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent
, wxCommandEvent
)
385 wxTabEvent::wxTabEvent( WXTYPE commandType
, int id
) :
386 wxCommandEvent(commandType
, id
)