blob: e6123ddaed3eb82e96eecf1ca82fa9fca9bcd46c [file] [log] [blame]
Alexandre Julliard889f7421997-04-15 17:19:52 +00001/*
2 * Windows Help
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00003 *
4 * Copyright 1996 Martin von Loewis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Alexandre Julliard889f7421997-04-15 17:19:52 +000019 */
20
21#include <stdlib.h>
22#include <stdio.h>
23#include <string.h>
24#include <unistd.h>
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000025#include "wine/debug.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000026#include "windef.h"
27#include "wingdi.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000028#include "wine/winuser16.h"
Michael Vekslerf935c591999-02-09 15:49:39 +000029#include "wine/winbase16.h"
Alexandre Julliardd23a82b2001-09-19 20:37:04 +000030#include "win.h"
Alexandre Julliard889f7421997-04-15 17:19:52 +000031
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000032WINE_DEFAULT_DEBUG_CHANNEL(win);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000033
Alexandre Julliard889f7421997-04-15 17:19:52 +000034
Francois Gouget67c96912000-10-12 23:18:55 +000035/* WinHelp internal structure */
36typedef struct
37{
38 WORD size;
39 WORD command;
40 LONG data;
41 LONG reserved;
42 WORD ofsFilename;
43 WORD ofsData;
44} WINHELP,*LPWINHELP;
45
Alexandre Julliard889f7421997-04-15 17:19:52 +000046/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +000047 * WinHelp (USER.171)
Alexandre Julliard889f7421997-04-15 17:19:52 +000048 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000049BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
50 DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +000051{
Peter Ganten65b1f9f2000-01-05 02:41:12 +000052 BOOL ret;
Alexandre Julliardab687972000-11-15 23:41:46 +000053 DWORD mutex_count;
54
Peter Ganten65b1f9f2000-01-05 02:41:12 +000055 /* We might call WinExec() */
Alexandre Julliardab687972000-11-15 23:41:46 +000056 ReleaseThunkLock( &mutex_count );
Alexandre Julliardd586dc92000-08-14 14:35:01 +000057
Alexandre Julliardd23a82b2001-09-19 20:37:04 +000058 if (!(ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) )))
Alexandre Julliardd586dc92000-08-14 14:35:01 +000059 {
60 /* try to start the 16-bit winhelp */
61 if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
62 {
Eric Pouech4d24e0f2000-12-22 23:25:47 +000063 K32WOWYield16();
Alexandre Julliardd23a82b2001-09-19 20:37:04 +000064 ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) );
Alexandre Julliardd586dc92000-08-14 14:35:01 +000065 }
66 }
67
Alexandre Julliardab687972000-11-15 23:41:46 +000068 RestoreThunkLock( mutex_count );
Peter Ganten65b1f9f2000-01-05 02:41:12 +000069 return ret;
Alexandre Julliard889f7421997-04-15 17:19:52 +000070}
71
72
73/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +000074 * WinHelpA (USER32.@)
Alexandre Julliard889f7421997-04-15 17:19:52 +000075 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000076BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
Alexandre Julliard670cdc41997-08-24 16:00:30 +000077 DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +000078{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000079 static WORD WM_WINHELP = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +000080 HWND hDest;
Alexandre Julliard889f7421997-04-15 17:19:52 +000081 LPWINHELP lpwh;
82 HGLOBAL16 hwh;
83 int size,dsize,nlen;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000084
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000085
Vincent BĂ©ron9a624912002-05-31 23:06:46 +000086 if(!WM_WINHELP)
Peter Ganten65b1f9f2000-01-05 02:41:12 +000087 {
88 WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
89 if(!WM_WINHELP)
90 return FALSE;
91 }
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000092
Alexandre Julliarda3960291999-02-26 11:11:13 +000093 hDest = FindWindowA( "MS_WINHELP", NULL );
Peter Ganten65b1f9f2000-01-05 02:41:12 +000094 if(!hDest) {
Alexandre Julliardd586dc92000-08-14 14:35:01 +000095 if(wCommand == HELP_QUIT) return TRUE;
Marcus Meissner6f9c8402000-10-29 01:17:24 +000096 if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) {
Andreas Mohrc9cf70d2001-01-26 20:40:50 +000097 ERR("can't start winhlp32.exe -x ?\n");
Marcus Meissner6f9c8402000-10-29 01:17:24 +000098 return FALSE;
99 }
100 if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) {
Andreas Mohrc9cf70d2001-01-26 20:40:50 +0000101 FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
Marcus Meissner6f9c8402000-10-29 01:17:24 +0000102 return FALSE;
103 }
Jesper Skov5c3e4571998-11-01 19:27:22 +0000104 }
Peter Ganten65b1f9f2000-01-05 02:41:12 +0000105
106
Alexandre Julliard889f7421997-04-15 17:19:52 +0000107 switch(wCommand)
108 {
109 case HELP_CONTEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000110 case HELP_SETCONTENTS:
Alexandre Julliard77b99181997-09-14 17:17:23 +0000111 case HELP_CONTENTS:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000112 case HELP_CONTEXTPOPUP:
113 case HELP_FORCEFILE:
114 case HELP_HELPONHELP:
Alexandre Julliard77b99181997-09-14 17:17:23 +0000115 case HELP_FINDER:
Alexandre Julliard889f7421997-04-15 17:19:52 +0000116 case HELP_QUIT:
117 dsize=0;
118 break;
119 case HELP_KEY:
120 case HELP_PARTIALKEY:
121 case HELP_COMMAND:
Rein Klazesba2c8d42000-04-29 14:15:11 +0000122 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000123 break;
124 case HELP_MULTIKEY:
Francois Gouget67c96912000-10-12 23:18:55 +0000125 dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000126 break;
127 case HELP_SETWINPOS:
Francois Gouget67c96912000-10-12 23:18:55 +0000128 dsize = ((LPHELPWININFOA)dwData)->wStructSize;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000129 break;
130 default:
Marcus Meissner6f9c8402000-10-29 01:17:24 +0000131 FIXME("Unknown help command %d\n",wCommand);
Alexandre Julliard889f7421997-04-15 17:19:52 +0000132 return FALSE;
133 }
134 if(lpHelpFile)
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000135 nlen = strlen(lpHelpFile)+1;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000136 else
137 nlen = 0;
138 size = sizeof(WINHELP) + nlen + dsize;
139 hwh = GlobalAlloc16(0,size);
140 lpwh = GlobalLock16(hwh);
141 lpwh->size = size;
142 lpwh->command = wCommand;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000143 lpwh->data = dwData;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000144 if(nlen) {
Alexandre Julliard889f7421997-04-15 17:19:52 +0000145 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000146 lpwh->ofsFilename = sizeof(WINHELP);
147 } else
148 lpwh->ofsFilename = 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000149 if(dsize) {
150 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
151 lpwh->ofsData = sizeof(WINHELP)+nlen;
152 } else
153 lpwh->ofsData = 0;
154 GlobalUnlock16(hwh);
155 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
156}
157
158
159/**********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000160 * WinHelpW (USER32.@)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000161 */
Alexandre Julliard193cf502002-01-01 00:24:30 +0000162BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +0000163{
Alexandre Julliard193cf502002-01-01 00:24:30 +0000164 INT len;
165 LPSTR file;
166 BOOL ret = FALSE;
167
168 if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData );
169
170 len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL );
171 if ((file = HeapAlloc( GetProcessHeap(), 0, len )))
172 {
173 WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL );
174 ret = WinHelpA( hWnd, file, command, dwData );
175 HeapFree( GetProcessHeap(), 0, file );
176 }
Alexandre Julliard889f7421997-04-15 17:19:52 +0000177 return ret;
178}