hhctrl.ocx: Update HtmlHelp and its commands definitions, and partially implement...
[wine] / dlls / hhctrl.ocx / hhctrl.c
1 /*
2  * hhctrl implementation
3  *
4  * Copyright 2004 Krzysztof Foltman
5  * Copyright 2007 Jacek Caban for CodeWeavers
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "wine/debug.h"
23
24 #define INIT_GUID
25 #include "hhctrl.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
28
29 HINSTANCE hhctrl_hinstance;
30 BOOL hh_process = FALSE;
31
32 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
33 {
34     TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
35
36     switch (fdwReason)
37     {
38     case DLL_PROCESS_ATTACH:
39         hhctrl_hinstance = hInstance;
40         DisableThreadLibraryCalls(hInstance);
41         break;
42     case DLL_PROCESS_DETACH:
43         break;
44     }
45     return TRUE;
46 }
47
48 static const char *command_to_string(UINT command)
49 {
50 #define X(x) case x: return #x
51     switch (command)
52     {
53         X( HH_DISPLAY_TOPIC );
54         X( HH_DISPLAY_TOC );
55         X( HH_DISPLAY_INDEX );
56         X( HH_DISPLAY_SEARCH );
57         X( HH_SET_WIN_TYPE );
58         X( HH_GET_WIN_TYPE );
59         X( HH_GET_WIN_HANDLE );
60         X( HH_ENUM_INFO_TYPE );
61         X( HH_SET_INFO_TYPE );
62         X( HH_SYNC );
63         X( HH_RESERVED1 );
64         X( HH_RESERVED2 );
65         X( HH_RESERVED3 );
66         X( HH_KEYWORD_LOOKUP );
67         X( HH_DISPLAY_TEXT_POPUP );
68         X( HH_HELP_CONTEXT );
69         X( HH_TP_HELP_CONTEXTMENU );
70         X( HH_TP_HELP_WM_HELP );
71         X( HH_CLOSE_ALL );
72         X( HH_ALINK_LOOKUP );
73         X( HH_GET_LAST_ERROR );
74         X( HH_ENUM_CATEGORY );
75         X( HH_ENUM_CATEGORY_IT );
76         X( HH_RESET_IT_FILTER );
77         X( HH_SET_INCLUSIVE_FILTER );
78         X( HH_SET_EXCLUSIVE_FILTER );
79         X( HH_INITIALIZE );
80         X( HH_UNINITIALIZE );
81         X( HH_SAFE_DISPLAY_TOPIC );
82         X( HH_PRETRANSLATEMESSAGE );
83         X( HH_SET_GLOBAL_PROPERTY );
84     default: return "???";
85     }
86 #undef X
87 }
88
89 /******************************************************************
90  *              HtmlHelpW (hhctrl.ocx.15)
91  */
92 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
93 {
94     TRACE("(%p, %s, command=%s, data=%lx)\n",
95           caller, debugstr_w( filename ),
96           command_to_string( command ), data);
97
98     switch (command)
99     {
100     case HH_DISPLAY_TOPIC:
101     case HH_DISPLAY_TOC:
102     case HH_DISPLAY_SEARCH:{
103         HHInfo *info;
104         BOOL res;
105
106         FIXME("Not all HH cases handled correctly\n");
107
108         info = CreateHelpViewer(filename);
109
110         res = NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszFile);
111         if(!res)
112             ReleaseHelpViewer(info);
113
114         return NULL; /* FIXME */
115     }
116     case HH_HELP_CONTEXT: {
117         HHInfo *info;
118         LPWSTR url;
119
120         info = CreateHelpViewer(filename);
121         if(!info)
122             return NULL;
123
124         url = FindContextAlias(info->pCHMInfo, data);
125         if(!url)
126             return NULL;
127
128         NavigateToUrl(info, url);
129         hhctrl_free(url);
130
131         return NULL; /* FIXME */
132     }
133     default:
134         FIXME("HH case %s not handled.\n", command_to_string( command ));
135     }
136
137     return 0;
138 }
139
140 /******************************************************************
141  *              HtmlHelpA (hhctrl.ocx.14)
142  */
143 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
144 {
145     WCHAR *wfile = NULL, *wdata = NULL;
146     DWORD len;
147     HWND result;
148
149     if (filename)
150     {
151         len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
152         wfile = hhctrl_alloc(len*sizeof(WCHAR));
153         MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
154     }
155
156     if (data)
157     {
158         switch(command)
159         {
160         case HH_ALINK_LOOKUP:
161         case HH_DISPLAY_SEARCH:
162         case HH_DISPLAY_TEXT_POPUP:
163         case HH_GET_LAST_ERROR:
164         case HH_GET_WIN_TYPE:
165         case HH_KEYWORD_LOOKUP:
166         case HH_SET_WIN_TYPE:
167         case HH_SYNC:
168             FIXME("structures not handled yet\n");
169             break;
170
171         case HH_DISPLAY_INDEX:
172         case HH_DISPLAY_TOPIC:
173         case HH_DISPLAY_TOC:
174         case HH_GET_WIN_HANDLE:
175         case HH_SAFE_DISPLAY_TOPIC:
176             len = MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, NULL, 0 );
177             wdata = hhctrl_alloc(len*sizeof(WCHAR));
178             MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, wdata, len );
179             break;
180
181         case HH_CLOSE_ALL:
182         case HH_HELP_CONTEXT:
183         case HH_INITIALIZE:
184         case HH_PRETRANSLATEMESSAGE:
185         case HH_TP_HELP_CONTEXTMENU:
186         case HH_TP_HELP_WM_HELP:
187         case HH_UNINITIALIZE:
188             /* either scalar or pointer to scalar - do nothing */
189             break;
190
191         default:
192             FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
193             break;
194         }
195     }
196
197     result = HtmlHelpW( caller, wfile, command, wdata ? (DWORD_PTR)wdata : data );
198
199     hhctrl_free(wfile);
200     hhctrl_free(wdata);
201     return result;
202 }
203
204 /******************************************************************
205  *              doWinMain (hhctrl.ocx.13)
206  */
207 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
208 {
209     MSG msg;
210
211     hh_process = TRUE;
212
213     /* FIXME: Check szCmdLine for bad arguments */
214     HtmlHelpA(GetDesktopWindow(), szCmdLine, HH_DISPLAY_TOPIC, 0);
215
216     while (GetMessageW(&msg, 0, 0, 0))
217     {
218         TranslateMessage(&msg);
219         DispatchMessageW(&msg);
220     }
221
222     return 0;
223 }
224
225 /******************************************************************
226  *              DllGetClassObject (hhctrl.ocx.@)
227  */
228 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
229 {
230     FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
231     return CLASS_E_CLASSNOTAVAILABLE;
232 }