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.

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