]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/treectrl.cpp
dbdf733b00c7dfba891e4be2c7983af716873d7a
[wxWidgets.git] / src / gtk1 / treectrl.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 #ifdef __GNUG__
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 #if !USE_SHARED_LIBRARY
79 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
80
81 #endif
82
83 void wxTreeCtrl::Init() {
84 m_imageListNormal = NULL;
85 m_imageListState = NULL;
86 m_textCtrl = NULL;
87 }
88
89 bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos,
90 const wxSize& size, long style,
91 const wxValidator& validator, const wxString& name) {
92 Init();
93
94 int x = pos.x;
95 int y = pos.y;
96 int width = size.x;
97 int height = size.y;
98
99 m_windowStyle = style;
100
101 SetParent(parent);
102
103 if (width <= 0)
104 width = 100;
105 if (height <= 0)
106 height = 30;
107 if (x < 0)
108 x = 0;
109 if (y < 0)
110 y = 0;
111
112 m_needParent = TRUE;
113
114 printf("precreate\n");
115 PreCreation( parent, id, pos, size, style, name );
116
117 printf("1\n");
118
119 m_widget = gtk_scrolled_window_new(NULL, NULL);
120 printf("2\n");
121 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
122 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
123
124 printf("3\n");
125 m_tree = GTK_TREE(gtk_tree_new());
126
127 printf("4\n");
128 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
129 printf("5\n");
130 gtk_widget_show(GTK_WIDGET(m_tree));
131
132 SetName(name);
133 SetValidator(validator);
134
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::GetParent(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::GetNextSibling(const wxTreeItemId& item) const {
348 GtkTreeItem *p = (GtkTreeItem *)item;
349 GtkWidget *parent = GTK_WIDGET(p)->parent;
350
351 if (!GTK_IS_TREE(parent))
352 return NULL;
353
354 if (g_list_index(GTK_TREE(parent)->children, p) == -1)
355 return NULL;
356
357 return GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
358 }
359
360 wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const {
361 GtkTreeItem *p = (GtkTreeItem *)item;
362 GtkWidget *parent = GTK_WIDGET(p)->parent;
363
364 if (!GTK_IS_TREE(parent))
365 return NULL;
366
367 if (g_list_index(GTK_TREE(parent)->children, p) == -1)
368 return NULL;
369
370 return GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
371 }
372
373 static void gtk_treectrl_first_visible_callback(GtkWidget *widget, gpointer data) {
374 GtkTreeItem *p = (*((GtkTreeItem **)data));
375
376 GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
377
378 if (tree->children != NULL) {
379 guint len = g_list_length(tree->children);
380 for (guint i=0; i<len; i++) {
381 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data)))) {
382 p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->children, i)->data);
383 return;
384 }
385 }
386 }
387
388 if (GTK_IS_CONTAINER(widget))
389 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_first_visible_callback, data);
390 }
391
392 wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const {
393 GtkTreeItem *p = NULL;
394
395 if (m_anchor == NULL)
396 return NULL;
397
398 gtk_treectrl_first_visible_callback(GTK_WIDGET(m_anchor), &p);
399
400 return p;
401 }
402
403 wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const {
404 GtkTreeItem *p = (GtkTreeItem *)item;
405 GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
406 GtkTreeItem *q;
407
408 if (!GTK_IS_TREE(parent))
409 return NULL;
410
411 if (parent->children == NULL)
412 return NULL;
413
414 q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, p))->data);
415
416 while (q != p) {
417 q = GTK_TREE_ITEM(g_list_next(g_list_find(GTK_TREE(parent)->children, q))->data);
418 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
419 return q;
420 }
421
422 return NULL;
423 }
424
425 wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const {
426 GtkTreeItem *p = (GtkTreeItem *)item;
427 GtkTree *parent = GTK_TREE(GTK_WIDGET(p)->parent);
428 GtkTreeItem *q;
429
430 if (!GTK_IS_TREE(parent))
431 return NULL;
432
433 if (parent->children == NULL)
434 return NULL;
435
436 q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, p))->data);
437
438 while (q != p) {
439 q = GTK_TREE_ITEM(g_list_previous(g_list_find(GTK_TREE(parent)->children, q))->data);
440 if (GTK_WIDGET_VISIBLE(GTK_WIDGET(q)))
441 return q;
442 }
443
444 return NULL;
445 }
446
447 wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text, int image,
448 int selectedImage, wxTreeItemData *data) {
449 return p_InsertItem(0, text, image, selectedImage, data);
450 }
451
452 wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
453 const wxString& text, int image, int selectedImage,
454 wxTreeItemData *data) {
455 #warning "Need to implement PrependItem"
456 return NULL;
457 }
458
459 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
460 const wxTreeItemId& idPrevious, const wxString& text,
461 int image, int selectedImage, wxTreeItemData *data) {
462 #warning "Need to implement InsertItem"
463 return NULL;
464 }
465
466 wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
467 const wxString& text, int image, int selectedImage,
468 wxTreeItemData *data) {
469 return p_InsertItem(parent, text, image, selectedImage, data);
470 }
471
472 wxTreeItemId wxTreeCtrl::p_InsertItem(GtkTreeItem *p,
473 const wxString& text, int image, int selectedImage,
474 wxTreeItemData *data) {
475 GtkTreeItem *item;
476
477 printf("begin insert\n");
478
479 item = GTK_TREE_ITEM(gtk_tree_item_new());
480
481 GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
482 gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
483
484 gtk_object_set_data(GTK_OBJECT(item), "w_box", m_box);
485
486 const wxBitmap *bmp;
487 const wxImageList *list;
488 if ((list = GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
489 if ((bmp = list->GetBitmap(image)) != NULL)
490 if (bmp->Ok()) {
491 GdkBitmap *mask = NULL;
492 if (bmp->GetMask())
493 mask = bmp->GetMask()->GetBitmap();
494 GtkPixmap *m_image_widget = GTK_PIXMAP(gtk_pixmap_new(bmp->GetPixmap(), mask));
495 gtk_misc_set_alignment (GTK_MISC (m_image_widget), 0.0, 0.5);
496 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_image_widget), FALSE, FALSE, 0);
497 gtk_object_set_data(GTK_OBJECT(item), "w_image", (void *)m_image_widget);
498 gtk_object_set_data(GTK_OBJECT(item), "image", (void *)image);
499 gtk_widget_show (GTK_WIDGET(m_image_widget));
500 }
501 GtkLabel *m_label_widget = GTK_LABEL(gtk_label_new ((char *)(const char *)text));
502 gtk_misc_set_alignment (GTK_MISC (m_label_widget), 0.5, 0.5);
503 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_label_widget), FALSE, FALSE, 0);
504 gtk_object_set_data(GTK_OBJECT(item), "w_label", m_label_widget);
505 gtk_widget_show (GTK_WIDGET(m_label_widget));
506
507 gtk_widget_show(GTK_WIDGET(m_box));
508
509 gtk_object_set_data(GTK_OBJECT(item), "owner", this);
510 gtk_object_set_data(GTK_OBJECT(item), "data", data);
511 gtk_object_set_data(GTK_OBJECT(item), "parent", p);
512
513 if (p != 0) {
514 if (p->subtree == NULL) {
515 GtkTree *tree = GTK_TREE(gtk_tree_new());
516 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
517 gtk_widget_show(GTK_WIDGET(tree));
518 p->expanded = 1;
519 }
520
521 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
522 } else {
523 printf("Adding root\n");
524 printf("m_tree = %p\n", m_tree);
525 m_anchor = item;
526 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
527 }
528
529 gtk_widget_show(GTK_WIDGET(item));
530
531 gtk_signal_connect(GTK_OBJECT(item), "select",
532 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
533
534 gtk_signal_connect(GTK_OBJECT(item), "deselect",
535 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
536
537 gtk_signal_connect(GTK_OBJECT(item), "expand",
538 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
539 gtk_signal_connect(GTK_OBJECT(item), "collapse",
540 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
541
542 return item;
543 }
544
545 void wxTreeCtrl::Delete(const wxTreeItemId& item) {
546 if (!item.IsOk())
547 return;
548
549 GtkTreeItem *parent = GTK_TREE_ITEM(GTK_WIDGET((GtkTreeItem *)item)->parent);
550 if (parent == NULL)
551 return;
552
553 gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET((GtkTreeItem *)item));
554
555 return;
556 }
557
558 void wxTreeCtrl::DeleteAllItems() {
559 gtk_tree_item_remove_subtree(m_anchor);
560 }
561
562 void wxTreeCtrl::Expand(const wxTreeItemId& item) {
563 if (!item.IsOk())
564 return;
565
566 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
567 }
568
569 void wxTreeCtrl::Collapse(const wxTreeItemId& item) {
570 if (!item.IsOk())
571 return;
572
573 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
574 }
575
576 void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item) {
577 if (!item.IsOk())
578 return;
579
580 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
581 gtk_tree_item_remove_subtree(GTK_TREE_ITEM((GtkTreeItem *)item));
582 }
583
584 void wxTreeCtrl::Toggle(const wxTreeItemId& item) {
585 if (!item.IsOk())
586 return;
587
588 if (((GtkTreeItem *)item)->expanded)
589 gtk_tree_item_collapse(GTK_TREE_ITEM((GtkTreeItem *)item));
590 else
591 gtk_tree_item_expand(GTK_TREE_ITEM((GtkTreeItem *)item));
592 }
593
594 static void gtk_treectrl_unselect_callback(GtkWidget *widget, gpointer data) {
595 GtkTreeItem *p;
596
597 GtkTree *tree = GTK_TREE(GTK_TREE_ITEM(widget)->subtree);
598
599 if (tree->selection != NULL) {
600 guint len = g_list_length(tree->selection);
601 for (guint i=0; i<len; i++) {
602 p = GTK_TREE_ITEM((GtkTreeItem *)g_list_nth(tree->selection, i)->data);
603 gtk_tree_unselect_child(tree, GTK_WIDGET(p));
604 }
605 }
606
607 if (GTK_IS_CONTAINER(widget))
608 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_unselect_callback, data);
609 }
610
611 void wxTreeCtrl::Unselect() {
612 if (m_anchor == NULL)
613 return;
614
615 gtk_treectrl_unselect_callback(GTK_WIDGET(m_anchor), NULL);
616 }
617
618 void wxTreeCtrl::SelectItem(const wxTreeItemId& item) {
619 if (!item.IsOk())
620 return;
621
622 gtk_tree_item_select((GtkTreeItem *)item);
623 }
624
625 void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item) {
626 #warning "Need to implement EnsureVisible"
627 }
628
629 void wxTreeCtrl::ScrollTo(const wxTreeItemId& item) {
630 #warning "Need to implement ScrollTo"
631 }
632
633 wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
634 wxClassInfo* textControlClass) {
635 wxASSERT( textControlClass->IsKindOf(CLASSINFO(wxTextCtrl)) );
636 #warning "Need to implement EditLabel"
637 /*
638 char *s;
639 m_editItem = item;
640
641 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)item), "w_label");
642 gtk_label_get(m_label, &s);
643
644 m_textCtrl = new wxTextCtrl(this, -1, s);
645 // m_textCtrl->SetValue(s);
646
647 gtk_object_set_data(GTK_OBJECT((GtkTreeItem *)item), "w_edit", m_textCtrl->m_widget);
648
649 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)item), GTK_WIDGET(m_label));
650 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)item), m_textCtrl->m_widget);
651
652 */
653 return m_textCtrl;
654 }
655
656 wxTextCtrl* wxTreeCtrl::GetEditControl() const {
657 return m_textCtrl;
658 }
659
660 void wxTreeCtrl::EndEditLabel(const wxTreeItemId& item, bool discardChanges) {
661 #warning "Need to implement EndEditLabel"
662 /*
663 GtkLabel *m_label = (GtkLabel *)gtk_object_get_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_label");
664 gtk_label_set(m_label, m_textCtrl->GetValue());
665
666 gtk_object_remove_data(GTK_OBJECT((GtkTreeItem *)m_editItem), "w_edit");
667
668 gtk_container_remove(GTK_CONTAINER((GtkTreeItem *)m_editItem), m_textCtrl->m_widget);
669 gtk_container_add(GTK_CONTAINER((GtkTreeItem *)m_editItem), GTK_WIDGET(m_label));
670
671 delete m_textCtrl;
672 m_textCtrl = NULL;
673 */
674 }
675
676 void wxTreeCtrl::ExpandItem(const wxTreeItemId& item, int action) {
677 switch (action) {
678 case wxTREE_EXPAND_EXPAND:
679 Expand(item);
680 break;
681
682 case wxTREE_EXPAND_COLLAPSE:
683 Collapse(item);
684 break;
685
686 case wxTREE_EXPAND_COLLAPSE_RESET:
687 CollapseAndReset(item);
688 break;
689
690 case wxTREE_EXPAND_TOGGLE:
691 Toggle(item);
692 break;
693
694 default:
695 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
696 }
697 }
698
699 wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
700 const wxString& text, int image, int selImage,
701 long insertAfter) {
702 // InsertItem(parent, insertAfter, text, image, selImage);
703 #warning "Need to implement InsertItem"
704 return NULL;
705 }
706
707 /* Old functions
708 long wxTreeCtrl::GetChild(long item) const {
709 GtkTreeItem *p;
710 GtkTreeItem *next = NULL;
711
712 p = findGtkTreeItem(item);
713 GList *list = gtk_container_children(GTK_CONTAINER(p));
714 next = GTK_TREE_ITEM(list->data);;
715
716 if (next != NULL)
717 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
718
719 return (-1);
720 }
721
722 long wxTreeCtrl::GetFirstVisibleItem(void) const {
723 GtkTreeItem *next = NULL;
724
725 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
726 next = GTK_TREE_ITEM(list->data);;
727 // gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
728
729 if (next != NULL)
730 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
731
732 return (-1);
733 }
734
735 long wxTreeCtrl::GetNextVisibleItem(long item) const {
736 GtkTreeItem *p;
737 GtkTreeItem *next = NULL;
738
739 p = findGtkTreeItem(item);
740 GList *list = gtk_container_children(GTK_CONTAINER(p));
741 next = GTK_TREE_ITEM(list->data);;
742 // gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
743
744 if (next != NULL)
745 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
746
747 return (-1);
748 }
749
750 bool wxTreeCtrl::GetItem(wxTreeItem& info) const {
751 GtkTreeItem *p;
752
753 p = findGtkTreeItem(info.m_itemId);
754
755 if (p == NULL) {
756 wxLogSysError("TreeCtrl::GetItem failed");
757 return FALSE;
758 }
759
760 wxConvertFromGtkTreeItem(info, p);
761
762 return TRUE;
763 }
764
765 bool wxTreeCtrl::SetItem(wxTreeItem& info) {
766 GtkTreeItem *p;
767
768 p = findGtkTreeItem(info.m_itemId);
769
770 if (p == NULL) {
771 wxLogSysError("TreeCtrl::SetItem failed");
772 return FALSE;
773 }
774
775 wxConvertToGtkTreeItem(this, info, &p);
776
777 return TRUE;
778 }
779
780 int wxTreeCtrl::GetItemState(long item, long stateMask) const {
781 wxTreeItem info;
782
783 info.m_mask = wxTREE_MASK_STATE ;
784 info.m_stateMask = stateMask;
785 info.m_itemId = item;
786
787 if (!GetItem(info))
788 return 0;
789
790 return info.m_state;
791 }
792
793 bool wxTreeCtrl::SetItemState(long item, long state, long stateMask) {
794 wxTreeItem info;
795
796 info.m_mask = wxTREE_MASK_STATE ;
797 info.m_state = state;
798 info.m_stateMask = stateMask;
799 info.m_itemId = item;
800
801 return SetItem(info);
802 }
803 */
804
805 // Operations
806 /*
807 bool wxTreeCtrl::DeleteChildren(long item) {
808 GtkTreeItem *p;
809
810 p = findGtkTreeItem(item);
811 if (p == NULL)
812 return FALSE;
813
814 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
815
816 return TRUE;
817 }
818 */
819
820 /*
821 long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter) {
822 GtkTreeItem *p;
823 GtkTreeItem *item = NULL;
824
825 info.m_itemId = m_curitemId;
826 m_curitemId++;
827
828 wxConvertToGtkTreeItem(this, info, &item);
829
830 if (parent != 0) {
831 p = findGtkTreeItem(parent);
832 if (p->subtree == NULL) {
833 GtkTree *tree = GTK_TREE(gtk_tree_new());
834 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
835 gtk_widget_show(GTK_WIDGET(tree));
836 p->expanded = 1;
837 }
838
839 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
840 } else {
841 m_anchor = item;
842 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
843 }
844
845 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
846 GtkTree *tree = GTK_TREE(gtk_tree_new());
847 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
848 gtk_widget_show(GTK_WIDGET(tree));
849 }
850
851 gtk_widget_show(GTK_WIDGET(item));
852
853 gtk_signal_connect(GTK_OBJECT(item), "select",
854 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
855
856 gtk_signal_connect(GTK_OBJECT(item), "deselect",
857 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
858
859 gtk_signal_connect(GTK_OBJECT(item), "expand",
860 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
861 gtk_signal_connect(GTK_OBJECT(item), "collapse",
862 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
863
864 return info.m_itemId;
865 }
866
867 long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
868 int selImage, long insertAfter) {
869
870 wxTreeItem info;
871 info.m_text = label;
872 info.m_mask = wxTREE_MASK_TEXT;
873 if (image > -1) {
874 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
875 info.m_image = image;
876 if (selImage == -1)
877 info.m_selectedImage = image;
878 else
879 info.m_selectedImage = selImage;
880 }
881
882 return InsertItem(parent, info, insertAfter);
883 }
884 */
885
886 void wxTreeCtrl::SendMessage(wxEventType command, const wxTreeItemId& item) {
887 wxTreeEvent event(command, GetId());
888 event.SetEventObject(this);
889 event.m_item = item;
890 ProcessEvent(event);
891 }
892
893 void wxTreeCtrl::SendExpanding(const wxTreeItemId& item) {
894 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDING, item);
895 }
896
897 void wxTreeCtrl::SendExpanded(const wxTreeItemId& item) {
898 SendMessage(wxEVT_COMMAND_TREE_ITEM_EXPANDED, item);
899 }
900
901 void wxTreeCtrl::SendCollapsing(const wxTreeItemId& item) {
902 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, item);
903 }
904
905 void wxTreeCtrl::SendCollapsed(const wxTreeItemId& item) {
906 SendMessage(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, item);
907 }
908
909 void wxTreeCtrl::SendSelChanging(const wxTreeItemId& item) {
910 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGED, item);
911 }
912
913 void wxTreeCtrl::SendSelChanged(const wxTreeItemId& item) {
914 SendMessage(wxEVT_COMMAND_TREE_SEL_CHANGING, item);
915 }
916
917 // Tree event
918 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
919
920 wxTreeEvent::wxTreeEvent(wxEventType commandType, int id):
921 wxCommandEvent(commandType, id) {
922 m_code = 0;
923 m_itemOld = 0;
924 }