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.

624 lines
15 KiB

  1. // Copyright (C) Microsoft Corporation 1997-1998, All Rights reserved.
  2. ///////////////////////////////////////////////////////////
  3. //
  4. //
  5. // CustmTab.cpp - Implementation of the Custom Tab frame.
  6. //
  7. // This source implements the frame window which manages
  8. // custom tabs. It mainly serves as a parent for the custom tab
  9. // window.
  10. ///////////////////////////////////////////////////////////
  11. //
  12. // Include section
  13. //
  14. #include "header.h"
  15. #include "strtable.h" // These headers were copied from search.cpp. Are they all needed?
  16. #include "system.h"
  17. #include "hhctrl.h"
  18. #include "resource.h"
  19. #include "secwin.h"
  20. #include "htmlhelp.h"
  21. #include "cpaldc.h"
  22. #include "TCHAR.h"
  23. #include "parserhh.h"
  24. #include "collect.h"
  25. #include "hhtypes.h"
  26. #include "toc.h"
  27. #include "contain.h"
  28. // Our header file.
  29. #include "custmtab.h"
  30. // Common Control Macros
  31. // #include <windowsx.h>
  32. // The GUIDS --- PUT IN A SHARED LOCATION
  33. #include "HTMLHelpId_.c"
  34. ///////////////////////////////////////////////////////////
  35. //
  36. // Constants
  37. //
  38. static const char txtCustomNavPaneWindowClass[] = "HH CustomNavPane";
  39. ///////////////////////////////////////////////////////////
  40. //
  41. // Static Member functions
  42. //
  43. ///////////////////////////////////////////////////////////
  44. //
  45. // Non-Member helper functions.
  46. //
  47. ///////////////////////////////////////////////////////////
  48. //
  49. // Construction
  50. //
  51. ///////////////////////////////////////////////////////////
  52. //
  53. // CCustomNavPane();
  54. //
  55. CCustomNavPane::CCustomNavPane(CHHWinType* pWinType)
  56. : m_hWnd(NULL),
  57. m_hfont(NULL),
  58. m_padding(2), // padding to put around the window
  59. m_pWinType(pWinType),
  60. m_hwndComponent(NULL)
  61. {
  62. ASSERT(pWinType) ;
  63. m_NavTabPos = pWinType->tabpos ;
  64. // Save the prog id.
  65. m_clsid = CLSID_NULL;
  66. }
  67. ///////////////////////////////////////////////////////////
  68. //
  69. // ~CCustomNavPane
  70. //
  71. CCustomNavPane::~CCustomNavPane()
  72. {
  73. //--- Persist Keywords in combo
  74. SaveCustomTabState() ;
  75. //--- Close down the component's pane.
  76. if (m_spIHHWindowPane.p)
  77. {
  78. HRESULT hr = m_spIHHWindowPane->ClosePane() ;
  79. // ASSERT(SUCCEEDED(hr)) ;
  80. }
  81. //--- CleanUp
  82. if (m_hfont)
  83. {
  84. ::DeleteObject(m_hfont);
  85. }
  86. if (m_hWnd)
  87. {
  88. ::DestroyWindow(m_hWnd) ;
  89. }
  90. //Don't free m_pTitleCollection
  91. }
  92. ///////////////////////////////////////////////////////////
  93. //
  94. // INavUI Interface functions.
  95. //
  96. ///////////////////////////////////////////////////////////
  97. //
  98. // Create
  99. //
  100. BOOL
  101. CCustomNavPane::Create(HWND hwndParent)
  102. {
  103. bool bReturn = FALSE ;
  104. if (m_hWnd)
  105. {
  106. return TRUE ;
  107. }
  108. // Get the size of the parent.
  109. RECT rcParent;
  110. GetParentSize(&rcParent, hwndParent, m_padding, m_NavTabPos);
  111. // ---Create the frame window to hold the customtab dialog.
  112. m_hWnd = CreateWindow(txtCustomNavPaneWindowClass,
  113. NULL,
  114. WS_CHILD | WS_VISIBLE,
  115. rcParent.left, rcParent.top,
  116. RECT_WIDTH(rcParent), RECT_HEIGHT(rcParent),
  117. hwndParent, NULL, _Module.GetModuleInstance(), NULL);
  118. if (m_hWnd)
  119. {
  120. // Set the userdata to our this pointer.
  121. SetWindowLongPtr(m_hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
  122. //--- Create the component.
  123. HRESULT hr = ::CoCreateInstance(m_clsid,
  124. NULL,
  125. CLSCTX_INPROC_SERVER,
  126. IID_IHHWindowPane,
  127. (void**)&m_spIHHWindowPane) ;
  128. if (SUCCEEDED(hr))
  129. {
  130. //--- Create the window.
  131. hr = m_spIHHWindowPane->CreatePaneWindow(m_hWnd,
  132. 0, 0,
  133. RECT_WIDTH(rcParent), RECT_HEIGHT(rcParent),
  134. &m_hwndComponent) ;
  135. if (SUCCEEDED(hr))
  136. {
  137. ASSERT(m_spIHHWindowPane.p) ;
  138. //--- Restore the persisted state.
  139. LoadCustomTabState() ;
  140. bReturn = TRUE;
  141. }
  142. else
  143. {
  144. //TODO: Cleanup.
  145. }
  146. }
  147. else {
  148. // BUGBUG: we now have an empty window. We shouldn't
  149. // have created this tab...
  150. return FALSE;
  151. }
  152. }
  153. return bReturn ;
  154. }
  155. ///////////////////////////////////////////////////////////
  156. //
  157. // OnCommand
  158. //
  159. LRESULT
  160. CCustomNavPane::OnCommand(HWND hwnd, UINT id, UINT NotifyCode, LPARAM lParam)
  161. {
  162. return 0 ;
  163. }
  164. ///////////////////////////////////////////////////////////
  165. //
  166. // ResizeWindow
  167. //
  168. void
  169. CCustomNavPane::ResizeWindow()
  170. {
  171. if (!::IsValidWindow(m_hWnd))
  172. {
  173. ASSERT(::IsValidWindow(m_hWnd)) ;
  174. return ;
  175. }
  176. // Resize to fit the client area of the parent.
  177. HWND hwndParent = GetParent(m_hWnd) ;
  178. ASSERT(::IsValidWindow(hwndParent)) ;
  179. //--- Get the size of the window
  180. RECT rcParent;
  181. GetParentSize(&rcParent, hwndParent, m_padding, m_NavTabPos);
  182. ::MoveWindow(m_hWnd, rcParent.left, rcParent.top,
  183. RECT_WIDTH(rcParent), RECT_HEIGHT(rcParent), FALSE);
  184. RECT rcChild;
  185. GetWindowRect(m_hWnd, &rcChild);
  186. MoveClientWindow(m_hWnd, m_hwndComponent, &rcChild, TRUE);
  187. // ::MoveWindow(m_hwndComponent, rcChild.left, rcChild.top,
  188. // RECT_WIDTH(rcChild), RECT_HEIGHT(rcChild), TRUE);
  189. #if 0
  190. //--- Move and size the dialog box itself.
  191. ::SetWindowPos( m_hWnd, NULL, rcParent.left, rcParent.top,
  192. rcParent.right-rcParent.left,
  193. rcParent.bottom-rcParent.top,
  194. SWP_NOZORDER | SWP_NOOWNERZORDER);
  195. //---Fix the painting bugs. However, this is a little on the flashy side.
  196. ::InvalidateRect(m_hWnd, NULL, TRUE) ;
  197. #endif
  198. }
  199. ///////////////////////////////////////////////////////////
  200. //
  201. // HideWindow
  202. //
  203. void
  204. CCustomNavPane::HideWindow()
  205. {
  206. if (::IsValidWindow(m_hWnd))
  207. {
  208. ::ShowWindow(m_hWnd, SW_HIDE) ;
  209. }
  210. }
  211. ///////////////////////////////////////////////////////////
  212. //
  213. // ShowWindow
  214. //
  215. void
  216. CCustomNavPane::ShowWindow()
  217. {
  218. if (::IsValidWindow(m_hWnd))
  219. {
  220. // Show the window.
  221. ::ShowWindow(m_hWnd, SW_SHOW) ;
  222. }
  223. }
  224. ///////////////////////////////////////////////////////////
  225. //
  226. // SetPadding
  227. //
  228. void
  229. CCustomNavPane::SetPadding(int pad)
  230. {
  231. m_padding = pad;
  232. }
  233. ///////////////////////////////////////////////////////////
  234. //
  235. // SetTabPos
  236. //
  237. void
  238. CCustomNavPane::SetTabPos(int tabpos)
  239. {
  240. m_NavTabPos = tabpos;
  241. }
  242. ///////////////////////////////////////////////////////////
  243. //
  244. // SetDefaultFocus --- Set focus to the most expected control, usually edit combo.
  245. //
  246. void
  247. CCustomNavPane::SetDefaultFocus()
  248. {
  249. //TODO: Needs to be implemented
  250. if (IsWindow(m_hwndComponent))
  251. {
  252. SetFocus(m_hwndComponent) ;
  253. }
  254. }
  255. ///////////////////////////////////////////////////////////
  256. //
  257. // ProcessMenuChar --- Process accelerator keys.
  258. //
  259. bool
  260. CCustomNavPane::ProcessMenuChar(HWND hwndParent, int ch)
  261. {
  262. bool iReturn = FALSE ;
  263. /*
  264. for (int i = 0 ; i < c_NumDlgItems ; i++)
  265. {
  266. if (m_aDlgItems[i].m_accelkey == ch)
  267. {
  268. if (m_aDlgItems[i].m_Type == ItemInfo::Button)
  269. {
  270. // Its a button so do the command.
  271. OnCommand(hwndParent, m_aDlgItems[i].m_id, BN_CLICKED, 0) ;
  272. }
  273. else
  274. {
  275. // Set focus.
  276. ::SetFocus(m_aDlgItems[i].m_hWnd) ;
  277. }
  278. // Found it!
  279. iReturn = TRUE ;
  280. // Finished
  281. break ;
  282. }
  283. }
  284. */
  285. return iReturn;
  286. }
  287. ///////////////////////////////////////////////////////////
  288. //
  289. // OnNotify --- Process WM_NOTIFY messages. Used by embedded Tree and List view controls.
  290. //
  291. LRESULT
  292. CCustomNavPane::OnNotify(HWND hwnd, WPARAM idCtrl, LPARAM lParam)
  293. {
  294. //TODO: Implement
  295. return 0 ;
  296. }
  297. ///////////////////////////////////////////////////////////
  298. //
  299. // OnDrawItem --- Process WM_DRAWITEM messages.
  300. //
  301. void
  302. CCustomNavPane::OnDrawItem(UINT id, LPDRAWITEMSTRUCT pdis)
  303. {
  304. }
  305. ///////////////////////////////////////////////////////////
  306. //
  307. // Seed --- Seed the nav ui with a search term or keyword.
  308. //
  309. void
  310. CCustomNavPane::Seed(LPCSTR pszSeed)
  311. {
  312. }
  313. ///////////////////////////////////////////////////////////
  314. //
  315. // Synchronize
  316. //
  317. BOOL
  318. CCustomNavPane::Synchronize(PSTR /*pNotUsed*/, CTreeNode* /*pNotUsed2*/)
  319. {
  320. // TODO: Forward to imbedded window.
  321. return FALSE ;
  322. }
  323. ///////////////////////////////////////////////////////////
  324. //
  325. // Helper Functions.
  326. //
  327. ///////////////////////////////////////////////////////////
  328. //
  329. // SaveCustomTabState --- Persists the tab to the storage
  330. // Do it by GUID...
  331. //
  332. //
  333. void
  334. CCustomNavPane::SaveCustomTabState()
  335. {
  336. //REVIEW: We should save this based on the GUID of the navpane.
  337. // Once we open the guid section they can party on it.
  338. }
  339. ///////////////////////////////////////////////////////////
  340. //
  341. // LoadCustomTabState- Loads the results list from the storage
  342. //
  343. void
  344. CCustomNavPane::LoadCustomTabState()
  345. {
  346. }
  347. ///////////////////////////////////////////////////////////
  348. //
  349. // GetAcceleratorKey - Find the accelerator key from the ctrl.
  350. //
  351. #if 0 //-------DISABLED
  352. int
  353. CCustomNavPane::GetAcceleratorKey(HWND hwndctrl)
  354. {
  355. int iReturn = 0 ;
  356. char text[256] ;
  357. ::GetWindowText(hwndctrl, text, 256) ;
  358. int len = strlen(text) ;
  359. if (len != 0)
  360. {
  361. // Find the '&' key.
  362. char* p = strchr(text, '&') ;
  363. if (p < text + len -1) // Make sure that it's not the last char.
  364. {
  365. iReturn = tolower(*(p+1)) ;
  366. }
  367. }
  368. return iReturn ;
  369. }
  370. #endif
  371. ///////////////////////////////////////////////////////////
  372. //
  373. // Public Functions.
  374. //
  375. HRESULT
  376. CCustomNavPane::SetControlProgId(LPCOLESTR ProgId)
  377. {
  378. HRESULT hr = E_FAIL ;
  379. // Check string.
  380. ASSERT(ProgId) ;
  381. // Covert ProgId to CLSID.
  382. if (m_clsid == CLSID_NULL)
  383. {
  384. if (SUCCEEDED(CLSIDFromProgID(ProgId, &m_clsid)))
  385. {
  386. hr = S_OK ;
  387. }
  388. }
  389. else
  390. {
  391. // Already initialized
  392. hr = S_FALSE ;
  393. }
  394. return hr;
  395. }
  396. ///////////////////////////////////////////////////////////
  397. //
  398. // Message Handlers
  399. //
  400. ///////////////////////////////////////////////////////////
  401. //
  402. // OnTab - Handles pressing of the tab key.
  403. //
  404. #if 0 //-------DISABLED
  405. void
  406. CCustomNavPane::OnTab(HWND hwndReceivedTab, BookmarkDlgItemInfoIndex /*index*/)
  407. {
  408. //if (index == c_NumDlgItems) --- caller doesn't know the index.
  409. ASSERT(::IsValidWindow(hwndReceivedTab)) ;
  410. //--- Is the shift key down?
  411. BOOL bPrevious = (GetKeyState(VK_SHIFT) < 0) ;
  412. //---Are we the first or last control?
  413. if ((bPrevious && hwndReceivedTab == m_aDlgItems[c_TopicsList].m_hWnd) || // The c_KeywordCombo control is the first control, so shift tab goes to the topic window.
  414. (!bPrevious && hwndReceivedTab == m_aDlgItems[c_AddBookmarkBtn].m_hWnd)) // The c_TitlesOnlyCheck is the last control, so tab goes to the topic window.
  415. {
  416. PostMessage(m_pWinType->GetHwnd(), WMP_HH_TAB_KEY, 0, 0);
  417. }
  418. else
  419. {
  420. //--- Move to the next control .
  421. // Get the next tab item.
  422. HWND hWndNext = GetNextDlgTabItem(m_hWnd, hwndReceivedTab, bPrevious) ;
  423. // Set focus to it.
  424. ::SetFocus(hWndNext) ;
  425. }
  426. }
  427. #endif
  428. ///////////////////////////////////////////////////////////
  429. //
  430. // OnArrow
  431. //
  432. #if 0 //-------DISABLED
  433. void
  434. CCustomNavPane::OnArrow(HWND hwndReceivedTab, BookmarkDlgItemInfoIndex /*index*/, int key)
  435. {
  436. //if (index == c_NumDlgItems) --- caller doesn't know the index.
  437. ASSERT(::IsValidWindow(hwndReceivedTab)) ;
  438. BOOL bPrevious = FALSE ;
  439. if (key == VK_LEFT || key == VK_UP)
  440. {
  441. bPrevious = TRUE ;
  442. }
  443. // Get the next tab item.
  444. HWND hWndNext = GetNextDlgGroupItem(m_hWnd, hwndReceivedTab, bPrevious) ;
  445. // Set focus to it.
  446. ::SetFocus(hWndNext) ;
  447. }
  448. #endif
  449. ///////////////////////////////////////////////////////////
  450. //
  451. // OnReturn - Default handling of the return key.
  452. //
  453. #if 0 //-------DISABLED
  454. bool
  455. CCustomNavPane::OnReturn(HWND hwndReceivedTab, BookmarkDlgItemInfoIndex /*index*/)
  456. {
  457. //if (index == c_NumDlgItems) --- caller doesn't know the index.
  458. // Do the default button action.
  459. // Always do a search topic, if its enabled.
  460. if (::IsWindowEnabled(m_aDlgItems[c_DisplayBtn].m_hWnd))
  461. {
  462. OnDisplay();
  463. return TRUE ;
  464. }
  465. else
  466. {
  467. return FALSE ;
  468. }
  469. }
  470. #endif
  471. ///////////////////////////////////////////////////////////
  472. //
  473. // Callback Functions.
  474. //
  475. ///////////////////////////////////////////////////////////
  476. //
  477. // Member function Window Proc
  478. //
  479. LRESULT
  480. CCustomNavPane::CustomNavePaneProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  481. {
  482. #if 0
  483. switch (msg)
  484. {
  485. case WM_PAINT:
  486. //TODO: REMOVE THIS IS TEST CODE!
  487. // Draw an edige on the left side of the size bar.
  488. {
  489. PAINTSTRUCT ps;
  490. HDC hdcPaint = BeginPaint(hwnd, &ps) ;
  491. //Draw() ;
  492. HDC hdc = GetDC(hwnd) ;
  493. // get the rectangle to draw on.
  494. RECT rc ;
  495. GetClientRect(hwnd, &rc) ;
  496. // Draw the edge.
  497. POINT dumb;
  498. MoveToEx(hdc, rc.left, rc.top, &dumb);
  499. LineTo(hdc, rc.right, rc.bottom) ;
  500. // Clean up.
  501. ReleaseDC(hwnd, hdc) ;
  502. EndPaint(hwnd, &ps) ;
  503. }
  504. break;
  505. default:
  506. return DefWindowProc(hwnd, msg, wParam, lParam);
  507. }
  508. return 0;
  509. #endif
  510. return DefWindowProc(hwnd, msg, wParam, lParam);
  511. };
  512. ///////////////////////////////////////////////////////////
  513. //
  514. // Static Window Proc
  515. //
  516. LRESULT WINAPI
  517. CCustomNavPane::s_CustomNavePaneProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  518. {
  519. CCustomNavPane* pThis = reinterpret_cast<CCustomNavPane*>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
  520. if (pThis)
  521. return pThis->CustomNavePaneProc(hwnd, msg, wParam, lParam) ;
  522. else
  523. return DefWindowProc(hwnd, msg, wParam, lParam);
  524. }
  525. ///////////////////////////////////////////////////////////
  526. //
  527. // Static Functions
  528. //
  529. ///////////////////////////////////////////////////////////
  530. //
  531. // RegisterWindowClass
  532. //
  533. void
  534. CCustomNavPane::RegisterWindowClass()
  535. {
  536. WNDCLASS wc;
  537. ZeroMemory(&wc, sizeof(WNDCLASS)); // clear all members
  538. wc.hInstance = _Module.GetModuleInstance();
  539. wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
  540. wc.lpfnWndProc = s_CustomNavePaneProc;
  541. wc.lpszClassName = txtCustomNavPaneWindowClass;
  542. wc.hCursor = LoadCursor(NULL, IDC_SIZEWE);
  543. VERIFY(RegisterClass(&wc));
  544. }