Release 970616
[wine] / windows / winhelp.c
1 /*
2  * Windows Help
3  */
4
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "windows.h"
10 #include "heap.h"
11 #include "ldt.h"
12
13
14 /**********************************************************************
15  *             WinHelp16   (USER.171)
16  */
17 BOOL16 WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
18                   DWORD dwData )
19 {
20     return WinHelp32A( hWnd, lpHelpFile, wCommand,
21                        (DWORD)PTR_SEG_TO_LIN(dwData) );
22 }
23
24
25 /**********************************************************************
26  *             WinHelp32A   (USER32.578)
27  */
28 BOOL32 WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
29                    DWORD dwData )
30 {
31         static WORD WM_WINHELP=0;
32         HWND32 hDest;
33         LPWINHELP lpwh;
34         HGLOBAL16 hwh;
35         int size,dsize,nlen;
36         if (wCommand != HELP_QUIT)  /* FIXME */
37             if(WinExec32("winhelp.exe -x",SW_SHOWNORMAL)<=32)
38                 return FALSE;
39         /* FIXME: Should be directed yield, to let winhelp open the window */
40         Yield();
41         if(!WM_WINHELP) {
42                 WM_WINHELP=RegisterWindowMessage32A("WM_WINHELP");
43                 if(!WM_WINHELP)
44                         return FALSE;
45         }
46         hDest = FindWindow32A( "MS_WINHELP", NULL );
47         if(!hDest)
48                 if(wCommand == HELP_QUIT)
49                         return TRUE;
50                 else
51                         return FALSE;
52         switch(wCommand)
53         {
54                 case HELP_CONTEXT:
55                 case HELP_CONTENTS:
56                 case HELP_SETCONTENTS:
57                 case HELP_CONTEXTPOPUP:
58                 case HELP_FORCEFILE:
59                 case HELP_HELPONHELP:
60                 case HELP_QUIT:
61                         dsize=0;
62                         break;
63                 case HELP_KEY:
64                 case HELP_PARTIALKEY:
65                 case HELP_COMMAND:
66                         dsize = strlen( (LPSTR)dwData )+1;
67                         break;
68                 case HELP_MULTIKEY:
69                         dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
70                         break;
71                 case HELP_SETWINPOS:
72                         dsize = ((LPHELPWININFO)dwData)->wStructSize;
73                         break;
74                 default:
75                         fprintf(stderr,"Unknown help command %d\n",wCommand);
76                         return FALSE;
77         }
78         if(lpHelpFile)
79                 nlen = strlen(lpHelpFile)+1;
80         else
81                 nlen = 0;
82         size = sizeof(WINHELP) + nlen + dsize;
83         hwh = GlobalAlloc16(0,size);
84         lpwh = GlobalLock16(hwh);
85         lpwh->size = size;
86         lpwh->command = wCommand;
87         lpwh->data = dwData;
88         if(nlen) {
89                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
90                 lpwh->ofsFilename = sizeof(WINHELP);
91         } else
92                 lpwh->ofsFilename = 0;
93         if(dsize) {
94                 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
95                 lpwh->ofsData = sizeof(WINHELP)+nlen;
96         } else
97                 lpwh->ofsData = 0;
98         GlobalUnlock16(hwh);
99         return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
100 }
101
102
103 /**********************************************************************
104  *             WinHelp32W   (USER32.579)
105  */
106 BOOL32 WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
107                    DWORD dwData )
108 {
109     LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
110     BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
111     HeapFree( GetProcessHeap(), 0, file );
112     return ret;
113 }