[Classes] [Prev] [Next] [Methods]

CTreeView

Methods Index

Heritage
Description
Usage
Public Data Members
Enums
Protected Data Members
Public Methods
Constructor, Destructor, and Initializer Methods
View Methods
Root Node Methods.
Title Bar Methods
Transformation Methods
Selection and Focus Methods
Factory Methods
Protected Methods

CTreeView


Heritage

Superclass: CScroller

Subclass: None


Description

Provides a standard tree view using CTreeItems.


Usage

Creating a tree view that fills its enclosure:

	aFrame = GetFrame();
itsTree = new CTreeView(this, aFrame);
Initializing a complex tree view with images, a tab set, and data source:

	// Set up images
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);
Handling mouse clicks and focus events sent by the tree view:

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);
}

Public Data Members

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


Enums

SelectionPolicy

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.

ExpansionPolicy

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.

TreeStyle

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.

Protected Data Members

CStringRW itsTitle; NULL if no title
barCOLOR itsTitleColor; Color of text in the tree view title
CFont itsTitleFont; Font for text in the tree view title bar
BOOLEAN itsDeleteUserData; Manages user data?
BOOLEAN itsDrawRoot; Draws the root node?
TreeStyle itsStyle; How to draw joining lines
SelectionPolicy itsPolicy; Selection policy
ExpansionPolicy itsExpansionPolicy; Expansion policy
CTreeMouseHandler* itsMouseHandler; (used by mouse handler)
CTreeNodeItem* itsRoot; The root tree item
RWOrdered itsAttributeList; Of CTreeAttributes
RWOrdered itsSelection; Of CTreeItems
CTreeItem* itsFocusItem; Tree item with the current keyboard focus
UNITS itsLine; Current v while drawing items
UNITS itsIndent; Current h while drawing items
UNITS itsMaxItemLength; Max item length encountered while drawing
UNITS TitleHeight() const; The height of the title bar of the tree view
BOOLEAN itsIsScrolling; Flag to adjust behavior of GetClippedRect()


Public Methods

Constructor, Destructor, and Initializer Methods

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);

View Methods

virtual void Key(const CKey& theKey);
virtual CRect GetInitialFrame(CSubview* theEnclosure,
const CRect& theRegion,
BOOLEAN hasHorizontalScrollBar,
BOOLEAN hasVerticalScrollBar) const;
virtual CRect GetInnerFrame() const;
virtual CRect GetClippedFrame() const;
void SetDeleteUserData(BOOLEAN theDelete);
BOOLEAN GetDeleteUserData() const;
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);

Root Node Methods.

CTreeNodeItem* GetRoot();
const CTreeNodeItem* GetRoot() const;

Title Bar Methods

virtual void SetTitleString(
const CStringRW& theTitle,
COLOR theColor = COLOR_BLACK,
const CFont& theFont = STDFont);
virtual CStringRW GetTitleString() const;
virtual const CFont& GetTitleFont() const;
virtual CRect GetTitleRect() const;

Transformation Methods

virtual CRect  ItemToRect(
const CTreeItem* theItem,
BOOLEAN theRecurse = FALSE) const;
virtual CTreeItem* PointToItem(const CPoint& thePoint);
virtual const CTreeItem* PointToItem(const CPoint& thePoint) const;
virtual void  InvalidateItem(
const CTreeItem* theItem,
BOOLEAN theRecurse = FALSE);
virtual const CTreeItem* TopItem() const;
virtual CTreeItem* TopItem();

Selection and Focus Methods

virtual const RWOrdered& GetSelection() const;
virtual void  SetSelection(
const RWOrdered& theSelection,
BOOLEAN theUpdate = FALSE);
virtual void  AddToSelection(CTreeItem* theItem,   
BOOLEAN theUpdate = FALSE);
virtual void  RemoveFromSelection(CTreeItem* theItem,  
BOOLEAN theUpdate = FALSE);
virtual void  ClearSelection(BOOLEAN theUpdate = FALSE);
virtual BOOLEAN  SelectionContains(const CTreeItem* theItem);
virtual void  InvalidateSelection();
virtual void  SetFocusItem(CTreeItem* theItem,   
BOOLEAN theUpdate = FALSE);
virtual const CTreeItem* GetFocusItem() const;
virtual CTreeItem* GetFocusItem();
virtual void  SetSelectionPolicy(SelectionPolicy thePolicy);
virtual SelectionPolicy GetSelectionPolicy() const;
virtual void  SetExpansionPolicy(ExpansionPolicy thePolicy);
virtual ExpansionPolicy GetExpansionPolicy() const;
virtual void  SetTreeStyle(TreeStyle theStyle);
virtual TreeStyle GetTreeStyle() const;
virtual void  SetDrawRoot(BOOLEAN theDrawRoot);
virtual BOOLEAN  GetDrawRoot() const;

Factory Methods

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);
virtual CTreeItem* CreateTerminal(
CTreeNodeItem* theParent,
const CTreeAttributes* theAttributes);
virtual CTreeNodeItem* CreateNode(
CTreeNodeItem* theParent,
const CTreeAttributes* theAttributes);

Protected Methods

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();
CTreeView(const CTreeView& theTree) : CScroller(theTree);
CTreeView& operator=(const CTreeView& theTree);



[Classes] [Prev] [Next] [Methods]

support@xvt.com


Visit our online help desk for tech support

Copyright © 2009, Providence Software Solutions Inc. All rights reserved.