X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/233058c7abe360926b8e905de1a49884e2035130..f1d93f0beeec9d88f8a225aa35a9ccc163dcdb15:/src/generic/treectlg.cpp?ds=sidebyside diff --git a/src/generic/treectlg.cpp b/src/generic/treectlg.cpp index 3e1dcb049b..01072caca3 100644 --- a/src/generic/treectlg.cpp +++ b/src/generic/treectlg.cpp @@ -84,7 +84,7 @@ public: const wxString &value = wxEmptyString, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, - int style = 0, + int style = wxSIMPLE_BORDER, const wxValidator& validator = wxDefaultValidator, const wxString &name = wxTextCtrlNameStr ); @@ -178,10 +178,10 @@ public: // status inquiries bool HasChildren() const { return !m_children.IsEmpty(); } - bool IsSelected() const { return m_hasHilight; } + bool IsSelected() const { return m_hasHilight != 0; } bool IsExpanded() const { return !m_isCollapsed; } bool HasPlus() const { return m_hasPlus || HasChildren(); } - bool IsBold() const { return m_isBold; } + bool IsBold() const { return m_isBold != 0; } // attributes // get them - may be NULL @@ -615,6 +615,8 @@ void wxGenericTreeCtrl::Init() m_imageListNormal = m_imageListState = (wxImageList *) NULL; + m_ownsImageListNormal = + m_ownsImageListState = FALSE; m_dragCount = 0; m_isDragging = FALSE; @@ -638,8 +640,6 @@ bool wxGenericTreeCtrl::Create(wxWindow *parent, wxWindowID id, const wxValidator &validator, const wxString& name ) { - Init(); - wxScrolledWindow::Create( parent, id, pos, size, style|wxHSCROLL|wxVSCROLL, name ); #if wxUSE_VALIDATORS @@ -660,6 +660,8 @@ wxGenericTreeCtrl::~wxGenericTreeCtrl() DeleteAllItems(); delete m_renameTimer; + if (m_ownsImageListNormal) delete m_imageListNormal; + if (m_ownsImageListState) delete m_imageListState; } // ----------------------------------------------------------------------------- @@ -803,9 +805,34 @@ void wxGenericTreeCtrl::SetItemFont(const wxTreeItemId& item, const wxFont& font // item status inquiries // ----------------------------------------------------------------------------- -bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& WXUNUSED(item)) const +bool wxGenericTreeCtrl::IsVisible(const wxTreeItemId& item) const { - wxFAIL_MSG(wxT("not implemented")); + wxCHECK_MSG( item.IsOk(), FALSE, wxT("invalid tree item") ); + + // An item is only visible if it's not a descendant of a collapsed item + wxGenericTreeItem *pItem = (wxGenericTreeItem*) item.m_pItem; + wxGenericTreeItem* parent = pItem->GetParent(); + while (parent) + { + if (!parent->IsExpanded()) + return FALSE; + parent = parent->GetParent(); + } + + int startX, startY; + GetViewStart(& startX, & startY); + + wxSize clientSize = GetClientSize(); + + wxRect rect; + if (!GetBoundingRect(item, rect)) + return FALSE; + if (rect.GetWidth() == 0 || rect.GetHeight() == 0) + return FALSE; + if (rect.GetBottom() < 0 || rect.GetTop() > clientSize.y) + return FALSE; + if (rect.GetRight() < 0 || rect.GetLeft() > clientSize.x) + return FALSE; return TRUE; } @@ -921,19 +948,70 @@ wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const : wxTreeItemId(siblings[(size_t)(index - 1)]); } -wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const +// Only for internal use right now, but should probably be public +wxTreeItemId wxGenericTreeCtrl::GetNext(const wxTreeItemId& item) const +{ + wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); + + wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem; + + // First see if there are any children. + wxArrayGenericTreeItems& children = i->GetChildren(); + if (children.GetCount() > 0) + { + return children.Item(0); + } + else + { + // Try a sibling of this or ancestor instead + wxTreeItemId p = item; + wxTreeItemId toFind; + do + { + toFind = GetNextSibling(p); + p = GetParent(p); + } while (p.IsOk() && !toFind.IsOk()); + return toFind; + } +} + +wxTreeItemId wxGenericTreeCtrl::GetPrev(const wxTreeItemId& item) const { + wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); + wxFAIL_MSG(wxT("not implemented")); return wxTreeItemId(); } +wxTreeItemId wxGenericTreeCtrl::GetFirstVisibleItem() const +{ + wxTreeItemId id = GetRootItem(); + if (!id.IsOk()) + return id; + + do + { + if (IsVisible(id)) + return id; + id = GetNext(id); + } while (id.IsOk()); + + return wxTreeItemId(); +} + wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const { wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") ); - wxFAIL_MSG(wxT("not implemented")); + wxTreeItemId id = item; + while (id.IsOk()) + { + id = GetNext(id); + if (id.IsOk() && IsVisible(id)) + return id; + } return wxTreeItemId(); } @@ -969,7 +1047,7 @@ wxTreeItemId wxGenericTreeCtrl::DoInsertItem(const wxTreeItemId& parentId, if ( data != NULL ) { - data->m_pItem = item; + data->m_pItem = (long) item; } parent->Insert( item, previous ); @@ -990,7 +1068,7 @@ wxTreeItemId wxGenericTreeCtrl::AddRoot(const wxString& text, image, selImage, data); if ( data != NULL ) { - data->m_pItem = m_anchor; + data->m_pItem = (long) m_anchor; } if (!HasFlag(wxTR_MULTIPLE)) @@ -1067,7 +1145,7 @@ wxTreeItemId wxGenericTreeCtrl::AppendItem(const wxTreeItemId& parentId, void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item) { wxTreeEvent event( wxEVT_COMMAND_TREE_DELETE_ITEM, GetId() ); - event.m_item = item; + event.m_item = (long) item; event.SetEventObject( this ); ProcessEvent( event ); } @@ -1146,7 +1224,7 @@ void wxGenericTreeCtrl::Expand(const wxTreeItemId& itemId) return; wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_EXPANDING, GetId() ); - event.m_item = item; + event.m_item = (long) item; event.SetEventObject( this ); if ( ProcessEvent( event ) && !event.IsAllowed() ) @@ -1188,7 +1266,7 @@ void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId) return; wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_COLLAPSING, GetId() ); - event.m_item = item; + event.m_item = (long) item; event.SetEventObject( this ); if ( ProcessEvent( event ) && !event.IsAllowed() ) { @@ -1364,8 +1442,8 @@ void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId, } wxTreeEvent event( wxEVT_COMMAND_TREE_SEL_CHANGING, GetId() ); - event.m_item = item; - event.m_itemOld = m_current; + event.m_item = (long) item; + event.m_itemOld = (long) m_current; event.SetEventObject( this ); // TODO : Here we don't send any selection mode yet ! @@ -1555,7 +1633,10 @@ wxImageList *wxGenericTreeCtrl::GetStateImageList() const void wxGenericTreeCtrl::SetImageList(wxImageList *imageList) { + if (m_ownsImageListNormal) delete m_imageListNormal; + m_imageListNormal = imageList; + m_ownsImageListNormal = FALSE; if ( !m_imageListNormal ) return; @@ -1582,7 +1663,21 @@ void wxGenericTreeCtrl::SetImageList(wxImageList *imageList) void wxGenericTreeCtrl::SetStateImageList(wxImageList *imageList) { + if (m_ownsImageListState) delete m_imageListState; m_imageListState = imageList; + m_ownsImageListState = FALSE; +} + +void wxGenericTreeCtrl::AssignImageList(wxImageList *imageList) +{ + SetImageList(imageList); + m_ownsImageListNormal = TRUE; +} + +void wxGenericTreeCtrl::AssignStateImageList(wxImageList *imageList) +{ + SetStateImageList(imageList); + m_ownsImageListState = TRUE; } // ----------------------------------------------------------------------------- @@ -1742,7 +1837,7 @@ void wxGenericTreeCtrl::PaintLevel( wxGenericTreeItem *item, wxDC &dc, int level if ( attr && attr->HasTextColour() ) colText = attr->GetTextColour(); else - colText = *wxBLACK; + colText = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_WINDOWTEXT ); } // prepare to draw @@ -1946,7 +2041,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event ) case WXK_RETURN: { wxTreeEvent event( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); - event.m_item = m_current; + event.m_item = (long) m_current; event.m_code = 0; event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); @@ -2109,6 +2204,27 @@ wxTreeItemId wxGenericTreeCtrl::HitTest(const wxPoint& point, int& flags) return m_anchor->HitTest( wxPoint(x, y), this, flags); } +// get the bounding rectangle of the item (or of its label only) +bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item, + wxRect& rect, + bool textOnly) const +{ + wxCHECK_MSG( item.IsOk(), FALSE, _T("invalid item in wxGenericTreeCtrl::GetBoundingRect") ); + + wxGenericTreeItem *i = (wxGenericTreeItem*) item.m_pItem; + + int startX, startY; + GetViewStart(& startX, & startY); + + rect.x = i->GetX() - startX*PIXELS_PER_UNIT; + rect.y = i->GetY() - startY*PIXELS_PER_UNIT; + rect.width = i->GetWidth(); + //rect.height = i->GetHeight(); + rect.height = GetLineHeight(i); + + return TRUE; +} + /* **** */ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) @@ -2118,7 +2234,7 @@ void wxGenericTreeCtrl::Edit( const wxTreeItemId& item ) m_currentEdit = (wxGenericTreeItem*) item.m_pItem; wxTreeEvent te( wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT, GetId() ); - te.m_item = m_currentEdit; + te.m_item = (long) m_currentEdit; te.SetEventObject( this ); GetEventHandler()->ProcessEvent( te ); @@ -2172,7 +2288,7 @@ void wxGenericTreeCtrl::OnRenameTimer() void wxGenericTreeCtrl::OnRenameAccept() { wxTreeEvent le( wxEVT_COMMAND_TREE_END_LABEL_EDIT, GetId() ); - le.m_item = m_currentEdit; + le.m_item = (long) m_currentEdit; le.SetEventObject( this ); le.m_label = m_renameRes; GetEventHandler()->ProcessEvent( le ); @@ -2227,7 +2343,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) : wxEVT_COMMAND_TREE_BEGIN_DRAG; wxTreeEvent nevent( command, GetId() ); - nevent.m_item = m_current; + nevent.m_item = (long) m_current; nevent.SetEventObject(this); // by default the dragging is not supported, the user code must @@ -2281,7 +2397,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) // generate the drag end event wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, GetId()); - event.m_item = item; + event.m_item = (long) item; event.m_pointDrag = wxPoint(x, y); event.SetEventObject(this); @@ -2314,21 +2430,27 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) if ( event.RightDown() ) { wxTreeEvent nevent(wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK, GetId()); - nevent.m_item = item; + nevent.m_item = (long) item; nevent.m_code = 0; nevent.SetEventObject(this); GetEventHandler()->ProcessEvent(nevent); } - else if ( event.LeftUp() && m_lastOnSame ) + else if ( event.LeftUp() ) { - if ( (item == m_current) && - (flags & wxTREE_HITTEST_ONITEMLABEL) && - HasFlag(wxTR_EDIT_LABELS) ) + if ( m_lastOnSame ) { - m_renameTimer->Start( 100, TRUE ); - } + if ( (item == m_current) && + (flags & wxTREE_HITTEST_ONITEMLABEL) && + HasFlag(wxTR_EDIT_LABELS) ) + { + if ( m_renameTimer->IsRunning() ) + m_renameTimer->Stop(); - m_lastOnSame = FALSE; + m_renameTimer->Start( 100, TRUE ); + } + + m_lastOnSame = FALSE; + } } else { @@ -2360,7 +2482,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event ) m_lastOnSame = FALSE; wxTreeEvent nevent( wxEVT_COMMAND_TREE_ITEM_ACTIVATED, GetId() ); - nevent.m_item = item; + nevent.m_item = (long) item; nevent.m_code = 0; nevent.SetEventObject( this ); GetEventHandler()->ProcessEvent( nevent );