hhctrl.ocx: Call PostQuitMessage only in hh.exe process.
[wine] / dlls / hhctrl.ocx / hhctrl.c
1 /*
2  * hhctrl implementation
3  *
4  * Copyright 2004 Krzysztof Foltman
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "wine/debug.h"
22
23 #define INIT_GUID
24 #include "hhctrl.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
27
28 HINSTANCE hhctrl_hinstance;
29 BOOL hh_process;
30
31 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
32 {
33     TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
34
35     switch (fdwReason)
36     {
37     case DLL_PROCESS_ATTACH:
38         hhctrl_hinstance = hInstance;
39         DisableThreadLibraryCalls(hInstance);
40         break;
41     case DLL_PROCESS_DETACH:
42         break;
43     }
44     return TRUE;
45 }
46
47 static const char *command_to_string(UINT command)
48 {
49 #define X(x) case x: return #x
50     switch (command)
51     {
52         X( HH_DISPLAY_TOPIC );
53         X( HH_DISPLAY_TOC );
54         X( HH_DISPLAY_INDEX );
55         X( HH_DISPLAY_SEARCH );
56         X( HH_SET_WIN_TYPE );
57         X( HH_GET_WIN_TYPE );
58         X( HH_GET_WIN_HANDLE );
59         X( HH_ENUM_INFO_TYPE );
60         X( HH_SET_INFO_TYPE );
61         X( HH_SYNC );
62         X( HH_RESERVED1 );
63         X( HH_RESERVED2 );
64         X( HH_RESERVED3 );
65         X( HH_KEYWORD_LOOKUP );
66         X( HH_DISPLAY_TEXT_POPUP );
67         X( HH_HELP_CONTEXT );
68         X( HH_TP_HELP_CONTEXTMENU );
69         X( HH_TP_HELP_WM_HELP );
70         X( HH_CLOSE_ALL );
71         X( HH_ALINK_LOOKUP );
72         X( HH_GET_LAST_ERROR );
73         X( HH_ENUM_CATEGORY );
74         X( HH_ENUM_CATEGORY_IT );
75         X( HH_RESET_IT_FILTER );
76         X( HH_SET_INCLUSIVE_FILTER );
77         X( HH_SET_EXCLUSIVE_FILTER );
78         X( HH_INITIALIZE );
79         X( HH_UNINITIALIZE );
80         X( HH_PRETRANSLATEMESSAGE );
81         X( HH_SET_GLOBAL_PROPERTY );
82     default: return "???";
83     }
84 #undef X
85 }
86
87 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD data)
88 {
89
90     TRACE("(%p, %s, command=%s, data=%d)\n",
91           caller, debugstr_w( filename ),
92           command_to_string( command ), data);
93
94     switch (command)
95     {
96     case HH_DISPLAY_TOPIC:
97     case HH_DISPLAY_TOC:
98     case HH_DISPLAY_SEARCH:
99     case HH_HELP_CONTEXT: {
100         HHInfo *info;
101         BOOL res;
102
103         FIXME("Not all HH cases handled correctly\n");
104
105         info = CreateHelpViewer(filename);
106
107         res = NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszFile);
108         if(!res)
109             ReleaseHelpViewer(info);
110
111         return NULL; /* FIXME */
112     }
113     default:
114         FIXME("HH case %s not handled.\n", command_to_string( command ));
115     }
116
117     return 0;
118 }
119
120 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD data)
121 {
122     WCHAR *wfile = NULL;
123     HWND result;
124
125     if (filename)
126     {
127         DWORD len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
128
129         wfile = hhctrl_alloc(len*sizeof(WCHAR));
130         MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
131     }
132
133     result = HtmlHelpW( caller, wfile, command, data );
134
135     hhctrl_free(wfile);
136     return result;
137 }
138
139 /******************************************************************
140  *              doWinMain (hhctrl.ocx.13)
141  */
142 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
143 {
144     MSG msg;
145     HHInfo *info;
146     LPWSTR filename = strdupAtoW(szCmdLine);
147
148     hh_process = TRUE;
149
150     /* FIXME: Check szCmdLine for bad arguments */
151     info = CreateHelpViewer(filename);
152     hhctrl_free(filename);
153     if(!info)
154         return -1;
155
156     NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszFile);
157
158     while (GetMessageW(&msg, 0, 0, 0))
159     {
160         TranslateMessage(&msg);
161         DispatchMessageW(&msg);
162     }
163
164     return 0;
165 }
166
167 /******************************************************************
168  *              DllGetClassObject (hhctrl.ocx.@)
169  */
170 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
171 {
172     FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
173     return CLASS_E_CLASSNOTAVAILABLE;
174 }