Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhhctrl.c
Go to the documentation of this file.
00001 /* 00002 * hhctrl implementation 00003 * 00004 * Copyright 2004 Krzysztof Foltman 00005 * Copyright 2007 Jacek Caban for CodeWeavers 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include "wine/debug.h" 00023 00024 #define INIT_GUID 00025 #include "hhctrl.h" 00026 00027 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp); 00028 00029 HINSTANCE hhctrl_hinstance; 00030 BOOL hh_process = FALSE; 00031 00032 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved) 00033 { 00034 TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved); 00035 00036 switch (fdwReason) 00037 { 00038 case DLL_PROCESS_ATTACH: 00039 hhctrl_hinstance = hInstance; 00040 DisableThreadLibraryCalls(hInstance); 00041 break; 00042 case DLL_PROCESS_DETACH: 00043 break; 00044 } 00045 return TRUE; 00046 } 00047 00048 static const char *command_to_string(UINT command) 00049 { 00050 #define X(x) case x: return #x 00051 switch (command) 00052 { 00053 X( HH_DISPLAY_TOPIC ); 00054 X( HH_DISPLAY_TOC ); 00055 X( HH_DISPLAY_INDEX ); 00056 X( HH_DISPLAY_SEARCH ); 00057 X( HH_SET_WIN_TYPE ); 00058 X( HH_GET_WIN_TYPE ); 00059 X( HH_GET_WIN_HANDLE ); 00060 X( HH_ENUM_INFO_TYPE ); 00061 X( HH_SET_INFO_TYPE ); 00062 X( HH_SYNC ); 00063 X( HH_RESERVED1 ); 00064 X( HH_RESERVED2 ); 00065 X( HH_RESERVED3 ); 00066 X( HH_KEYWORD_LOOKUP ); 00067 X( HH_DISPLAY_TEXT_POPUP ); 00068 X( HH_HELP_CONTEXT ); 00069 X( HH_TP_HELP_CONTEXTMENU ); 00070 X( HH_TP_HELP_WM_HELP ); 00071 X( HH_CLOSE_ALL ); 00072 X( HH_ALINK_LOOKUP ); 00073 X( HH_GET_LAST_ERROR ); 00074 X( HH_ENUM_CATEGORY ); 00075 X( HH_ENUM_CATEGORY_IT ); 00076 X( HH_RESET_IT_FILTER ); 00077 X( HH_SET_INCLUSIVE_FILTER ); 00078 X( HH_SET_EXCLUSIVE_FILTER ); 00079 X( HH_INITIALIZE ); 00080 X( HH_UNINITIALIZE ); 00081 X( HH_SAFE_DISPLAY_TOPIC ); 00082 X( HH_PRETRANSLATEMESSAGE ); 00083 X( HH_SET_GLOBAL_PROPERTY ); 00084 default: return "???"; 00085 } 00086 #undef X 00087 } 00088 00089 static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen) 00090 { 00091 static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0}; 00092 00093 GetFullPathNameW(filename, buflen, fullname, NULL); 00094 if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES) 00095 { 00096 GetWindowsDirectoryW(fullname, buflen); 00097 strcatW(fullname, helpW); 00098 strcatW(fullname, filename); 00099 } 00100 return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES); 00101 } 00102 00103 /****************************************************************** 00104 * HtmlHelpW (HHCTRL.OCX.15) 00105 */ 00106 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data) 00107 { 00108 WCHAR fullname[MAX_PATH]; 00109 00110 TRACE("(%p, %s, command=%s, data=%lx)\n", 00111 caller, debugstr_w( filename ), 00112 command_to_string( command ), data); 00113 00114 switch (command) 00115 { 00116 case HH_DISPLAY_TOPIC: 00117 case HH_DISPLAY_TOC: 00118 case HH_DISPLAY_SEARCH:{ 00119 static const WCHAR delimW[] = {':',':',0}; 00120 HHInfo *info; 00121 BOOL res; 00122 WCHAR chm_file[MAX_PATH]; 00123 const WCHAR *index; 00124 00125 FIXME("Not all HH cases handled correctly\n"); 00126 00127 if (!filename) 00128 return NULL; 00129 00130 index = strstrW(filename, delimW); 00131 if (index) 00132 { 00133 memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR)); 00134 chm_file[index-filename] = 0; 00135 filename = chm_file; 00136 index += 2; /* advance beyond "::" for calling NavigateToChm() later */ 00137 } 00138 00139 if (!resolve_filename(filename, fullname, MAX_PATH)) 00140 { 00141 WARN("can't find %s\n", debugstr_w(filename)); 00142 return 0; 00143 } 00144 00145 info = CreateHelpViewer(fullname); 00146 if(!info) 00147 return NULL; 00148 00149 if(!index) 00150 index = info->WinType.pszFile; 00151 00152 res = NavigateToChm(info, info->pCHMInfo->szFile, index); 00153 if(!res) 00154 { 00155 ReleaseHelpViewer(info); 00156 return NULL; 00157 } 00158 return info->WinType.hwndHelp; 00159 } 00160 case HH_HELP_CONTEXT: { 00161 HHInfo *info; 00162 LPWSTR url; 00163 00164 if (!filename) 00165 return NULL; 00166 00167 if (!resolve_filename(filename, fullname, MAX_PATH)) 00168 { 00169 WARN("can't find %s\n", debugstr_w(filename)); 00170 return 0; 00171 } 00172 00173 info = CreateHelpViewer(fullname); 00174 if(!info) 00175 return NULL; 00176 00177 url = FindContextAlias(info->pCHMInfo, data); 00178 if(!url) 00179 { 00180 ReleaseHelpViewer(info); 00181 return NULL; 00182 } 00183 00184 NavigateToUrl(info, url); 00185 heap_free(url); 00186 return info->WinType.hwndHelp; 00187 } 00188 case HH_PRETRANSLATEMESSAGE: { 00189 static BOOL warned = FALSE; 00190 00191 if (!warned) 00192 { 00193 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n"); 00194 warned = TRUE; 00195 } 00196 return 0; 00197 } 00198 default: 00199 FIXME("HH case %s not handled.\n", command_to_string( command )); 00200 } 00201 00202 return 0; 00203 } 00204 00205 /****************************************************************** 00206 * HtmlHelpA (HHCTRL.OCX.14) 00207 */ 00208 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data) 00209 { 00210 WCHAR *wfile = NULL, *wdata = NULL; 00211 DWORD len; 00212 HWND result; 00213 00214 if (filename) 00215 { 00216 len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); 00217 wfile = heap_alloc(len*sizeof(WCHAR)); 00218 MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len ); 00219 } 00220 00221 if (data) 00222 { 00223 switch(command) 00224 { 00225 case HH_ALINK_LOOKUP: 00226 case HH_DISPLAY_SEARCH: 00227 case HH_DISPLAY_TEXT_POPUP: 00228 case HH_GET_LAST_ERROR: 00229 case HH_GET_WIN_TYPE: 00230 case HH_KEYWORD_LOOKUP: 00231 case HH_SET_WIN_TYPE: 00232 case HH_SYNC: 00233 FIXME("structures not handled yet\n"); 00234 break; 00235 00236 case HH_DISPLAY_INDEX: 00237 case HH_DISPLAY_TOPIC: 00238 case HH_DISPLAY_TOC: 00239 case HH_GET_WIN_HANDLE: 00240 case HH_SAFE_DISPLAY_TOPIC: 00241 len = MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, NULL, 0 ); 00242 wdata = heap_alloc(len*sizeof(WCHAR)); 00243 MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, wdata, len ); 00244 break; 00245 00246 case HH_CLOSE_ALL: 00247 case HH_HELP_CONTEXT: 00248 case HH_INITIALIZE: 00249 case HH_PRETRANSLATEMESSAGE: 00250 case HH_TP_HELP_CONTEXTMENU: 00251 case HH_TP_HELP_WM_HELP: 00252 case HH_UNINITIALIZE: 00253 /* either scalar or pointer to scalar - do nothing */ 00254 break; 00255 00256 default: 00257 FIXME("Unknown command: %s (%d)\n", command_to_string(command), command); 00258 break; 00259 } 00260 } 00261 00262 result = HtmlHelpW( caller, wfile, command, wdata ? (DWORD_PTR)wdata : data ); 00263 00264 heap_free(wfile); 00265 heap_free(wdata); 00266 return result; 00267 } 00268 00269 /****************************************************************** 00270 * doWinMain (HHCTRL.OCX.13) 00271 */ 00272 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine) 00273 { 00274 MSG msg; 00275 int len, buflen, mapid = -1; 00276 WCHAR *filename; 00277 char *endq = NULL; 00278 00279 hh_process = TRUE; 00280 00281 /* Parse command line option of the HTML Help command. 00282 * 00283 * Note: The only currently handled action is "mapid", 00284 * which corresponds to opening a specific page. 00285 */ 00286 while(*szCmdLine == '-') 00287 { 00288 LPSTR space, ptr; 00289 00290 ptr = szCmdLine + 1; 00291 space = strchr(ptr, ' '); 00292 if(!strncmp(ptr, "mapid", space-ptr)) 00293 { 00294 char idtxt[10]; 00295 00296 ptr += strlen("mapid")+1; 00297 space = strchr(ptr, ' '); 00298 memcpy(idtxt, ptr, space-ptr); 00299 idtxt[space-ptr] = '\0'; 00300 mapid = atoi(idtxt); 00301 szCmdLine = space+1; 00302 } 00303 else 00304 { 00305 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space-szCmdLine), szCmdLine); 00306 return 0; 00307 } 00308 } 00309 00310 /* FIXME: Check szCmdLine for bad arguments */ 00311 if (*szCmdLine == '\"') 00312 endq = strchr(++szCmdLine, '\"'); 00313 00314 if (endq) 00315 len = endq - szCmdLine; 00316 else 00317 len = strlen(szCmdLine); 00318 buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1; 00319 filename = heap_alloc(buflen * sizeof(WCHAR)); 00320 MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen); 00321 filename[buflen-1] = 0; 00322 00323 /* Open a specific help topic */ 00324 if(mapid != -1) 00325 HtmlHelpW(GetDesktopWindow(), filename, HH_HELP_CONTEXT, mapid); 00326 else 00327 HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0); 00328 00329 heap_free(filename); 00330 00331 while (GetMessageW(&msg, 0, 0, 0)) 00332 { 00333 TranslateMessage(&msg); 00334 DispatchMessageW(&msg); 00335 } 00336 00337 return 0; 00338 } 00339 00340 /****************************************************************** 00341 * DllGetClassObject (HHCTRL.OCX.@) 00342 */ 00343 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv) 00344 { 00345 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv); 00346 return CLASS_E_CLASSNOTAVAILABLE; 00347 } Generated on Sat May 26 2012 04:22:22 for ReactOS by
1.7.6.1
|