home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 October / Chip_1997-10_cd.bin / tema / sybase / powerj / hpp.z / WTREEVW.HPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  15KB  |  467 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. /*************************************************************************
  12.  *
  13.  * WTreeView -- Wrapper for the Windows 95 TreeView control.
  14.  *
  15.  *
  16.  *   Events:
  17.  *
  18.  *       BeginLabelEdit --
  19.  *
  20.  *       Click -- When an item is clicked.
  21.  *
  22.  *       Collapse -- When an item has collapsed.
  23.  *
  24.  *       DoubleClick -- When an item is double-clicked.
  25.  *
  26.  *       EndLabelEdit --
  27.  *
  28.  *       Expand -- When an item has expanded.
  29.  *
  30.  *       NeedItemText --
  31.  *
  32.  *       RightClick --
  33.  *
  34.  *       Select --
  35.  *
  36.  *       SelectChanging --
  37.  *
  38.  *************************************************************************/
  39.  
  40. #ifndef _WTREEVW_HPP_INCLUDED
  41. #define _WTREEVW_HPP_INCLUDED
  42.  
  43. #ifndef _WNO_PRAGMA_PUSH
  44. #pragma pack(push,8);
  45. #pragma enum int;
  46. #endif
  47.  
  48. #ifndef _WCONTROL_HPP_INCLUDED
  49. #  include "wcontrol.hpp"
  50. #endif
  51. #ifndef _WLLIST_HPP_INCLUDED
  52. #  include "wllist.hpp"
  53. #endif
  54. #ifndef _WIMGLIST_HPP_INCLUDED
  55. #  include "wimglist.hpp"
  56. #endif
  57.  
  58.  
  59. class WTreeView;
  60.  
  61. enum WTreeViewItemHandle { NULLHTVITEM  = 0,  LASTHTVITEM = LAST_32BIT };
  62.  
  63. typedef WBool WCMDEF (WObject::*WTreeViewCallback)( WTreeView * treeView, WTreeViewItemHandle item, void * userData );
  64.  
  65.  
  66. enum WTVImageListType {
  67.     WTVINormal, 
  68.     WTVIState
  69. };
  70.  
  71. enum WTreeViewCChildren {
  72.     WTVC_NO_CHILDREN = 0,
  73.     WTVC_HAS_CHILDREN,
  74.     WTVC_FIELD_UNUSED
  75. };
  76.  
  77. // flags
  78.  
  79. #define WTVIfText               0x0001
  80. #define WTVIfImage              0x0002
  81. #define WTVIfParam              0x0004
  82. #define WTVIfState              0x0008
  83. #define WTVIfHandle             0x0010
  84. #define WTVIfSelectedImage      0x0020
  85. #define WTVIfChildren           0x0040
  86.  
  87. // TreeView item state masks
  88.  
  89. #define WTVIsFocused            0x0001
  90. #define WTVIsSelected           0x0002
  91. #define WTVIsCut                0x0004
  92. #define WTVIsDropHilited        0x0008
  93. #define WTVIsBold               0x0010
  94. #define WTVIsExpanded           0x0020
  95. #define WTVIsExpandedOnce       0x0040
  96. #define WTVIsOverlayMask        0x0F00
  97. #define WTVIsStateImageMask     0xF000
  98. #define WTVIsUserMask           0xF000
  99.  
  100. struct WTreeViewEventData : public WEventData {
  101.     WTreeViewItemHandle         item;
  102.     WTreeViewItemHandle         oldItem;
  103. };
  104.  
  105. struct WTreeViewDispEventData : public WEventData {
  106.     WUInt                mask;
  107.     WTreeViewItemHandle  itemHandle;
  108.     WUInt                state;
  109.     WUInt                stateMask;
  110.     const WChar *        itemText;
  111.     WInt                 textMax;
  112.     WInt                 imageIndex;
  113.     WInt                 selectedImageIndex;
  114.     WInt                 children;
  115.     void *               userData;
  116. };
  117.  
  118. //
  119. // TreeView styles
  120. //
  121.  
  122. #define WTVSDefault           ((WStyle)0x50000007L) // WS_VISIBLE|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|WS_CHILD
  123. #define WTVSHasButtons        ((WStyle)0x00000001L) // TVS_HASBUTTONS
  124. #define WTVSHasLines          ((WStyle)0x00000002L) // TVS_HASLINES
  125. #define WTVSLinesAtRoot       ((WStyle)0x00000004L) // TVS_LINESATROOT
  126. #define WTVSEditLabels        ((WStyle)0x00000008L) // TVS_EDITLABELS
  127. #define WTVSDisabledDragDrop  ((WStyle)0x00000010L) // TVS_DISABLEDRAGDROP
  128. #define WTVSShowSelAlways     ((WStyle)0x00000020L) // TVS_SHOWSELALWAYS
  129.  
  130. #define WTVFocusedState      0x0001
  131. #define WTVSelectedState     0x0002
  132. #define WTVCutState          0x0004
  133. #define WTVDropHilitedState  0x0008
  134. #define WTVBoldState         0x0010
  135. #define WTVExpandedState     0x0020
  136. #define WTVExpandedOnceState 0x0040
  137.  
  138. #define WTVInsertRoot    ((WTreeViewItemHandle)0xFFFF0000L)
  139. #define WTVInsertFirst   ((WTreeViewItemHandle)0xFFFF0001L)
  140. #define WTVInsertLast    ((WTreeViewItemHandle)0xFFFF0002L)
  141. #define WTVInsertSort    ((WTreeViewItemHandle)0xFFFF0003L)
  142.  
  143. #define WTVDeleteRoot    WTVInsertRoot
  144.  
  145. #define WTVNIRoot               0x0000 
  146. #define WTVNINext               0x0001
  147. #define WTVNIPrevious           0x0002
  148. #define WTVNIParent             0x0003
  149. #define WTVNIChild              0x0004
  150. #define WTVNIFirstVisible       0x0005
  151. #define WTVNINextVisible        0x0006
  152. #define WTVNIPreviousVisible    0x0007
  153. #define WTVNIDropHilite         0x0008
  154. #define WTVNICaret              0x0009
  155. #define WTVNISelected           WTVNICaret
  156.  
  157. class WCMCLASS WTreeView : public WControl {
  158.     WDeclareSubclass( WTreeView, WControl );
  159.  
  160.     public:
  161.  
  162.         /**********************************************************
  163.          * Constructors and Destructors
  164.          *********************************************************/
  165.  
  166.         WTreeView();
  167.     
  168.         ~WTreeView();
  169.  
  170.         /**********************************************************
  171.          * Properties
  172.          *********************************************************/
  173.  
  174.         // Count -- Gets the number of items in the treeview.
  175.  
  176.         WULong GetCount() const;
  177.  
  178.         // ImageList
  179.         //
  180.         //     Get or set one of the imagelists used by the treeview.
  181.         //     All imagelists are shared, so it is up to the user
  182.         //     to destroy the imagelist after destroying the treeview.
  183.  
  184.         WImageList * GetImageList( WTVImageListType type=WTVINormal ) const;
  185.         WBool        SetImageList( WImageList * imageList,
  186.                                    WTVImageListType type=WTVINormal );
  187.  
  188.         // Selected
  189.         //
  190.         //     The selected item.
  191.  
  192.         WBool SetSelectedItem( WTreeViewItemHandle item );
  193.         WTreeViewItemHandle GetSelectedItem() const;
  194.  
  195.         /**********************************************************
  196.          * Methods
  197.          *********************************************************/
  198.  
  199.         // Add
  200.         //
  201.         //     Add a new item.  The label can be NULL.  The imageIndex
  202.         //     refers to the index into the imagelist.  The itemData is
  203.         //     per-item userdata.  If parent is NULL, item is added
  204.         //     at the root level.  If insertAfter is NULL, item is
  205.         //     added at end of sibling group -- other valid choices
  206.         //     are WTVInsertFirst, WTVInsertLast, WTVInsertSort.
  207.         //     Returns NULL if error occurs.
  208.  
  209.         WTreeViewItemHandle Add( const WChar *label,
  210.                                  WTreeViewItemHandle parent=NULLHTVITEM,
  211.                                  WLong imageIndex=0,
  212.                                  WLong selectedImageIndex=-1,
  213.                                  WShort stateImageIndex=0,
  214.                                  WTreeViewItemHandle insertAfter=NULLHTVITEM,
  215.                                  void *itemData=NULL,
  216.                                  WTreeViewCChildren cChildren=WTVC_FIELD_UNUSED );
  217.  
  218.         // CreateDragImage
  219.         //
  220.         //     Returns an imagelist that can be used for drawing purposes
  221.         //     during a drag operation.  Caller must delete the image
  222.         //     list when done.  
  223.  
  224.         WImageList CreateDragImage( WTreeViewItemHandle item ) const;
  225.  
  226.         // DeleteAll
  227.         //
  228.         //     Clear all the items in the treeview.
  229.  
  230.         WBool DeleteAll();
  231.  
  232.         // Delete
  233.         //
  234.         //     Delete an item in the treeview.  All descendents are
  235.         //     also deleted... If NULL is passed, nothing is deleted.
  236.         //     You can pass in WTVDeleteRoot to delete everything.
  237.  
  238.         WBool Delete( WTreeViewItemHandle item );
  239.  
  240.         // Retrieve
  241.         //
  242.         //     Retrieves an item by position or by state.  The startAt value
  243.         //     is where the search should start.
  244.         //
  245.         //     Returns the item, or NULL if not found.
  246.  
  247.         WTreeViewItemHandle Retrieve( const WPoint & pt ) const;
  248.         WTreeViewItemHandle Retrieve( WTreeViewItemHandle startAt=NULLHTVITEM,
  249.                                       WULong flags=WTVNISelected ) const;
  250.  
  251.         // Collapse
  252.         //
  253.         //     Collapse an item.
  254.  
  255.         WBool Collapse( WTreeViewItemHandle item, WBool deleteItems=FALSE );
  256.  
  257.         // Expand
  258.         //
  259.         //     Expand an item.
  260.  
  261.         WBool Expand( WTreeViewItemHandle item );
  262.  
  263.         // Toggle
  264.         //
  265.         //     Expand/collapse an item.
  266.  
  267.         WBool Toggle( WTreeViewItemHandle item );
  268.  
  269.         // EditLabel
  270.         //
  271.         //     Invoke label editing for an item.
  272.  
  273.         WWindowHandle EditLabel( WTreeViewItemHandle itemHandle);
  274.         
  275.         // EnsureIsFirstVisible
  276.         //
  277.         //     Ensures that an item is the first visible item
  278.         //     OF ITS INDENTATION LEVEL.
  279.  
  280.         WBool EnsureIsFirstVisible( WTreeViewItemHandle item );
  281.                 
  282.         // EnsureIsVisible
  283.         //
  284.         //     Ensure that an item is visible.
  285.  
  286.         WBool EnsureIsVisible( WTreeViewItemHandle item );
  287.  
  288.         /**********************************************************
  289.          * Item Methods
  290.          *********************************************************/
  291.  
  292.         // CollapseAll
  293.  
  294.         WBool CollapseAll( WTreeViewItemHandle item=NULLHTVITEM );
  295.  
  296.         // Enumerate
  297.  
  298.         WBool Enumerate( WObject * client, WTreeViewCallback callback,
  299.                          void * userData=NULL );
  300.  
  301.         // EnumerateChildren
  302.  
  303.         WBool EnumerateChildren( WTreeViewItemHandle item, WObject * client,
  304.                                  WTreeViewCallback callback,
  305.                                  void * userData=NULL );
  306.  
  307.         // ExpandAll
  308.  
  309.         WBool ExpandAll( WTreeViewItemHandle item=NULLHTVITEM,
  310.                          WBool expandSelf=TRUE );
  311.  
  312.         /**********************************************************
  313.          * Item Properties
  314.          *********************************************************/
  315.  
  316.         // Expanded
  317.  
  318.         WBool SetExpanded( WTreeViewItemHandle item, WBool expanded );
  319.         WBool GetExpanded( WTreeViewItemHandle item ) const;
  320.  
  321.         // ImageIndex
  322.  
  323.         WBool SetImageIndex( WTreeViewItemHandle item, WLong index );
  324.         WLong GetImageIndex( WTreeViewItemHandle item ) const;
  325.  
  326.         // Selected
  327.  
  328.         WBool SetSelected( WTreeViewItemHandle item, WBool selected=TRUE,
  329.                            WBool singleSelection=TRUE );
  330.         WBool GetSelected( WTreeViewItemHandle item ) const;
  331.  
  332.         // SelectedImageIndex
  333.  
  334.         WBool SetSelectedImageIndex( WTreeViewItemHandle item, WLong index );
  335.         WLong GetSelectedImageIndex( WTreeViewItemHandle item ) const;
  336.  
  337.         // StateImageIndex
  338.  
  339.         WBool SetStateImageIndex( WTreeViewItemHandle item, WShort index );
  340.         WShort GetStateImageIndex( WTreeViewItemHandle item ) const;
  341.  
  342.         // Rectangle
  343.         //
  344.         //     Get/set the rectangle where the control is placed
  345.         //     If an handle of Item is supplied, then the rectangle applies
  346.         //     to the position
  347.  
  348.         WRect GetRectangle( WTreeViewItemHandle item, WBool type=TRUE );
  349.  
  350.         // Text
  351.         //
  352.         //     Get or set the caption of an item.
  353.  
  354.         WString GetText( WTreeViewItemHandle item ) const;
  355.         WBool   GetText( WTreeViewItemHandle item, WString *str ) const;
  356.         WBool   SetText( WTreeViewItemHandle item, const WString & text );
  357.  
  358.         // UserData
  359.         //
  360.         //     Set/Get per-item data.
  361.  
  362.         WBool  SetUserData( WTreeViewItemHandle item, void *itemUserData );
  363.         void * GetUserData( WTreeViewItemHandle item ) const;
  364.  
  365.         // State
  366.         //
  367.         //     Set/Get treeview item state information
  368.  
  369.         WUInt GetState( WTreeViewItemHandle item,
  370.                         WUInt stateMask=WTVIsSelected );
  371.         WBool SetState( WTreeViewItemHandle item, WUInt state,
  372.                         WUInt stateMask=WTVIsSelected );
  373.  
  374.         /**********************************************************
  375.          * Event Handlers
  376.          *********************************************************/
  377.  
  378.         WBool DragEnterHandler( WTreeView *, WDragEventData * );
  379.  
  380.         WBool DragOverHandler( WTreeView *, WDragEventData * );
  381.  
  382.         WBool DragLeaveHandler( WTreeView *, WDragEventData * );
  383.  
  384.         WBool ContextMenuEventHandler( WTreeView *, WContextMenuEventData * );
  385.  
  386.         WBool RightClickEventHandler( WTreeView *, WTreeViewEventData * );
  387.  
  388.     protected:
  389.  
  390.         WBool DestroyEventHandler( WTreeView *, WEventData * );
  391.  
  392.         /**********************************************************
  393.          * Overrides
  394.          *********************************************************/
  395.  
  396.     public:
  397.  
  398.         virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
  399.  
  400.         virtual WBool SetParent( const WWindow * parent );
  401.  
  402.         virtual WBool WantsDragMessage( WULong whichButton ) const;
  403.         virtual WBool FillDragEventData( WDragEventData & event ) const;
  404.  
  405.         virtual WBool SetText( const WString & str );
  406.  
  407.         virtual WString GetText() const;
  408.  
  409.         virtual WRect GetRectangle( WBool absolute=FALSE ) const;
  410.  
  411.         virtual WBool SetUserData( void * userData );
  412.  
  413.         virtual void * GetUserData() const;
  414.  
  415.         virtual const WChar * InitializeClass();
  416.  
  417.         virtual WStyle GetDefaultStyle() const;
  418.  
  419.         virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
  420.                                    void * data=NULL );
  421.  
  422.         virtual WBool Destroy();
  423.  
  424.     protected:
  425.  
  426.         virtual WBool ProcessNotify( WUInt id, WNotify code,
  427.                                      WNotifyInfo info, WLong & returns );
  428.     
  429.         /**********************************************************
  430.          * Others
  431.          *********************************************************/
  432.  
  433.     private:
  434.  
  435.         WBool Expand( WTreeView * tv, WTreeViewItemHandle item,
  436.                       void * userData );
  437.  
  438.         WBool Collapse( WTreeView *tv, WTreeViewItemHandle item,
  439.                         void *userData );
  440.  
  441.         WBool StoreChildren( WTreeView *tv, WTreeViewItemHandle item,
  442.                              void *userData );
  443.  
  444.         WBool RestoreChildren( WTreeView *tv, WTreeViewItemHandle item,
  445.                                void *userData );
  446.  
  447.         /**********************************************************
  448.          * Data Members
  449.          *********************************************************/
  450.  
  451.     private:
  452.  
  453.         WImageList *            _normalImages;
  454.         WImageList *            _stateImages;
  455.         WULong                  _itemBufferLength;
  456.         WBool                   _inRightClick;
  457.         WTreeViewItemHandle     _storedHandle;
  458.         WTreeViewItemHandle     _dragSelectedHandle;
  459. };
  460.  
  461. #ifndef _WNO_PRAGMA_PUSH
  462. #pragma enum pop;
  463. #pragma pack(pop);
  464. #endif
  465.  
  466. #endif // _WTREEVW_HPP_INCLUDED
  467.