]>
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"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 class wxNotebookPage
: public wxObject
32 GtkNotebookPage
*m_page
;
33 wxWindow
*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
= GetNotebookPage(page
);
136 return nb_page
->m_text
;
141 int wxNotebook::GetPageImage( const int page
) const
143 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
145 return nb_page
->m_image
;
150 void* wxNotebook::GetPageData( const int page
) const
152 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
154 return nb_page
->m_clientData
;
159 wxNotebookPage
* wxNotebook::GetNotebookPage(int page
) const
161 wxNotebookPage
*nb_page
= NULL
;
163 wxNode
*node
= m_pages
.First();
166 nb_page
= (wxNotebookPage
*)node
->Data();
167 if (nb_page
->m_id
== page
) break;
170 if (!node
) return NULL
;
174 int wxNotebook::SetSelection( const int page
)
176 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
177 if (!nb_page
) return -1;
180 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
183 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
188 if (!child
) return -1;
190 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page_num
);
195 void wxNotebook::SetImageList( wxImageList
* imageList
)
197 m_imageList
= imageList
;
200 bool wxNotebook::SetPageText( const int page
, const wxString
&text
)
202 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
203 if (!nb_page
) return FALSE
;
205 nb_page
->m_text
= text
;
212 bool wxNotebook::SetPageImage( const int page
, const int image
)
214 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
218 nb_page
->m_image
= image
;
225 bool wxNotebook::SetPageData( const int page
, void* data
)
227 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
228 if (!nb_page
) return FALSE
;
230 nb_page
->m_clientData
= data
;
235 void wxNotebook::SetPageSize( const wxSize
&WXUNUSED(size
) )
239 void wxNotebook::SetPadding( const wxSize
&WXUNUSED(padding
) )
244 bool wxNotebook::DeleteAllPages(void)
246 wxNode
*page_node
= m_pages
.First();
249 wxNotebookPage
*page
= (wxNotebookPage
*)page_node
->Data();
251 DeletePage( page
->m_id
);
253 page_node
= m_pages
.First();
259 bool wxNotebook::DeletePage( const int page
)
261 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
262 if (!nb_page
) return FALSE
;
265 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
268 if (nb_page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
275 delete nb_page
->m_clientPanel
;
277 // Amazingly, this is not necessary
278 // gtk_notebook_remove_page( GTK_NOTEBOOK(m_widget), page_num );
280 m_pages
.DeleteObject( nb_page
);
285 bool wxNotebook::AddPage( const int item
, const wxString
&text
, wxWindow
* win
, const int imageId
, void* data
)
287 wxNotebookPage
*page
= new wxNotebookPage
;
290 if (page
->m_text
.IsNull()) page
->m_text
= "";
292 page
->m_image
= imageId
;
293 page
->m_clientData
= data
;
295 m_frame
= gtk_label_new( page
->m_text
);
296 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), win
->m_widget
, m_frame
);
298 gtk_misc_set_alignment( GTK_MISC(m_frame
), 0.0, 0.5 );
300 page
->m_clientPanel
= win
;
301 // page->m_clientPanel = new wxPanel( this, -1, wxPoint(0,0), wxSize(100,100) );
305 page
->m_page
= (GtkNotebookPage
*)( g_list_last( GTK_NOTEBOOK(m_widget
)->children
)->data
);
309 wxFatalError( "Notebook page creation error" );
313 m_pages
.Append( page
);
318 wxWindow
*wxNotebook::GetPageWindow( const int page
) const
320 wxNotebookPage
* nb_page
= GetNotebookPage(page
);
321 if (!nb_page
) return NULL
;
323 return nb_page
->m_clientPanel
;
326 void wxNotebook::AddChild( wxWindow
*win
)
328 if (!m_frame
) wxFatalError( "Notebook::Addchild() must not be called directly." );
330 // gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), win->m_widget, m_frame );
333 //-----------------------------------------------------------------------------
335 //-----------------------------------------------------------------------------
337 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent
, wxCommandEvent
)
339 wxTabEvent::wxTabEvent( WXTYPE commandType
, int id
) :
340 wxCommandEvent(commandType
, id
)