2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/unicode.h"
35 #include "webbrowser.h"
37 static void Help_OnSize(HWND hWnd
);
39 /* Window type defaults */
41 #define WINTYPE_DEFAULT_X 280
42 #define WINTYPE_DEFAULT_Y 100
43 #define WINTYPE_DEFAULT_WIDTH 740
44 #define WINTYPE_DEFAULT_HEIGHT 640
45 #define WINTYPE_DEFAULT_NAVWIDTH 250
47 static const WCHAR szEmpty
[] = {0};
49 typedef struct tagHHInfo
51 HH_WINTYPEW
*pHHWinType
;
61 extern HINSTANCE hhctrl_hinstance
;
63 static LPWSTR
HH_ANSIToUnicode(LPCSTR ansi
)
68 count
= MultiByteToWideChar(CP_ACP
, 0, ansi
, -1, NULL
, 0);
69 unicode
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
70 MultiByteToWideChar(CP_ACP
, 0, ansi
, -1, unicode
, count
);
75 /* Loads a string from the resource file */
76 static LPWSTR
HH_LoadString(DWORD dwID
)
81 iSize
= LoadStringW(hhctrl_hinstance
, dwID
, NULL
, 0);
82 iSize
+= 2; /* some strings (tab text) needs double-null termination */
84 string
= HeapAlloc(GetProcessHeap(), 0, iSize
* sizeof(WCHAR
));
85 LoadStringW(hhctrl_hinstance
, dwID
, string
, iSize
);
92 #define SIZEBAR_WIDTH 4
94 static const WCHAR szSizeBarClass
[] = {
95 'H','H',' ','S','i','z','e','B','a','r',0
98 /* Draw the SizeBar */
99 static void SB_OnPaint(HWND hWnd
)
105 hdc
= BeginPaint(hWnd
, &ps
);
107 GetClientRect(hWnd
, &rc
);
112 FrameRect(hdc
, &rc
, GetStockObject(GRAY_BRUSH
));
114 /* white highlight */
115 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
116 MoveToEx(hdc
, rc
.right
, 1, NULL
);
118 LineTo(hdc
, 1, rc
.bottom
- 1);
121 MoveToEx(hdc
, 0, rc
.bottom
, NULL
);
122 LineTo(hdc
, rc
.right
, rc
.bottom
);
127 static void SB_OnLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
132 static void SB_OnLButtonUp(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
134 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
137 pt
.x
= (short)LOWORD(lParam
);
138 pt
.y
= (short)HIWORD(lParam
);
140 /* update the window sizes */
141 pHHInfo
->pHHWinType
->iNavWidth
+= pt
.x
;
147 static void SB_OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
149 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
150 if (!(wParam
& MK_LBUTTON
))
154 static LRESULT CALLBACK
SizeBar_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
159 SB_OnLButtonDown(hWnd
, wParam
, lParam
);
162 SB_OnLButtonUp(hWnd
, wParam
, lParam
);
165 SB_OnMouseMove(hWnd
, wParam
, lParam
);
171 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
177 static void HH_RegisterSizeBarClass(HHInfo
*pHHInfo
)
181 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
183 wcex
.lpfnWndProc
= (WNDPROC
)SizeBar_WndProc
;
186 wcex
.hInstance
= pHHInfo
->hInstance
;
187 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
188 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_SIZEWE
);
189 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
190 wcex
.lpszMenuName
= NULL
;
191 wcex
.lpszClassName
= szSizeBarClass
;
192 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
194 RegisterClassExW(&wcex
);
197 static void SB_GetSizeBarRect(HHInfo
*pHHInfo
, RECT
*rc
)
199 RECT rectWND
, rectTB
, rectNP
;
201 GetClientRect(pHHInfo
->pHHWinType
->hwndHelp
, &rectWND
);
202 GetClientRect(pHHInfo
->pHHWinType
->hwndToolBar
, &rectTB
);
203 GetClientRect(pHHInfo
->pHHWinType
->hwndNavigation
, &rectNP
);
205 rc
->left
= rectNP
.right
;
206 rc
->top
= rectTB
.bottom
;
207 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
208 rc
->right
= SIZEBAR_WIDTH
;
211 static BOOL
HH_AddSizeBar(HHInfo
*pHHInfo
)
214 HWND hwndParent
= pHHInfo
->pHHWinType
->hwndHelp
;
215 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_OVERLAPPED
;
216 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
219 SB_GetSizeBarRect(pHHInfo
, &rc
);
221 hWnd
= CreateWindowExW(dwExStyles
, szSizeBarClass
, szEmpty
, dwStyles
,
222 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
223 hwndParent
, NULL
, pHHInfo
->hInstance
, NULL
);
227 /* store the pointer to the HH info struct */
228 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LONG_PTR
)pHHInfo
);
230 pHHInfo
->hwndSizeBar
= hWnd
;
236 static const WCHAR szChildClass
[] = {
237 'H','H',' ','C','h','i','l','d',0
240 static void Child_OnPaint(HWND hWnd
)
246 hdc
= BeginPaint(hWnd
, &ps
);
248 /* Only paint the Navigation pane, identified by the fact
249 * that it has a child window
251 if (GetWindow(hWnd
, GW_CHILD
))
253 GetClientRect(hWnd
, &rc
);
255 /* set the border color */
256 SelectObject(hdc
, GetStockObject(DC_PEN
));
257 SetDCPenColor(hdc
, GetSysColor(COLOR_BTNSHADOW
));
259 /* Draw the top border */
260 LineTo(hdc
, rc
.right
, 0);
262 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
263 MoveToEx(hdc
, 0, 1, NULL
);
264 LineTo(hdc
, rc
.right
, 1);
270 static LRESULT CALLBACK
Child_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
278 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
284 static void HH_RegisterChildWndClass(HHInfo
*pHHInfo
)
288 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
290 wcex
.lpfnWndProc
= (WNDPROC
)Child_WndProc
;
293 wcex
.hInstance
= pHHInfo
->hInstance
;
294 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
295 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
296 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
297 wcex
.lpszMenuName
= NULL
;
298 wcex
.lpszClassName
= szChildClass
;
299 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
301 RegisterClassExW(&wcex
);
308 static void TB_OnClick(HWND hWnd
, DWORD dwID
)
310 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
315 WB_DoPageAction(pHHInfo
->pWBInfo
, WB_STOP
);
318 WB_DoPageAction(pHHInfo
->pWBInfo
, WB_REFRESH
);
321 WB_DoPageAction(pHHInfo
->pWBInfo
, WB_GOBACK
);
325 WCHAR szUrl
[MAX_PATH
];
327 CHM_CreateITSUrl(pHHInfo
->pCHMInfo
, pHHInfo
->pHHWinType
->pszHome
, szUrl
);
328 WB_Navigate(pHHInfo
->pWBInfo
, szUrl
);
332 WB_DoPageAction(pHHInfo
->pWBInfo
, WB_GOFORWARD
);
339 case IDTB_BROWSE_FWD
:
340 case IDTB_BROWSE_BACK
:
351 static void TB_AddButton(TBBUTTON
*pButtons
, DWORD dwIndex
, DWORD dwID
)
353 /* FIXME: Load the correct button bitmaps */
354 pButtons
[dwIndex
].iBitmap
= STD_PRINT
;
355 pButtons
[dwIndex
].idCommand
= dwID
;
356 pButtons
[dwIndex
].fsState
= TBSTATE_ENABLED
;
357 pButtons
[dwIndex
].fsStyle
= BTNS_BUTTON
;
358 pButtons
[dwIndex
].dwData
= 0;
359 pButtons
[dwIndex
].iString
= 0;
362 static void TB_AddButtonsFromFlags(TBBUTTON
*pButtons
, DWORD dwButtonFlags
, LPDWORD pdwNumButtons
)
366 if (dwButtonFlags
& HHWIN_BUTTON_EXPAND
)
367 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_EXPAND
);
369 if (dwButtonFlags
& HHWIN_BUTTON_BACK
)
370 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_BACK
);
372 if (dwButtonFlags
& HHWIN_BUTTON_FORWARD
)
373 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_FORWARD
);
375 if (dwButtonFlags
& HHWIN_BUTTON_STOP
)
376 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_STOP
);
378 if (dwButtonFlags
& HHWIN_BUTTON_REFRESH
)
379 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_REFRESH
);
381 if (dwButtonFlags
& HHWIN_BUTTON_HOME
)
382 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_HOME
);
384 if (dwButtonFlags
& HHWIN_BUTTON_SYNC
)
385 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_SYNC
);
387 if (dwButtonFlags
& HHWIN_BUTTON_OPTIONS
)
388 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_OPTIONS
);
390 if (dwButtonFlags
& HHWIN_BUTTON_PRINT
)
391 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_PRINT
);
393 if (dwButtonFlags
& HHWIN_BUTTON_JUMP1
)
394 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_JUMP1
);
396 if (dwButtonFlags
& HHWIN_BUTTON_JUMP2
)
397 TB_AddButton(pButtons
,(*pdwNumButtons
)++, IDTB_JUMP2
);
399 if (dwButtonFlags
& HHWIN_BUTTON_ZOOM
)
400 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_ZOOM
);
402 if (dwButtonFlags
& HHWIN_BUTTON_TOC_NEXT
)
403 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_TOC_NEXT
);
405 if (dwButtonFlags
& HHWIN_BUTTON_TOC_PREV
)
406 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_TOC_PREV
);
409 static BOOL
HH_AddToolbar(HHInfo
*pHHInfo
)
412 HWND hwndParent
= pHHInfo
->pHHWinType
->hwndHelp
;
414 TBBUTTON buttons
[IDTB_TOC_PREV
- IDTB_EXPAND
];
416 DWORD dwStyles
, dwExStyles
;
417 DWORD dwNumButtons
, dwIndex
;
419 if (pHHInfo
->pHHWinType
->fsWinProperties
& HHWIN_PARAM_TB_FLAGS
)
420 toolbarFlags
= pHHInfo
->pHHWinType
->fsToolBarFlags
;
422 toolbarFlags
= HHWIN_DEF_BUTTONS
;
424 TB_AddButtonsFromFlags(buttons
, toolbarFlags
, &dwNumButtons
);
426 dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| TBSTYLE_FLAT
|
427 TBSTYLE_WRAPABLE
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
;
428 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
430 hToolbar
= CreateWindowExW(dwExStyles
, TOOLBARCLASSNAMEW
, NULL
, dwStyles
,
431 0, 0, 0, 0, hwndParent
, NULL
,
432 pHHInfo
->hInstance
, NULL
);
436 SendMessageW(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(ICON_SIZE
, ICON_SIZE
));
437 SendMessageW(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
438 SendMessageW(hToolbar
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
440 /* FIXME: Load correct icons for all buttons */
441 tbAB
.hInst
= HINST_COMMCTRL
;
442 tbAB
.nID
= IDB_STD_LARGE_COLOR
;
443 SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
445 for (dwIndex
= 0; dwIndex
< dwNumButtons
; dwIndex
++)
447 LPWSTR szBuf
= HH_LoadString(buttons
[dwIndex
].idCommand
);
448 DWORD dwLen
= strlenW(szBuf
);
449 szBuf
[dwLen
+ 2] = 0; /* Double-null terminate */
451 buttons
[dwIndex
].iString
= (DWORD
)SendMessageW(hToolbar
, TB_ADDSTRINGW
, 0, (LPARAM
)szBuf
);
452 HeapFree(GetProcessHeap(), 0, szBuf
);
455 SendMessageW(hToolbar
, TB_ADDBUTTONSW
, dwNumButtons
, (LPARAM
)&buttons
);
456 SendMessageW(hToolbar
, TB_AUTOSIZE
, 0, 0);
457 ShowWindow(hToolbar
, SW_SHOW
);
459 pHHInfo
->pHHWinType
->hwndToolBar
= hToolbar
;
463 /* Navigation Pane */
465 #define TAB_TOP_PADDING 8
466 #define TAB_RIGHT_PADDING 4
468 static void NP_GetNavigationRect(HHInfo
*pHHInfo
, RECT
*rc
)
470 HWND hwndParent
= pHHInfo
->pHHWinType
->hwndHelp
;
471 HWND hwndToolbar
= pHHInfo
->pHHWinType
->hwndToolBar
;
472 RECT rectWND
, rectTB
;
474 GetClientRect(hwndParent
, &rectWND
);
475 GetClientRect(hwndToolbar
, &rectTB
);
478 rc
->top
= rectTB
.bottom
;
479 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
481 if (!(pHHInfo
->pHHWinType
->fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
482 pHHInfo
->pHHWinType
->iNavWidth
== 0)
484 pHHInfo
->pHHWinType
->iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
487 rc
->right
= pHHInfo
->pHHWinType
->iNavWidth
;
490 static void NP_CreateTab(HINSTANCE hInstance
, HWND hwndTabCtrl
, DWORD dwStrID
, DWORD dwIndex
)
493 LPWSTR tabText
= HH_LoadString(dwStrID
);
495 tie
.mask
= TCIF_TEXT
;
496 tie
.pszText
= tabText
;
498 SendMessageW( hwndTabCtrl
, TCM_INSERTITEMW
, dwIndex
, (LPARAM
)&tie
);
499 HeapFree(GetProcessHeap(), 0, tabText
);
502 static BOOL
HH_AddNavigationPane(HHInfo
*pHHInfo
)
504 HWND hWnd
, hwndTabCtrl
;
505 HWND hwndParent
= pHHInfo
->pHHWinType
->hwndHelp
;
506 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
;
507 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
511 NP_GetNavigationRect(pHHInfo
, &rc
);
513 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
514 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
515 hwndParent
, NULL
, pHHInfo
->hInstance
, NULL
);
519 hwndTabCtrl
= CreateWindowExW(dwExStyles
, WC_TABCONTROLW
, szEmpty
, dwStyles
,
521 rc
.right
- TAB_RIGHT_PADDING
,
522 rc
.bottom
- TAB_TOP_PADDING
,
523 hWnd
, NULL
, pHHInfo
->hInstance
, NULL
);
527 if (*pHHInfo
->pHHWinType
->pszToc
)
528 NP_CreateTab(pHHInfo
->hInstance
, hwndTabCtrl
, IDS_CONTENTS
, dwIndex
++);
530 if (*pHHInfo
->pHHWinType
->pszIndex
)
531 NP_CreateTab(pHHInfo
->hInstance
, hwndTabCtrl
, IDS_INDEX
, dwIndex
++);
533 if (pHHInfo
->pHHWinType
->fsWinProperties
& HHWIN_PROP_TAB_SEARCH
)
534 NP_CreateTab(pHHInfo
->hInstance
, hwndTabCtrl
, IDS_SEARCH
, dwIndex
++);
536 if (pHHInfo
->pHHWinType
->fsWinProperties
& HHWIN_PROP_TAB_FAVORITES
)
537 NP_CreateTab(pHHInfo
->hInstance
, hwndTabCtrl
, IDS_FAVORITES
, dwIndex
++);
539 SendMessageW(hwndTabCtrl
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
541 pHHInfo
->hwndTabCtrl
= hwndTabCtrl
;
542 pHHInfo
->pHHWinType
->hwndNavigation
= hWnd
;
548 static void HP_GetHTMLRect(HHInfo
*pHHInfo
, RECT
*rc
)
550 RECT rectTB
, rectWND
, rectNP
, rectSB
;
552 GetClientRect(pHHInfo
->pHHWinType
->hwndHelp
, &rectWND
);
553 GetClientRect(pHHInfo
->pHHWinType
->hwndToolBar
, &rectTB
);
554 GetClientRect(pHHInfo
->pHHWinType
->hwndNavigation
, &rectNP
);
555 GetClientRect(pHHInfo
->hwndSizeBar
, &rectSB
);
557 rc
->left
= rectNP
.right
+ rectSB
.right
;
558 rc
->top
= rectTB
.bottom
;
559 rc
->right
= rectWND
.right
- rc
->left
;
560 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
563 static BOOL
HH_AddHTMLPane(HHInfo
*pHHInfo
)
566 HWND hwndParent
= pHHInfo
->pHHWinType
->hwndHelp
;
567 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
;
568 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
| WS_EX_CLIENTEDGE
;
571 HP_GetHTMLRect(pHHInfo
, &rc
);
573 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
574 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
575 hwndParent
, NULL
, pHHInfo
->hInstance
, NULL
);
579 if (!WB_EmbedBrowser(pHHInfo
->pWBInfo
, hWnd
))
582 /* store the pointer to the HH info struct */
583 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LONG_PTR
)pHHInfo
);
585 ShowWindow(hWnd
, SW_SHOW
);
588 pHHInfo
->pHHWinType
->hwndHTML
= hWnd
;
594 static void Help_OnSize(HWND hWnd
)
596 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
603 NP_GetNavigationRect(pHHInfo
, &rc
);
604 SetWindowPos(pHHInfo
->pHHWinType
->hwndNavigation
, HWND_TOP
, 0, 0,
605 rc
.right
, rc
.bottom
, SWP_NOMOVE
);
607 GetClientRect(pHHInfo
->pHHWinType
->hwndNavigation
, &rc
);
608 SetWindowPos(pHHInfo
->hwndTabCtrl
, HWND_TOP
, 0, 0,
609 rc
.right
- TAB_RIGHT_PADDING
,
610 rc
.bottom
- TAB_TOP_PADDING
, SWP_NOMOVE
);
612 SB_GetSizeBarRect(pHHInfo
, &rc
);
613 SetWindowPos(pHHInfo
->hwndSizeBar
, HWND_TOP
, rc
.left
, rc
.top
,
614 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
616 HP_GetHTMLRect(pHHInfo
, &rc
);
617 SetWindowPos(pHHInfo
->pHHWinType
->hwndHTML
, HWND_TOP
, rc
.left
, rc
.top
,
618 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
620 /* Resize browser window taking the frame size into account */
621 dwSize
= GetSystemMetrics(SM_CXFRAME
);
622 WB_ResizeBrowser(pHHInfo
->pWBInfo
, rc
.right
- dwSize
, rc
.bottom
- dwSize
);
625 static LRESULT CALLBACK
Help_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
633 if (HIWORD(wParam
) == BN_CLICKED
)
634 TB_OnClick(hWnd
, LOWORD(wParam
));
640 hdc
= BeginPaint(hWnd
, &ps
);
648 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
654 static BOOL
HH_CreateHelpWindow(HHInfo
*pHHInfo
)
657 HINSTANCE hInstance
= pHHInfo
->hInstance
;
658 RECT winPos
= pHHInfo
->pHHWinType
->rcWindowPos
;
660 DWORD dwStyles
, dwExStyles
;
661 DWORD x
, y
, width
, height
;
663 static const WCHAR windowClassW
[] = {
664 'H','H',' ', 'P','a','r','e','n','t',0
667 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
668 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
669 wcex
.lpfnWndProc
= (WNDPROC
)Help_WndProc
;
672 wcex
.hInstance
= hInstance
;
673 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
674 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
675 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
676 wcex
.lpszMenuName
= NULL
;
677 wcex
.lpszClassName
= windowClassW
;
678 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
680 RegisterClassExW(&wcex
);
682 /* Read in window parameters if available */
683 if (pHHInfo
->pHHWinType
->fsValidMembers
& HHWIN_PARAM_STYLES
)
684 dwStyles
= pHHInfo
->pHHWinType
->dwStyles
;
686 dwStyles
= WS_OVERLAPPEDWINDOW
| WS_VISIBLE
|
687 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
689 if (pHHInfo
->pHHWinType
->fsValidMembers
& HHWIN_PARAM_EXSTYLES
)
690 dwExStyles
= pHHInfo
->pHHWinType
->dwExStyles
;
692 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
|
693 WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
;
695 if (pHHInfo
->pHHWinType
->fsValidMembers
& HHWIN_PARAM_RECT
)
699 width
= winPos
.right
- x
;
700 height
= winPos
.bottom
- y
;
704 x
= WINTYPE_DEFAULT_X
;
705 y
= WINTYPE_DEFAULT_Y
;
706 width
= WINTYPE_DEFAULT_WIDTH
;
707 height
= WINTYPE_DEFAULT_HEIGHT
;
710 hWnd
= CreateWindowExW(dwExStyles
, windowClassW
, pHHInfo
->pHHWinType
->pszCaption
,
711 dwStyles
, x
, y
, width
, height
, NULL
, NULL
, hInstance
, NULL
);
715 ShowWindow(hWnd
, SW_SHOW
);
718 /* store the pointer to the HH info struct */
719 SetWindowLongPtrW(hWnd
, GWLP_USERDATA
, (LONG_PTR
)pHHInfo
);
721 pHHInfo
->pHHWinType
->hwndHelp
= hWnd
;
725 static void HH_CreateFont(HHInfo
*pHHInfo
)
729 GetObjectW(GetStockObject(ANSI_VAR_FONT
), sizeof(LOGFONTW
), &lf
);
730 lf
.lfWeight
= FW_NORMAL
;
732 lf
.lfUnderline
= FALSE
;
734 pHHInfo
->hFont
= CreateFontIndirectW(&lf
);
737 static void HH_InitRequiredControls(DWORD dwControls
)
739 INITCOMMONCONTROLSEX icex
;
741 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
742 icex
.dwICC
= dwControls
;
743 InitCommonControlsEx(&icex
);
746 /* Creates the whole package */
747 static BOOL
HH_CreateViewer(HHInfo
*pHHInfo
)
749 HH_CreateFont(pHHInfo
);
751 if (!HH_CreateHelpWindow(pHHInfo
))
754 HH_InitRequiredControls(ICC_BAR_CLASSES
);
756 if (!HH_AddToolbar(pHHInfo
))
759 HH_RegisterChildWndClass(pHHInfo
);
761 if (!HH_AddNavigationPane(pHHInfo
))
764 HH_RegisterSizeBarClass(pHHInfo
);
766 if (!HH_AddSizeBar(pHHInfo
))
769 if (!HH_AddHTMLPane(pHHInfo
))
775 static HHInfo
*HH_OpenHH(HINSTANCE hInstance
, LPWSTR szCmdLine
)
777 HHInfo
*pHHInfo
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HHInfo
));
779 pHHInfo
->pHHWinType
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(HH_WINTYPEW
));
780 pHHInfo
->pCHMInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo
));
781 pHHInfo
->pWBInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo
));
782 pHHInfo
->hInstance
= hInstance
;
783 pHHInfo
->szCmdLine
= szCmdLine
;
788 static void HH_Close(HHInfo
*pHHInfo
)
793 /* Free allocated strings */
794 if (pHHInfo
->pHHWinType
)
796 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszType
);
797 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszCaption
);
798 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszToc
);
799 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszType
);
800 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszIndex
);
801 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszFile
);
802 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszHome
);
803 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszJump1
);
804 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszJump2
);
805 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszUrlJump1
);
806 HeapFree(GetProcessHeap(), 0, (LPWSTR
)pHHInfo
->pHHWinType
->pszUrlJump2
);
809 HeapFree(GetProcessHeap(), 0, pHHInfo
->pHHWinType
);
810 HeapFree(GetProcessHeap(), 0, pHHInfo
->szCmdLine
);
812 if (pHHInfo
->pCHMInfo
)
814 CHM_CloseCHM(pHHInfo
->pCHMInfo
);
815 HeapFree(GetProcessHeap(), 0, pHHInfo
->pCHMInfo
);
818 if (pHHInfo
->pWBInfo
)
820 WB_UnEmbedBrowser(pHHInfo
->pWBInfo
);
821 HeapFree(GetProcessHeap(), 0, pHHInfo
->pWBInfo
);
825 static void HH_OpenDefaultTopic(HHInfo
*pHHInfo
)
828 LPCWSTR defTopic
= pHHInfo
->pHHWinType
->pszFile
;
830 CHM_CreateITSUrl(pHHInfo
->pCHMInfo
, defTopic
, url
);
831 WB_Navigate(pHHInfo
->pWBInfo
, url
);
834 static BOOL
HH_OpenCHM(HHInfo
*pHHInfo
)
836 if (!CHM_OpenCHM(pHHInfo
->pCHMInfo
, pHHInfo
->szCmdLine
))
839 if (!CHM_LoadWinTypeFromCHM(pHHInfo
->pCHMInfo
, pHHInfo
->pHHWinType
))
845 /* FIXME: Check szCmdLine for bad arguments */
846 int WINAPI
doWinMain(HINSTANCE hInstance
, LPSTR szCmdLine
)
851 if (OleInitialize(NULL
) != S_OK
)
854 pHHInfo
= HH_OpenHH(hInstance
, HH_ANSIToUnicode(szCmdLine
));
855 if (!pHHInfo
|| !HH_OpenCHM(pHHInfo
) || !HH_CreateViewer(pHHInfo
))
861 HH_OpenDefaultTopic(pHHInfo
);
863 while (GetMessageW(&msg
, 0, 0, 0))
865 TranslateMessage(&msg
);
866 DispatchMessageW(&msg
);
870 HeapFree(GetProcessHeap(), 0, pHHInfo
);