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