| Methods Index |
CScrollerSubclass: None
CTreeItems.
aFrame = GetFrame();Initializing a complex tree view with images, a tab set, and data source:
itsTree = new CTreeView(this, aFrame);
// Set up imagesHandling mouse clicks and focus events sent by the tree view:
itsFileImage = new CImage("file.bmp");
itsOpenDirectoryImage = new CImage("open.bmp");
itsClosedDirectoryImage = new CImage("closed.bmp");
itsCheckImage = new CImage("check.bmp");
// Set up tabs
itsTbSet = new CTabSet;
itsTabSet->AddTab(CTextTab(CTextTab::Left, (UNITS)180));
itsTabSet->AddTab(CTextTab(CTextTab::LeftImage, (UNITS)250));
itsTabSet->AddImage(itsCheckImage, "check");
// Set title string
itsTree->SetTitleString(
"Name" + CTabSet::TabString() +
"Size" + CTabSet::TabString() +
"checked"
);
itsTree->ITreeView(&aFileSource);
itsTree->SetGlue(ALLSTICKY);
itsTree->GetRoot()->SetString("..");
itsTree->GetRoot()->SetImage(itsFileImage);
itsTree->GetRoot()->SetCollapsedImage(itsClosedDirectoryImage);
itsTree->GetRoot()->SetExpandedImage(itsOpenDirectoryImage);
// This will use the images above to recalc
itsTree->GetRoot()->SetHeight(CTreeItem::kBestHeight);
itsTree->GetRoot()->SetTabSet(itsTabSet);
itsTree->GetRoot()->SortChildren(&itsSorter);
itsTree->GetRoot()->Expand();
itsTree->SetThumbtracking(TRUE);
itsTree->SetSelectionPolicy(CTreeView::SelectNone);
itsTree->SetExpansionPolicy(CTreeView::ExpandRestore);
void CTreeWin::DoCommand(long theCommand,void* theData)
{
// Handle tree events
if(theCommand == TreeEventCmd)
{
CTreeEvent* anEvent = (CTreeEvent*)theData;
CTreeItem* anItem = anEvent->GetTreeItem();
if(anItem != NULL)
{
switch(anEvent->GetType())
{
case CTreeEvent::MouseClick:
// If we hit the second tab, toggle the check mark
if(anEvent->GetTabHit() == kCheckTab)
{
anItem->SetString(
CTabSet::ToggleField(
anItem->GetString(),
kCheckTab,
"check",
""
)
);
anEvent->GetTree()->InvalidateItem(anItem);
}
break;
case CTreeEvent::FocusIn:
{
CStringRW aPath;
do
{
CStringRW aDirectory = CTabSet::GetField(
anItem->GetString(),
0
);
if(aPath.isNull())
aPath = aDirectory.strip(
RWCString::both);
else
aPath = aDirectory.strip(
RWCString::both) +
"/" + aPath;
} while((anItem = anItem->GetParent()) != NULL);
itsText->SetTitle(aPath);
}
break;
}
}
} else CWindow::DoCommand(theCommand,theData);
}
|
|
|
|
static const UNITS
|
kTopMargin;
| Top of view to root item |
static const UNITS
|
kLeftMargin;
| Left of view to root item |
static const UNITS
|
kTextMargin;
| Left of image to text |
|
|
|
SelectNone,
| No selection allowed |
SelectOne,
| Only one at a time |
SelectMany
| General selection |
Used as constants to the methods
SetSelectionPolicy() and GetSelectionPolicy(). The selection policy controls how the user may select tree items with the mouse.
|
|
|
ExpandOne
| Only expand one node |
ExpandAll
| Expand all subnodes also |
ExpandRestore
| Expand subnodes that were expanded |
Used as constants to the methods
SetExpansionPolicy() and GetExpansionPolicy(). The expansion policy controls what the tree view does when expanding or collapsing a node. ExpandOne expands only the current node, leaving all of its children collapsed. ExpandAll expands the current node and all of its children. ExpandRestore expands the current node and all of the children that where expanded when the current node was last collapsed by the user. Note that for ExpandRestore to work properly on a node, you must set the policy before the node is collapsed.
|
|
|
StyleOrthogonal,
| Squared connections |
StyleSlant,
| Slanted branches |
StyleNone
| No tree lines drawn |
Used as constants to the methods
SetTreeStyle() and GetTreeStyle(). The tree view uses the current tree style to determine whether to draw the skeleton lines between nodes and whether the lines should be square or skewed. CTreView uses StyleOrthogonal by default.
CTreeView(CSubview *theEnclosure, const CRect& theRegion);
virtual ~CTreeView(void);
BOOLEAN ITreeView(
const CTreeSource* theSource = NULL,
COLOR theColor = COLOR_BLACK,
const CFont& theFont = CFont::GetBestCtlFont(),
UNITS theHeight = CTreeItem::kBestHeight,
UNITS theIndent = CTreeItem::kBestIndent,
const CImage* theImage = NULL,
const CImage* theCollapsedImage = NULL,
const CImage* theExpandedImage = NULL,
const CTabSet* theTabSet = NULL,
BOOLEAN hasHorizontalScrollBar = TRUE,
BOOLEAN hasVerticalScrollBar = TRUE,
BOOLEAN isThumbTracking = FALSE,
UNITS theLineIncrement = 10,
UNITS thePageIncrement = 50,
BOOLEAN isVisible = TRUE,
GLUETYPE theGlue = NULLSTICKY);
theSource provides data to a dynamic tree.
theColor sets the text color of the root node and therefore the default color of all items. Equivalent to calling GetRoot()->SetColor(...).
theFont sets the text font of the root node and therefore the default font of all items. Equivalent to calling GetRoot()->SetFont(...).
theHeight sets the height of the root node and therefore the default height of all items. Equivalent to calling GetRoot()->SetHeight(...).
theIndent sets the indentation of the root node's children and therefore the default indentation of all children. This is equivalent to calling GetRoot()->SetIndent(...).
theImage sets the terminal image of the root node and therefore the terminal image of all items. Equivalent to calling GetRoot()->SetImage(...). The tree view uses the terminal image, if any, to display a picture to the left of terminal items (items that are not nodes).
theCollapsedImage sets the collapsed image of the root node and therefore the collapsed image of all items. Equivalent to calling GetRoot()->SetCollapsedImage(...). The tree view uses the collapsed image, if any, to display a picture to the left of collapsed node items.
theExpandedImage sets the expanded image of the root node and therefore the expanded image of all items. Equivalent to calling GetRoot()->SetExpandedImage(...). The tree view uses the expanded image, if any, to display a picture to the left of expanded node items.
theTabSet sets the tab set of the root node and therefore the tab set of all items. Equivalent to calling GetRoot()->SetTabSet(...). The tree view uses an item's tab set to justify fields within tabbed text and to imbed images within an item.
hasHorizontalScrollBar determines whether or not the tree view will have a horizontal scroll bar. Also see CScroller::IScroller.
hasVerticalScrollBar determines whether or not the tree view will have a vertical scroll bar. Also see CScroller::IScroller.
isThumbTracking is TRUE, the tree view will scroll its contents while the user drags the thumb of a scrollbar. If FALSE, the view scrolls after the user releases the mouse button. Also see CScroller::IScroller.
theLineIncrement provides the number of pixels to scroll in response to a line up or down click on the scroll bar. Note that the tree view will always attempt to display whole items at the top of the view and adjust the line increment to equal the height of the top item. Also see CScroller::IScroller.
thePageIncrement provides the number of pixels to scroll in response to a page up or down click on the scroll bar. Also see CScroller::IScroller.
isVisible determines whether the tree view is intially visible. Also see CView::IViewtheGlue sets the glue type between the tree view and its enclosure. Also see CView::IViewvirtual void Key(const CKey& theKey);
virtual CRect GetInitialFrame(CSubview* theEnclosure,
const CRect& theRegion,
BOOLEAN hasHorizontalScrollBar,
BOOLEAN hasVerticalScrollBar) const;
hasHorizontalScrollBar and hasVerticalScrollBar.
virtual CRect GetInnerFrame() const;
virtual CRect GetClippedFrame() const;
void SetDeleteUserData(BOOLEAN theDelete); BOOLEAN GetDeleteUserData() const;
TRUE if you want the tree to delete user data. The default is FALSE. For user data information see CTreeItem.
virtual void Draw(const CRect& theClippingRegion);
virtual void VScroll(SCROLL_CONTROL theEventType, UNITS thePos);
virtual void HScroll(SCROLL_CONTROL theEventType, UNITS thePos);
virtual void ScrollViews(const CPoint& theNewOrigin);
virtual void MakeItemVisible(const CTreeItem* theItem);
CTreeNodeItem* GetRoot();
const CTreeNodeItem* GetRoot() const;
virtual void SetTitleString(
const CStringRW& theTitle,
COLOR theColor = COLOR_BLACK,
const CFont& theFont = STDFont);
CView::Invalidate() to redraw the tree view.
virtual CStringRW GetTitleString() const;
virtual const CFont& GetTitleFont() const;
virtual CRect GetTitleRect() const;
virtual CRect ItemToRect(
const CTreeItem* theItem,
BOOLEAN theRecurse = FALSE) const;
theItem in global coordinates. If theRecurse is TRUE, this rectangle includes theItem and all of its children.
virtual CTreeItem* PointToItem(const CPoint& thePoint);
NULL if none, that contains thePoint in global coordinates.
virtual const CTreeItem* PointToItem(const CPoint& thePoint) const;
NULL if none, that contains thePoint in global coordinates.
virtual void InvalidateItem(
const CTreeItem* theItem,
BOOLEAN theRecurse = FALSE);
theItem and, if theRecurse is TRUE, all of its children.
virtual const CTreeItem* TopItem() const;
virtual CTreeItem* TopItem();
virtual const RWOrdered& GetSelection() const;
CTreeItem pointers representing all of the tree items currently selected.
virtual void SetSelection(
const RWOrdered& theSelection,
BOOLEAN theUpdate = FALSE);
theSelection is an ordered collection of CTreeItem pointers representing all of the tree items in the selection. Each element of theSelection must be a pointer to a valid CTreeItem. If theUpdate is TRUE, the tree view redraws the affected items.
virtual void AddToSelection(CTreeItem* theItem,
BOOLEAN theUpdate = FALSE);
theItem to the list of selected tree items. If theUpdate is TRUE, the tree view redraws the item.
virtual void RemoveFromSelection(CTreeItem* theItem,
BOOLEAN theUpdate = FALSE);
theUpdate if TRUE, the tree view redraws the item.
virtual void ClearSelection(BOOLEAN theUpdate = FALSE);
theUpdate is TRUE, the tree view redraws the affected area.
virtual BOOLEAN SelectionContains(const CTreeItem* theItem);
TRUE if the list of selected items contains theItem.
virtual void InvalidateSelection();
virtual void SetFocusItem(CTreeItem* theItem,
BOOLEAN theUpdate = FALSE);
theItem to have keyboard focus. If theUpdate is TRUE, the tree view redraws the item.
virtual const CTreeItem* GetFocusItem() const;
NULL if no tree item currently has focus.
virtual CTreeItem* GetFocusItem();
NULL if no tree item currently has focus.
virtual void SetSelectionPolicy(SelectionPolicy thePolicy);
SelectionPolicy under Enums.
virtual SelectionPolicy GetSelectionPolicy() const;
SelectionPolicy under Enums.
virtual void SetExpansionPolicy(ExpansionPolicy thePolicy);
ExpansionPolicy under Enums.
virtual ExpansionPolicy GetExpansionPolicy() const;
ExpansionPolicy under Enums.
virtual void SetTreeStyle(TreeStyle theStyle);
TreeStyle under Enums.
virtual TreeStyle GetTreeStyle() const;
TreeStyle under Enums.
virtual void SetDrawRoot(BOOLEAN theDrawRoot);
theDrawRoot is TRUE, draw the root item, otherwise starts drawing with the children of the root item. When using the tree view as a list, you should call SetDrawRoot(FALSE);.
virtual BOOLEAN GetDrawRoot() const;
TRUE if the tree view draws the root node.
virtual const CTreeAttributes* GetAttributes(
COLOR theColor,
const CFont& theFont,
UNITS theHeight,
UNITS theIndent,
const CImage* theImage,
const CImage* theCollapsedImage,
const CImage* theExpandedImage,
const CTabSet* theTabSet,
const CTreeSource* theSource);
CTreeAttributes (internal object), possibly shared, with the given attributes.
virtual CTreeItem* CreateTerminal(
CTreeNodeItem* theParent,
const CTreeAttributes* theAttributes);
virtual CTreeNodeItem* CreateNode(
CTreeNodeItem* theParent,
const CTreeAttributes* theAttributes);
virtual CRect DrawTitle(const CRect& theClippingRegion);
virtual void DrawItem(
const CTreeItem* theItem,
CDrawingContext& theContext,
const CRect& theClippingRegion);
virtual void DrawSingleItem(
const CTreeItem* theItem,
CDrawingContext& theContext,
const CRect& theClippingRegion);
virtual CPoint DrawImagePart(
const CPoint& theStart,
const CTreeItem* theItem,
CDrawingContext& theContext,
const CRect& theClippingRegion);
virtual void DrawSelectionPart(
const CPoint& theStart,
UNITS theTextLength,
const CTreeItem* theItem,
const CRect& theClippingRegion);
virtual void DrawTreePart(
const CTreeItem* theItem,
const CRect& theClippingRegion);
virtual CTreeMouseHandler* CreateMouseHandler();
CreateMouseHandler() instantiates a CTreeMouseHandler.
CTreeView(const CTreeView& theTree) : CScroller(theTree); CTreeView& operator=(const CTreeView& theTree);