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.

1059 lines
28 KiB

  1. /****************************************************************************\
  2. *
  3. * picsdlg.cpp
  4. *
  5. * Created: William Taylor (wtaylor) 01/22/01
  6. *
  7. * MS Ratings Pics Ratings Property Page
  8. *
  9. \****************************************************************************/
  10. #include "msrating.h"
  11. #include "mslubase.h"
  12. #include "picsdlg.h" // CPicsDialog
  13. #include "debug.h" // TraceMsg()
  14. #include <contxids.h> // Help Context ID's
  15. #include <mluisupp.h> // SHWinHelpOnDemandWrap() and MLLoadStringA()
  16. /*Helpers---------------------------------------------------------------------*/
  17. int g_nKeys, g_nLock; // indexes of the images
  18. DWORD CPicsDialog::aIds[] = {
  19. IDC_STATIC1, IDH_RATINGS_CATEGORY_LABEL,
  20. IDC_PT_TREE, IDH_RATINGS_CATEGORY_LIST,
  21. IDC_RATING_LABEL, IDH_RATINGS_RATING_LABEL,
  22. IDC_PT_TB_SELECT, IDH_RATINGS_RATING_LABEL,
  23. IDC_PT_T_RSN_SDESC, IDH_RATINGS_RATING_TEXT,
  24. IDC_STATIC2, IDH_RATINGS_DESCRIPTION_LABEL,
  25. IDC_PT_T_RSN_LDESC, IDH_RATINGS_DESCRIPTION_TEXT,
  26. IDC_STATIC3, IDH_RATINGS_VIEW_PROVIDER_PAGE,
  27. IDC_DETAILSBUTTON, IDH_RATINGS_VIEW_PROVIDER_PAGE,
  28. 0,0
  29. };
  30. CPicsDialog::CPicsDialog( PRSD * p_pPRSD )
  31. {
  32. ASSERT( p_pPRSD );
  33. m_pPRSD = p_pPRSD;
  34. }
  35. LRESULT CPicsDialog::OnSysColorChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  36. {
  37. TV_ITEM tvm;
  38. TreeNode *pTN;
  39. InitTreeViewImageLists(GetDlgItem(IDC_PT_TREE));
  40. //force the trackbar to redraw its background with the new color
  41. PRSD * pPRSD = m_pPRSD;
  42. ZeroMemory(&tvm,sizeof(tvm));
  43. tvm.hItem=TreeView_GetSelection(GetDlgItem(IDC_PT_TREE));
  44. tvm.mask=TVIF_PARAM;
  45. TreeView_GetItem(GetDlgItem(IDC_PT_TREE),&tvm);
  46. pTN=(TreeNode *) tvm.lParam;
  47. ASSERT( pTN );
  48. if ( ! pTN )
  49. {
  50. TraceMsg( TF_ERROR, "CPicsDialog::OnSysColorChange() - pTN is NULL!" );
  51. return 0L;
  52. }
  53. ControlsShow( pTN->tne );
  54. switch(pTN->tne)
  55. {
  56. case tneRatingSystemInfo:
  57. {
  58. SelectRatingSystemInfo( (PicsRatingSystem*) pTN->pData );
  59. break;
  60. }
  61. case tneRatingSystemNode:
  62. {
  63. SelectRatingSystemNode( (PicsCategory*) pTN->pData );
  64. break;
  65. }
  66. }
  67. return 0L;
  68. }
  69. LRESULT CPicsDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  70. {
  71. PicsDlgInit();
  72. bHandled = FALSE;
  73. return 1L; // Let the system set the focus
  74. }
  75. LRESULT CPicsDialog::OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  76. {
  77. switch (LOWORD(wParam)){
  78. case TB_THUMBTRACK:
  79. case TB_BOTTOM:
  80. case TB_ENDTRACK:
  81. case TB_LINEDOWN:
  82. case TB_LINEUP:
  83. case TB_PAGEDOWN:
  84. case TB_PAGEUP:
  85. case TB_THUMBPOSITION:
  86. case TB_TOP:
  87. NewTrackbarPosition();
  88. MarkChanged();
  89. break;
  90. }
  91. return 0L;
  92. }
  93. LRESULT CPicsDialog::OnDetails(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  94. {
  95. LaunchRatingSystemSite();
  96. return 0L;
  97. }
  98. LRESULT CPicsDialog::OnSetActive(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  99. {
  100. PRSD * pPRSD = m_pPRSD;
  101. ASSERT( pPRSD );
  102. if ( ! pPRSD )
  103. {
  104. TraceMsg( TF_ERROR, "CPicsDialog::OnSetActive() - pPRSD is NULL!" );
  105. return 0L;
  106. }
  107. if (pPRSD->fNewProviders)
  108. {
  109. //Means that user changed list of provider files
  110. HWND hwndTree;
  111. hwndTree = GetDlgItem(IDC_PT_TREE);
  112. KillTree(hwndTree , TreeView_GetRoot(hwndTree));
  113. pPRSD->fNewProviders = FALSE;
  114. PicsDlgInit();
  115. }
  116. bHandled = FALSE;
  117. return 0L;
  118. }
  119. LRESULT CPicsDialog::OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  120. {
  121. LPPSHNOTIFY lpPSHNotify = (LPPSHNOTIFY) pnmh;
  122. /*do apply stuff*/
  123. PicsDlgSave();
  124. if ( ! lpPSHNotify->lParam )
  125. {
  126. // Apply
  127. return PSNRET_NOERROR;
  128. }
  129. // Do this if hit OK or Cancel, not Apply
  130. OnReset( idCtrl, pnmh, bHandled );
  131. return PSNRET_NOERROR;
  132. }
  133. LRESULT CPicsDialog::OnReset(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  134. {
  135. // Do this if hit OK or Cancel, not Apply
  136. HWND hDlg = m_hWnd;
  137. ASSERT( hDlg );
  138. SendMessage(hDlg,WM_SETREDRAW, FALSE,0L);
  139. PicsDlgUninit();
  140. SendMessage(hDlg,WM_SETREDRAW, TRUE,0L);
  141. return 0L;
  142. }
  143. LRESULT CPicsDialog::OnTreeItemExpanding(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  144. {
  145. LPNMTREEVIEW pNMTreeView = (LPNMTREEVIEW)pnmh;
  146. if ( ! pNMTreeView )
  147. {
  148. return 0L;
  149. }
  150. if (pNMTreeView->action == TVE_COLLAPSE)
  151. {
  152. ::SetWindowLongPtr(m_hWnd, DWLP_MSGRESULT, TRUE);
  153. return 1L; //Suppress expanding tree.
  154. }
  155. return 0L;
  156. }
  157. LRESULT CPicsDialog::OnTreeSelChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
  158. {
  159. LPNMTREEVIEW pNMTreeView = (LPNMTREEVIEW)pnmh;
  160. TreeNode *pTN = pNMTreeView ? ((TreeNode*) pNMTreeView->itemNew.lParam) : NULL;
  161. if ( ! pTN )
  162. {
  163. TraceMsg( TF_ERROR, "CPicsDialog::OnTreeSelChanged() - pTN is NULL!" );
  164. return 0L;
  165. }
  166. PRSD * pPRSD = m_pPRSD;
  167. if ( ! pPRSD )
  168. {
  169. TraceMsg( TF_ERROR, "CPicsDialog::OnTreeSelChanged() - pPRSD is NULL!" );
  170. return 0L;
  171. }
  172. if (pPRSD->fNewProviders)
  173. {
  174. return 1L; /* tree is being cleaned up, ignore sel changes */
  175. }
  176. ControlsShow( pTN->tne );
  177. switch(pTN->tne)
  178. {
  179. case tneRatingSystemInfo:
  180. SelectRatingSystemInfo( (PicsRatingSystem*) pTN->pData );
  181. break;
  182. case tneRatingSystemNode:
  183. SelectRatingSystemNode( (PicsCategory*) pTN->pData );
  184. break;
  185. }
  186. return 1L;
  187. }
  188. LRESULT CPicsDialog::OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  189. {
  190. SHWinHelpOnDemandWrap((HWND)((LPHELPINFO)lParam)->hItemHandle, ::szHelpFile,
  191. HELP_WM_HELP, (DWORD_PTR)(LPSTR)aIds);
  192. return 0L;
  193. }
  194. LRESULT CPicsDialog::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  195. {
  196. SHWinHelpOnDemandWrap((HWND)wParam, ::szHelpFile, HELP_CONTEXTMENU,
  197. (DWORD_PTR)(LPVOID)aIds);
  198. return 0L;
  199. }
  200. // InitTreeViewImageLists - creates an image list, adds three bitmaps to
  201. // it, and associates the image list with a tree-view control.
  202. // Returns TRUE if successful or FALSE otherwise.
  203. // hwndTV - handle of the tree-view control
  204. //
  205. #define NUM_BITMAPS 2
  206. #define CX_BITMAP 16
  207. #define CY_BITMAP 16
  208. void CPicsDialog::SetTreeImages( HWND hwndTV, HIMAGELIST himl )
  209. {
  210. HIMAGELIST oldHiml; // handle of image list
  211. // Associate the image list with the tree-view control.
  212. oldHiml = TreeView_SetImageList( hwndTV, himl, TVSIL_NORMAL );
  213. if ( oldHiml != NULL )
  214. {
  215. ImageList_Destroy( oldHiml );
  216. }
  217. }
  218. BOOL CPicsDialog::InitTreeViewImageLists(HWND hwndTV)
  219. {
  220. HIMAGELIST himl; // handle of image list
  221. HBITMAP hbmp; // handle of bitmap
  222. // Create the image list.
  223. if ((himl = ImageList_Create(CX_BITMAP, CY_BITMAP,
  224. FALSE, NUM_BITMAPS, 0)) == NULL)
  225. {
  226. TraceMsg( TF_WARNING, "CPicsDialog::InitTreeViewImageLists() - himl Image List Creation Failed!" );
  227. return FALSE;
  228. }
  229. // Add the open file, closed file, and document bitmaps.
  230. hbmp=(HBITMAP) LoadImage(g_hInstance,
  231. MAKEINTRESOURCE(IDB_KEYS),
  232. IMAGE_BITMAP,
  233. 0,
  234. 0,
  235. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  236. g_nKeys = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
  237. DeleteObject(hbmp);
  238. hbmp=(HBITMAP) LoadImage(g_hInstance,
  239. MAKEINTRESOURCE(IDB_LOCK),
  240. IMAGE_BITMAP,
  241. 0,
  242. 0,
  243. LR_LOADTRANSPARENT|LR_DEFAULTCOLOR|LR_CREATEDIBSECTION);
  244. g_nLock = ImageList_Add(himl, hbmp, (HBITMAP) NULL);
  245. DeleteObject(hbmp);
  246. // Fail if not all of the images were added.
  247. if (ImageList_GetImageCount(himl) < NUM_BITMAPS)
  248. {
  249. TraceMsg( TF_WARNING, "CPicsDialog::InitTreeViewImageLists() - Not all images were added!" );
  250. return FALSE;
  251. }
  252. // Associate the image list with the tree-view control.
  253. SetTreeImages( hwndTV, himl );
  254. return TRUE;
  255. }
  256. void CPicsDialog::LaunchRatingSystemSite( void )
  257. {
  258. HWND hDlg = m_hWnd;
  259. TreeNode *pTN = TreeView_GetSelectionLParam(GetDlgItem(IDC_PT_TREE));
  260. if (pTN == NULL)
  261. return;
  262. PicsRatingSystem *pPRS = NULL;
  263. if (pTN->tne == tneRatingSystemInfo)
  264. pPRS = (PicsRatingSystem *)pTN->pData;
  265. else if (pTN->tne == tneRatingSystemNode) {
  266. if ((PicsCategory *)pTN->pData != NULL)
  267. pPRS = ((PicsCategory *)pTN->pData)->pPRS;
  268. }
  269. if (pPRS != NULL) {
  270. BOOL fSuccess = FALSE;
  271. HINSTANCE hShell32 = ::LoadLibrary(::szShell32);
  272. if (hShell32 != NULL) {
  273. PFNSHELLEXECUTE pfnShellExecute = (PFNSHELLEXECUTE)::GetProcAddress(hShell32, ::szShellExecute);
  274. if (pfnShellExecute != NULL) {
  275. fSuccess = (*pfnShellExecute)(hDlg, NULL, pPRS->etstrRatingService.Get(),
  276. NULL, NULL, SW_SHOW) != NULL;
  277. }
  278. ::FreeLibrary(hShell32);
  279. }
  280. if (!fSuccess) {
  281. NLS_STR nlsMessage(MAX_RES_STR_LEN);
  282. if(nlsMessage)
  283. {
  284. NLS_STR nlsTemp(STR_OWNERALLOC, pPRS->etstrRatingSystem.Get());
  285. const NLS_STR *apnls[] = { &nlsTemp, NULL };
  286. if ( WN_SUCCESS == (nlsMessage.LoadString(IDS_CANT_LAUNCH, apnls)) )
  287. {
  288. MyMessageBox(hDlg, nlsMessage.QueryPch(), IDS_GENERIC, MB_OK | MB_ICONSTOP);
  289. }
  290. }
  291. }
  292. }
  293. }
  294. void CPicsDialog::PicsDlgInit( void )
  295. {
  296. HTREEITEM hTree;
  297. TreeNode *pTN;
  298. HWND hwndTree;
  299. int x,z;
  300. HWND hDlg = m_hWnd;
  301. ASSERT( hDlg );
  302. if ( ! hDlg )
  303. {
  304. TraceMsg( TF_ERROR, "CPicsDialog::PicsDlgInit() - hDlg is NULL!" );
  305. return;
  306. }
  307. PRSD * pPRSD = m_pPRSD;
  308. ASSERT( pPRSD );
  309. if ( ! pPRSD )
  310. {
  311. TraceMsg( TF_ERROR, "CPicsDialog::PicsDlgInit() - pPRSD is NULL!" );
  312. return;
  313. }
  314. hwndTree = GetDlgItem(IDC_PT_TREE);
  315. /* Note, if there are installed providers but they all failed, there
  316. * will be dummy entries for them in the array. So we will not attempt
  317. * to install RSACi automatically unless there really are no providers
  318. * installed at all.
  319. */
  320. if (!pPRSD->pPRSI->arrpPRS.Length())
  321. {
  322. // There are no providers.
  323. if ( ! InstallDefaultProvider() )
  324. {
  325. MyMessageBox(hDlg, IDS_INSTALL_INFO, IDS_GENERIC, MB_OK);
  326. ControlsShow( tneNone );
  327. return;
  328. }
  329. }
  330. /*make the tree listing*/
  331. /*Individual Rating Systems*/
  332. InitTreeViewImageLists(hwndTree);
  333. BOOL fAnyInvalid = FALSE;
  334. BOOL fAnyValid = FALSE;
  335. for (z = 0; z < pPRSD->pPRSI->arrpPRS.Length(); ++z)
  336. {
  337. PicsRatingSystem *pPRS = pPRSD->pPRSI->arrpPRS[z];
  338. if (!(pPRS->dwFlags & PRS_ISVALID))
  339. {
  340. fAnyInvalid = TRUE;
  341. continue;
  342. }
  343. fAnyValid = TRUE;
  344. pTN = new TreeNode(tneRatingSystemInfo, pPRS);
  345. ASSERT(pTN);
  346. hTree = AddOneItem(hwndTree, NULL, (char*) pPRS->etstrName.Get(), TVI_SORT, (LPARAM) pTN, g_nLock);
  347. for (x = 0; x < pPRS->arrpPC.Length(); ++x)
  348. {
  349. AddCategory(pPRS->arrpPC[x], hwndTree, hTree);
  350. }
  351. TreeView_Expand(hwndTree, hTree, TVE_EXPAND);
  352. }
  353. if (fAnyInvalid)
  354. {
  355. MyMessageBox(hDlg, IDS_INVALID_PROVIDERS, IDS_GENERIC, MB_OK | MB_ICONWARNING);
  356. }
  357. if (fAnyValid)
  358. {
  359. HTREEITEM hTreeItem;
  360. hTreeItem=TreeView_GetNextItem(hwndTree, TreeView_GetRoot(hwndTree),TVGN_CHILD);
  361. if(hTreeItem!=NULL)
  362. {
  363. TreeView_SelectItem(hwndTree, hTreeItem);
  364. pTN = TreeView_GetSelectionLParam(GetDlgItem(IDC_PT_TREE));
  365. if (pTN)
  366. {
  367. ControlsShow( pTN->tne );
  368. switch(pTN->tne)
  369. {
  370. case tneRatingSystemInfo:
  371. SelectRatingSystemInfo( (PicsRatingSystem*) pTN->pData );
  372. break;
  373. case tneRatingSystemNode:
  374. SelectRatingSystemNode( (PicsCategory*) pTN->pData );
  375. break;
  376. }
  377. }
  378. }
  379. else
  380. {
  381. TreeView_SelectItem(hwndTree, TreeView_GetRoot(hwndTree));
  382. pTN = TreeView_GetSelectionLParam(GetDlgItem(IDC_PT_TREE));
  383. ControlsShow( tneRatingSystemInfo );
  384. if ( pTN )
  385. {
  386. SelectRatingSystemInfo( (PicsRatingSystem*) pTN->pData );
  387. }
  388. }
  389. }
  390. else
  391. {
  392. ControlsShow( tneNone );
  393. }
  394. }
  395. void CPicsDialog::KillTree(HWND hwndTree, HTREEITEM hTree)
  396. {
  397. ASSERT( hwndTree );
  398. while (hTree != NULL)
  399. {
  400. /* If this node has any items under it, delete them as well. */
  401. HTREEITEM hChild = TreeView_GetChild( hwndTree, hTree );
  402. if (hChild != NULL)
  403. {
  404. KillTree( hwndTree, hChild );
  405. }
  406. HTREEITEM hNext = TreeView_GetNextSibling( hwndTree, hTree );
  407. TreeView_SelectItem( hwndTree, hTree );
  408. delete TreeView_GetSelectionLParam( hwndTree );
  409. TreeView_DeleteItem( hwndTree, hTree );
  410. hTree = hNext;
  411. }
  412. }
  413. void CPicsDialog::PicsDlgUninit( void )
  414. {
  415. HWND hwndTree;
  416. hwndTree = GetDlgItem(IDC_PT_TREE);
  417. KillTree( hwndTree, TreeView_GetRoot(hwndTree) );
  418. // Remove the image list from the tree-view control.
  419. SetTreeImages( hwndTree, NULL );
  420. PRSD * pPRSD = m_pPRSD;
  421. ASSERT( pPRSD );
  422. /* If we have a temporary copy of the user's ratings list, destroy it. */
  423. if ( pPRSD && pPRSD->pTempRatings != NULL )
  424. {
  425. DestroyRatingSystemList(pPRSD->pTempRatings);
  426. pPRSD->pTempRatings = NULL;
  427. }
  428. ControlsShow( tneNone );
  429. }
  430. void CPicsDialog::PicsDlgSave( void )
  431. {
  432. PRSD * pPRSD = m_pPRSD;
  433. ASSERT( pPRSD );
  434. if ( ! pPRSD )
  435. {
  436. TraceMsg( TF_ERROR, "CPicsDialog::PicsDlgSave() - pPRSD is NULL!" );
  437. return;
  438. }
  439. /* To save changes, throw away the user's ratings list and steal the
  440. * temporary copy we're using in the dialog. As an optimization, we
  441. * don't copy it here, because in the case of OK, we'd just be destroying
  442. * the original immediately after this. If the user hit Apply, we'll
  443. * re-clone a new temp ratings list for the dialog's purpose the next
  444. * time we need one.
  445. *
  446. * If there is no temporary copy, then PicsDlgSave is a nop.
  447. */
  448. if (pPRSD->pTempRatings != NULL)
  449. {
  450. DestroyRatingSystemList(pPRSD->pPU->m_pRatingSystems);
  451. pPRSD->pPU->m_pRatingSystems = pPRSD->pTempRatings;
  452. pPRSD->pTempRatings = NULL;
  453. }
  454. }
  455. #ifdef RATING_LOAD_GRAPHICS /* loading icon out of msrating.dll? completely bogus. */
  456. POINT CPicsDialog::BitmapWindowCoord( int nID )
  457. {
  458. POINT pt;
  459. RECT rD, rI;
  460. pt.x = ::GetWindowRect(GetDlgItem(nID), &rI);
  461. pt.y = GetWindowRect(&rD);
  462. pt.x = rI.left - rD.left;
  463. pt.y = rI.top - rD.top;
  464. return pt;
  465. }
  466. void CPicsDialog::LoadGraphic( char *pIcon, POINT pt )
  467. {
  468. HICON hIcon;
  469. int i;
  470. MyAtoi(pIcon, &i);
  471. PRSD * pPRSD = m_pPRSD;
  472. ASSERT( pPRSD );
  473. if ( ! pPRSD )
  474. {
  475. TraceMsg( TF_ERROR, "CPicsDialog::LoadGraphic() - pPRSD is NULL!" );
  476. return;
  477. }
  478. // No need to pull from msratelc.dll for non-localized icons.
  479. hIcon = pIcon ? LoadIcon( g_hInstance, MAKEINTRESOURCE(i) ) : NULL;
  480. if (hIcon)
  481. {
  482. HWND hwndBitmapCategory;
  483. HWND hDlg = m_hWnd;
  484. ASSERT( hDlg );
  485. if ( ! hDlg )
  486. {
  487. TraceMsg( TF_ERROR, "CPicsDialog::LoadGraphic() - hDlg is NULL!" );
  488. return;
  489. }
  490. hwndBitmapCategory = CreateWindow("Static",NULL,SS_ICON|WS_CHILD, pt.x, pt.y,0,0,hDlg, NULL,NULL,0);
  491. ::ShowWindow( hwndBitmapCategory, SW_SHOW );
  492. DeleteObject( (HGDIOBJ) SendMessage( hwndBitmapCategory, STM_SETIMAGE, IMAGE_ICON, (LPARAM) hIcon) );
  493. pPRSD->hwndBitmapCategory = hwndBitmapCategory;
  494. }
  495. }
  496. #endif /* RATING_LOAD_GRAPHICS */
  497. PicsEnum* CPicsDialog::PosToEnum(PicsCategory *pPC, LPARAM lPos)
  498. {
  499. int z, diff=-1, temp;
  500. PicsEnum *pPE=NULL;
  501. for (z=0;z<pPC->arrpPE.Length();++z){
  502. temp = (int) (lPos-pPC->arrpPE[z]->etnValue.Get());
  503. if (temp>=0){
  504. if (temp<diff || diff==-1){
  505. diff = temp;
  506. pPE = pPC->arrpPE[z];
  507. }
  508. }
  509. }
  510. return pPE;
  511. }
  512. void CPicsDialog::NewTrackbarPosition( void )
  513. {
  514. signed long lPos;
  515. TreeNode *pTN;
  516. PicsEnum *pPE;
  517. PicsCategory *pPC;
  518. PRSD * pPRSD = m_pPRSD;
  519. ASSERT( pPRSD );
  520. if ( ! pPRSD )
  521. {
  522. TraceMsg( TF_ERROR, "CPicsDialog::NewTrackbarPosition() - pPRSD is NULL!" );
  523. return;
  524. }
  525. DeleteBitmapWindow( pPRSD->hwndBitmapLabel );
  526. pTN = TreeView_GetSelectionLParam(GetDlgItem(IDC_PT_TREE));
  527. if (pTN == NULL)
  528. return;
  529. pPC = (PicsCategory*) pTN->pData;
  530. BOOL fLabelled = pPC->etfLabelled.fIsInit() && pPC->etfLabelled.Get();
  531. lPos = (long) SendMessage(GetDlgItem(IDC_PT_TB_SELECT), TBM_GETPOS, 0, 0);
  532. pPE = PosToEnum(pPC, fLabelled ? (LPARAM) pPC->arrpPE[lPos]->etnValue.Get() : lPos);
  533. if (pPE)
  534. {
  535. ::SetWindowText(GetDlgItem(IDC_PT_T_RSN_SDESC), pPE->etstrName.Get());
  536. ::SetWindowText(GetDlgItem(IDC_PT_T_RSN_LDESC),
  537. pPE->etstrDesc.fIsInit() ? pPE->etstrDesc.Get() : szNULL);
  538. }
  539. else
  540. {
  541. char pszBuf[MAXPATHLEN];
  542. char rgBuf[sizeof(pszBuf) + 12]; // big enough to insert a number
  543. MLLoadStringA(IDS_VALUE, pszBuf, sizeof(pszBuf));
  544. wsprintf(rgBuf, pszBuf, lPos);
  545. ::SetWindowText(GetDlgItem(IDC_PT_T_RSN_SDESC), rgBuf);
  546. ::SetWindowText(GetDlgItem(IDC_PT_T_RSN_LDESC),
  547. pPC->etstrDesc.fIsInit() ? pPC->etstrDesc.Get() : szNULL);
  548. }
  549. /* save the selected value into the temporary ratings list */
  550. UserRating *pRating = GetTempRating( pPC );
  551. if (pRating != NULL)
  552. {
  553. pRating->m_nValue = (int) (fLabelled ? pPC->arrpPE[lPos]->etnValue.Get() : lPos);
  554. }
  555. }
  556. void CPicsDialog::SelectRatingSystemNode( PicsCategory *pPC )
  557. {
  558. HWND hwnd;
  559. BOOL fLabelOnly;
  560. LPARAM lValue;
  561. int z;
  562. ASSERT( pPC );
  563. if ( ! pPC )
  564. {
  565. TraceMsg( TF_ERROR, "CPicsDialog::SelectRatingSystemNode() - pPC is NULL!" );
  566. return;
  567. }
  568. #ifdef RATING_LOAD_GRAPHICS
  569. /*Category Icon*/
  570. if (pPC->etstrIcon.fIsInit())
  571. {
  572. // Load Graphic to m_pPRSD->hwndBitmapCategory
  573. LoadGraphic( pPC->etstrIcon.Get(), BitmapWindowCoord( IDC_PT_T_BITMAP_LABEL ) );
  574. }
  575. #endif
  576. /*Setup Trackbar*/
  577. if ((pPC->etnMax.fIsInit() && P_INFINITY==pPC->etnMax.Get())
  578. ||
  579. (pPC->etnMin.fIsInit() && N_INFINITY==pPC->etnMin.Get())
  580. ||
  581. (!(pPC->etnMin.fIsInit() && pPC->etnMax.fIsInit()))
  582. )
  583. {
  584. ShowHideControl( IDC_PT_T_RSN_SDESC, FALSE );
  585. ShowHideControl( IDC_PT_T_RSN_LDESC, FALSE );
  586. ShowHideControl( IDC_PT_TB_SELECT, FALSE );
  587. }
  588. else
  589. {
  590. hwnd = GetDlgItem(IDC_PT_TB_SELECT);
  591. SendMessage(hwnd, TBM_CLEARTICS, TRUE, 0);
  592. fLabelOnly = pPC->etfLabelled.fIsInit() && pPC->etfLabelled.Get();
  593. /*Ranges*/
  594. if (pPC->etnMax.fIsInit())
  595. {
  596. lValue = (LPARAM) ( fLabelOnly ? pPC->arrpPE.Length()-1 : pPC->etnMax.Get() );
  597. SendMessage(hwnd, TBM_SETRANGEMAX, TRUE, lValue);
  598. ASSERT(lValue == SendMessage(hwnd, TBM_GETRANGEMAX, 0,0));
  599. }
  600. if (pPC->etnMin.fIsInit())
  601. {
  602. lValue = (LPARAM) ( fLabelOnly ? 0 : pPC->etnMin.Get() );
  603. SendMessage(hwnd, TBM_SETRANGEMIN, TRUE, lValue);
  604. ASSERT(lValue == SendMessage(hwnd, TBM_GETRANGEMIN, 0,0));
  605. }
  606. /*Ticks*/
  607. for (z=0;z<pPC->arrpPE.Length();++z)
  608. {
  609. lValue = (LPARAM) ( fLabelOnly ? z : pPC->arrpPE[z]->etnValue.Get());
  610. SendMessage(hwnd, TBM_SETTIC, 0, lValue);
  611. }
  612. /*Initial Position of trackbar*/
  613. UserRating *pRating = GetTempRating( pPC );
  614. if (pRating != NULL)
  615. {
  616. if (fLabelOnly)
  617. {
  618. for (z=0;z<pPC->arrpPE.Length();++z)
  619. {
  620. if (pPC->arrpPE[z]->etnValue.Get() == pRating->m_nValue)
  621. {
  622. lValue=z;
  623. break;
  624. }
  625. }
  626. }
  627. else
  628. {
  629. lValue = (LPARAM) pRating->m_nValue;
  630. }
  631. }
  632. else
  633. {
  634. lValue = (LPARAM) ( fLabelOnly ? 0 : pPC->etnMin.Get());
  635. }
  636. SendMessage(hwnd, TBM_SETPOS, TRUE, lValue);
  637. // On dialog close, setting the trackbar position fails.
  638. // ASSERT(lValue == SendMessage(hwnd, TBM_GETPOS, 0,0));
  639. NewTrackbarPosition();
  640. }
  641. }
  642. void CPicsDialog::SelectRatingSystemInfo( PicsRatingSystem *pPRS )
  643. {
  644. ASSERT( pPRS );
  645. if ( ! pPRS )
  646. {
  647. TraceMsg( TF_ERROR, "CPicsDialog::SelectRatingSystemInfo() - pPRS is NULL!" );
  648. return;
  649. }
  650. ::SetWindowText(GetDlgItem(IDC_PT_T_RSN_LDESC), pPRS->etstrDesc.Get());
  651. #ifdef RATING_LOAD_GRAPHICS
  652. if (pPRS->etstrIcon.fIsInit())
  653. {
  654. // Load Graphic to m_pPRSD->hwndBitmapCategory
  655. LoadGraphic( pPRS->etstrIcon.Get(), BitmapWindowCoord( IDC_PT_T_BITMAP_LABEL ) );
  656. }
  657. #endif
  658. }
  659. void CPicsDialog::DeleteBitmapWindow( HWND & p_rhwnd )
  660. {
  661. if (p_rhwnd)
  662. {
  663. DeleteObject( (HGDIOBJ) SendMessage(p_rhwnd, STM_GETIMAGE, IMAGE_BITMAP, 0));
  664. ::DestroyWindow(p_rhwnd);
  665. p_rhwnd = 0;
  666. }
  667. }
  668. void CPicsDialog::ControlsShow( TreeNodeEnum tne )
  669. {
  670. BOOL fEnable;
  671. /*Bitmap placeholders never need to be seen*/
  672. ShowHideControl( IDC_PT_T_BITMAP_CATEGORY, FALSE );
  673. ShowHideControl( IDC_PT_T_BITMAP_LABEL, FALSE );
  674. PRSD * pPRSD = m_pPRSD;
  675. ASSERT( pPRSD );
  676. /*Kill old graphic windows*/
  677. if ( pPRSD )
  678. {
  679. DeleteBitmapWindow( pPRSD->hwndBitmapCategory );
  680. DeleteBitmapWindow( pPRSD->hwndBitmapLabel );
  681. }
  682. /*RatingSystemNode Controls*/
  683. fEnable = (tne == tneRatingSystemNode);
  684. ShowHideControl( IDC_PT_T_RSN_SDESC, fEnable );
  685. ShowHideControl( IDC_PT_TB_SELECT, fEnable );
  686. ShowHideControl( IDC_RATING_LABEL, fEnable );
  687. /*RatingSystemInfo Controls*/
  688. fEnable = (tne==tneRatingSystemInfo || tne==tneRatingSystemNode);
  689. ShowHideControl( IDC_PT_T_RSN_LDESC, fEnable);
  690. ShowHideControl( IDC_DETAILSBUTTON, fEnable);
  691. }
  692. TreeNode* CPicsDialog::TreeView_GetSelectionLParam(HWND hwndTree){
  693. TV_ITEM tv;
  694. tv.mask = TVIF_HANDLE | TVIF_PARAM;
  695. tv.hItem = TreeView_GetSelection(hwndTree);
  696. if (SendMessage(hwndTree, TVM_GETITEM, 0, (LPARAM) &tv)) return (TreeNode*) tv.lParam;
  697. else return 0;
  698. }
  699. HTREEITEM CPicsDialog::AddOneItem(HWND hwndTree, HTREEITEM hParent, LPSTR szText, HTREEITEM hInsAfter, LPARAM lpData, int iImage){
  700. HTREEITEM hItem;
  701. TV_ITEM tvI;
  702. TV_INSERTSTRUCT tvIns;
  703. // The .pszText is filled in.
  704. tvI.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
  705. tvI.iSelectedImage = iImage;
  706. tvI.iImage = iImage;
  707. tvI.pszText = szText;
  708. tvI.cchTextMax = strlenf(szText);
  709. tvI.lParam = lpData;
  710. tvIns.item = tvI;
  711. tvIns.hInsertAfter = hInsAfter;
  712. tvIns.hParent = hParent;
  713. // Insert the item into the tree.
  714. hItem = (HTREEITEM)SendMessage(hwndTree, TVM_INSERTITEM, 0, (LPARAM)(LPTV_INSERTSTRUCT)&tvIns);
  715. return (hItem);
  716. }
  717. void CPicsDialog::AddCategory(PicsCategory *pPC, HWND hwndTree, HTREEITEM hParent){
  718. int z;
  719. char *pc;
  720. TreeNode *pTN;
  721. /*if we have a real name, us it, else use transmission name*/
  722. if (pPC->etstrName.fIsInit())
  723. {
  724. pc = pPC->etstrName.Get();
  725. }
  726. else if (pPC->etstrDesc.fIsInit())
  727. {
  728. pc = pPC->etstrDesc.Get();
  729. }
  730. else
  731. {
  732. pc = (char*) pPC->etstrTransmitAs.Get();
  733. }
  734. /*Category Tab*/
  735. pTN = new TreeNode(tneRatingSystemNode, pPC);
  736. ASSERT(pTN);
  737. /*insert self*/
  738. hParent = AddOneItem(hwndTree, hParent, pc, TVI_SORT, (LPARAM) pTN, g_nKeys);
  739. /*insert children*/
  740. int cChildren = pPC->arrpPC.Length();
  741. if (cChildren > 0) {
  742. for (z = 0; z < cChildren; ++z)
  743. AddCategory(pPC->arrpPC[z], hwndTree, hParent);
  744. TreeView_Expand(hwndTree, hParent, TVE_EXPAND);
  745. }
  746. }
  747. BOOL CPicsDialog::InstallDefaultProvider( void )
  748. {
  749. NLS_STR nlsFilename(MAXPATHLEN);
  750. BOOL fRet = FALSE;
  751. PRSD * pPRSD = m_pPRSD;
  752. ASSERT( pPRSD );
  753. if ( ! pPRSD )
  754. {
  755. TraceMsg( TF_ERROR, "CPicsDialog::InstallDefaultProvider() - pPRSD is NULL!" );
  756. return fRet;
  757. }
  758. if (nlsFilename.QueryError() != ERROR_SUCCESS)
  759. {
  760. TraceMsg( TF_ERROR, "CPicsDialog::InstallDefaultProvider() - nlsFilename Allocation Failed!" );
  761. return fRet;
  762. }
  763. CHAR * pszFileName = nlsFilename.Party();
  764. if (pszFileName)
  765. {
  766. GetSystemDirectory(pszFileName, nlsFilename.QueryAllocSize());
  767. nlsFilename.DonePartying();
  768. LPSTR pszBackslash = ::strrchrf(nlsFilename.QueryPch(), '\\');
  769. if (pszBackslash == NULL || *(pszBackslash+1) != '\0')
  770. nlsFilename.strcat(szBACKSLASH);
  771. nlsFilename.strcat(szDEFAULTRATFILE);
  772. PicsRatingSystem *pPRS;
  773. HRESULT hres = LoadRatingSystem(nlsFilename.QueryPch(), &pPRS);
  774. if (pPRS != NULL)
  775. {
  776. pPRSD->pPRSI->arrpPRS.Append(pPRS);
  777. fRet = TRUE;
  778. }
  779. pPRSD->pPRSI->fRatingInstalled = fRet;
  780. CheckUserSettings(pPRS); /* give user default settings for all categories */
  781. }
  782. else
  783. {
  784. nlsFilename.DonePartying();
  785. }
  786. return fRet;
  787. }
  788. /* GetTempRatingList returns the dialog's temporary copy of the user's rating
  789. * system list. If we don't have any such temporary copy yet, we make one.
  790. */
  791. UserRatingSystem * CPicsDialog::GetTempRatingList( void )
  792. {
  793. PRSD * pPRSD = m_pPRSD;
  794. ASSERT( pPRSD );
  795. if ( ! pPRSD )
  796. {
  797. TraceMsg( TF_ERROR, "CPicsDialog::GetTempRatingList() - pPRSD is NULL!" );
  798. return NULL;
  799. }
  800. if (pPRSD->pTempRatings == NULL)
  801. {
  802. pPRSD->pTempRatings = DuplicateRatingSystemList(pPRSD->pPU->m_pRatingSystems);
  803. }
  804. return pPRSD->pTempRatings;
  805. }
  806. UserRating * CPicsDialog::GetTempRating( PicsCategory *pPC )
  807. {
  808. UserRating *pRating = NULL;
  809. /* save the selected value into the temporary ratings list */
  810. UserRatingSystem *pURS = GetTempRatingList();
  811. LPSTR pszRatingService = pPC->pPRS->etstrRatingService.Get();
  812. if (pURS != NULL)
  813. {
  814. pURS = FindRatingSystem(pURS, pszRatingService);
  815. }
  816. if (pURS == NULL)
  817. {
  818. pURS = new UserRatingSystem;
  819. if (pURS == NULL)
  820. {
  821. TraceMsg( TF_ERROR, "CPicsDialog::GetTempRating() - pURS is NULL!" );
  822. return NULL;
  823. }
  824. PRSD * pPRSD = m_pPRSD;
  825. ASSERT( pPRSD );
  826. pURS->SetName(pszRatingService);
  827. pURS->m_pNext = pPRSD ? pPRSD->pTempRatings : NULL;
  828. pURS->m_pPRS = pPC->pPRS;
  829. if ( pPRSD )
  830. {
  831. pPRSD->pTempRatings = pURS;
  832. }
  833. }
  834. LPSTR pszRatingName = pPC->etstrTransmitAs.Get();
  835. pRating = pURS->FindRating(pszRatingName);
  836. if (pRating == NULL)
  837. {
  838. pRating = new UserRating;
  839. if (pRating == NULL)
  840. {
  841. TraceMsg( TF_ERROR, "CPicsDialog::GetTempRating() - pRating is NULL!" );
  842. return NULL;
  843. }
  844. pRating->SetName(pszRatingName);
  845. pRating->m_pPC = pPC;
  846. if (!pPC->etnMin.fIsInit() || (pPC->etfLabelled.fIsInit() && pPC->etfLabelled.Get()))
  847. {
  848. pRating->m_nValue = 0;
  849. }
  850. else
  851. {
  852. pRating->m_nValue = pPC->etnMin.Get();
  853. }
  854. pURS->AddRating(pRating);
  855. }
  856. return pRating;
  857. }