]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/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"
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 class wxNotebookPage
: public wxObject
34 GtkNotebookPage
*m_page
;
36 wxWindow
*m_clientPanel
;
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(wxNotebook
, wxControl
)
57 IMPLEMENT_DYNAMIC_CLASS(wxNotebook
,wxControl
)
59 wxNotebook::wxNotebook(void)
62 m_pages
.DeleteContents( TRUE
);
65 wxNotebook::wxNotebook( wxWindow
*parent
, const wxWindowID id
,
66 const wxPoint
& pos
, const wxSize
& size
,
67 const long style
, const wxString
& name
)
70 m_pages
.DeleteContents( TRUE
);
71 Create( parent
, id
, pos
, size
, style
, name
);
74 wxNotebook::~wxNotebook(void)
76 if (m_imageList
) delete m_imageList
;
80 bool wxNotebook::Create(wxWindow
*parent
, const wxWindowID id
,
81 const wxPoint
& pos
, const wxSize
& size
,
82 const long style
, const wxString
& name
)
86 PreCreation( parent
, id
, pos
, size
, style
, name
);
88 m_widget
= gtk_notebook_new();
97 int wxNotebook::GetSelection(void) const
99 if (m_pages
.Number() == 0) return -1;
101 GtkNotebookPage
*g_page
= GTK_NOTEBOOK(m_widget
)->cur_page
;
103 wxNotebookPage
*page
= NULL
;
105 wxNode
*node
= m_pages
.First();
108 page
= (wxNotebookPage
*)node
->Data();
109 if (page
->m_page
== g_page
) break;
113 if (!node
) wxFatalError( "Notebook error." );
118 wxImageList
* wxNotebook::GetImageList(void) const
123 int wxNotebook::GetPageCount(void) const
125 return m_pages
.Number();
128 int wxNotebook::GetRowCount(void) const
133 wxString
wxNotebook::GetPageText( const int page
) const
135 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
137 return nb_page
->m_text
;
142 int wxNotebook::GetPageImage( const int page
) const
144 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
146 return nb_page
->m_image
;
151 void* wxNotebook::GetPageData( const int page
) const
153 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
155 return nb_page
->m_clientData
;
160 wxNotebookPage
* wxNotebook::GetNotebookPage(int page
) const
162 wxNotebookPage
*nb_page
= NULL
;
164 wxNode
*node
= m_pages
.First();
167 nb_page
= (wxNotebookPage
*)node
->Data();
168 if (nb_page
->m_id
== page
) break;
171 if (!node
) return NULL
;
175 int wxNotebook::SetSelection( const int page
)
177 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
178 if (!nb_page
) return -1;
181 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
184 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
189 if (!child
) return -1;
191 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page_num
);
196 void wxNotebook::SetImageList( wxImageList
* imageList
)
198 m_imageList
= imageList
;
201 bool wxNotebook::SetPageText( const int page
, const wxString
&text
)
203 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
204 if (!nb_page
) return FALSE
;
206 nb_page
->m_text
= text
;
213 bool wxNotebook::SetPageImage( const int page
, const int image
)
215 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
219 nb_page
->m_image
= image
;
226 bool wxNotebook::SetPageData( const int page
, void* data
)
228 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
229 if (!nb_page
) return FALSE
;
231 nb_page
->m_clientData
= data
;
236 void wxNotebook::SetPageSize( const wxSize
&WXUNUSED(size
) )
240 void wxNotebook::SetPadding( const wxSize
&WXUNUSED(padding
) )
245 bool wxNotebook::DeleteAllPages(void)
247 wxNode
*page_node
= m_pages
.First();
250 wxNotebookPage
*page
= (wxNotebookPage
*)page_node
->Data();
252 DeletePage( page
->m_id
);
254 page_node
= m_pages
.First();
260 bool wxNotebook::DeletePage( const int page
)
262 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
263 if (!nb_page
) return FALSE
;
266 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
269 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
276 delete nb_page
->m_clientPanel
;
278 // Amazingly, this is not necessary
279 // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
281 m_pages
.DeleteObject( nb_page
);
286 bool wxNotebook::AddPage(wxWindow
* win
, const wxString
& text
, const int imageId
, void* data
)
288 // we've created the notebook page in AddChild(). Now we just have to set
289 // the caption for the page and set the others parameters.
291 // first, find the page
292 wxNotebookPage
*page
= NULL
;
294 wxNode
*node
= m_pages
.First();
297 page
= (wxNotebookPage
*)node
->Data();
298 if ( page
->m_clientPanel
== win
)
303 if ( page
== NULL
) {
304 wxFAIL_MSG("Can't add a page whose parent is not the notebook!");
309 // then set the attributes
311 if ( page
->m_text
.IsEmpty() )
313 page
->m_image
= imageId
;
314 page
->m_clientData
= data
;
315 gtk_label_set(page
->m_label
, page
->m_text
);
320 wxWindow
*wxNotebook::GetPageWindow( const int page
) const
322 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
323 if (!nb_page
) return NULL
;
325 return nb_page
->m_clientPanel
;
328 void wxNotebook::AddChild( wxWindow
*win
)
330 wxNotebookPage
*page
= new wxNotebookPage();
332 page
->m_id
= GetPageCount();
333 page
->m_label
= (GtkLabel
*)gtk_label_new("no caption");
334 page
->m_clientPanel
= win
;
335 gtk_notebook_append_page(GTK_NOTEBOOK(m_widget
), win
->m_widget
,
336 (GtkWidget
*)page
->m_label
);
337 gtk_misc_set_alignment(GTK_MISC(page
->m_label
), 0.0, 0.5);
339 page
->m_page
= (GtkNotebookPage
*)
341 g_list_last(GTK_NOTEBOOK(m_widget
)->children
)->data
346 wxLogFatalError( "Notebook page creation error" );
350 m_pages
.Append( page
);
353 //-----------------------------------------------------------------------------
355 //-----------------------------------------------------------------------------
357 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent
, wxCommandEvent
)
359 wxTabEvent::wxTabEvent( WXTYPE commandType
, int id
) :
360 wxCommandEvent(commandType
, id
)