]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/treectrl.cpp
SetBackground for ListBox and others
[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
c89a6106 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"
f4e325b3
DP
28#include "wx/log.h"
29
d9692df7 30#include <gtk/gtk.h>
f4e325b3 31
d9692df7
DP
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);
f4e325b3 38
d9692df7
DP
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);
f4e325b3 42
c89a6106
VZ
43static void gtk_treeitem_expand_callback(GtkWidget *widget, wxTreeItem *treeitem)
44{
d9692df7
DP
45 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
46 if (owner == NULL)
befe54c6 47 return;
d9692df7
DP
48
49 long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
50 owner->SendExpanding(id);
51 owner->SendExpanded(id);
f4e325b3
DP
52};
53
c89a6106
VZ
54static void gtk_treeitem_collapse_callback(GtkWidget *widget, wxTreeItem *treeitem)
55{
d9692df7
DP
56 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
57 if (owner == NULL)
befe54c6 58 return;
d9692df7
DP
59
60 long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
61 owner->SendCollapsing(id);
62 owner->SendCollapsed(id);
f4e325b3
DP
63};
64
c89a6106
VZ
65static void gtk_treeitem_select_callback(GtkWidget *widget, wxTreeItem *treeitem)
66{
d9692df7
DP
67 wxTreeCtrl *owner = (wxTreeCtrl *)gtk_object_get_data(GTK_OBJECT(widget), "owner");
68 if (owner == NULL)
69 return;
f4e325b3 70
d9692df7
DP
71 long id = (long)gtk_object_get_data(GTK_OBJECT(widget), "id");
72 owner->SendSelChanging(id);
73 owner->SendSelChanged(id);
f4e325b3
DP
74}
75
d9692df7 76#if !USE_SHARED_LIBRARY
c89a6106
VZ
77 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
78 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem, wxObject)
d9692df7 79#endif
f4e325b3 80
c89a6106
VZ
81wxTreeCtrl::wxTreeCtrl()
82{
d9692df7
DP
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),
c89a6106 121 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
f4e325b3
DP
122
123 m_tree = GTK_TREE(gtk_tree_new());
d9692df7
DP
124
125 gtk_container_add(GTK_CONTAINER(m_widget), GTK_WIDGET(m_tree));
f4e325b3 126 gtk_widget_show(GTK_WIDGET(m_tree));
befe54c6 127
d9692df7
DP
128 wxSystemSettings settings;
129 SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
fd71308f 130 SetForegroundColour(parent->GetForegroundColour());
d9692df7
DP
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
c89a6106
VZ
144wxTreeCtrl::~wxTreeCtrl()
145{
146 wxDELETE(m_textCtrl);
f4e325b3
DP
147}
148
d9692df7 149// Attributes
c89a6106
VZ
150static void gtk_treectrl_count_callback (GtkWidget *widget, gpointer data)
151{
d9692df7 152 int count = (*((int *)data));
f4e325b3 153
d9692df7
DP
154 count++;
155 if (GTK_IS_CONTAINER(widget))
156 gtk_container_foreach(GTK_CONTAINER(widget), gtk_treectrl_count_callback, data);
f4e325b3
DP
157}
158
c89a6106
VZ
159int wxTreeCtrl::GetCount() const
160{
d9692df7
DP
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;
f4e325b3
DP
166}
167
c89a6106
VZ
168int wxTreeCtrl::GetIndent() const
169{
d9692df7
DP
170 return m_tree->indent_value;
171}
befe54c6 172
c89a6106
VZ
173void wxTreeCtrl::SetIndent(int indent)
174{
d9692df7
DP
175 m_tree->indent_value = indent;
176}
177
c89a6106
VZ
178wxImageList *wxTreeCtrl::GetImageList(int which) const
179{
d9692df7
DP
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
c89a6106
VZ
190void wxTreeCtrl::SetImageList(wxImageList *imageList, int which)
191{
d9692df7
DP
192 if (which == wxIMAGE_LIST_NORMAL)
193 m_imageListNormal = imageList;
194 else
195 if (which == wxIMAGE_LIST_STATE)
196 m_imageListState = imageList;
197}
198
c89a6106
VZ
199long wxTreeCtrl::GetNextItem(long item, int code) const
200{
d9692df7
DP
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
c89a6106
VZ
240bool wxTreeCtrl::ItemHasChildren(long item) const
241{
d9692df7
DP
242 GtkTreeItem *p;
243 int count = 0;
244
245 p = findGtkTreeItem(item);
f4e325b3 246
d9692df7 247 gtk_container_foreach(GTK_CONTAINER(p), gtk_treectrl_count_callback, &count);
f4e325b3 248
d9692df7 249 return (count != 0);
f4e325b3
DP
250}
251
c89a6106
VZ
252static GtkTreeItem *findItem(GtkTreeItem *p, long id)
253{
d9692df7 254 GtkTreeItem *q;
f4e325b3 255
d9692df7
DP
256 if (((long)gtk_object_get_data(GTK_OBJECT(p), "id")) == id)
257 return p;
f4e325b3 258
d9692df7
DP
259 if (p->subtree == NULL)
260 return NULL;
f4e325b3 261
d9692df7 262 GtkTree *tree = GTK_TREE(p->subtree);
f4e325b3 263
d9692df7
DP
264 GList *list = gtk_container_children(GTK_CONTAINER(tree));
265 guint len = g_list_length(list);
f4e325b3 266
d9692df7
DP
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 }
f4e325b3 276
d9692df7
DP
277 return NULL;
278}
f4e325b3 279
c89a6106
VZ
280GtkTreeItem *wxTreeCtrl::findGtkTreeItem(long id) const
281{
d9692df7
DP
282 return findItem(m_anchor, id);
283}
f4e325b3 284
c89a6106
VZ
285long wxTreeCtrl::GetChild(long item) const
286{
d9692df7
DP
287 GtkTreeItem *p;
288 GtkTreeItem *next = NULL;
f4e325b3 289
d9692df7
DP
290 p = findGtkTreeItem(item);
291 GList *list = gtk_container_children(GTK_CONTAINER(p));
292 next = GTK_TREE_ITEM(list->data);;
f4e325b3 293
d9692df7
DP
294 if (next != NULL)
295 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
296
297 return (-1);
298}
f4e325b3 299
c89a6106
VZ
300long wxTreeCtrl::GetParent(long item) const
301{
d9692df7 302 GtkTreeItem *p;
f4e325b3 303
d9692df7
DP
304 p = findGtkTreeItem(item);
305 if (p != NULL)
306 return (long)gtk_object_get_data(GTK_OBJECT(p), "parent");
f4e325b3 307
d9692df7
DP
308 return (-1);
309}
f4e325b3 310
c89a6106
VZ
311long wxTreeCtrl::GetFirstVisibleItem() const
312{
d9692df7 313 GtkTreeItem *next = NULL;
f4e325b3 314
d9692df7
DP
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");
f4e325b3 321
d9692df7
DP
322 return (-1);
323}
324
c89a6106
VZ
325long wxTreeCtrl::GetNextVisibleItem(long item) const
326{
d9692df7
DP
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");
f4e325b3 337
d9692df7
DP
338 return (-1);
339}
f4e325b3 340
c89a6106
VZ
341long wxTreeCtrl::GetSelection() const
342{
d9692df7 343 GtkTreeItem *next = NULL;
f4e325b3 344
d9692df7
DP
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);
f4e325b3 348
d9692df7
DP
349 if (next != NULL)
350 return (long)gtk_object_get_data(GTK_OBJECT(next), "id");
f4e325b3 351
d9692df7
DP
352 return (-1);
353}
354
c89a6106
VZ
355long wxTreeCtrl::GetRootItem() const
356{
d9692df7
DP
357 return (long)gtk_object_get_data(GTK_OBJECT(m_anchor), "id");
358}
359
c89a6106
VZ
360bool wxTreeCtrl::GetItem(wxTreeItem& info) const
361{
d9692df7
DP
362 GtkTreeItem *p;
363
364 p = findGtkTreeItem(info.m_itemId);
365
366 if (p == NULL) {
c89a6106 367 wxLogError("TreeCtrl::GetItem failed.");
d9692df7
DP
368 return FALSE;
369 }
370
371 wxConvertFromGtkTreeItem(info, p);
f4e325b3
DP
372
373 return TRUE;
d9692df7 374}
f4e325b3 375
c89a6106
VZ
376bool wxTreeCtrl::SetItem(wxTreeItem& info)
377{
d9692df7 378 GtkTreeItem *p;
f4e325b3 379
d9692df7
DP
380 p = findGtkTreeItem(info.m_itemId);
381
382 if (p == NULL) {
c89a6106 383 wxLogError("TreeCtrl::SetItem failed.");
d9692df7
DP
384 return FALSE;
385 }
f4e325b3 386
d9692df7 387 wxConvertToGtkTreeItem(this, info, &p);
f4e325b3 388
d9692df7
DP
389 return TRUE;
390}
391
c89a6106
VZ
392int wxTreeCtrl::GetItemState(long item, long stateMask) const
393{
d9692df7
DP
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
c89a6106
VZ
406bool wxTreeCtrl::SetItemState(long item, long state, long stateMask)
407{
d9692df7
DP
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
c89a6106
VZ
418bool wxTreeCtrl::SetItemImage(long item, int image, int selImage)
419{
d9692df7
DP
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;
f4e325b3 427 }
d9692df7
DP
428 info.m_itemId = item;
429
430 return SetItem(info);
431}
432
c89a6106
VZ
433wxString wxTreeCtrl::GetItemText(long item) const
434{
d9692df7
DP
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
c89a6106
VZ
445void wxTreeCtrl::SetItemText(long item, const wxString& str)
446{
d9692df7
DP
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
c89a6106
VZ
456long wxTreeCtrl::GetItemData(long item) const
457{
d9692df7
DP
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
c89a6106
VZ
468bool wxTreeCtrl::SetItemData(long item, long data)
469{
d9692df7 470 wxTreeItem info;
f4e325b3 471
d9692df7
DP
472 info.m_mask = wxTREE_MASK_DATA ;
473 info.m_itemId = item;
474 info.m_data = data;
475
476 return SetItem(info);
477}
478
c89a6106
VZ
479bool wxTreeCtrl::GetItemRect(long item, wxRectangle& rect, bool textOnly) const
480{
befe54c6 481/*
d9692df7 482 RECT rect2;
befe54c6 483
d9692df7
DP
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;
f4e325b3 493*/
c89a6106
VZ
494 wxFAIL_MSG("Not implemented");
495
d9692df7
DP
496 return FALSE;
497}
f4e325b3 498
c89a6106
VZ
499wxTextCtrl* wxTreeCtrl::GetEditControl() const
500{
501 return m_textCtrl;
d9692df7 502}
f4e325b3 503
d9692df7 504// Operations
c89a6106
VZ
505bool wxTreeCtrl::DeleteItem(long item)
506{
d9692df7 507 GtkTreeItem *p;
f4e325b3 508
d9692df7
DP
509 p = findGtkTreeItem(item);
510 if (p == NULL)
511 return FALSE;
f4e325b3 512
d9692df7
DP
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
c89a6106
VZ
522bool wxTreeCtrl::DeleteChildren(long item)
523{
d9692df7
DP
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
c89a6106
VZ
535bool wxTreeCtrl::ExpandItem(long item, int action)
536{
d9692df7
DP
537 GtkTreeItem *p;
538
539 p = findGtkTreeItem(item);
540
541 if (p == NULL)
f4e325b3
DP
542 return FALSE;
543
544 switch (action) {
545 case wxTREE_EXPAND_EXPAND:
d9692df7 546 gtk_tree_item_expand(GTK_TREE_ITEM(p));
f4e325b3
DP
547 break;
548
f4e325b3 549 case wxTREE_EXPAND_COLLAPSE:
d9692df7
DP
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));
f4e325b3
DP
556 break;
557
558 case wxTREE_EXPAND_TOGGLE:
d9692df7
DP
559 if (p->expanded)
560 gtk_tree_item_collapse(GTK_TREE_ITEM(p));
f4e325b3 561 else
d9692df7 562 gtk_tree_item_expand(GTK_TREE_ITEM(p));
f4e325b3 563 break;
d9692df7
DP
564
565 default:
566 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
f4e325b3
DP
567 }
568
569 return TRUE;
d9692df7 570}
f4e325b3 571
c89a6106
VZ
572long wxTreeCtrl::InsertItem(long parent, wxTreeItem& info, long insertAfter)
573{
d9692df7
DP
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 }
f4e325b3 590
d9692df7
DP
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;
f4e325b3
DP
617}
618
d9692df7
DP
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 }
f4e325b3 633
d9692df7 634 return InsertItem(parent, info, insertAfter);
f4e325b3
DP
635}
636
c89a6106
VZ
637bool wxTreeCtrl::SelectItem(long item)
638{
d9692df7 639 GtkTreeItem *p;
f4e325b3 640
d9692df7
DP
641 p = findGtkTreeItem(item);
642 if (p == NULL)
643 return FALSE;
f4e325b3 644
d9692df7
DP
645 gtk_tree_item_select(p);
646 return TRUE;
647}
f4e325b3 648
c89a6106
VZ
649bool wxTreeCtrl::ScrollTo(long item)
650{
651 wxFAIL_MSG("Not implemented");
652
d9692df7
DP
653 return FALSE; // Still unimplemented
654}
f4e325b3 655
c89a6106
VZ
656bool wxTreeCtrl::DeleteAllItems()
657{
d9692df7
DP
658 gtk_tree_item_remove_subtree(m_anchor);
659 return TRUE;
f4e325b3
DP
660}
661
c89a6106
VZ
662wxTextCtrl* wxTreeCtrl::EditLabel(long item, wxClassInfo* textControlClass)
663{
d9692df7
DP
664 wxASSERT( (textControlClass->IsKindOf(CLASSINFO(wxTextCtrl))) );
665
f4e325b3 666/*
d9692df7 667 HWND hWnd = (HWND) TreeView_EditLabel((HWND) GetHWND(), item);
f4e325b3 668
d9692df7
DP
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);
f4e325b3 680
c89a6106
VZ
681*/
682 wxFAIL_MSG("Not implemented");
683
d9692df7
DP
684 return m_textCtrl;
685}
686
687// End label editing, optionally cancelling the edit
c89a6106
VZ
688bool wxTreeCtrl::EndEditLabel(bool cancel)
689{
f4e325b3 690/*
d9692df7 691 bool success = (TreeView_EndEditLabelNow((HWND) GetHWND(), cancel) != 0);
f4e325b3 692
d9692df7
DP
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*/
c89a6106
VZ
702 wxFAIL_MSG("Not implemented");
703
d9692df7
DP
704 return FALSE;
705}
f4e325b3 706
c89a6106
VZ
707long wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
708{
d9692df7
DP
709/*
710 TV_HITTESTINFO hitTestInfo;
711 hitTestInfo.pt.x = (int) point.x;
712 hitTestInfo.pt.y = (int) point.y;
f4e325b3 713
d9692df7 714 TreeView_HitTest((HWND) GetHWND(), & hitTestInfo);
f4e325b3 715
d9692df7
DP
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*/
c89a6106
VZ
742 wxFAIL_MSG("Not implemented");
743
d9692df7
DP
744 return 0;
745}
f4e325b3 746
d9692df7
DP
747/*
748wxImageList *wxTreeCtrl::CreateDragImage(long item)
f4e325b3 749{
f4e325b3
DP
750}
751*/
752
c89a6106
VZ
753bool wxTreeCtrl::SortChildren(long item)
754{
755 wxFAIL_MSG("Not implemented");
756
d9692df7
DP
757 return FALSE; // Still unimplemented
758}
f4e325b3 759
c89a6106
VZ
760bool wxTreeCtrl::EnsureVisible(long item)
761{
762 wxFAIL_MSG("Not implemented");
763
d9692df7
DP
764 return FALSE; // Still unimplemented
765}
f4e325b3 766
c89a6106
VZ
767void wxTreeCtrl::SendExpanding(long item)
768{
d9692df7
DP
769 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId());
770 event.SetEventObject(this);
771 ProcessEvent(event);
772}
f4e325b3 773
c89a6106
VZ
774void wxTreeCtrl::SendExpanded(long item)
775{
d9692df7
DP
776 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDED, GetId());
777 event.SetEventObject(this);
778 ProcessEvent(event);
779}
f4e325b3 780
c89a6106
VZ
781void wxTreeCtrl::SendCollapsing(long item)
782{
d9692df7
DP
783 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId());
784 event.SetEventObject(this);
785 ProcessEvent(event);
786}
f4e325b3 787
c89a6106
VZ
788void wxTreeCtrl::SendCollapsed(long item)
789{
d9692df7
DP
790 wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSED, GetId());
791 event.SetEventObject(this);
792 ProcessEvent(event);
793}
f4e325b3 794
c89a6106
VZ
795void wxTreeCtrl::SendSelChanging(long item)
796{
d9692df7
DP
797 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGED, GetId());
798 event.SetEventObject(this);
799 ProcessEvent(event);
f4e325b3
DP
800}
801
c89a6106
VZ
802void wxTreeCtrl::SendSelChanged(long item)
803{
d9692df7
DP
804 wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, GetId());
805 event.SetEventObject(this);
806 ProcessEvent(event);
807}
f4e325b3 808
d9692df7 809// Tree item structure
c89a6106
VZ
810wxTreeItem::wxTreeItem()
811{
d9692df7
DP
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}
f4e325b3 821
d9692df7 822// If getFullInfo is TRUE, we explicitly query for more info if we haven't got it all.
f4e325b3 823
c89a6106
VZ
824static void wxConvertFromGtkTreeItem(wxTreeItem& info, GtkTreeItem *gtkItem)
825{
d9692df7
DP
826 GtkLabel *l;
827 char *t;
f4e325b3 828
d9692df7
DP
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");
f4e325b3 833
d9692df7
DP
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}
f4e325b3 841
c89a6106
VZ
842static void wxConvertToGtkTreeItem(wxTreeCtrl *owner, wxTreeItem& info, GtkTreeItem **gtkItem)
843{
d9692df7 844 GtkTreeItem *item = (*gtkItem);
f4e325b3 845
d9692df7
DP
846 if (item == NULL) {
847 item = GTK_TREE_ITEM(gtk_tree_item_new());
f4e325b3 848
d9692df7
DP
849 GtkHBox *m_box = GTK_HBOX(gtk_hbox_new(FALSE, 0));
850 gtk_container_add (GTK_CONTAINER (item), GTK_WIDGET(m_box));
f4e325b3 851
d9692df7 852 gtk_object_set_data(GTK_OBJECT(item), "box", m_box);
f4e325b3 853
d9692df7
DP
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 }
f4e325b3 869
d9692df7
DP
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);
f4e325b3 872
d9692df7
DP
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);
f4e325b3 875
d9692df7 876 gtk_widget_show (GTK_WIDGET(m_label_widget));
f4e325b3 877
d9692df7
DP
878 gtk_widget_show(GTK_WIDGET(m_box));
879 gtk_object_set_data(GTK_OBJECT(item), "id", (gpointer)info.m_itemId);
d9692df7
DP
880 gtk_object_set_data(GTK_OBJECT(item), "owner", owner);
881 (*gtkItem) = item;
f4e325b3 882 }
d9692df7
DP
883}
884
885// Tree event
886IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent, wxCommandEvent)
887
c89a6106
VZ
888wxTreeEvent::wxTreeEvent(wxEventType commandType, int id)
889 : wxCommandEvent(commandType, id)
890{
d9692df7
DP
891 m_code = 0;
892 m_oldItem = 0;
893}
f4e325b3 894