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.

640 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.SetTime(&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. CTime tmThen(2035, 12, 31, 23, 59, 59);
  291. m_dtpDate.SetRange(&m_tmNow, &tmThen);
  292. // if there is no expire date, set it for one year after the mod date
  293. if ( m_pRatData->m_expire_year == 0 )
  294. {
  295. m_pRatData->m_expire_minute = 0;
  296. m_pRatData->m_expire_hour = 12;
  297. m_pRatData->m_expire_day = m_pRatData->m_start_day;
  298. m_pRatData->m_expire_month = m_pRatData->m_start_month;
  299. m_pRatData->m_expire_year = m_pRatData->m_start_year + 1;
  300. }
  301. // update the date strings
  302. UpdateDateStrings();
  303. // update the name string and the enabled switch as well
  304. m_sz_person = m_pRatData->m_szEmail;
  305. m_bool_enable = m_pRatData->m_fEnabled;
  306. // put the data back
  307. UpdateData( FALSE );
  308. EnableButtons();
  309. // success
  310. return TRUE;
  311. }
  312. //--------------------------------------------------------------------------
  313. // load the parsed rat files into the tree
  314. BOOL CRatGenPage::FLoadRatFiles()
  315. {
  316. HTREEITEM hRoot;
  317. HTREEITEM hItem;
  318. CString sz;
  319. // how many rat files are there?
  320. DWORD nRatFiles = (DWORD)m_pRatData->rgbRats.GetSize();
  321. // loop them
  322. for ( DWORD iRat = 0; iRat < nRatFiles; iRat++ )
  323. {
  324. // get the rating system
  325. PicsRatingSystem* pRating = m_pRatData->rgbRats[iRat];
  326. // get the root node name
  327. sz = pRating->etstrName.Get();
  328. // add the root node to the tree
  329. hRoot = m_ctree_tree.InsertItem( sz );
  330. // because the list is alphabetized, embed the iRat number in the item
  331. m_ctree_tree.SetItemData( hRoot, iRat );
  332. m_ctree_tree.SetItemImage( hRoot, IMAGE_SERVICE, IMAGE_SERVICE );
  333. // add the subnodes to the tree as well
  334. DWORD nCats = pRating->arrpPC.Length();
  335. // loop them
  336. for ( DWORD iCat = 0; iCat < nCats; iCat++ )
  337. {
  338. // get the category node name
  339. sz = pRating->arrpPC[iCat]->etstrName.Get();
  340. // add the category node to the tree
  341. hItem = m_ctree_tree.InsertItem( sz, hRoot );
  342. // because the list is alphabetized, embed the iCat number in the item
  343. m_ctree_tree.SetItemData( hItem, iCat );
  344. m_ctree_tree.SetItemImage( hItem, IMAGE_CATEGORY, IMAGE_CATEGORY );
  345. // even though there aren't any now, add any sub-categories
  346. LoadSubCategories( pRating->arrpPC[iCat], hItem );
  347. }
  348. // expand the rat node
  349. m_ctree_tree.Expand( hRoot, TVE_EXPAND );
  350. }
  351. return TRUE;
  352. }
  353. //--------------------------------------------------------------------------
  354. void CRatGenPage::LoadSubCategories( PicsCategory* pParentCat, HTREEITEM hParent )
  355. {
  356. CString sz;
  357. HTREEITEM hItem;
  358. // add the subnodes to the tree as well
  359. DWORD nCats = pParentCat->arrpPC.Length();
  360. // loop them
  361. for ( DWORD iCat = 0; iCat < nCats; iCat++ )
  362. {
  363. // get the category node name
  364. sz = pParentCat->arrpPC[iCat]->etstrName.Get();
  365. // add the category node to the tree
  366. hItem = m_ctree_tree.InsertItem( sz, hParent );
  367. // because the list is alphabetized, embed the iCat number in the item
  368. m_ctree_tree.SetItemData( hItem, iCat );
  369. m_ctree_tree.SetItemImage( hItem, IMAGE_CATEGORY, IMAGE_CATEGORY );
  370. // even though there aren't any now, add any sub-categories
  371. LoadSubCategories( pParentCat->arrpPC[iCat], hItem );
  372. }
  373. // if there were sub-categories, expand the parental node in the tree
  374. if ( nCats > 0 )
  375. m_ctree_tree.Expand( hParent, TVE_EXPAND );
  376. }
  377. //--------------------------------------------------------------------------
  378. void CRatGenPage::SetModifiedTime()
  379. {
  380. SetCurrentModDate();
  381. UpdateDateStrings();
  382. SetModified();
  383. }
  384. /////////////////////////////////////////////////////////////////////////////
  385. // CRatGenPage message handlers
  386. //--------------------------------------------------------------------------
  387. void CRatGenPage::OnEnable()
  388. {
  389. EnableButtons();
  390. SetModified();
  391. }
  392. //--------------------------------------------------------------------------
  393. BOOL CRatGenPage::OnSetActive()
  394. {
  395. // if it hasn't been initialized yet, do so
  396. if ( !m_fInititialized )
  397. {
  398. FInit();
  399. m_fInititialized = TRUE;
  400. }
  401. // enable the button appropriately
  402. EnableButtons();
  403. return CPropertyPage::OnSetActive();
  404. }
  405. //--------------------------------------------------------------------------
  406. void CRatGenPage::OnOK()
  407. {
  408. CPropertyPage::OnOK();
  409. }
  410. //--------------------------------------------------------------------------
  411. BOOL CRatGenPage::OnApply()
  412. {
  413. UpdateData( TRUE );
  414. // make sure there are no quote symbols in the name
  415. if ( m_sz_person.Find(_T('\"')) >= 0 )
  416. {
  417. AfxMessageBox( IDS_RAT_NAME_ERROR );
  418. return FALSE;
  419. }
  420. // put the data into place
  421. m_pRatData->m_fEnabled = m_bool_enable;
  422. m_pRatData->m_szEmail = m_sz_person;
  423. // set the expire date
  424. SYSTEMTIME sysTime;
  425. ZeroMemory( &sysTime, sizeof(sysTime) );
  426. // get the date from the control
  427. m_dtpDate.GetTime(&sysTime);
  428. // set the date into place
  429. m_pRatData->m_expire_day = sysTime.wDay;
  430. m_pRatData->m_expire_month = sysTime.wMonth;
  431. m_pRatData->m_expire_year = sysTime.wYear;
  432. // generate the label and save it into the metabase
  433. m_pRatData->SaveTheLable();
  434. // we can now apply
  435. SetModified( FALSE );
  436. return CPropertyPage::OnApply();
  437. }
  438. //--------------------------------------------------------------------------
  439. void CRatGenPage::SetCurrentModDate()
  440. {
  441. SYSTEMTIME time;
  442. GetLocalTime( &time );
  443. m_pRatData->m_start_day = time.wDay;
  444. m_pRatData->m_start_month = time.wMonth;
  445. m_pRatData->m_start_year = time.wYear;
  446. m_pRatData->m_start_minute = time.wMinute;
  447. m_pRatData->m_start_hour = time.wHour;
  448. }
  449. //--------------------------------------------------------------------------
  450. void CRatGenPage::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
  451. {
  452. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  453. UpdateRatingItems();
  454. *pResult = 0;
  455. }
  456. //--------------------------------------------------------------------------
  457. void CRatGenPage::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  458. {
  459. // get the value of the slider
  460. WORD iPos = (WORD)m_cslider_slider.GetPos();
  461. // get the current item
  462. HTREEITEM hItem = m_ctree_tree.GetSelectedItem();
  463. // get the selected category object
  464. PicsCategory* pCat = GetTreeItemCategory( hItem );
  465. // shouldn't be any problem, but might as well check
  466. if ( !pCat )
  467. return;
  468. // set the category value
  469. pCat->currentValue = iPos;
  470. // update the description
  471. UdpateDescription();
  472. // we can now apply
  473. SetModifiedTime();
  474. // update the mod date
  475. SetCurrentModDate();
  476. CPropertyPage::OnHScroll(nSBCode, nPos, pScrollBar);
  477. }
  478. //--------------------------------------------------------------------------
  479. void CRatGenPage::OnChangeNamePerson()
  480. {
  481. // we can now apply
  482. SetModifiedTime();
  483. }
  484. //--------------------------------------------------------------------------
  485. void CRatGenPage::OnChangeModDate()
  486. {
  487. // we can now apply
  488. SetModifiedTime();
  489. }
  490. //--------------------------------------------------------------------------
  491. // Stolen from w3scfg - the httppage.cpp file
  492. BOOL
  493. CRatGenPage::OnNotify(
  494. WPARAM wParam,
  495. LPARAM lParam,
  496. LRESULT * pResult
  497. )
  498. /*++
  499. Routine Description:
  500. Handle notification changes
  501. Arguments:
  502. WPARAM wParam : Control ID
  503. LPARAM lParam : NMHDR *
  504. LRESULT * pResult : Result pointer
  505. Return Value:
  506. TRUE if handled, FALSE if not
  507. --*/
  508. {
  509. //
  510. // Message cracker crashes - so checking this here instead
  511. //
  512. if (wParam == IDC_DTP_ABS_DATE)
  513. {
  514. NMHDR * pHdr = (NMHDR *)lParam;
  515. if (pHdr->code == DTN_DATETIMECHANGE)
  516. {
  517. SetModified();
  518. }
  519. }
  520. //
  521. // Default behaviour -- go to the message map
  522. //
  523. return CPropertyPage::OnNotify(wParam, lParam, pResult);
  524. }