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