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.

450 lines
11 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1996.
  5. //
  6. // File: sdetails.cxx
  7. //
  8. // Contents: implementation of IShellDetails
  9. //
  10. // Classes: CJobsSD
  11. //
  12. // Functions:
  13. //
  14. // History: 1/4/1996 RaviR Created
  15. //
  16. //____________________________________________________________________________
  17. #include "..\pch\headers.hxx"
  18. #pragma hdrstop
  19. #include "dbg.h"
  20. #include "macros.h"
  21. #include "resource.h"
  22. #include "dll.hxx"
  23. #include "jobidl.hxx"
  24. #include "util.hxx"
  25. #include "common.hxx"
  26. //
  27. // extern
  28. //
  29. extern HINSTANCE g_hInstance;
  30. //////////////////////////////////////////////////////////////////////////////
  31. // Forward declaration of local functions
  32. //
  33. BOOL
  34. GetLocaleDateTimeString(
  35. SYSTEMTIME* pst,
  36. DWORD dwDateFlags,
  37. DWORD dwTimeFlags,
  38. TCHAR szBuff[],
  39. int cchBuffLen,
  40. LPSHELLDETAILS lpDetails);
  41. //////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Define the columns (used by CJobsSD::GetDetailsOf)
  44. //
  45. struct COL_INFO
  46. {
  47. UINT idString;
  48. int fmt;
  49. UINT cxChar;
  50. };
  51. const COL_INFO c_ColumnHeaders[] =
  52. {
  53. {IDS_NAME, LVCFMT_LEFT, 30},
  54. {IDS_SCHEDULE, LVCFMT_LEFT, 20},
  55. {IDS_NEXTRUNTIME, LVCFMT_LEFT, 15},
  56. {IDS_LASTRUNTIME, LVCFMT_LEFT, 15},
  57. {IDS_STATUS, LVCFMT_LEFT, 25},
  58. {IDS_LASTEXITCODE, LVCFMT_RIGHT, 15},
  59. {IDS_CREATOR, LVCFMT_LEFT, 15}
  60. };
  61. //____________________________________________________________________________
  62. //
  63. // Class: CJobsSD
  64. //
  65. // Purpose: Provide IShellDetails interface to Job Folder objects.
  66. //
  67. // History: 1/24/1996 RaviR Created
  68. //____________________________________________________________________________
  69. class CJobsSD : public IShellDetails
  70. {
  71. public:
  72. CJobsSD(HWND hwnd) : m_ulRefs(1), m_hwnd(hwnd) {}
  73. ~CJobsSD() {}
  74. // IUnknown methods
  75. DECLARE_STANDARD_IUNKNOWN;
  76. // IShellDetails methods
  77. STDMETHOD(GetDetailsOf)(LPCITEMIDLIST pidl, UINT iColumn,
  78. LPSHELLDETAILS pDetails);
  79. STDMETHOD(ColumnClick)(UINT iColumn);
  80. private:
  81. HWND m_hwnd;
  82. CDllRef m_DllRef;
  83. };
  84. //____________________________________________________________________________
  85. //
  86. // Member: CJobsSD::IUnknown methods
  87. //____________________________________________________________________________
  88. IMPLEMENT_STANDARD_IUNKNOWN(CJobsSD)
  89. STDMETHODIMP
  90. CJobsSD::QueryInterface(REFIID riid, LPVOID* ppvObj)
  91. {
  92. if (IsEqualIID(IID_IUnknown, riid) ||
  93. IsEqualIID(IID_IShellDetails, riid))
  94. {
  95. *ppvObj = (IUnknown*)(IShellDetails*) this;
  96. this->AddRef();
  97. return S_OK;
  98. }
  99. else
  100. {
  101. *ppvObj = NULL;
  102. return E_NOINTERFACE;
  103. }
  104. }
  105. inline
  106. HRESULT
  107. CopyToSTRRET(STRRET &str, LPTSTR pszIn)
  108. {
  109. UINT uiByteLen = (lstrlen(pszIn) + 1) * sizeof(TCHAR);
  110. str.uType = STRRET_WSTR;
  111. str.pOleStr = (LPWSTR) SHAlloc(uiByteLen);
  112. if (str.pOleStr == NULL)
  113. {
  114. CHECK_HRESULT(E_OUTOFMEMORY);
  115. return E_OUTOFMEMORY;
  116. }
  117. CopyMemory(str.pOleStr, pszIn, uiByteLen);
  118. return S_OK;
  119. }
  120. //____________________________________________________________________________
  121. //
  122. // Member: CJobsSD::GetDetailsOf
  123. //
  124. // Arguments: [pidl] -- IN
  125. // [iColumn] -- IN
  126. // [lpDetails] -- IN
  127. //
  128. // Returns: HRESULT.
  129. //
  130. // History: 1/8/1996 RaviR Created
  131. //
  132. //____________________________________________________________________________
  133. STDMETHODIMP
  134. CJobsSD::GetDetailsOf(
  135. LPCITEMIDLIST pidl,
  136. UINT iColumn,
  137. LPSHELLDETAILS lpDetails)
  138. {
  139. // TRACE(CJobsSD, GetDetailsOf);
  140. HRESULT hr = S_OK;
  141. TCHAR tcBuff[SCH_XBIGBUF_LEN] = TEXT("");
  142. if (iColumn >= COLUMN_COUNT)
  143. {
  144. return E_FAIL;
  145. }
  146. if (NULL == pidl)
  147. {
  148. //
  149. // Caller wants strings for the column headers
  150. //
  151. LoadString(g_hInstance,
  152. c_ColumnHeaders[iColumn].idString,
  153. tcBuff,
  154. SCH_XBIGBUF_LEN);
  155. lpDetails->fmt = c_ColumnHeaders[iColumn].fmt;
  156. lpDetails->cxChar = c_ColumnHeaders[iColumn].cxChar;
  157. }
  158. else
  159. {
  160. CJobID & jid = *(PJOBID)pidl;
  161. //
  162. // Fill tcBuff with the string describing column iColumn of
  163. // object jid. If jid represents a template object, only the
  164. // name column is not blank.
  165. //
  166. if (!jid.IsTemplate() || iColumn == COLUMN_NAME)
  167. {
  168. switch (iColumn)
  169. {
  170. case COLUMN_NAME:
  171. {
  172. StringCchCopy(tcBuff, SCH_XBIGBUF_LEN, jid.GetName());
  173. break;
  174. }
  175. case COLUMN_SCHEDULE:
  176. {
  177. if (jid.IsJobFlagOn(TASK_FLAG_DISABLED) == TRUE)
  178. {
  179. LoadString(g_hInstance,
  180. IDS_DISABLED,
  181. tcBuff,
  182. SCH_XBIGBUF_LEN);
  183. }
  184. else if (jid.GetTriggerCount() > 1)
  185. {
  186. LoadString(g_hInstance,
  187. IDS_MULTIPLE_TRIGGERS,
  188. tcBuff,
  189. SCH_XBIGBUF_LEN);
  190. }
  191. else
  192. {
  193. hr = GetTriggerStringFromTrigger(&jid.GetTrigger(),
  194. tcBuff,
  195. SCH_XBIGBUF_LEN,
  196. lpDetails);
  197. }
  198. break;
  199. }
  200. case COLUMN_LASTRUNTIME:
  201. {
  202. SYSTEMTIME &st = jid.GetLastRunTime();
  203. if (st.wYear == 0 || st.wMonth == 0 || st.wDay == 0)
  204. {
  205. LoadString(g_hInstance,
  206. IDS_NEVER,
  207. tcBuff,
  208. SCH_XBIGBUF_LEN);
  209. }
  210. else
  211. {
  212. GetLocaleDateTimeString(&st,
  213. DATE_SHORTDATE,
  214. 0,
  215. tcBuff,
  216. SCH_XBIGBUF_LEN, lpDetails);
  217. }
  218. break;
  219. }
  220. case COLUMN_NEXTRUNTIME:
  221. jid.GetNextRunTimeString(tcBuff, SCH_XBIGBUF_LEN, FALSE, lpDetails);
  222. break;
  223. case COLUMN_STATUS:
  224. {
  225. ULONG ids = 0;
  226. if (jid.IsRunning())
  227. {
  228. ids = IDS_RUNNING;
  229. }
  230. else if (jid.WasRunMissed())
  231. {
  232. ids = IDS_MISSED;
  233. }
  234. else if (jid.DidJobStartFail())
  235. {
  236. ids = IDS_START_FAILED;
  237. }
  238. else if(jid.DidJobBadAcct())
  239. {
  240. ids = IDS_BAD_ACCT;
  241. }
  242. else if(jid.DidJobRestAcct())
  243. {
  244. ids = IDS_REST_ACCT;
  245. }
  246. if (ids)
  247. {
  248. LoadString(g_hInstance, ids, tcBuff, SCH_XBIGBUF_LEN);
  249. }
  250. break;
  251. }
  252. case COLUMN_LASTEXITCODE:
  253. StringCchPrintf(tcBuff, SCH_XBIGBUF_LEN, TEXT("0x%x"), jid.GetExitCode());
  254. break;
  255. case COLUMN_CREATOR:
  256. StringCchCopy(tcBuff, SCH_XBIGBUF_LEN, jid.GetCreator());
  257. break;
  258. }
  259. }
  260. }
  261. hr = CopyToSTRRET(lpDetails->str, tcBuff);
  262. return hr;
  263. }
  264. //____________________________________________________________________________
  265. //
  266. // Member: CJobsSD::ColumnClick
  267. //
  268. // Arguments: [iColumn] -- IN
  269. //
  270. // Returns: STDMETHODIMP
  271. //
  272. // History: 1/8/1996 RaviR Created
  273. //
  274. //____________________________________________________________________________
  275. STDMETHODIMP
  276. CJobsSD::ColumnClick(
  277. UINT iColumn)
  278. {
  279. TRACE(CJobsSD, ColumnClick);
  280. ShellFolderView_ReArrange(m_hwnd, iColumn);
  281. return S_OK;
  282. }
  283. //
  284. //Define the UNICODE RLM control character.
  285. //
  286. #define RLM TEXT("\x200f")
  287. //+-------------------------------------------------------------------------
  288. //
  289. // Function: GetLocaleDateTimeString, public
  290. //
  291. // Synopsis: Use the proper locale-formatted time and date
  292. //
  293. // History: 07/09/95 RaviR Created.
  294. //
  295. //--------------------------------------------------------------------------
  296. BOOL
  297. GetLocaleDateTimeString(
  298. SYSTEMTIME* pst,
  299. DWORD dwDateFlags,
  300. DWORD dwTimeFlags,
  301. TCHAR szBuff[],
  302. int cchBuffLen,
  303. LPSHELLDETAILS lpDetails)
  304. {
  305. if (pst->wYear == 0 || pst->wMonth == 0 || pst->wDay == 0)
  306. {
  307. szBuff = TEXT('\0');
  308. return TRUE;
  309. }
  310. LCID lcid = GetUserDefaultLCID();
  311. TCHAR Time[150] = TEXT("");
  312. TCHAR Date[150] = TEXT("");
  313. if (0 == GetTimeFormat(lcid, dwTimeFlags, pst, NULL, Time, 150))
  314. {
  315. DEBUG_OUT_LASTERROR;
  316. return FALSE;
  317. }
  318. if (lpDetails) {
  319. if (lpDetails->fmt & LVCFMT_RIGHT_TO_LEFT) {
  320. dwDateFlags |= DATE_RTLREADING;
  321. } else if (lpDetails->fmt & LVCFMT_LEFT_TO_RIGHT) {
  322. dwDateFlags |= DATE_LTRREADING;
  323. }
  324. }
  325. if (0 == GetDateFormat(lcid, dwDateFlags, pst, NULL, Date, 150))
  326. {
  327. DEBUG_OUT_LASTERROR;
  328. return FALSE;
  329. }
  330. //
  331. //Force the time to appears as if it is preceded by BiDi character.
  332. //
  333. if (dwDateFlags & DATE_RTLREADING)
  334. {
  335. StringCchCopy(szBuff, cchBuffLen, RLM);
  336. StringCchCat(szBuff, cchBuffLen, Time);
  337. }
  338. else
  339. StringCchCopy(szBuff,cchBuffLen, Time);
  340. StringCchCat(szBuff, cchBuffLen, TEXT(" "));
  341. StringCchCat(szBuff, cchBuffLen, Date);
  342. return TRUE;
  343. }
  344. //____________________________________________________________________________
  345. //
  346. // Function: CJobsShellDetails_Create
  347. //
  348. // Synopsis: S
  349. //
  350. // Arguments: [hwnd] -- IN
  351. // [riid] -- IN
  352. // [ppvObj] -- IN
  353. //
  354. // Returns: HRESULT
  355. //
  356. // History: 1/24/1996 RaviR Created
  357. //____________________________________________________________________________
  358. HRESULT
  359. JFGetShellDetails(
  360. HWND hwnd,
  361. LPVOID* ppvObj)
  362. {
  363. CJobsSD* pObj = new CJobsSD(hwnd);
  364. if (NULL == pObj)
  365. {
  366. return E_OUTOFMEMORY;
  367. }
  368. HRESULT hr = pObj->QueryInterface(IID_IShellDetails, ppvObj);
  369. pObj->Release();
  370. return hr;
  371. }