home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 October
/
Chip_1997-10_cd.bin
/
tema
/
sybase
/
powerj
/
hpp.z
/
WTREEVW.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-16
|
15KB
|
467 lines
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Copyright (C) 1994, by WATCOM International Inc. All rights %
% reserved. No part of this software may be reproduced or %
% used in any form or by any means - graphic, electronic or %
% mechanical, including photocopying, recording, taping or %
% information storage and retrieval systems - except with the %
% written permission of WATCOM International Inc. %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*/
/*************************************************************************
*
* WTreeView -- Wrapper for the Windows 95 TreeView control.
*
*
* Events:
*
* BeginLabelEdit --
*
* Click -- When an item is clicked.
*
* Collapse -- When an item has collapsed.
*
* DoubleClick -- When an item is double-clicked.
*
* EndLabelEdit --
*
* Expand -- When an item has expanded.
*
* NeedItemText --
*
* RightClick --
*
* Select --
*
* SelectChanging --
*
*************************************************************************/
#ifndef _WTREEVW_HPP_INCLUDED
#define _WTREEVW_HPP_INCLUDED
#ifndef _WNO_PRAGMA_PUSH
#pragma pack(push,8);
#pragma enum int;
#endif
#ifndef _WCONTROL_HPP_INCLUDED
# include "wcontrol.hpp"
#endif
#ifndef _WLLIST_HPP_INCLUDED
# include "wllist.hpp"
#endif
#ifndef _WIMGLIST_HPP_INCLUDED
# include "wimglist.hpp"
#endif
class WTreeView;
enum WTreeViewItemHandle { NULLHTVITEM = 0, LASTHTVITEM = LAST_32BIT };
typedef WBool WCMDEF (WObject::*WTreeViewCallback)( WTreeView * treeView, WTreeViewItemHandle item, void * userData );
enum WTVImageListType {
WTVINormal,
WTVIState
};
enum WTreeViewCChildren {
WTVC_NO_CHILDREN = 0,
WTVC_HAS_CHILDREN,
WTVC_FIELD_UNUSED
};
// flags
#define WTVIfText 0x0001
#define WTVIfImage 0x0002
#define WTVIfParam 0x0004
#define WTVIfState 0x0008
#define WTVIfHandle 0x0010
#define WTVIfSelectedImage 0x0020
#define WTVIfChildren 0x0040
// TreeView item state masks
#define WTVIsFocused 0x0001
#define WTVIsSelected 0x0002
#define WTVIsCut 0x0004
#define WTVIsDropHilited 0x0008
#define WTVIsBold 0x0010
#define WTVIsExpanded 0x0020
#define WTVIsExpandedOnce 0x0040
#define WTVIsOverlayMask 0x0F00
#define WTVIsStateImageMask 0xF000
#define WTVIsUserMask 0xF000
struct WTreeViewEventData : public WEventData {
WTreeViewItemHandle item;
WTreeViewItemHandle oldItem;
};
struct WTreeViewDispEventData : public WEventData {
WUInt mask;
WTreeViewItemHandle itemHandle;
WUInt state;
WUInt stateMask;
const WChar * itemText;
WInt textMax;
WInt imageIndex;
WInt selectedImageIndex;
WInt children;
void * userData;
};
//
// TreeView styles
//
#define WTVSDefault ((WStyle)0x50000007L) // WS_VISIBLE|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|WS_CHILD
#define WTVSHasButtons ((WStyle)0x00000001L) // TVS_HASBUTTONS
#define WTVSHasLines ((WStyle)0x00000002L) // TVS_HASLINES
#define WTVSLinesAtRoot ((WStyle)0x00000004L) // TVS_LINESATROOT
#define WTVSEditLabels ((WStyle)0x00000008L) // TVS_EDITLABELS
#define WTVSDisabledDragDrop ((WStyle)0x00000010L) // TVS_DISABLEDRAGDROP
#define WTVSShowSelAlways ((WStyle)0x00000020L) // TVS_SHOWSELALWAYS
#define WTVFocusedState 0x0001
#define WTVSelectedState 0x0002
#define WTVCutState 0x0004
#define WTVDropHilitedState 0x0008
#define WTVBoldState 0x0010
#define WTVExpandedState 0x0020
#define WTVExpandedOnceState 0x0040
#define WTVInsertRoot ((WTreeViewItemHandle)0xFFFF0000L)
#define WTVInsertFirst ((WTreeViewItemHandle)0xFFFF0001L)
#define WTVInsertLast ((WTreeViewItemHandle)0xFFFF0002L)
#define WTVInsertSort ((WTreeViewItemHandle)0xFFFF0003L)
#define WTVDeleteRoot WTVInsertRoot
#define WTVNIRoot 0x0000
#define WTVNINext 0x0001
#define WTVNIPrevious 0x0002
#define WTVNIParent 0x0003
#define WTVNIChild 0x0004
#define WTVNIFirstVisible 0x0005
#define WTVNINextVisible 0x0006
#define WTVNIPreviousVisible 0x0007
#define WTVNIDropHilite 0x0008
#define WTVNICaret 0x0009
#define WTVNISelected WTVNICaret
class WCMCLASS WTreeView : public WControl {
WDeclareSubclass( WTreeView, WControl );
public:
/**********************************************************
* Constructors and Destructors
*********************************************************/
WTreeView();
~WTreeView();
/**********************************************************
* Properties
*********************************************************/
// Count -- Gets the number of items in the treeview.
WULong GetCount() const;
// ImageList
//
// Get or set one of the imagelists used by the treeview.
// All imagelists are shared, so it is up to the user
// to destroy the imagelist after destroying the treeview.
WImageList * GetImageList( WTVImageListType type=WTVINormal ) const;
WBool SetImageList( WImageList * imageList,
WTVImageListType type=WTVINormal );
// Selected
//
// The selected item.
WBool SetSelectedItem( WTreeViewItemHandle item );
WTreeViewItemHandle GetSelectedItem() const;
/**********************************************************
* Methods
*********************************************************/
// Add
//
// Add a new item. The label can be NULL. The imageIndex
// refers to the index into the imagelist. The itemData is
// per-item userdata. If parent is NULL, item is added
// at the root level. If insertAfter is NULL, item is
// added at end of sibling group -- other valid choices
// are WTVInsertFirst, WTVInsertLast, WTVInsertSort.
// Returns NULL if error occurs.
WTreeViewItemHandle Add( const WChar *label,
WTreeViewItemHandle parent=NULLHTVITEM,
WLong imageIndex=0,
WLong selectedImageIndex=-1,
WShort stateImageIndex=0,
WTreeViewItemHandle insertAfter=NULLHTVITEM,
void *itemData=NULL,
WTreeViewCChildren cChildren=WTVC_FIELD_UNUSED );
// CreateDragImage
//
// Returns an imagelist that can be used for drawing purposes
// during a drag operation. Caller must delete the image
// list when done.
WImageList CreateDragImage( WTreeViewItemHandle item ) const;
// DeleteAll
//
// Clear all the items in the treeview.
WBool DeleteAll();
// Delete
//
// Delete an item in the treeview. All descendents are
// also deleted... If NULL is passed, nothing is deleted.
// You can pass in WTVDeleteRoot to delete everything.
WBool Delete( WTreeViewItemHandle item );
// Retrieve
//
// Retrieves an item by position or by state. The startAt value
// is where the search should start.
//
// Returns the item, or NULL if not found.
WTreeViewItemHandle Retrieve( const WPoint & pt ) const;
WTreeViewItemHandle Retrieve( WTreeViewItemHandle startAt=NULLHTVITEM,
WULong flags=WTVNISelected ) const;
// Collapse
//
// Collapse an item.
WBool Collapse( WTreeViewItemHandle item, WBool deleteItems=FALSE );
// Expand
//
// Expand an item.
WBool Expand( WTreeViewItemHandle item );
// Toggle
//
// Expand/collapse an item.
WBool Toggle( WTreeViewItemHandle item );
// EditLabel
//
// Invoke label editing for an item.
WWindowHandle EditLabel( WTreeViewItemHandle itemHandle);
// EnsureIsFirstVisible
//
// Ensures that an item is the first visible item
// OF ITS INDENTATION LEVEL.
WBool EnsureIsFirstVisible( WTreeViewItemHandle item );
// EnsureIsVisible
//
// Ensure that an item is visible.
WBool EnsureIsVisible( WTreeViewItemHandle item );
/**********************************************************
* Item Methods
*********************************************************/
// CollapseAll
WBool CollapseAll( WTreeViewItemHandle item=NULLHTVITEM );
// Enumerate
WBool Enumerate( WObject * client, WTreeViewCallback callback,
void * userData=NULL );
// EnumerateChildren
WBool EnumerateChildren( WTreeViewItemHandle item, WObject * client,
WTreeViewCallback callback,
void * userData=NULL );
// ExpandAll
WBool ExpandAll( WTreeViewItemHandle item=NULLHTVITEM,
WBool expandSelf=TRUE );
/**********************************************************
* Item Properties
*********************************************************/
// Expanded
WBool SetExpanded( WTreeViewItemHandle item, WBool expanded );
WBool GetExpanded( WTreeViewItemHandle item ) const;
// ImageIndex
WBool SetImageIndex( WTreeViewItemHandle item, WLong index );
WLong GetImageIndex( WTreeViewItemHandle item ) const;
// Selected
WBool SetSelected( WTreeViewItemHandle item, WBool selected=TRUE,
WBool singleSelection=TRUE );
WBool GetSelected( WTreeViewItemHandle item ) const;
// SelectedImageIndex
WBool SetSelectedImageIndex( WTreeViewItemHandle item, WLong index );
WLong GetSelectedImageIndex( WTreeViewItemHandle item ) const;
// StateImageIndex
WBool SetStateImageIndex( WTreeViewItemHandle item, WShort index );
WShort GetStateImageIndex( WTreeViewItemHandle item ) const;
// Rectangle
//
// Get/set the rectangle where the control is placed
// If an handle of Item is supplied, then the rectangle applies
// to the position
WRect GetRectangle( WTreeViewItemHandle item, WBool type=TRUE );
// Text
//
// Get or set the caption of an item.
WString GetText( WTreeViewItemHandle item ) const;
WBool GetText( WTreeViewItemHandle item, WString *str ) const;
WBool SetText( WTreeViewItemHandle item, const WString & text );
// UserData
//
// Set/Get per-item data.
WBool SetUserData( WTreeViewItemHandle item, void *itemUserData );
void * GetUserData( WTreeViewItemHandle item ) const;
// State
//
// Set/Get treeview item state information
WUInt GetState( WTreeViewItemHandle item,
WUInt stateMask=WTVIsSelected );
WBool SetState( WTreeViewItemHandle item, WUInt state,
WUInt stateMask=WTVIsSelected );
/**********************************************************
* Event Handlers
*********************************************************/
WBool DragEnterHandler( WTreeView *, WDragEventData * );
WBool DragOverHandler( WTreeView *, WDragEventData * );
WBool DragLeaveHandler( WTreeView *, WDragEventData * );
WBool ContextMenuEventHandler( WTreeView *, WContextMenuEventData * );
WBool RightClickEventHandler( WTreeView *, WTreeViewEventData * );
protected:
WBool DestroyEventHandler( WTreeView *, WEventData * );
/**********************************************************
* Overrides
*********************************************************/
public:
virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
virtual WBool SetParent( const WWindow * parent );
virtual WBool WantsDragMessage( WULong whichButton ) const;
virtual WBool FillDragEventData( WDragEventData & event ) const;
virtual WBool SetText( const WString & str );
virtual WString GetText() const;
virtual WRect GetRectangle( WBool absolute=FALSE ) const;
virtual WBool SetUserData( void * userData );
virtual void * GetUserData() const;
virtual const WChar * InitializeClass();
virtual WStyle GetDefaultStyle() const;
virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
void * data=NULL );
virtual WBool Destroy();
protected:
virtual WBool ProcessNotify( WUInt id, WNotify code,
WNotifyInfo info, WLong & returns );
/**********************************************************
* Others
*********************************************************/
private:
WBool Expand( WTreeView * tv, WTreeViewItemHandle item,
void * userData );
WBool Collapse( WTreeView *tv, WTreeViewItemHandle item,
void *userData );
WBool StoreChildren( WTreeView *tv, WTreeViewItemHandle item,
void *userData );
WBool RestoreChildren( WTreeView *tv, WTreeViewItemHandle item,
void *userData );
/**********************************************************
* Data Members
*********************************************************/
private:
WImageList * _normalImages;
WImageList * _stateImages;
WULong _itemBufferLength;
WBool _inRightClick;
WTreeViewItemHandle _storedHandle;
WTreeViewItemHandle _dragSelectedHandle;
};
#ifndef _WNO_PRAGMA_PUSH
#pragma enum pop;
#pragma pack(pop);
#endif
#endif // _WTREEVW_HPP_INCLUDED