]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/treegtk.cpp
reSWIGged
[wxWidgets.git] / src / gtk1 / treegtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: treectrl.cpp
3 // Purpose: wxTreeCtrl
4 // Author: Denis Pershin
5 // Modified by:
6 // Created: 07/05/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Denis Pershin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "treectrl.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/gtk/treectrl.h"
28 #include "wx/textctrl.h"
29 #include "wx/log.h"
30
31 #include <gtk/gtk.h>
32
33 //static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
34 //static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
35
36 static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data);
37 static void gtk_treectrl_first_selected_callback(GtkWidget *widget, gpointer data);
38 static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data);
39
40 // static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
41 // static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
42 // static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
43
44 static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem);
45 static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem);
46 static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem);
47
48 static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
49 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
50 if (owner == NULL)
51 return;
52
53 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
54 owner->SendExpanding(GTK_TREE_ITEM(widget));
55 owner->SendExpanded(GTK_TREE_ITEM(widget));
56 };
57
58 static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
59 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
60 if (owner == NULL)
61 return;
62
63 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
64 owner->SendCollapsing(GTK_TREE_ITEM(widget));
65 owner->SendCollapsed(GTK_TREE_ITEM(widget));
66 };
67
68 static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItemId *treeitem) {
69 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
70 if (owner == NULL)
71 return;
72
73 // long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
74 owner->SendSelChanging(GTK_TREE_ITEM(widget));
75 owner->SendSelChanged(GTK_TREE_ITEM(widget));
76 }
77
78 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
79
80
81 void wxTreeCtrl::Init() {
82 m_imageListNormal = NULL;
83 m_imageListState = NULL;
84 m_textCtrl = NULL;
85 }
86
87 bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
88 const wxSize& size, long style,
89 const wxValidator& validator, const wxString& name) {
90 Init();
91
92 int x = pos.x;
93 int y = pos.y;
94 int width = size.x;
95 int height = size.y;
96
97 m_windowStyle = style;
98
99 SetParent(parent);
100
101 if (width <= 0)
102 width = 100;
103 if (height <= 0)
104 height = 30;
105 if (x < 0)
106 x = 0;
107 if (y < 0)
108 y = 0;
109
110 m_needParent = TRUE;
111
112 printf("precreate\n");
113 PreCreation( parent, id, pos, size, style, name );
114
115 printf("1\n");
116
117 m_widget = gtk_scrolled_window_new(NULL, NULL);
118 printf("2\n");
119 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
120 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
121
122 printf("3\n");
123 m_tree = GTK_TREE(gtk_tree_new());
124
125 printf("4\n");
126 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
127 printf("5\n");
128 gtk_widget_show(GTK_WIDGET(m_tree));
129
130 SetName(name);
131 SetValidator(validator);
132
133 printf("Robert's new insertion code :-)\n");
134 m_parent->DoAddChild( this );
135 printf("postcreate\n");
136 PostCreation();
137
138 gtk_widget_realize(GTK_WIDGET(m_tree));
139
140 Show(TRUE);
141
142 return TRUE;
143 }
144
145 wxTreeCtrl::~wxTreeCtrl(void) {
146 if (m_textCtrl)
147 delete m_textCtrl;
148 }
149
150 // Attributes
151 static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data) {
152 int count = (*((int *)data));
153
154 count++;
155 if (GTK_IS_CONTAINER(widget))
156 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_count_callback, data);
157 }
158
159 size_t wxTreeCtrl::GetCount() const {
160 int count = 0;
161
162 if (m_anchor != NULL)
163 gtk_treectrl_count_callback(GTK_WIDGET(m_anchor), &count);
164 return count;
165 }
166
167 unsigned int wxTreeCtrl::GetIndent() const {
168 return m_tree->indent_value;
169 }
170
171 void wxTreeCtrl::SetIndent(unsigned int indent) {
172 m_tree->indent_value = indent;
173 }
174
175 wxImageList *wxTreeCtrl::GetImageList() const {
176 return m_imageListNormal;
177 }
178
179 wxImageList *wxTreeCtrl::GetStateImageList() const {
180 return m_imageListState;
181 }
182
183 void wxTreeCtrl::SetImageList(wxImageList *imageList) {
184 m_imageListNormal = imageList;
185 }
186
187 void wxTreeCtrl::SetStateImageList(wxImageList *imageList) {
188 m_imageListState = imageList;
189 }
190
191 wxString wxTreeCtrl::GetItemText(const wxTreeItemId &item) const {
192 char *t;
193
194 if (!item.IsOk())
195 return wxString("");
196
197 GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
198 gtk_label_get(l, &t);
199
200 return t;
201 }
202
203 int wxTreeCtrl::GetItemImage(const wxTreeItemId& item) const {
204 if (!item.IsOk())
205 return (-1);
206
207 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "image");
208 }
209
210 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId& item) const {
211 if (!item.IsOk())
212 return (-1);
213
214 return (int)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage");
215 }
216
217 wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const {
218 if (!item.IsOk())
219 return NULL;
220
221 return (wxTreeItemData *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "data");
222 }
223
224 void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text) {
225 if (!item.IsOk())
226 return;
227
228 GtkLabel *l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label"));
229 gtk_label_set(l, text);
230 }
231
232 void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image) {
233 if (!item.IsOk())
234 return;
235
236 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "image", (void *)image);
237 }
238
239 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId& item, int image) {
240 if (!item.IsOk())
241 return;
242
243 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "selectedImage", (void *)image);
244 }
245
246 void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data) {
247 if (!item.IsOk())
248 return;
249
250 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "data", data);
251 }
252
253 bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const {
254 return GTK_WIDGET_VISIBLE(GTK_TREE_ITEM((GtkTreeItem *)item));
255 }
256
257 bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const {
258 GtkTreeItem *p = (GtkTreeItem *)item;
259
260 if (p->subtree == NULL)
261 return wxFalse;
262
263 if (GTK_TREE(p->subtree)->children == NULL)
264 return wxFalse;
265
266 if (g_list_length(GTK_TREE(p->subtree)->children) == 0)
267 return wxFalse;
268
269 return wxTrue;
270 }
271
272 bool wxTreeCtrl::IsExpanded(const wxTreeItemId& item) const {
273 return (((GtkTreeItem *)item)->expanded != 0);
274 }
275
276 bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const {
277 GtkTreeItem *p = (GtkTreeItem *)item;
278 GtkWidget *parent = GTK_WIDGET(p)->parent;
279
280 if (!GTK_IS_TREE(parent))
281 return wxFalse;
282
283 if (g_list_index(GTK_TREE(parent)->children, p) == -1)
284 return wxFalse;
285
286 return wxTrue;
287 }
288
289 wxTreeItemId wxTreeCtrl::GetRootItem() const {
290 return m_anchor;
291 }
292
293 static void gtk_treectrl_first_selected_callback(GtkWidget *widget, gpointer data) {
294 GtkTreeItem *p = (*((GtkTreeItem **)data));
295
296 GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
297
298 if (tree->selection != NULL) {
299 p = (GtkTreeItem *)tree->selection->data;
300 return;
301 }
302
303 if (GTK_IS_CONTAINER(widget))
304 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_selected_callback, data);
305 }
306
307 wxTreeItemId wxTreeCtrl::GetSelection() const {
308 GtkTreeItem *p = NULL;
309
310 if (m_anchor == NULL)
311 return NULL;
312
313 gtk_treectrl_first_selected_callback(GTK_WIDGET(m_anchor), &p);
314
315 return p;
316 }
317
318 wxTreeItemId wxTreeCtrl::GetItemParent(const wxTreeItemId& item) const {
319 if (item.IsOk())
320 return (GtkTreeItem *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "parent");
321
322 return NULL;
323 }
324
325 wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item, long& cookie) const {
326 GtkTreeItem *p = (GtkTreeItem *)item;
327 GtkWidget *parent = GTK_WIDGET(p)->parent;
328
329 if (!GTK_IS_TREE(parent))
330 return NULL;
331
332 cookie = 0;
333 return GTK_TREE_ITEM(g_list_first(GTK_TREE(parent)->children)->data);
334 }
335
336 wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& item, long& cookie) const {
337 GtkTreeItem *p = (GtkTreeItem *)item;
338 GtkWidget *parent = GTK_WIDGET(p)->parent;
339
340 if (!GTK_IS_TREE(parent))
341 return NULL;
342
343 cookie++;
344 return GTK_TREE_ITEM(g_list_nth(GTK_TREE(parent)->children, cookie)->data);
345 }
346
347 wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
348 {
349 GtkTreeItem *p = (GtkTreeItem *)item;
350 GtkWidget *parent = GTK_WIDGET(p)->parent;
351
352 wxCHECK_MSG( GTK_IS_TREE(parent), NULL, "invalid tree item" );
353
354 return GTK_TREE_ITEM(g_list_last(GTK_TREE(parent)->children)->data);
355 }
356
357 wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const {
358 GtkTreeItem *p = (GtkTreeItem *)item;
359 GtkWidget *parent = GTK_WIDGET(p)->parent;
360
361 if (!GTK_IS_TREE(parent))
362 return NULL;
363
364 if (g_list_index(GTK_TREE(parent)->children, p) == -1)
365 return NULL;
366
367 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
368 }
369
370 wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const {
371 GtkTreeItem *p = (GtkTreeItem *)item;
372 GtkWidget *parent = GTK_WIDGET(p)->parent;
373
374 if (!GTK_IS_TREE(parent))
375 return NULL;
376
377 if (g_list_index(GTK_TREE(parent)->children, p) == -1)
378 return NULL;
379
380 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
381 }
382
383 static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data) {
384 GtkTreeItem *p = (*((GtkTreeItem **)data));
385
386 GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
387
388 if (tree->children != NULL) {
389 guint len = g_list_length(tree->children);
390 for (guint i=0; i<len; i++) {
391 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data)))) {
392 p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data);
393 return;
394 }
395 }
396 }
397
398 if (GTK_IS_CONTAINER(widget))
399 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_visible_callback, data);
400 }
401
402 wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const {
403 GtkTreeItem *p = NULL;
404
405 if (m_anchor == NULL)
406 return NULL;
407
408 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor), &p);
409
410 return p;
411 }
412
413 wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const {
414 GtkTreeItem *p = (GtkTreeItem *)item;
415 GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
416 GtkTreeItem *q;
417
418 if (!GTK_IS_TREE(parent))
419 return NULL;
420
421 if (parent->children == NULL)
422 return NULL;
423
424 q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
425
426 while (q != p) {
427 q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, q))->data);
428 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
429 return q;
430 }
431
432 return NULL;
433 }
434
435 wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const {
436 GtkTreeItem *p = (GtkTreeItem *)item;
437 GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
438 GtkTreeItem *q;
439
440 if (!GTK_IS_TREE(parent))
441 return NULL;
442
443 if (parent->children == NULL)
444 return NULL;
445
446 q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
447
448 while (q != p) {
449 q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, q))->data);
450 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
451 return q;
452 }
453
454 return NULL;
455 }
456
457 wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, int image,
458 int selectedImage, wxTreeItemData *data) {
459 return p_InsertItem(0, text, image, selectedImage, data);
460 }
461
462 wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
463 const wxString& text, int image, int selectedImage,
464 wxTreeItemData *data) {
465 #warning "Need to implement PrependItem"
466 return NULL;
467 }
468
469 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
470 const wxTreeItemId& idPrevious, const wxString& text,
471 int image, int selectedImage, wxTreeItemData *data) {
472 #warning "Need to implement InsertItem"
473 return NULL;
474 }
475
476 wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
477 const wxString& text, int image, int selectedImage,
478 wxTreeItemData *data) {
479 return p_InsertItem(parent, text, image, selectedImage, data);
480 }
481
482 wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
483 const wxString& text, int image, int selectedImage,
484 wxTreeItemData *data) {
485 GtkTreeItem *item;
486
487 printf("begin insert\n");
488
489 item = GTK_TREE_ITEM(gtk_tree_item_new());
490
491 GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
492 gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
493
494 gtk_object_set_data(GTK_OBJECT(item), "w_box", m_box);
495
496 const wxBitmap *bmp;
497 const wxImageList *list;
498 if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
499 if ((bmp = list->GetBitmapPtr(image)) != NULL)
500 if (bmp->Ok()) {
501 GdkBitmap *mask = NULL;
502 if (bmp->GetMask())
503 mask = bmp->GetMask()->GetBitmap();
504 GtkPixmap *m_image_widget = GTK_PIXMAP(gtk_pixmap_new(bmp->GetPixmap(), mask));
505 gtk_misc_set_alignment (GTK_MISC (m_image_widget), 0.0, 0.5);
506 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_image_widget), FALSE, FALSE, 0);
507 gtk_object_set_data(GTK_OBJECT(item), "w_image", (void *)m_image_widget);
508 gtk_object_set_data(GTK_OBJECT(item), "image", (void *)image);
509 gtk_widget_show (GTK_WIDGET(m_image_widget));
510 }
511 GtkLabel *m_label_widget = GTK_LABEL(gtk_label_new ((char *)(const char *)text));
512 gtk_misc_set_alignment (GTK_MISC (m_label_widget), 0.5, 0.5);
513 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_label_widget), FALSE, FALSE, 0);
514 gtk_object_set_data(GTK_OBJECT(item), "w_label", m_label_widget);
515 gtk_widget_show (GTK_WIDGET(m_label_widget));
516
517 gtk_widget_show(GTK_WIDGET(m_box));
518
519 gtk_object_set_data(GTK_OBJECT(item), "owner", this);
520 gtk_object_set_data(GTK_OBJECT(item), "data", data);
521 gtk_object_set_data(GTK_OBJECT(item), "parent", p);
522
523 if (p != 0) {
524 if (p->subtree == NULL) {
525 GtkTree *tree = GTK_TREE(gtk_tree_new());
526 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
527 gtk_widget_show(GTK_WIDGET(tree));
528 p->expanded = 1;
529 }
530
531 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
532 } else {
533 printf("Adding root\n");
534 printf("m_tree = %p\n", m_tree);
535 m_anchor = item;
536 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
537 }
538
539 gtk_widget_show(GTK_WIDGET(item));
540
541 gtk_signal_connect(GTK_OBJECT(item), "select",
542 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
543
544 gtk_signal_connect(GTK_OBJECT(item), "deselect",
545 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
546
547 gtk_signal_connect(GTK_OBJECT(item), "expand",
548 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
549 gtk_signal_connect(GTK_OBJECT(item), "collapse",
550 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
551
552 return item;
553 }
554
555 void wxTreeCtrl::Delete(const wxTreeItemId& item) {
556 if (!item.IsOk())
557 return;
558
559 GtkTreeItem *parent = GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem *)item)->parent);
560 if (parent == NULL)
561 return;
562
563 gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET((GtkTreeItem *)item));
564
565 return;
566 }
567
568 void wxTreeCtrl::DeleteAllItems() {
569 gtk_tree_item_remove_subtree(m_anchor);
570 }
571
572 void wxTreeCtrl::Expand(const wxTreeItemId& item) {
573 if (!item.IsOk())
574 return;
575
576 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
577 }
578
579 void wxTreeCtrl::Collapse(const wxTreeItemId& item) {
580 if (!item.IsOk())
581 return;
582
583 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
584 }
585
586 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item) {
587 if (!item.IsOk())
588 return;
589
590 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
591 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem *)item));
592 }
593
594 void wxTreeCtrl::Toggle(const wxTreeItemId& item) {
595 if (!item.IsOk())
596 return;
597
598 if (((GtkTreeItem *)item)->expanded)
599 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
600 else
601 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
602 }
603
604 static void gtk_treectrl_unselect_callback(GtkWidget *widget, gpointer data) {
605 GtkTreeItem *p;
606
607 GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
608
609 if (tree->selection != NULL) {
610 guint len = g_list_length(tree->selection);
611 for (guint i=0; i<len; i++) {
612 p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->selection, i)->data);
613 gtk_tree_unselect_child(tree, GTK_WIDGET(p));
614 }
615 }
616
617 if (GTK_IS_CONTAINER(widget))
618 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_unselect_callback, data);
619 }
620
621 void wxTreeCtrl::Unselect() {
622 if (m_anchor == NULL)
623 return;
624
625 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor), NULL);
626 }
627
628 void wxTreeCtrl::SelectItem(const wxTreeItemId& item) {
629 if (!item.IsOk())
630 return;
631
632 gtk_tree_item_select((GtkTreeItem *)item);
633 }
634
635 void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) {
636 #warning "Need to implement EnsureVisible"
637 }
638
639 void wxTreeCtrl::ScrollTo(const wxTreeItemId& item) {
640 #warning "Need to implement ScrollTo"
641 }
642
643 wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
644 wxClassInfo* textControlClass) {
645 wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) );
646 #warning "Need to implement EditLabel"
647 /*
648 char *s;
649 m_editItem = item;
650
651 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
652 gtk_label_get(m_label, &s);
653
654 m_textCtrl = new wxTextCtrl(this, -1, s);
655 // m_textCtrl->SetValue(s);
656
657 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
658
659 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
660 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
661
662 */
663 return m_textCtrl;
664 }
665
666 wxTextCtrl* wxTreeCtrl::GetEditControl() const {
667 return m_textCtrl;
668 }
669
670 void wxTreeCtrl::EndEditLabel(const wxTreeItemId& item, bool discardChanges) {
671 #warning "Need to implement EndEditLabel"
672 /*
673 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
674 gtk_label_set(m_label, m_textCtrl->GetValue());
675
676 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
677
678 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
679 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
680
681 delete m_textCtrl;
682 m_textCtrl = NULL;
683 */
684 }
685
686 void wxTreeCtrl::ExpandItem(const wxTreeItemId& item, int action) {
687 switch (action) {
688 case wxTREE_EXPAND_EXPAND:
689 Expand(item);
690 break;
691
692 case wxTREE_EXPAND_COLLAPSE:
693 Collapse(item);
694 break;
695
696 case wxTREE_EXPAND_COLLAPSE_RESET:
697 CollapseAndReset(item);
698 break;
699
700 case wxTREE_EXPAND_TOGGLE:
701 Toggle(item);
702 break;
703
704 default:
705 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
706 }
707 }
708
709 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
710 const wxString& text, int image, int selImage,
711 long insertAfter) {
712 // InsertItem(parent, insertAfter, text, image, selImage);
713 #warning "Need to implement InsertItem"
714 return NULL;
715 }
716
717 /* Old functions
718 long wxTreeCtrl::GetChild(long item) const {
719 GtkTreeItem *p;
720 GtkTreeItem *next = NULL;
721
722 p = findGtkTreeItem(item);
723 GList *list = gtk_container_children(GTK_CONTAINER(p));
724 next = GTK_TREE_ITEM(list->data);;
725
726 if (next != NULL)
727 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
728
729 return (-1);
730 }
731
732 long wxTreeCtrl::GetFirstVisibleItem(void) const {
733 GtkTreeItem *next = NULL;
734
735 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
736 next = GTK_TREE_ITEM(list->data);;
737 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
738
739 if (next != NULL)
740 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
741
742 return (-1);
743 }
744
745 long wxTreeCtrl::GetNextVisibleItem(long item) const {
746 GtkTreeItem *p;
747 GtkTreeItem *next = NULL;
748
749 p = findGtkTreeItem(item);
750 GList *list = gtk_container_children(GTK_CONTAINER(p));
751 next = GTK_TREE_ITEM(list->data);;
752 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
753
754 if (next != NULL)
755 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
756
757 return (-1);
758 }
759
760 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
761 GtkTreeItem *p;
762
763 p = findGtkTreeItem(info.m_itemId);
764
765 if (p == NULL) {
766 wxLogSysError("TreeCtrl::GetItem failed");
767 return FALSE;
768 }
769
770 wxConvertFromGtkTreeItem(info, p);
771
772 return TRUE;
773 }
774
775 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
776 GtkTreeItem *p;
777
778 p = findGtkTreeItem(info.m_itemId);
779
780 if (p == NULL) {
781 wxLogSysError("TreeCtrl::SetItem failed");
782 return FALSE;
783 }
784
785 wxConvertToGtkTreeItem(this, info, &p);
786
787 return TRUE;
788 }
789
790 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
791 wxTreeItem info;
792
793 info.m_mask = wxTREE_MASK_STATE ;
794 info.m_stateMask = stateMask;
795 info.m_itemId = item;
796
797 if (!GetItem(info))
798 return 0;
799
800 return info.m_state;
801 }
802
803 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
804 wxTreeItem info;
805
806 info.m_mask = wxTREE_MASK_STATE ;
807 info.m_state = state;
808 info.m_stateMask = stateMask;
809 info.m_itemId = item;
810
811 return SetItem(info);
812 }
813 */
814
815 // Operations
816 /*
817 bool wxTreeCtrl::DeleteChildren(long item) {
818 GtkTreeItem *p;
819
820 p = findGtkTreeItem(item);
821 if (p == NULL)
822 return FALSE;
823
824 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
825
826 return TRUE;
827 }
828 */
829
830 /*
831 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
832 GtkTreeItem *p;
833 GtkTreeItem *item = NULL;
834
835 info.m_itemId = m_curitemId;
836 m_curitemId++;
837
838 wxConvertToGtkTreeItem(this, info, &item);
839
840 if (parent != 0) {
841 p = findGtkTreeItem(parent);
842 if (p->subtree == NULL) {
843 GtkTree *tree = GTK_TREE(gtk_tree_new());
844 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
845 gtk_widget_show(GTK_WIDGET(tree));
846 p->expanded = 1;
847 }
848
849 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
850 } else {
851 m_anchor = item;
852 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
853 }
854
855 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
856 GtkTree *tree = GTK_TREE(gtk_tree_new());
857 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
858 gtk_widget_show(GTK_WIDGET(tree));
859 }
860
861 gtk_widget_show(GTK_WIDGET(item));
862
863 gtk_signal_connect(GTK_OBJECT(item), "select",
864 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
865
866 gtk_signal_connect(GTK_OBJECT(item), "deselect",
867 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
868
869 gtk_signal_connect(GTK_OBJECT(item), "expand",
870 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
871 gtk_signal_connect(GTK_OBJECT(item), "collapse",
872 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
873
874 return info.m_itemId;
875 }
876
877 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
878 int selImage, long insertAfter) {
879
880 wxTreeItem info;
881 info.m_text = label;
882 info.m_mask = wxTREE_MASK_TEXT;
883 if (image > -1) {
884 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
885 info.m_image = image;
886 if (selImage == -1)
887 info.m_selectedImage = image;
888 else
889 info.m_selectedImage = selImage;
890 }
891
892 return InsertItem(parent, info, insertAfter);
893 }
894 */
895
896 void wxTreeCtrl::SendMessage(wxEventType command, const wxTreeItemId& item) {
897 wxTreeEvent event(command, GetId());
898 event.SetEventObject(this);
899 event.m_item = item;
900 ProcessEvent(event);
901 }
902
903 void wxTreeCtrl::SendExpanding(const wxTreeItemId& item) {
904 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING, item);
905 }
906
907 void wxTreeCtrl::SendExpanded(const wxTreeItemId& item) {
908 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED, item);
909 }
910
911 void wxTreeCtrl::SendCollapsing(const wxTreeItemId& item) {
912 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, item);
913 }
914
915 void wxTreeCtrl::SendCollapsed(const wxTreeItemId& item) {
916 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, item);
917 }
918
919 void wxTreeCtrl::SendSelChanging(const wxTreeItemId& item) {
920 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED, item);
921 }
922
923 void wxTreeCtrl::SendSelChanged(const wxTreeItemId& item) {
924 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING, item);
925 }
926
927 // Tree event
928 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
929
930 wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
931 wxCommandEvent(commandType, id) {
932 m_code = 0;
933 m_itemOld = 0;
934 }