migrate substitution keywords to SVN
[reactos.git] / reactos / lib / user32 / misc / winhelp.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/misc/winhelp.c
23 * PURPOSE: WinHelp
24 * PROGRAMMER: Robert Dickenson(robd@reactos.org)
25 * UPDATE HISTORY:
26 * 23-08-2002 RDD Created from wine sources
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include "user32.h"
32 #include <string.h>
33 #include <debug.h>
34
35 /* WinHelp internal structure */
36 typedef struct
37 {
38 WORD size;
39 WORD command;
40 LONG data;
41 LONG reserved;
42 WORD ofsFilename;
43 WORD ofsData;
44 } WINHELP,*LPWINHELP;
45
46
47 /* FUNCTIONS *****************************************************************/
48
49 /*
50 * @unimplemented
51 */
52 BOOL
53 STDCALL
54 WinHelpA(HWND hWnd, LPCSTR lpszHelp, UINT uCommand, DWORD dwData)
55 {
56 static WORD WM_WINHELP = 0;
57 HWND hDest;
58 LPWINHELP lpwh;
59 HGLOBAL hwh;
60 int size,dsize,nlen;
61
62 if (!WM_WINHELP) {
63 WM_WINHELP = RegisterWindowMessageA("WM_WINHELP");
64 if (!WM_WINHELP)
65 return FALSE;
66 }
67
68 hDest = FindWindowA("MS_WINHELP", NULL);
69 if (!hDest) {
70 if (uCommand == HELP_QUIT) return TRUE;
71 if (WinExec("winhlp32.exe -x", SW_SHOWNORMAL) < 32) {
72 //ERR("can't start winhlp32.exe -x ?\n");
73 return FALSE;
74 }
75 if (!(hDest = FindWindowA("MS_WINHELP", NULL))) {
76 //FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
77 return FALSE;
78 }
79 }
80 switch (uCommand) {
81 case HELP_CONTEXT:
82 case HELP_SETCONTENTS:
83 case HELP_CONTENTS:
84 case HELP_CONTEXTPOPUP:
85 case HELP_FORCEFILE:
86 case HELP_HELPONHELP:
87 case HELP_FINDER:
88 case HELP_QUIT:
89 dsize=0;
90 break;
91 case HELP_KEY:
92 case HELP_PARTIALKEY:
93 case HELP_COMMAND:
94 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
95 break;
96 case HELP_MULTIKEY:
97 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
98 break;
99 case HELP_SETWINPOS:
100 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
101 break;
102 default:
103 //FIXME("Unknown help command %d\n",uCommand);
104 return FALSE;
105 }
106 if (lpszHelp)
107 nlen = strlen(lpszHelp)+1;
108 else
109 nlen = 0;
110 size = sizeof(WINHELP) + nlen + dsize;
111 hwh = GlobalAlloc(0,size);
112 lpwh = GlobalLock(hwh);
113 lpwh->size = size;
114 lpwh->command = uCommand;
115 lpwh->data = dwData;
116 if (nlen) {
117 strcpy(((char*)lpwh) + sizeof(WINHELP), lpszHelp);
118 lpwh->ofsFilename = sizeof(WINHELP);
119 } else {
120 lpwh->ofsFilename = 0;
121 }
122 if (dsize) {
123 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
124 lpwh->ofsData = sizeof(WINHELP)+nlen;
125 } else {
126 lpwh->ofsData = 0;
127 }
128 GlobalUnlock(hwh);
129 return SendMessageA(hDest, WM_WINHELP, (WPARAM)hWnd, (LPARAM)hwh);
130 }
131
132
133 /*
134 * @unimplemented
135 */
136 BOOL
137 STDCALL
138 WinHelpW(HWND hWnd, LPCWSTR lpszHelp, UINT uCommand, DWORD dwData)
139 {
140 INT len;
141 LPSTR file;
142 BOOL ret = FALSE;
143
144 if (!lpszHelp) return WinHelpA(hWnd, NULL, uCommand, dwData);
145
146 len = WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, NULL, 0, NULL, NULL);
147 if ((file = HeapAlloc(GetProcessHeap(), 0, len))) {
148 WideCharToMultiByte(CP_ACP, 0, lpszHelp, -1, file, len, NULL, NULL);
149 ret = WinHelpA(hWnd, file, uCommand, dwData);
150 HeapFree(GetProcessHeap(), 0, file);
151 }
152 return ret;
153 }
154