treeview.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 8k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "listview.h"   // for some helper routines and border metrics
  2. #define MAGIC_MININDENT 5
  3. #define MAGIC_INDENT    3
  4. // flags for TV_DrawItem
  5. #define TVDI_NOIMAGE 0x0001 // don't draw image
  6. #define TVDI_NOTREE 0x0002 // don't draw indent, lines, +/-
  7. #define TVDI_TRANSTEXT 0x0004 // draw text transparently in black
  8. #define TVDI_ERASE 0x0008 // erase while drawing
  9. #define TVDI_GRAYTEXT   0x0010  // text is gray (disabled item)
  10. #define TVDI_GRAYCTL    0x0020  // text and background is gray (disabled control)
  11. typedef struct _TREE {
  12.     HWND        hwnd;           // tree window
  13.     HWND hwndParent; // parent window to send notifys to
  14.     DWORD style; // style bits
  15.     // Flags
  16.     BOOL        fHorz:1;        // horizontal scrollbar present
  17.     BOOL        fVert:1;        // vertical scrollbar present
  18.     BOOL        fFocus:1;       // currently has focus
  19.     BOOL        fNameEditPending:1;  // Is a name edit pending?
  20.     BOOL        fRedraw:1;      // should redraw?
  21.     BOOL        fScrollWait:1;  // are we waiting for a dblclk to not scroll?
  22.     BOOL fCreatedFont:1; // we created our font
  23.     BOOL        fNoDismissEdit:1; // don't dismiss in-place edit control
  24.     BOOL        fIndentSet:1;    // is the parent managing the indent size?
  25.     // Handles
  26.     HTREEITEM   hRoot;          // tree root item
  27.     HTREEITEM   hCaret;         // item with focus caret
  28.     HTREEITEM   hDropTarget;    // item which is the drop target
  29.     HTREEITEM   htiEdit;        // The item that is being edited.
  30.     HIMAGELIST  hImageList;     // image list
  31.     HIMAGELIST  himlState;      // state image list
  32.     int         iPuntChar;      // number of wm_char's to punt
  33.     int         cxState;       
  34.     int         cyState;
  35.     HBRUSH      hbrBk;          // background brush
  36.     HFONT       hFont;          // tree font
  37.     HFONT       hFontBold;      // bold tree font 
  38.     HBITMAP     hStartBmp;      // initial DC mono bitmap
  39.     HBITMAP     hBmp;           // indent bitmaps in hdcBits
  40.     HDC         hdcBits;        // HDC for drawing indent bitmaps
  41.     HTREEITEM   hItemPainting;  // the guy we are currently painting
  42. #ifdef WIN32
  43.     HANDLE hheap; // heap for allocs for win32
  44. #endif
  45.     // Dimensions
  46.     SHORT       cxImage;        // image width
  47.     SHORT       cyImage;        // image height
  48.     SHORT       cyText;         // text height
  49.     SHORT       cyItem;         // item height
  50.     SHORT       cxIndent;       // indent width
  51.     SHORT       cxWnd;          // window width
  52.     SHORT       cyWnd;          // window height
  53.     // Scroll Positioners
  54.     WORD        cxMax;          // width of longest item
  55.     WORD        cFullVisible;   // number of items that CAN fully fit in window
  56.     SHORT       xPos;           // horizontal scrolled position
  57.     UINT        cShowing;       // number of showing (non-collapsed) items
  58.     UINT        cItems;         // total number of items
  59.     HTREEITEM   hTop;           // first visible item
  60.     // stuff for edit in place
  61.     HWND        hwndEdit;       // Edit window for name editing.
  62.     WNDPROC     pfnEditWndProc; // edit field subclass proc
  63. } TREE, NEAR *PTREE;
  64. #define TV_StateIndex(pitem) ((int)(((DWORD)((pitem)->state) >> 12) & 0xF))
  65. #define KIDS_COMPUTE 0    // use hKids to determine if a node has children
  66. #define KIDS_FORCE_YES 1    // force a node to have kids (ignore hKids)
  67. #define KIDS_FORCE_NO 2    // force a node to not have kids (ignore hKids)
  68. #define KIDS_CALLBACK 3    // callback to see if a node has kids
  69. // BUGBUG: OINK OINK
  70. typedef struct _TREEITEM {
  71.     HTREEITEM hParent; // allows us to walk back out of the tree
  72.     HTREEITEM hNext;   // next sibling
  73.     HTREEITEM hKids;   // first child
  74.     LPSTR     lpstr;     // item text, can be LPSTR_TEXTCALLBACK
  75.     WORD      state; // TVIS_ state flags
  76.     WORD      iImage;    // normal state image at iImage
  77.     WORD      iSelectedImage;  // selected state image
  78.     WORD      iWidth; // cached: width of text area (for hit test, drawing)
  79.     WORD      iShownIndex;     // cached: -1 if not visible, otherwise nth visible item
  80.     unsigned char iLevel;     // cached: level of item (indent)
  81.     unsigned char fKids; // KIDS_ values
  82.     LPARAM lParam;           // item data
  83. #ifdef DEBUG
  84. #define DEBUG_SIG   (('T' << 8) + 'I')
  85.     WORD dbg_sig;
  86. #endif
  87. } TREEITEM;
  88. #define ITEM_VISIBLE(hti) ((hti)->iShownIndex != (WORD)-1)
  89. // get the parent, avoiding the hidden root node
  90. #define VISIBLE_PARENT(hItem) (!(hItem)->iLevel ? NULL : (hItem)->hParent)
  91. // REVIEW: make this a function if the optimizer doesn't do well with this
  92. #define FULL_WIDTH(pTree, hItem)  (ITEM_OFFSET(pTree,hItem) + hItem->iWidth)
  93. int FAR PASCAL ITEM_OFFSET(PTREE pTree, HTREEITEM hItem);
  94. #ifdef DEBUG
  95. void NEAR   ValidateTreeItem(HTREEITEM hItem, BOOL bNullOk);
  96. #else
  97. #define ValidateTreeItem(hItem, bNullOk)
  98. #endif
  99. // in TVSCROLL.C
  100. BOOL      NEAR  TV_ScrollBarsAfterAdd       (PTREE, HTREEITEM);
  101. BOOL      NEAR  TV_ScrollBarsAfterRemove    (PTREE, HTREEITEM);
  102. BOOL      NEAR  TV_ScrollBarsAfterExpand    (PTREE, HTREEITEM);
  103. BOOL      NEAR  TV_ScrollBarsAfterCollapse  (PTREE, HTREEITEM);
  104. BOOL      NEAR  TV_ScrollBarsAfterSetWidth  (PTREE, HTREEITEM);
  105. BOOL      NEAR  TV_HorzScroll               (PTREE, UINT, UINT);
  106. BOOL      NEAR  TV_VertScroll               (PTREE, UINT, UINT);
  107. BOOL      NEAR  TV_SetLeft                  (PTREE, int);
  108. BOOL      NEAR  TV_SetTopItem               (PTREE, UINT);
  109. BOOL      NEAR  TV_CalcScrollBars           (PTREE);
  110. BOOL      NEAR  TV_ScrollIntoView           (PTREE, HTREEITEM);
  111. BOOL      NEAR  TV_ScrollVertIntoView       (PTREE, HTREEITEM);
  112. HTREEITEM NEAR  TV_GetShownIndexItem        (HTREEITEM, UINT);
  113. UINT      NEAR  TV_ScrollBelow              (PTREE, HTREEITEM, BOOL, BOOL);
  114. BOOL      NEAR  TV_SortChildren(PTREE, HTREEITEM, BOOL);
  115. BOOL      NEAR  TV_SortChildrenCB(PTREE, LPTV_SORTCB, BOOL);
  116. void   NEAR  TV_ComputeItemWidth(PTREE pTree, HTREEITEM hItem, HDC hdc);
  117. // in TVPAINT.C
  118. void      NEAR TV_GetBackgroundBrush        (PTREE pTree, HDC hdc);
  119. void      NEAR  TV_UpdateTreeWindow         (PTREE, BOOL);
  120. void      NEAR  TV_ChangeColors             (PTREE);
  121. void      NEAR  TV_CreateIndentBmps         (PTREE);
  122. void      NEAR  TV_Paint                    (PTREE, HDC);
  123. HIMAGELIST NEAR TV_CreateDragImage     (PTREE pTree, HTREEITEM hItem);
  124. // in TVMEM.C
  125. #define TVDI_NORMAL 0x0000 // TV_DeleteItem flags
  126. #define TVDI_NONOTIFY 0x0001
  127. #define TVDI_CHILDRENONLY 0x0002
  128. #define TVDI_NOSELCHANGE 0x0004
  129. BOOL      NEAR  TV_DeleteItem(PTREE, HTREEITEM, UINT);
  130. HTREEITEM NEAR  TV_InsertItem(PTREE pTree, LPTV_INSERTSTRUCT lpis);
  131. void      NEAR  TV_DestroyTree(PTREE);
  132. LRESULT   NEAR  TV_OnCreate(HWND, LPCREATESTRUCT);
  133. // in TREEVIEW.C
  134. BOOL      NEAR TV_GetItemRect(PTREE, HTREEITEM, LPRECT, BOOL);
  135. BOOL    NEAR TV_Expand(PTREE pTree, UINT wCode, TREEITEM FAR * hItem, BOOL fNotify);
  136. HTREEITEM NEAR TV_GetNextItem(PTREE, HTREEITEM, UINT);
  137. void    NEAR TV_GetItem(PTREE pTree, HTREEITEM hItem, UINT mask, LPTV_ITEM lpItem);
  138. BOOL      NEAR TV_SelectItem(PTREE, UINT, HTREEITEM, BOOL, BOOL, UINT);
  139. BOOL      NEAR TV_SendChange(PTREE, HTREEITEM, int, UINT, UINT, UINT, int, int);
  140. HTREEITEM NEAR TV_GetNextVisItem(HTREEITEM);
  141. HTREEITEM NEAR TV_GetPrevItem(HTREEITEM);
  142. HTREEITEM NEAR TV_GetPrevVisItem(HTREEITEM);
  143. void      NEAR TV_CalcShownItems(PTREE, HTREEITEM hItem);
  144. void      NEAR TV_OnSetFont(PTREE, HFONT, BOOL);
  145. BOOL      NEAR TV_SizeWnd(PTREE, UINT, UINT);
  146. void      NEAR TV_InvalidateItem(PTREE, HTREEITEM, UINT uFlags);
  147. VOID NEAR PASCAL TV_CreateBoldFont(PTREE pTree) ;
  148. LRESULT CALLBACK _export TV_EditWndProc(HWND, UINT, WPARAM, LPARAM);
  149. LRESULT CALLBACK _export TV_WndProc(HWND, UINT, WPARAM, LPARAM);
  150. BOOL FAR                 TV_Init(HINSTANCE hinst);
  151. void FAR                 TV_Terminate(BOOL fSystemExit);
  152. LRESULT   NEAR  TV_Timer                    (PTREE pTree, UINT uTimerId);
  153. HWND      NEAR  TV_OnEditLabel              (PTREE pTree, HTREEITEM hItem);
  154. void      NEAR  TV_SetEditSize              (PTREE pTree);
  155. BOOL      NEAR  TV_DismissEdit              (PTREE pTree, BOOL fCancel);
  156. void      NEAR  TV_CancelPendingEdit        (PTREE pTree);
  157. int       NEAR  TV_UpdateShownIndexes       (PTREE pTree, HTREEITEM hWalk);