https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f6c565bc22e18eb308cc9…
commit f6c565bc22e18eb308cc9c072530a6ffdf0b67db
Author: Carlo-Bramini <carlo_bramini(a)users.sourceforge.net>
AuthorDate: Mon Aug 6 20:22:36 2018 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Mar 18 01:34:01 2019 +0100
[CALC] Add support for HTML-Help. CORE-15019
---
base/applications/calc/CMakeLists.txt | 1 +
base/applications/calc/calc.h | 16 +++++++++
base/applications/calc/htmlhelp.c | 67 +++++++++++++++++++++++++++++++++++
base/applications/calc/winmain.c | 14 +++++---
4 files changed, 94 insertions(+), 4 deletions(-)
diff --git a/base/applications/calc/CMakeLists.txt
b/base/applications/calc/CMakeLists.txt
index a92c7c3911..ffe0ee3a5e 100644
--- a/base/applications/calc/CMakeLists.txt
+++ b/base/applications/calc/CMakeLists.txt
@@ -7,6 +7,7 @@ list(APPEND SOURCE
rpn_ieee.c
utl_ieee.c
winmain.c
+ htmlhelp.c
calc.h)
file(GLOB calc_rc_deps res/*.*)
diff --git a/base/applications/calc/calc.h b/base/applications/calc/calc.h
index afbc813d83..db984f0760 100644
--- a/base/applications/calc/calc.h
+++ b/base/applications/calc/calc.h
@@ -51,6 +51,22 @@
#define MAX_CALC_SIZE 256
+/* HTMLHELP SUPPORT */
+typedef HWND (WINAPI* type_HtmlHelpA)(HWND, LPCSTR, UINT, DWORD);
+typedef HWND (WINAPI* type_HtmlHelpW)(HWND, LPCWSTR, UINT, DWORD);
+
+extern type_HtmlHelpA calc_HtmlHelpA;
+extern type_HtmlHelpW calc_HtmlHelpW;
+
+#ifndef UNICODE
+#define calc_HtmlHelp calc_HtmlHelpA
+#else
+#define calc_HtmlHelp calc_HtmlHelpW
+#endif
+
+void HtmlHelp_Start(HINSTANCE hInstance);
+void HtmlHelp_Stop(void);
+
/*#define USE_KEYBOARD_HOOK*/
#define SIZEOF(_ar) (sizeof(_ar)/sizeof(_ar[1]))
diff --git a/base/applications/calc/htmlhelp.c b/base/applications/calc/htmlhelp.c
new file mode 100644
index 0000000000..a306ae441b
--- /dev/null
+++ b/base/applications/calc/htmlhelp.c
@@ -0,0 +1,67 @@
+/*
+ * ReactOS Calc (HtmlHelp support)
+ *
+ * Copyright 2007-2017, Carlo Bramini
+ *
+ * This program 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "calc.h"
+
+#define GET_CB(name) \
+ calc_##name = (type_##name)GetProcAddress(hHtmlHelp, #name); \
+ if (calc_##name == NULL) calc_##name = dummy_##name;
+
+static HWND WINAPI
+dummy_HtmlHelpA(HWND hWnd, LPCSTR pszFile, UINT uCommand, DWORD dwData);
+
+static HWND WINAPI
+dummy_HtmlHelpW(HWND hWnd, LPCWSTR pszFile, UINT uCommand, DWORD dwData);
+
+type_HtmlHelpA calc_HtmlHelpA = dummy_HtmlHelpA;
+type_HtmlHelpW calc_HtmlHelpW = dummy_HtmlHelpW;
+
+static HMODULE hHtmlHelp;
+
+static HWND WINAPI
+dummy_HtmlHelpA(HWND hWnd, LPCSTR pszFile, UINT uCommand, DWORD dwData)
+{
+ return NULL;
+}
+
+static HWND WINAPI
+dummy_HtmlHelpW(HWND hWnd, LPCWSTR pszFile, UINT uCommand, DWORD dwData)
+{
+ return NULL;
+}
+
+void HtmlHelp_Start(HINSTANCE hInstance)
+{
+ hHtmlHelp = LoadLibrary(_T("HTMLHELP"));
+ if (hHtmlHelp == NULL)
+ return;
+
+ GET_CB(HtmlHelpW)
+ GET_CB(HtmlHelpA)
+}
+
+void HtmlHelp_Stop(void)
+{
+ if(hHtmlHelp == NULL)
+ return;
+
+ FreeLibrary(hHtmlHelp);
+ hHtmlHelp = NULL;
+}
diff --git a/base/applications/calc/winmain.c b/base/applications/calc/winmain.c
index ad9b5763b4..696e3ee9df 100644
--- a/base/applications/calc/winmain.c
+++ b/base/applications/calc/winmain.c
@@ -20,7 +20,7 @@
#include "calc.h"
-#define HTMLHELP_PATH(_pt) TEXT("%systemroot%\\Help\\calc.chm::") TEXT(_pt)
+#define HTMLHELP_PATH(_pt) _T("%systemroot%\\Help\\calc.chm::") _T(_pt)
#define MAKE_BITMASK4(_show_b16, _show_b10, _show_b8, _show_b2) \
(((_show_b2) << 0) | \
@@ -1181,7 +1181,7 @@ static void handle_context_menu(HWND hWnd, WPARAM wp, LPARAM lp)
popup.rcMargins.left = -1;
popup.rcMargins.right = -1;
popup.idString = GetWindowLongPtr((HWND)wp, GWL_ID);
- HtmlHelp((HWND)wp, HTMLHELP_PATH("/popups.txt"), HH_DISPLAY_TEXT_POPUP,
(DWORD_PTR)&popup);
+ calc_HtmlHelp((HWND)wp, HTMLHELP_PATH("/popups.txt"),
HH_DISPLAY_TEXT_POPUP, (DWORD_PTR)&popup);
}
#else
(void)idm;
@@ -1272,8 +1272,9 @@ static INT_PTR CALLBACK DlgMainProc(HWND hWnd, UINT msg, WPARAM wp,
LPARAM lp)
return SubclassButtonProc(hWnd, wp, lp);
case WM_INITDIALOG:
- // For now, the Help dialog is disabled because of lacking of HTML Help support
+#ifdef DISABLE_HTMLHELP_SUPPORT
EnableMenuItem(GetMenu(hWnd), IDM_HELP_HELP, MF_BYCOMMAND | MF_GRAYED);
+#endif
calc.hWnd=hWnd;
#ifdef USE_KEYBOARD_HOOK
@@ -1358,7 +1359,7 @@ static INT_PTR CALLBACK DlgMainProc(HWND hWnd, UINT msg, WPARAM wp,
LPARAM lp)
}
case IDM_HELP_HELP:
#ifndef DISABLE_HTMLHELP_SUPPORT
- HtmlHelp(hWnd, HTMLHELP_PATH("/general_information.htm"),
HH_DISPLAY_TOPIC, (DWORD_PTR)NULL);
+ calc_HtmlHelp(hWnd, HTMLHELP_PATH("/general_information.htm"),
HH_DISPLAY_TOPIC, (DWORD_PTR)NULL);
#endif
return TRUE;
case IDM_VIEW_STANDARD:
@@ -1763,6 +1764,7 @@ static INT_PTR CALLBACK DlgMainProc(HWND hWnd, UINT msg, WPARAM wp,
LPARAM lp)
calc.action = IDC_STATIC;
DestroyWindow(hWnd);
return TRUE;
+
case WM_DESTROY:
/* Get (x,y) position of the calculator */
GetWindowRect(hWnd, &rc);
@@ -1812,6 +1814,8 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdL
load_config();
start_rpn_engine();
+ HtmlHelp_Start(hInstance);
+
do {
/* ignore hwnd: dialogs are already visible! */
if (calc.layout == CALC_LAYOUT_SCIENTIFIC)
@@ -1839,5 +1843,7 @@ int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdL
stop_rpn_engine();
+ HtmlHelp_Stop();
+
return 0;
}