]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/treectrl.cpp
change the last changes back
[wxWidgets.git] / src / gtk / treectrl.cpp
... / ...
CommitLineData
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/log.h"
29
30#include <gtk/gtk.h>
31
32static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem);
33static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem);
34static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data);
35// static void gtk_treectrl_next_callback (GtkWidget *widget, gpointer data);
36// static void gtk_treectrl_next_visible_callback (GtkWidget *widget, gpointer data);
37// static void gtk_treectrl_next_selected_callback (GtkWidget *widget, gpointer data);
38
39static void gtk_treeitem_expand_callback(GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem);
40static void gtk_treeitem_collapse_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem);
41static void gtk_treeitem_select_callback( GtkWidget *WXUNUSED(widget), wxTreeItem *treeitem);
42
43static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItem *treeitem)
44{
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(id);
51 owner->SendExpanded(id);
52};
53
54static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItem *treeitem)
55{
56 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
57 if (owner == NULL)
58 return;
59
60 long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
61 owner->SendCollapsing(id);
62 owner->SendCollapsed(id);
63};
64
65static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItem *treeitem)
66{
67 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
68 if (owner == NULL)
69 return;
70
71 long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
72 owner->SendSelChanging(id);
73 owner->SendSelChanged(id);
74}
75
76#if !USE_SHARED_LIBRARY
77 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
78 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
79#endif
80
81wxTreeCtrl::wxTreeCtrl()
82{
83 m_imageListNormal = NULL;
84 m_imageListState = NULL;
85 m_textCtrl = NULL;
86 m_curitemId = 1;
87}
88
89bool wxTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
90 long style, const wxValidator& validator, const wxString& name)
91{
92 m_imageListNormal = NULL;
93 m_imageListState = NULL;
94 m_textCtrl = NULL;
95 m_curitemId = 1;
96
97 int x = pos.x;
98 int y = pos.y;
99 int width = size.x;
100 int height = size.y;
101
102 m_windowStyle = style;
103
104 SetParent(parent);
105
106 if (width <= 0)
107 width = 100;
108 if (height <= 0)
109 height = 30;
110 if (x < 0)
111 x = 0;
112 if (y < 0)
113 y = 0;
114
115 m_needParent = TRUE;
116
117 PreCreation( parent, id, pos, size, style, name );
118
119 m_widget = gtk_scrolled_window_new(NULL, NULL);
120 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(m_widget),
121 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
122
123 m_tree = GTK_TREE(gtk_tree_new());
124
125 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
126 gtk_widget_show(GTK_WIDGET(m_tree));
127
128 wxSystemSettings settings;
129 SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
130 SetForegroundColour(parent->GetDefaultForegroundColour());
131
132 SetName(name);
133 SetValidator(validator);
134
135 PostCreation();
136
137 gtk_widget_realize(GTK_WIDGET(m_tree));
138
139 Show(TRUE);
140
141 return TRUE;
142}
143
144wxTreeCtrl::~wxTreeCtrl()
145{
146 wxDELETE(m_textCtrl);
147}
148
149// Attributes
150static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data)
151{
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
159int wxTreeCtrl::GetCount() const
160{
161 int count = 0;
162
163 if (m_anchor != NULL)
164 gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_count_callback, &count);
165 return count;
166}
167
168int wxTreeCtrl::GetIndent() const
169{
170 return m_tree->indent_value;
171}
172
173void wxTreeCtrl::SetIndent(int indent)
174{
175 m_tree->indent_value = indent;
176}
177
178wxImageList *wxTreeCtrl::GetImageList(int which) const
179{
180 if (which == wxIMAGE_LIST_NORMAL) {
181 return m_imageListNormal;
182 }
183 else
184 if (which == wxIMAGE_LIST_STATE) {
185 return m_imageListState;
186 }
187 return NULL;
188}
189
190void wxTreeCtrl::SetImageList(wxImageList *imageList, int which)
191{
192 if (which == wxIMAGE_LIST_NORMAL)
193 m_imageListNormal = imageList;
194 else
195 if (which == wxIMAGE_LIST_STATE)
196 m_imageListState = imageList;
197}
198
199long wxTreeCtrl::GetNextItem(long item, int code) const
200{
201 switch (code) {
202 case wxTREE_NEXT_CARET:
203// flag = TVGN_CARET;
204 break;
205 case wxTREE_NEXT_CHILD:
206// flag = TVGN_CHILD;
207 break;
208 case wxTREE_NEXT_DROPHILITE:
209// flag = TVGN_DROPHILITE;
210 break;
211 case wxTREE_NEXT_FIRSTVISIBLE:
212// flag = TVGN_FIRSTVISIBLE;
213 break;
214 case wxTREE_NEXT_NEXT:
215// flag = TVGN_NEXT;
216 break;
217 case wxTREE_NEXT_NEXTVISIBLE:
218// flag = TVGN_NEXTVISIBLE;
219 break;
220 case wxTREE_NEXT_PARENT:
221// flag = TVGN_PARENT;
222 break;
223 case wxTREE_NEXT_PREVIOUS:
224// flag = TVGN_PREVIOUS;
225 break;
226 case wxTREE_NEXT_PREVIOUSVISIBLE:
227// flag = TVGN_PREVIOUSVISIBLE;
228 break;
229 case wxTREE_NEXT_ROOT:
230// flag = TVGN_ROOT;
231 break;
232
233 default :
234 break;
235 }
236// return (long) TreeView_GetNextItem( (HWND) GetHWND(), (HTREEITEM) item, flag);
237 return 0;
238}
239
240bool wxTreeCtrl::ItemHasChildren(long item) const
241{
242 GtkTreeItem *p;
243 int count = 0;
244
245 p = findGtkTreeItem(item);
246
247 gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_count_callback, &count);
248
249 return (count != 0);
250}
251
252static GtkTreeItem *findItem(GtkTreeItem *p, long id)
253{
254 GtkTreeItem *q;
255
256 if (((long)gtk_object_get_data(GTK_OBJECT(p), "id")) == id)
257 return p;
258
259 if (p->subtree == NULL)
260 return NULL;
261
262 GtkTree *tree = GTK_TREE(p->subtree);
263
264 GList *list = gtk_container_children(GTK_CONTAINER(tree));
265 guint len = g_list_length(list);
266
267 for (guint i=0; i<len;i++) {
268 GList *l = g_list_nth(list, i);
269 if (!GTK_IS_TREE_ITEM(l->data))
270 continue;
271 q = GTK_TREE_ITEM(l->data);
272 GtkTreeItem *ret = findItem(q, id);
273 if (ret != NULL)
274 return ret;
275 }
276
277 return NULL;
278}
279
280GtkTreeItem *wxTreeCtrl::findGtkTreeItem(long id) const
281{
282 return findItem(m_anchor, id);
283}
284
285long wxTreeCtrl::GetChild(long item) const
286{
287 GtkTreeItem *p;
288 GtkTreeItem *next = NULL;
289
290 p = findGtkTreeItem(item);
291 GList *list = gtk_container_children(GTK_CONTAINER(p));
292 next = GTK_TREE_ITEM(list->data);;
293
294 if (next != NULL)
295 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
296
297 return (-1);
298}
299
300long wxTreeCtrl::GetParent(long item) const
301{
302 GtkTreeItem *p;
303
304 p = findGtkTreeItem(item);
305 if (p != NULL)
306 return (long)gtk_object_get_data(GTK_OBJECT(p), "parent");
307
308 return (-1);
309}
310
311long wxTreeCtrl::GetFirstVisibleItem() const
312{
313 GtkTreeItem *next = NULL;
314
315 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
316 next = GTK_TREE_ITEM(list->data);;
317// gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_visible_callback, &next);
318
319 if (next != NULL)
320 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
321
322 return (-1);
323}
324
325long wxTreeCtrl::GetNextVisibleItem(long item) const
326{
327 GtkTreeItem *p;
328 GtkTreeItem *next = NULL;
329
330 p = findGtkTreeItem(item);
331 GList *list = gtk_container_children(GTK_CONTAINER(p));
332 next = GTK_TREE_ITEM(list->data);;
333// gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_next_visible_callback, &next);
334
335 if (next != NULL)
336 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
337
338 return (-1);
339}
340
341long wxTreeCtrl::GetSelection() const
342{
343 GtkTreeItem *next = NULL;
344
345 GList *list = gtk_container_children(GTK_CONTAINER(m_anchor));
346 next = GTK_TREE_ITEM(list->data);;
347// gtk_container_foreach(GTK_CONTAINER(m_anchor), gtk_treectrl_next_selected_callback, &next);
348
349 if (next != NULL)
350 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
351
352 return (-1);
353}
354
355long wxTreeCtrl::GetRootItem() const
356{
357 return (long)gtk_object_get_data(GTK_OBJECT(m_anchor), "id");
358}
359
360bool wxTreeCtrl::GetItem(wxTreeItem& info) const
361{
362 GtkTreeItem *p;
363
364 p = findGtkTreeItem(info.m_itemId);
365
366 if (p == NULL) {
367 wxLogError("TreeCtrl::GetItem failed.");
368 return FALSE;
369 }
370
371 wxConvertFromGtkTreeItem(info, p);
372
373 return TRUE;
374}
375
376bool wxTreeCtrl::SetItem(wxTreeItem& info)
377{
378 GtkTreeItem *p;
379
380 p = findGtkTreeItem(info.m_itemId);
381
382 if (p == NULL) {
383 wxLogError("TreeCtrl::SetItem failed.");
384 return FALSE;
385 }
386
387 wxConvertToGtkTreeItem(this, info, &p);
388
389 return TRUE;
390}
391
392int wxTreeCtrl::GetItemState(long item, long stateMask) const
393{
394 wxTreeItem info;
395
396 info.m_mask = wxTREE_MASK_STATE ;
397 info.m_stateMask = stateMask;
398 info.m_itemId = item;
399
400 if (!GetItem(info))
401 return 0;
402
403 return info.m_state;
404}
405
406bool wxTreeCtrl::SetItemState(long item, long state, long stateMask)
407{
408 wxTreeItem info;
409
410 info.m_mask = wxTREE_MASK_STATE ;
411 info.m_state = state;
412 info.m_stateMask = stateMask;
413 info.m_itemId = item;
414
415 return SetItem(info);
416}
417
418bool wxTreeCtrl::SetItemImage(long item, int image, int selImage)
419{
420 wxTreeItem info;
421
422 info.m_mask = wxTREE_MASK_IMAGE ;
423 info.m_image = image;
424 if (selImage > -1) {
425 info.m_selectedImage = selImage;
426 info.m_mask |= wxTREE_MASK_SELECTED_IMAGE;
427 }
428 info.m_itemId = item;
429
430 return SetItem(info);
431}
432
433wxString wxTreeCtrl::GetItemText(long item) const
434{
435 wxTreeItem info;
436
437 info.m_mask = wxTREE_MASK_TEXT ;
438 info.m_itemId = item;
439
440 if (!GetItem(info))
441 return wxString("");
442 return info.m_text;
443}
444
445void wxTreeCtrl::SetItemText(long item, const wxString& str)
446{
447 wxTreeItem info;
448
449 info.m_mask = wxTREE_MASK_TEXT ;
450 info.m_itemId = item;
451 info.m_text = str;
452
453 SetItem(info);
454}
455
456long wxTreeCtrl::GetItemData(long item) const
457{
458 wxTreeItem info;
459
460 info.m_mask = wxTREE_MASK_DATA ;
461 info.m_itemId = item;
462
463 if (!GetItem(info))
464 return 0;
465 return info.m_data;
466}
467
468bool wxTreeCtrl::SetItemData(long item, long data)
469{
470 wxTreeItem info;
471
472 info.m_mask = wxTREE_MASK_DATA ;
473 info.m_itemId = item;
474 info.m_data = data;
475
476 return SetItem(info);
477}
478
479bool wxTreeCtrl::GetItemRect(long item, wxRectangle& rect, bool textOnly) const
480{
481/*
482 RECT rect2;
483
484 *(HTREEITEM*)& rect2 = (HTREEITEM) item;
485 bool success = (::SendMessage((HWND) GetHWND(), TVM_GETITEMRECT, (WPARAM)textOnly,
486 (LPARAM)&rect2) != 0);
487
488 rect.x = rect2.left;
489 rect.y = rect2.top;
490 rect.width = rect2.right - rect2.left;
491 rect.height = rect2.bottom - rect2.left;
492 return success;
493*/
494 wxFAIL_MSG("Not implemented");
495
496 return FALSE;
497}
498
499wxTextCtrl* wxTreeCtrl::GetEditControl() const
500{
501 return m_textCtrl;
502}
503
504// Operations
505bool wxTreeCtrl::DeleteItem(long item)
506{
507 GtkTreeItem *p;
508
509 p = findGtkTreeItem(item);
510 if (p == NULL)
511 return FALSE;
512
513 GtkTreeItem *parent = GTK_TREE_ITEM(GTK_WIDGET(p)->parent);
514 if (parent == NULL)
515 return FALSE;
516
517 gtk_container_remove(GTK_CONTAINER(parent), GTK_WIDGET(p));
518
519 return TRUE;
520}
521
522bool wxTreeCtrl::DeleteChildren(long item)
523{
524 GtkTreeItem *p;
525
526 p = findGtkTreeItem(item);
527 if (p == NULL)
528 return FALSE;
529
530 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
531
532 return TRUE;
533}
534
535bool wxTreeCtrl::ExpandItem(long item, int action)
536{
537 GtkTreeItem *p;
538
539 p = findGtkTreeItem(item);
540
541 if (p == NULL)
542 return FALSE;
543
544 switch (action) {
545 case wxTREE_EXPAND_EXPAND:
546 gtk_tree_item_expand(GTK_TREE_ITEM(p));
547 break;
548
549 case wxTREE_EXPAND_COLLAPSE:
550 gtk_tree_item_collapse(GTK_TREE_ITEM(p));
551 break;
552
553 case wxTREE_EXPAND_COLLAPSE_RESET:
554 gtk_tree_item_collapse(GTK_TREE_ITEM(p));
555 gtk_tree_item_remove_subtree(GTK_TREE_ITEM(p));
556 break;
557
558 case wxTREE_EXPAND_TOGGLE:
559 if (p->expanded)
560 gtk_tree_item_collapse(GTK_TREE_ITEM(p));
561 else
562 gtk_tree_item_expand(GTK_TREE_ITEM(p));
563 break;
564
565 default:
566 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
567 }
568
569 return TRUE;
570}
571
572long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
573{
574 GtkTreeItem *p;
575 GtkTreeItem *item = NULL;
576
577 info.m_itemId = m_curitemId;
578 m_curitemId++;
579
580 wxConvertToGtkTreeItem(this, info, &item);
581
582 if (parent != 0) {
583 p = findGtkTreeItem(parent);
584 if (p->subtree == NULL) {
585 GtkTree *tree = GTK_TREE(gtk_tree_new());
586 gtk_tree_item_set_subtree(GTK_TREE_ITEM(p), GTK_WIDGET(tree));
587 gtk_widget_show(GTK_WIDGET(tree));
588 p->expanded = 1;
589 }
590
591 gtk_container_add(GTK_CONTAINER(p->subtree), GTK_WIDGET(item));
592 } else {
593 m_anchor = item;
594 gtk_container_add(GTK_CONTAINER(m_tree), GTK_WIDGET(item));
595 }
596
597 if ((info.m_mask & wxTREE_MASK_CHILDREN) != 0) {
598 GtkTree *tree = GTK_TREE(gtk_tree_new());
599 gtk_tree_item_set_subtree(GTK_TREE_ITEM(item), GTK_WIDGET(tree));
600 gtk_widget_show(GTK_WIDGET(tree));
601 }
602
603 gtk_widget_show(GTK_WIDGET(item));
604
605 gtk_signal_connect(GTK_OBJECT(item), "select",
606 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
607
608 gtk_signal_connect(GTK_OBJECT(item), "deselect",
609 GTK_SIGNAL_FUNC(gtk_treeitem_select_callback), (gpointer)this );
610
611 gtk_signal_connect(GTK_OBJECT(item), "expand",
612 GTK_SIGNAL_FUNC(gtk_treeitem_expand_callback), (gpointer)this );
613 gtk_signal_connect(GTK_OBJECT(item), "collapse",
614 GTK_SIGNAL_FUNC(gtk_treeitem_collapse_callback), (gpointer)this );
615
616 return info.m_itemId;
617}
618
619long wxTreeCtrl::InsertItem(long parent, const wxString& label, int image,
620 int selImage, long insertAfter) {
621
622 wxTreeItem info;
623 info.m_text = label;
624 info.m_mask = wxTREE_MASK_TEXT;
625 if (image > -1) {
626 info.m_mask |= wxTREE_MASK_IMAGE | wxTREE_MASK_SELECTED_IMAGE;
627 info.m_image = image;
628 if (selImage == -1)
629 info.m_selectedImage = image;
630 else
631 info.m_selectedImage = selImage;
632 }
633
634 return InsertItem(parent, info, insertAfter);
635}
636
637bool wxTreeCtrl::SelectItem(long item)
638{
639 GtkTreeItem *p;
640
641 p = findGtkTreeItem(item);
642 if (p == NULL)
643 return FALSE;
644
645 gtk_tree_item_select(p);
646 return TRUE;
647}
648
649bool wxTreeCtrl::ScrollTo(long item)
650{
651 wxFAIL_MSG("Not implemented");
652
653 return FALSE; // Still unimplemented
654}
655
656bool wxTreeCtrl::DeleteAllItems()
657{
658 gtk_tree_item_remove_subtree(m_anchor);
659 return TRUE;
660}
661
662wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
663{
664 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
665
666/*
667 HWND hWnd = (HWND) TreeView_EditLabel((HWND) GetHWND(), item);
668
669 if (m_textCtrl)
670 {
671 m_textCtrl->UnsubclassWin();
672 m_textCtrl->SetHWND(0);
673 delete m_textCtrl;
674 m_textCtrl = NULL;
675 }
676
677 m_textCtrl = (wxTextCtrl*) textControlClass->CreateObject();
678 m_textCtrl->SetHWND((WXHWND) hWnd);
679 m_textCtrl->SubclassWin((WXHWND) hWnd);
680
681*/
682 wxFAIL_MSG("Not implemented");
683
684 return m_textCtrl;
685}
686
687// End label editing, optionally cancelling the edit
688bool wxTreeCtrl::EndEditLabel(bool cancel)
689{
690/*
691 bool success = (TreeView_EndEditLabelNow((HWND) GetHWND(), cancel) != 0);
692
693 if (m_textCtrl)
694 {
695 m_textCtrl->UnsubclassWin();
696 m_textCtrl->SetHWND(0);
697 delete m_textCtrl;
698 m_textCtrl = NULL;
699 }
700 return success;
701*/
702 wxFAIL_MSG("Not implemented");
703
704 return FALSE;
705}
706
707long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
708{
709/*
710 TV_HITTESTINFO hitTestInfo;
711 hitTestInfo.pt.x = (int) point.x;
712 hitTestInfo.pt.y = (int) point.y;
713
714 TreeView_HitTest((HWND) GetHWND(), & hitTestInfo);
715
716 flags = 0;
717 if ( hitTestInfo.flags & TVHT_ABOVE )
718 flags |= wxTREE_HITTEST_ABOVE;
719 if ( hitTestInfo.flags & TVHT_BELOW )
720 flags |= wxTREE_HITTEST_BELOW;
721 if ( hitTestInfo.flags & TVHT_NOWHERE )
722 flags |= wxTREE_HITTEST_NOWHERE;
723 if ( hitTestInfo.flags & TVHT_ONITEMBUTTON )
724 flags |= wxTREE_HITTEST_ONITEMBUTTON;
725 if ( hitTestInfo.flags & TVHT_ONITEMICON )
726 flags |= wxTREE_HITTEST_ONITEMICON;
727 if ( hitTestInfo.flags & TVHT_ONITEMINDENT )
728 flags |= wxTREE_HITTEST_ONITEMINDENT;
729 if ( hitTestInfo.flags & TVHT_ONITEMLABEL )
730 flags |= wxTREE_HITTEST_ONITEMLABEL;
731 if ( hitTestInfo.flags & TVHT_ONITEMRIGHT )
732 flags |= wxTREE_HITTEST_ONITEMRIGHT;
733 if ( hitTestInfo.flags & TVHT_ONITEMSTATEICON )
734 flags |= wxTREE_HITTEST_ONITEMSTATEICON;
735 if ( hitTestInfo.flags & TVHT_TOLEFT )
736 flags |= wxTREE_HITTEST_TOLEFT;
737 if ( hitTestInfo.flags & TVHT_TORIGHT )
738 flags |= wxTREE_HITTEST_TORIGHT;
739
740 return (long) hitTestInfo.hItem ;
741*/
742 wxFAIL_MSG("Not implemented");
743
744 return 0;
745}
746
747/*
748wxImageList *wxTreeCtrl::CreateDragImage(long item)
749{
750}
751*/
752
753bool wxTreeCtrl::SortChildren(long item)
754{
755 wxFAIL_MSG("Not implemented");
756
757 return FALSE; // Still unimplemented
758}
759
760bool wxTreeCtrl::EnsureVisible(long item)
761{
762 wxFAIL_MSG("Not implemented");
763
764 return FALSE; // Still unimplemented
765}
766
767void wxTreeCtrl::SendExpanding(long item)
768{
769 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId());
770 event.SetEventObject(this);
771 ProcessEvent(event);
772}
773
774void wxTreeCtrl::SendExpanded(long item)
775{
776 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, GetId());
777 event.SetEventObject(this);
778 ProcessEvent(event);
779}
780
781void wxTreeCtrl::SendCollapsing(long item)
782{
783 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId());
784 event.SetEventObject(this);
785 ProcessEvent(event);
786}
787
788void wxTreeCtrl::SendCollapsed(long item)
789{
790 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, GetId());
791 event.SetEventObject(this);
792 ProcessEvent(event);
793}
794
795void wxTreeCtrl::SendSelChanging(long item)
796{
797 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, GetId());
798 event.SetEventObject(this);
799 ProcessEvent(event);
800}
801
802void wxTreeCtrl::SendSelChanged(long item)
803{
804 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, GetId());
805 event.SetEventObject(this);
806 ProcessEvent(event);
807}
808
809// Tree item structure
810wxTreeItem::wxTreeItem()
811{
812 m_mask = 0;
813 m_itemId = 0;
814 m_state = 0;
815 m_stateMask = 0;
816 m_image = -1;
817 m_selectedImage = -1;
818 m_children = 0;
819 m_data = 0;
820}
821
822// If getFullInfo is TRUE, we explicitly query for more info if we haven't got it all.
823
824static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem)
825{
826 GtkLabel *l;
827 char *t;
828
829 info.m_data = (long)gtk_object_get_data(GTK_OBJECT(gtkItem), "data");
830 info.m_itemId = (long)gtk_object_get_data(GTK_OBJECT(gtkItem), "id");
831 info.m_image = (int)gtk_object_get_data(GTK_OBJECT(gtkItem), "image");
832 info.m_selectedImage = (int)gtk_object_get_data(GTK_OBJECT(gtkItem), "selectedImage");
833
834 info.m_mask = 0;
835 info.m_state = 0;
836 info.m_stateMask = 0;
837 l = GTK_LABEL(gtk_object_get_data(GTK_OBJECT(gtkItem), "label"));
838 gtk_label_get(l, &t);
839 info.m_text = t;
840}
841
842static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem)
843{
844 GtkTreeItem *item = (*gtkItem);
845
846 if (item == NULL) {
847 item = GTK_TREE_ITEM(gtk_tree_item_new());
848
849 GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
850 gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
851
852 gtk_object_set_data(GTK_OBJECT(item), "box", m_box);
853
854 const wxBitmap *bmp;
855 const wxImageList *list;
856 if (owner != NULL)
857 if ((list = owner->GetImageList(wxIMAGE_LIST_NORMAL)) != NULL)
858 if ((bmp = list->GetBitmap(info.m_image)) != NULL)
859 if (bmp->Ok()) {
860 GdkBitmap *mask = NULL;
861 if (bmp->GetMask())
862 mask = bmp->GetMask()->GetBitmap();
863 GtkPixmap *m_image_widget = GTK_PIXMAP(gtk_pixmap_new(bmp->GetPixmap(), mask));
864 gtk_misc_set_alignment (GTK_MISC (m_image_widget), 0.0, 0.5);
865 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_image_widget), FALSE, FALSE, 0);
866 gtk_object_set_data(GTK_OBJECT(item), "image", m_image_widget);
867 gtk_widget_show (GTK_WIDGET(m_image_widget));
868 }
869
870 GtkLabel *m_label_widget = GTK_LABEL(gtk_label_new ((char *)(const char *)info.m_text));
871 gtk_misc_set_alignment (GTK_MISC (m_label_widget), 0.5, 0.5);
872
873 gtk_box_pack_start(GTK_BOX(m_box), GTK_WIDGET(m_label_widget), FALSE, FALSE, 0);
874 gtk_object_set_data(GTK_OBJECT(item), "label", m_label_widget);
875
876 gtk_widget_show (GTK_WIDGET(m_label_widget));
877
878 gtk_widget_show(GTK_WIDGET(m_box));
879 gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer)info.m_itemId);
880 gtk_object_set_data(GTK_OBJECT(item), "owner", owner);
881 (*gtkItem) = item;
882 }
883}
884
885// Tree event
886IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
887
888wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
889 : wxCommandEvent(commandType, id)
890{
891 m_code = 0;
892 m_oldItem = 0;
893}
894