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.

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