00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __WXTREEMULTICTRL_H__
00013 #define __WXTREEMULTICTRL_H__
00014
00067 #ifdef __GNUG__
00068 #pragma interface "wxTreeMultiCtrl.cpp"
00069 #endif
00070
00071 #ifndef WX_PRECOMP
00072 #include "wx/wx.h"
00073 #endif
00074
00075 #include <wx/dynarray.h>
00076
00077
00078
00079 #include "TreeMultiItemRoot.h"
00080
00081
00082 #define wxTMC_DEFAULT_STYLE wxSIMPLE_BORDER
00083
00091 #define wxTMC_BG_ADJUST_CNT 0x000000001
00092
00094 #define wxTMC_BG_ADJUST_BTN 0x000000002
00095
00097 #define wxTMC_BG_ADJUST_ALL (wxTMC_BG_ADJUST_CNT | wxTMC_BG_ADJUST_BTN)
00098
00100 #define wxTMC_SPAN_WIDTH 0x000000004
00101
00105 #define wxTreeMultiCtrlNameStr wxT("wxTreeMultiCtrl")
00106
00107 #define WXTMC_GUTTER_DEFAULT 6 // gutter before and after image of [+] or [-]
00108 #define WXTMC_YSPACING_DEFAULT 10 // per item 10 pixels spacing extra for every item
00109 #define WXTMC_PIXELS_PER_UNIT 10
00110
00115 enum
00116 {
00118 wxTMC_HITTEST_GUTTER = 1,
00120 wxTMC_HITTEST_WINDOW,
00122 wxTMC_HITTEST_CAPTION,
00124 wxTMC_HITTEST_CHECKBOX
00125 };
00126
00172 class wxTreeMultiItem
00173 {
00174 private:
00175 TreeMultiItemBase *_item;
00176 public:
00179 wxTreeMultiItem() {
00180 _item = 0;
00181 };
00182
00183 #ifndef _NO_DOXYGEN_
00184
00185 wxTreeMultiItem(TreeMultiItemBase *ptr) {
00186 _item = ptr;
00187 };
00188
00189
00190
00191 TreeMultiItemBase *GetItem() const {
00192 return _item;
00193 };
00194
00195 #endif // _NO_DOXYGEN_
00196
00200 void operator=(const wxTreeMultiItem &item) {
00201 _item = item._item;
00202 };
00203
00205 bool operator==(wxTreeMultiItem const& item) const {return (this->GetItem() == item.GetItem());}
00206
00208 bool operator!=(wxTreeMultiItem const& item) const {return (this->GetItem() != item.GetItem());}
00209
00212 wxTreeMultiItem GetParent() const{
00213 wxCHECK(IsOk(), wxTreeMultiItem(0));
00214 return wxTreeMultiItem(_item->GetParent());
00215 };
00216
00235 bool IsOk() const {
00236 return _item != 0;
00237 };
00238
00244 bool IsWindowItem() const {
00245 if(_item && _item->IsTreeMultiItemWindow())
00246 return true;
00247 return false;
00248 };
00249
00256 bool IsNodeItem() const {
00257 if(_item && (_item->IsTreeMultiItemNode() || _item->IsTreeMultiItemRoot()))
00258 return true;
00259 return false;
00260 };
00261
00267 bool IsRootItem() const {
00268 if(_item && _item->IsTreeMultiItemRoot())
00269 return true;
00270 return false;
00271 };
00272
00278 bool IsExpanded() const {
00279 wxCHECK(_item, false);
00280 TreeMultiItemNode *n = _item->IsTreeMultiItemNode();
00281 wxCHECK(n, false);
00282
00283 return n->IsExpanded();
00284 };
00285
00289 bool IsExcluded() {
00290 wxCHECK(_item, false);
00291 return _item->IsExcluded();
00292 }
00293
00297 bool IsSelected(void) const
00298 {
00299 wxCHECK(this->GetItem(),false);
00300 return this->GetItem()->IsSelected();
00301 }
00305 bool IsVisible() {
00306 wxCHECK(_item, false);
00307 return _item->IsVisible();
00308 }
00309
00310 };
00311
00312 WX_DECLARE_OBJARRAY(wxTreeMultiItem,wxArrayTreeMultiItem);
00313
00345
00346
00347 class wxTreeMultiWindowInfo
00348 {
00349 private:
00353 int _flags;
00356 int _frontSpacing,
00357 _frontSpacingOrg;
00358
00360 int _topSpacing;
00361
00362 #if(CHECKBOXVIEW)
00363
00364 bool _checkState;
00365 #endif
00366
00367 public:
00368 #if(CHECKBOXVIEW)
00369 wxTreeMultiWindowInfo(int flags, int frontSpacing, int topSpacing, bool checkState = false)
00370 : _flags(flags)
00371 , _frontSpacing(frontSpacing)
00372 , _frontSpacingOrg(frontSpacing)
00373 , _topSpacing(topSpacing)
00374 , _checkState(checkState)
00375 #else
00376 wxTreeMultiWindowInfo(int flags, int frontSpacing, int topSpacing)
00377 : _flags(flags)
00378 , _frontSpacing(frontSpacing)
00379 , _frontSpacingOrg(frontSpacing)
00380 , _topSpacing(topSpacing)
00381 #endif
00382 {
00383
00384 }
00394 int Indent(int num = 1) {
00395 if(num > 0)
00396 _frontSpacing += (_frontSpacingOrg * num);
00397 return _frontSpacing;
00398 };
00405 int Outdent(int num = 1) {
00406 _frontSpacing -= (_frontSpacingOrg * num);
00407 if(_frontSpacing < 0)
00408 _frontSpacing = 0;
00409 return _frontSpacing;
00410 };
00411
00413 void SetFrontSpacing(int frontSpacing) {
00414 _frontSpacing = frontSpacing;
00415 _frontSpacingOrg = frontSpacing;
00416 };
00419 int GetFrontSpacing() const {
00420 return _frontSpacing;
00421 };
00422
00426 void SetTopSpacing(int topSpacing) {
00427 _topSpacing = topSpacing;
00428 if(_topSpacing < 0)
00429 _topSpacing = 0;
00430 };
00431
00432
00433 int GetTopSpacing() const {
00434 return _topSpacing;
00435 };
00436
00440 int SetFlags(int flags) {
00441 int tmp = _flags;
00442 _flags = flags;
00443 return tmp;
00444 };
00445
00449 int GetFlags() const {
00450 return _flags;
00451 };
00452
00457 int AddFlag(int flag_mask) {
00458 int tmp = _flags;
00459 _flags |= flag_mask;
00460 return tmp;
00461 };
00462
00467 int RemoveFlag(int flag_mask) {
00468 int tmp = _flags;
00469 _flags &= ~(flag_mask);
00470 return tmp;
00471 };
00472
00473 #if(CHECKBOXVIEW)
00474
00477 void SetDefaultCheckState(bool checkState = true) {
00478 _checkState = checkState;
00479 };
00480
00483 bool GetDefaultCheckState() const {
00484 return _checkState;
00485 };
00486 #endif
00487 };
00488
00489
00490 #ifndef LINUX
00491 #define wxTreeMultiWindowInfoDefault wxTreeMultiWindowInfo(wxTMC_BG_ADJUST_CNT, 8, 0)
00492 #else
00493 #define wxTreeMultiWindowInfoDefault wxTreeMultiWindowInfo(wxTMC_BG_ADJUST_ALL, 8, 0)
00494 #endif
00495
00532 class wxTreeMultiCtrl: public wxScrolledWindow
00533 {
00534 DECLARE_DYNAMIC_CLASS(wxTreeMultiCtrl)
00535
00536
00538 private:
00539 TreeMultiItemRoot _root;
00540
00541 long _style;
00542 wxBitmap *_expandBmp, *_collBmp;
00543
00545 int _iconDeltaY, _checkDeltaY;
00546
00547
00548 int _captionHeight;
00549
00552 int _gutterWidth;
00553
00555 int _iconWidth;
00556
00558 int _iconHeight;
00559
00561 int _maxHeight;
00562
00563
00565 int _spacingY;
00566
00568 bool _create_called;
00569
00570 #if(CHECKBOXVIEW)
00571 wxBitmap *_checkBmp, *_uncheckBmp, *_tristateBmp;
00572
00574 bool _checkboxView;
00575
00577 int _checkHeight, _checkWidth;
00578 #endif
00579
00581 wxBrush* m_HilightBrush;
00582
00585 wxFont _captionFont;
00586
00588 wxArrayTreeMultiItem m_SelectedItems;
00589
00591 void DoFold(TreeMultiItemBase *item, bool expand, bool recursive);
00592
00595 void RedrawFromNode(TreeMultiItemNode *n);
00596
00598 void RedrawFromParentNode(TreeMultiItemBase *b);
00599
00601 void DrawCheckbox(TreeMultiItemBase *b, wxDC &dc, bool convertScrolled = false);
00602
00611 void RecalculateNodePositions();
00612
00615 int CalculateNodeDimensions(TreeMultiItemBase *b, int currentY, int level);
00616
00617 void DrawNode(TreeMultiItemBase *b, wxDC &dc);
00618
00621 void SetWindowBackgroundColour(wxWindow *wnd, const wxColour &col, int flags);
00622
00624 void ShowTreeMultiWindow(TreeMultiItemWindow *window, bool show = true);
00625
00628 void UpdateAllWindowVisibility();
00629
00631 void UpdateTreeMultiWindowVisibility(TreeMultiItemBase *b, bool show);
00632
00635 void RecalculateVirtualSize();
00636
00638 using wxScrolledWindow::AdjustScrollbars;
00639 virtual void AdjustScrollbars(int x, int y);
00640
00642 void RecalculateVirtualSizeFromNode(const TreeMultiItemNode *node, int &x, int &y);
00643
00646 TreeMultiItemBase *FindNodeByPoint(TreeMultiItemBase *b, wxPoint const& pt, int &area);
00647
00651 wxTreeMultiItem FindWindowNode(wxWindow *wnd, TreeMultiItemNode *n = 0);
00652
00655 TreeMultiItemWindow *FindNextVisibleWindowItem(TreeMultiItemBase *b, int index = -1);
00656
00659 void AdjustIconsDeltaY();
00660
00662 void CalculateNodeSpanning(TreeMultiItemBase *b);
00663
00664 #if(CHECKBOXVIEW)
00665
00666 void SetRecursiveCheckState(TreeMultiItemNode *n, bool check);
00667
00672 void ScanTristateCheckstates(TreeMultiItemBase *b);
00673 #endif
00674
00686 wxTreeMultiItem InsertNode(TreeMultiItemNode* ParentPtr, size_t Position, wxString const& Caption, wxString const& Name);
00687
00695 wxTreeMultiItem InsertWindow(TreeMultiItemNode* ParentPtr, size_t Position, wxWindow* WindowPtr, wxString const& Name,
00696 wxTreeMultiWindowInfo const& Info, int Flags);
00697
00700 private:
00701 void Init();
00702
00703
00704
00705
00706
00707 void OnPaint(wxPaintEvent &event);
00708 void OnMouseClick (wxMouseEvent& event);
00709 void OnRightMouseClick(wxMouseEvent& Event);
00710 void OnKey(wxKeyEvent &event);
00711 void OnSize(wxSizeEvent &event);
00712
00714 void RecalculateSpanSizes();
00715
00716 public:
00720 wxTreeMultiCtrl()
00721 : _create_called(false)
00722 {
00723
00724 Init();
00725 }
00726
00731 wxTreeMultiCtrl(wxWindow *parent, wxWindowID id = -1,
00732 const wxPoint& pos = wxDefaultPosition,
00733 const wxSize& size = wxDefaultSize,
00734 long style = wxTMC_DEFAULT_STYLE,
00735 const wxValidator &validator = wxDefaultValidator,
00736 const wxString& name = wxTreeMultiCtrlNameStr)
00737 : _style(style | wxTAB_TRAVERSAL)
00738 , _create_called(false)
00739 {
00740 Create(parent, id, pos, size, style, validator, name);
00741 }
00742
00744 virtual ~wxTreeMultiCtrl();
00745
00751 bool Create(wxWindow *parent, wxWindowID id = -1,
00752 const wxPoint& pos = wxDefaultPosition,
00753 const wxSize& size = wxDefaultSize,
00754 long style = wxTMC_DEFAULT_STYLE,
00755 const wxValidator &validator = wxDefaultValidator,
00756 const wxString& name = wxTreeMultiCtrlNameStr);
00757
00758
00759
00760
00769 wxTreeMultiItem AddRoot(const wxString &caption, const wxString &name = wxEmptyString);
00770
00776 wxTreeMultiItem AppendWindow(const wxTreeMultiItem &ParentItem, wxWindow *window = NULL, const wxString &name = wxEmptyString,
00777 wxTreeMultiWindowInfo const& info = wxTreeMultiWindowInfoDefault, int flags = 0);
00778
00785 wxTreeMultiItem InsertWindow(wxTreeMultiItem const& ParentItem, size_t Position, wxWindow *window = NULL, wxString const& Name = wxEmptyString,
00786 wxTreeMultiWindowInfo const& info = wxTreeMultiWindowInfoDefault, int flags = 0);
00787
00792 wxTreeMultiItem PrependWindow(wxTreeMultiItem const& ParentItem, wxWindow *window = NULL, const wxString &name = wxEmptyString,
00793 wxTreeMultiWindowInfo const& info = wxTreeMultiWindowInfoDefault, int flags = 0);
00794
00798 wxTreeMultiItem AppendNode(wxTreeMultiItem const& ParentItem, const wxString &caption = wxEmptyString,
00799 const wxString &name = wxEmptyString);
00800
00807 wxTreeMultiItem InsertNode(wxTreeMultiItem const& ParentItem, size_t Position, wxString const& caption, wxString const& name);
00808
00813 wxTreeMultiItem PrependNode(wxTreeMultiItem const& ParentItem, wxString const& caption = wxEmptyString,
00814 wxString const& name = wxEmptyString);
00815
00818 bool Delete(wxTreeMultiItem &item);
00819
00821 void DeleteAllItems(void)
00822 {
00823 this->_root.Clear();
00824 this->m_SelectedItems.Clear();
00825 Refresh();
00826 };
00827
00830 void DeleteChildren(const wxTreeMultiItem &item);
00831
00841 void ExpandNodes(bool recursive = false);
00842
00844 void CollapseNodes(bool recursive = false);
00845
00847 void Expand(const wxTreeMultiItem &item, bool recursive);
00848
00851 void Collapse(const wxTreeMultiItem &item, bool recursive);
00852
00855 void CollapseAndReset(const wxTreeMultiItem &item);
00856
00859 void Fold(const wxTreeMultiItem &item, bool expand = true) {
00860 if(expand)
00861 Expand(item, false);
00862 else
00863 Collapse(item, false);
00864 };
00865
00876 size_t GetSelectedItemCount(void) const {return this->m_SelectedItems.GetCount();}
00877
00881 wxTreeMultiItem GetFirstSelectedItem(void) const;
00882
00886 wxTreeMultiItem GetLastSelectedItem(void) const;
00887
00891 wxTreeMultiItem GetSelectedItem(size_t Index) const;
00892
00896 size_t GetSelectedItemIndex(wxTreeMultiItem const& Item) const;
00897
00906 void SelectItem(wxTreeMultiItem const& Item, bool UnselectOthers=true, bool ExpandSelection=false);
00907
00909 void UnselectAll(void);
00910
00912 void Unselect(wxTreeMultiItem const& Item);
00913
00928 void Exclude(const wxTreeMultiItem &item);
00929
00933 void Include(const wxTreeMultiItem &item);
00934
00937 wxTreeMultiItem GetExcludedParent(const wxTreeMultiItem &item);
00938
00949 wxTreeMultiItem HitTest(wxPoint const& pt, int &flags);
00950
00960 wxTreeMultiItem FindItem(const wxTreeMultiItem &item, const wxString &name, bool ignoreCase = false,
00961 bool skipFirst = false);
00962
00964 wxTreeMultiItem FindItem(const wxString &name, bool ignoreCase = false) {
00965 return FindItem(wxTreeMultiItem(&_root), name, ignoreCase, false);
00966 };
00967
00972 int GetChildrenCount(const wxTreeMultiItem &item) {
00973 if(item.IsNodeItem())
00974 {
00975 TreeMultiItemNode *n = (TreeMultiItemNode *)item.GetItem();
00976 return n->GetNodeCount();
00977 }
00978
00979 return -1;
00980 };
00981
00986 wxTreeMultiItem GetFocus();
00987
01006 bool GetBooleanValue(int wndId);
01007
01016 wxString GetTextValue(int wndId);
01017
01025 void SetBooleanValue(int wndId, bool value = true);
01026
01034 void SetTextValue(int wndId, const wxString &value = wxEmptyString);
01035
01038 wxWindow *GetWindow(const wxTreeMultiItem &item) {
01039 if(item.IsWindowItem())
01040 return ((TreeMultiItemWindow *)item.GetItem())->GetWindow();
01041 return 0;
01042 };
01043
01049 void SetSelectionValue(int wndId, int sel);
01050
01056 int GetSelectionValue(int wndId);
01057
01064 void GetSelectionValues(int wndId, wxArrayInt &sels);
01065
01066 #if(CHECKBOXVIEW)
01067
01071 int GetCheckboxState(const wxTreeMultiItem &item, bool WXUNUSED(recursive)) {
01072 wxCHECK(item.IsOk(), -1);
01073
01074
01075 TreeMultiItemBase *b = item.GetItem();
01076 if(b->GetCheckbox())
01077 return b->GetCheckboxState();
01078
01079 return -1;
01080 };
01081
01085 void SetCheckboxState( const wxTreeMultiItem &item, int state ) {
01086 wxCHECK2( item.IsOk(), return );
01087 TreeMultiItemBase *b = item.GetItem();
01088 if( b->GetCheckbox() )
01089 b->SetCheckboxState( state );
01090 RedrawFromNode( item.GetItem()->GetParent() );
01091 };
01092 #endif
01093
01105 void SetSpacingY(int spacingY) {
01106 if(spacingY >= 0)
01107 {
01108 _spacingY = spacingY;
01109 RedrawFromNode(0);
01110 }
01111 };
01112
01115 int GetSpacingY() const {
01116 return _spacingY;
01117 };
01118
01119 #if(CHECKBOXVIEW)
01120
01124 void SetCheckboxView(bool value) {
01125 _checkboxView = value;
01126 };
01127
01132 bool GetCheckboxView() const {
01133 return _checkboxView;
01134 };
01135 #endif
01136
01147 wxTreeMultiItem GetFirstRoot(void) const {return wxTreeMultiItem(this->_root.First());}
01148
01150 wxTreeMultiItem GetLastRoot(void) const {return wxTreeMultiItem(this->_root.Last());}
01151
01153 wxTreeMultiItem GetParent(wxTreeMultiItem const& item) const;
01154
01158 wxTreeMultiItem GetFirstChild(const wxTreeMultiItem &item, int &cookie) const;
01159
01162 wxTreeMultiItem GetNextChild(const wxTreeMultiItem &item, int &cookie) const;
01163
01166 wxTreeMultiItem GetLastChild(const wxTreeMultiItem &item) const;
01167
01169 wxTreeMultiItem GetNextSibling(wxTreeMultiItem const& item) const;
01170
01172 wxTreeMultiItem GetPrevSibling(wxTreeMultiItem const& item) const;
01173
01179 wxTreeMultiItem GetNext(wxTreeMultiItem const& item) const;
01180
01186 wxTreeMultiItem GetPrevious(wxTreeMultiItem const& item) const;
01187
01188
01200 const wxFont &GetCaptionFont() const {
01201 return _captionFont;
01202 };
01203
01207 void SetCaptionFont(const wxFont &font);
01208
01212 void OnDraw(wxDC& dc);
01213
01214 private:
01215 DECLARE_EVENT_TABLE()
01216 };
01217
01218 #endif