Turn mega double switch into static table (reduces compile time).
[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 "debug.h"
10 #include "windows.h"
11 #include "heap.h"
12 #include "ldt.h"
13
14
15 /**********************************************************************
16  *             WinHelp16   (USER.171)
17  */
18 BOOL16 WINAPI WinHelp16( HWND16 hWnd, LPCSTR lpHelpFile, UINT16 wCommand,
19                          DWORD dwData )
20 {
21     return WinHelp32A( hWnd, lpHelpFile, wCommand,
22                        (DWORD)PTR_SEG_TO_LIN(dwData) );
23 }
24
25
26 /**********************************************************************
27  *             WinHelp32A   (USER32.579)
28  */
29 BOOL32 WINAPI WinHelp32A( HWND32 hWnd, LPCSTR lpHelpFile, UINT32 wCommand,
30                           DWORD dwData )
31 {
32         static WORD WM_WINHELP = 0;
33         HWND32 hDest;
34         LPWINHELP lpwh;
35         HGLOBAL16 hwh;
36         int size,dsize,nlen;
37         if (wCommand != HELP_QUIT)  /* FIXME */
38         {
39             if (WinExec32("winhelp.exe -x",SW_SHOWNORMAL) <= 32)
40                 return FALSE;
41
42             /* NOTE: Probably, this should be directed yield, 
43                      to let winhelp open the window in all cases. */
44             Yield16();
45         }
46
47         if(!WM_WINHELP) 
48         {
49                 WM_WINHELP=RegisterWindowMessage32A("WM_WINHELP");
50                 if(!WM_WINHELP)
51                         return FALSE;
52         }
53
54         hDest = FindWindow32A( "MS_WINHELP", NULL );
55         if(!hDest)
56         {
57                 if(wCommand == HELP_QUIT)
58                         return TRUE;
59                 else
60                         return FALSE;
61         }
62         switch(wCommand)
63         {
64                 case HELP_CONTEXT:
65                 case HELP_SETCONTENTS:
66                 case HELP_CONTENTS:
67                 case HELP_CONTEXTPOPUP:
68                 case HELP_FORCEFILE:
69                 case HELP_HELPONHELP:
70                 case HELP_FINDER:
71                 case HELP_QUIT:
72                         dsize=0;
73                         break;
74                 case HELP_KEY:
75                 case HELP_PARTIALKEY:
76                 case HELP_COMMAND:
77                         dsize = strlen( (LPSTR)dwData )+1;
78                         break;
79                 case HELP_MULTIKEY:
80                         dsize = ((LPMULTIKEYHELP)dwData)->mkSize;
81                         break;
82                 case HELP_SETWINPOS:
83                         dsize = ((LPHELPWININFO)dwData)->wStructSize;
84                         break;
85                 default:
86                         WARN( win,"Unknown help command %d\n",wCommand);
87                         return FALSE;
88         }
89         if(lpHelpFile)
90                 nlen = strlen(lpHelpFile)+1;
91         else
92                 nlen = 0;
93         size = sizeof(WINHELP) + nlen + dsize;
94         hwh = GlobalAlloc16(0,size);
95         lpwh = GlobalLock16(hwh);
96         lpwh->size = size;
97         lpwh->command = wCommand;
98         lpwh->data = dwData;
99         if(nlen) {
100                 strcpy(((char*)lpwh) + sizeof(WINHELP),lpHelpFile);
101                 lpwh->ofsFilename = sizeof(WINHELP);
102         } else
103                 lpwh->ofsFilename = 0;
104         if(dsize) {
105                 memcpy(((char*)lpwh)+sizeof(WINHELP)+nlen,(LPSTR)dwData,dsize);
106                 lpwh->ofsData = sizeof(WINHELP)+nlen;
107         } else
108                 lpwh->ofsData = 0;
109         GlobalUnlock16(hwh);
110         return SendMessage16(hDest,WM_WINHELP,hWnd,hwh);
111 }
112
113
114 /**********************************************************************
115  *             WinHelp32W   (USER32.580)
116  */
117 BOOL32 WINAPI WinHelp32W( HWND32 hWnd, LPCWSTR helpFile, UINT32 command,
118                           DWORD dwData )
119 {
120     LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile );
121     BOOL32 ret = WinHelp32A( hWnd, file, command, dwData );
122     HeapFree( GetProcessHeap(), 0, file );
123     return ret;
124 }