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