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