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