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.

345 lines
9.1 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2001.
  5. //
  6. // File: SchedBas.cpp
  7. //
  8. // Contents:
  9. //
  10. //----------------------------------------------------------------------------
  11. // SchedBas.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "log.h"
  15. #include <schedule.h>
  16. #include "SchedBas.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. //****************************************************************************
  23. //
  24. // ReplaceFrameWithControl ()
  25. //
  26. // Use the a dialog control to set the size of the Schedule Matrix.
  27. //
  28. // HISTORY
  29. // 17-Jul-97 t-danm Copied from sample written by Scott Walker.
  30. //
  31. //****************************************************************************
  32. void ReplaceFrameWithControl (CWnd *pWnd, UINT nFrameID, CWnd *pControl,
  33. BOOL bAssignFrameIDToControl)
  34. {
  35. CWnd *pFrame;
  36. CRect rect;
  37. ASSERT (pWnd != NULL);
  38. ASSERT (pControl != NULL);
  39. // Get the frame control
  40. pFrame = pWnd->GetDlgItem (nFrameID);
  41. ASSERT (pFrame != NULL);
  42. // Get the frame rect
  43. pFrame->GetClientRect (&rect);
  44. pFrame->ClientToScreen (&rect);
  45. pWnd->ScreenToClient (&rect);
  46. // Set the control on the frame
  47. pControl->SetWindowPos (pFrame, rect.left, rect.top, rect.Width (), rect.Height (),
  48. SWP_SHOWWINDOW);
  49. // set the control font to match the dialog font
  50. pControl->SetFont (pWnd->GetFont ());
  51. // hide the placeholder frame
  52. pFrame->ShowWindow (SW_HIDE);
  53. if (bAssignFrameIDToControl)
  54. pControl->SetDlgCtrlID ( nFrameID );
  55. } // ReplaceFrameWithControl
  56. /////////////////////////////////////////////////////////////////////////////
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CLogOnHoursDlg dialog
  59. void CLegendCell::Init (CWnd* pParent, UINT nCtrlID, CScheduleMatrix* pMatrix, UINT nPercentage)
  60. {
  61. ASSERT (pParent && pMatrix );
  62. m_pMatrix = pMatrix;
  63. m_nPercentage = nPercentage;
  64. // subclass the window so that we get paint notifications
  65. VERIFY ( SubclassDlgItem ( nCtrlID, pParent ) );
  66. // Resize the legend cell to have the same interior size as the cells
  67. // in the schedule matrix
  68. CSize size = pMatrix->GetCellSize ();
  69. SetWindowPos ( NULL, 0, 0, size.cx+1, size.cy+1,
  70. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER );
  71. }
  72. void CLegendCell::OnPaint ()
  73. {
  74. if (NULL == m_pMatrix)
  75. {
  76. ASSERT (0);
  77. return;
  78. }
  79. CRect rect;
  80. GetClientRect (rect);
  81. PAINTSTRUCT paintStruct;
  82. CDC *pdc = BeginPaint ( &paintStruct );
  83. m_pMatrix->DrawCell (
  84. pdc,
  85. rect,
  86. m_nPercentage,
  87. FALSE,
  88. m_pMatrix->GetBackColor (0,0),
  89. m_pMatrix->GetForeColor (0,0),
  90. m_pMatrix->GetBlendColor (0,0)
  91. );
  92. EndPaint (&paintStruct);
  93. }
  94. BEGIN_MESSAGE_MAP(CLegendCell, CStatic)
  95. //{{AFX_MSG_MAP(CLegendCell)
  96. ON_WM_PAINT ()
  97. //}}AFX_MSG_MAP
  98. END_MESSAGE_MAP()
  99. /////////////////////////////////////////////////////////////////////////////
  100. // CScheduleBaseDlg dialog
  101. CScheduleBaseDlg::CScheduleBaseDlg(UINT nIDTemplate, bool bAddDaylightBias, CWnd* pParent /*=NULL*/)
  102. : CDialog(nIDTemplate, pParent),
  103. m_bSystemTimeChanged (false),
  104. m_dwFlags (0),
  105. m_bAddDaylightBias (bAddDaylightBias)
  106. {
  107. EnableAutomation();
  108. //{{AFX_DATA_INIT(CScheduleBaseDlg)
  109. // NOTE: the ClassWizard will add member initialization here
  110. //}}AFX_DATA_INIT
  111. }
  112. void CScheduleBaseDlg::OnFinalRelease()
  113. {
  114. // When the last reference for an automation object is released
  115. // OnFinalRelease is called. The base class will automatically
  116. // deletes the object. Add additional cleanup required for your
  117. // object before calling the base class.
  118. CDialog::OnFinalRelease();
  119. }
  120. void CScheduleBaseDlg::DoDataExchange(CDataExchange* pDX)
  121. {
  122. CDialog::DoDataExchange(pDX);
  123. //{{AFX_DATA_MAP(CScheduleBaseDlg)
  124. // NOTE: the ClassWizard will add DDX and DDV calls here
  125. //}}AFX_DATA_MAP
  126. }
  127. BEGIN_MESSAGE_MAP(CScheduleBaseDlg, CDialog)
  128. //{{AFX_MSG_MAP(CScheduleBaseDlg)
  129. //}}AFX_MSG_MAP
  130. ON_MN_SELCHANGE (IDC_SCHEDULE_MATRIX, OnSelChange)
  131. ON_WM_TIMECHANGE()
  132. ON_MESSAGE (BASEDLGMSG_GETIDD, OnGetIDD)
  133. END_MESSAGE_MAP()
  134. BEGIN_DISPATCH_MAP(CScheduleBaseDlg, CDialog)
  135. //{{AFX_DISPATCH_MAP(CScheduleBaseDlg)
  136. // NOTE - the ClassWizard will add and remove mapping macros here.
  137. //}}AFX_DISPATCH_MAP
  138. END_DISPATCH_MAP()
  139. // Note: we add support for IID_IScheduleBaseDlg to support typesafe binding
  140. // from VBA. This IID must match the GUID that is attached to the
  141. // dispinterface in the .ODL file.
  142. // {701CFB38-AEF8-11D1-9864-00C04FB94F17}
  143. static const IID IID_IScheduleBaseDlg =
  144. { 0x701cfb38, 0xaef8, 0x11d1, { 0x98, 0x64, 0x0, 0xc0, 0x4f, 0xb9, 0x4f, 0x17 } };
  145. BEGIN_INTERFACE_MAP(CScheduleBaseDlg, CDialog)
  146. INTERFACE_PART(CScheduleBaseDlg, IID_IScheduleBaseDlg, Dispatch)
  147. END_INTERFACE_MAP()
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CScheduleBaseDlg message handlers
  150. BOOL CScheduleBaseDlg::OnInitDialog()
  151. {
  152. _TRACE (1, L"Entering CScheduleBaseDlg::OnInitDialog\n");
  153. CDialog::OnInitDialog();
  154. CRect rect (0,0,0,0);
  155. // Set up the weekly matrix and slap it on the dialog.
  156. BOOL bRet = m_schedulematrix.Create (L"WeeklyMatrix", rect, this, IDC_SCHEDULE_MATRIX);
  157. if ( !bRet )
  158. {
  159. DWORD dwErr = GetLastError ();
  160. _TRACE (0, L"CScheduleMatrix::Create () failed: 0x%x\n", dwErr);
  161. }
  162. ::ReplaceFrameWithControl (this, IDC_STATIC_LOGON_MATRIX, &m_schedulematrix, FALSE);
  163. // Set the blending color for the whole matrix
  164. m_schedulematrix.SetBlendColor (c_crBlendColor, 0, 0, 24, 7);
  165. m_schedulematrix.SetForeColor (c_crBlendColor, 0, 0, 24, 7);
  166. SetWindowText (m_szTitle);
  167. InitMatrix ();
  168. UpdateUI ();
  169. if ( m_dwFlags & SCHED_FLAG_READ_ONLY )
  170. {
  171. // Change the Cancel button to Close
  172. CString strClose;
  173. VERIFY (strClose.LoadString (IDS_CLOSE));
  174. GetDlgItem (IDCANCEL)->SetWindowText (strClose);
  175. // Hide the OK button
  176. GetDlgItem (IDOK)->ShowWindow (SW_HIDE);
  177. }
  178. _TRACE (-1, L"Leaving CScheduleBaseDlg::OnInitDialog\n");
  179. return TRUE; // return TRUE unless you set the focus to a control
  180. // EXCEPTION: OCX Property Pages should return FALSE
  181. }
  182. void CScheduleBaseDlg::SetTitle(LPCTSTR pszTitle)
  183. {
  184. m_szTitle = pszTitle;
  185. }
  186. void CScheduleBaseDlg::OnSelChange ()
  187. {
  188. UpdateUI ();
  189. }
  190. void CScheduleBaseDlg::UpdateUI ()
  191. {
  192. CString strDescr;
  193. m_schedulematrix.GetSelDescription (OUT strDescr);
  194. SetDlgItemText (IDC_STATIC_DESCRIPTION, strDescr);
  195. UpdateButtons ();
  196. }
  197. /////////////////////////////////////////////////////////////////////
  198. // InitMatrix2 ()
  199. //
  200. // Initialize the schedule matrix with an array of values
  201. // representing replication frequencies.
  202. //
  203. // INTERFACE NOTES
  204. // Each byte of rgbData represent one hour. The first day of
  205. // the week is Sunday and the last day is Saturday.
  206. //
  207. void CScheduleBaseDlg::InitMatrix2 (const BYTE rgbData[])
  208. {
  209. ASSERT (rgbData);
  210. bool bMatrixAllSelected = true;
  211. bool bMatrixAllClear = true;
  212. const BYTE * pbData = rgbData;
  213. for (int iDayOfWeek = 0; iDayOfWeek < 7; iDayOfWeek++)
  214. {
  215. for (int iHour = 0; iHour < 24; iHour++)
  216. {
  217. if (!*pbData)
  218. bMatrixAllSelected = false;
  219. else
  220. bMatrixAllClear = false;
  221. m_schedulematrix.SetPercentage (GetPercentageToSet (*pbData) , iHour, iDayOfWeek);
  222. pbData++;
  223. } // for
  224. } // for
  225. // If the whole matrix is selected, then set the selection to the whole matrix
  226. if ( bMatrixAllSelected || bMatrixAllClear )
  227. m_schedulematrix.SetSel (0, 0, 24, 7);
  228. else
  229. m_schedulematrix.SetSel (0, 0, 1, 1);
  230. } // InitMatrix2 ()
  231. /////////////////////////////////////////////////////////////////////
  232. // GetByteArray ()
  233. //
  234. // Get an array of bytes from the schedule matrix. Each byte
  235. // is a boolean value representing one hour of logon access to a user.
  236. //
  237. // INTERFACE NOTES
  238. // Same as SetLogonByteArray ().
  239. //
  240. void CScheduleBaseDlg::GetByteArray (OUT BYTE rgbData[])
  241. {
  242. ASSERT (rgbData);
  243. BYTE * pbData = rgbData;
  244. for (int iDayOfWeek = 0; iDayOfWeek < 7; iDayOfWeek++)
  245. {
  246. for (int iHour = 0; iHour < 24; iHour++)
  247. {
  248. *pbData = GetMatrixPercentage (iHour, iDayOfWeek);
  249. pbData++;
  250. } // for
  251. } // for
  252. } // GetByteArray ()
  253. // If the system time or time zone has changed prompt the user to close and reopen
  254. // the dialog. Otherwise, if the dialog data was saved, data could be corrupted.
  255. // Disable all controls.
  256. void CScheduleBaseDlg::OnTimeChange()
  257. {
  258. if ( !m_bSystemTimeChanged )
  259. {
  260. m_bSystemTimeChanged = true;
  261. CString caption;
  262. CString text;
  263. VERIFY (caption.LoadString (IDS_ACTIVE_DIRECTORY_MANAGER));
  264. VERIFY (text.LoadString (IDS_TIMECHANGE));
  265. MessageBox (text, caption, MB_ICONINFORMATION | MB_OK);
  266. GetDlgItem (IDCANCEL)->SetFocus ();
  267. GetDlgItem (IDOK)->EnableWindow (FALSE);
  268. m_schedulematrix.EnableWindow (FALSE);
  269. TimeChange ();
  270. }
  271. }
  272. void CScheduleBaseDlg::SetFlags(DWORD dwFlags)
  273. {
  274. m_dwFlags = dwFlags;
  275. }
  276. DWORD CScheduleBaseDlg::GetFlags() const
  277. {
  278. return m_dwFlags;
  279. }
  280. LRESULT CScheduleBaseDlg::OnGetIDD (WPARAM /*wParam*/, LPARAM /*lParam*/)
  281. {
  282. return GetIDD ();
  283. }