blob: 9e3ca16c78f6adef16fceb73fd532bf95307c5c6 [file] [log] [blame]
Alexandre Julliard889f7421997-04-15 17:19:52 +00001/*
2 * Windows Help
3 */
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <unistd.h>
Alexandre Julliard359f497e1999-07-04 16:02:24 +00009#include "debugtools.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000010#include "windef.h"
11#include "wingdi.h"
Michael Vekslerca1bc861999-01-01 18:57:33 +000012#include "wine/winuser16.h"
Michael Vekslerf935c591999-02-09 15:49:39 +000013#include "wine/winbase16.h"
Alexandre Julliard889f7421997-04-15 17:19:52 +000014#include "heap.h"
15#include "ldt.h"
Peter Ganten65b1f9f2000-01-05 02:41:12 +000016#include "syslevel.h"
Alexandre Julliard889f7421997-04-15 17:19:52 +000017
Alexandre Julliardd586dc92000-08-14 14:35:01 +000018DEFAULT_DEBUG_CHANNEL(win);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000019
Alexandre Julliard889f7421997-04-15 17:19:52 +000020
21/**********************************************************************
22 * WinHelp16 (USER.171)
23 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000024BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
25 DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +000026{
Peter Ganten65b1f9f2000-01-05 02:41:12 +000027 BOOL ret;
28 /* We might call WinExec() */
29 SYSLEVEL_ReleaseWin16Lock();
Alexandre Julliardd586dc92000-08-14 14:35:01 +000030
31 if (!(ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) )))
32 {
33 /* try to start the 16-bit winhelp */
34 if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
35 {
36 Yield16();
37 ret = WinHelpA( hWnd, lpHelpFile, wCommand, (DWORD)PTR_SEG_TO_LIN(dwData) );
38 }
39 }
40
Peter Ganten65b1f9f2000-01-05 02:41:12 +000041 SYSLEVEL_RestoreWin16Lock();
42 return ret;
Alexandre Julliard889f7421997-04-15 17:19:52 +000043}
44
45
46/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +000047 * WinHelpA (USER32.579)
Alexandre Julliard889f7421997-04-15 17:19:52 +000048 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000049BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
Alexandre Julliard670cdc41997-08-24 16:00:30 +000050 DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +000051{
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000052 static WORD WM_WINHELP = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +000053 HWND hDest;
Alexandre Julliard889f7421997-04-15 17:19:52 +000054 LPWINHELP lpwh;
55 HGLOBAL16 hwh;
56 int size,dsize,nlen;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000057
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000058
59 if(!WM_WINHELP)
Peter Ganten65b1f9f2000-01-05 02:41:12 +000060 {
61 WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
62 if(!WM_WINHELP)
63 return FALSE;
64 }
Alexandre Julliard44ed71f1997-12-21 19:17:50 +000065
Alexandre Julliarda3960291999-02-26 11:11:13 +000066 hDest = FindWindowA( "MS_WINHELP", NULL );
Peter Ganten65b1f9f2000-01-05 02:41:12 +000067 if(!hDest) {
Alexandre Julliardd586dc92000-08-14 14:35:01 +000068 if(wCommand == HELP_QUIT) return TRUE;
69 if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) return FALSE;
Peter Ganten65b1f9f2000-01-05 02:41:12 +000070 if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) return FALSE;
Jesper Skov5c3e4571998-11-01 19:27:22 +000071 }
Peter Ganten65b1f9f2000-01-05 02:41:12 +000072
73
Alexandre Julliard889f7421997-04-15 17:19:52 +000074 switch(wCommand)
75 {
76 case HELP_CONTEXT:
Alexandre Julliard889f7421997-04-15 17:19:52 +000077 case HELP_SETCONTENTS:
Alexandre Julliard77b99181997-09-14 17:17:23 +000078 case HELP_CONTENTS:
Alexandre Julliard889f7421997-04-15 17:19:52 +000079 case HELP_CONTEXTPOPUP:
80 case HELP_FORCEFILE:
81 case HELP_HELPONHELP:
Alexandre Julliard77b99181997-09-14 17:17:23 +000082 case HELP_FINDER:
Alexandre Julliard889f7421997-04-15 17:19:52 +000083 case HELP_QUIT:
84 dsize=0;
85 break;
86 case HELP_KEY:
87 case HELP_PARTIALKEY:
88 case HELP_COMMAND:
Rein Klazesba2c8d42000-04-29 14:15:11 +000089 dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +000090 break;
91 case HELP_MULTIKEY:
92 dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
93 break;
94 case HELP_SETWINPOS:
95 dsize = ((LPHELPWININFO)dwData)->wStructSize;
96 break;
97 default:
Alexandre Julliard359f497e1999-07-04 16:02:24 +000098 WARN("Unknown help command %d\n",wCommand);
Alexandre Julliard889f7421997-04-15 17:19:52 +000099 return FALSE;
100 }
101 if(lpHelpFile)
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000102 nlen = strlen(lpHelpFile)+1;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000103 else
104 nlen = 0;
105 size = sizeof(WINHELP) + nlen + dsize;
106 hwh = GlobalAlloc16(0,size);
107 lpwh = GlobalLock16(hwh);
108 lpwh->size = size;
109 lpwh->command = wCommand;
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000110 lpwh->data = dwData;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000111 if(nlen) {
Alexandre Julliard889f7421997-04-15 17:19:52 +0000112 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
Alexandre Julliard23946ad1997-06-16 17:43:53 +0000113 lpwh->ofsFilename = sizeof(WINHELP);
114 } else
115 lpwh->ofsFilename = 0;
Alexandre Julliard889f7421997-04-15 17:19:52 +0000116 if(dsize) {
117 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
118 lpwh->ofsData = sizeof(WINHELP)+nlen;
119 } else
120 lpwh->ofsData = 0;
121 GlobalUnlock16(hwh);
122 return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
123}
124
125
126/**********************************************************************
Patrik Stridvall2d6457c2000-03-28 20:22:59 +0000127 * WinHelpW (USER32.580)
Alexandre Julliard889f7421997-04-15 17:19:52 +0000128 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000129BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000130 DWORD dwData )
Alexandre Julliard889f7421997-04-15 17:19:52 +0000131{
132 LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
Alexandre Julliarda3960291999-02-26 11:11:13 +0000133 BOOL ret = WinHelpA( hWnd, file, command, dwData );
Alexandre Julliard889f7421997-04-15 17:19:52 +0000134 HeapFree( GetProcessHeap(), 0, file );
135 return ret;
136}