home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (c) 1992, 1993 by Barking Spider Software Inc. All rights reserved
-
- Filename...: bscore.h
-
- Version....: 1.0
-
- Language...: Microsoft C/C++ 7.0
-
- Model......: Small
-
- Environment: Microsoft Windows 3.1
-
- Description: This header file is probably the most important document of
- the tree/list control package. It describes the internal
- tree node/list item structure and the external tree node/
- list item definition structure used by the application to
- define a tree node or list item. It describes the
- notification messages that the tree/list control sends to
- the application as a result of an event. Error codes
- returned by the exported APIs are defined in this header
- plus a list of useful macros to aid the developer.
-
- IMPORTANT! The tree portion of this control was developed
- first therefore there are many references to tree, tree
- nodes, etc. If the developer is building a tree, then
- the jargon will be helpful. But if the developer is
- building a list then it will be helpful for the developer to
- relate references to trees with lists, tree nodes with list
- items, and ignore the concept of children and levels.
-
- Essentially, in the context of a listbox control, tree nodes
- are list items, and trees are lists.
-
- The header BSTREE.H contains the prototypes for all the
- exported APIs for the tree control.
-
- The header BSLIST.H contains the prototypes for all the
- exported APIs for the list control.
-
-
-
- BSCORE.H is divided into the following sections.
-
- Useful Macros
- Tree/List Class Name And Styles
- Tree/List Limits
- Version Macros
- Error Codes
- Tree/List Control Structures
- Tree/List Control Node States
- Tree/List Control Notification Messages
-
- Notes......:
-
- History....:
-
- Author.....: Peter J. Kaufman
-
- */
-
- /****************************************************************************/
- /* USEFUL MACROS */
- /****************************************************************************/
-
- #define MAKEP(sel,off) ((VOID FAR *)MAKELONG(off,sel))
- #define ALLOCP(dwBytes) ((VOID FAR*) MAKELONG (0, GlobalAlloc(GPTR,(DWORD)(dwBytes))))
- #define FREEP(lp) GlobalFree((HANDLE)HIWORD((DWORD)(lp)));
- #define FP_SEG(fp) (*((unsigned __far *)&(fp)+1))
- #define FP_OFF(fp) (*((unsigned __far *)&(fp)))
-
-
- /****************************************************************************/
- /* TREE/LIST CONTROL CLASS NAME AND STYLES */
- /****************************************************************************/
-
- #define TREE_CLASS "BST_Tree" // Same class name for a list.
- #define BST_TREE_STYLE 0x0001L
- #define BSL_LIST_STYLE 0x0002L
-
- /****************************************************************************/
- /* TREE/LIST LIMITS */
- /****************************************************************************/
-
- #define MAX_LEVELS 64 // Maximum tree indentation (tree only)
- #define MAX_NODES_IN_TREE 32767 // Maximum number of nodes in one tree and
- #define MAX_BITMAPS 3 // Maximum bitmap spaces per node per tree
- #define MAX_LINE_COLORS 3 // The number of different colors used in
- // line drawing.
-
-
- /****************************************************************************/
- /* VERSION MACROS */
- /****************************************************************************/
-
- // wVersion = (((wVersion|MINOR_TREE_VERSION) << 8) | MAJOR_TREE_VERSION);
- #define MAJOR_TREE_VERSION 0x0001
- #define MINOR_TREE_VERSION 0x0000
-
- /****************************************************************************/
- /* ERROR CODES */
- /****************************************************************************/
-
- #define BST_NO_ERROR 0
- #define BST_ERR_MEMORY_ALLOC_FAILED 1
- #define BST_ERR_LEVEL_LIMIT_EXCEEDED 2 // only MAX_LEVELS allowed
- #define BST_ERR_TOO_MANY_NODES 3 // only MAX_NODES_IN_TREE
- // allowed
- #define BST_ERR_ONLY_ONE_ROOT_ALLOWED 4
- #define BST_ERR_INVALID_PARENT_FOR_INSERTION 5
- #define BST_ERR_INVALID_PARENT_FOR_CHILDREN 6
- #define BSL_ERR_INVALID_INDEX 7
-
- /****************************************************************************/
- /* TREE/LIST CONTROL STRUCTURES */
- /****************************************************************************/
-
- /* TREE_NODE structure - Internal tree node or list item.
-
- typedef struct TreeNodeTag
- {
- LPSTR lpUserData;
- WORD wTextLength;
- LPSTR lpszText;
- WORD wState;
- WORD wIndex;
- BYTE chBitmapTypeBits;
- HBITMAP hBitmap[MAX_BITMAPS];
- HBITMAP hActiveBitmap[MAX_BITMAPS];
- }
- TREE_NODE;
-
- typedef TREE_NODE FAR* LP_TREE_NODE;
-
- NOTE: If in the the context of a listbox control, references to the word
- "tree" should be replaced with the word "list" and references to the
- phrase "tree node" should be replaced with the phrase "list item".
-
- The TREE_NODE structure is the description of a tree node belonging to a
- tree control. When a node is created by the tree control, at the request
- of the application, it allocates sizeof ( TREE_NODE ) worth of memory.
- The tree control then initializes the members of the newly created tree
- node by copying the contents of the application supplied TREE_NODE_DEF
- structure. The TREE_NODE_DEF structure describes the tree node to be
- created. After the newly created tree is initialized, the pointer to the
- tree node is then returned to the application to be used as a handle or
- identifier in future references. Since the memory for each tree node is NOT
- allocated by the application but by the tree control, the memory is
- read-only. If the application writes to any part of this structure or
- frees the memory of this structure, the integrity of the tree will be
- violated.
-
- Below are somes ways of retrieving the TREE_NODE pointer of a tree node in
- a tree.
-
- 1. Calling BST_GetActiveNode ( ) will return a TREE_NODE pointer of the
- currently highlighted node.
-
- 2. The application will receive a notification when an event takes
- place, such as a mouse click. The notification messages are:
- WM_BST_SELECT_NOTIF
- WM_BST_SELECT_NOTIF_DBLCLK
- When the application receives any of these notifications, the
- lParam points to the tree control owned SELECT_NOTIF structure. In
- this structure is a member called 'lpTreeNode' which points to the
- tree node (TREE_NODE) which was selected.
-
- 3. After a tree node addition or insertion via the exported APIs
- BST_AddChildrenToParent ( ) and
- BST_InsertSiblingNodes ( ), the pointer to the newly created tree
- node(s) can be accessed. First, to create new tree nodes, the
- application passes an array of TREE_NODE_DEF structures to the tree
- control via the above APIs to describe the desired tree nodes.
- After the new tree node(s) are created and before returning to the
- application, the tree control copies the pointers to the newly
- created tree node(s) into the 'lpTreeNode' members of the application
- supplied TREE_NODE_DEFs. On return, the application can read the
- pointers stored the 'lpTreeNode' members of the TREE_NODE_DEFS and
- copy them for future references to the newly created tree nodes.
-
- 4. Calling BST_ConvertPointToSelectNotif ( ) or the list equivalent,
- BSL_ConvertPointToSelectNotif ( ), will return a pointer to
- the tree node that lies under the coordinate supplied by the
- application.
-
- 5. The application will receive notification when the user holds the left
- button down and drags the mouse a distance greater than the average
- character width or height of the current font. The notification
- message is WM_BST_DODRAG. The lParam of this message points to the
- tree control owned SELECT_NOTIF structure in which it's 'lpTreeNode'
- member points to the node to be dragged.
-
- 5. BST_SetDeleteNodeCallBack ( ), or the list equivalent
- BSL_SetDeleteListItemCallBack ( ), allows the application to register
- a callback with the given tree control. The callback will be called
- everytime a node is deleted from the tree. Nodes can be deleted from
- the tree with three tree control export APIs or with the Windows API
- DestroyWindow ( ). The three tree control exported APIs are:
-
- BST_DeleteChildrenOfParent ( )
- BST_DeleteNode ( )
- BST_EraseTree ( )
-
- The list equivalents are:
-
- BSL_ResetList ( )
- BSL_DeleteListItem ( )
-
- 6. For the list control, the index of a list item can be converted to
- a TREE_NODE pointer by calling, BSL_GetListItem ( ) with the index
- value as it's argument.
- */
-
- typedef struct TreeNodeTag
- {
- LPSTR lpUserData; // This member stores a pointer or value
- // that is supplied by the application
- // via the TREE_NODE_DEF structure when the
- // application calls
- // BST_AddChildrenToParent ( ),
- // BST_InsertSiblingNodes ( ),
- // BSL_AddListItems ( ), or
- // BSL_InsertListItems ( ).
- // (The APIs add nodes to the tree.)
- // The tree control only stores this value or
- // pointer. If the item in lpUserData is a
- // pointer, then the tree control
- // will NOT free the memory that this pointer
- // points to when the node is destroyed. This
- // is the responsibility of the application.
- // A node can be destroyed by a call to
- // BST_DeleteChildrenOfParent ( ),
- // BST_DeleteNode ( ),
- // BST_EraseTree ( ),
- // BSL_ResetList ( ),
- // BSL_DeleteListItem ( ), or
- // when the tree control receives a WM_DESTROY
- // message. To aid in the managing of the data
- // stored in lpUserData, the tree control
- // provides a method of registering a callback
- // in which the tree control calls just
- // before the tree node is destroyed. The API
- // to register a callback with the tree control
- // is the exported API
- // BST_SetDeleteNodeCallBack ( ) for trees and
- // BSL_SetDeleteNodeCallBack ( ) for lists.
-
- WORD wTextLength; // This member states the number of characters
- // in which the tree control is to display as
- // text for this tree node. The source of the
- // node text is the lpszText member. Both the
- // wTextLength and lpszText member values are
- // copied from the corresponding TREE_NODE_DEF
- // structure used in defining the TREE_NODE.
- // Normally, the application does a
- // lstrlen ( ) on lpszText and assigns the
- // result to wTextLength. But there may be
- // cases that the string pointed to by
- // lpszText is just too long and fewer
- // characters are required.
-
- // There is a special attribute of wTextLength
- // in which the most significant bit or the
- // sign bit acts as a flag. Depending
- // on how this bit is set there are
- // two ways to handle text in a tree node.
- // In both cases, the application passes
- // a long pointer to the text via the lpszText
- // member of TREE_NODE_DEF structure. The
- // two methods are:
-
- // 1) If the sign bit of wTextLength
- // (0x8000) is set to 1, then the pointer
- // in lpszText points to memory owned by
- // the application and is guaranteed not to
- // change (deleted or moved).
- // This signals the tree control to just
- // copy the pointer in lpszText of the the
- // TREE_NODE_DEF structure to the TREE_NODE
- // structure. The tree control will NOT
- // worry about allocating, copying, and
- // freeing the memory pointed to be lpszText.
- // The pointer is used "as is", to display
- // wTextLength worth of the characters pointed
- // to by lpszText.
-
- // 2) If the sign bit of
- // wTextLength is set to 0, then the tree
- // control allocates wTextLength + 1 worth of
- // memory. The tree control then copies
- // wTextLength worth of characters from the
- // string pointed to by the lpszText member
- // of the TREE_NODE_DEF to the memory pointed
- // to by the lpszText member of the newly
- // created TREE_NODE. This will be the text
- // displayed by the tree control. When the
- // node is to be deleted, the tree control
- // will free the memory pointed to by lpszText
- // in the TREE_NODE since it belongs to the
- // tree control.
-
- // The 1) method is usually
- // used with static databases and the 2)
- // method is used with real-time systems. And
- // of course, both methods can be intermixed.
- // The obvious advantage of using method 1)
- // is the faster performance and use of
- // less memory since the application already
- // has memory allocated.
-
- // NOTE: If the low 15 bits of wTextLength
- // are set to 0 then lpszText is set to NULL
- // by the tree control, meaning there is no
- // text to display.
-
- LPSTR lpszText; // The application supplies a long pointer to
- // a string that it wishes to be displayed in
- // the tree control for a given node. The
- // application must specify the length of
- // string to be displayed in wTextLength.
- // Please refer to the wTextLength
- // documentation above for an understanding
- // of the different methods that can be
- // applied to the handling of lpszText.
-
- WORD wState; // The low byte of this word maintains the
- // state of the node. The node can be open
- // or closed. If BST_AddChildrenToParent() is
- // called by the application, the parent
- // node's wState member will be assigned a
- // value of NODE_OPENED in the low byte since
- // it now has children. If a tree node has no
- // children, probably from the fact it has
- // just been created or a call to
- // BST_DeleteChildrenOfParent ( ) has been
- // made, wState will be assigned a value of
- // NODE_CLOSED.
-
- // The high byte of this member is reserved.
- // Any modification of this byte will
- // invalidate the tree control.
-
- WORD wIndex; // For trees and lists, wIndex is an index
- // value used/ internally and should not be
- // modified in any way. If modified, the tree
- // will die!
-
- // If this control is used as a tree then
- // wIndex has no usefulness to the
- // application. If this control is used
- // as a list then this is a different
- // story. wIndex represents the position of
- // a list item in a list. This index value
- // is 0 for the first list item,
- // 1 for the second list item, 2 for the next,
- // and so on.
-
- BYTE chBitmapTypeBits; // Starting from the least significant bit,
- // each bit position corresponds to an
- // index into the hBitmap[] array starting at
- // 0. Only MAX_BITMAPS worth of bits have
- // significance.
- // These bits tell the tree control whether
- // it's corresponding hBitmap[] array member
- // is a bitmap handle or an icon
- // handle. For example, if the least
- // significant bit of chBitmapTypeBits
- // is set to 0 then the handle in
- // hBitmap[0] is a handle to a bitmap.
- // If this bit is set to 1 then
- // the handle in hBitmap[0] is a handle
- // to an icon.
- // This TREE_NODE member is copied from the
- // TREE_NODE_DEF structure when the tree node
- // is created.
-
- HBITMAP hBitmap[MAX_BITMAPS];// hBitmap[] is an array of handles to bitmaps
- // and icons to be displayed for the given
- // node, left to right, before the tree node
- // text.
-
- // The TREE_NODE member chBitmapTypeBits is
- // referenced by the tree control to determine
- // which handles are bitmap handles and which
- // are icon handles. chBitmapTypeBits and
- // hBitmap[] are initially defined by the
- // application via the TREE_NODE_DEF structure
- // when a tree node is created.
- // These items can be changed later by calling
- // the exported APIs,
- // BST_SetBitmap ( ),
- // BST_SetBitmapAndActiveBitmap ( ),
- // BST_SetIcon ( ),
- // BSL_SetBitmap ( ),
- // BSL_SetBitmapAndActiveBitmap ( ),
- // BSL_SetIcon ( ).
-
- // For documentation purposes icons and
- // bitmaps will be referred to as bitmaps for
- // the rest of this discussion.
-
- // A NULL value for any of the array
- // members will signal to the tree control
- // that NO bitmap has been specified for this
- // array member. All array members are
- // checked by the tree control for non-NULL
- // handles. Each non-NULL bitmap handle will
- // be used to display the bitmap in it's
- // corresponding bitmap position. Applications
- // must make sure that the array members NOT
- // containing a bitmap handle are set to NULL
- // in the TREE_NODE_DEF describing a tree
- // node. The tree control does NOT validate
- // tree handles!
-
- // Each handle in the hBitmap[] array
- // is associated with a bitmap space. A
- // bitmap is displayed inside the rectangular
- // region of it's corresponding bitmap space.
- // Bitmap spaces offer the application the
- // ability to fine tune each bitmap position
- // and to define each bitmap hit test area.
- // Hit testing is not performed on the bitmap
- // but on the bitmap space. The width and
- // height of a bitmap space are defined by
- // the exported APIs, BST_SetBitmapSpace ( )
- // and BSL_SetBitmapSpace ( ).
- // The dimensions of a bitmap space are
- // defined globally. The reason for this
- // is to keep column alignment of the
- // bitmaps. This is visually pleasing
- // and offers consistency with hit testing.
- // If the application does not call
- // BST_SetBitmapSpace ( ) or
- // BSL_SetBitmapSpace ( ) to define a
- // bitmap space width and height, then the
- // bitmap space default width and height are
- // both zero making the bitmap space
- // invisible. Even if a valid handle is
- // associated with this bitmap space, the
- // bitmap will not be displayed.
-
- // Some useful techniques and tips to utilize
- // bitmap spaces are listed below:
-
- // 1) Setting the bitmap space width greater
- // than the corresponding bitmap's width can
- // be used to set gaps between bitmaps.
-
- // 2) Setting the bitmap space height greater
- // than the corresponding bitmap's height
- // can be used to allocate space between tree
- // nodes.
-
- // 3) If the application needs to make a
- // bitmap and it's corresponding bitmap space
- // disappear but leave the bitmap handle
- // unchanged in the hBitmap[] array, the
- // application only needs to set the bitmap
- // space width or height to 0. The
- // tree control will collapse the bitmap
- // space out of existence.
- // Later, if the application wishes to show
- // the bitmap again, the application will need
- // to set the bitmap space width and height
- // to non zero values.
-
- // 4) If a hBitmap[] array element contains
- // a NULL bitmap handle but it's corresponding
- // bitmap space width and height are non zero
- // then the tree control will draw the space
- // with no bitmap in it. This is true only
- // if there is a bitmap that is displayable
- // to the right of the empty space. If there
- // is no bitmap that is displayable to the
- // right of the empty space, then the tree
- // node text will be left justified next
- // to the last displayed bitmap.
-
- HBITMAP hActiveBitmap[MAX_BITMAPS];
- // Handles of bitmaps/icons to be display when
- // the tree node is active (which means
- // highlighted).
-
- // For documentation purposes icons and
- // bitmaps will be referred to as bitmaps for
- // the rest of this discussion.
-
- // hActiveBitmap[] array elements need to be
- // assigned to a NULL by the application
- // if no bitmap handle is supplied. If a
- // hActiveBitmap[] array element is
- // NULL but the hBitmap[] index equivalent is
- // non-NULL then that hBitmap[] handle is used
- // to display the bitmap when the tree node
- // is selected. hActiveBitmap[] is only
- // referenced to display the bitmap if the
- // tree node is highlighted
- // and hActiveBitmap[] has a non-zero
- // corresponding hBitmap[] array member.
- // Besides the above conditions, the handling
- // of this array of bitmap handles
- // follow the same rules and conditions as
- // hBitmap[].
- }
- TREE_NODE;
-
- typedef TREE_NODE FAR* LP_TREE_NODE;
-
-
- /* TREE_NODE_DEF structure - Allows the app to describe a tree node or
- list item to the tree/list control.
-
- typedef struct TreeNodeDefTag
- {
- LP_TREE_NODE lpTreeNode;
- LPSTR lpUserData;
- WORD wTextLength;
- LPSTR lpszText;
- BYTE chBitmapTypeBits;
- HBITMAP hBitmap[MAX_BITMAPS];
- HBITMAP hActiveBitmap[MAX_BITMAPS];
- }
- TREE_NODE_DEF;
-
- typedef TREE_NODE_DEF FAR* LP_TREE_NODE_DEF;
-
- NOTE: If in the the context of a listbox control, references to the word
- "tree" should be replaced with the word "list" and references to the
- phrase "tree node" should be replaced with the phrase "list item".
-
- The TREE_NODE_DEF structure is the "node definition structure" that serves
- as a vehicle for the application to describe a node to the tree control
- in the case of a node add or node insertion. When the tree control receives
- the TREE_NODE_DEF structure, it creates a TREE_NODE with the information in
- the given TREE_NODE_DEF. The tree control then passes back the pointer to
- the newly created TREE_NODE via the 'lpTreeNode' member of the TREE_NODE_DEF
- structure.
-
- The detailed process of creating tree nodes is described below:
-
- 1) An application will allocate an array of TREE_NODE_DEF structures,
- each corresponding to a tree node to be created, all belonging to the
- same parent.
-
- 2) The application will initialize the TREE_NODE_DEF structures with each
- node's desired bitmap/icon handles, text, and user defined data.
-
- 3) The the application will make a call to either BST_AddChildrenToParent ( ) or
- BST_InsertSiblingNodes ( ) to create the new tree nodes. The list
- equivalents are BSL_AddListItems ( ) and BSL_InsertListItems ( ).
-
- NOTE: All the child tree nodes for the same parent node DO NOT have to be
- defined all at once. Additional calls to BST_AddChildrenToParent ( ) with
- the same parent tree node will result in the concatenation of the newly
- created child tree nodes to the parent's already existing children.
- This allows for a greater capability for multitasking under Windows.
-
- 4) The tree control will allocate TREE_NODE memory for the requested tree
- nodes.
-
- 5) The tree control will traverse the given TREE_NODE_DEF array, copying
- the TREE_NODE_DEF structure data to the corresponding TREE_NODE structure
- for each newly created node. During this traversal the tree control
- stores each new TREE_NODE pointer into the 'lpTreeNode' member of each
- of the TREE_NODE_DEF structures.
-
- 6) For trees, on return from BST_AddChildrenToParent ( ) or BST_InsertSiblingNodes ( ),
- the application usually retrieves the pointer value from the TREE_NODE_DEF
- member 'lpTreeNode', especially for the tree root, and stores it for
- future references to the tree node. Some of the tree control's
- exported APIs require it as an argument. In many cases the
- 'lpTreeNode' member of the TREE_NODE_DEF structure is ignored. The
- notification messages supply the pointer to the tree node involved in a
- event such as a mouse click, so why store it? Plus, when the tree is
- destroyed, if there is a need to access each tree node before they are
- deleted then a callback routine can be registered by the application via
- the tree control exported API BST_SetDeleteNodeCallBack ( ).
-
- For lists, once the list items are added via the calls,
- BSL_AddListItems ( ) and BSL_InsertListItems ( ), the TREE_NODE_DEF
- structures used to defined the list items do not need to be accessed.
- Since a list is linear, indexes are used instead of pointers. Given an
- index, the API BSL_GetListItem ( ) will return the TREE_NODE pointer so
- the application can access any vital data.
- */
-
-
- typedef struct TreeNodeDefTag
- {
- LP_TREE_NODE lpTreeNode; // This member will be assigned the pointer to
- // the tree node that the tree control created
- // as a result of the application passing this
- // structure to the tree control. In other
- // words, this member will be assigned a
- // TREE_NODE pointer as a result of the
- // application calling
- // BST_AddChildrenToParent ( )
- // BST_InsertSiblingNodes ( ),
- // BSL_AddListItems ( ),
- // or BSL_InsertListItems ( ). The
- // application will use this pointer value as
- // an ID in referencing the newly created
- // TREE_NODE. In the case of a list, the
- // index location of the list item in the
- // list will be used.
-
- WORD wUserDataSize; // If this member is 0 then the tree control
- // will copy the below pointer, lpUserData,
- // into the lpUserData member of the
- // newly created tree node. When the tree
- // node is deleted, it is the reponsibility
- // of the application to manage the memory or
- // data represented by the lpUserData member.
-
- // If this member is non zero then the
- // tree control will allocate wUserDataSize
- // worth of memory and use the below pointer,
- // lpUserData, to copy wUserDataSize worth
- // of memory pointed to by lpUserData, into
- // the newly allocated memory. Then the
- // pointer to the newly allocated memory will
- // be copied into the lpUserData member of
- // the new tree node. When the tree node
- // is destroyed, the tree control will free
- // the memory. It is the responsibility of
- // the tree control to manage the memory.
-
- LPSTR lpUserData; // lpUserData is an application defined
- // pointer or value that will be stored with
- // the newly created tree node. This member
- // will be copied from every TREE_NODE_DEF to
- // it's corresponding TREE_NODE. This is a
- // facility that the tree control provides to
- // allow the application to tie data to the
- // tree node.
- // Typically, the application will retrieve
- // this pointer when it receives a
- // WM_BST_SELECT_NOTIF or
- // WM_BST_SELECT_NOTIF_DBLCLK notification
- // from the tree control as a result of an
- // event.
- // If the above member, wUserDataSize, is zero
- // then the tree control only stores the data
- // in lpUserData. If lpUserData is a pointer
- // to dynamically allocated data then the tree
- // control only stores this pointer. It will
- // not free the memory that this pointer
- // points to when the node is destroyed by
- // a call to BST_DeleteChildrenOfParent ( ),
- // BST_DeleteNode ( ), BST_EraseTree ( ), or
- // when the tree control receives a WM_DESTROY
- // message. This is the responsibility of the
- // application.
-
- // To aid in the managing of the data in
- // lpUserData, the tree control provides a
- // way to register a callback in which the
- // tree control will call just before the
- // node is destroyed. The API to register a
- // callback is BST_SetDeleteNodeCallBack ( ).
-
- // If the above member, wUserDataSize, is non
- // zero then the tree control will allocate
- // wUserDataSize worth of memory and use
- // lpUserData to copy wUserDataSize worth
- // of memory into the newly allocated memory.
- // Then the pointer to the newly allocated
- // memory will be copied into the lpUserData
- // member of the new tree node. When the tree
- // node is destroyed, the tree control will
- // free the memory. It is the responsibility
- // of the tree control to manage the memory.
-
- WORD wTextLength;
- // This member states the number of characters
- // in which the tree control is to display as
- // text for this tree node. The source of the
- // node text is the lpszText member.
- // Normally, the application does a
- // lstrlen ( ) on lpszText and assigns the
- // result to wTextLength. But there may be
- // cases that the string pointed to by
- // lpszText is just too long and fewer
- // characters are required.
-
- // There is a special attribute of wTextLength
- // in which the most significant bit or the
- // sign bit acts as a flag. Depending
- // on how this bit is set there are
- // two ways to handle text in a tree node.
- // In both cases, the application passes
- // a long pointer to the text via the lpszText
- // member of TREE_NODE_DEF structure. The
- // two methods are:
-
- // 1) If the sign bit of wTextLength
- // (0x8000) is set to 1, then the pointer
- // in lpszText points to memory owned by
- // the application and is guaranteed not to
- // change (deleted or moved).
- // This signals the tree control to just
- // copy the pointer in lpszText of the the
- // TREE_NODE_DEF structure to the TREE_NODE
- // structure. The tree control will NOT
- // worry about allocating, copying, and
- // freeing the memory pointed to be lpszText.
- // The pointer is used "as is", to display
- // wTextLength worth of the characters pointed
- // to by lpszText.
-
- // 2) If the sign bit of
- // wTextLength is set to 0, then the tree
- // control allocates wTextLength + 1 worth of
- // memory. The tree control then copies
- // wTextLength worth of characters from the
- // string pointed to by the lpszText member
- // of the TREE_NODE_DEF to the memory pointed
- // to by the lpszText member of the newly
- // created TREE_NODE. This will be the text
- // displayed by the tree control. When the
- // node is to be deleted, the tree control
- // will free the memory pointed to by lpszText
- // in the TREE_NODE since it belongs to the
- // tree control.
-
- // The 1) method is usually
- // used with static databases and the 2)
- // method is used with real-time systems. And
- // of course, both methods can be intermixed.
- // The obvious advantage of using method 1)
- // is the faster performance and use of
- // less memory since the application already
- // has memory allocated.
-
- // NOTE: If the low 15 bits of wTextLength
- // are set to 0 then lpszText is set to NULL
- // by the tree control, meaning there is no
- // text to display.
- LPSTR lpszText;
- // The application supplies a long pointer to
- // a string that it wishes to be displayed in
- // the tree control for a given node. The
- // application must specify the length of
- // string to be displayed in wTextLength.
-
- // Please refer to the wTextLength
- // documentation above for an understanding
- // of the different methods that can be
- // applied to the handling of lpszText.
-
- BYTE chBitmapTypeBits;
- // Starting from the least significant bit,
- // each bit position corresponds to an
- // index into the hBitmap[] array starting at
- // 0. Only MAX_BITMAPS worth of bits have
- // significance.
- // These bits tell the tree control whether
- // it's corresponding hBitmap[] array member
- // is a bitmap handle or an icon
- // handle. For example, if the least
- // significant bit of chBitmapTypeBits
- // is set to 0 then the handle in
- // hBitmap[0] is a handle to a bitmap.
- // If this bit is set to 1 then
- // the handle in hBitmap[0] is a handle
- // to an icon.
-
- HBITMAP hBitmap[MAX_BITMAPS];// hBitmap[] is an array of handles to bitmaps
- // and icons to be displayed for the given
- // node, left to right, before the tree node
- // text.
-
- // The member chBitmapTypeBits is the
- // indicator of which handles are bitmap
- // handles and which are icon handles.
- // chBitmapTypeBits and hBitmap[] are
- // initially defined by the
- // application before a tree node is created.
- // These items can be changed later by calling
- // the exported APIs,
- // BST_SetBitmap ( ),
- // BST_SetBitmapAndActiveBitmap ( ),
- // BST_SetIcon ( ),
- // BSL_SetBitmap ( ),
- // BSL_SetBitmapAndActiveBitmap ( ), and
- // BSL_SetIcon ( ).
-
- // For documentation purposes icons and
- // bitmaps will be referred to as bitmaps for
- // the rest of this discussion.
-
- // A NULL value for any of the array
- // members will signal to the tree control
- // that NO bitmap has been specified for this
- // array member. All array members are
- // checked by the tree control for non-NULL
- // handles. Each non-NULL bitmap handle will
- // be used to display the bitmap in it's
- // corresponding bitmap position. Applications
- // must make sure that the array members NOT
- // containing a bitmap handle are set to NULL.
- // The tree control does NOT validate
- // tree handles!
-
- // Each handle in the hBitmap[] array
- // is associated with a bitmap space. A
- // bitmap is displayed inside the rectangular
- // region of it's corresponding bitmap space.
- // Bitmap spaces offer the application the
- // ability to fine tune each bitmap position
- // and to define each bitmap hit test area.
- // Hit testing is not performed on the bitmap
- // but the bitmap space. The width and
- // height of a bitmap space are defined by
- // the exported APIs, BST_SetBitmapSpace ( )
- // and BSL_SetBitmapSpace ( ).
- // The dimensions of a bitmap space are
- // defined globally. The reason for this
- // is to keep column alignment of the
- // bitmaps. This is visually pleasing
- // and offers consistency with hit testing.
- // If the application does not call
- // BST_SetBitmapSpace ( ) or
- // BSL_SetBitmapSpace ( ), to define a
- // bitmap space width and height, then the
- // bitmap space default width and height are
- // both zero making the bitmap space
- // invisible. Even if a valid handle is
- // associated with this bitmap space, the
- // bitmap will not be displayed.
-
- // Some useful techniques and tips to utilize
- // bitmap spaces are listed below:
-
- // 1) Setting the bitmap space width greater
- // than the corresponding bitmap's width can
- // be used to set gaps between bitmaps.
-
- // 2) Setting the bitmap space height greater
- // than the corresponding bitmap's height
- // can be used to allocate space between tree
- // nodes.
-
- // 3) If the application needs to make a
- // bitmap and it's corresponding bitmap space
- // disappear but leave the bitmap handle
- // unchanged in the hBitmap[] array, the
- // application only needs to set the bitmap
- // space width or height to 0. The
- // tree control will collapse the bitmap
- // space out of existance.
- // Later, if the application wishes to show
- // the bitmap again, the application will need
- // to set the bitmap space width and height
- // to non zero values.
-
- // 4) If a hBitmap[] array element contains
- // a NULL bitmap handle but it's corresponding
- // bitmap space width and height are non zero
- // then the tree control will draw the space
- // with no bitmap in it. This is true only
- // if there is a bitmap that is displayable
- // to the right of the empty space. If there
- // is no bitmap that is displayable to the
- // right of the empty space, then the tree
- // node text will be left justified next
- // to the last displayed bitmap.
-
- HBITMAP hActiveBitmap[MAX_BITMAPS];
- // Handles of bitmaps/icons to be display when
- // the tree node is active (which means
- // highlighted).
-
- // For documentation purposes icons and
- // bitmaps will be referred to as bitmaps for
- // the rest of this discussion.
-
- // Handles of bitmaps/icons to be display when
- // the tree node is active (which means
- // highlighted).
-
- // For documentation purposes icons and
- // bitmaps will be referred to as bitmaps for
- // the rest of this discussion.
-
- // hActiveBitmap[] array elements need to be
- // assigned to a NULL by the application
- // if no bitmap handle is supplied. If a
- // hActiveBitmap[] array element is
- // NULL but the hBitmap[] index equivalent is
- // non-NULL then that hBitmap[] handle is used
- // to display the bitmap when the tree node
- // is selected. hActiveBitmap[] is only
- // referenced to display the bitmap if the
- // tree node is highlighted
- // and hActiveBitmap[] has a non-zero
- // corresponding hBitmap[] array member.
- // Besides the above conditions, the handling
- // of this array of bitmap handles
- // follow the same rules and conditions as
- // hBitmap[].
- }
- TREE_NODE_DEF;
-
- typedef TREE_NODE_DEF FAR* LP_TREE_NODE_DEF;
-
-
-
-
- /* SELECT_NOTIF structure
-
- typedef struct SelectNotifTag
- {
- WORD wFlags;
- LP_TREE_NODE lpTreeNode;
- }
- SELECT_NOTIF;
-
- typedef SELECT_NOTIF FAR* LP_SELECT_NOTIF;
-
- NOTE: If in the the context of a listbox control, references to the word
- "tree" should be replaced with the word "list" and references to the
- phrase "tree node" should be replaced with the phrase "list item".
-
-
- A pointer to this structure is passed as the lParam of the
- node selection notification messages. These notification messages are:
-
- Notification Cause
-
- WM_BST_SELECT_NOTIF - Single click left mouse button while over
- tree node.
- - Select node with up or down arrow.
- - Select node with page up or page down key.
- - Select node with home or end key.
- - Select node with Ctrl Up or Ctrl Down.
-
- WM_BST_SELECT_NOTIF_DBLCLK - Double click left mouse button while over
- tree node. Sends WM_BST_SELECT_NOTIF on
- first click.
- - Hit carriage return while a node is selected.
- - '+' key if the currently selected node has no
- children.
- - '-' key if the currently selected node has
- children.
-
- WM_BST_DODRAG - Depress the left mouse button over a tree
- node and while continuing to hold down the
- left button, move the mouse a predetermined
- distance.
-
- When a notification is received the wParam is the window handle of the
- tree control and lParam is a pointer to a SELECT_NOTIF structure.
- The 'lpTreeNode' member of the SELECT_NOTIF structure is a pointer to the
- TREE_NODE that is involved in the notification. The 'wFlags' member
- reflects the state of tree node. The bit definitions for the 'wFlags'
- member are described below under the title TREE CONTROL NODE STATES..
-
- The SELECT_NOTIF memory is the property of the tree control and is NOT to be
- freed or modified by the application. Just return back to the tree control
- from the SendMessage (notification) and everything will be alright.
- */
-
- typedef struct SelectNotifTag
- {
- WORD wFlags; // The states of the node are discussed below.
- LP_TREE_NODE lpTreeNode; // Selected node from a single click or double
- // click.
- }
- SELECT_NOTIF;
-
- typedef SELECT_NOTIF FAR* LP_SELECT_NOTIF;
-
-
- /****************************************************************************/
- /* TREE/LIST CONTROL NODE STATES */
- /****************************************************************************/
-
- /*
- NOTE: If in the the context of a listbox control, references to the word
- "tree" should be replaced with the word "list" and references to the
- phrase "tree node" should be replaced with the phrase "list item".
-
- The 'wFlags' member of the notification structure reflects the tree node's
- state. This member tells:
- 1) the hardware (mouse or keyboard) cause of the click or the double
- click (if it is a click notification) plus the shift states,
- 2) whether the node is open or closed where open means that the node
- has children,
- 3) what part of the node did the click or drag occur (bitmap space,
- text, ...)
- When the app gets a WM_BST_SELECT_NOTIF_DBLCLK, WM_BST_SELECT_NOTIF, or
- WM_BST_DODRAG notification, the application can examine the 'wFlags' bits
- and determine the appropriate action.
- */
-
- #define NODE_CLOSED 0x0000
- #define NODE_OPENED 0x0001
- #define TEXT_HIT 0x0002
- #define SPACE_BEFORE_FIRST_BITMAP_HIT 0x0004
-
- // 0x0008
- // R E S E R V E D 0x0010
- // 0x0020
-
- #define KEYBOARD_HIT 0x0040
- #define SHIFT_KEY_DOWN 0x0080
- #define CTRL_KEY_DOWN 0x0100
- #define RBUTTON_DOWN 0x0200
- #define BITMAP0_HIT 0x8000
- #define BITMAP1_HIT 0x4000
- #define BITMAP2_HIT 0x2000
- //#define BITMAP3_HIT N O T 0x1000
- //#define BITMAP4_HIT A V A I L A B L E 0x0800
- //#define BITMAP5_HIT 0x0400
-
- /****************************************************************************/
- /* TREE/LIST CONTROL NOTIFICATION MESSAGES */
- /****************************************************************************/
- /*
- NOTE: If in the the context of a listbox control, references to the word
- "tree" should be replaced with the word "list" and references to the
- phrase "tree node" should be replaced with the phrase "list item".
-
- Notification Event
-
- WM_BST_SELECT_NOTIF - Single click left mouse button while over
- tree node.
- - Select node with up or down arrow.
- - Select node with page up or page down key.
- - Select node with home or end key.
- - Select node with Ctrl Up or Ctrl Down.
-
- WM_BST_SELECT_NOTIF_DBLCLK - Double click left mouse button while over
- tree node. Sends WM_BST_SELECT_NOTIF on
- first click.
- - Hit carriage return while a node is selected.
- - '+' key if the currently selected node has no
- children.
- - '-' key if the currently selected node has
- children.
-
- When a node is selected from the tree, typically by a mouse single or
- double click, the WM_BST_SELECT_NOTIF or WM_BST_SELECT_NOTIF_DBLCLK
- notification is sent to the parent window. wParam is the window handle of
- the tree control and lParam is a pointer to a SELECT_NOTIF structure.
- This structure is described above. This pointer is the property of the
- tree control so just use it to access the members. The 'lpTreeNode' member
- will point to the TREE_NODE that was selected and the 'wFlags' member will
- be set to the attributes listed above.
- */
-
- #define WM_BST_SELECT_NOTIF WM_USER+160 // single click
- #define WM_BST_SELECT_NOTIF_DBLCLK WM_USER+170 // double click
-
- /*
-
- When a tree control receives a WM_DROPFILES, a WM_BST_DROPFILES is sent to
- the parent with wParam and lParam the same values as the WM_DROPFILES.
- It is the responsibility of the application to process dropped information
- as if it had received the WM_DROPFILE directly.
- */
-
- #define WM_BST_DROPFILES WM_USER+180
-
- /*
-
- WM_BST_DODRAG - Depress the left mouse button over a tree
- node and while continuing to hold down the
- left button, move the mouse a predetermined
- distance.
-
- This notification message is sent to the parent window (application) of the
- tree control when the user clicks and holds the left mouse button over a
- tree node and while continuing to hold down the left button, moves the
- mouse a predetermined distance. This predetermined distance is
- the average character width of the current font for the x axis and the
- average character height of the current font for the y axis. In effect,
- this notification informs the application that the user is dragging a tree
- node and that the tree control is relinquishing control to the application
- so that the application will handle the drag. The application may use the
- OLE 2.0 drag/drop classes or process the drag similar to the the article in
- MSJ May/June 1992 Vol 7 No 3. wParam is the window handle of
- the tree control and lParam is a pointer to a SELECT_NOTIF structure.
- This structure is described above. This pointer is the property of the
- tree control so just use it to access the members. The 'lpTreeNode'
- member will point to the TREE_NODE that is being dragged and the 'wFlags'
- member will be set to the attributes listed above.
- */
-
- #define WM_BST_DODRAG WM_USER+190
-
- /*----------------------------------EOF-------------------------------------*/
-