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.

215 lines
6.1 KiB

  1. ///////////////////////////////////////////////////////////
  2. //
  3. //
  4. // tabctrl - CTabControl controls encapsulates the system
  5. // tab control.
  6. //
  7. //
  8. /*
  9. TODO:
  10. Move tab ordering into this CTabControl.
  11. */
  12. ///////////////////////////////////////////////////////////
  13. //
  14. // Includes
  15. //
  16. #include "header.h"
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static const char THIS_FILE[] = __FILE__;
  20. #endif
  21. #include "system.h"
  22. #include "secwin.h"
  23. // For ID_TAB_CONTROL
  24. #include "resource.h"
  25. // Our header
  26. #include "tabctrl.h"
  27. // So that we can get the width of the sizebar.
  28. #include "sizebar.h"
  29. #include "hha_strtable.h"
  30. #include "cctlww.h"
  31. ///////////////////////////////////////////////////////////
  32. //
  33. // Constructor
  34. //
  35. CTabControl::CTabControl(HWND hwndParent, int tabpos, CHHWinType* phh)
  36. {
  37. ASSERT(IsValidWindow(hwndParent)) ;
  38. m_phh = phh;
  39. m_hWndParent = hwndParent ;
  40. RECT rc;
  41. CalcSize(&rc) ; // Get our size.
  42. int tabstyle = 0;
  43. if (tabpos == HHWIN_NAVTAB_LEFT)
  44. tabstyle = TCS_VERTICAL;
  45. else if (tabpos == HHWIN_NAVTAB_BOTTOM)
  46. tabstyle = TCS_BOTTOM;
  47. m_hWnd = W_CreateControlWindow (0, WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | tabstyle,
  48. W_TabCtrl, NULL, rc.left, rc.top, RECT_WIDTH(rc), RECT_HEIGHT(rc),
  49. hwndParent, (HMENU) ID_TAB_CONTROL, _Module.GetModuleInstance(), NULL );
  50. W_EnableUnicode(m_hWnd, W_TabCtrl);
  51. ZeroMemory(m_apTabText, sizeof(m_apTabText));
  52. m_cTabs = 0;
  53. if (m_phh->IsValidNavPane(HH_TAB_CONTENTS))
  54. {
  55. m_apTabText[m_cTabs] = lcStrDupW(GetStringResourceW(IDS_TAB_CONTENTS));
  56. m_cTabs++;
  57. }
  58. if (m_phh->IsValidNavPane(HH_TAB_INDEX))
  59. {
  60. m_apTabText[m_cTabs] = lcStrDupW(GetStringResourceW(IDS_TAB_INDEX));
  61. m_cTabs++;
  62. }
  63. if (m_phh->IsValidNavPane(HH_TAB_SEARCH))
  64. {
  65. m_apTabText[m_cTabs] = lcStrDupW(GetStringResourceW(IDS_TAB_SEARCH));
  66. m_cTabs++;
  67. }
  68. if (m_phh->IsValidNavPane(HH_TAB_HISTORY))
  69. {
  70. m_apTabText[m_cTabs] = lcStrDupW(GetStringResourceW(IDS_TAB_HISTORY));
  71. m_cTabs++;
  72. }
  73. // Turn on the Help Favorites Tab
  74. if (m_phh->IsValidNavPane(HH_TAB_FAVORITES))
  75. {
  76. m_apTabText[m_cTabs] = lcStrDupW(GetStringResourceW(IDS_TAB_FAVORITES));
  77. m_cTabs++;
  78. }
  79. // Add the Custom Tabs.
  80. //int iNumCustomTabs = phh->GetExtTabCount();
  81. int index = HH_TAB_CUSTOM_FIRST;
  82. for (int j = HH_TAB_CUSTOM_FIRST ; j <= HH_TAB_CUSTOM_LAST ; j++)
  83. {
  84. if (m_phh->IsValidNavPane(j))
  85. {
  86. //TODO: You never know when any of Ralph's objects are valid and there is almost never a way to know.
  87. // The failure condition below, should never have gotten this far. However, its not clear
  88. // when we have valid system data to check against.
  89. EXTENSIBLE_TAB* pExtTab = phh->GetExtTab(j - HH_TAB_CUSTOM_FIRST);
  90. if (pExtTab && pExtTab->pszTabName && pExtTab->pszProgId)
  91. {
  92. //TODO:[paulde] EXTENSIBLE_TAB should be made Unicode, or at least a way to get the authored codepage
  93. // [mikecole] Chanced the MultiByteToWideChar() call to use the CP info from the .CHM rather than ACP.
  94. int cch = lstrlen(pExtTab->pszTabName) + 1;
  95. PWSTR psz = (PWSTR)lcMalloc(cch*sizeof(WCHAR));
  96. MultiByteToWideChar(phh->GetCodePage(), 0, pExtTab->pszTabName, -1, psz, cch);
  97. m_apTabText[m_cTabs] = psz;
  98. m_cTabs++ ;
  99. }
  100. else
  101. {
  102. // Reset the window type so that this tab no longer valid.
  103. m_phh->fsWinProperties &= ~(HHWIN_PROP_TAB_CUSTOM1 << (j - HH_TAB_CUSTOM_FIRST));
  104. }
  105. }
  106. }
  107. #ifdef __TEST_CUSTOMTAB__
  108. if (IsHelpAuthor(hwndParent)) {
  109. m_apTabText[m_phh->tabOrder[HH_TAB_AUTHOR]] = lcStrDup(pGetDllStringResource(IDSHHA_TAB_AUTHOR));
  110. m_cTabs++;
  111. }
  112. #endif
  113. TC_ITEMW tie;
  114. tie.mask = TCIF_TEXT;
  115. tie.iImage = -1;
  116. int i;
  117. for (i = 0; i < m_cTabs; i++)
  118. {
  119. tie.pszText = (PWSTR) m_apTabText[i];
  120. if (tie.pszText) {
  121. tie.cchTextMax = lstrlenW( m_apTabText[i] );
  122. W_TabCtrl_InsertItem(m_hWnd, i, &tie);
  123. }
  124. }
  125. // see if we need to adjust vertical tab padding
  126. //
  127. char *pszTabVertSize = lcStrDup(GetStringResource(IDS_TAB_VERT_PADDING));
  128. char *pszTabHorzSize = lcStrDup(GetStringResource(IDS_TAB_HORZ_PADDING));
  129. if (pszTabVertSize && pszTabHorzSize)
  130. {
  131. if ((g_fDBCSSystem || g_langSystem == LANG_ARABIC || g_langSystem == LANG_HEBREW) && IsDigit((BYTE) *pszTabVertSize) && IsDigit((BYTE) *pszTabHorzSize))
  132. W_TabCtrl_SetPadding(m_hWnd,Atoi(pszTabHorzSize),Atoi(pszTabVertSize));
  133. lcFree(pszTabVertSize);
  134. lcFree(pszTabHorzSize);
  135. }
  136. SendMessage(m_hWnd, WM_SETFONT, (WPARAM)_Resource.GetAccessableUIFont() , 0);
  137. }
  138. ///////////////////////////////////////////////////////////
  139. //
  140. // Destructor
  141. //
  142. CTabControl::~CTabControl()
  143. {
  144. for (int i = 0; i < m_cTabs; i++) {
  145. if (m_apTabText[i])
  146. lcFree(m_apTabText[i]);
  147. }
  148. }
  149. ///////////////////////////////////////////////////////////
  150. //
  151. // Operations
  152. //
  153. ///////////////////////////////////////////////////////////
  154. //
  155. // ResizeWindow
  156. //
  157. void
  158. CTabControl::ResizeWindow()
  159. {
  160. // Validate
  161. ASSERT(IsValidWindow(hWnd())) ;
  162. // Calculate our size.
  163. RECT rc;
  164. CalcSize(&rc); // This will be the navigation window.
  165. // Size the window.
  166. MoveWindow(hWnd(), rc.left, rc.top,
  167. RECT_WIDTH(rc), RECT_HEIGHT(rc),
  168. TRUE);
  169. }
  170. ///////////////////////////////////////////////////////////
  171. //
  172. // Helper Functions
  173. //
  174. ///////////////////////////////////////////////////////////
  175. //
  176. // CalcSize - This is where we calc the size of the tab control
  177. //
  178. void
  179. CTabControl::CalcSize(RECT* prect)
  180. {
  181. // Currently this is simple. It will get more complicated.
  182. ::GetClientRect(m_hWndParent, prect);
  183. // Subtract room for padding and room for the sizebar.
  184. prect->right -= GetSystemMetrics(SM_CXSIZEFRAME)*2 - CSizeBar::Width();
  185. prect->top += GetSystemMetrics(SM_CYSIZEFRAME)*2 ; // Add room on top to see the top edge.
  186. }