winex11: Set window style to normal for windows with a minimize box.
[wine/hramrach.git] / dlls / hhctrl.ocx / hhctrl.c
blob9ab66de4344b0cda5ae4c6764272be75dbe9d5e8
1 /*
2 * hhctrl implementation
4 * Copyright 2004 Krzysztof Foltman
5 * Copyright 2007 Jacek Caban for CodeWeavers
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.
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.
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
22 #include "wine/debug.h"
24 #define INIT_GUID
25 #include "hhctrl.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
29 HINSTANCE hhctrl_hinstance;
30 BOOL hh_process = FALSE;
32 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
34 TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
36 switch (fdwReason)
38 case DLL_PROCESS_ATTACH:
39 hhctrl_hinstance = hInstance;
40 DisableThreadLibraryCalls(hInstance);
41 break;
42 case DLL_PROCESS_DETACH:
43 break;
45 return TRUE;
48 static const char *command_to_string(UINT command)
50 #define X(x) case x: return #x
51 switch (command)
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 "???";
86 #undef X
89 static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen)
91 static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0};
93 GetFullPathNameW(filename, buflen, fullname, NULL);
94 if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES)
96 GetWindowsDirectoryW(fullname, buflen);
97 strcatW(fullname, helpW);
98 strcatW(fullname, filename);
100 return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES);
103 /******************************************************************
104 * HtmlHelpW (HHCTRL.OCX.15)
106 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
108 WCHAR fullname[MAX_PATH];
110 TRACE("(%p, %s, command=%s, data=%lx)\n",
111 caller, debugstr_w( filename ),
112 command_to_string( command ), data);
114 switch (command)
116 case HH_DISPLAY_TOPIC:
117 case HH_DISPLAY_TOC:
118 case HH_DISPLAY_SEARCH:{
119 static const WCHAR delimW[] = {':',':',0};
120 HHInfo *info;
121 BOOL res;
122 WCHAR chm_file[MAX_PATH];
123 const WCHAR *index;
125 FIXME("Not all HH cases handled correctly\n");
127 if (!filename)
128 return NULL;
130 index = strstrW(filename, delimW);
131 if (index)
133 memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR));
134 chm_file[index-filename] = 0;
135 filename = chm_file;
136 index += 2; /* advance beyond "::" for calling NavigateToChm() later */
139 if (!resolve_filename(filename, fullname, MAX_PATH))
141 WARN("can't find %s\n", debugstr_w(filename));
142 return 0;
145 info = CreateHelpViewer(fullname);
146 if(!info)
147 return NULL;
149 if(!index)
150 index = info->WinType.pszFile;
152 res = NavigateToChm(info, info->pCHMInfo->szFile, index);
153 if(!res)
155 ReleaseHelpViewer(info);
156 return NULL;
158 return info->WinType.hwndHelp;
160 case HH_HELP_CONTEXT: {
161 HHInfo *info;
162 LPWSTR url;
164 if (!filename)
165 return NULL;
167 if (!resolve_filename(filename, fullname, MAX_PATH))
169 WARN("can't find %s\n", debugstr_w(filename));
170 return 0;
173 info = CreateHelpViewer(fullname);
174 if(!info)
175 return NULL;
177 url = FindContextAlias(info->pCHMInfo, data);
178 if(!url)
180 ReleaseHelpViewer(info);
181 return NULL;
184 NavigateToUrl(info, url);
185 heap_free(url);
186 return info->WinType.hwndHelp;
188 case HH_PRETRANSLATEMESSAGE: {
189 static BOOL warned = FALSE;
191 if (!warned)
193 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
194 warned = TRUE;
196 return 0;
198 default:
199 FIXME("HH case %s not handled.\n", command_to_string( command ));
202 return 0;
205 /******************************************************************
206 * HtmlHelpA (HHCTRL.OCX.14)
208 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
210 WCHAR *wfile = NULL, *wdata = NULL;
211 DWORD len;
212 HWND result;
214 if (filename)
216 len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
217 wfile = heap_alloc(len*sizeof(WCHAR));
218 MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
221 if (data)
223 switch(command)
225 case HH_ALINK_LOOKUP:
226 case HH_DISPLAY_SEARCH:
227 case HH_DISPLAY_TEXT_POPUP:
228 case HH_GET_LAST_ERROR:
229 case HH_GET_WIN_TYPE:
230 case HH_KEYWORD_LOOKUP:
231 case HH_SET_WIN_TYPE:
232 case HH_SYNC:
233 FIXME("structures not handled yet\n");
234 break;
236 case HH_DISPLAY_INDEX:
237 case HH_DISPLAY_TOPIC:
238 case HH_DISPLAY_TOC:
239 case HH_GET_WIN_HANDLE:
240 case HH_SAFE_DISPLAY_TOPIC:
241 len = MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, NULL, 0 );
242 wdata = heap_alloc(len*sizeof(WCHAR));
243 MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, wdata, len );
244 break;
246 case HH_CLOSE_ALL:
247 case HH_HELP_CONTEXT:
248 case HH_INITIALIZE:
249 case HH_PRETRANSLATEMESSAGE:
250 case HH_TP_HELP_CONTEXTMENU:
251 case HH_TP_HELP_WM_HELP:
252 case HH_UNINITIALIZE:
253 /* either scalar or pointer to scalar - do nothing */
254 break;
256 default:
257 FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
258 break;
262 result = HtmlHelpW( caller, wfile, command, wdata ? (DWORD_PTR)wdata : data );
264 heap_free(wfile);
265 heap_free(wdata);
266 return result;
269 /******************************************************************
270 * doWinMain (HHCTRL.OCX.13)
272 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
274 MSG msg;
275 int len, buflen, mapid = -1;
276 WCHAR *filename;
277 char *endq = NULL;
279 hh_process = TRUE;
281 /* Parse command line option of the HTML Help command.
283 * Note: The only currently handled action is "mapid",
284 * which corresponds to opening a specific page.
286 while(*szCmdLine == '-')
288 LPSTR space, ptr;
290 ptr = szCmdLine + 1;
291 space = strchr(ptr, ' ');
292 if(!strncmp(ptr, "mapid", space-ptr))
294 char idtxt[10];
296 ptr += strlen("mapid")+1;
297 space = strchr(ptr, ' ');
298 memcpy(idtxt, ptr, space-ptr);
299 idtxt[space-ptr] = '\0';
300 mapid = atoi(idtxt);
301 szCmdLine = space+1;
303 else
305 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space-szCmdLine), szCmdLine);
306 return 0;
310 /* FIXME: Check szCmdLine for bad arguments */
311 if (*szCmdLine == '\"')
312 endq = strchr(++szCmdLine, '\"');
314 if (endq)
315 len = endq - szCmdLine;
316 else
317 len = strlen(szCmdLine);
318 buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1;
319 filename = heap_alloc(buflen * sizeof(WCHAR));
320 MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen);
321 filename[buflen-1] = 0;
323 /* Open a specific help topic */
324 if(mapid != -1)
325 HtmlHelpW(GetDesktopWindow(), filename, HH_HELP_CONTEXT, mapid);
326 else
327 HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0);
329 heap_free(filename);
331 while (GetMessageW(&msg, 0, 0, 0))
333 TranslateMessage(&msg);
334 DispatchMessageW(&msg);
337 return 0;
340 /******************************************************************
341 * DllGetClassObject (HHCTRL.OCX.@)
343 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
345 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
346 return CLASS_E_CLASSNOTAVAILABLE;