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