/////////////////////////////////////////////////////////////////////////////
-// Name: treectlg.cpp
+// Name: src/generic/treectlg.cpp
// Purpose: generic tree control implementation
// Author: Robert Roebling
// Created: 01/02/97
#if wxUSE_TREECTRL
-#include "wx/treebase.h"
#include "wx/treectrl.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/dcclient.h"
+ #include "wx/timer.h"
+ #include "wx/settings.h"
+#endif
+
#include "wx/generic/treectlg.h"
-#include "wx/timer.h"
#include "wx/textctrl.h"
#include "wx/imaglist.h"
-#include "wx/settings.h"
-#include "wx/dcclient.h"
#include "wx/renderer.h"
static const int PIXELS_PER_UNIT = 10;
+// the margin between the item image and the item text
+static const int MARGIN_BETWEEN_IMAGE_AND_TEXT = 4;
+
// -----------------------------------------------------------------------------
// private classes
// -----------------------------------------------------------------------------
wxGenericTreeItem *GetParent() const { return m_parent; }
// operations
- // deletes all children notifying the treectrl about it if !NULL
- // pointer given
- void DeleteChildren(wxGenericTreeCtrl *tree = NULL);
+
+ // deletes all children notifying the treectrl about it
+ void DeleteChildren(wxGenericTreeCtrl *tree);
// get count of all children (and grand children if 'recursively')
size_t GetChildrenCount(bool recursively = true) const;
if ( m_owner->m_imageListNormal )
{
m_owner->m_imageListNormal->GetSize( image, image_w, image_h );
- image_w += 4;
+ image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}
else
{
for ( size_t n = 0; n < count; n++ )
{
wxGenericTreeItem *child = m_children[n];
- if (tree)
- tree->SendDeleteEvent(child);
+ tree->SendDeleteEvent(child);
child->DeleteChildren(tree);
- if (child == tree->m_select_me)
+ if ( child == tree->m_select_me )
tree->m_select_me = NULL;
delete child;
}
// accessors
// -----------------------------------------------------------------------------
-size_t wxGenericTreeCtrl::GetCount() const
+unsigned int wxGenericTreeCtrl::GetCount() const
{
if ( !m_anchor )
{
return 0;
}
- size_t count = m_anchor->GetChildrenCount();
+ unsigned int count = m_anchor->GetChildrenCount();
if ( !HasFlag(wxTR_HIDE_ROOT) )
{
// take the root itself into account
parent = GetItemParent( parent );
}
- EnsureVisible( itemId );
-
// ctrl press
if (unselect_others)
{
RefreshLine( m_current );
}
+ // This can cause idle processing to select the root
+ // if no item is selected, so it must be after the
+ // selection is set
+ EnsureVisible( itemId );
+
event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
GetEventHandler()->ProcessEvent( event );
}
if ( m_imageListNormal )
{
m_imageListNormal->GetSize( image, image_w, image_h );
- image_w += 4;
+ image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}
else
{
if (IsExposed(exposed_x, exposed_y, 10000, h)) // 10000 = very much
{
- wxPen *pen =
+ const wxPen *pen =
#ifndef __WXMAC__
// don't draw rect outline if we already have the
// background color under Mac
wxTRANSPARENT_PEN;
wxColour colText;
- if ( item->IsSelected() )
+ if ( item->IsSelected()
+#ifdef __WXMAC__
+ // 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
+ // don't use the highlight text colour unless we have the focus.
+ && m_hasFocus
+#endif
+ )
{
colText = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
}
}
}
-wxTreeItemId wxGenericTreeCtrl::DoHitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxGenericTreeCtrl::DoTreeHitTest(const wxPoint& point, int& flags)
{
// JACS: removed wxYieldIfNeeded() because it can cause the window
// to be deleted from under us if a close window event is pending
// get the bounding rectangle of the item (or of its label only)
bool wxGenericTreeCtrl::GetBoundingRect(const wxTreeItemId& item,
wxRect& rect,
- bool WXUNUSED(textOnly)) const
+ 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);
+ if ( textOnly )
+ {
+ rect.x = i->GetX();
+ rect.width = i->GetWidth();
+
+ if ( m_imageListNormal )
+ {
+ int image_w, image_h;
+ m_imageListNormal->GetSize( 0, image_w, image_h );
+ rect.width += image_w + MARGIN_BETWEEN_IMAGE_AND_TEXT;
+ }
+ }
+ else // the entire line
+ {
+ rect.x = 0;
+ rect.width = GetClientSize().x;
+ }
- 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.y = i->GetY();
rect.height = GetLineHeight(i);
+ // we have to return the logical coordinates, not physical ones
+ rect.SetTopLeft(CalcScrolledPosition(rect.GetTopLeft()));
+
return true;
}
wxTreeEvent nevent( command, GetId() );
nevent.m_item = m_current;
nevent.SetEventObject(this);
- nevent.SetPoint(pt);
+ nevent.SetPoint(CalcScrolledPosition(pt));
// by default the dragging is not supported, the user code must
// explicitly allow the event for it to take place
}
else if ( (event.LeftUp() || event.RightUp()) && m_isDragging )
{
+ ReleaseMouse();
+
// erase the highlighting
DrawDropEffect(m_dropTarget);
wxTreeEvent eventEndDrag(wxEVT_COMMAND_TREE_END_DRAG, GetId());
eventEndDrag.m_item = item;
- eventEndDrag.m_pointDrag = pt;
+ eventEndDrag.m_pointDrag = CalcScrolledPosition(pt);
eventEndDrag.SetEventObject(this);
(void)GetEventHandler()->ProcessEvent(eventEndDrag);
m_isDragging = false;
m_dropTarget = (wxGenericTreeItem *)NULL;
- ReleaseMouse();
-
SetCursor(m_oldCursor);
#if defined( __WXMSW__ ) || defined(__WXMAC__)
if ( m_imageListNormal )
{
m_imageListNormal->GetSize( image, image_w, image_h );
- image_w += 4;
+ image_w += MARGIN_BETWEEN_IMAGE_AND_TEXT;
}
}
{
wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen tree control?") );
- if ( !--m_freezeCount )
+ if ( --m_freezeCount == 0 )
{
Refresh();
}
}
-wxSize wxGenericTreeCtrl::DoGetBestSize() const
-{
- // something is better than nothing...
- // 100x80 is what the MSW version will get from the default
- // wxControl::DoGetBestSize
- return wxSize(100,80);
-}
-
-
// NOTE: If using the wxListBox visual attributes works everywhere then this can
// be removed, as well as the #else case below.
#define _USE_VISATTR 0