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.

359 lines
12 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Dlg.cpp
  7. //
  8. // Contents: common dialog routines.
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 05-Nov-97 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "precomp.h"
  18. extern HINSTANCE g_hInst; // current instance
  19. //+---------------------------------------------------------------------------
  20. //
  21. // function: AddItemsFromQueueToListView, private
  22. //
  23. // Synopsis: Adds the items in the Queue to the ListView.
  24. //
  25. // Arguments:
  26. // int iDateColumn,int iStatusColumn - if these are >= zero
  27. // means the Column is Valid and the proper data is initialized.
  28. //
  29. // Returns:
  30. //
  31. // Modifies:
  32. //
  33. // History: 30-Jul-98 rogerg Created.
  34. //
  35. //----------------------------------------------------------------------------
  36. BOOL AddItemsFromQueueToListView(CListView *pItemListView,CHndlrQueue *pHndlrQueue
  37. ,DWORD dwExtStyle,LPARAM lparam,int iDateColumn,int iStatusColumn,BOOL fHandlerParent
  38. ,BOOL fAddOnlyCheckedItems)
  39. {
  40. WORD wItemID;
  41. HIMAGELIST himageSmallIcon;
  42. HANDLERINFO *pHandlerId;
  43. WCHAR wszStatusText[MAX_STRING_RES];
  44. DWORD dwDateReadingFlags;
  45. dwDateReadingFlags = GetDateFormatReadingFlags(pItemListView->GetHwnd());
  46. *wszStatusText = NULL;
  47. if (!pItemListView)
  48. {
  49. Assert(pItemListView);
  50. return FALSE;
  51. }
  52. if (!pHndlrQueue)
  53. {
  54. Assert(pHndlrQueue);
  55. return FALSE;
  56. }
  57. pItemListView->SetExtendedListViewStyle(dwExtStyle);
  58. // not an error to not get the small Icon, just won't have icons.
  59. himageSmallIcon = pItemListView->GetImageList(LVSIL_SMALL );
  60. pHandlerId = 0;;
  61. wItemID = 0;
  62. // loop through queue finding any
  63. while (S_OK == pHndlrQueue->FindNextItemInState(HANDLERSTATE_PREPAREFORSYNC,
  64. pHandlerId,wItemID,&pHandlerId,&wItemID))
  65. {
  66. INT iListViewItem;
  67. CLSID clsidDataHandler;
  68. SYNCMGRITEM offlineItem;
  69. BOOL fHiddenItem;
  70. LVITEMEX lvItemInfo; // structure to pass into ListView Calls
  71. // grab the offline item info.
  72. if (S_OK == pHndlrQueue->GetItemDataAtIndex(pHandlerId,wItemID,&clsidDataHandler,&offlineItem,&fHiddenItem))
  73. {
  74. LVHANDLERITEMBLOB lvHandlerItemBlob;
  75. int iParentItemId;
  76. // if the item is hidden don't show it in the UI
  77. if (fHiddenItem)
  78. {
  79. continue;
  80. }
  81. // if only add checked items and this one isn't continue on
  82. if (fAddOnlyCheckedItems && (SYNCMGRITEMSTATE_CHECKED != offlineItem.dwItemState))
  83. {
  84. continue;
  85. }
  86. // Check if item is already in the ListView and if so
  87. // go on
  88. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  89. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  90. lvHandlerItemBlob.ItemID = offlineItem.ItemID;
  91. if (-1 != pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob))
  92. {
  93. // already in ListView, go on to the next item.
  94. continue;
  95. }
  96. if (!fHandlerParent)
  97. {
  98. iParentItemId = LVI_ROOT;
  99. }
  100. else
  101. {
  102. // need to add to list so find parent and if one doesn't exist, create it.
  103. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  104. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  105. lvHandlerItemBlob.ItemID = GUID_NULL;
  106. iParentItemId = pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  107. if (-1 == iParentItemId)
  108. {
  109. LVITEMEX itemInfoParent;
  110. SYNCMGRHANDLERINFO SyncMgrHandlerInfo;
  111. // if can't get the ParentInfo then don't add the Item
  112. if (S_OK != pHndlrQueue->GetHandlerInfo(clsidDataHandler,&SyncMgrHandlerInfo))
  113. {
  114. continue;
  115. }
  116. // Insert the Parent.
  117. itemInfoParent.mask = LVIF_TEXT;
  118. itemInfoParent.iItem = LVI_LAST;;
  119. itemInfoParent.iSubItem = 0;
  120. itemInfoParent.iImage = -1;
  121. itemInfoParent.pszText = SyncMgrHandlerInfo.wszHandlerName;
  122. if (himageSmallIcon)
  123. {
  124. HICON hIcon = SyncMgrHandlerInfo.hIcon ? SyncMgrHandlerInfo.hIcon : offlineItem.hIcon;
  125. // if have toplevel handler info icon use this else use the items icon
  126. if (hIcon)
  127. {
  128. itemInfoParent.iImage = ImageList_AddIcon(himageSmallIcon,hIcon);
  129. if (itemInfoParent.iImage != -1)
  130. {
  131. itemInfoParent.mask |= LVIF_IMAGE ;
  132. }
  133. }
  134. }
  135. // save the blob
  136. itemInfoParent.maskEx = LVIFEX_BLOB;
  137. itemInfoParent.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  138. iParentItemId = pItemListView->InsertItem(&itemInfoParent);
  139. // if parent insert failed go onto the next item
  140. if (-1 == iParentItemId)
  141. {
  142. continue;
  143. }
  144. }
  145. }
  146. // now attempt to insert the item.
  147. lvItemInfo.mask = LVIF_TEXT | LVIF_PARAM;
  148. lvItemInfo.maskEx = LVIFEX_PARENT | LVIFEX_BLOB;
  149. lvItemInfo.iItem = LVI_LAST;
  150. lvItemInfo.iSubItem = 0;
  151. lvItemInfo.iParent = iParentItemId;
  152. lvItemInfo.pszText = offlineItem.wszItemName;
  153. lvItemInfo.iImage = -1; // set to -1 in case can't get image.
  154. lvItemInfo.lParam = lparam;
  155. if (himageSmallIcon && offlineItem.hIcon)
  156. {
  157. lvItemInfo.iImage = ImageList_AddIcon(himageSmallIcon,offlineItem.hIcon);
  158. lvItemInfo.mask |= LVIF_IMAGE ;
  159. }
  160. // setup the blob
  161. lvHandlerItemBlob.ItemID = offlineItem.ItemID;
  162. lvItemInfo.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  163. iListViewItem = lvItemInfo.iItem = pItemListView->InsertItem(&lvItemInfo);
  164. if (-1 == iListViewItem)
  165. {
  166. continue;
  167. }
  168. // if the item has a date column insert it and the item
  169. // has a last update time.
  170. if (iDateColumn >= 0 && (offlineItem.dwFlags & SYNCMGRITEM_LASTUPDATETIME))
  171. {
  172. SYSTEMTIME sysTime;
  173. FILETIME filetime;
  174. WCHAR DateTime[256];
  175. LPWSTR pDateTime = DateTime;
  176. int cchWritten;
  177. lvItemInfo.mask = LVIF_TEXT;
  178. lvItemInfo.iSubItem = iDateColumn;
  179. lvItemInfo.maskEx = 0;
  180. FileTimeToLocalFileTime(&(offlineItem.ftLastUpdate),&filetime);
  181. FileTimeToSystemTime(&filetime,&sysTime);
  182. // insert date in form of date<space>hour
  183. *DateTime = NULL;
  184. // want to insert the date
  185. if (cchWritten = GetDateFormat(NULL,DATE_SHORTDATE | dwDateReadingFlags,&sysTime,NULL,pDateTime,ARRAYSIZE(DateTime)))
  186. {
  187. pDateTime += (cchWritten -1); // move number of characters written. (cchWritten includes the NULL)
  188. *pDateTime = TEXT(' '); // pDateTime is now ponting at the NULL character.
  189. ++pDateTime;
  190. // if left to right add the LRM
  191. if (DATE_LTRREADING & dwDateReadingFlags)
  192. {
  193. *pDateTime = LRM;
  194. ++pDateTime;
  195. }
  196. // no try to get the hours if fails we make sure that the last char is NULL;
  197. if (!GetTimeFormat(NULL,TIME_NOSECONDS,&sysTime,NULL,pDateTime,ARRAYSIZE(DateTime) - cchWritten))
  198. {
  199. *pDateTime = NULL;
  200. }
  201. }
  202. lvItemInfo.pszText = DateTime;
  203. pItemListView->SetItem(&lvItemInfo); // if fail, then just don't have any date.
  204. }
  205. if (iStatusColumn >= 0)
  206. {
  207. lvItemInfo.iSubItem = iStatusColumn;
  208. lvItemInfo.maskEx = 0;
  209. lvItemInfo.mask = LVIF_TEXT;
  210. if (NULL == *wszStatusText)
  211. {
  212. LoadString(g_hInst, IDS_PENDING,wszStatusText, MAX_STRING_RES);
  213. }
  214. lvItemInfo.pszText = wszStatusText;
  215. pItemListView->SetItem(&lvItemInfo); // if fail, then just don't have any date.
  216. }
  217. // if the listbox has checkBoxes then set the CheckState accordingly
  218. if (LVS_EX_CHECKBOXES & dwExtStyle)
  219. {
  220. if (SYNCMGRITEMSTATE_CHECKED == offlineItem.dwItemState)
  221. {
  222. lvItemInfo.state = LVIS_STATEIMAGEMASK_CHECK;
  223. }
  224. else
  225. {
  226. lvItemInfo.state = LVIS_STATEIMAGEMASK_UNCHECK;
  227. }
  228. // if LVS_EX_CHECKBOXES set then setup the CheckBox State setitem State, must do after insert
  229. pItemListView->SetItemState(iListViewItem,lvItemInfo.state,LVIS_STATEIMAGEMASK);
  230. }
  231. }
  232. }
  233. // now loop through to see if any handlers that want to always show but don't
  234. // yet have any items have been added
  235. if (fHandlerParent)
  236. {
  237. LVHANDLERITEMBLOB lvHandlerItemBlob;
  238. int iParentItemId;
  239. HANDLERINFO *pHandlerID = 0;
  240. CLSID clsidDataHandler;
  241. while (S_OK == pHndlrQueue->FindNextHandlerInState(pHandlerID,
  242. GUID_NULL,HANDLERSTATE_PREPAREFORSYNC,&pHandlerID
  243. ,&clsidDataHandler))
  244. {
  245. SYNCMGRHANDLERINFO SyncMgrHandlerInfo;
  246. // if can't get the ParentInfo then don't add.
  247. if (S_OK != pHndlrQueue->GetHandlerInfo(clsidDataHandler,&SyncMgrHandlerInfo))
  248. {
  249. continue;
  250. }
  251. // only add if handler says too
  252. if (!(SYNCMGRHANDLER_ALWAYSLISTHANDLER & SyncMgrHandlerInfo.SyncMgrHandlerFlags))
  253. {
  254. continue;
  255. }
  256. // need to add to list so find parent and if one doesn't exist, create it.
  257. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  258. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  259. lvHandlerItemBlob.ItemID = GUID_NULL;
  260. iParentItemId = pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  261. if (-1 == iParentItemId)
  262. {
  263. LVITEMEX itemInfoParent;
  264. // Insert the Parent.
  265. itemInfoParent.mask = LVIF_TEXT;
  266. itemInfoParent.iItem = LVI_LAST;;
  267. itemInfoParent.iSubItem = 0;
  268. itemInfoParent.iImage = -1;
  269. itemInfoParent.pszText = SyncMgrHandlerInfo.wszHandlerName;
  270. if (himageSmallIcon)
  271. {
  272. HICON hIcon = SyncMgrHandlerInfo.hIcon;
  273. // if have toplevel handler info icon use this else use the items icon
  274. if (hIcon)
  275. {
  276. itemInfoParent.iImage = ImageList_AddIcon(himageSmallIcon, hIcon);
  277. if (itemInfoParent.iImage != -1)
  278. {
  279. itemInfoParent.mask |= LVIF_IMAGE ;
  280. }
  281. }
  282. }
  283. // save the blob
  284. itemInfoParent.maskEx = LVIFEX_BLOB;
  285. itemInfoParent.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  286. iParentItemId = pItemListView->InsertItem(&itemInfoParent);
  287. }
  288. }
  289. }
  290. return TRUE;
  291. }