Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Windows Help |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright 1996 Martin von Loewis |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 5 | * 2002 Eric Pouech |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 22 | #include "config.h" |
| 23 | |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <string.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 28 | #ifdef HAVE_UNISTD_H |
| 29 | # include <unistd.h> |
| 30 | #endif |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 31 | #include "wine/debug.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 32 | #include "windef.h" |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 33 | #include "winbase.h" |
Jeremy White | d3e22d9 | 2000-02-10 19:03:02 +0000 | [diff] [blame] | 34 | #include "wingdi.h" |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 35 | #include "winuser.h" |
| 36 | #include "winnls.h" |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 37 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 38 | WINE_DEFAULT_DEBUG_CHANNEL(win); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 39 | |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 40 | /* Wine doesn't use the way WinHelp API sends information in Windows, because: |
| 41 | * 1/ it's not consistent acrosss Win9x, NT... |
| 42 | * 2/ NT implementation is not yet fully understood (and includes some shared |
| 43 | * memory mechanism) |
| 44 | * 3/ uses a dynamically allocated message number (WM_WINHELP), which |
| 45 | * obfuscates the code |
| 46 | * |
| 47 | * So we use (for now) the simple protocol: |
| 48 | * 1/ it's based on copy data |
| 49 | * 2/ we tag the message with a magic number, to make it a bit more robust |
| 50 | * (even if it's not 100% safe) |
| 51 | * 3/ data structure (WINHELP) has the same layout that the one used on Win95. |
| 52 | * This doesn't bring much, except not going to far away from real |
| 53 | * implementation. |
| 54 | * |
| 55 | * This means anyway that native winhelp.exe and winhlp32.exe cannot be |
| 56 | * called/manipulated from WinHelp API. |
| 57 | */ |
Francois Gouget | 67c9691 | 2000-10-12 23:18:55 +0000 | [diff] [blame] | 58 | typedef struct |
| 59 | { |
| 60 | WORD size; |
| 61 | WORD command; |
| 62 | LONG data; |
| 63 | LONG reserved; |
| 64 | WORD ofsFilename; |
| 65 | WORD ofsData; |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 66 | } WINHELP; |
Francois Gouget | 67c9691 | 2000-10-12 23:18:55 +0000 | [diff] [blame] | 67 | |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 68 | /* magic number for this message: |
| 69 | * aide means help is French ;-) |
| 70 | * SOS means ??? |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 71 | */ |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 72 | #define WINHELP_MAGIC 0xA1DE505 |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 73 | |
| 74 | /********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 75 | * WinHelpA (USER32.@) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 76 | */ |
Dmitry Timoshkov | 601a3ab | 2002-10-31 01:04:39 +0000 | [diff] [blame] | 77 | BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, ULONG_PTR dwData ) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 78 | { |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 79 | COPYDATASTRUCT cds; |
| 80 | HWND hDest; |
| 81 | int size, dsize, nlen; |
| 82 | WINHELP* lpwh; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 83 | |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 84 | hDest = FindWindowA("MS_WINHELP", NULL); |
| 85 | if (!hDest) |
| 86 | { |
| 87 | if (wCommand == HELP_QUIT) return TRUE; |
| 88 | if (WinExec("winhelp.exe -x", SW_SHOWNORMAL) < 32) |
| 89 | { |
| 90 | ERR("can't start winhelp.exe -x ?\n"); |
| 91 | return FALSE; |
Jesper Skov | 5c3e457 | 1998-11-01 19:27:22 +0000 | [diff] [blame] | 92 | } |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 93 | if (!(hDest = FindWindowA("MS_WINHELP", NULL))) |
| 94 | { |
| 95 | FIXME("Did not find a MS_WINHELP Window\n"); |
| 96 | return FALSE; |
| 97 | } |
| 98 | } |
Peter Ganten | 65b1f9f | 2000-01-05 02:41:12 +0000 | [diff] [blame] | 99 | |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 100 | switch (wCommand) |
| 101 | { |
| 102 | case HELP_CONTEXT: |
| 103 | case HELP_SETCONTENTS: |
| 104 | case HELP_CONTENTS: |
| 105 | case HELP_CONTEXTPOPUP: |
| 106 | case HELP_FORCEFILE: |
| 107 | case HELP_HELPONHELP: |
| 108 | case HELP_FINDER: |
| 109 | case HELP_QUIT: |
| 110 | dsize = 0; |
| 111 | break; |
| 112 | case HELP_KEY: |
| 113 | case HELP_PARTIALKEY: |
| 114 | case HELP_COMMAND: |
| 115 | dsize = dwData ? strlen((LPSTR)dwData) + 1 : 0; |
| 116 | break; |
| 117 | case HELP_MULTIKEY: |
| 118 | dsize = ((LPMULTIKEYHELPA)dwData)->mkSize; |
| 119 | break; |
| 120 | case HELP_SETWINPOS: |
| 121 | dsize = ((LPHELPWININFOA)dwData)->wStructSize; |
| 122 | break; |
| 123 | default: |
| 124 | FIXME("Unknown help command %d\n", wCommand); |
| 125 | return FALSE; |
| 126 | } |
| 127 | if (lpHelpFile) |
| 128 | nlen = strlen(lpHelpFile) + 1; |
| 129 | else |
| 130 | nlen = 0; |
| 131 | size = sizeof(WINHELP) + nlen + dsize; |
Peter Ganten | 65b1f9f | 2000-01-05 02:41:12 +0000 | [diff] [blame] | 132 | |
Eric Pouech | b6aad50 | 2002-11-11 22:20:47 +0000 | [diff] [blame] | 133 | lpwh = HeapAlloc(GetProcessHeap(), 0, size); |
| 134 | if (!lpwh) return FALSE; |
| 135 | |
| 136 | cds.dwData = WINHELP_MAGIC; |
| 137 | cds.cbData = size; |
| 138 | cds.lpData = (void*)lpwh; |
| 139 | |
| 140 | lpwh->size = size; |
| 141 | lpwh->command = wCommand; |
| 142 | lpwh->data = dwData; |
| 143 | if (nlen) |
| 144 | { |
| 145 | strcpy(((char*)lpwh) + sizeof(WINHELP), lpHelpFile); |
| 146 | lpwh->ofsFilename = sizeof(WINHELP); |
| 147 | } else |
| 148 | lpwh->ofsFilename = 0; |
| 149 | if (dsize) |
| 150 | { |
| 151 | memcpy(((char*)lpwh) + sizeof(WINHELP) + nlen, (LPSTR)dwData, dsize); |
| 152 | lpwh->ofsData = sizeof(WINHELP) + nlen; |
| 153 | } else |
| 154 | lpwh->ofsData = 0; |
| 155 | WINE_TRACE("Sending[%u]: cmd=%u data=%08lx fn=%s\n", |
| 156 | lpwh->size, lpwh->command, lpwh->data, |
| 157 | lpwh->ofsFilename ? (LPSTR)lpwh + lpwh->ofsFilename : ""); |
| 158 | |
Alexandre Julliard | 7ef66af | 2002-11-22 04:47:10 +0000 | [diff] [blame] | 159 | return SendMessageA(hDest, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds); |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | |
| 163 | /********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 164 | * WinHelpW (USER32.@) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 165 | */ |
Dmitry Timoshkov | 601a3ab | 2002-10-31 01:04:39 +0000 | [diff] [blame] | 166 | BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, ULONG_PTR dwData ) |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 167 | { |
Alexandre Julliard | 193cf50 | 2002-01-01 00:24:30 +0000 | [diff] [blame] | 168 | INT len; |
| 169 | LPSTR file; |
| 170 | BOOL ret = FALSE; |
| 171 | |
| 172 | if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData ); |
| 173 | |
| 174 | len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL ); |
| 175 | if ((file = HeapAlloc( GetProcessHeap(), 0, len ))) |
| 176 | { |
| 177 | WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL ); |
| 178 | ret = WinHelpA( hWnd, file, command, dwData ); |
| 179 | HeapFree( GetProcessHeap(), 0, file ); |
| 180 | } |
Alexandre Julliard | 889f742 | 1997-04-15 17:19:52 +0000 | [diff] [blame] | 181 | return ret; |
| 182 | } |