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.

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