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.

434 lines
18 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: Dlg.h
  7. //
  8. // Contents: Dialog box classes
  9. //
  10. // Classes: CBaseDlg
  11. // CChoiceDlg
  12. // CProgressDlg
  13. //
  14. // Notes:
  15. //
  16. // History: 05-Nov-97 rogerg Created.
  17. //
  18. //--------------------------------------------------------------------------
  19. #ifndef _ONESTOPDLG_
  20. #define _ONESTOPDLG_
  21. //Used for item data on Progress Results UI
  22. // !!!!Warning - Automated test look at this structure directly
  23. // If you change it you need to notify Testing so they can also
  24. // Update their tests
  25. typedef struct tagLBDATA
  26. {
  27. BOOL fTextRectValid; // flag to indicate if rcText has been calculated.
  28. RECT rcTextHitTestRect; // rectangle for hitTesting.
  29. RECT rcText; // total bounding box of text to use for draw
  30. INT IconIndex;
  31. BOOL fIsJump;
  32. BOOL fHasBeenClicked;
  33. BOOL fAddLineSpacingAtEnd; // set if should leave space after item
  34. HANDLERINFO * pHandlerID;
  35. SYNCMGRERRORID ErrorID;
  36. DWORD dwErrorLevel; // Error level of this item
  37. TCHAR pszText[1]; // errorText, dynamic array.
  38. } LBDATA;
  39. // cmdIds passed ot the ReleaseDlg method
  40. #define RELEASEDLGCMDID_DESTROY 0 // cmdid send when dialog was destroyed before added to list
  41. #define RELEASEDLGCMDID_DEFAULT 1 // cmdid sent if cmd hasn't been explicitly set.
  42. #define RELEASEDLGCMDID_OK 2 // treated as if user Pressed Okay
  43. #define RELEASEDLGCMDID_CANCEL 3 // treated as if user pressed Cancel
  44. // helper utilities
  45. BOOL AddItemsFromQueueToListView(CListView *pItemListView,CHndlrQueue *pHndlrQueue
  46. ,DWORD dwExtStyle,LPARAM lparam,int iDateColumn,int iStatusColumn,BOOL fHandlerParent
  47. ,BOOL fAddOnlyCheckedItems);
  48. typedef struct _tagDlgResizeList
  49. {
  50. int iCtrlId;
  51. DWORD dwDlgResizeFlags;
  52. } DlgResizeList;
  53. // structure passed as lParam to call completion routine.
  54. // must free after processin the message
  55. // CallCompletion message declarations.
  56. // DWORD dwThreadMsg; // passed as wParam.
  57. typedef struct _tagCALLCOMPLETIONMSGLPARAM
  58. {
  59. HRESULT hCallResult;
  60. CLSID clsidHandler;
  61. SYNCMGRITEMID itemID;
  62. } CALLCOMPLETIONMSGLPARAM , *LPCALLCOMPLETIONMSGLPARAM;
  63. // base class both dialogs derive from
  64. #define CHOICELIST_NAMECOLUMN 0
  65. #define CHOICELIST_LASTUPDATECOLUMN 1
  66. #define PROGRESSLIST_NAMECOLUMN 0
  67. #define PROGRESSLIST_STATUSCOLUMN 1
  68. #define PROGRESSLIST_INFOCOLUMN 2
  69. #define PROGRESS_TAB_UPDATE 0
  70. #define PROGRESS_TAB_ERRORS 1
  71. class CBaseDlg
  72. {
  73. public:
  74. HWND m_hwnd;
  75. DWORD m_dwThreadID;
  76. BOOL m_fForceClose; // passed in generic release.
  77. BOOL m_fHwndRightToLeft;
  78. inline HWND GetHwnd() { return m_hwnd; };
  79. virtual BOOL Initialize(DWORD dwThreadID,int nCmdShow) = 0;
  80. virtual void ReleaseDlg(WORD wCommandID) = 0;
  81. virtual void UpdateWndPosition(int nCmdShow,BOOL fForce)= 0;
  82. // make HandleLogError as a base dialog class so can call it from queue and
  83. // other locations without worrying about the dialog type.
  84. virtual void HandleLogError(HWND hwnd,HANDLERINFO *pHandlerID,MSGLogErrors *lpmsgLogErrors) = 0;
  85. virtual void PrivReleaseDlg(WORD wCommandID) = 0;
  86. virtual void CallCompletionRoutine(DWORD dwThreadMsg,LPCALLCOMPLETIONMSGLPARAM lpCallCompletelParam) = 0;
  87. virtual HRESULT QueryCanSystemShutdown(/* [out] */ HWND *phwnd, /* [out] */ UINT *puMessageId,
  88. /* [out] */ BOOL *pfLetUserDecide) = 0;
  89. };
  90. // Messages Shared between both dialogs
  91. #define WM_BASEDLG_SHOWWINDOW (WM_USER + 3)
  92. #define WM_BASEDLG_COMPLETIONROUTINE (WM_USER + 4)
  93. #define WM_BASEDLG_HANDLESYSSHUTDOWN (WM_USER + 5)
  94. #define WM_BASEDLG_NOTIFYLISTVIEWEX (WM_USER + 6)
  95. #define WM_BASEDLG_LAST WM_BASEDLG_NOTIFYLISTVIEWEX
  96. // choice dialog messages
  97. #define WM_CHOICE_FIRST (WM_BASEDLG_LAST + 1)
  98. #define WM_CHOICE_SETQUEUEDATA (WM_CHOICE_FIRST + 1)
  99. #define WM_CHOICE_RELEASEDLGCMD (WM_CHOICE_FIRST + 2)
  100. #define WM_CHOICE_LAST WM_CHOICE_RELEASEDLGCMD
  101. // progress dialog messages
  102. #define WM_PROGRESS_FIRST (WM_CHOICE_LAST + 1)
  103. #define WM_PROGRESS_UPDATE (WM_PROGRESS_FIRST + 1)
  104. #define WM_PROGRESS_LOGERROR (WM_PROGRESS_FIRST + 2)
  105. #define WM_PROGRESS_DELETELOGERROR (WM_PROGRESS_FIRST + 3)
  106. #define WM_PROGRESS_STARTPROGRESS (WM_PROGRESS_FIRST + 4)
  107. #define WM_PROGRESS_RELEASEDLGCMD (WM_PROGRESS_FIRST + 5)
  108. #define WM_PROGRESS_TRANSFERQUEUEDATA (WM_PROGRESS_FIRST + 6)
  109. #define WM_PROGRESS_SHELLTRAYNOTIFICATION (WM_PROGRESS_FIRST + 7)
  110. #define WM_PROGRESS_SHUTDOWN (WM_PROGRESS_FIRST + 8)
  111. #define WM_PROGRESS_RESETKILLHANDLERSTIMER (WM_PROGRESS_FIRST + 9)
  112. // helper macros for sending window messages
  113. #define BASEDLG_SHOWWINDOW(hwnd,nCmdShow) SendMessage(hwnd,WM_BASEDLG_SHOWWINDOW,nCmdShow,0);
  114. BOOL CALLBACK CChoiceDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  115. LPARAM lParam);
  116. typedef struct _tagSetQueueDataInfo
  117. {
  118. const CLSID *rclsid;
  119. CHndlrQueue * pHndlrQueue;
  120. } SetQueueDataInfo;
  121. #define NUM_DLGRESIZEINFOCHOICE 6 // make sure update if change numitems
  122. class CChoiceDlg : public CBaseDlg
  123. {
  124. public:
  125. CChoiceDlg(REFCLSID rclsid);
  126. BOOL Initialize(DWORD dwThreadID,int nCmdShow); // called to initialize the choice dialog
  127. BOOL SetQueueData(REFCLSID rclsid,CHndlrQueue * pHndlrQueue);
  128. void ReleaseDlg(WORD wCommandID);
  129. void UpdateWndPosition(int nCmdShow,BOOL fForce);
  130. HRESULT QueryCanSystemShutdown(/* [out] */ HWND *phwnd, /* [out] */ UINT *puMessageId,
  131. /* [out] */ BOOL *pfLetUserDecide);
  132. void HandleLogError(HWND hwnd,HANDLERINFO *pHandlerID,MSGLogErrors *lpmsgLogErrors);
  133. void PrivReleaseDlg(WORD wCommandID);
  134. void CallCompletionRoutine(DWORD dwThreadMsg,LPCALLCOMPLETIONMSGLPARAM lpCallCompletelParam);
  135. private:
  136. BOOL PrivSetQueueData(REFCLSID rclsid,CHndlrQueue * pHndlrQueue);
  137. BOOL SetButtonState(int nIDDlgItem,BOOL fEnabled);
  138. int CalcListViewWidth(HWND hwndList);
  139. BOOL OnInitialize(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
  140. void OnClose(UINT uMsg,WPARAM wParam,LPARAM lParam);
  141. void OnCommand(UINT uMsg,WPARAM wParam,LPARAM lParam);
  142. void OnGetMinMaxInfo(UINT uMsg,WPARAM wParam,LPARAM lParam);
  143. void OnSize(UINT uMsg,WPARAM wParam,LPARAM lParam);
  144. LRESULT OnNotifyListViewEx(UINT uMsg,WPARAM wParam,LPARAM lParam);
  145. LRESULT OnNotify(UINT uMsg,WPARAM wParam,LPARAM lParam);
  146. void OnHelp(UINT uMsg,WPARAM wParam,LPARAM lParam);
  147. void OnContextMenu(UINT uMsg,WPARAM wParam,LPARAM lParam);
  148. void OnSetQueueData(UINT uMsg,WPARAM wParam,LPARAM lParam);
  149. void OnStartCommand(UINT uMsg,WPARAM wParam,LPARAM lParam);
  150. void OnPropertyCommand(UINT uMsg,WPARAM wParam,LPARAM lParam);
  151. // Set QueueData has to be in sync with
  152. BOOL ShowChoiceDialog();
  153. BOOL AddNewItemsToListView();
  154. HRESULT ShowProperties(int iItem);
  155. CHndlrQueue *m_pHndlrQueue;
  156. BOOL m_fDead;
  157. int m_nCmdShow; // How to show dialog, same flags pased to ShowWindow.
  158. BOOL m_fInternalAddref; // bool to indicate if dialog has placed an addref on self.
  159. DWORD m_dwShowPropertiesCount; // keeps track of number of show properties open.
  160. CLSID m_clsid; // clsid associated with this dialog.
  161. ULONG m_ulNumDlgResizeItem;
  162. DLGRESIZEINFO m_dlgResizeInfo[NUM_DLGRESIZEINFOCHOICE];
  163. POINT m_ptMinimizeDlgSize;
  164. CListView *m_pItemListView;
  165. friend BOOL CALLBACK CChoiceDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam,
  166. LPARAM lParam);
  167. };
  168. // structures for dialog messages
  169. // wparam of the progress update message,
  170. // lparam of the Update is teh SYNCPROGRESSITEM.
  171. typedef struct _tagPROGRESSUPDATEDATA
  172. {
  173. HANDLERINFO *pHandlerID;
  174. WORD wItemId;
  175. CLSID clsidHandler;
  176. SYNCMGRITEMID ItemID;
  177. } PROGRESSUPDATEDATA;
  178. // flags for keeping track of progress dlg state.
  179. // make sure all flags are unique bits.
  180. typedef enum _tagPROGRESSFLAG
  181. {
  182. // general state of the dialog
  183. PROGRESSFLAG_NEWDIALOG = 0x01, // dialog is new and no items have been added yet.
  184. PROGRESSFLAG_TRANSFERADDREF = 0x02, // an addref has been placed on dialog by queue items getting trasferred.
  185. PROGRESSFLAG_SYNCINGITEMS = 0x04, // process of synchronizing items in queue has started but not finished.
  186. PROGRESSFLAG_INCANCELCALL = 0x08, // cancel call is in progress.
  187. PROGRESSFLAG_CANCELWHILESHUTTINGDOWN = 0x10, // cancel was pressed while in shutdownloop
  188. PROGRESSFLAG_DEAD = 0x20, // done with dialog no methods should be called.
  189. PROGRESSFLAG_CALLBACKPOSTED = 0x40, // at leasted on callback message is in the queue.
  190. PROGRESSFLAG_STARTPROGRESSPOSTED = 0x80, // anyone who posts a start process check this before posting
  191. // flags used by main sync loop to figure out what to do next.
  192. PROGRESSFLAG_NEWITEMSINQUEUE = 0x0100, // new items have been placed in the queue.
  193. PROGRESSFLAG_IDLENETWORKTIMER = 0x0200, // idle timer has been setup for network idles.
  194. PROGRESSFLAG_PROGRESSANIMATION = 0x0400, // progress animatiion has been turned on.
  195. PROGRESSFLAG_SHUTTINGDOWNLOOP = 0x0800, // set when no more items in queue and starting shutdown process
  196. PROGRESSFLAG_INHANDLEROUTCALL = 0x1000, // set when in main loop and making an out call.
  197. PROGRESSFLAG_COMPLETIONROUTINEWHILEINOUTCALL = 0x2000, // set in callback when handler is already in an out calll.
  198. PROGRESSFLAG_INSHOWERRORSCALL = 0x4000, // set when in showerrors call
  199. PROGRESSFLAG_SHOWERRORSCALLBACKCALLED = 0x8000, // set when showerrors callback comes in while still in original cal.
  200. // flags used to keep track of Idle state (if any)
  201. PROGRESSFLAG_REGISTEREDFOROFFIDLE = 0x010000, // off idle callback has been registered.
  202. PROGRESSFLAG_RECEIVEDOFFIDLE = 0x020000, // queue has receive the offIdle event
  203. PROGRESSFLAG_IDLERETRYENABLED = 0x040000, // retry on idle has been set.
  204. PROGRESSFLAG_INOFFIDLE = 0x080000, // set when handling an offidle
  205. PROGRESSFLAG_CANCELPRESSED = 0x100000, // set when cancel has been pressed and never reset.
  206. //flag used to terminate unresponsive hanlders
  207. PROGRESSFLAG_INTERMINATE = 0x200000 //We are terminating unresponsive handlers.
  208. } PROGRESSFLAG;
  209. BOOL CALLBACK ProgressWndProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam);
  210. #define NUM_DLGRESIZEINFO_PROGRESS 15
  211. #define NUM_DLGRESIZEINFO_PROGRESS_COLLAPSED 7
  212. #define NUM_PROGRESS_ERRORIMAGES 3
  213. /////////////////////////////////////////////////////////////////////////////
  214. // Images
  215. //
  216. typedef enum _tagErrorImageIndex
  217. {
  218. ErrorImage_Information = 0,
  219. ErrorImage_Warning = 1,
  220. ErrorImage_Error = 2,
  221. } ErrorImageIndex;
  222. enum {
  223. IMAGE_TACK_IN = 0,
  224. IMAGE_TACK_OUT
  225. };
  226. class CProgressDlg : public CBaseDlg
  227. {
  228. public:
  229. CProgressDlg(REFCLSID rclsid);
  230. BOOL Initialize(DWORD dwThreadID,int nCmdShow);
  231. // transfer queue has to be synced with person doing the transfer.
  232. STDMETHODIMP TransferQueueData(CHndlrQueue *HndlrQueue);
  233. void ReleaseDlg(WORD wCommandID);
  234. void UpdateWndPosition(int nCmdShow,BOOL fForce);
  235. void HandleLogError(HWND hwnd,HANDLERINFO *pHandlerID,MSGLogErrors *lpmsgLogErrors);
  236. void HandleDeleteLogError(HWND hwnd,MSGDeleteLogErrors *pDeleteLogError);
  237. void CallCompletionRoutine(DWORD dwThreadMsg,LPCALLCOMPLETIONMSGLPARAM lpCallCompletelParam);
  238. HRESULT QueryCanSystemShutdown(/* [out] */ HWND *phwnd, /* [out] */ UINT *puMessageId,
  239. /* [out] */ BOOL *pfLetUserDecide);
  240. void PrivReleaseDlg(WORD wCommandID);
  241. void OffIdle();
  242. void OnIdle();
  243. void SetIdleParams( ULONG m_ulIdleRetryMinutes,ULONG m_ulDelayIdleShutDownTime,BOOL fRetryEnabled);
  244. private:
  245. STDMETHODIMP_(ULONG) AddRefProgressDialog();
  246. STDMETHODIMP_(ULONG) ReleaseProgressDialog(BOOL fForce);
  247. // methods called from the wndProc
  248. BOOL InitializeHwnd(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
  249. BOOL OnCommand(HWND hwnd, WORD wID, WORD wNotifyCode);
  250. BOOL OnSysCommand(UINT uMsg,WPARAM wParam,LPARAM lParam);
  251. void OnTimer(UINT uMsg,WPARAM wParam,LPARAM lParam);
  252. void OnTaskBarCreated(UINT uMsg,WPARAM wParam,LPARAM lParam);
  253. void OnPaint(UINT uMsg,WPARAM wParam,LPARAM lParam);
  254. void OnShellTrayNotification(UINT uMsg,WPARAM wParam,LPARAM lParam);
  255. void OnClose(UINT uMsg,WPARAM wParam,LPARAM lParam);
  256. void OnSize(UINT uMsg,WPARAM wParam,LPARAM lParam);
  257. void OnGetMinMaxInfo(UINT uMsg,WPARAM wParam,LPARAM lParam);
  258. void OnMoving(UINT uMsg,WPARAM wParam,LPARAM lParam);
  259. void OnCommand(UINT uMsg,WPARAM wParam,LPARAM lParam);
  260. LRESULT OnNotify(UINT uMsg,WPARAM wParam,LPARAM lParam);
  261. BOOL OnContextMenu(UINT uMsg,WPARAM wParam,LPARAM lParam);
  262. BOOL OnPowerBroadcast(UINT uMsg,WPARAM wParam,LPARAM lParam);
  263. LRESULT OnNotifyListViewEx(UINT uMsg,WPARAM wParam,LPARAM lParam);
  264. void OnResetKillHandlersTimers(void);
  265. STDMETHODIMP PrivTransferQueueData(CHndlrQueue *HndlrQueue);
  266. BOOL KeepProgressAlive();
  267. void OnCancel(BOOL fOffIdle);
  268. STDMETHODIMP CreateListViewItem(HWND hwnd,HANDLERINFO *pHandlerID,REFCLSID clsidHandler,SYNCMGRITEM *pofflineItem, INT *piListViewItem, INT iItem);
  269. STDMETHODIMP OnShowError(HANDLERINFO *pHandlerId,HWND hWndParent,REFSYNCMGRERRORID ErrorID);
  270. BOOL RedrawIcon();
  271. void ShowProgressTab(int iTab);
  272. void UpdateProgressValues();
  273. STDMETHODIMP PrepareNewItemsForSync(void);
  274. void DoSyncTask(HWND hwnd);
  275. void HandleProgressUpdate(HWND hwnd, WPARAM wParam,LPARAM lParam);
  276. void ExpandCollapse(BOOL fExpand, BOOL fForce);
  277. BOOL InitializeTabs(HWND hwnd);
  278. BOOL InitializeToolbar(HWND hwnd);
  279. BOOL InitializeUpdateList(HWND hwnd);
  280. BOOL InitializeResultsList(HWND hwnd);
  281. BOOL ShowCompletedProgress(BOOL fComplete,BOOL fDialogIsLocked);
  282. BOOL AnimateTray(BOOL fTayAdded);
  283. BOOL RegisterShellTrayIcon(BOOL fRegister);
  284. BOOL UpdateTrayIcon();
  285. BOOL SetButtonState(int nIDDlgItem,BOOL fEnabled);
  286. BOOL IsItemWorking(int iListViewItem);
  287. void UpdateDetailsInfo(DWORD dwStatusType,int iItem, TCHAR *pszItemInfo);
  288. void AddListData(LBDATA *pData, int iNumChars, HWND hwndList);
  289. private:
  290. LONG m_cInternalcRefs;
  291. LONG m_lTimerSet;
  292. HWND m_hwndTabs;
  293. WNDPROC m_fnResultsListBox; // function for ListBoxSubClass.
  294. BOOL m_fSensInstalled;
  295. // variables for resizing.
  296. DLGRESIZEINFO m_dlgResizeInfo[NUM_DLGRESIZEINFO_PROGRESS];
  297. ULONG m_cbNumDlgResizeItemsCollapsed;
  298. ULONG m_cbNumDlgResizeItemsExpanded;
  299. POINT m_ptMinimumDlgExpandedSize; // minimum size dialog can be in expanded mode.
  300. DWORD m_cyCollapsed; // min Height of the collapsed dialog
  301. BOOL m_fExpanded; // TRUE if the details part of the dialog is visible
  302. BOOL m_fPushpin; //Pushpin state
  303. BOOL m_fMaximized; // set to true when the window has been maximized.
  304. RECT m_rcDlg; // Size of the fully expanded dialog
  305. HIMAGELIST m_errorimage;
  306. int m_iIconMetricX;
  307. int m_iIconMetricY;
  308. INT m_ErrorImages[NUM_PROGRESS_ERRORIMAGES];
  309. INT m_iProgressSelectedItem;
  310. INT m_iResultCount;
  311. INT m_iInfoCount;
  312. INT m_iWarningCount;
  313. INT m_iErrorCount;
  314. LBDATA *m_CurrentListEntry;
  315. int m_iLastItem;
  316. DWORD m_dwLastStatusType;
  317. INT m_iTab; // The index of the current tab
  318. CHndlrQueue *m_HndlrQueue;
  319. // Idle specific members
  320. CSyncMgrIdle *m_pSyncMgrIdle;
  321. ULONG m_ulIdleRetryMinutes;
  322. ULONG m_ulDelayIdleShutDownTime;
  323. DWORD m_dwProgressFlags;
  324. DWORD m_dwShowErrorRefCount; // number of RefCounts showError calls have on the dialog.
  325. DWORD m_dwSetItemStateRefCount; // number of RefCounts SetItemState OutCall has on the dialog.
  326. DWORD m_dwHandleThreadNestcount; // make sure main handler thread isn't re-entrant
  327. DWORD m_dwPrepareForSyncOutCallCount; // number of prepareForSyncs in progress.
  328. DWORD m_dwSynchronizeOutCallCount; // number of prepareForSyncs in progress.
  329. DWORD m_dwHandlerOutCallCount; // total number of outcalls in progress.
  330. CLSID m_clsidHandlerInSync; // clsid associated with handler that is currently synchronizing.
  331. DWORD m_dwQueueTransferCount; // number of queue transfers in progress.
  332. BOOL m_fHasShellTrayIcon;
  333. BOOL m_fAddedIconToTray;
  334. int m_iTrayAniFrame;
  335. CLSID m_clsid; // clsid associated with this dialog.
  336. INT m_iItem; // index to any new item to the list box.
  337. int m_nCmdShow; // How to show dialog, same flags pased to ShowWindow.
  338. CListView *m_pItemListView;
  339. UINT m_nKillHandlerTimeoutValue; // TimeoutValue for ForceKill
  340. TCHAR m_pszStatusText[8][MAX_STRING_RES + 1];
  341. friend BOOL CALLBACK ProgressWndProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam);
  342. friend BOOL OnProgressUpdateNotify(HWND hwnd,CProgressDlg *pProgress, int idFrom, LPNMHDR pnmhdr);
  343. friend BOOL OnProgressResultsDrawItem(HWND hwnd,CProgressDlg *pProgress,UINT idCtl, const DRAWITEMSTRUCT* lpDrawItem);
  344. friend BOOL OnProgressResultsNotify(HWND hwnd,CProgressDlg *pProgress, int idFrom, LPNMHDR pnmhdr);
  345. friend BOOL CALLBACK ResultsListBoxWndProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam);
  346. friend BOOL CALLBACK ResultsProgressWndProc(HWND hwnd, UINT uMsg,WPARAM wParam,LPARAM lParam);
  347. friend BOOL OnProgressResultsMeasureItem(HWND hwnd,CProgressDlg *pProgress, UINT *horizExtent, UINT idCtl, MEASUREITEMSTRUCT *pMeasureItem);
  348. };
  349. #endif // _ONESTOPDLG_