// array types
// -----------------------------------------------------------------------------
-class WXDLLEXPORT wxGenericTreeItem;
+class WXDLLIMPEXP_FWD_CORE wxGenericTreeItem;
WX_DEFINE_EXPORTED_ARRAY_PTR(wxGenericTreeItem *, wxArrayGenericTreeItems);
void wxGenericTreeItem::DeleteChildren(wxGenericTreeCtrl *tree)
{
- size_t count = m_children.Count();
+ size_t count = m_children.GetCount();
for ( size_t n = 0; n < count; n++ )
{
wxGenericTreeItem *child = m_children[n];
size_t wxGenericTreeItem::GetChildrenCount(bool recursively) const
{
- size_t count = m_children.Count();
+ size_t count = m_children.GetCount();
if ( !recursively )
return count;
if (IsExpanded())
{
- size_t count = m_children.Count();
+ size_t count = m_children.GetCount();
for ( size_t n = 0; n < count; ++n )
{
m_children[n]->GetSize( x, y, theButton );
}
// evaluate children
- size_t count = m_children.Count();
+ size_t count = m_children.GetCount();
for ( size_t n = 0; n < count; n++ )
{
wxGenericTreeItem *res = m_children[n]->HitTest( point,
m_lastOnSame = false;
-#ifdef __WXMAC_CARBON__
- m_normalFont.MacCreateThemeFont( kThemeViewsFont ) ;
+#ifdef __WXMAC__
+ m_normalFont.MacCreateFromThemeFont( kThemeViewsFont ) ;
#else
m_normalFont = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT );
#endif
if (!m_hasFont)
SetOwnFont(attr.font);
- m_dottedPen = wxPen( wxT("grey"), 0, 0 );
+ // this is a misnomer: it's called "dotted pen" but uses (default) wxSOLID
+ // style because we apparently get performance problems when using dotted
+ // pen for drawing in some ports -- but under MSW it seems to work fine
+#ifdef __WXMSW__
+ m_dottedPen = wxPen(*wxLIGHT_GREY, 0, wxDOT);
+#else
+ m_dottedPen = *wxGREY_PEN;
+#endif
SetInitialSize(size);
// it's ok to cast cookie to size_t, we never have indices big enough to
// overflow "void *"
size_t *pIndex = (size_t *)&cookie;
- if ( *pIndex < children.Count() )
+ if ( *pIndex < children.GetCount() )
{
return children.Item((*pIndex)++);
}
wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
size_t n = (size_t)(index + 1);
- return n == siblings.Count() ? wxTreeItemId() : wxTreeItemId(siblings[n]);
+ return n == siblings.GetCount() ? wxTreeItemId() : wxTreeItemId(siblings[n]);
}
wxTreeItemId wxGenericTreeCtrl::GetPrevSibling(const wxTreeItemId& item) const
wxTreeItemId wxGenericTreeCtrl::GetNextVisible(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+ wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") );
wxTreeItemId id = item;
if (id.IsOk())
wxTreeItemId wxGenericTreeCtrl::GetPrevVisible(const wxTreeItemId& item) const
{
wxCHECK_MSG( item.IsOk(), wxTreeItemId(), wxT("invalid tree item") );
+ wxASSERT_MSG( IsVisible(item), wxT("this item itself should be visible") );
- wxFAIL_MSG(wxT("not implemented"));
+ // find out the starting point
+ wxTreeItemId prevItem = GetPrevSibling(item);
+ if ( !prevItem.IsOk() )
+ {
+ prevItem = GetItemParent(item);
+ }
- return wxTreeItemId();
+ // find the first visible item after it
+ while ( prevItem.IsOk() && !IsVisible(prevItem) )
+ {
+ prevItem = GetNext(prevItem);
+ if ( !prevItem.IsOk() || prevItem == item )
+ {
+ // there are no visible items before item
+ return wxTreeItemId();
+ }
+ }
+
+ // from there we must be able to navigate until this item
+ while ( prevItem.IsOk() )
+ {
+ const wxTreeItemId nextItem = GetNextVisible(prevItem);
+ if ( !nextItem.IsOk() || nextItem == item )
+ break;
+
+ prevItem = nextItem;
+ }
+
+ return prevItem;
}
// called by wxTextTreeCtrl when it marks itself for deletion
parent->Insert( item, previous == (size_t)-1 ? parent->GetChildren().size()
: previous );
+ InvalidateBestSize();
return item;
}
m_current->SetHilight( true );
}
+ InvalidateBestSize();
return m_anchor;
}
void wxGenericTreeCtrl::SendDeleteEvent(wxGenericTreeItem *item)
{
wxTreeEvent event(wxEVT_COMMAND_TREE_DELETE_ITEM, this, item);
- ProcessEvent( event );
+ GetEventHandler()->ProcessEvent( event );
}
// Don't leave edit or selection on a child which is about to disappear
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
ChildrenClosing(item);
item->DeleteChildren(this);
+ InvalidateBestSize();
}
void wxGenericTreeCtrl::Delete(const wxTreeItemId& itemId)
m_select_me = NULL;
delete item;
+
+ InvalidateBestSize();
}
void wxGenericTreeCtrl::DeleteAllItems()
wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_EXPANDING, this, item);
- if ( ProcessEvent( event ) && !event.IsAllowed() )
+ if ( GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed() )
{
// cancelled by program
return;
}
item->Expand();
- CalculatePositions();
+ if ( !m_freezeCount )
+ {
+ CalculatePositions();
- RefreshSubtree(item);
+ RefreshSubtree(item);
+ }
+ else // frozen
+ {
+ m_dirty = true;
+ }
event.SetEventType(wxEVT_COMMAND_TREE_ITEM_EXPANDED);
- ProcessEvent( event );
+ GetEventHandler()->ProcessEvent( event );
}
void wxGenericTreeCtrl::Collapse(const wxTreeItemId& itemId)
return;
wxTreeEvent event(wxEVT_COMMAND_TREE_ITEM_COLLAPSING, this, item);
- if ( ProcessEvent( event ) && !event.IsAllowed() )
+ if ( GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed() )
{
// cancelled by program
return;
#if 0 // TODO why should items be collapsed recursively?
wxArrayGenericTreeItems& children = item->GetChildren();
- size_t count = children.Count();
+ size_t count = children.GetCount();
for ( size_t n = 0; n < count; n++ )
{
Collapse(children[n]);
RefreshSubtree(item);
event.SetEventType(wxEVT_COMMAND_TREE_ITEM_COLLAPSED);
- ProcessEvent( event );
+ GetEventHandler()->ProcessEvent( event );
}
void wxGenericTreeCtrl::CollapseAndReset(const wxTreeItemId& item)
if (item->HasChildren())
{
wxArrayGenericTreeItems& children = item->GetChildren();
- size_t count = children.Count();
+ size_t count = children.GetCount();
for ( size_t n = 0; n < count; ++n )
{
UnselectAllChildren(children[n]);
int index = children.Index(crt_item);
wxASSERT( index != wxNOT_FOUND ); // I'm not a child of my parent?
- size_t count = children.Count();
+ size_t count = children.GetCount();
for (size_t n=(size_t)(index+1); n<count; ++n)
{
if (TagAllChildrenUntilLast(children[n], last_item, select)) return true;
if (crt_item->HasChildren())
{
wxArrayGenericTreeItems& children = crt_item->GetChildren();
- size_t count = children.Count();
+ size_t count = children.GetCount();
for ( size_t n = 0; n < count; ++n )
{
if (TagAllChildrenUntilLast(children[n], last_item, select))
}
//else: the tree is empty, so no selections
- return array.Count();
+ return array.GetCount();
}
void wxGenericTreeCtrl::EnsureVisible(const wxTreeItemId& item)
wxT("wxGenericTreeCtrl::SortChildren is not reentrant") );
wxArrayGenericTreeItems& children = item->GetChildren();
- if ( children.Count() > 1 )
+ if ( children.GetCount() > 1 )
{
m_dirty = true;
else if (item->IsBold())
dc.SetFont(m_boldFont);
- long text_w = 0, text_h = 0;
+ wxCoord text_w = 0, text_h = 0;
dc.GetTextExtent( item->GetText(), &text_w, &text_h );
int image_h = 0, image_w = 0;
{
int flags = wxCONTROL_SELECTED;
if (m_hasFocus
-#ifdef __WXMAC__
+#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
&& IsControlActive( (ControlRef)GetHandle() )
#endif
)
// always expand hidden root
int origY = y;
wxArrayGenericTreeItems& children = item->GetChildren();
- int count = children.Count();
+ int count = children.GetCount();
if (count > 0)
{
int n = 0, oldY;
wxColour colText;
if ( item->IsSelected()
-#ifdef __WXMAC__
+#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
// On wxMac, if the tree doesn't have the focus we draw an empty
// rectangle, so we want to make sure that the text is visible
// against the normal background, not the highlightbackground, so
if (item->IsExpanded())
{
wxArrayGenericTreeItems& children = item->GetChildren();
- int count = children.Count();
+ int count = children.GetCount();
if (count > 0)
{
int n = 0, oldY;
case WXK_RIGHT:
// this works the same as the down arrow except that we
// also expand the item if it wasn't expanded yet
- Expand(m_current);
+ if (m_current != GetRootItem().m_pItem || !HasFlag(wxTR_HIDE_ROOT))
+ Expand(m_current);
+ //else: don't try to expand hidden root item (which can be the
+ // current one when the tree is empty)
+
// fall through
case WXK_DOWN:
{
wxTreeItemIdValue cookie;
wxTreeItemId child = GetFirstChild( m_key_current, cookie );
+ if ( !child )
+ break;
+
DoSelectItem( child, unselect_others, extended_select );
m_key_current=(wxGenericTreeItem*) child.m_pItem;
}
Recurse:
wxArrayGenericTreeItems& children = item->GetChildren();
- size_t n, count = children.Count();
+ size_t n, count = children.GetCount();
++level;
for (n = 0; n < count; ++n )
CalculateLevel( children[n], dc, level, y ); // recurse
if ( --m_freezeCount == 0 )
{
- Refresh();
+ if ( m_dirty )
+ DoDirtyProcessing();
+ else
+ Refresh();
}
}