]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/tabctrl.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 "tabctrl.h"
15 #include "wx/tabctrl.h"
17 #include "wx/imaglist.h"
19 #include "wx/gtk/win_gtk.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class wxTabPage
: public wxObject
33 GtkNotebookPage
*m_page
;
34 GtkWidget
*m_wxwindow
;
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 BEGIN_EVENT_TABLE(wxTabCtrl
, wxControl
)
56 IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl
,wxControl
)
58 wxTabCtrl::wxTabCtrl(void)
61 m_pages
.DeleteContents( TRUE
);
64 wxTabCtrl::wxTabCtrl( wxWindow
*parent
, const wxWindowID id
,
65 const wxPoint
& pos
, const wxSize
& size
,
66 const long style
, const wxString
& name
)
69 m_pages
.DeleteContents( TRUE
);
70 Create( parent
, id
, pos
, size
, style
, name
);
73 wxTabCtrl::~wxTabCtrl(void)
75 if (m_imageList
) delete m_imageList
;
79 bool wxTabCtrl::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 wxTabCtrl::GetSelection(void) const
98 return gtk_notebook_current_page( GTK_NOTEBOOK(m_widget
) );
101 wxImageList
* wxTabCtrl::GetImageList(void) const
106 int wxTabCtrl::GetItemCount(void) const
108 return m_pages
.Number();
111 bool wxTabCtrl::GetItemRect( const int WXUNUSED(item
), wxRect
& WXUNUSED(rect
) ) const
116 int wxTabCtrl::GetRowCount(void) const
121 wxString
wxTabCtrl::GetItemText( const int item
) const
123 wxNode
*node
= m_pages
.Nth( item
);
126 wxTabPage
*page
= (wxTabPage
*)node
->Data();
132 int wxTabCtrl::GetItemImage( const int item
) const
134 wxNode
*node
= m_pages
.Nth( item
);
137 wxTabPage
*page
= (wxTabPage
*)node
->Data();
138 return page
->m_image
;
143 void* wxTabCtrl::GetItemData( const int item
) const
145 wxNode
*node
= m_pages
.Nth( item
);
148 wxTabPage
*page
= (wxTabPage
*)node
->Data();
149 return page
->m_clientData
;
154 int wxTabCtrl::SetSelection( const int item
)
156 wxTabPage
*page
= NULL
;
158 wxNode
*node
= m_pages
.First();
161 page
= (wxTabPage
*)node
->Data();
162 if (page
->m_id
== item
) break;
166 if (!page
) return -1;
169 GList
*child
= GTK_NOTEBOOK(m_widget
)->children
;
172 if (page
->m_page
== (GtkNotebookPage
*)child
->data
) break;
177 if (!child
) return -1;
179 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget
), page_num
);
184 void wxTabCtrl::SetImageList( wxImageList
* imageList
)
186 m_imageList
= imageList
;
189 bool wxTabCtrl::SetItemText( const int WXUNUSED(item
), const wxString
& WXUNUSED(text
) )
194 bool wxTabCtrl::SetItemImage( const int WXUNUSED(item
), const int WXUNUSED(image
) )
199 bool wxTabCtrl::SetItemData( const int WXUNUSED(item
), void* WXUNUSED(data
) )
204 void wxTabCtrl::SetItemSize( const wxSize
&WXUNUSED(size
) )
208 void wxTabCtrl::SetPadding( const wxSize
&WXUNUSED(padding
) )
212 bool wxTabCtrl::DeleteAllItems(void)
214 wxNode
*page_node
= m_pages
.First();
217 wxTabPage
*page
= (wxTabPage
*)page_node
->Data();
219 wxNode
*node
= page
->m_children
.First();
222 wxWindow
*child
= (wxWindow
*)node
->Data();
228 gtk_widget_destroy( page
->m_wxwindow
);
230 m_pages
.DeleteObject( page
);
232 page_node
= m_pages
.First();
238 bool wxTabCtrl::DeleteItem( const int item
)
240 wxTabPage
*page
= NULL
;
242 wxNode
*node
= m_pages
.First();
245 page
= (wxTabPage
*)node
->Data();
246 if (page
->m_id
== item
) break;
249 if (!node
) return FALSE
;
251 node
= page
->m_children
.First();
254 wxWindow
*child
= (wxWindow
*)node
->Data();
260 gtk_widget_destroy( page
->m_wxwindow
);
262 m_pages
.DeleteObject( page
);
267 int wxTabCtrl::HitTest( const wxPoint
&WXUNUSED(pt
), long &WXUNUSED(flags
) )
269 return wxTAB_HITTEST_NOWHERE
;
272 int wxTabCtrl::InsertItem( const int item
, const wxString
&text
, const int imageId
, void* data
)
274 wxTabPage
*page
= new wxTabPage
;
277 if (page
->m_text
.IsNull()) page
->m_text
= "";
279 page
->m_image
= imageId
;
280 page
->m_clientData
= data
;
282 GtkWidget
*label_widget
= gtk_label_new( page
->m_text
);
283 gtk_misc_set_alignment( GTK_MISC(label_widget
), 0.0, 0.5 );
285 page
->m_wxwindow
= gtk_myfixed_new();
286 gtk_widget_show( page
->m_wxwindow
);
287 gtk_widget_set_usize( page
->m_wxwindow
, 100, 100 );
289 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget
), page
->m_wxwindow
, label_widget
);
291 page
->m_page
= GTK_NOTEBOOK(m_widget
)->cur_page
;
293 m_pages
.Append( page
);
298 void wxTabCtrl::AddChild( wxWindow
*win
)
300 GtkNotebookPage
*g_page
= GTK_NOTEBOOK(m_widget
)->cur_page
;
302 wxTabPage
*page
= NULL
;
304 wxNode
*node
= m_pages
.First();
307 page
= (wxTabPage
*)node
->Data();
308 if (page
->m_page
== g_page
) break;
312 if (!page
) wxFatalError( "wxTabCtrl error" );
314 gtk_myfixed_put( GTK_MYFIXED(page
->m_wxwindow
), win
->m_widget
, win
->m_x
, win
->m_y
);
315 gtk_widget_set_usize( win
->m_widget
, win
->m_width
, win
->m_height
);
317 page
->m_children
.Append( win
);
320 //-----------------------------------------------------------------------------
322 //-----------------------------------------------------------------------------
324 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent
, wxCommandEvent
)
326 wxTabEvent::wxTabEvent( WXTYPE commandType
, int id
) :
327 wxCommandEvent(commandType
, id
)