Weird thing with lcid of library is that if sublang is neutral then we
[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 "debugtools.h"
10 #include "windef.h"
11 #include "wingdi.h"
12 #include "wine/winuser16.h"
13 #include "wine/winbase16.h"
14 #include "win.h"
15
16 DEFAULT_DEBUG_CHANNEL(win);
17
18
19 /* WinHelp internal structure */
20 typedef struct
21 {
22     WORD size;
23     WORD command;
24     LONG data;
25     LONG reserved;
26     WORD ofsFilename;
27     WORD ofsData;
28 } WINHELP,*LPWINHELP;
29
30 /**********************************************************************
31  *              WinHelp (USER.171)
32  */
33 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
34                          DWORD dwData )
35 {
36   BOOL ret;
37   DWORD mutex_count;
38
39   /* We might call WinExec() */
40   ReleaseThunkLock( &mutex_count );
41
42   if (!(ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) )))
43   {
44       /* try to start the 16-bit winhelp */
45       if (WinExec( "winhelp.exe -x", SW_SHOWNORMAL ) >= 32)
46       {
47           K32WOWYield16();
48           ret = WinHelpA( WIN_Handle32(hWnd), lpHelpFile, wCommand, (DWORD)MapSL(dwData) );
49       }
50   }
51
52   RestoreThunkLock( mutex_count );
53   return ret;
54 }
55
56
57 /**********************************************************************
58  *              WinHelpA (USER32.@)
59  */
60 BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand,
61                           DWORD dwData )
62 {
63         static WORD WM_WINHELP = 0;
64         HWND hDest;
65         LPWINHELP lpwh;
66         HGLOBAL16 hwh;
67         int size,dsize,nlen;
68
69
70         if(!WM_WINHELP) 
71           {
72             WM_WINHELP=RegisterWindowMessageA("WM_WINHELP");
73             if(!WM_WINHELP)
74               return FALSE;
75           }
76
77         hDest = FindWindowA( "MS_WINHELP", NULL );
78         if(!hDest) {
79           if(wCommand == HELP_QUIT) return TRUE;
80           if (WinExec ( "winhlp32.exe -x", SW_SHOWNORMAL ) < 32) {
81               ERR("can't start winhlp32.exe -x ?\n");
82               return FALSE;
83           }
84           if ( ! ( hDest = FindWindowA ( "MS_WINHELP", NULL ) )) {
85               FIXME("did not find MS_WINHELP (FindWindow() failed, maybe global window handling still unimplemented)\n");
86               return FALSE;
87           }
88         }
89
90
91         switch(wCommand)
92         {
93                 case HELP_CONTEXT:
94                 case HELP_SETCONTENTS:
95                 case HELP_CONTENTS:
96                 case HELP_CONTEXTPOPUP:
97                 case HELP_FORCEFILE:
98                 case HELP_HELPONHELP:
99                 case HELP_FINDER:
100                 case HELP_QUIT:
101                         dsize=0;
102                         break;
103                 case HELP_KEY:
104                 case HELP_PARTIALKEY:
105                 case HELP_COMMAND:
106                         dsize = dwData ? strlen( (LPSTR)dwData )+1: 0;
107                         break;
108                 case HELP_MULTIKEY:
109                         dsize = ((LPMULTIKEYHELPA)dwData)->mkSize;
110                         break;
111                 case HELP_SETWINPOS:
112                         dsize = ((LPHELPWININFOA)dwData)->wStructSize;
113                         break;
114                 default:
115                         FIXME("Unknown help command %d\n",wCommand);
116                         return FALSE;
117         }
118         if(lpHelpFile)
119                 nlen = strlen(lpHelpFile)+1;
120         else
121                 nlen = 0;
122         size = sizeof(WINHELP) + nlen + dsize;
123         hwh = GlobalAlloc16(0,size);
124         lpwh = GlobalLock16(hwh);
125         lpwh->size = size;
126         lpwh->command = wCommand;
127         lpwh->data = dwData;
128         if(nlen) {
129                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
130                 lpwh->ofsFilename = sizeof(WINHELP);
131         } else
132                 lpwh->ofsFilename = 0;
133         if(dsize) {
134                 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
135                 lpwh->ofsData = sizeof(WINHELP)+nlen;
136         } else
137                 lpwh->ofsData = 0;
138         GlobalUnlock16(hwh);
139         return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
140 }
141
142
143 /**********************************************************************
144  *              WinHelpW (USER32.@)
145  */
146 BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, DWORD dwData )
147 {
148     INT len;
149     LPSTR file;
150     BOOL ret = FALSE;
151
152     if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData );
153
154     len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL );
155     if ((file = HeapAlloc( GetProcessHeap(), 0, len )))
156     {
157         WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL );
158         ret = WinHelpA( hWnd, file, command, dwData );
159         HeapFree( GetProcessHeap(), 0, file );
160     }
161     return ret;
162 }