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.

652 lines
19 KiB

  1. // RatGenPg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <iadmw.h>
  5. #include "cnfgprts.h"
  6. #include "parserat.h"
  7. #include "RatData.h"
  8. #include "RatGenPg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. // enumerate the tree icon indexes
  15. enum
  16. {
  17. IMAGE_SERVICE = 0,
  18. IMAGE_CATEGORY
  19. };
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CRatGenPage property page
  22. IMPLEMENT_DYNCREATE(CRatGenPage, CPropertyPage)
  23. //--------------------------------------------------------------------------
  24. CRatGenPage::CRatGenPage() : CPropertyPage(CRatGenPage::IDD),
  25. m_fInititialized( FALSE )
  26. {
  27. //{{AFX_DATA_INIT(CRatGenPage)
  28. m_sz_description = _T("");
  29. m_bool_enable = FALSE;
  30. m_sz_moddate = _T("");
  31. m_sz_person = _T("");
  32. //}}AFX_DATA_INIT
  33. }
  34. //--------------------------------------------------------------------------
  35. CRatGenPage::~CRatGenPage()
  36. {
  37. }
  38. //--------------------------------------------------------------------------
  39. void CRatGenPage::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CPropertyPage::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CRatGenPage)
  43. DDX_Control(pDX, IDC_MOD_DATE, m_cstatic_moddate);
  44. DDX_Control(pDX, IDC_STATIC_MOD_DATE, m_cstatic_moddate_title);
  45. DDX_Control(pDX, IDC_TREE, m_ctree_tree);
  46. DDX_Control(pDX, IDC_TITLE, m_cstatic_title);
  47. DDX_Control(pDX, IDC_STATIC_RATING, m_cstatic_rating);
  48. DDX_Control(pDX, IDC_STATIC_ICON, m_cstatic_icon);
  49. DDX_Control(pDX, IDC_STATIC_EXPIRES, m_cstatic_expires);
  50. DDX_Control(pDX, IDC_STATIC_EMAIL, m_cstatic_email);
  51. DDX_Control(pDX, IDC_STATIC_CATEGORY, m_cstatic_category);
  52. DDX_Control(pDX, IDC_SLIDER, m_cslider_slider);
  53. DDX_Control(pDX, IDC_NAME_PERSON, m_cedit_person);
  54. DDX_Control(pDX, IDC_DESCRIPTION, m_cstatic_description);
  55. DDX_Text(pDX, IDC_DESCRIPTION, m_sz_description);
  56. DDX_Check(pDX, IDC_ENABLE, m_bool_enable);
  57. DDX_Text(pDX, IDC_MOD_DATE, m_sz_moddate);
  58. DDX_Text(pDX, IDC_NAME_PERSON, m_sz_person);
  59. DDV_MaxChars(pDX, m_sz_person, 200);
  60. //}}AFX_DATA_MAP
  61. DDX_Control(pDX, IDC_DTP_ABS_DATE, m_dtpDate);
  62. }
  63. //--------------------------------------------------------------------------
  64. BEGIN_MESSAGE_MAP(CRatGenPage, CPropertyPage)
  65. //{{AFX_MSG_MAP(CRatGenPage)
  66. ON_BN_CLICKED(IDC_ENABLE, OnEnable)
  67. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
  68. ON_WM_HSCROLL()
  69. ON_WM_DESTROY()
  70. ON_EN_CHANGE(IDC_NAME_PERSON, OnChangeNamePerson)
  71. ON_EN_CHANGE(IDC_MOD_DATE, OnChangeModDate)
  72. //}}AFX_MSG_MAP
  73. ON_COMMAND(ID_HELP_FINDER, DoHelp)
  74. ON_COMMAND(ID_HELP, DoHelp)
  75. ON_COMMAND(ID_CONTEXT_HELP, DoHelp)
  76. ON_COMMAND(ID_DEFAULT_HELP, DoHelp)
  77. END_MESSAGE_MAP()
  78. //---------------------------------------------------------------------------
  79. void CRatGenPage::DoHelp()
  80. {
  81. DebugTraceHelp(HIDD_RATINGS_RATING);
  82. WinHelp( HIDD_RATINGS_RATING );
  83. }
  84. //--------------------------------------------------------------------------
  85. void CRatGenPage::EnableButtons()
  86. {
  87. UpdateData( TRUE );
  88. // enabling is based on whether or not things are enabled
  89. if ( m_bool_enable )
  90. {
  91. m_ctree_tree.EnableWindow( TRUE );
  92. m_cstatic_title.EnableWindow( TRUE );
  93. m_cstatic_rating.EnableWindow( TRUE );
  94. m_cstatic_icon.EnableWindow( TRUE );
  95. m_cstatic_expires.EnableWindow( TRUE );
  96. m_cstatic_email.EnableWindow( TRUE );
  97. m_cstatic_category.EnableWindow( TRUE );
  98. m_cslider_slider.EnableWindow( TRUE );
  99. m_cedit_person.EnableWindow( TRUE );
  100. m_cstatic_moddate.EnableWindow( TRUE );
  101. m_cstatic_moddate_title.EnableWindow( TRUE );
  102. m_cstatic_description.EnableWindow( TRUE );
  103. m_dtpDate.EnableWindow(TRUE);
  104. // also need to take care of the slider bar
  105. UpdateRatingItems();
  106. }
  107. else
  108. {
  109. // not enabled
  110. m_ctree_tree.EnableWindow( FALSE );
  111. m_cstatic_title.EnableWindow( FALSE );
  112. m_cstatic_rating.EnableWindow( FALSE );
  113. m_cstatic_icon.EnableWindow( FALSE );
  114. m_cstatic_email.EnableWindow( FALSE );
  115. m_cstatic_category.EnableWindow( FALSE );
  116. m_cedit_person.EnableWindow( FALSE );
  117. m_cstatic_moddate.EnableWindow( FALSE );
  118. m_cstatic_moddate_title.EnableWindow( FALSE );
  119. m_dtpDate.EnableWindow(FALSE);
  120. // don't just disable the slider and description - hide them!
  121. m_cslider_slider.ShowWindow( SW_HIDE );
  122. m_cstatic_description.ShowWindow( SW_HIDE );
  123. }
  124. }
  125. //--------------------------------------------------------------------------
  126. void CRatGenPage::UpdateRatingItems()
  127. {
  128. // get the selected item in the tree
  129. HTREEITEM hItem = m_ctree_tree.GetSelectedItem();
  130. // get the item category
  131. PicsCategory* pCat = GetTreeItemCategory( hItem );
  132. // if there is no item, or it is the root, hide the sliders
  133. if ( !pCat )
  134. {
  135. // don't just disable the slider and description - hide them!
  136. m_cslider_slider.ShowWindow( SW_HIDE );
  137. m_cstatic_description.ShowWindow( SW_HIDE );
  138. }
  139. else
  140. {
  141. // make sure the windows are showing and enabled
  142. m_cslider_slider.ShowWindow( SW_SHOW );
  143. m_cstatic_description.ShowWindow( SW_SHOW );
  144. m_cslider_slider.EnableWindow( TRUE );
  145. m_cstatic_description.EnableWindow( TRUE );
  146. // get the item category
  147. PicsCategory* pCat = GetTreeItemCategory( hItem );
  148. // set up the slider
  149. m_cslider_slider.SetRangeMin( 0 );
  150. m_cslider_slider.SetRangeMax( pCat->arrpPE.Length() - 1, TRUE );
  151. // set current value of the slider
  152. m_cslider_slider.SetPos( pCat->currentValue );
  153. // set up the description
  154. UpdateDescription();
  155. }
  156. }
  157. //--------------------------------------------------------------------------
  158. PicsCategory* CRatGenPage::GetTreeItemCategory( HTREEITEM hItem )
  159. {
  160. DWORD iRat;
  161. DWORD iCat = 0;
  162. // get the item's parent in the tree
  163. HTREEITEM hParent = m_ctree_tree.GetParentItem(hItem);
  164. // get the cat
  165. // IA64 - OK to cast as this is an index
  166. iCat = (DWORD)m_ctree_tree.GetItemData( hItem );
  167. // if the parent is null, return NULL to indicate that this is a root item
  168. if ( !hParent )
  169. return NULL;
  170. // if the parent is a root though, we can simply return the category
  171. if ( !m_ctree_tree.GetParentItem(hParent) )
  172. {
  173. // get the rat and the cat
  174. // IA64 - OK to cast as this is an index
  175. iRat = (DWORD)m_ctree_tree.GetItemData( hParent );
  176. // return the category
  177. return m_pRatData->rgbRats[iRat]->arrpPC[iCat];
  178. }
  179. else
  180. {
  181. // we are deeper in the tree. Get the parent category first
  182. PicsCategory* pParentCat = GetTreeItemCategory( hParent );
  183. // return the category
  184. return pParentCat->arrpPC[iCat];
  185. }
  186. // shouldn't get here
  187. return NULL;
  188. }
  189. //--------------------------------------------------------------------------
  190. void CRatGenPage::UpdateDateStrings()
  191. {
  192. CString sz;
  193. TCHAR chBuff[MAX_PATH];
  194. int i;
  195. SYSTEMTIME sysTime;
  196. UpdateData( TRUE );
  197. // start with the epxiration date
  198. ZeroMemory( chBuff, sizeof(chBuff) );
  199. ZeroMemory( &sysTime, sizeof(sysTime) );
  200. sysTime.wDay = m_pRatData->m_expire_day;
  201. sysTime.wMonth = m_pRatData->m_expire_month;
  202. sysTime.wYear = m_pRatData->m_expire_year;
  203. m_dtpDate.SetTime(&sysTime);
  204. // now the modified date and time
  205. ZeroMemory( chBuff, sizeof(chBuff) );
  206. ZeroMemory( &sysTime, sizeof(sysTime) );
  207. sysTime.wDay = m_pRatData->m_start_day;
  208. sysTime.wMonth = m_pRatData->m_start_month;
  209. sysTime.wYear = m_pRatData->m_start_year;
  210. sysTime.wMinute = m_pRatData->m_start_minute;
  211. sysTime.wHour = m_pRatData->m_start_hour;
  212. i = GetDateFormat(
  213. LOCALE_USER_DEFAULT,
  214. DATE_LONGDATE,
  215. &sysTime,
  216. NULL,
  217. chBuff,
  218. sizeof(chBuff)/sizeof(TCHAR)
  219. );
  220. m_sz_moddate = chBuff;
  221. ZeroMemory( chBuff, sizeof(chBuff) );
  222. i = GetTimeFormat(
  223. LOCALE_USER_DEFAULT,
  224. TIME_NOSECONDS,
  225. &sysTime,
  226. NULL,
  227. chBuff,
  228. sizeof(chBuff)/sizeof(TCHAR)
  229. );
  230. m_sz_moddate += ", ";
  231. m_sz_moddate += chBuff;
  232. // CTime timeModified( sysTime );
  233. // m_sz_moddate = timeModified.Format( "%#c" );
  234. // put it back
  235. UpdateData( FALSE );
  236. }
  237. //--------------------------------------------------------------------------
  238. // Update the text displayed in the description
  239. void CRatGenPage::UpdateDescription()
  240. {
  241. // get the selected item in the tree
  242. HTREEITEM hItem = m_ctree_tree.GetSelectedItem();
  243. if ( !hItem ) return;
  244. // get the selected category object
  245. PicsCategory* pCat = GetTreeItemCategory( hItem );
  246. // shouldn't be any problem, but might as well check
  247. if ( !pCat )
  248. return;
  249. // get the current value
  250. WORD value = pCat->currentValue;
  251. // build the description string
  252. m_sz_description = pCat->arrpPE[value]->etstrName.Get();
  253. UpdateData( FALSE );
  254. }
  255. //--------------------------------------------------------------------------
  256. // tell it to query the metabase and get any defaults
  257. BOOL CRatGenPage::FInit()
  258. {
  259. UpdateData( TRUE );
  260. HIMAGELIST hImage = ImageList_LoadImage(AfxGetResourceHandle(),
  261. MAKEINTRESOURCE(IDB_RATLIST), 16, 3, 0x00FF00FF, IMAGE_BITMAP, LR_DEFAULTCOLOR);
  262. if (hImage != NULL)
  263. {
  264. m_ctree_tree.SetImageList(CImageList::FromHandle(hImage), TVSIL_NORMAL);
  265. }
  266. // start with the parsed rat files
  267. if ( !FLoadRatFiles() )
  268. return FALSE;
  269. // do the right thing based on the ratings being enabled
  270. if ( m_pRatData->m_fEnabled )
  271. {
  272. // ratings are enabled.
  273. m_bool_enable = TRUE;
  274. m_sz_person = m_pRatData->m_szEmail;
  275. }
  276. else
  277. {
  278. // ratings are not enabled.
  279. m_bool_enable = FALSE;
  280. }
  281. // do the dates
  282. // if the mod date is not set give date today's as a default moddate
  283. if ( m_pRatData->m_start_year == 0 )
  284. {
  285. SetCurrentModDate();
  286. }
  287. //
  288. // Set the minimum of the date picker to today
  289. // and the maximum to Dec 31, 2035.
  290. // taken from Ron's code
  291. //
  292. CTime m_tmNow(CTime::GetCurrentTime());
  293. CTime tmThen(2035, 12, 31, 23, 59, 59);
  294. m_dtpDate.SetRange(&m_tmNow, &tmThen);
  295. // if there is no expire date, set it for one year after the mod date
  296. if ( m_pRatData->m_expire_year == 0 )
  297. {
  298. m_pRatData->m_expire_minute = 0;
  299. m_pRatData->m_expire_hour = 12;
  300. m_pRatData->m_expire_day = m_pRatData->m_start_day;
  301. m_pRatData->m_expire_month = m_pRatData->m_start_month;
  302. m_pRatData->m_expire_year = m_pRatData->m_start_year + 1;
  303. }
  304. // update the date strings
  305. UpdateDateStrings();
  306. // update the name string and the enabled switch as well
  307. m_sz_person = m_pRatData->m_szEmail;
  308. m_bool_enable = m_pRatData->m_fEnabled;
  309. // put the data back
  310. UpdateData( FALSE );
  311. EnableButtons();
  312. // success
  313. return TRUE;
  314. }
  315. //--------------------------------------------------------------------------
  316. // load the parsed rat files into the tree
  317. BOOL CRatGenPage::FLoadRatFiles()
  318. {
  319. HTREEITEM hRoot;
  320. HTREEITEM hItem;
  321. CString sz;
  322. // how many rat files are there?
  323. DWORD nRatFiles = (DWORD)m_pRatData->rgbRats.GetSize();
  324. // loop them
  325. for ( DWORD iRat = 0; iRat < nRatFiles; iRat++ )
  326. {
  327. // get the rating system
  328. PicsRatingSystem* pRating = m_pRatData->rgbRats[iRat];
  329. // get the root node name
  330. sz = pRating->etstrName.Get();
  331. // add the root node to the tree
  332. hRoot = m_ctree_tree.InsertItem( sz );
  333. // because the list is alphabetized, embed the iRat number in the item
  334. m_ctree_tree.SetItemData( hRoot, iRat );
  335. m_ctree_tree.SetItemImage( hRoot, IMAGE_SERVICE, IMAGE_SERVICE );
  336. // add the subnodes to the tree as well
  337. DWORD nCats = pRating->arrpPC.Length();
  338. // loop them
  339. for ( DWORD iCat = 0; iCat < nCats; iCat++ )
  340. {
  341. // get the category node name
  342. sz = pRating->arrpPC[iCat]->etstrName.Get();
  343. // add the category node to the tree
  344. hItem = m_ctree_tree.InsertItem( sz, hRoot );
  345. // because the list is alphabetized, embed the iCat number in the item
  346. m_ctree_tree.SetItemData( hItem, iCat );
  347. m_ctree_tree.SetItemImage( hItem, IMAGE_CATEGORY, IMAGE_CATEGORY );
  348. // even though there aren't any now, add any sub-categories
  349. LoadSubCategories( pRating->arrpPC[iCat], hItem );
  350. }
  351. // expand the rat node
  352. m_ctree_tree.Expand( hRoot, TVE_EXPAND );
  353. }
  354. return TRUE;
  355. }
  356. //--------------------------------------------------------------------------
  357. void CRatGenPage::LoadSubCategories( PicsCategory* pParentCat, HTREEITEM hParent )
  358. {
  359. CString sz;
  360. HTREEITEM hItem;
  361. // add the subnodes to the tree as well
  362. DWORD nCats = pParentCat->arrpPC.Length();
  363. // loop them
  364. for ( DWORD iCat = 0; iCat < nCats; iCat++ )
  365. {
  366. // get the category node name
  367. sz = pParentCat->arrpPC[iCat]->etstrName.Get();
  368. // add the category node to the tree
  369. hItem = m_ctree_tree.InsertItem( sz, hParent );
  370. // because the list is alphabetized, embed the iCat number in the item
  371. m_ctree_tree.SetItemData( hItem, iCat );
  372. m_ctree_tree.SetItemImage( hItem, IMAGE_CATEGORY, IMAGE_CATEGORY );
  373. // even though there aren't any now, add any sub-categories
  374. LoadSubCategories( pParentCat->arrpPC[iCat], hItem );
  375. }
  376. // if there were sub-categories, expand the parental node in the tree
  377. if ( nCats > 0 )
  378. m_ctree_tree.Expand( hParent, TVE_EXPAND );
  379. }
  380. //--------------------------------------------------------------------------
  381. void CRatGenPage::SetModifiedTime()
  382. {
  383. SetCurrentModDate();
  384. UpdateDateStrings();
  385. SetModified();
  386. }
  387. /////////////////////////////////////////////////////////////////////////////
  388. // CRatGenPage message handlers
  389. //--------------------------------------------------------------------------
  390. void CRatGenPage::OnEnable()
  391. {
  392. EnableButtons();
  393. SetModified();
  394. }
  395. //--------------------------------------------------------------------------
  396. BOOL CRatGenPage::OnSetActive()
  397. {
  398. // if it hasn't been initialized yet, do so
  399. if ( !m_fInititialized )
  400. {
  401. FInit();
  402. m_fInititialized = TRUE;
  403. }
  404. // enable the button appropriately
  405. EnableButtons();
  406. return CPropertyPage::OnSetActive();
  407. }
  408. //--------------------------------------------------------------------------
  409. void CRatGenPage::OnOK()
  410. {
  411. CPropertyPage::OnOK();
  412. }
  413. //--------------------------------------------------------------------------
  414. BOOL CRatGenPage::OnApply()
  415. {
  416. UpdateData( TRUE );
  417. // make sure there are no quote symbols in the name
  418. if ( m_sz_person.Find(_T('\"')) >= 0 )
  419. {
  420. AfxMessageBox( IDS_RAT_NAME_ERROR );
  421. return FALSE;
  422. }
  423. // put the data into place
  424. m_pRatData->m_fEnabled = m_bool_enable;
  425. m_pRatData->m_szEmail = m_sz_person;
  426. // set the expire date
  427. SYSTEMTIME sysTime;
  428. ZeroMemory( &sysTime, sizeof(sysTime) );
  429. // get the date from the control
  430. m_dtpDate.GetTime(&sysTime);
  431. // set the date into place
  432. m_pRatData->m_expire_day = sysTime.wDay;
  433. m_pRatData->m_expire_month = sysTime.wMonth;
  434. m_pRatData->m_expire_year = sysTime.wYear;
  435. // generate the label and save it into the metabase
  436. m_pRatData->SaveTheLabel();
  437. // we can now apply
  438. SetModified( FALSE );
  439. return CPropertyPage::OnApply();
  440. }
  441. //--------------------------------------------------------------------------
  442. void CRatGenPage::SetCurrentModDate()
  443. {
  444. SYSTEMTIME time;
  445. GetLocalTime( &time );
  446. m_pRatData->m_start_day = time.wDay;
  447. m_pRatData->m_start_month = time.wMonth;
  448. m_pRatData->m_start_year = time.wYear;
  449. m_pRatData->m_start_minute = time.wMinute;
  450. m_pRatData->m_start_hour = time.wHour;
  451. }
  452. //--------------------------------------------------------------------------
  453. void CRatGenPage::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
  454. {
  455. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  456. UpdateRatingItems();
  457. *pResult = 0;
  458. }
  459. //--------------------------------------------------------------------------
  460. void CRatGenPage::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  461. {
  462. // get the value of the slider
  463. WORD iPos = (WORD)m_cslider_slider.GetPos();
  464. // get the current item
  465. HTREEITEM hItem = m_ctree_tree.GetSelectedItem();
  466. // get the selected category object
  467. PicsCategory* pCat = GetTreeItemCategory( hItem );
  468. // shouldn't be any problem, but might as well check
  469. if ( !pCat )
  470. return;
  471. // set the category value
  472. pCat->currentValue = iPos;
  473. // update the description
  474. UpdateDescription();
  475. // we can now apply
  476. SetModifiedTime();
  477. // update the mod date
  478. SetCurrentModDate();
  479. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  480. }
  481. //--------------------------------------------------------------------------
  482. void CRatGenPage::OnChangeNamePerson()
  483. {
  484. // we can now apply
  485. SetModifiedTime();
  486. }
  487. //--------------------------------------------------------------------------
  488. void CRatGenPage::OnChangeModDate()
  489. {
  490. // we can now apply
  491. SetModifiedTime();
  492. }
  493. //--------------------------------------------------------------------------
  494. // Stolen from w3scfg - the httppage.cpp file
  495. BOOL
  496. CRatGenPage::OnNotify(
  497. WPARAM wParam,
  498. LPARAM lParam,
  499. LRESULT * pResult
  500. )
  501. /*++
  502. Routine Description:
  503. Handle notification changes
  504. Arguments:
  505. WPARAM wParam : Control ID
  506. LPARAM lParam : NMHDR *
  507. LRESULT * pResult : Result pointer
  508. Return Value:
  509. TRUE if handled, FALSE if not
  510. --*/
  511. {
  512. //
  513. // Message cracker crashes - so checking this here instead
  514. //
  515. if (wParam == IDC_DTP_ABS_DATE)
  516. {
  517. NMHDR * pHdr = (NMHDR *)lParam;
  518. if (pHdr->code == DTN_DATETIMECHANGE)
  519. {
  520. SetModified();
  521. }
  522. }
  523. //
  524. // Default behaviour -- go to the message map
  525. //
  526. return CPropertyPage::OnNotify(wParam, lParam, pResult);
  527. }
  528. void CRatGenPage::OnDestroy()
  529. {
  530. CPropertyPage::OnDestroy();
  531. CImageList * pImage = m_ctree_tree.SetImageList(CImageList::FromHandle(NULL), TVSIL_NORMAL);
  532. if (pImage != NULL && pImage->m_hImageList != NULL)
  533. {
  534. ImageList_Destroy(pImage->m_hImageList);
  535. }
  536. }