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.

361 lines
13 KiB

  1. // Copyright (C) 1996-1997 Microsoft Corporation. All rights reserved.
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifndef __SECWIN_H__
  6. #define __SECWIN_H__
  7. #undef WINUSERAPI
  8. #define WINUSERAPI
  9. #include "htmlhelp.h"
  10. #include "hhctrl.h"
  11. #include "tabctrl.h"
  12. #include "chistory.h"
  13. #include "system.h"
  14. #include "navui.h" // Replace with forward reference.
  15. // Sizebar class.
  16. #include "sizebar.h"
  17. // Tool Bar defines
  18. // ----------------
  19. // Length of the text under each toolbar button
  20. #define MAX_TB_TEXT_LENGTH 64
  21. // Select tab commands. Used by the tab accelerator table.
  22. #define IDC_SELECT_TAB_FIRST 0x9000 // Make sure this doesn't conflict with other WM_COMMANDS!
  23. #define IDC_SELECT_TAB_LAST (IDC_SELECT_TAB_FIRST + HH_MAX_TABS)
  24. // max number of toolbar buttons
  25. // #define MAX_TB_BUTTONS 20
  26. #define MAX_TB_BUTTONS 18
  27. // Dimensions of Coolbar Glyphs ..
  28. #define TB_BMP_CX 20
  29. #define TB_BMP_CY 20
  30. #define TB_BTN_CY TB_BMP_CY // TB button height
  31. #define TB_BTN_CX TB_BMP_CX // TB button width
  32. // End Tool Bar defines
  33. // --------------------
  34. const int c_NUMNAVPANES = HH_MAX_TABS+1 ; //REVIEW: Why not use HH_MAX_TABS instead?
  35. #define HHFLAG_AUTOSYNC (1 << 0)
  36. #define HHFLAG_NOTIFY_ON_NAV_COMPLETE (1 << 1)
  37. #define DEFAULT_STYLE (WS_THICKFRAME | WS_OVERLAPPED)
  38. #define DEFAULT_NAV_WIDTH 250
  39. #define DEFAULT_NOTES_HEIGHT 100
  40. #define SIZE_BAR_WIDTH 7
  41. const char WINDOW_SEPARATOR = '>';
  42. const int TAB_PADDING = 8; // UI Cleanup. Was 4 now 8.
  43. extern RECT g_rcWorkArea;
  44. extern int g_cxScreen;
  45. extern int g_cyScreen;
  46. extern BOOL g_fOleInitialized;
  47. extern CRITICAL_SECTION g_cs; // per-instance
  48. typedef struct {
  49. int cbStruct;
  50. RECT rcPos;
  51. int iNavWidth;
  52. BOOL fHighlight;
  53. BOOL fLockSize;
  54. BOOL fNoToolBarText;
  55. BOOL fNotExpanded;
  56. int curNavType;
  57. } WINDOW_STATE;
  58. ///////////////////////////////////////////////////////////
  59. //
  60. // Forward References
  61. //
  62. class CContainer; // forward reference
  63. class CNotes; // forward reference
  64. class CSizeBar; // forward reference
  65. // WARNING! Do not add classes -- only add class members, or constructor
  66. // for CHHWinType will trash the class.
  67. class CHHWinType : public tagHH_WINTYPE
  68. MI2_COUNT(CHHWinType)
  69. {
  70. public:
  71. CHHWinType(LPCTSTR pszOwnerFile)
  72. :m_hAccel(NULL)
  73. {
  74. ZERO_INIT_CLASS(CHHWinType);
  75. cbStruct = sizeof(HH_WINTYPE);
  76. // Which CHM files "owns" this window type.
  77. m_szOwnerFile = pszOwnerFile ;
  78. #ifdef _CHECKMEM_ON_CLOSEWINDOW_
  79. _CrtMemCheckpoint(&m_MemState) ;
  80. #endif
  81. }
  82. ~CHHWinType();
  83. bool ReloadNavData(CHmData* phmdata) ; // Nasty hack for mso. Reloads nav pane from new chm.
  84. PCSTR GetCaption() const { return pszCaption; }
  85. DWORD GetExStyles() const { return dwExStyles; }
  86. DWORD GetStyles() const ;
  87. PCSTR GetTypeName() const { return pszType; }
  88. RECT* GetWinRect() { return &rcWindowPos; }
  89. BOOL IsProperty(UINT prop) const { return (fsWinProperties & prop); }
  90. BOOL IsUniCodeStrings() const { return fUniCodeStrings; }
  91. BOOL IsValidMember(UINT member) const { return (fsValidMembers & member); }
  92. void GetWindowRect(void) { if (IsValidWindow(*this)) ::GetWindowRect(*this, &rcWindowPos); }
  93. void GetClientRect(RECT* prc); // gets client area for host window
  94. int GetShowState() const { return nShowState; }
  95. int GetLeft() const { return rcWindowPos.left; }
  96. int GetTop() const { return rcWindowPos.top; }
  97. int GetRight() const { return rcWindowPos.right; }
  98. int GetBottom() const { return rcWindowPos.bottom; }
  99. int GetWidth() const { return RECT_WIDTH(rcWindowPos); }
  100. int GetHeight() const { return RECT_HEIGHT(rcWindowPos); }
  101. HWND GetHwnd() const { return hwndHelp; }
  102. HWND GetCallerHwnd() const { return hwndCaller; }
  103. HWND GetToolBarHwnd() const { return hwndToolBar; }
  104. HWND GetNavigationHwnd() const { return hwndNavigation; }
  105. HWND GetSizeBarHwnd() const { return m_pSizeBar->hWnd(); }
  106. HWND GetHTMLHwnd() const { return hwndHTML; }
  107. HWND GetTabCtrlHwnd() const // TabCtrlHwnd doesn't always exist.
  108. {return (m_pTabCtrl ? m_pTabCtrl->hWnd() : GetNavigationHwnd()); }
  109. int GetCurrentNavPaneIndex() ;
  110. int GetTabIndexFromNavPaneIndex(int iNavPaneIndex);
  111. PCSTR GetToc() const { return pszToc; }
  112. PCSTR GetIndex() const { return pszIndex; }
  113. PCSTR GetFile() const { return pszFile; }
  114. // Return the CHM file which owns this window type.
  115. LPCTSTR GetOwnerFile() const { return m_szOwnerFile.psz; }
  116. BOOL IsExpandedNavPane() const { return !fNotExpanded; }
  117. operator HWND() const
  118. { return hwndHelp; }
  119. operator RECT*()
  120. { return &rcWindowPos; }
  121. operator PCSTR() const
  122. { return pszType; }
  123. void SetUniCodeStrings(HH_WINTYPE* phhWinType) { fUniCodeStrings = phhWinType->fUniCodeStrings; }
  124. void SetTypeName(HH_WINTYPE* phhWinType);
  125. void SetValidMembers(HH_WINTYPE* phhWinType) { fsValidMembers = phhWinType->fsValidMembers; }
  126. void SetProperties(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_PROPERTIES)) fsWinProperties = phhWinType->fsWinProperties; }
  127. void SetStyles(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_STYLES)) dwStyles = phhWinType->dwStyles; }
  128. void SetExStyles(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_EXSTYLES)) dwExStyles = phhWinType->dwExStyles; }
  129. void SetWindowRect(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_RECT)) memcpy(&rcWindowPos, &phhWinType->rcWindowPos, sizeof(RECT)); }
  130. void SetDisplayState(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_SHOWSTATE)) nShowState = phhWinType->nShowState; else nShowState = SW_SHOW; }
  131. void SetTabPos(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_TABPOS)) tabpos = phhWinType->tabpos; else tabpos = HHWIN_NAVTAB_TOP; }
  132. void SetTabOrder(HH_WINTYPE* phhWinType);
  133. void SetCaption(HH_WINTYPE* phhWinType) { SetString(phhWinType->pszCaption, (PSTR*) &pszCaption); }
  134. void SetJump1(HH_WINTYPE* phhWinType);
  135. void SetJump2(HH_WINTYPE* phhWinType);
  136. void SetToc(HH_WINTYPE* phhWinType) { SetUrl(phhWinType->pszToc, (PSTR*) &pszToc); }
  137. void SetIndex(HH_WINTYPE* phhWinType) { SetUrl(phhWinType->pszIndex, (PSTR*) &pszIndex); }
  138. void SetFile(HH_WINTYPE* phhWinType) { SetUrl(phhWinType->pszFile, (PSTR*) &pszFile); }
  139. void SetNavExpansion(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_EXPANSION)) fNotExpanded = phhWinType->fNotExpanded; }
  140. void SetNavWidth(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_NAV_WIDTH)) iNavWidth = phhWinType->iNavWidth; }
  141. void SetCaller(HH_WINTYPE* phhWinType) { hwndCaller = phhWinType->hwndCaller; }
  142. void SetHome(HH_WINTYPE* phhWinType) { SetUrl(phhWinType->pszHome, (PSTR*) &pszHome); }
  143. void SetToolBar(HH_WINTYPE* phhWinType) { fsToolBarFlags =
  144. IsValidMember(HHWIN_PARAM_TB_FLAGS) ? phhWinType->fsToolBarFlags : HHWIN_DEF_BUTTONS; }
  145. void SetString(PCSTR pszSrcString, PSTR* ppszDst);
  146. void SetUrl(PCSTR pszSrcString, PSTR* ppszDst);
  147. void SetCurNavType(HH_WINTYPE* phhWinType) { if (IsValidMember(HHWIN_PARAM_CUR_TAB)) curNavType = phhWinType->curNavType ;}
  148. void SetLeft(int left) { rcWindowPos.left = left; }
  149. void SetTop(int top) { rcWindowPos.top = top; }
  150. void SetRight(int right) { rcWindowPos.right = right; }
  151. void SetBottom(int bottom) { rcWindowPos.bottom = bottom; }
  152. // General functions
  153. void AddExStyle(DWORD style) { dwExStyles |= style; }
  154. void AddStyle(DWORD style) { dwStyles |= style; }
  155. void AddToHistory(PCSTR pszTitle, PCSTR pszUrl);
  156. void AuthorMsg(UINT idStringFormatResource, PCSTR pszSubString = "") { ::AuthorMsg(idStringFormatResource, pszSubString, *this, NULL); }
  157. void CalcHtmlPaneRect(void);
  158. void CloseWindow();
  159. void SaveState() ;
  160. void ReloadCleanup() ;
  161. void ProcessDetachSafeCleanup();
  162. void CreateBookmarksTab() ;
  163. void CreateHistoryTab(void);
  164. void CreateCustomTab(int iPane, LPCOLESTR pszProgId);
  165. BOOL IsValidNavPane(int iTab);
  166. int GetValidNavPane(); // Returns the index of the first valid tab it finds. -1 if no valid tabs.
  167. BOOL AnyValidNavPane(void) {return GetValidNavPane() != -1; }
  168. int GetValidNavPaneCount() ;
  169. void CreateIndex(void);
  170. void CreateNavPane(int iPane) ; // Creates the appropriate NavPane if it doesn't already exist.
  171. void CreateOrShowHTMLPane(void);
  172. void CreateOrShowNavPane(void);
  173. void CreateSearchTab(void);
  174. void CreateSizeBar( void );
  175. void CreateToc(void);
  176. int CreateToolBar(TBBUTTON* pabtn);
  177. void DestroySizeBar( void );
  178. void doSelectTab(int newTabIndex);
  179. void OnNavigateComplete(LPCTSTR pszUrl);
  180. #ifndef CHIINDEX
  181. void OnPrint(void);
  182. #endif
  183. BOOL OnTrackNotifyCaller(int idAction);
  184. void SetActiveHelpWindow(void);
  185. void SetChmData(CHmData* phmData) { m_phmData = phmData; }
  186. void SetDisplayState(int nShow) { nShowState = nShow; }
  187. void SetTypeName(PCSTR pszSetType) { ASSERT(!pszType); pszType = lcStrDup(pszSetType); }
  188. void ToggleExpansion(bool bNotify=true);
  189. void UpdateInformationTypes(void);
  190. void WrapTB();
  191. bool ManualTranslateAccelerator(char iChar);
  192. bool DynamicTranslateAccelerator(MSG* pMsg);
  193. int GetExtTabCount() ;
  194. EXTENSIBLE_TAB* GetExtTab(int pos) ;
  195. HFONT GetUIFont() const { return _Resource.GetUIFont(); }
  196. HFONT GetContentFont();
  197. HFONT GetAccessableContentFont();
  198. INT GetContentCharset();
  199. UINT GetCodePage(void);
  200. void UpdateCmdUI(void);
  201. //--- Save/Restore focus during WM_ACTIVATE.
  202. bool RestoreCtrlWithFocus();
  203. void SaveCtrlWithFocus();
  204. HWND m_hwndLastFocus ; // The window handle of the control which had focus last. See WM_ACTIVATE in wndproc.cpp
  205. HWND m_hwndIndexEdit;
  206. HWND m_hwndIndexDisplay;
  207. HWND m_hwndNotes;
  208. HWND m_hwndListBox;
  209. CSizeBar* m_pSizeBar ;// moveable window in TRIPANE to size the HTML and NAV panes.
  210. // Tab classes
  211. HWND m_hwndControl;
  212. INavUI* m_aNavPane[c_NUMNAVPANES] ;
  213. CToc* m_ptocDynCast ; // We need a dynamic cast, but we don't have RTTI. Use this as a temp hack.
  214. HH_INFOTYPE* m_paInfoTypes; // Pointer to an array of Information Types
  215. RECT rcNav;
  216. RECT rcToolBar;
  217. RECT rcNotes;
  218. BOOL m_fNotesWindow; // TRUE to show the notes window
  219. BOOL m_fHighlight;
  220. BOOL m_bCancel;
  221. BOOL m_fLockSize; // TRUE to prevent show/hide from changing window size
  222. CTable* m_ptblBtnStrings;
  223. BOOL m_fNoToolBarText;
  224. CTabControl* m_pTabCtrl;
  225. CContainer* m_pCIExpContainer;
  226. CHmData* m_phmData;
  227. CHmData* m_phmDataOrg; // The original CHM before the ReloadNavData call.
  228. #ifdef _DEBUG
  229. CNotes* m_pNotes;
  230. #endif
  231. BOOL m_fActivated;
  232. HWND m_hwndFocused; // The window with the focus.
  233. HWND m_hWndSSCB;
  234. HWND m_hWndST;
  235. //
  236. // This is the total height in pels for margins + static text + combo-box.
  237. // ie. it's the distance between the bootm of the toolbar and the top of the hh child window that frames the nav pane.
  238. //
  239. int m_iSSCBHeight;
  240. private:
  241. // Filename of the CHM File which owns this window definition.
  242. CStr m_szOwnerFile;
  243. HMENU m_hMenuOptions;
  244. HACCEL m_hAccel ; // The accelerator table for this window.
  245. public:
  246. // Zoom support.
  247. //
  248. int m_iZoom;
  249. int m_iZoomMin;
  250. int m_iZoomMax;
  251. HRESULT Zoom(int iZoom);
  252. HRESULT GetZoomMinMax(void);
  253. void ZoomOut(void);
  254. void ZoomIn(void);
  255. //
  256. // Next/Prev in TOC support.
  257. //
  258. BOOL OnTocNext(BOOL bDoJump);
  259. BOOL OnTocPrev(BOOL bDoJump);
  260. // image lists
  261. HIMAGELIST m_hImageListGray;
  262. HIMAGELIST m_hImageList;
  263. // Memory checking class.
  264. #ifdef _DEBUG
  265. _CrtMemState m_MemState ;
  266. #endif
  267. };
  268. extern CHHWinType** pahwnd;
  269. __inline CHHWinType* FindWindowIndex(HWND hwnd) {
  270. for (int i = 0; i < g_cWindowSlots; i++) {
  271. if (pahwnd && pahwnd[i] != NULL && pahwnd[i]->hwndHelp == hwnd)
  272. return pahwnd[i];
  273. }
  274. return NULL;
  275. }
  276. CExCollection* GetCurrentCollection( HWND hwnd, LPCSTR lpszChmFilespec = NULL );
  277. BOOL GetCurrentURL( CStr* pcszCurrentURL, HWND hWnd = NULL );
  278. CHHWinType* CreateHelpWindow(PCSTR pszType, LPCTSTR pszFile, HWND hwndCaller, CHmData* phmData);
  279. HWND doDisplaySearch(HWND hwndCaller, LPCSTR pszFile, HH_FTS_QUERY* pFtsQuery);
  280. CHHWinType* FindCurWindow();
  281. CHHWinType* FindHHWindowIndex(CContainer* m_pOuter);
  282. CHHWinType* FindHHWindowIndex(HWND hwndChild);
  283. CHHWinType* FindOrCreateWindowSlot(LPCTSTR pszType, LPCTSTR pszOwnerFile);
  284. CHHWinType* FindWindowType(PCSTR pszType, HWND hwndCaller, LPCTSTR pszOwnerFile);
  285. HWND OnKeywordSearch(HWND hwndCaller, PCSTR pszFile, HH_AKLINK* pakLink, BOOL fKLink = TRUE);
  286. void DeleteWindows() ;
  287. // These functions handle the HH_GET/SET_WINTYPE commands
  288. HWND GetWinType(HWND hwndCaller, LPCSTR pszFile, HH_WINTYPE** pphh) ;
  289. HWND SetWinType(LPCSTR pszFile, HH_WINTYPE* phhWinType, CHmData* pChmDataOrg = NULL) ;
  290. // Helper function for resizing the window. see wndproc.cpp
  291. void ResizeWindow(CHHWinType* phh, bool bRecalcHtmlFrame=true) ;
  292. #endif // __SECWIN_H__