Better support for configure detection of missing types, added check
[wine] / windows / winhelp.c
1 /*
2  * Windows Help
3  *
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
19  */
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include "wine/debug.h"
26 #include "windef.h"
27 #include "wingdi.h"
28 #include "wine/winuser16.h"
29 #include "wine/winbase16.h"
30 #include "win.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(win);
33
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  *              WinHelp (USER.171)
48  */
49 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
50                          DWORD dwData )
51 {
52   BOOL ret;
53   DWORD mutex_count;
54
55   /* We might call WinExec() */
56   ReleaseThunkLock( &mutex_count );
57
58   if (!(ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) )))
59   {
60       /* try to start the 16-bit winhelp */
61       if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
62       {
63           K32WOWYield16();
64           ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) );
65       }
66   }
67
68   RestoreThunkLock( mutex_count );
69   return ret;
70 }
71
72
73 /**********************************************************************
74  *              WinHelpA (USER32.@)
75  */
76 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
77                           DWORD dwData )
78 {
79         static WORD WM_WINHELP = 0;
80         HWND hDest;
81         LPWINHELP lpwh;
82         HGLOBAL16 hwh;
83         int size,dsize,nlen;
84
85
86         if(!WM_WINHELP) 
87           {
88             WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
89             if(!WM_WINHELP)
90               return FALSE;
91           }
92
93         hDest = FindWindowA( "MS_WINHELP", NULL );
94         if(!hDest) {
95           if(wCommand == HELP_QUIT) return TRUE;
96           if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) {
97               ERR("can't start winhlp32.exe -x ?\n");
98               return FALSE;
99           }
100           if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) {
101               FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
102               return FALSE;
103           }
104         }
105
106
107         switch(wCommand)
108         {
109                 case HELP_CONTEXT:
110                 case HELP_SETCONTENTS:
111                 case HELP_CONTENTS:
112                 case HELP_CONTEXTPOPUP:
113                 case HELP_FORCEFILE:
114                 case HELP_HELPONHELP:
115                 case HELP_FINDER:
116                 case HELP_QUIT:
117                         dsize=0;
118                         break;
119                 case HELP_KEY:
120                 case HELP_PARTIALKEY:
121                 case HELP_COMMAND:
122                         dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
123                         break;
124                 case HELP_MULTIKEY:
125                         dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
126                         break;
127                 case HELP_SETWINPOS:
128                         dsize = ((LPHELPWININFOA)dwData)->wStructSize;
129                         break;
130                 default:
131                         FIXME("Unknown help command %d\n",wCommand);
132                         return FALSE;
133         }
134         if(lpHelpFile)
135                 nlen = strlen(lpHelpFile)+1;
136         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;
143         lpwh->data = dwData;
144         if(nlen) {
145                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
146                 lpwh->ofsFilename = sizeof(WINHELP);
147         } else
148                 lpwh->ofsFilename = 0;
149         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 /**********************************************************************
160  *              WinHelpW (USER32.@)
161  */
162 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, DWORD dwData )
163 {
164     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     }
177     return ret;
178 }