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.

774 lines
24 KiB

  1. #include "header.h"
  2. #ifndef __CDEFINESS_H__
  3. #include "CDefinSS.h"
  4. #endif
  5. #ifndef HHCTRL
  6. #include "..\hhw\strtable.h"
  7. #else
  8. #include "strtable.h"
  9. #include "secwin.h"
  10. #include "adsearch.h"
  11. #endif
  12. LRESULT WINAPI TreeViewProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  13. void FreeChildrenAllocations(HWND hwndTreeView, HTREEITEM ti);
  14. void AddChildren( TVITEM* pTvi, HWND hwndTreeView );
  15. CDefineSubSet::CDefineSubSet( HWND hwndParent, CSubSets *pSubSets, CInfoType *pInfoType, BOOL fHidden=FALSE )
  16. #ifdef HHCTRL
  17. :CDlg( hwndParent, CDefineSubSet::IDD )
  18. #else
  19. :CDlg( CDefineSubSet::IDD, hwndParent )
  20. #endif
  21. {
  22. m_pSSRoot = NULL;
  23. m_pInfoType = pInfoType;
  24. m_hwndTree = NULL;
  25. m_cFonts = 0;
  26. m_pSSRoot =NULL;
  27. m_pSubSets = pSubSets;
  28. m_ahfonts = (HFONT*) lcCalloc(3 * sizeof(HFONT));
  29. m_cFonts=0;
  30. m_fModified = FALSE;
  31. m_pSubSet = new CSubSet( pInfoType->InfoTypeSize());
  32. m_pSubSet->m_pIT = m_pSubSets->m_pIT;
  33. int fnWeight = 100;
  34. int err_cnt=0;
  35. while( (m_cFonts<3) && (fnWeight<900) )
  36. {
  37. m_ahfonts[m_cFonts] = CreateFont( 0,0,0,0,
  38. fnWeight,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,
  39. CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,NULL );
  40. if ( m_ahfonts[m_cFonts] )
  41. {
  42. m_cFonts++;
  43. fnWeight +=300;
  44. err_cnt=0;
  45. }
  46. else
  47. {
  48. fnWeight += 100;
  49. err_cnt++;
  50. if ( err_cnt == 3)
  51. {
  52. m_cFonts++;
  53. err_cnt=0;
  54. }
  55. }
  56. }
  57. }
  58. CDefineSubSet::~CDefineSubSet(void)
  59. {
  60. TV_ITEM hCur;
  61. hCur.hItem = TreeView_GetRoot(m_hwndTree);
  62. hCur.mask = TVIF_PARAM;
  63. if (TreeView_GetItem(m_hwndTree, &hCur) == TRUE)
  64. {
  65. if (hCur.lParam)
  66. {
  67. //delete ( *)hCur.lParam;
  68. }
  69. }
  70. if (IsValidWindow(m_hwndTree))
  71. DestroyWindow(m_hwndTree);
  72. if (m_cFonts)
  73. {
  74. for (int i = 0; i < m_cFonts; i++)
  75. if ( m_ahfonts[i] )
  76. DeleteObject(m_ahfonts[i]);
  77. lcFree(m_ahfonts);
  78. }
  79. if (m_hil)
  80. ImageList_Destroy(m_hil);
  81. // if ( m_pSubSet )
  82. // delete m_pSubSet;
  83. }
  84. __inline HTREEITEM Tree_AddItem(HWND hwndTree,
  85. HTREEITEM htiParent, int iImage, UINT cChildren, LPARAM lParam,
  86. TV_INSERTSTRUCT* ptcInsert)
  87. {
  88. ptcInsert->hParent = htiParent;
  89. ptcInsert->item.iImage = iImage;
  90. ptcInsert->item.iSelectedImage = iImage;
  91. ptcInsert->item.cChildren = cChildren;
  92. ptcInsert->item.lParam = lParam;
  93. return TreeView_InsertItem(hwndTree, ptcInsert);
  94. }
  95. BOOL CDefineSubSet::InitTreeView(int iSubSet=0) //By Default the first subset is selected.
  96. {
  97. // Suspend drawing to the treeview while it is being populated
  98. // ::SendMessage(m_hwndTree, WM_SETREDRAW, FALSE, 0);
  99. TV_INSERTSTRUCT tcAdd;
  100. tcAdd.hInsertAfter = TVI_LAST;
  101. tcAdd.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_CHILDREN | TVIF_PARAM;
  102. tcAdd.item.hItem = NULL;
  103. HTREEITEM CatParent = TVI_ROOT;
  104. if ( m_pSubSets && m_pSubSets->m_cur_Set )
  105. *m_pSubSet = *m_pSubSets->m_cur_Set;
  106. TreeView_DeleteAllItems( m_hwndTree );
  107. for ( int cat=0; cat<m_pInfoType->HowManyCategories(); cat++)
  108. {
  109. CStr cszTemp = m_pInfoType->GetCategoryString(cat+1);
  110. tcAdd.item.pszText = cszTemp.psz;
  111. tcAdd.item.cchTextMax = (int)strlen(tcAdd.item.pszText);
  112. CatParent = Tree_AddItem(m_hwndTree,
  113. TVI_ROOT, // The parent tree item
  114. 0, // image Number, categories all have image 0... the image does not change
  115. (m_pInfoType->m_itTables.m_aCategories[cat-1].c_Types>0)?1:0, // # children
  116. (LPARAM) NULL,
  117. &tcAdd);
  118. if ( m_pSSRoot == NULL )
  119. m_pSSRoot = &CatParent;
  120. int type = m_pInfoType->GetFirstCategoryType(cat);
  121. while( type != -1 )
  122. {
  123. CStr cszTemp = m_pInfoType->GetInfoTypeName( type );
  124. tcAdd.item.pszText = cszTemp.psz;
  125. tcAdd.item.cchTextMax = (int)strlen( tcAdd.item.pszText );
  126. int iState = GetITState(type);
  127. SetItemFont( m_ahfonts[iState] );
  128. Tree_AddItem(m_hwndTree,
  129. CatParent,
  130. iState, // The image number
  131. 0, // no children
  132. (LPARAM)type,
  133. &tcAdd);
  134. type = m_pInfoType->GetNextITinCategory();
  135. }
  136. }
  137. if ( m_pInfoType->HowManyCategories() == 0 )
  138. {
  139. for (int type = 1; type<m_pInfoType->HowManyInfoTypes(); type++)
  140. {
  141. CStr cszTemp = m_pInfoType->GetInfoTypeName( type );
  142. tcAdd.item.pszText = cszTemp.psz;
  143. tcAdd.item.cchTextMax = (int)strlen( tcAdd.item.pszText );
  144. int iState = GetITState(type);
  145. SetItemFont( m_ahfonts[iState] );
  146. HTREEITEM hret = Tree_AddItem(m_hwndTree,
  147. TVI_ROOT,
  148. iState, // The image number
  149. 0, // no children
  150. (LPARAM)type,
  151. &tcAdd);
  152. if ( m_pSSRoot == NULL )
  153. m_pSSRoot = &hret;
  154. }
  155. }
  156. // Activate redraws to the treeview.
  157. // ::SendMessage(m_hwndTree, WM_SETREDRAW, TRUE, 0);
  158. return TRUE;
  159. }
  160. int CDefineSubSet::GetITState(int const type )
  161. {
  162. INFOTYPE *pIT;
  163. if ( !m_pSubSet )
  164. return DONT_CARE;
  165. pIT = m_pSubSet->m_pInclusive + (type/32)*4;
  166. if ( *pIT & 1<<type )
  167. {
  168. return INCLUSIVE;
  169. }
  170. else
  171. {
  172. pIT = m_pSubSet->m_pExclusive + (type/32)*4;
  173. if( *pIT & 1<<type )
  174. {
  175. return EXCLUSIVE;
  176. }
  177. else
  178. {
  179. return DONT_CARE;
  180. }
  181. }
  182. }
  183. // Incerement treeview item state
  184. int CDefineSubSet::IncState(int const type)
  185. {
  186. int state;
  187. INFOTYPE *pIT;
  188. if ( !m_pSubSet )
  189. return DONT_CARE;
  190. pIT = m_pSubSet->m_pInclusive + (type/32)*4;
  191. if ( *pIT & 1<<type )
  192. {
  193. state=EXCLUSIVE;
  194. DeleteIT(type, m_pSubSet->m_pInclusive);
  195. AddIT(type, m_pSubSet->m_pExclusive);
  196. }
  197. else
  198. {
  199. pIT = m_pSubSet->m_pExclusive + (type/32)*4;
  200. if( *pIT & 1<<type )
  201. {
  202. state = DONT_CARE;
  203. DeleteIT(type, m_pSubSet->m_pExclusive);
  204. }
  205. else
  206. {
  207. state = INCLUSIVE;
  208. AddIT( type, m_pSubSet->m_pInclusive);
  209. }
  210. }
  211. return state;
  212. }
  213. void CDefineSubSet::SetItemFont(HFONT hFont)
  214. {
  215. return;
  216. if ( hFont == NULL )
  217. return;
  218. ::SendMessage(m_hwndTree, WM_SETFONT, (WPARAM) hFont, 0);
  219. }
  220. BOOL CDefineSubSet::OnBeginOrEnd()
  221. {
  222. if ( m_fInitializing )
  223. {
  224. #ifdef HHCTRL
  225. m_hwndTree = ::GetDlgItem(m_hWnd, IDC_TREE1);
  226. HWND hlistBox = ::GetDlgItem(m_hWnd, IDC_LIST_SUBSETS);
  227. m_hil = ImageList_LoadImage(_Module.GetResourceInstance(),
  228. MAKEINTRESOURCE(IDBMP_HH_SS_IMAGE_LIST),
  229. SS_IMAGELIST_WIDTH, 0, 0x00FF00FF, IMAGE_BITMAP, LR_DEFAULTCOLOR);
  230. #else
  231. m_hwndTree = ::GetDlgItem(m_hdlg, IDC_TREE1);
  232. HWND hlistBox = ::GetDlgItem(m_hdlg, IDC_LIST_SUBSETS);
  233. m_hil = ImageList_LoadImage(HINST_THIS,
  234. MAKEINTRESOURCE(IDBMP_SS_IMAGE_LIST),
  235. SS_IMAGELIST_WIDTH, 0, CLR_NONE, IMAGE_BITMAP, LR_DEFAULTCOLOR);
  236. #endif
  237. for (int i=0; i< m_pSubSets->HowManySubSets(); i++)
  238. {
  239. CSubSet *pSSTemp = m_pSubSets->GetSubSet(i);
  240. if (pSSTemp == NULL )
  241. continue;
  242. ::SendMessage(hlistBox, LB_ADDSTRING, 0, (LPARAM)(PCSTR)pSSTemp->m_cszSubSetName.psz);
  243. }
  244. if ( m_pSubSets->m_cur_Set )
  245. SetWindowText(IDC_SUBSET_NAME, m_pSubSets->m_cur_Set->m_cszSubSetName.psz);
  246. TreeView_SetImageList(m_hwndTree, m_hil, TVSIL_NORMAL);
  247. InitTreeView();
  248. m_fInitializing = FALSE;
  249. }
  250. else
  251. {
  252. }
  253. return TRUE;
  254. }
  255. BOOL CDefineSubSet::Save()
  256. {
  257. CStr cszSaveName;
  258. #ifndef HHCTRL
  259. HWND hwndLb = ::GetDlgItem(m_hdlg, IDC_LIST_SUBSETS);
  260. #else
  261. HWND hwndLb = ::GetDlgItem(m_hWnd, IDC_LIST_SUBSETS);
  262. #endif
  263. CStr csz1 = GetStringResource(IDS_SAVESUBSET);
  264. CStr csz2 = GetStringResource(IDS_SAVESUBSET_TITLE);
  265. cszSaveName.ReSize(80);
  266. #ifndef HHCTRL
  267. cszSaveName.GetText(m_hdlg, IDC_SUBSET_NAME );
  268. #else
  269. cszSaveName.GetText(m_hWnd, IDC_SUBSET_NAME );
  270. #endif
  271. if( ::MessageBox(NULL, csz1.psz, csz2.psz, MB_YESNO|MB_TASKMODAL) == IDYES )
  272. {
  273. CNameSubSet SSName( *this, cszSaveName, 79);
  274. if ( !SSName.DoModal() )
  275. return FALSE;
  276. if ( m_pSubSets->GetSubSetIndex( cszSaveName.psz) == -1 )
  277. { // Add a new subset
  278. m_pSubSet->m_cszSubSetName = cszSaveName.psz;
  279. m_pSubSets->AddSubSet( m_pSubSet );
  280. }
  281. else
  282. {
  283. m_pSubSets->SelectSubSet( cszSaveName.psz );
  284. memcpy(m_pSubSets->m_cur_Set, m_pSubSet->m_pInclusive, m_pSubSet->m_ITSize);
  285. memcpy(m_pSubSets->m_cur_Set, m_pSubSet->m_pExclusive, m_pSubSet->m_ITSize);
  286. }
  287. m_pSubSets->m_cur_Set->BuildMask();
  288. m_fSaveHHP = TRUE;
  289. return TRUE;
  290. }
  291. return FALSE;
  292. }
  293. void CDefineSubSet::OnSelChange(UINT id)
  294. {
  295. #ifndef HHCTRL
  296. HWND hwndLb = ::GetDlgItem(m_hdlg, IDC_LIST_SUBSETS);
  297. #else
  298. HWND hwndLb = ::GetDlgItem(m_hWnd, IDC_LIST_SUBSETS);
  299. #endif
  300. if (id == IDC_LIST_SUBSETS )
  301. {
  302. INT_PTR iSel = ::SendMessage(hwndLb, LB_GETCURSEL, (WPARAM)0, (LPARAM)0L);
  303. int ilen = (int)::SendMessage(hwndLb, LB_GETTEXTLEN, (WPARAM)iSel, (LPARAM)0L);
  304. CStr cszNewSS;
  305. cszNewSS.ReSize(ilen+1);
  306. ::SendMessage(hwndLb, LB_GETTEXT, (WPARAM) iSel, (LPARAM)(PSTR)cszNewSS.psz);
  307. SetWindowText( IDC_SUBSET_NAME, cszNewSS.psz );
  308. if ( m_fModified )
  309. Save();
  310. m_fModified = FALSE;
  311. *m_pSubSet = *(m_pSubSets->SelectSubSet(cszNewSS.psz));
  312. InitTreeView();
  313. }
  314. }
  315. void CDefineSubSet::OnButton( UINT id )
  316. {
  317. CStr cszNewSubSet(IDS_NEW);
  318. #ifndef HHCTRL
  319. HWND hwndLb = ::GetDlgItem(m_hdlg, IDC_LIST_SUBSETS);
  320. #else
  321. HWND hwndLb = ::GetDlgItem(m_hWnd, IDC_LIST_SUBSETS);
  322. #endif
  323. switch( id )
  324. {
  325. case IDC_REMOVE:
  326. {
  327. INT_PTR iSel=::SendMessage(hwndLb, LB_GETCURSEL, (WPARAM) 0, (LPARAM)(PSTR)m_pSubSet->m_cszSubSetName.psz);
  328. if ( strcmp(m_pSubSet->m_cszSubSetName.psz, cszNewSubSet.psz) == 0)
  329. break;
  330. ::SendMessage(hwndLb, LB_DELETESTRING, (WPARAM) iSel, (LPARAM)0L);
  331. m_pSubSets->RemoveSubSet( m_pSubSet->m_cszSubSetName.psz );
  332. int iLen = (int)::SendMessage(hwndLb, LB_GETTEXTLEN, (WPARAM) 1, (LPARAM) 0L);
  333. m_pSubSet->m_cszSubSetName.ReSize(iLen);
  334. ::SendMessage(hwndLb, LB_GETTEXT, (WPARAM) 1, (LPARAM)(PSTR)m_pSubSet->m_cszSubSetName);
  335. if ( !m_pSubSet->m_cszSubSetName.IsEmpty() )
  336. {
  337. m_pSubSets->SelectSubSet( m_pSubSet->m_cszSubSetName );
  338. ::SendMessage(hwndLb, LB_SETCURSEL, (WPARAM) 1, (LPARAM) 0L);
  339. Refresh();
  340. }
  341. else
  342. {
  343. SetWindowText( IDC_SUBSET_NAME, " ");
  344. m_pSubSet = NULL;
  345. m_pSubSets->m_cur_Set = NULL;
  346. }
  347. InitTreeView();
  348. m_fSaveHHP = TRUE;
  349. break;
  350. }
  351. case IDC_SAVE:
  352. if ( Save() )
  353. {
  354. INT_PTR iSel = ::SendMessage(hwndLb, LB_ADDSTRING, (WPARAM) 0, (LPARAM)(PSTR)m_pSubSet->m_cszSubSetName.psz);
  355. ::SendMessage(hwndLb, LB_SETCURSEL, (WPARAM) iSel, (LPARAM)0L);
  356. Refresh();
  357. }
  358. m_fModified = FALSE;
  359. break;
  360. case IDC_CLOSE:
  361. EndDialog( TRUE );
  362. break;
  363. }
  364. }
  365. void CDefineSubSet::Refresh()
  366. {
  367. #ifndef HHCTRL
  368. HWND hwndLb = ::GetDlgItem(m_hdlg, IDC_LIST_SUBSETS);
  369. #else
  370. HWND hwndLb = ::GetDlgItem(m_hWnd, IDC_LIST_SUBSETS);
  371. #endif
  372. INT_PTR iSel = ::SendMessage(hwndLb, LB_GETCURSEL, (WPARAM) 0, (LPARAM)0L);
  373. ::SendMessage(hwndLb, LB_SETCURSEL, (WPARAM) iSel, (LPARAM)0L);
  374. SetWindowText(IDC_SUBSET_NAME, m_pSubSet->m_cszSubSetName.psz);
  375. }
  376. LRESULT CDefineSubSet::OnDlgMsg(UINT msg, WPARAM wParam, LPARAM lParam)
  377. {
  378. switch(msg)
  379. {
  380. case WM_NOTIFY:
  381. TreeViewMsg( (NM_TREEVIEW*) lParam );
  382. break;
  383. default:
  384. ;
  385. }
  386. return FALSE;
  387. }
  388. LRESULT CDefineSubSet::TreeViewMsg(NM_TREEVIEW* pnmhdr)
  389. {
  390. switch(pnmhdr->hdr.code) {
  391. // The return key cycles through the states of the
  392. // currently selected item in the treeview.
  393. case NM_RETURN:
  394. {
  395. TV_ITEM tvi;
  396. tvi.hItem = TreeView_GetSelection(m_hwndTree);
  397. if (!tvi.hItem)
  398. break;
  399. tvi.mask = TVIF_PARAM;
  400. TreeView_GetItem(m_hwndTree, &tvi);
  401. if ( tvi.lParam == NULL )
  402. { // This is a category... expand and contract the category
  403. if ( tvi.state & TVIS_EXPANDED )
  404. {
  405. TreeView_Expand( m_hwndTree, tvi.hItem, TVE_COLLAPSE );
  406. }
  407. else
  408. {
  409. TreeView_Expand( m_hwndTree, tvi.hItem, TVE_EXPAND );
  410. // The first time we send the TVE_EXPAND message we get a TVIS_ITEMEXPANDING message for the item.
  411. // The TVIS_ITEMEXPANDING message is not sent on subsequent expands of the same item.
  412. }
  413. }
  414. else
  415. {
  416. // Set the correct image
  417. int iState = GetITState((int)tvi.lParam );
  418. SetItemFont( m_ahfonts[iState] );
  419. tvi.mask = TVIF_TEXT | TVIF_IMAGE;
  420. tvi.iImage = iState;
  421. CStr cszTemp = m_pInfoType->GetInfoTypeName( (int)tvi.lParam );
  422. tvi.pszText = cszTemp.psz;
  423. tvi.cchTextMax = (int)strlen(tvi.pszText);
  424. TreeView_SetItem(m_hwndTree, tvi.hItem);
  425. }
  426. }
  427. break;
  428. case TVN_SELCHANGING:
  429. {
  430. HTREEITEM htemp = pnmhdr->itemNew.hItem;
  431. break;
  432. }
  433. case TVN_SELCHANGED:
  434. {
  435. HTREEITEM htemp = pnmhdr->itemNew.hItem;
  436. break;
  437. }
  438. case NM_CLICK:
  439. {
  440. HTREEITEM htemp = pnmhdr->itemNew.hItem;
  441. TV_HITTESTINFO ht;
  442. GetCursorPos(&ht.pt);
  443. ScreenToClient(m_hwndTree, &ht.pt);
  444. TreeView_HitTest(m_hwndTree, &ht);
  445. TV_ITEM tvi;
  446. tvi.hItem = ht.hItem;
  447. if (!tvi.hItem)
  448. break; // probably ENTER with no selection
  449. m_fModified = TRUE;
  450. tvi.mask = TVIF_PARAM|TVIF_IMAGE;
  451. TreeView_GetItem(m_hwndTree, &tvi);
  452. tvi.iImage = IncState((int)tvi.lParam);
  453. tvi.iSelectedImage = tvi.iImage;
  454. tvi.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
  455. SetItemFont(m_ahfonts[tvi.iImage]);
  456. TreeView_SetItem(m_hwndTree, &tvi);
  457. break;
  458. }
  459. /*
  460. * We want a single click to open a topic. We already process
  461. * the case where the selection changes, and we jump if it does.
  462. * However, the user may click an existing selection, in which
  463. * case we want to jump (because the jump may have failed when
  464. * the item was first selected. However, we need to post the
  465. * message so that the treeview control will finish processing
  466. * the click (which could result in a selection change.
  467. */
  468. #ifdef NOTYET
  469. if (!m_fSuppressJump) {
  470. TV_HITTESTINFO ht;
  471. GetCursorPos(&ht.pt);
  472. ScreenToClient(m_hwndTree, &ht.pt);
  473. TreeView_HitTest(m_hwndTree, &ht);
  474. if (ht.flags & TVHT_ONITEMBUTTON)
  475. break; // just clicking the button, so ignore
  476. TV_ITEM tvi;
  477. tvi.hItem = ht.hItem;
  478. if (!tvi.hItem)
  479. break; // probably ENTER with no selection
  480. tvi.mask = TVIF_PARAM;
  481. TreeView_GetItem(m_hwndTree, &tvi);
  482. pSiteMapEntry = m_sitemap.GetSiteMapEntry(tvi.lParam);
  483. PostMessage(FindMessageParent(m_hwndTree), WM_COMMAND, ID_TV_SINGLE_CLICK,
  484. (LPARAM) TreeView_GetSelection(m_hwndTree));
  485. }
  486. break;
  487. case TVN_ITEMEXPANDING:
  488. {
  489. if (m_fHack) {
  490. m_fHack = FALSE;
  491. break;
  492. }
  493. SITEMAP_ENTRY* pSiteMapEntry = m_sitemap.GetSiteMapEntry(pnmhdr->itemNew.lParam);
  494. // if click on vacant area of TOC Tree view there is no sitemap entry.
  495. if ( pSiteMapEntry == NULL )
  496. break;
  497. // REVIEW: need to update this to support multiple images
  498. // for multiple levels, and also to support "new" images
  499. if (pnmhdr->action & TVE_EXPAND) {
  500. if (pSiteMapEntry->iImage == 0)
  501. pSiteMapEntry->iImage =
  502. m_sitemap.GetImageNumber(pSiteMapEntry);
  503. if (pSiteMapEntry->iImage < IMAGE_OPEN_FOLDER_NEW)
  504. pSiteMapEntry->iImage++;
  505. }
  506. else {
  507. ASSERT(pnmhdr->action & TVE_COLLAPSE);
  508. ASSERT(pSiteMapEntry->iImage);
  509. if ( (pSiteMapEntry->iImage>1) && (pSiteMapEntry->iImage <= IMAGE_OPEN_FOLDER_NEW) )
  510. pSiteMapEntry->iImage--;
  511. }
  512. // Set the correct image
  513. Tree_SetImage(m_hwndTree,
  514. pSiteMapEntry->iImage, pnmhdr->itemNew.hItem);
  515. }
  516. break;
  517. // The right click creates and displayes a popup menu with the three states.
  518. // If an item is selected on the menu the state of the currently hightlited
  519. // item changes to that state and the menu goes away.
  520. case NM_RCLICK:
  521. {
  522. HMENU hmenu = CreatePopupMenu();
  523. if (!hmenu)
  524. break;
  525. // NOTICE: Changes here must be reflected in the binary toc verison of this menu
  526. if (!(m_dwStyles & TVS_SINGLEEXPAND)) {
  527. HxAppendMenu(hmenu, MF_STRING, ID_EXPAND_ALL,
  528. GetStringResource(IDS_EXPAND_ALL));
  529. HxAppendMenu(hmenu, MF_STRING, ID_CONTRACT_ALL,
  530. GetStringResource(IDS_CONTRACT_ALL));
  531. }
  532. HxAppendMenu(hmenu, MF_STRING, ID_PRINT,
  533. GetStringResource(IDS_PRINT));
  534. ASSERT( m_pInfoType );
  535. // populate the InfoType member object of the CToc
  536. if ( !m_pInfoType )
  537. {
  538. if (m_phh && m_phh->m_phmData && m_phh->m_phmData->m_pdInfoTypes )
  539. { // load from the global IT store
  540. m_pInfoType = new CInfoType;
  541. m_pInfoType->CopyTo( m_phh->m_phmData );
  542. }else
  543. {
  544. // no global IT's; load from the .hhc IT store
  545. m_pInfoType = new CInfoType;
  546. *m_pInfoType = m_sitemap;
  547. }
  548. }
  549. else
  550. {
  551. // Set the infotypes bits to set all the types
  552. }
  553. // If there are infotypes add the "customize" option to the popup menu
  554. if (m_pInfoType && m_pInfoType->HowManyInfoTypes() && m_pInfoType->GetFirstHidden() != 1)
  555. HxAppendMenu(hmenu, MF_STRING, ID_CUSTOMIZE_INFO_TYPES,
  556. GetStringResource(IDS_CUSTOMIZE_INFO_TYPES));
  557. if (IsHelpAuthor(FindMessageParent(m_hwndTree))) {
  558. AppendMenu(hmenu, MF_SEPARATOR, 0, 0);
  559. HxAppendMenu(hmenu, MF_STRING, ID_VIEW_ENTRY,
  560. pGetDllStringResource(IDS_VIEW_ENTRY));
  561. if (NoRun() == FALSE)
  562. HxAppendMenu(hmenu, MF_STRING, ID_JUMP_URL, pGetDllStringResource(IDS_JUMP_URL));
  563. }
  564. #ifdef _DEBUG
  565. HxAppendMenu(hmenu, MF_STRING, ID_VIEW_MEMORY,
  566. "Debug: memory usage...");
  567. #endif
  568. TV_HITTESTINFO ht;
  569. GetCursorPos(&ht.pt);
  570. ScreenToClient(m_hwndTree, &ht.pt);
  571. TreeView_HitTest(m_hwndTree, &ht);
  572. TreeView_Select(m_hwndTree, ht.hItem, TVGN_CARET);
  573. ClientToScreen(m_hwndTree, &ht.pt);
  574. TrackPopupMenu(hmenu,
  575. TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
  576. ht.pt.x, ht.pt.y, 0, FindMessageParent(m_hwndTree), NULL);
  577. DestroyMenu(hmenu);
  578. return TRUE;
  579. }
  580. break;
  581. #endif // NOTYET
  582. }
  583. return FALSE;
  584. }
  585. #ifdef HHCTRL
  586. BOOL CChooseSubsets::OnBeginOrEnd(void)
  587. {
  588. CSubSets* pSS;
  589. CSubSet* pS;
  590. int i,n;
  591. CDlgComboBox cbToc(m_hWnd, IDCOMBO_TOC);
  592. CDlgComboBox cbIndex(m_hWnd, IDCOMBO_INDEX);
  593. CDlgComboBox cbFTS(m_hWnd, IDCOMBO_SEARCH);
  594. if (Initializing())
  595. {
  596. if ( m_phh && m_phh->m_phmData && m_phh->m_phmData->m_pTitleCollection &&
  597. (pSS= m_phh->m_phmData->m_pTitleCollection->m_pSubSets) )
  598. {
  599. i = pSS->HowManySubSets();
  600. for (n = 0; n < i ; n++ )
  601. {
  602. if ( (pS = pSS->GetSubSet(n)) )
  603. {
  604. cbToc.AddString(pS->m_cszSubSetName.psz);
  605. cbIndex.AddString(pS->m_cszSubSetName.psz);
  606. cbFTS.AddString(pS->m_cszSubSetName.psz);
  607. }
  608. }
  609. //
  610. // Select current selections.
  611. //
  612. if ( pSS->m_Toc && pSS->m_Toc->m_cszSubSetName.psz )
  613. cbToc.SelectString(pSS->m_Toc->m_cszSubSetName.psz);
  614. else
  615. cbToc.SetCurSel(0);
  616. if ( pSS->m_Index && pSS->m_Index->m_cszSubSetName.psz )
  617. cbIndex.SelectString(pSS->m_Index->m_cszSubSetName.psz);
  618. else
  619. cbIndex.SetCurSel(0);
  620. if ( pSS->m_FTS && pSS->m_FTS->m_cszSubSetName.psz )
  621. cbFTS.SelectString(pSS->m_FTS->m_cszSubSetName.psz);
  622. else
  623. cbFTS.SetCurSel(0);
  624. }
  625. }
  626. else
  627. {
  628. if ( m_phh && m_phh->m_phmData && m_phh->m_phmData->m_pTitleCollection &&
  629. (pSS= m_phh->m_phmData->m_pTitleCollection->m_pSubSets) )
  630. {
  631. TCHAR szBuf[256];
  632. cbToc.GetLBText(szBuf, (int)cbToc.GetCurSel());
  633. pSS->SetTocMask(szBuf, m_phh);
  634. cbIndex.GetLBText(szBuf, (int)cbIndex.GetCurSel());
  635. pSS->SetIndexMask(szBuf);
  636. cbFTS.GetLBText(szBuf, (int)cbFTS.GetCurSel());
  637. pSS->SetFTSMask(szBuf);
  638. #ifdef HHCTRL
  639. // Sync the search tab's subset combo. REVIEW:: Need event firing!
  640. // If the search tab exists, then update the combo box. Slimy! We need a notification scheme for tabs.
  641. if (m_phh->m_aNavPane[HH_TAB_SEARCH])
  642. {
  643. CAdvancedSearchNavPane* pSearch = reinterpret_cast<CAdvancedSearchNavPane*>(m_phh->m_aNavPane[HH_TAB_SEARCH]) ;
  644. pSearch->UpdateSSCombo() ;
  645. }
  646. #endif
  647. }
  648. }
  649. return TRUE;
  650. }
  651. #endif // HHCTRL