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.

377 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 (NOERROR == 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 (NOERROR == pHndlrQueue->GetItemDataAtIndex(pHandlerId,wItemID,
  73. &clsidDataHandler,&offlineItem,&fHiddenItem))
  74. {
  75. LVHANDLERITEMBLOB lvHandlerItemBlob;
  76. int iParentItemId;
  77. // if the item is hidden don't show it in the UI
  78. if (fHiddenItem)
  79. {
  80. continue;
  81. }
  82. // if only add checked items and this one isn't continue on
  83. if (fAddOnlyCheckedItems && (SYNCMGRITEMSTATE_CHECKED != offlineItem.dwItemState))
  84. {
  85. continue;
  86. }
  87. // Check if item is already in the ListView and if so
  88. // go on
  89. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  90. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  91. lvHandlerItemBlob.ItemID = offlineItem.ItemID;
  92. if (-1 != pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob))
  93. {
  94. // already in ListView, go on to the next item.
  95. continue;
  96. }
  97. if (!fHandlerParent)
  98. {
  99. iParentItemId = LVI_ROOT;
  100. }
  101. else
  102. {
  103. // need to add to list so find parent and if one doesn't exist, create it.
  104. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  105. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  106. lvHandlerItemBlob.ItemID = GUID_NULL;
  107. iParentItemId = pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  108. if (-1 == iParentItemId)
  109. {
  110. LVITEMEX itemInfoParent;
  111. SYNCMGRHANDLERINFO SyncMgrHandlerInfo;
  112. // if can't get the ParentInfo then don't add the Item
  113. if (NOERROR != pHndlrQueue->GetHandlerInfo(clsidDataHandler,&SyncMgrHandlerInfo))
  114. {
  115. continue;
  116. }
  117. // Insert the Parent.
  118. itemInfoParent.mask = LVIF_TEXT;
  119. itemInfoParent.iItem = LVI_LAST;;
  120. itemInfoParent.iSubItem = 0;
  121. itemInfoParent.iImage = -1;
  122. itemInfoParent.pszText = SyncMgrHandlerInfo.wszHandlerName;
  123. if (himageSmallIcon)
  124. {
  125. HICON hIcon = SyncMgrHandlerInfo.hIcon ? SyncMgrHandlerInfo.hIcon : offlineItem.hIcon;
  126. // if have toplevel handler info icon use this else use the
  127. // items icon
  128. if (hIcon && (itemInfoParent.iImage =
  129. ImageList_AddIcon(himageSmallIcon,hIcon)) )
  130. {
  131. itemInfoParent.mask |= LVIF_IMAGE ;
  132. }
  133. }
  134. // save the blob
  135. itemInfoParent.maskEx = LVIFEX_BLOB;
  136. itemInfoParent.pBlob = (LPLVBLOB) &lvHandlerItemBlob;
  137. iParentItemId = pItemListView->InsertItem(&itemInfoParent);
  138. // if parent insert failed go onto the next item
  139. if (-1 == iParentItemId)
  140. {
  141. continue;
  142. }
  143. }
  144. }
  145. // now attemp to insert the item.
  146. lvItemInfo.mask = LVIF_TEXT | LVIF_PARAM;
  147. lvItemInfo.maskEx = LVIFEX_PARENT | LVIFEX_BLOB;
  148. lvItemInfo.iItem = LVI_LAST;
  149. lvItemInfo.iSubItem = 0;
  150. lvItemInfo.iParent = iParentItemId;
  151. lvItemInfo.pszText = offlineItem.wszItemName;
  152. lvItemInfo.iImage = -1; // set to -1 in case can't get image.
  153. lvItemInfo.lParam = lparam;
  154. if (himageSmallIcon && offlineItem.hIcon)
  155. {
  156. lvItemInfo.iImage =
  157. 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,ARRAY_SIZE(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,ARRAY_SIZE(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
  229. // setitem State, must do after insert
  230. pItemListView->SetItemState(iListViewItem,lvItemInfo.state,LVIS_STATEIMAGEMASK);
  231. }
  232. }
  233. }
  234. // now loop through to see if any handlers that want to always show but don't
  235. // yet have any items have been added
  236. if (fHandlerParent)
  237. {
  238. LVHANDLERITEMBLOB lvHandlerItemBlob;
  239. int iParentItemId;
  240. HANDLERINFO *pHandlerID = 0;
  241. CLSID clsidDataHandler;
  242. while (NOERROR == pHndlrQueue->FindNextHandlerInState(pHandlerID,
  243. GUID_NULL,HANDLERSTATE_PREPAREFORSYNC,&pHandlerID
  244. ,&clsidDataHandler))
  245. {
  246. SYNCMGRHANDLERINFO SyncMgrHandlerInfo;
  247. // if can't get the ParentInfo then don't add.
  248. if (NOERROR != pHndlrQueue->GetHandlerInfo(clsidDataHandler,&SyncMgrHandlerInfo))
  249. {
  250. continue;
  251. }
  252. // only add if handler says too
  253. if (!(SYNCMGRHANDLER_ALWAYSLISTHANDLER &
  254. SyncMgrHandlerInfo.SyncMgrHandlerFlags))
  255. {
  256. continue;
  257. }
  258. // need to add to list so find parent and if one doesn't exist, create it.
  259. lvHandlerItemBlob.cbSize = sizeof(LVHANDLERITEMBLOB);
  260. lvHandlerItemBlob.clsidServer = clsidDataHandler;
  261. lvHandlerItemBlob.ItemID = GUID_NULL;
  262. iParentItemId = pItemListView->FindItemFromBlob((LPLVBLOB) &lvHandlerItemBlob);
  263. if (-1 == iParentItemId)
  264. {
  265. LVITEMEX itemInfoParent;
  266. // Insert the Parent.
  267. itemInfoParent.mask = LVIF_TEXT;
  268. itemInfoParent.iItem = LVI_LAST;;
  269. itemInfoParent.iSubItem = 0;
  270. itemInfoParent.iImage = -1;
  271. itemInfoParent.pszText = SyncMgrHandlerInfo.wszHandlerName;
  272. if (himageSmallIcon)
  273. {
  274. HICON hIcon = SyncMgrHandlerInfo.hIcon ? SyncMgrHandlerInfo.hIcon : NULL;
  275. // if have toplevel handler info icon use this else use the
  276. // items icon
  277. if (hIcon && (itemInfoParent.iImage =
  278. ImageList_AddIcon(himageSmallIcon,hIcon)) )
  279. {
  280. itemInfoParent.mask |= LVIF_IMAGE ;
  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. }