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