Leaked source code of windows server 2003
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.

361 lines
15 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. LPSTR pszTipA; // store current ANSI tooltip/infotip string.
  107. //incremental search stuff
  108. ISEARCHINFO is;
  109. HTHEME hTheme;
  110. DWORD dwLastAccId;
  111. DWORD dwExStyle;
  112. #ifdef DEBUG
  113. BOOL fInTextCallback;
  114. #endif
  115. } TREE, *PTREE;
  116. #define TV_StateIndex(pitem) ((int)(((DWORD)((pitem)->state) >> 12) & 0xF))
  117. #define KIDS_COMPUTE 0 // use hKids to determine if a node has children
  118. #define KIDS_FORCE_YES 1 // force a node to have kids (ignore hKids)
  119. #define KIDS_FORCE_NO 2 // force a node to not have kids (ignore hKids)
  120. #define KIDS_CALLBACK 3 // callback to see if a node has kids
  121. #define KIDS_INVALID 4 // all values this and above are bogus
  122. #define MAXLABELTEXT MAX_PATH
  123. //
  124. // Note that there are multiple senses of "visible" going on.
  125. //
  126. // TREE.hTop tracks visibility in the sense of "will it be painted?"
  127. //
  128. // TREEITEM.iShownIndex tracks visibility in the sense of "not collapsed".
  129. // You can be off the screen but as long as your parent is expanded
  130. // you get an iShownIndex.
  131. //
  132. //
  133. typedef struct _TREEITEM
  134. {
  135. HTREEITEM hParent; // allows us to walk back out of the tree
  136. HTREEITEM hNext; // next sibling
  137. HTREEITEM hKids; // first child
  138. LPTSTR lpstr; // item text, can be LPSTR_TEXTCALLBACK
  139. LPARAM lParam; // item data
  140. DWORD dwAccId;
  141. WORD state; // TVIS_ state flags
  142. WORD iImage; // normal state image at iImage
  143. WORD iSelectedImage; // selected state image
  144. WORD iWidth; // cached: width of text area (for hit test, drawing)
  145. WORD iShownIndex; // cached: -1 if not visible, otherwise nth visible item
  146. // invisible = parent is invisible or collapsed
  147. BYTE iLevel; // cached: level of item (indent)
  148. BYTE fKids; // KIDS_ values
  149. WORD iIntegral; // integral height
  150. // for parameter validation, put at end of struct
  151. // ******************************
  152. WORD wSignature;
  153. // ******************************
  154. } TREEITEM;
  155. //
  156. // The signature is intentionally not ASCII characters, so it's
  157. // harder to run into by mistake. I choose a value greater than
  158. // 0x8000 so it can't be the high word of a pointer.
  159. //
  160. #define TV_SIG 0xABCD
  161. #define TV_MarkAsDead(hti) ((hti)->wSignature = 0)
  162. #define ITEM_VISIBLE(hti) ((hti)->iShownIndex != (WORD)-1)
  163. // get the parent, avoiding the hidden root node
  164. #define VISIBLE_PARENT(hItem) (!(hItem)->iLevel ? NULL : (hItem)->hParent)
  165. // REVIEW: make this a function if the optimizer doesn't do well with this
  166. #define FULL_WIDTH(pTree, hItem) (ITEM_OFFSET(pTree,hItem) + hItem->iWidth)
  167. int ITEM_OFFSET(PTREE pTree, HTREEITEM hItem);
  168. #define VTI_NULLOK 1
  169. BOOL ValidateTreeItem(HTREEITEM hItem, UINT flags);
  170. #ifdef DEBUG
  171. #define DBG_ValidateTreeItem(hItem, flags) ValidateTreeItem(hItem, flags)
  172. #else
  173. #define DBG_ValidateTreeItem(hItem, flags)
  174. #endif
  175. //
  176. // TVWATCHEDITEM
  177. //
  178. // Structure that tracks items being watched.
  179. //
  180. // See TV_StartWatch for more information, and TV_DoExpandRecurse
  181. // for an example.
  182. //
  183. // The hti field is a bit odd.
  184. //
  185. // if fStale == FALSE, then hti is the item being watched.
  186. // if fStale == TRUE , then hti is the item *after* the item being watched.
  187. //
  188. // We keep this strange semantic for fStale==TRUE so that TV_NextWatchItem
  189. // can successfully step to the item after a deleted item. (Normally,
  190. // trying to do anything with a deleted item will fault.)
  191. //
  192. typedef struct TVWATCHEDITEM
  193. {
  194. HTREEITEM hti; // current item
  195. BOOL fStale; // has the original item been deleted?
  196. } TVWATCHEDITEM, *PTVWATCHEDITEM;
  197. BOOL TV_StartWatch(PTREE pTree, PTVWATCHEDITEM pwi, HTREEITEM htiStart);
  198. BOOL TV_EndWatch(PTREE pTree, PTVWATCHEDITEM pwi);
  199. #define TV_GetWatchItem(pTree, pwi) ((pwi)->hti)
  200. #define TV_RestartWatch(pTree, pwi, htiStart) \
  201. ((pwi)->hti = (htiStart), (pwi)->fStale = FALSE)
  202. #define TV_IsWatchStale(pTree, pwi) ((pwi)->fStale)
  203. #define TV_IsWatchValid(pTree, pwi) (!(pwi)->fStale)
  204. #define TV_GetAccId(hItem) ((hItem)? (hItem)->dwAccId : CHILDID_SELF)
  205. //
  206. // TV_NextWatchItem - Enumerate the item after the watched item.
  207. // This works even if the watched item was deleted.
  208. //
  209. #define TV_NextWatchItem(pTree, pwi) \
  210. ((pwi)->fStale || ((pwi)->hti = (pwi)->hti->hNext)), \
  211. (pwi)->fStale = FALSE
  212. // in TVSCROLL.C
  213. BOOL TV_ScrollBarsAfterAdd (PTREE, HTREEITEM);
  214. BOOL TV_ScrollBarsAfterRemove (PTREE, HTREEITEM);
  215. BOOL TV_ScrollBarsAfterExpand (PTREE, HTREEITEM);
  216. BOOL TV_ScrollBarsAfterCollapse (PTREE, HTREEITEM);
  217. void TV_ScrollBarsAfterResize (PTREE, HTREEITEM, int, UINT);
  218. BOOL TV_ScrollBarsAfterSetWidth (PTREE, HTREEITEM);
  219. BOOL TV_HorzScroll (PTREE, UINT, UINT);
  220. BOOL TV_VertScroll (PTREE, UINT, UINT);
  221. BOOL TV_SetLeft (PTREE, int);
  222. #define TV_SetTopItem(pTree, i) TV_SmoothSetTopItem(pTree, i, 0)
  223. BOOL TV_SmoothSetTopItem (PTREE, UINT, UINT);
  224. BOOL TV_CalcScrollBars (PTREE);
  225. BOOL TV_ScrollIntoView (PTREE, HTREEITEM);
  226. BOOL TV_ScrollVertIntoView (PTREE, HTREEITEM);
  227. HTREEITEM TV_GetShownIndexItem (HTREEITEM, UINT);
  228. UINT TV_ScrollBelow (PTREE, HTREEITEM, BOOL, BOOL);
  229. BOOL TV_SortChildren(PTREE, HTREEITEM, BOOL);
  230. BOOL TV_SortChildrenCB(PTREE, LPTV_SORTCB, BOOL);
  231. void TV_ComputeItemWidth(PTREE pTree, HTREEITEM hItem, HDC hdc);
  232. // in TVPAINT.C
  233. void TV_GetBackgroundBrush (PTREE pTree, HDC hdc);
  234. void TV_UpdateTreeWindow (PTREE, BOOL);
  235. void TV_ChangeColors (PTREE);
  236. void TV_CreateIndentBmps (PTREE);
  237. void TV_Paint (PTREE, HDC);
  238. HIMAGELIST TV_CreateDragImage (PTREE pTree, HTREEITEM hItem);
  239. BOOL TV_ShouldItemDrawBlue (PTREE pTree, TVITEMEX *ti, UINT flags);
  240. LRESULT TV_GenerateDragImage (PTREE ptree, SHDRAGIMAGE* pshdi);
  241. BOOL TV_GetInsertMarkRect(PTREE pTree, LPRECT prc);
  242. // in TVMEM.C
  243. #define TVDI_NORMAL 0x0000 // TV_DeleteItem flags
  244. #define TVDI_NONOTIFY 0x0001
  245. #define TVDI_CHILDRENONLY 0x0002
  246. #define TVDI_NOSELCHANGE 0x0004
  247. BOOL TV_DeleteItem(PTREE, HTREEITEM, UINT);
  248. HTREEITEM TV_InsertItem(PTREE pTree, LPTV_INSERTSTRUCT lpis);
  249. void TV_DestroyTree(PTREE);
  250. LRESULT TV_OnCreate(HWND, LPCREATESTRUCT);
  251. HTREEITEM TV_InsertItemA(PTREE pTree, LPTV_INSERTSTRUCTA lpis);
  252. // in TREEVIEW.C
  253. BOOL TV_GetItemRect(PTREE, HTREEITEM, LPRECT, BOOL);
  254. BOOL TV_Expand(PTREE pTree, WPARAM wCode, TREEITEM * hItem, BOOL fNotify);
  255. HTREEITEM TV_GetNextItem(PTREE, HTREEITEM, WPARAM);
  256. void TV_GetItem(PTREE pTree, HTREEITEM hItem, UINT mask, LPTVITEMEX lpItem);
  257. void TV_PopBubble(PTREE pTree);
  258. // Flags for TV_SelectItem
  259. #define TVSIFI_NOTIFY 0x0001
  260. #define TVSIFI_UPDATENOW 0x0002
  261. #define TVSIFI_NOSINGLEEXPAND 0x0004
  262. BOOL TV_SelectItem(PTREE, WPARAM, HTREEITEM, UINT, UINT);
  263. BOOL TV_SendChange(PTREE, HTREEITEM, int, UINT, UINT, UINT, int, int);
  264. HTREEITEM TV_GetNextVisItem(HTREEITEM);
  265. HTREEITEM TV_GetPrevItem(HTREEITEM);
  266. HTREEITEM TV_GetPrevVisItem(HTREEITEM);
  267. void TV_CalcShownItems(PTREE, HTREEITEM hItem);
  268. void TV_OnSetFont(PTREE, HFONT, BOOL);
  269. BOOL TV_SizeWnd(PTREE, UINT, UINT);
  270. void TV_InvalidateItem(PTREE, HTREEITEM, UINT uFlags);
  271. VOID TV_CreateBoldFont(PTREE pTree);
  272. BOOL TV_SetInsertMark(PTREE pTree, HTREEITEM hItem, BOOL fAfter);
  273. LRESULT CALLBACK _export TV_EditWndProc(HWND, UINT, WPARAM, LPARAM);
  274. LRESULT CALLBACK _export TV_WndProc(HWND, UINT, WPARAM, LPARAM);
  275. BOOL TV_Init(HINSTANCE hinst);
  276. void TV_Terminate(BOOL fSystemExit);
  277. LRESULT TV_Timer (PTREE pTree, UINT uTimerId);
  278. HWND TV_OnEditLabel (PTREE pTree, HTREEITEM hItem);
  279. void TV_SetEditSize (PTREE pTree);
  280. BOOL TV_DismissEdit (PTREE pTree, BOOL fCancel);
  281. void TV_CancelPendingEdit (PTREE pTree);
  282. int TV_UpdateShownIndexes (PTREE pTree, HTREEITEM hWalk);
  283. void TV_UnsubclassToolTips(PTREE pTree);
  284. LRESULT WINAPI TV_SubClassWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  285. void TV_SubclassToolTips(PTREE pTree);
  286. BOOL TV_UpdateToolTip(PTREE pTree);
  287. BOOL TV_SetToolTipTarget(PTREE pTree, HTREEITEM hItem);
  288. void TV_OnSetBkColor(PTREE pTree, COLORREF clr);
  289. void TV_InitCheckBoxes(PTREE pTree);
  290. void TV_InitThemeMetrics(PTREE pTree, HTHEME hTheme);
  291. #define TVMP_CALCSCROLLBARS (TV_FIRST + 0x1000)
  292. // Fake customdraw. See comment block in tvscroll.c
  293. typedef struct TVFAKEDRAW
  294. {
  295. NMTVCUSTOMDRAW nmcd;
  296. PTREE pTree;
  297. HFONT hfontPrev;
  298. DWORD dwCustomPrev;
  299. DWORD dwCustomItem;
  300. } TVFAKEDRAW, *PTVFAKEDRAW;
  301. void TreeView_BeginFakeCustomDraw(PTREE pTree, PTVFAKEDRAW ptvfd);
  302. DWORD TreeView_BeginFakeItemDraw(PTVFAKEDRAW plvfd, HTREEITEM hitem);
  303. void TreeView_EndFakeItemDraw(PTVFAKEDRAW ptvfd);
  304. void TreeView_EndFakeCustomDraw(PTVFAKEDRAW ptvfd);