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.

251 lines
14 KiB

  1. //--------------------------------------------------------------------------
  2. // MsgTable.h
  3. //--------------------------------------------------------------------------
  4. #pragma once
  5. //--------------------------------------------------------------------------
  6. // Forward Decl.
  7. //--------------------------------------------------------------------------
  8. class CFindFolder;
  9. class CMessageTable;
  10. //--------------------------------------------------------------------------
  11. // SafeReleaseRow
  12. //--------------------------------------------------------------------------
  13. #define SafeReleaseRow(_pTable, _pMessage) \
  14. if (_pMessage) { \
  15. _pTable->ReleaseRow(_pMessage); \
  16. _pMessage = NULL; \
  17. }
  18. //--------------------------------------------------------------------------
  19. // WALKTHREADFLAGS
  20. //--------------------------------------------------------------------------
  21. typedef DWORD WALKTHREADFLAGS;
  22. #define WALK_THREAD_CURRENT 0x00000001
  23. #define WALK_THREAD_BOTTOMUP 0x00000020
  24. //--------------------------------------------------------------------------
  25. // SORTCHANGEINFO
  26. //--------------------------------------------------------------------------
  27. typedef struct tagSORTCHANGEINFO {
  28. BYTE fSort;
  29. BYTE fThread;
  30. BYTE fFilter;
  31. BYTE fExpand;
  32. } SORTCHANGEINFO, *LPSORTCHANGEINFO;
  33. //--------------------------------------------------------------------------
  34. // ROWINFO
  35. //--------------------------------------------------------------------------
  36. typedef struct tagROWINFO *LPROWINFO;
  37. typedef struct tagROWINFO {
  38. BYTE cRefs;
  39. ROWSTATE dwState;
  40. LPROWINFO pParent;
  41. LPROWINFO pChild;
  42. LPROWINFO pSibling;
  43. WORD wHighlight;
  44. unsigned fExpanded : 1; // A thread parent that is expanded
  45. unsigned fVisible : 1; // Is displayed in the m_prgpView index
  46. unsigned fFiltered : 1; // Filtered and won't be displayed until filter changes
  47. unsigned fHidden : 1; // Hidden, but if row is changed it may become visible.
  48. unsigned fDelayed : 1; // Delayed Insert
  49. MESSAGEINFO Message;
  50. } ROWINFO;
  51. //--------------------------------------------------------------------------
  52. // NOTIFYQUEUE
  53. //--------------------------------------------------------------------------
  54. typedef struct tagNOTIFYQUEUE {
  55. BOOL fClean;
  56. TRANSACTIONTYPE tyCurrent;
  57. ROWINDEX iRowMin;
  58. ROWINDEX iRowMax;
  59. DWORD cUpdate;
  60. DWORD cAllocated;
  61. DWORD cRows;
  62. BYTE fIsExpandCollapse;
  63. LPROWINDEX prgiRow;
  64. } NOTIFYQUEUE, *LPNOTIFYQUEUE;
  65. //--------------------------------------------------------------------------
  66. // PFWALKTHREADCALLBACK
  67. //--------------------------------------------------------------------------
  68. typedef HRESULT (APIENTRY *PFWALKTHREADCALLBACK)(CMessageTable *pThis,
  69. LPROWINFO pRow, DWORD_PTR dwCookie);
  70. //--------------------------------------------------------------------------
  71. // PFNENUMREFS
  72. //--------------------------------------------------------------------------
  73. typedef HRESULT (APIENTRY *PFNENUMREFS)(LPCSTR pszMessageId, DWORD_PTR dwCookie,
  74. BOOL *pfDone);
  75. //--------------------------------------------------------------------------
  76. // CMessageTable
  77. //--------------------------------------------------------------------------
  78. class CMessageTable : public IMessageTable,
  79. public IDatabaseNotify,
  80. public IServiceProvider,
  81. public IOperationCancel
  82. {
  83. public:
  84. //----------------------------------------------------------------------
  85. // Construction
  86. //----------------------------------------------------------------------
  87. CMessageTable(void);
  88. ~CMessageTable(void);
  89. //----------------------------------------------------------------------
  90. // IUnknown Members
  91. //----------------------------------------------------------------------
  92. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  93. STDMETHODIMP_(ULONG) AddRef(void);
  94. STDMETHODIMP_(ULONG) Release(void);
  95. //----------------------------------------------------------------------
  96. // IMessageTable Members
  97. //----------------------------------------------------------------------
  98. STDMETHODIMP Initialize(FOLDERID idFolder, IMessageServer *pServer, BOOL fFindTable, IStoreCallback *pCallback);
  99. STDMETHODIMP StartFind(LPFINDINFO pCriteria, IStoreCallback *pCallback);
  100. STDMETHODIMP SetOwner(IStoreCallback *pDefaultCallback);
  101. STDMETHODIMP Close(void);
  102. STDMETHODIMP Synchronize(SYNCFOLDERFLAGS dwFlags, DWORD cHeaders, IStoreCallback *pCallback);
  103. STDMETHODIMP OnSynchronizeComplete(void);
  104. STDMETHODIMP GetCount(GETCOUNTTYPE tyCount, DWORD *pdwCount);
  105. STDMETHODIMP GetRow(ROWINDEX iRow, LPMESSAGEINFO *ppData);
  106. STDMETHODIMP ReleaseRow(LPMESSAGEINFO pInfo);
  107. STDMETHODIMP GetRelativeRow(ROWINDEX iRow, RELATIVEROWTYPE tyRelative, LPROWINDEX piRelative);
  108. STDMETHODIMP GetIndentLevel(ROWINDEX iRow, LPDWORD pcIndent);
  109. STDMETHODIMP Mark(LPROWINDEX prgiView, DWORD cRows, APPLYCHILDRENTYPE tyApply, MARK_TYPE mark, IStoreCallback *pCallback);
  110. STDMETHODIMP GetSortInfo(LPFOLDERSORTINFO pSortInfo);
  111. STDMETHODIMP SetSortInfo(LPFOLDERSORTINFO pSortInfo, IStoreCallback *pCallback);
  112. STDMETHODIMP GetLanguage(ROWINDEX iRow, LPDWORD pdwCodePage);
  113. STDMETHODIMP SetLanguage(DWORD cRows, LPROWINDEX prgiRow, DWORD dwCodePage);
  114. STDMETHODIMP GetNextRow(ROWINDEX iCurrentRow, GETNEXTTYPE tyDirection, ROWMESSAGETYPE tyMessage, GETNEXTFLAGS dwFlags, LPROWINDEX piNewRow);
  115. STDMETHODIMP GetRowState(ROWINDEX iRow, ROWSTATE dwStateMask, ROWSTATE *pdwState);
  116. STDMETHODIMP GetSelectionState(DWORD cRows, LPROWINDEX prgiView, SELECTIONSTATE dwMask, BOOL fIncludeChildren, SELECTIONSTATE *pdwState);
  117. STDMETHODIMP Expand(ROWINDEX iRow);
  118. STDMETHODIMP Collapse(ROWINDEX iRow);
  119. STDMETHODIMP OpenMessage(ROWINDEX iRow, OPENMESSAGEFLAGS dwFlags, IMimeMessage **ppMessage, IStoreCallback *pCallback);
  120. STDMETHODIMP GetRowMessageId(ROWINDEX iRow, LPMESSAGEID pidMessage);
  121. STDMETHODIMP GetRowIndex(MESSAGEID idMessage, LPROWINDEX piView);
  122. STDMETHODIMP DeleteRows(DELETEMESSAGEFLAGS dwFlags, DWORD cRows, LPROWINDEX prgiView, BOOL fIncludeChildren, IStoreCallback *pCallback);
  123. STDMETHODIMP CopyRows(FOLDERID idFolder, COPYMESSAGEFLAGS dwOptions, DWORD cRows, LPROWINDEX prgiView, LPADJUSTFLAGS pFlags, IStoreCallback *pCallback);
  124. STDMETHODIMP RegisterNotify(REGISTERNOTIFYFLAGS dwFlags, IMessageTableNotify *pNotify);
  125. STDMETHODIMP UnregisterNotify(IMessageTableNotify *pNotify);
  126. STDMETHODIMP FindNextRow(ROWINDEX iStartRow, LPCTSTR pszFindString, FINDNEXTFLAGS dwFlags, BOOL fIncludeBody, ROWINDEX *piNextRow, BOOL *pfWrapped);
  127. STDMETHODIMP GetRowFolderId(ROWINDEX iRow, LPFOLDERID pidFolder);
  128. STDMETHODIMP GetMessageIdList(BOOL fRootsOnly, DWORD cRows, LPROWINDEX prgiView, LPMESSAGEIDLIST pIdList);
  129. STDMETHODIMP ConnectionAddRef(void);
  130. STDMETHODIMP ConnectionRelease(void);
  131. STDMETHODIMP IsChild(ROWINDEX iRowParent, ROWINDEX iRowChild);
  132. STDMETHODIMP GetAdBarUrl(IStoreCallback *pCallback);
  133. //----------------------------------------------------------------------
  134. // IDatabaseNotify
  135. //----------------------------------------------------------------------
  136. STDMETHODIMP OnTransaction(HTRANSACTION hTransaction, DWORD_PTR dwCookie, IDatabase *pDB);
  137. //----------------------------------------------------------------------
  138. // IServiceProvider
  139. //----------------------------------------------------------------------
  140. STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, LPVOID *ppvObject);
  141. //----------------------------------------------------------------------
  142. // IOperationCancel
  143. //----------------------------------------------------------------------
  144. STDMETHODIMP Cancel(CANCELTYPE tyCancel) { return(S_OK); }
  145. private:
  146. //----------------------------------------------------------------------
  147. // Private Methods
  148. //----------------------------------------------------------------------
  149. HRESULT _CreateRow(LPMESSAGEINFO pMessage, LPROWINFO *ppRow);
  150. HRESULT _InsertRowIntoThread(LPROWINFO pRow, BOOL fNotify);
  151. HRESULT _DeleteRowFromThread(LPROWINFO pRow, BOOL fNotify);
  152. HRESULT _FreeTable(void);
  153. HRESULT _FreeTableElements(void);
  154. HRESULT _BuildTable(IStoreCallback *pCallback);
  155. HRESULT _WalkMessageThread(LPROWINFO pRow, WALKTHREADFLAGS dwFlags, DWORD_PTR dwCookie, PFWALKTHREADCALLBACK pfnCallback);
  156. HRESULT _RowTableInsert(ROWORDINAL iOrdinal, LPMESSAGEINFO pMessage);
  157. HRESULT _RowTableDelete(ROWORDINAL iOrdinal, LPMESSAGEINFO pMessage);
  158. HRESULT _RowTableUpdate(ROWORDINAL iOrdinal, LPMESSAGEINFO pMessage);
  159. HRESULT _GetRowFromIndex(ROWINDEX iRow, LPROWINFO *ppRow);
  160. HRESULT _LinkRowIntoThread(LPROWINFO pParent, LPROWINFO pRow, BOOL fNotify);
  161. HRESULT _GrowIdList(LPMESSAGEIDLIST pList, DWORD cNeeded);
  162. HRESULT _ExpandThread(ROWINDEX iRow, BOOL fNotify, BOOL fReExpand);
  163. HRESULT _ExpandSingleThread(LPROWINDEX piCurrent, LPROWINFO pParent, BOOL fNotify, BOOL fForceExpand);
  164. HRESULT _CollapseThread(ROWINDEX iRow, BOOL fNotify);
  165. HRESULT _CollapseSingleThread(LPROWINDEX piCurrent, LPROWINFO pParent, BOOL fNotify);
  166. HRESULT _InsertIntoView(ROWINDEX iRow, LPROWINFO pRow);
  167. HRESULT _DeleteFromView(ROWINDEX iRow, LPROWINFO pRow);
  168. HRESULT _GetRowFromOrdinal(ROWORDINAL iOrdinal, LPMESSAGEINFO pExpected, LPROWINFO *ppRow);
  169. HRESULT _AdjustUnreadCount(LPROWINFO pRow, LONG lCount);
  170. HRESULT _GetThreadIndexRange(LPROWINFO pRow, BOOL fClearState, LPROWINDEX piMin, LPROWINDEX piMax);
  171. HRESULT _IsThreadImportance(LPROWINFO pRow, MESSAGEFLAGS dwFlag, ROWSTATE dwState, ROWSTATE *pdwState);
  172. HRESULT _QueueNotification(TRANSACTIONTYPE tyTransaction, ROWINDEX iRowMin, ROWINDEX iRowMax, BOOL fIsExpandCollapse=FALSE);
  173. HRESULT _FlushNotificationQueue(BOOL fFinal);
  174. HRESULT _GetSortChangeInfo(LPFOLDERSORTINFO pSortInfo, LPFOLDERUSERDATA pUserData, LPSORTCHANGEINFO pChange);
  175. HRESULT _SortThreadFilterTable(LPSORTCHANGEINFO pChange, BOOL fApplyFilter);
  176. HRESULT _SortAndThreadTable(BOOL fApplyFilter);
  177. HRESULT _HideRow(LPROWINFO pRow, BOOL fNotify);
  178. HRESULT _ShowRow(LPROWINFO pRow);
  179. HRESULT _PruneToReplies(void);
  180. HRESULT _FindThreadParentByRef(LPCSTR pszReferences, LPROWINFO *ppParent);
  181. HRESULT _RefreshFilter(void);
  182. //----------------------------------------------------------------------
  183. // Utilities
  184. //----------------------------------------------------------------------
  185. VOID _SortView(LONG left, LONG right);
  186. LONG _CompareMessages(LPMESSAGEINFO pMsg1, LPMESSAGEINFO pMsg2);
  187. BOOL _FIsFiltered(LPROWINFO pRow);
  188. BOOL _FIsHidden(LPROWINFO pRow);
  189. LPROWINFO _PGetThreadRoot(LPROWINFO pRow);
  190. //----------------------------------------------------------------------
  191. // Friends
  192. //----------------------------------------------------------------------
  193. static HRESULT _WalkThreadGetSelectionState(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  194. static HRESULT _WalkThreadGetIdList(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  195. static HRESULT _WalkThreadGetState(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  196. static HRESULT _WalkThreadClearState(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  197. static HRESULT _WalkThreadIsFromMe(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  198. static HRESULT _WalkThreadHide(CMessageTable *pThis, LPROWINFO pRow, DWORD_PTR dwCookie);
  199. private:
  200. //----------------------------------------------------------------------
  201. // Private Data
  202. //----------------------------------------------------------------------
  203. LONG m_cRef; // Reference Counting
  204. BOOL m_fSynching; // Are we synching a folder ?
  205. DWORD m_cAllocated; // Allocated elements in m_prgRow and m_prgiView
  206. DWORD m_cRows; // Rows...
  207. DWORD m_cView; // Number of items in the listview
  208. DWORD m_cFiltered; // Number of rows that were filtered
  209. DWORD m_cUnread; // Number of unread rows in m_prgpRow
  210. LPROWINFO *m_prgpRow; // Array of Pointers to Rows
  211. LPROWINFO *m_prgpView; // Current View
  212. FOLDERSORTINFO m_SortInfo; // Folder Sort Info
  213. IMessageFolder *m_pFolder; // Base Folder
  214. IDatabase *m_pDB; // The Database
  215. CFindFolder *m_pFindFolder; // Find Folder
  216. IMessageTableNotify *m_pNotify; // usually the message list
  217. BYTE m_fRelNotify; // Release m_pNotify?
  218. IDatabaseQuery *m_pQuery; // Query Object
  219. NOTIFYQUEUE m_Notify; // Notify Queue
  220. FOLDERINFO m_Folder; // Folder Information
  221. DWORD m_cDelayed; // Number of news messages not insert into view
  222. BYTE m_fRegistered; // Registered for Notifications
  223. BYTE m_fLoaded; // The first load has completed.
  224. WORD m_clrWatched; // Watched Color
  225. LPSTR m_pszEmail; // Email Address to use for show replies filter
  226. IHashTable *m_pThreadMsgId; // Message-ID Hash Table for Threading
  227. IHashTable *m_pThreadSubject; // Message-ID Hash Table for Threading
  228. };
  229. //--------------------------------------------------------------------------
  230. // Prototypes
  231. //--------------------------------------------------------------------------
  232. HRESULT EnumerateRefs(LPCSTR pszReferences, DWORD_PTR dwCookie, PFNENUMREFS pfnEnumRefs);