]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/treectrl.cpp
Typo
[wxWidgets.git] / src / palmos / treectrl.cpp
CommitLineData
ffecfa5a
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/palmos/treectrl.cpp
3// Purpose: wxTreeCtrl
e2731512 4// Author: William Osborne - minimal working wxPalmOS port
ffecfa5a
JS
5// Modified by:
6// Created: 10/13/04
e2731512 7// RCS-ID: $Id$
ffecfa5a
JS
8// Copyright: (c) William Osborne
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
ffecfa5a
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#if wxUSE_TREECTRL
28
e4db172a
WS
29#include "wx/treectrl.h"
30
ad9835c9
WS
31#ifndef WX_PRECOMP
32 #include "wx/dynarray.h"
e4db172a 33 #include "wx/log.h"
670f9935 34 #include "wx/app.h"
9eddec69 35 #include "wx/settings.h"
ad9835c9
WS
36#endif
37
ffecfa5a
JS
38#include "wx/palmos/private.h"
39
ffecfa5a 40#include "wx/imaglist.h"
ffecfa5a 41
ffecfa5a
JS
42// macros to hide the cast ugliness
43// --------------------------------
44
45// ptr is the real item id, i.e. wxTreeItemId::m_pItem
46#define HITEM_PTR(ptr) (HTREEITEM)(ptr)
47
48// item here is a wxTreeItemId
49#define HITEM(item) HITEM_PTR((item).m_pItem)
50
51// the native control doesn't support multiple selections under MSW and we
52// have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
53// checkboxes be the selection status (checked == selected) or by really
54// emulating everything, i.e. intercepting mouse and key events &c. The first
55// approach is much easier but doesn't work with comctl32.dll < 4.71 and also
56// looks quite ugly.
57#define wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE 0
58
59// ----------------------------------------------------------------------------
60// private functions
61// ----------------------------------------------------------------------------
62
63// ----------------------------------------------------------------------------
64// private classes
65// ----------------------------------------------------------------------------
66
67// ----------------------------------------------------------------------------
68// wxWin macros
69// ----------------------------------------------------------------------------
70
71#if wxUSE_EXTENDED_RTTI
72WX_DEFINE_FLAGS( wxTreeCtrlStyle )
73
74wxBEGIN_FLAGS( wxTreeCtrlStyle )
75 // new style border flags, we put them first to
76 // use them for streaming out
77 wxFLAGS_MEMBER(wxBORDER_SIMPLE)
78 wxFLAGS_MEMBER(wxBORDER_SUNKEN)
79 wxFLAGS_MEMBER(wxBORDER_DOUBLE)
80 wxFLAGS_MEMBER(wxBORDER_RAISED)
81 wxFLAGS_MEMBER(wxBORDER_STATIC)
82 wxFLAGS_MEMBER(wxBORDER_NONE)
83
84 // old style border flags
85 wxFLAGS_MEMBER(wxSIMPLE_BORDER)
86 wxFLAGS_MEMBER(wxSUNKEN_BORDER)
87 wxFLAGS_MEMBER(wxDOUBLE_BORDER)
88 wxFLAGS_MEMBER(wxRAISED_BORDER)
89 wxFLAGS_MEMBER(wxSTATIC_BORDER)
90 wxFLAGS_MEMBER(wxBORDER)
91
92 // standard window styles
93 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
94 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
95 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
96 wxFLAGS_MEMBER(wxWANTS_CHARS)
97 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
98 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
99 wxFLAGS_MEMBER(wxVSCROLL)
100 wxFLAGS_MEMBER(wxHSCROLL)
101
102 wxFLAGS_MEMBER(wxTR_EDIT_LABELS)
103 wxFLAGS_MEMBER(wxTR_NO_BUTTONS)
104 wxFLAGS_MEMBER(wxTR_HAS_BUTTONS)
105 wxFLAGS_MEMBER(wxTR_TWIST_BUTTONS)
106 wxFLAGS_MEMBER(wxTR_NO_LINES)
107 wxFLAGS_MEMBER(wxTR_FULL_ROW_HIGHLIGHT)
108 wxFLAGS_MEMBER(wxTR_LINES_AT_ROOT)
109 wxFLAGS_MEMBER(wxTR_HIDE_ROOT)
110 wxFLAGS_MEMBER(wxTR_ROW_LINES)
111 wxFLAGS_MEMBER(wxTR_HAS_VARIABLE_ROW_HEIGHT)
112 wxFLAGS_MEMBER(wxTR_SINGLE)
113 wxFLAGS_MEMBER(wxTR_MULTIPLE)
114 wxFLAGS_MEMBER(wxTR_EXTENDED)
115 wxFLAGS_MEMBER(wxTR_DEFAULT_STYLE)
116
117wxEND_FLAGS( wxTreeCtrlStyle )
118
119IMPLEMENT_DYNAMIC_CLASS_XTI(wxTreeCtrl, wxControl,"wx/treectrl.h")
120
121wxBEGIN_PROPERTIES_TABLE(wxTreeCtrl)
122 wxEVENT_PROPERTY( TextUpdated , wxEVT_COMMAND_TEXT_UPDATED , wxCommandEvent )
123 wxEVENT_RANGE_PROPERTY( TreeEvent , wxEVT_COMMAND_TREE_BEGIN_DRAG , wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK , wxTreeEvent )
124 wxPROPERTY_FLAGS( WindowStyle , wxTreeCtrlStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
125wxEND_PROPERTIES_TABLE()
126
127wxBEGIN_HANDLERS_TABLE(wxTreeCtrl)
128wxEND_HANDLERS_TABLE()
129
130wxCONSTRUCTOR_5( wxTreeCtrl , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
131#else
132IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl, wxControl)
133#endif
134
135// ----------------------------------------------------------------------------
136// constants
137// ----------------------------------------------------------------------------
138
139// indices in gs_expandEvents table below
140enum
141{
142 IDX_COLLAPSE,
143 IDX_EXPAND,
144 IDX_WHAT_MAX
145};
146
147enum
148{
149 IDX_DONE,
150 IDX_DOING,
151 IDX_HOW_MAX
152};
153
154// handy table for sending events - it has to be initialized during run-time
155// now so can't be const any more
156static /* const */ wxEventType gs_expandEvents[IDX_WHAT_MAX][IDX_HOW_MAX];
157
158/*
159 but logically it's a const table with the following entries:
160=
161{
162 { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxEVT_COMMAND_TREE_ITEM_COLLAPSING },
163 { wxEVT_COMMAND_TREE_ITEM_EXPANDED, wxEVT_COMMAND_TREE_ITEM_EXPANDING }
164};
165*/
166
167// ============================================================================
168// implementation
169// ============================================================================
170
171// ----------------------------------------------------------------------------
172// construction and destruction
173// ----------------------------------------------------------------------------
174
175void wxTreeCtrl::Init()
176{
177}
178
179bool wxTreeCtrl::Create(wxWindow *parent,
180 wxWindowID id,
181 const wxPoint& pos,
182 const wxSize& size,
183 long style,
184 const wxValidator& validator,
185 const wxString& name)
186{
187 return false;
188}
189
190wxTreeCtrl::~wxTreeCtrl()
191{
192}
193
194// ----------------------------------------------------------------------------
195// accessors
196// ----------------------------------------------------------------------------
197
198/* static */ wxVisualAttributes
199wxTreeCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
200{
201 wxVisualAttributes attrs;
202
203 return attrs;
204}
205
206
207// simple wrappers which add error checking in debug mode
208
209bool wxTreeCtrl::DoGetItem(wxTreeViewItem* tvItem) const
210{
211 return false;
212}
213
214void wxTreeCtrl::DoSetItem(wxTreeViewItem* tvItem)
215{
216}
217
027d45e8 218unsigned int wxTreeCtrl::GetCount() const
ffecfa5a 219{
027d45e8 220 // TODO
ffecfa5a
JS
221 return 0;
222}
223
224unsigned int wxTreeCtrl::GetIndent() const
225{
226 return 0;
227}
228
229void wxTreeCtrl::SetIndent(unsigned int indent)
230{
231}
232
233wxImageList *wxTreeCtrl::GetImageList() const
234{
235 return m_imageListNormal;
236}
237
238wxImageList *wxTreeCtrl::GetStateImageList() const
239{
240 return m_imageListState;
241}
242
243void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
244{
245}
246
247void wxTreeCtrl::SetImageList(wxImageList *imageList)
248{
249}
250
251void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
252{
253}
254
255void wxTreeCtrl::AssignImageList(wxImageList *imageList)
256{
257}
258
259void wxTreeCtrl::AssignStateImageList(wxImageList *imageList)
260{
261}
262
263size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
264 bool recursively) const
265{
266 return 0;
267}
268
269// ----------------------------------------------------------------------------
270// control colours
271// ----------------------------------------------------------------------------
272
273bool wxTreeCtrl::SetBackgroundColour(const wxColour &colour)
274{
275 return false;
276}
277
278bool wxTreeCtrl::SetForegroundColour(const wxColour &colour)
279{
280 return false;
281}
282
283// ----------------------------------------------------------------------------
284// Item access
285// ----------------------------------------------------------------------------
286
287wxString wxTreeCtrl::GetItemText(const wxTreeItemId& item) const
288{
289 return wxString;
290}
291
292void wxTreeCtrl::SetItemText(const wxTreeItemId& item, const wxString& text)
293{
294}
295
296int wxTreeCtrl::DoGetItemImageFromData(const wxTreeItemId& item,
297 wxTreeItemIcon which) const
298{
299 return -1;
300}
301
302void wxTreeCtrl::DoSetItemImageFromData(const wxTreeItemId& item,
303 int image,
304 wxTreeItemIcon which) const
305{
306}
307
308void wxTreeCtrl::DoSetItemImages(const wxTreeItemId& item,
309 int image,
310 int imageSel)
311{
312}
313
314int wxTreeCtrl::GetItemImage(const wxTreeItemId& item,
315 wxTreeItemIcon which) const
316{
317 return -1;
318}
319
320void wxTreeCtrl::SetItemImage(const wxTreeItemId& item, int image,
321 wxTreeItemIcon which)
322{
323}
324
325wxTreeItemData *wxTreeCtrl::GetItemData(const wxTreeItemId& item) const
326{
327 return NULL;
328}
329
330void wxTreeCtrl::SetItemData(const wxTreeItemId& item, wxTreeItemData *data)
331{
332}
333
334void wxTreeCtrl::SetIndirectItemData(const wxTreeItemId& item,
335 wxTreeItemIndirectData *data)
336{
337}
338
339bool wxTreeCtrl::HasIndirectData(const wxTreeItemId& item) const
340{
341 return false;
342}
343
344void wxTreeCtrl::SetItemHasChildren(const wxTreeItemId& item, bool has)
345{
346}
347
348void wxTreeCtrl::SetItemBold(const wxTreeItemId& item, bool bold)
349{
350}
351
352void wxTreeCtrl::SetItemDropHighlight(const wxTreeItemId& item, bool highlight)
353{
354}
355
356void wxTreeCtrl::RefreshItem(const wxTreeItemId& item)
357{
358}
359
360wxColour wxTreeCtrl::GetItemTextColour(const wxTreeItemId& item) const
361{
362 return wxNullColour;
363}
364
365wxColour wxTreeCtrl::GetItemBackgroundColour(const wxTreeItemId& item) const
366{
367 return wxNullColour;
368}
369
370wxFont wxTreeCtrl::GetItemFont(const wxTreeItemId& item) const
371{
372 return wxNullFont;
373}
374
375void wxTreeCtrl::SetItemTextColour(const wxTreeItemId& item,
376 const wxColour& col)
377{
378}
379
380void wxTreeCtrl::SetItemBackgroundColour(const wxTreeItemId& item,
381 const wxColour& col)
382{
383}
384
385void wxTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font)
386{
387}
388
389// ----------------------------------------------------------------------------
390// Item status
391// ----------------------------------------------------------------------------
392
393bool wxTreeCtrl::IsVisible(const wxTreeItemId& item) const
394{
395 return false;
396}
397
398bool wxTreeCtrl::ItemHasChildren(const wxTreeItemId& item) const
399{
400 return false;
401}
402
403bool wxTreeCtrl::IsExpanded(const wxTreeItemId& item) const
404{
405 return false;
406}
407
408bool wxTreeCtrl::IsSelected(const wxTreeItemId& item) const
409{
410 return false;
411}
412
413bool wxTreeCtrl::IsBold(const wxTreeItemId& item) const
414{
415 return false;
416}
417
418// ----------------------------------------------------------------------------
419// navigation
420// ----------------------------------------------------------------------------
421
422wxTreeItemId wxTreeCtrl::GetRootItem() const
423{
424 // Root may be real (visible) or virtual (hidden).
425 if ( GET_VIRTUAL_ROOT() )
426 return TVI_ROOT;
427
428 return wxTreeItemId(TreeView_GetRoot(GetHwnd()));
429}
430
431wxTreeItemId wxTreeCtrl::GetSelection() const
432{
433 return 0;
434}
435
436wxTreeItemId wxTreeCtrl::GetItemParent(const wxTreeItemId& item) const
437{
438 return 0;
439}
440
441wxTreeItemId wxTreeCtrl::GetFirstChild(const wxTreeItemId& item,
442 wxTreeItemIdValue& cookie) const
443{
444 return 0;
445}
446
447wxTreeItemId wxTreeCtrl::GetNextChild(const wxTreeItemId& WXUNUSED(item),
448 wxTreeItemIdValue& cookie) const
449{
450 return 0;
451}
452
ffecfa5a
JS
453wxTreeItemId wxTreeCtrl::GetLastChild(const wxTreeItemId& item) const
454{
455 return 0;
456}
457
458wxTreeItemId wxTreeCtrl::GetNextSibling(const wxTreeItemId& item) const
459{
460 return 0;
461}
462
463wxTreeItemId wxTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
464{
465 return 0;
466}
467
468wxTreeItemId wxTreeCtrl::GetFirstVisibleItem() const
469{
470 return 0;
471}
472
473wxTreeItemId wxTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
474{
475 return 0;
476}
477
478wxTreeItemId wxTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
479{
480 return 0;
481}
482
483// ----------------------------------------------------------------------------
484// multiple selections emulation
485// ----------------------------------------------------------------------------
486
487bool wxTreeCtrl::IsItemChecked(const wxTreeItemId& item) const
488{
489 return false;
490}
491
492void wxTreeCtrl::SetItemCheck(const wxTreeItemId& item, bool check)
493{
494}
495
496size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds& selections) const
497{
498 return 0;
499}
500
501// ----------------------------------------------------------------------------
502// Usual operations
503// ----------------------------------------------------------------------------
504
505wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
506 wxTreeItemId hInsertAfter,
507 const wxString& text,
508 int image, int selectedImage,
509 wxTreeItemData *data)
510{
511 return 0;
512}
513
ffecfa5a
JS
514wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
515 int image, int selectedImage,
516 wxTreeItemData *data)
517{
518 return 0;
519}
520
521wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
522 const wxString& text,
523 int image, int selectedImage,
524 wxTreeItemData *data)
525{
526 return 0;
527}
528
529wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
530 const wxTreeItemId& idPrevious,
531 const wxString& text,
532 int image, int selectedImage,
533 wxTreeItemData *data)
534{
535 return 0;
536}
537
538wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
539 size_t index,
540 const wxString& text,
541 int image, int selectedImage,
542 wxTreeItemData *data)
543{
544 return 0;
545}
546
547wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
548 const wxString& text,
549 int image, int selectedImage,
550 wxTreeItemData *data)
551{
552 return 0;
553}
554
555void wxTreeCtrl::Delete(const wxTreeItemId& item)
556{
557 return 0;
558}
559
560// delete all children (but don't delete the item itself)
561void wxTreeCtrl::DeleteChildren(const wxTreeItemId& item)
562{
563}
564
565void wxTreeCtrl::DeleteAllItems()
566{
567}
568
569void wxTreeCtrl::DoExpand(const wxTreeItemId& item, int flag)
570{
571}
572
573void wxTreeCtrl::Expand(const wxTreeItemId& item)
574{
575}
576
577void wxTreeCtrl::Collapse(const wxTreeItemId& item)
578{
579}
580
581void wxTreeCtrl::CollapseAndReset(const wxTreeItemId& item)
582{
583}
584
585void wxTreeCtrl::Toggle(const wxTreeItemId& item)
586{
587}
588
ffecfa5a
JS
589void wxTreeCtrl::Unselect()
590{
591}
592
593void wxTreeCtrl::UnselectAll()
594{
595}
596
597void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
598{
599}
600
601void wxTreeCtrl::UnselectItem(const wxTreeItemId& item)
602{
603}
604
605void wxTreeCtrl::ToggleItemSelection(const wxTreeItemId& item)
606{
607}
608
609void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
610{
611}
612
613void wxTreeCtrl::ScrollTo(const wxTreeItemId& item)
614{
615}
616
617wxTextCtrl *wxTreeCtrl::GetEditControl() const
618{
619 return NULL;
620}
621
622void wxTreeCtrl::DeleteTextCtrl()
623{
624}
625
626wxTextCtrl* wxTreeCtrl::EditLabel(const wxTreeItemId& item,
627 wxClassInfo* textControlClass)
628{
629 return NULL;
630}
631
632// End label editing, optionally cancelling the edit
633void wxTreeCtrl::EndEditLabel(const wxTreeItemId& WXUNUSED(item), bool discardChanges)
634{
635}
636
637wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
638{
639 return 0;
640}
641
642bool wxTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
643 wxRect& rect,
644 bool textOnly) const
645{
646 return false;
647}
648
649// ----------------------------------------------------------------------------
650// sorting stuff
651// ----------------------------------------------------------------------------
652
653// this is just a tiny namespace which is friend to wxTreeCtrl and so can use
654// functions such as IsDataIndirect()
655class wxTreeSortHelper
656{
657public:
658 static int CALLBACK Compare(LPARAM data1, LPARAM data2, LPARAM tree);
659
660private:
661 static wxTreeItemId GetIdFromData(wxTreeCtrl *tree, LPARAM item)
662 {
663 wxTreeItemData *data = (wxTreeItemData *)item;
664 if ( tree->IsDataIndirect(data) )
665 {
666 data = ((wxTreeItemIndirectData *)data)->GetData();
667 }
668
669 return data->GetId();
670 }
671};
672
673int CALLBACK wxTreeSortHelper::Compare(LPARAM pItem1,
674 LPARAM pItem2,
675 LPARAM htree)
676{
677 wxCHECK_MSG( pItem1 && pItem2, 0,
678 wxT("sorting tree without data doesn't make sense") );
679
680 wxTreeCtrl *tree = (wxTreeCtrl *)htree;
681
682 return tree->OnCompareItems(GetIdFromData(tree, pItem1),
683 GetIdFromData(tree, pItem2));
684}
685
686int wxTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
687 const wxTreeItemId& item2)
688{
689 return wxStrcmp(GetItemText(item1), GetItemText(item2));
690}
691
692void wxTreeCtrl::SortChildren(const wxTreeItemId& item)
693{
694 wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
695
696 // rely on the fact that TreeView_SortChildren does the same thing as our
697 // default behaviour, i.e. sorts items alphabetically and so call it
698 // directly if we're not in derived class (much more efficient!)
699 if ( GetClassInfo() == CLASSINFO(wxTreeCtrl) )
700 {
701 TreeView_SortChildren(GetHwnd(), HITEM(item), 0);
702 }
703 else
704 {
705 TV_SORTCB tvSort;
706 tvSort.hParent = HITEM(item);
707 tvSort.lpfnCompare = wxTreeSortHelper::Compare;
708 tvSort.lParam = (LPARAM)this;
709 TreeView_SortChildrenCB(GetHwnd(), &tvSort, 0 /* reserved */);
710 }
711}
712
ffecfa5a
JS
713// ----------------------------------------------------------------------------
714// State control.
715// ----------------------------------------------------------------------------
716
717// why do they define INDEXTOSTATEIMAGEMASK but not the inverse?
718#define STATEIMAGEMASKTOINDEX(state) (((state) & TVIS_STATEIMAGEMASK) >> 12)
719
720void wxTreeCtrl::SetState(const wxTreeItemId& node, int state)
721{
722}
723
724int wxTreeCtrl::GetState(const wxTreeItemId& node)
725{
726 return 0;
727}
728
729#endif // wxUSE_TREECTRL