Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
14 KiB

  1. #include "listview.h" // for some helper routines and border metrics
  2. #define __IOleControl_INTERFACE_DEFINED__ // There is a conflich with the IOleControl's def of CONTROLINFO
  3. #include "shlobj.h"
  4. //
  5. // Definitions missing from commctrl.h
  6. //
  7. typedef const TVITEMEX *LPCTVITEMEX;
  8. //
  9. // Private definitions
  10. //
  11. #define MAGIC_MININDENT 5
  12. #define MAGIC_INDENT 3
  13. #define MAGIC_HORZLINE 5
  14. // flags for TV_DrawItem
  15. #define TVDI_NOIMAGE 0x0001 // don't draw image
  16. #define TVDI_NOTREE 0x0002 // don't draw indent, lines, +/-
  17. #define TVDI_TRANSTEXT 0x0004 // draw text transparently in black
  18. #define TVDI_ERASE 0x0008 // erase while drawing
  19. #define TVDI_GRAYTEXT 0x0010 // text is gray (disabled item)
  20. #define TVDI_GRAYCTL 0x0020 // text and background is gray (disabled control)
  21. #define TVDI_FORCEIMAGE 0x0040 // Always draw image
  22. #define TVDI_NOBK 0x0080
  23. // Internal flags for TV_SelectItem
  24. #define TVC_INTERNAL 0x1000
  25. typedef struct _TREE {
  26. CONTROLINFO ci;
  27. // Flags
  28. BITBOOL fHorz:1; // horizontal scrollbar present
  29. BITBOOL fVert:1; // vertical scrollbar present
  30. BITBOOL fFocus:1; // currently has focus
  31. BITBOOL fNameEditPending:1; // Is a name edit pending?
  32. BITBOOL fRedraw:1; // should redraw?
  33. BITBOOL fScrollWait:1; // are we waiting for a dblclk to not scroll?
  34. BITBOOL fCreatedFont:1; // we created our font
  35. BITBOOL fNoDismissEdit:1; // don't dismiss in-place edit control
  36. BITBOOL fIndentSet:1; // is the parent managing the indent size?
  37. BITBOOL fTrackSet:1; // have we set a track event?
  38. BITBOOL fPlaceTooltip:1; // should we do the placement of tooltip over the text?
  39. BITBOOL fCyItemSet:1; // the the parent set our item height?
  40. BITBOOL fInsertAfter:1; // insert mark should be after htiInsert instead of before
  41. BITBOOL fRestoreOldDrop:1; // hOldDrop needs to be restored to hDropTarget
  42. // Handles
  43. HTREEITEM hRoot; // tree root item
  44. HTREEITEM hCaret; // item with focus caret
  45. HTREEITEM hDropTarget; // item which is the drop target
  46. HTREEITEM hOldDrop; // item which used to be the drop target
  47. HTREEITEM htiEdit; // The item that is being edited.
  48. HTREEITEM hHot; // the currently hottracked item
  49. HTREEITEM hToolTip; // the current item set in tooltips
  50. HTREEITEM htiInsert; // item that is relative to the insert mark
  51. HTREEITEM htiSearch; // item active in most recent incremental search
  52. HTREEITEM htiDrag; // item that's being dragged.
  53. HDPA hdpaWatch; // array of PTVWATCHEDITEMs - items being watched
  54. HIMAGELIST hImageList; // image list
  55. HIMAGELIST himlState; // state image list
  56. HCURSOR hCurHot; // the cursor when we're over a hot item
  57. int iPuntChar; // number of wm_char's to punt
  58. int cxState;
  59. int cyState;
  60. UINT uDBCSChar; // DBCS character for incremental search
  61. HBRUSH hbrBk; // background brush
  62. HFONT hFont; // tree font
  63. HFONT hFontHot; // underlined for hot tracking
  64. HFONT hFontBold; // bold tree font
  65. HFONT hFontBoldHot; // underlined for hot tracking
  66. HBITMAP hStartBmp; // initial DC mono bitmap
  67. HBITMAP hBmp; // indent bitmaps in hdcBits
  68. HDC hdcBits; // HDC for drawing indent bitmaps
  69. HTREEITEM hItemPainting; // the guy we are currently painting
  70. HANDLE hheap; // heap for allocs for win32
  71. POINT ptCapture; // Point where the mouse was capture
  72. COLORREF clrText;
  73. COLORREF clrBk;
  74. COLORREF clrim; // insert mark color.
  75. COLORREF clrLine; // line color
  76. // Dimensions
  77. SHORT cxImage; // image width
  78. SHORT cyImage; // image height
  79. SHORT cyText; // text height
  80. SHORT cyItem; // item height
  81. SHORT cxBorder; // horizontal item border
  82. SHORT cyBorder; // vert item border
  83. SHORT cxIndent; // indent width
  84. SHORT cxWnd; // window width
  85. SHORT cyWnd; // window height
  86. // Scroll Positioners
  87. WORD cxMax; // width of longest item
  88. WORD cFullVisible; // number of items that CAN fully fit in window
  89. SHORT xPos; // horizontal scrolled position
  90. UINT cShowing; // number of showing (non-collapsed) items
  91. UINT cItems; // total number of items
  92. HTREEITEM hTop; // first visible item (i.e., at top of client rect)
  93. UINT uMaxScrollTime; // the maximum smooth scroll timing
  94. // stuff for edit in place
  95. HWND hwndEdit; // Edit window for name editing.
  96. WNDPROC pfnEditWndProc; // edit field subclass proc
  97. //tooltip stuff
  98. HWND hwndToolTips;
  99. LPTSTR pszTip; // store current tooltip/infotip string.
  100. #ifdef UNICODE
  101. LPSTR pszTipA; // store current ANSI tooltip/infotip string.
  102. #endif
  103. //incremental search stuff
  104. ISEARCHINFO is;
  105. } TREE, NEAR *PTREE;
  106. #define TV_StateIndex(pitem) ((int)(((DWORD)((pitem)->state) >> 12) & 0xF))
  107. #define KIDS_COMPUTE 0 // use hKids to determine if a node has children
  108. #define KIDS_FORCE_YES 1 // force a node to have kids (ignore hKids)
  109. #define KIDS_FORCE_NO 2 // force a node to not have kids (ignore hKids)
  110. #define KIDS_CALLBACK 3 // callback to see if a node has kids
  111. #define KIDS_INVALID 4 // all values this and above are bogus
  112. #define MAXLABELTEXT MAX_PATH
  113. // BUGBUG: OINK OINK
  114. //
  115. // Note that there are multiple senses of "visible" going on.
  116. //
  117. // TREE.hTop tracks visibility in the sense of "will it be painted?"
  118. //
  119. // TREEITEM.iShownIndex tracks visibility in the sense of "not collapsed".
  120. // You can be off the screen but as long as your parent is expanded
  121. // you get an iShownIndex.
  122. //
  123. //
  124. typedef struct _TREEITEM {
  125. HTREEITEM hParent; // allows us to walk back out of the tree
  126. HTREEITEM hNext; // next sibling
  127. HTREEITEM hKids; // first child
  128. LPTSTR lpstr; // item text, can be LPSTR_TEXTCALLBACK
  129. LPARAM lParam; // item data
  130. WORD state; // TVIS_ state flags
  131. WORD iImage; // normal state image at iImage
  132. WORD iSelectedImage; // selected state image
  133. WORD iWidth; // cached: width of text area (for hit test, drawing)
  134. WORD iShownIndex; // cached: -1 if not visible, otherwise nth visible item
  135. // invisible = parent is invisible or collapsed
  136. BYTE iLevel; // cached: level of item (indent)
  137. BYTE fKids; // KIDS_ values
  138. WORD iIntegral; // integral height
  139. WORD wSignature; // for parameter validation, put at end of struct
  140. } TREEITEM;
  141. //
  142. // The signature is intentionally not ASCII characters, so it's
  143. // harder to run into by mistake. I choose a value greater than
  144. // 0x8000 so it can't be the high word of a pointer.
  145. //
  146. #define TV_SIG 0xABCD
  147. #define TV_MarkAsDead(hti) ((hti)->wSignature = 0)
  148. #define ITEM_VISIBLE(hti) ((hti)->iShownIndex != (WORD)-1)
  149. // get the parent, avoiding the hidden root node
  150. #define VISIBLE_PARENT(hItem) (!(hItem)->iLevel ? NULL : (hItem)->hParent)
  151. // REVIEW: make this a function if the optimizer doesn't do well with this
  152. #define FULL_WIDTH(pTree, hItem) (ITEM_OFFSET(pTree,hItem) + hItem->iWidth)
  153. int FAR PASCAL ITEM_OFFSET(PTREE pTree, HTREEITEM hItem);
  154. #define VTI_NULLOK 1
  155. BOOL ValidateTreeItem(HTREEITEM hItem, UINT flags);
  156. #ifdef DEBUG
  157. #define DBG_ValidateTreeItem(hItem, flags) ValidateTreeItem(hItem, flags)
  158. #else
  159. #define DBG_ValidateTreeItem(hItem, flags)
  160. #endif
  161. //
  162. // TVWATCHEDITEM
  163. //
  164. // Structure that tracks items being watched.
  165. //
  166. // See TV_StartWatch for more information, and TV_DoExpandRecurse
  167. // for an example.
  168. //
  169. // The hti field is a bit odd.
  170. //
  171. // if fStale == FALSE, then hti is the item being watched.
  172. // if fStale == TRUE , then hti is the item *after* the item being watched.
  173. //
  174. // We keep this strange semantic for fStale==TRUE so that TV_NextWatchItem
  175. // can successfully step to the item after a deleted item. (Normally,
  176. // trying to do anything with a deleted item will fault.)
  177. //
  178. typedef struct TVWATCHEDITEM {
  179. HTREEITEM hti; // current item
  180. BOOL fStale; // has the original item been deleted?
  181. } TVWATCHEDITEM, *PTVWATCHEDITEM;
  182. BOOL TV_StartWatch(PTREE pTree, PTVWATCHEDITEM pwi, HTREEITEM htiStart);
  183. BOOL TV_EndWatch(PTREE pTree, PTVWATCHEDITEM pwi);
  184. #define TV_GetWatchItem(pTree, pwi) ((pwi)->hti)
  185. #define TV_RestartWatch(pTree, pwi, htiStart) \
  186. ((pwi)->hti = (htiStart), (pwi)->fStale = FALSE)
  187. #define TV_IsWatchStale(pTree, pwi) ((pwi)->fStale)
  188. #define TV_IsWatchValid(pTree, pwi) (!(pwi)->fStale)
  189. //
  190. // TV_NextWatchItem - Enumerate the item after the watched item.
  191. // This works even if the watched item was deleted.
  192. //
  193. #define TV_NextWatchItem(pTree, pwi) \
  194. ((pwi)->fStale || ((pwi)->hti = (pwi)->hti->hNext)), \
  195. (pwi)->fStale = FALSE
  196. // in TVSCROLL.C
  197. BOOL NEAR TV_ScrollBarsAfterAdd (PTREE, HTREEITEM);
  198. BOOL NEAR TV_ScrollBarsAfterRemove (PTREE, HTREEITEM);
  199. BOOL NEAR TV_ScrollBarsAfterExpand (PTREE, HTREEITEM);
  200. BOOL NEAR TV_ScrollBarsAfterCollapse (PTREE, HTREEITEM);
  201. void NEAR TV_ScrollBarsAfterResize (PTREE, HTREEITEM, int, UINT);
  202. BOOL NEAR TV_ScrollBarsAfterSetWidth (PTREE, HTREEITEM);
  203. BOOL NEAR TV_HorzScroll (PTREE, UINT, UINT);
  204. BOOL NEAR TV_VertScroll (PTREE, UINT, UINT);
  205. BOOL NEAR TV_SetLeft (PTREE, int);
  206. #define TV_SetTopItem(pTree, i) TV_SmoothSetTopItem(pTree, i, 0)
  207. BOOL NEAR TV_SmoothSetTopItem (PTREE, UINT, UINT);
  208. BOOL NEAR TV_CalcScrollBars (PTREE);
  209. BOOL NEAR TV_ScrollIntoView (PTREE, HTREEITEM);
  210. BOOL NEAR TV_ScrollVertIntoView (PTREE, HTREEITEM);
  211. HTREEITEM NEAR TV_GetShownIndexItem (HTREEITEM, UINT);
  212. UINT NEAR TV_ScrollBelow (PTREE, HTREEITEM, BOOL, BOOL);
  213. BOOL NEAR TV_SortChildren(PTREE, HTREEITEM, BOOL);
  214. BOOL NEAR TV_SortChildrenCB(PTREE, LPTV_SORTCB, BOOL);
  215. void NEAR TV_ComputeItemWidth(PTREE pTree, HTREEITEM hItem, HDC hdc);
  216. // in TVPAINT.C
  217. void NEAR TV_GetBackgroundBrush (PTREE pTree, HDC hdc);
  218. void NEAR TV_UpdateTreeWindow (PTREE, BOOL);
  219. void NEAR TV_ChangeColors (PTREE);
  220. void NEAR TV_CreateIndentBmps (PTREE);
  221. void NEAR TV_Paint (PTREE, HDC);
  222. HIMAGELIST NEAR TV_CreateDragImage (PTREE pTree, HTREEITEM hItem);
  223. BOOL NEAR TV_ShouldItemDrawBlue (PTREE pTree, TVITEMEX *ti, UINT flags);
  224. LRESULT NEAR TV_GenerateDragImage (PTREE ptree, SHDRAGIMAGE* pshdi);
  225. BOOL TV_GetInsertMarkRect(PTREE pTree, LPRECT prc);
  226. // in TVMEM.C
  227. #define TVDI_NORMAL 0x0000 // TV_DeleteItem flags
  228. #define TVDI_NONOTIFY 0x0001
  229. #define TVDI_CHILDRENONLY 0x0002
  230. #define TVDI_NOSELCHANGE 0x0004
  231. BOOL NEAR TV_DeleteItem(PTREE, HTREEITEM, UINT);
  232. HTREEITEM NEAR TV_InsertItem(PTREE pTree, LPTV_INSERTSTRUCT lpis);
  233. void NEAR TV_DestroyTree(PTREE);
  234. LRESULT NEAR TV_OnCreate(HWND, LPCREATESTRUCT);
  235. #ifdef UNICODE
  236. HTREEITEM NEAR TV_InsertItemA(PTREE pTree, LPTV_INSERTSTRUCTA lpis);
  237. #endif
  238. // in TREEVIEW.C
  239. BOOL NEAR TV_GetItemRect(PTREE, HTREEITEM, LPRECT, BOOL);
  240. BOOL NEAR TV_Expand(PTREE pTree, WPARAM wCode, TREEITEM FAR * hItem, BOOL fNotify);
  241. HTREEITEM NEAR TV_GetNextItem(PTREE, HTREEITEM, WPARAM);
  242. void NEAR TV_GetItem(PTREE pTree, HTREEITEM hItem, UINT mask, LPTVITEMEX lpItem);
  243. void TV_PopBubble(PTREE pTree);
  244. // Flags for TV_SelectItem
  245. #define TVSIF_NOTIFY 0x0001
  246. #define TVSIF_UPDATENOW 0x0002
  247. #define TVSIF_NOSINGLEEXPAND 0x0004
  248. BOOL NEAR TV_SelectItem(PTREE, WPARAM, HTREEITEM, UINT, UINT);
  249. BOOL NEAR TV_SendChange(PTREE, HTREEITEM, int, UINT, UINT, UINT, int, int);
  250. HTREEITEM NEAR TV_GetNextVisItem(HTREEITEM);
  251. HTREEITEM NEAR TV_GetPrevItem(HTREEITEM);
  252. HTREEITEM NEAR TV_GetPrevVisItem(HTREEITEM);
  253. void NEAR TV_CalcShownItems(PTREE, HTREEITEM hItem);
  254. void NEAR TV_OnSetFont(PTREE, HFONT, BOOL);
  255. BOOL NEAR TV_SizeWnd(PTREE, UINT, UINT);
  256. void NEAR TV_InvalidateItem(PTREE, HTREEITEM, UINT uFlags);
  257. VOID NEAR PASCAL TV_CreateBoldFont(PTREE pTree);
  258. BOOL TV_SetInsertMark(PTREE pTree, HTREEITEM hItem, BOOL fAfter);
  259. LRESULT CALLBACK _export TV_EditWndProc(HWND, UINT, WPARAM, LPARAM);
  260. LRESULT CALLBACK _export TV_WndProc(HWND, UINT, WPARAM, LPARAM);
  261. BOOL FAR TV_Init(HINSTANCE hinst);
  262. void FAR TV_Terminate(BOOL fSystemExit);
  263. LRESULT NEAR TV_Timer (PTREE pTree, UINT uTimerId);
  264. HWND NEAR TV_OnEditLabel (PTREE pTree, HTREEITEM hItem);
  265. void NEAR TV_SetEditSize (PTREE pTree);
  266. BOOL NEAR TV_DismissEdit (PTREE pTree, BOOL fCancel);
  267. void NEAR TV_CancelPendingEdit (PTREE pTree);
  268. int NEAR TV_UpdateShownIndexes (PTREE pTree, HTREEITEM hWalk);
  269. void NEAR TV_UnsubclassToolTips(PTREE pTree);
  270. LRESULT WINAPI TV_SubClassWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  271. void NEAR TV_SubclassToolTips(PTREE pTree);
  272. BOOL TV_UpdateToolTip(PTREE pTree);
  273. BOOL TV_SetToolTipTarget(PTREE pTree, HTREEITEM hItem);
  274. void TV_OnSetBkColor(PTREE pTree, COLORREF clr);
  275. void TV_InitCheckBoxes(PTREE pTree);
  276. #define TVMP_CALCSCROLLBARS (TV_FIRST + 0x1000)
  277. // Fake customdraw. See comment block in tvscroll.c
  278. typedef struct TVFAKEDRAW {
  279. NMTVCUSTOMDRAW nmcd;
  280. PTREE pTree;
  281. HFONT hfontPrev;
  282. DWORD dwCustomPrev;
  283. DWORD dwCustomItem;
  284. } TVFAKEDRAW, *PTVFAKEDRAW;
  285. void TreeView_BeginFakeCustomDraw(PTREE pTree, PTVFAKEDRAW ptvfd);
  286. DWORD TreeView_BeginFakeItemDraw(PTVFAKEDRAW plvfd, HTREEITEM hitem);
  287. void TreeView_EndFakeItemDraw(PTVFAKEDRAW ptvfd);
  288. void TreeView_EndFakeCustomDraw(PTVFAKEDRAW ptvfd);