From 3e00dec8274a122d7a051cf9ddf1174cfe325f5d Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Tue, 2 Aug 2005 14:55:11 +0000 Subject: [PATCH] - Add the toolbar to the viewer window. - Load the toolbar button text from the resource file. --- dlls/hhctrl.ocx/.cvsignore | 2 +- dlls/hhctrl.ocx/En.rc | 50 +++++++++++++++++ dlls/hhctrl.ocx/Makefile.in | 2 +- dlls/hhctrl.ocx/help.c | 127 ++++++++++++++++++++++++++++++++++++++++++++ dlls/hhctrl.ocx/hhctrl.rc | 31 +++++++++++ 5 files changed, 210 insertions(+), 2 deletions(-) create mode 100644 dlls/hhctrl.ocx/En.rc create mode 100644 dlls/hhctrl.ocx/hhctrl.rc diff --git a/dlls/hhctrl.ocx/.cvsignore b/dlls/hhctrl.ocx/.cvsignore index 8c9976e8c48..b76977a86e4 100644 --- a/dlls/hhctrl.ocx/.cvsignore +++ b/dlls/hhctrl.ocx/.cvsignore @@ -1,3 +1,3 @@ Makefile hhctrl.ocx.dbg.c -version.res +hhctrl.res diff --git a/dlls/hhctrl.ocx/En.rc b/dlls/hhctrl.ocx/En.rc new file mode 100644 index 00000000000..9927fafcb95 --- /dev/null +++ b/dlls/hhctrl.ocx/En.rc @@ -0,0 +1,50 @@ +/* + * HTML Help resources + * English Language Support + * + * Copyright 2005 James Hawkins + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +STRINGTABLE +BEGIN + IDTB_EXPAND "Show" + IDTB_CONTRACT "Hide" + IDTB_STOP "Stop" + IDTB_REFRESH "Refresh" + IDTB_BACK "Back" + IDTB_HOME "Home" + IDTB_SYNC "Sync" + IDTB_PRINT "Print" + IDTB_OPTIONS "Options" + IDTB_FORWARD "Forward" + IDTB_NOTES "IDTB_NOTES" + IDTB_BROWSE_FWD "IDTB_BROWSE_FWD" + IDTB_BROWSE_BACK "IDT_BROWSE_BACK" + IDTB_CONTENTS "IDTB_CONTENTS" + IDTB_INDEX "IDTB_INDEX" + IDTB_SEARCH "IDTB_SEARCH" + IDTB_HISTORY "IDTB_HISTORY" + IDTB_FAVORITES "IDTB_FAVORITES" + IDTB_JUMP1 "Jump1" + IDTB_JUMP2 "Jump2" + IDTB_CUSTOMIZE "Customize" + IDTB_ZOOM "Zoom" + IDTB_TOC_NEXT "IDTB_TOC_NEXT" + IDTB_TOC_PREV "IDTB_TOC_PREV" +END diff --git a/dlls/hhctrl.ocx/Makefile.in b/dlls/hhctrl.ocx/Makefile.in index 4aeb5feb180..80bedc7ab65 100644 --- a/dlls/hhctrl.ocx/Makefile.in +++ b/dlls/hhctrl.ocx/Makefile.in @@ -11,7 +11,7 @@ C_SRCS = \ main.c \ regsvr.c -RC_SRCS = version.rc +RC_SRCS = hhctrl.rc @MAKE_DLL_RULES@ diff --git a/dlls/hhctrl.ocx/help.c b/dlls/hhctrl.ocx/help.c index a92955661da..51fffc8bbe4 100644 --- a/dlls/hhctrl.ocx/help.c +++ b/dlls/hhctrl.ocx/help.c @@ -28,6 +28,7 @@ #include "commctrl.h" #include "htmlhelp.h" #include "ole2.h" +#include "wine/unicode.h" /* Window type defaults */ @@ -41,9 +42,12 @@ typedef struct tagHHInfo HH_WINTYPEW *pHHWinType; HINSTANCE hInstance; LPCWSTR szCmdLine; + DWORD dwNumTBButtons; HFONT hFont; } HHInfo; +extern HINSTANCE hhctrl_hinstance; + static LPWSTR HH_ANSIToUnicode(LPCSTR ansi) { LPWSTR unicode; @@ -56,10 +60,133 @@ static LPWSTR HH_ANSIToUnicode(LPCSTR ansi) return unicode; } +/* Loads a string from the resource file */ +static LPWSTR HH_LoadString(DWORD dwID) +{ + LPWSTR string = NULL; + int iSize; + + iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0); + iSize += 2; /* some strings (tab text) needs double-null termination */ + + string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR)); + LoadStringW(hhctrl_hinstance, dwID, string, iSize); + + return string; +} + /* Toolbar */ +#define ICON_SIZE 20 + +static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID) +{ + /* FIXME: Load the correct button bitmaps */ + pButtons[dwIndex].iBitmap = STD_PRINT; + pButtons[dwIndex].idCommand = dwID; + pButtons[dwIndex].fsState = TBSTATE_ENABLED; + pButtons[dwIndex].fsStyle = BTNS_BUTTON; + pButtons[dwIndex].dwData = 0; + pButtons[dwIndex].iString = 0; +} + +static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons) +{ + *pdwNumButtons = 0; + + if (dwButtonFlags & HHWIN_BUTTON_EXPAND) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND); + + if (dwButtonFlags & HHWIN_BUTTON_BACK) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK); + + if (dwButtonFlags & HHWIN_BUTTON_FORWARD) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD); + + if (dwButtonFlags & HHWIN_BUTTON_STOP) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP); + + if (dwButtonFlags & HHWIN_BUTTON_REFRESH) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH); + + if (dwButtonFlags & HHWIN_BUTTON_HOME) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME); + + if (dwButtonFlags & HHWIN_BUTTON_SYNC) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC); + + if (dwButtonFlags & HHWIN_BUTTON_OPTIONS) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS); + + if (dwButtonFlags & HHWIN_BUTTON_PRINT) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT); + + if (dwButtonFlags & HHWIN_BUTTON_JUMP1) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1); + + if (dwButtonFlags & HHWIN_BUTTON_JUMP2) + TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2); + + if (dwButtonFlags & HHWIN_BUTTON_ZOOM) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM); + + if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT); + + if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV) + TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV); +} + static BOOL HH_AddToolbar(HHInfo *pHHInfo) { + HWND hToolbar; + HWND hwndParent = pHHInfo->pHHWinType->hwndHelp; + DWORD toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags; + TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND]; + TBADDBITMAP tbAB; + DWORD dwStyles, dwExStyles; + DWORD dwNumButtons, dwIndex; + + /* FIXME: Remove the following line once we read the CHM file */ + toolbarFlags = HHWIN_BUTTON_EXPAND | HHWIN_BUTTON_BACK | HHWIN_BUTTON_STOP | + HHWIN_BUTTON_REFRESH | HHWIN_BUTTON_HOME | HHWIN_BUTTON_PRINT; + TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons); + pHHInfo->dwNumTBButtons = dwNumButtons; + + dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT | + TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER; + dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR; + + hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles, + 0, 0, 0, 0, hwndParent, NULL, + pHHInfo->hInstance, NULL); + if (!hToolbar) + return FALSE; + + SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE)); + SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); + SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE); + + /* FIXME: Load correct icons for all buttons */ + tbAB.hInst = HINST_COMMCTRL; + tbAB.nID = IDB_STD_LARGE_COLOR; + SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB); + + for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++) + { + LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand); + DWORD dwLen = strlenW(szBuf); + szBuf[dwLen + 2] = 0; /* Double-null terminate */ + + buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf); + HeapFree(GetProcessHeap(), 0, szBuf); + } + + SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons); + SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0); + ShowWindow(hToolbar, SW_SHOW); + + pHHInfo->pHHWinType->hwndToolBar = hToolbar; return TRUE; } diff --git a/dlls/hhctrl.ocx/hhctrl.rc b/dlls/hhctrl.ocx/hhctrl.rc new file mode 100644 index 00000000000..872bf3c6702 --- /dev/null +++ b/dlls/hhctrl.ocx/hhctrl.rc @@ -0,0 +1,31 @@ +/* + * HTML Help resources + * + * Copyright 2005 James Hawkins + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "windef.h" +#include "winbase.h" +#include "wingdi.h" +#include "winnls.h" +#include "htmlhelp.h" + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +#include "version.rc" + +#include "En.rc" -- 2.11.4.GIT