]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/tabctrl.cpp
a12cf6ca59e561d930ce023c7dd46695ca9be0b7
[wxWidgets.git] / src / gtk / tabctrl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tabctrl.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Created: 01/02/97
6 // Id:
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "tabctrl.h"
13 #endif
14
15 #include "wx/tabctrl.h"
16 #include "wx/utils.h"
17 #include "wx/imaglist.h"
18
19 #include "wx/gtk/win_gtk.h"
20
21 //-----------------------------------------------------------------------------
22 // wxTabPage
23 //-----------------------------------------------------------------------------
24
25 class wxTabPage: public wxObject
26 {
27 public:
28
29 int m_id;
30 wxString m_text;
31 int m_image;
32 void *m_clientData;
33 GtkNotebookPage *m_page;
34 GtkWidget *m_wxwindow;
35 wxList m_children;
36
37 wxTabPage(void)
38 {
39 m_id = -1;
40 m_text = "";
41 m_image = -1;
42 m_clientData = NULL;
43 m_page = NULL;
44 m_wxwindow = NULL;
45 };
46
47 };
48
49 //-----------------------------------------------------------------------------
50 // wxTabCtrl
51 //-----------------------------------------------------------------------------
52
53 BEGIN_EVENT_TABLE(wxTabCtrl, wxControl)
54 END_EVENT_TABLE()
55
56 IMPLEMENT_DYNAMIC_CLASS(wxTabCtrl,wxControl)
57
58 wxTabCtrl::wxTabCtrl(void)
59 {
60 m_imageList = NULL;
61 m_pages.DeleteContents( TRUE );
62 };
63
64 wxTabCtrl::wxTabCtrl( wxWindow *parent, const wxWindowID id,
65 const wxPoint& pos, const wxSize& size,
66 const long style, const wxString& name )
67 {
68 m_imageList = NULL;
69 m_pages.DeleteContents( TRUE );
70 Create( parent, id, pos, size, style, name );
71 };
72
73 wxTabCtrl::~wxTabCtrl(void)
74 {
75 if (m_imageList) delete m_imageList;
76 DeleteAllItems();
77 };
78
79 bool wxTabCtrl::Create(wxWindow *parent, const wxWindowID id,
80 const wxPoint& pos, const wxSize& size,
81 const long style, const wxString& name )
82 {
83 m_needParent = TRUE;
84
85 PreCreation( parent, id, pos, size, style, name );
86
87 m_widget = gtk_notebook_new();
88
89 PostCreation();
90
91 Show( TRUE );
92
93 return TRUE;
94 };
95
96 int wxTabCtrl::GetSelection(void) const
97 {
98 return gtk_notebook_current_page( GTK_NOTEBOOK(m_widget) );
99 };
100
101 wxImageList* wxTabCtrl::GetImageList(void) const
102 {
103 return m_imageList;
104 };
105
106 int wxTabCtrl::GetItemCount(void) const
107 {
108 return m_pages.Number();
109 };
110
111 bool wxTabCtrl::GetItemRect( const int WXUNUSED(item), wxRect& WXUNUSED(rect) ) const
112 {
113 return FALSE;
114 };
115
116 int wxTabCtrl::GetRowCount(void) const
117 {
118 return 1;
119 };
120
121 wxString wxTabCtrl::GetItemText( const int item ) const
122 {
123 wxNode *node = m_pages.Nth( item );
124 if (node)
125 {
126 wxTabPage *page = (wxTabPage*)node->Data();
127 return page->m_text;
128 };
129 return "";
130 };
131
132 int wxTabCtrl::GetItemImage( const int item ) const
133 {
134 wxNode *node = m_pages.Nth( item );
135 if (node)
136 {
137 wxTabPage *page = (wxTabPage*)node->Data();
138 return page->m_image;
139 };
140 return -1;
141 };
142
143 void* wxTabCtrl::GetItemData( const int item ) const
144 {
145 wxNode *node = m_pages.Nth( item );
146 if (node)
147 {
148 wxTabPage *page = (wxTabPage*)node->Data();
149 return page->m_clientData;
150 };
151 return NULL;
152 };
153
154 int wxTabCtrl::SetSelection( const int item )
155 {
156 wxTabPage *page = NULL;
157
158 wxNode *node = m_pages.First();
159 while (node)
160 {
161 page = (wxTabPage*)node->Data();
162 if (page->m_id == item) break;
163 page = NULL;
164 node = node->Next();
165 };
166 if (!page) return -1;
167
168 int page_num = 0;
169 GList *child = GTK_NOTEBOOK(m_widget)->children;
170 while (child)
171 {
172 if (page->m_page == (GtkNotebookPage*)child->data) break;
173 page_num++;
174 child = child->next;
175 };
176
177 if (!child) return -1;
178
179 gtk_notebook_set_page( GTK_NOTEBOOK(m_widget), page_num );
180
181 return item;
182 };
183
184 void wxTabCtrl::SetImageList( wxImageList* imageList )
185 {
186 m_imageList = imageList;
187 };
188
189 bool wxTabCtrl::SetItemText( const int WXUNUSED(item), const wxString& WXUNUSED(text) )
190 {
191 return TRUE;
192 };
193
194 bool wxTabCtrl::SetItemImage( const int WXUNUSED(item), const int WXUNUSED(image) )
195 {
196 return TRUE;
197 };
198
199 bool wxTabCtrl::SetItemData( const int WXUNUSED(item), void* WXUNUSED(data) )
200 {
201 return TRUE;
202 };
203
204 void wxTabCtrl::SetItemSize( const wxSize &WXUNUSED(size) )
205 {
206 };
207
208 void wxTabCtrl::SetPadding( const wxSize &WXUNUSED(padding) )
209 {
210 };
211
212 bool wxTabCtrl::DeleteAllItems(void)
213 {
214 wxNode *page_node = m_pages.First();
215 while (page_node)
216 {
217 wxTabPage *page = (wxTabPage*)page_node->Data();
218
219 wxNode *node = page->m_children.First();
220 while (node)
221 {
222 wxWindow *child = (wxWindow*)node->Data();
223 delete child;
224
225 node = node->Next();
226 };
227
228 gtk_widget_destroy( page->m_wxwindow );
229
230 m_pages.DeleteObject( page );
231
232 page_node = m_pages.First();
233 };
234
235 return TRUE;
236 };
237
238 bool wxTabCtrl::DeleteItem( const int item )
239 {
240 wxTabPage *page = NULL;
241
242 wxNode *node = m_pages.First();
243 while (node)
244 {
245 page = (wxTabPage*)node->Data();
246 if (page->m_id == item) break;
247 node = node->Next();
248 };
249 if (!node) return FALSE;
250
251 node = page->m_children.First();
252 while (node)
253 {
254 wxWindow *child = (wxWindow*)node->Data();
255 delete child;
256
257 node = node->Next();
258 };
259
260 gtk_widget_destroy( page->m_wxwindow );
261
262 m_pages.DeleteObject( page );
263
264 return TRUE;
265 };
266
267 int wxTabCtrl::HitTest( const wxPoint &WXUNUSED(pt), long &WXUNUSED(flags) )
268 {
269 return wxTAB_HITTEST_NOWHERE;
270 };
271
272 int wxTabCtrl::InsertItem( const int item, const wxString &text, const int imageId, void* data )
273 {
274 wxTabPage *page = new wxTabPage;
275
276 page->m_text = text;
277 if (page->m_text.IsNull()) page->m_text = "";
278 page->m_id = item;
279 page->m_image = imageId;
280 page->m_clientData = data;
281
282 GtkWidget *label_widget = gtk_label_new( page->m_text );
283 gtk_misc_set_alignment( GTK_MISC(label_widget), 0.0, 0.5 );
284
285 page->m_wxwindow = gtk_myfixed_new();
286 gtk_widget_show( page->m_wxwindow );
287 gtk_widget_set_usize( page->m_wxwindow, 100, 100 );
288
289 gtk_notebook_append_page( GTK_NOTEBOOK(m_widget), page->m_wxwindow, label_widget );
290
291 page->m_page = GTK_NOTEBOOK(m_widget)->cur_page;
292
293 m_pages.Append( page );
294
295 return item;
296 };
297
298 void wxTabCtrl::AddChild( wxWindow *win )
299 {
300 GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
301
302 wxTabPage *page = NULL;
303
304 wxNode *node = m_pages.First();
305 while (node)
306 {
307 page = (wxTabPage*)node->Data();
308 if (page->m_page == g_page) break;
309 node = node->Next();
310 };
311
312 if (!page) wxFatalError( "wxTabCtrl error" );
313
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 );
316
317 page->m_children.Append( win );
318 };
319
320 //-----------------------------------------------------------------------------
321 // wxTabEvent
322 //-----------------------------------------------------------------------------
323
324 IMPLEMENT_DYNAMIC_CLASS(wxTabEvent, wxCommandEvent)
325
326 wxTabEvent::wxTabEvent( WXTYPE commandType, int id ) :
327 wxCommandEvent(commandType, id)
328 {
329 };