wcmd: Improve command line processing.
[wine] / programs / winhelp / macro.c
1 /*
2  * Help Viewer
3  *
4  * Copyright 1996 Ulrich Schmid
5  * Copyright 2002 Eric Pouech
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #define WIN32_LEAN_AND_MEAN
23
24 #include <stdio.h>
25
26 #include "windows.h"
27 #include "commdlg.h"
28 #include "winhelp.h"
29
30 #include "wine/debug.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
33
34 /**************************************************/
35 /*               Macro table                      */
36 /**************************************************/
37 struct MacroDesc {
38     const char* name;
39     const char* alias;
40     BOOL        isBool;
41     const char* arguments;
42     FARPROC     fn;
43 };
44
45 /* types:
46  *      U:      32 bit unsigned int
47  *      I:      32 bit signed int
48  *      S:      string
49  *      v:      unknown (32 bit entity)
50  */
51
52 static struct MacroDesc MACRO_Builtins[] = {
53     {"About",               NULL, 0, "",       (FARPROC)MACRO_About},
54     {"AddAccelerator",      "AA", 0, "UUS",    (FARPROC)MACRO_AddAccelerator},
55     {"ALink",               "AL", 0, "SUS",    (FARPROC)MACRO_ALink},
56     {"Annotate",            NULL, 0, "",       (FARPROC)MACRO_Annotate},
57     {"AppendItem",          NULL, 0, "SSSS",   (FARPROC)MACRO_AppendItem},
58     {"Back",                NULL, 0, "",       (FARPROC)MACRO_Back},
59     {"BackFlush",           "BF", 0, "",       (FARPROC)MACRO_BackFlush},
60     {"BookmarkDefine",      NULL, 0, "",       (FARPROC)MACRO_BookmarkDefine},
61     {"BookmarkMore",        NULL, 0, "",       (FARPROC)MACRO_BookmarkMore},
62     {"BrowseButtons",       NULL, 0, "",       (FARPROC)MACRO_BrowseButtons},
63     {"ChangeButtonBinding", "CBB",0, "SS",     (FARPROC)MACRO_ChangeButtonBinding},
64     {"ChangeEnable",        "CE", 0, "SS",     (FARPROC)MACRO_ChangeEnable},
65     {"ChangeItemBinding",   "CIB",0, "SS",     (FARPROC)MACRO_ChangeItemBinding},
66     {"CheckItem",           "CI", 0, "S",      (FARPROC)MACRO_CheckItem},
67     {"CloseSecondarys",     "CS", 0, "",       (FARPROC)MACRO_CloseSecondarys},
68     {"CloseWindow",         "CW", 0, "S",      (FARPROC)MACRO_CloseWindow},
69     {"Compare",             NULL, 0, "S",      (FARPROC)MACRO_Compare},
70     {"Contents",            NULL, 0, "",       (FARPROC)MACRO_Contents},
71     {"ControlPanel",        NULL, 0, "SSU",    (FARPROC)MACRO_ControlPanel},
72     {"CopyDialog",          NULL, 0, "",       (FARPROC)MACRO_CopyDialog},
73     {"CopyTopic",           "CT", 0, "",       (FARPROC)MACRO_CopyTopic},
74     {"CreateButton",        "CB", 0, "SSS",    (FARPROC)MACRO_CreateButton},
75     {"DeleteItem",          NULL, 0, "S",      (FARPROC)MACRO_DeleteItem},
76     {"DeleteMark",          NULL, 0, "S",      (FARPROC)MACRO_DeleteMark},
77     {"DestroyButton",       NULL, 0, "S",      (FARPROC)MACRO_DestroyButton},
78     {"DisableButton",       "DB", 0, "S",      (FARPROC)MACRO_DisableButton},
79     {"DisableItem",         "DI", 0, "S",      (FARPROC)MACRO_DisableItem},
80     {"EnableButton",        "EB", 0, "S",      (FARPROC)MACRO_EnableButton},
81     {"EnableItem",          "EI", 0, "S",      (FARPROC)MACRO_EnableItem},
82     {"EndMPrint",           NULL, 0, "",       (FARPROC)MACRO_EndMPrint},
83     {"ExecFile",            "EF", 0, "SSUS",   (FARPROC)MACRO_ExecFile},
84     {"ExecProgram",         "EP", 0, "SU",     (FARPROC)MACRO_ExecProgram},
85     {"Exit",                NULL, 0, "",       (FARPROC)MACRO_Exit},
86     {"ExtAbleItem",         NULL, 0, "SU",     (FARPROC)MACRO_ExtAbleItem},
87     {"ExtInsertItem",       NULL, 0, "SSSSUU", (FARPROC)MACRO_ExtInsertItem},
88     {"ExtInsertMenu",       NULL, 0, "SSSUU",  (FARPROC)MACRO_ExtInsertMenu},
89     {"FileExist",           "FE", 1, "S",      (FARPROC)MACRO_FileExist},
90     {"FileOpen",            "FO", 0, "",       (FARPROC)MACRO_FileOpen},
91     {"Find",                NULL, 0, "",       (FARPROC)MACRO_Find},
92     {"Finder",              "FD", 0, "",       (FARPROC)MACRO_Finder},
93     {"FloatingMenu",        NULL, 0, "",       (FARPROC)MACRO_FloatingMenu},
94     {"Flush",               "FH", 0, "",       (FARPROC)MACRO_Flush},
95     {"FocusWindow",         NULL, 0, "S",      (FARPROC)MACRO_FocusWindow},
96     {"Generate",            NULL, 0, "SUU",    (FARPROC)MACRO_Generate},
97     {"GotoMark",            NULL, 0, "S",      (FARPROC)MACRO_GotoMark},
98     {"HelpOn",              NULL, 0, "",       (FARPROC)MACRO_HelpOn},
99     {"HelpOnTop",           NULL, 0, "",       (FARPROC)MACRO_HelpOnTop},
100     {"History",             NULL, 0, "",       (FARPROC)MACRO_History},
101     {"InitMPrint",          NULL, 1, "",       (FARPROC)MACRO_InitMPrint},
102     {"InsertItem",          NULL, 0, "SSSSU",  (FARPROC)MACRO_InsertItem},
103     {"InsertMenu",          NULL, 0, "SSU",    (FARPROC)MACRO_InsertMenu},
104     {"IfThen",              "IF", 0, "BS",     (FARPROC)MACRO_IfThen},
105     {"IfThenElse",          "IE", 0, "BSS",    (FARPROC)MACRO_IfThenElse},
106     {"IsBook",              NULL, 1, "",       (FARPROC)MACRO_IsBook},
107     {"IsMark",              NULL, 1, "S",      (FARPROC)MACRO_IsMark},
108     {"IsNotMark",           "NM", 1, "S",      (FARPROC)MACRO_IsNotMark},
109     {"JumpContents",        NULL, 0, "SS",     (FARPROC)MACRO_JumpContents},
110     {"JumpContext",         "JC", 0, "SSU",    (FARPROC)MACRO_JumpContext},
111     {"JumpHash",            "JH", 0, "SSU",    (FARPROC)MACRO_JumpHash},
112     {"JumpHelpOn",          NULL, 0, "",       (FARPROC)MACRO_JumpHelpOn},
113     {"JumpID",              "JI", 0, "SSS",    (FARPROC)MACRO_JumpID},
114     {"JumpKeyword",         "JK", 0, "SSS",    (FARPROC)MACRO_JumpKeyword},
115     {"KLink",               "KL", 0, "SUSS",   (FARPROC)MACRO_KLink},
116     {"Menu",                "MU", 0, "",       (FARPROC)MACRO_Menu},
117     {"MPrintHash",          NULL, 0, "U",      (FARPROC)MACRO_MPrintHash},
118     {"MPrintID",            NULL, 0, "S",      (FARPROC)MACRO_MPrintID},
119     {"Next",                NULL, 0, "",       (FARPROC)MACRO_Next},
120     {"NoShow",              NULL, 0, "",       (FARPROC)MACRO_NoShow},
121     {"PopupContext",        "PC", 0, "SU",     (FARPROC)MACRO_PopupContext},
122     {"PopupHash",           NULL, 0, "SU",     (FARPROC)MACRO_PopupHash},
123     {"PopupId",             "PI", 0, "SS",     (FARPROC)MACRO_PopupId},
124     {"PositionWindow",      "PW", 0, "IIUUUS", (FARPROC)MACRO_PositionWindow},
125     {"Prev",                NULL, 0, "",       (FARPROC)MACRO_Prev},
126     {"Print",               NULL, 0, "",       (FARPROC)MACRO_Print},
127     {"PrinterSetup",        NULL, 0, "",       (FARPROC)MACRO_PrinterSetup},
128     {"RegisterRoutine",     "RR", 0, "SSS",    (FARPROC)MACRO_RegisterRoutine},
129     {"RemoveAccelerator",   "RA", 0, "UU",     (FARPROC)MACRO_RemoveAccelerator},
130     {"ResetMenu",           NULL, 0, "",       (FARPROC)MACRO_ResetMenu},
131     {"SaveMark",            NULL, 0, "S",      (FARPROC)MACRO_SaveMark},
132     {"Search",              NULL, 0, "",       (FARPROC)MACRO_Search},
133     {"SetContents",         NULL, 0, "SU",     (FARPROC)MACRO_SetContents},
134     {"SetHelpOnFile",       NULL, 0, "S",      (FARPROC)MACRO_SetHelpOnFile},
135     {"SetPopupColor",       "SPC",0, "UUU",    (FARPROC)MACRO_SetPopupColor},
136     {"ShellExecute",        "SE", 0, "SSUUSS", (FARPROC)MACRO_ShellExecute},
137     {"ShortCut",            "SH", 0, "SSUUS",  (FARPROC)MACRO_ShortCut},
138     {"TCard",               NULL, 0, "U",      (FARPROC)MACRO_TCard},
139     {"Test",                NULL, 0, "U",      (FARPROC)MACRO_Test},
140     {"TestALink",           NULL, 1, "S",      (FARPROC)MACRO_TestALink},
141     {"TestKLink",           NULL, 1, "S",      (FARPROC)MACRO_TestKLink},
142     {"UncheckItem",         "UI", 0, "S",      (FARPROC)MACRO_UncheckItem},
143     {"UpdateWindow",        "UW", 0, "SS",     (FARPROC)MACRO_UpdateWindow},
144     {NULL,                  NULL, 0, NULL,     NULL}
145 };
146
147 static struct MacroDesc*MACRO_Loaded /* = NULL */;
148 static unsigned         MACRO_NumLoaded /* = 0 */;
149
150 static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len)
151 {
152     struct MacroDesc*   md;
153
154     for (md = start; md->name && len != 0; md++, len--)
155     {
156         if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))
157         {
158             lr->proto = md->arguments;
159             lr->function = md->fn;
160             return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;
161         }
162     }
163     return EMPTY;
164 }
165
166 int MACRO_Lookup(const char* name, struct lexret* lr)
167 {
168     int ret;
169
170     if ((ret = MACRO_DoLookUp(MACRO_Builtins, name, lr, -1)) != EMPTY)
171         return ret;
172     if (MACRO_Loaded && (ret = MACRO_DoLookUp(MACRO_Loaded, name, lr, MACRO_NumLoaded)) != EMPTY)
173         return ret;
174
175     lr->string = name;
176     return IDENTIFIER;
177 }
178
179 /*******      helper functions     *******/
180
181 static WINHELP_BUTTON**        MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
182 {
183     WINHELP_BUTTON**    b;
184
185     for (b = &win->first_button; *b; b = &(*b)->next)
186         if (!lstrcmpi(name, (*b)->lpszID)) break;
187     return b;
188 }
189
190 /******* real macro implementation *******/
191
192 void CALLBACK MACRO_About(void)
193 {
194     WINE_FIXME("()\n");
195 }
196
197 void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
198 {
199     WINE_FIXME("(%lu, %lu, \"%s\")\n", u1, u2, str);
200 }
201
202 void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
203 {
204     WINE_FIXME("(\"%s\", %lu, \"%s\")\n", str1, u, str2);
205 }
206
207 void CALLBACK MACRO_Annotate(void)
208 {
209     WINE_FIXME("()\n");
210 }
211
212 void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
213 {
214     WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);
215 }
216
217 void CALLBACK MACRO_Back(void)
218 {
219     WINHELP_WINDOW* win = Globals.active_win;
220
221     WINE_TRACE("()\n");
222
223     if (win && win->backIndex >= 2)
224         WINHELP_CreateHelpWindow(win->back[--win->backIndex - 1],
225                                  win->info, SW_SHOW);
226 }
227
228 void CALLBACK MACRO_BackFlush(void)
229 {
230     WINHELP_WINDOW* win = Globals.active_win;
231
232     WINE_TRACE("()\n");
233
234     if (win)
235     {
236         int     i;
237
238         for (i = 0; i < win->backIndex; i++)
239         {
240             HLPFILE_FreeHlpFile(win->back[i]->file);
241             win->back[i] = NULL;
242         }
243         win->backIndex = 0;
244     }
245 }
246
247 void CALLBACK MACRO_BookmarkDefine(void)
248 {
249     WINE_FIXME("()\n");
250 }
251
252 void CALLBACK MACRO_BookmarkMore(void)
253 {
254     WINE_FIXME("()\n");
255 }
256
257 void CALLBACK MACRO_BrowseButtons(void)
258 {
259     WINE_TRACE("()\n");
260
261     MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
262     MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
263 }
264
265 void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
266 {
267     WINHELP_WINDOW*     win = Globals.active_win;
268     WINHELP_BUTTON*     button;
269     WINHELP_BUTTON**    b;
270     LONG                size;
271     LPSTR               ptr;
272
273     WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
274
275     b = MACRO_LookupButton(win, id);
276     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
277
278     size = sizeof(WINHELP_BUTTON) + lstrlen(id) +
279         lstrlen((*b)->lpszName) + lstrlen(macro) + 3;
280
281     button = HeapAlloc(GetProcessHeap(), 0, size);
282     if (!button) return;
283
284     button->next  = (*b)->next;
285     button->hWnd  = (*b)->hWnd;
286     button->wParam = (*b)->wParam;
287
288     ptr = (char*)button + sizeof(WINHELP_BUTTON);
289
290     lstrcpy(ptr, id);
291     button->lpszID = ptr;
292     ptr += lstrlen(id) + 1;
293
294     lstrcpy(ptr, (*b)->lpszName);
295     button->lpszName = ptr;
296     ptr += lstrlen((*b)->lpszName) + 1;
297
298     lstrcpy(ptr, macro);
299     button->lpszMacro = ptr;
300
301     *b = button;
302
303     SendMessage(win->hMainWnd, WM_USER, 0, 0);
304 }
305
306 void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
307 {
308     WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
309
310     MACRO_ChangeButtonBinding(id, macro);
311     MACRO_EnableButton(id);
312 }
313
314 void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
315 {
316     WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
317 }
318
319 void CALLBACK MACRO_CheckItem(LPCSTR str)
320 {
321     WINE_FIXME("(\"%s\")\n", str);
322 }
323
324 void CALLBACK MACRO_CloseSecondarys(void)
325 {
326     WINHELP_WINDOW *win;
327
328     WINE_TRACE("()\n");
329     for (win = Globals.win_list; win; win = win->next)
330         if (win->lpszName && lstrcmpi(win->lpszName, "main"))
331             DestroyWindow(win->hMainWnd);
332 }
333
334 void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow)
335 {
336     WINHELP_WINDOW *win;
337
338     WINE_TRACE("(\"%s\")\n", lpszWindow);
339
340     if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
341
342     for (win = Globals.win_list; win; win = win->next)
343         if (win->lpszName && !lstrcmpi(win->lpszName, lpszWindow))
344             DestroyWindow(win->hMainWnd);
345 }
346
347 void CALLBACK MACRO_Compare(LPCSTR str)
348 {
349     WINE_FIXME("(\"%s\")\n", str);
350 }
351
352 void CALLBACK MACRO_Contents(void)
353 {
354     WINE_TRACE("()\n");
355
356     if (Globals.active_win->page)
357         MACRO_JumpContents(Globals.active_win->page->file->lpszPath, NULL);
358 }
359
360 void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
361 {
362     WINE_FIXME("(\"%s\", \"%s\", %lu)\n", str1, str2, u);
363 }
364
365 void CALLBACK MACRO_CopyDialog(void)
366 {
367     WINE_FIXME("()\n");
368 }
369
370 void CALLBACK MACRO_CopyTopic(void)
371 {
372     WINE_FIXME("()\n");
373 }
374
375 void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
376 {
377     WINHELP_WINDOW *win = Globals.active_win;
378     WINHELP_BUTTON *button, **b;
379     LONG            size;
380     LPSTR           ptr;
381
382     WINE_TRACE("(\"%s\", \"%s\", %s)\n", id, name, macro);
383
384     size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;
385
386     button = HeapAlloc(GetProcessHeap(), 0, size);
387     if (!button) return;
388
389     button->next  = 0;
390     button->hWnd  = 0;
391
392     ptr = (char*)button + sizeof(WINHELP_BUTTON);
393
394     lstrcpy(ptr, id);
395     button->lpszID = ptr;
396     ptr += lstrlen(id) + 1;
397
398     lstrcpy(ptr, name);
399     button->lpszName = ptr;
400     ptr += lstrlen(name) + 1;
401
402     lstrcpy(ptr, macro);
403     button->lpszMacro = ptr;
404
405     button->wParam = WH_FIRST_BUTTON;
406     for (b = &win->first_button; *b; b = &(*b)->next)
407         button->wParam = max(button->wParam, (*b)->wParam + 1);
408     *b = button;
409
410     SendMessage(win->hMainWnd, WM_USER, 0, 0);
411 }
412
413 void CALLBACK MACRO_DeleteItem(LPCSTR str)
414 {
415     WINE_FIXME("(\"%s\")\n", str);
416 }
417
418 void CALLBACK MACRO_DeleteMark(LPCSTR str)
419 {
420     WINE_FIXME("(\"%s\")\n", str);
421 }
422
423 void CALLBACK MACRO_DestroyButton(LPCSTR str)
424 {
425     WINE_FIXME("(\"%s\")\n", str);
426 }
427
428 void CALLBACK MACRO_DisableButton(LPCSTR id)
429 {
430     WINHELP_BUTTON**    b;
431
432     WINE_FIXME("(\"%s\")\n", id);
433
434     b = MACRO_LookupButton(Globals.active_win, id);
435     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
436
437     EnableWindow((*b)->hWnd, FALSE);
438 }
439
440 void CALLBACK MACRO_DisableItem(LPCSTR str)
441 {
442     WINE_FIXME("(\"%s\")\n", str);
443 }
444
445 void CALLBACK MACRO_EnableButton(LPCSTR id)
446 {
447     WINHELP_BUTTON**    b;
448
449     WINE_TRACE("(\"%s\")\n", id);
450
451     b = MACRO_LookupButton(Globals.active_win, id);
452     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
453
454     EnableWindow((*b)->hWnd, TRUE);
455 }
456
457 void CALLBACK MACRO_EnableItem(LPCSTR str)
458 {
459     WINE_FIXME("(\"%s\")\n", str);
460 }
461
462 void CALLBACK MACRO_EndMPrint(void)
463 {
464     WINE_FIXME("()\n");
465 }
466
467 void CALLBACK MACRO_ExecFile(LPCSTR str1, LPCSTR str2, LONG u, LPCSTR str3)
468 {
469     WINE_FIXME("(\"%s\", \"%s\", %lu, \"%s\")\n", str1, str2, u, str3);
470 }
471
472 void CALLBACK MACRO_ExecProgram(LPCSTR str, LONG u)
473 {
474     WINE_FIXME("(\"%s\", %lu)\n", str, u);
475 }
476
477 void CALLBACK MACRO_Exit(void)
478 {
479     WINE_TRACE("()\n");
480
481     while (Globals.win_list)
482         DestroyWindow(Globals.win_list->hMainWnd);
483 }
484
485 void CALLBACK MACRO_ExtAbleItem(LPCSTR str, LONG u)
486 {
487     WINE_FIXME("(\"%s\", %lu)\n", str, u);
488 }
489
490 void CALLBACK MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
491 {
492     WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %lu, %lu)\n", str1, str2, str3, str4, u1, u2);
493 }
494
495 void CALLBACK MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
496 {
497     WINE_FIXME("(\"%s\", \"%s\", \"%s\", %lu, %lu)\n", str1, str2, str3, u1, u2);
498 }
499
500 BOOL CALLBACK MACRO_FileExist(LPCSTR str)
501 {
502     WINE_TRACE("(\"%s\")\n", str);
503     return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES;
504 }
505
506 void CALLBACK MACRO_FileOpen(void)
507 {
508     OPENFILENAME openfilename;
509     CHAR szPath[MAX_PATHNAME_LEN];
510     CHAR szDir[MAX_PATHNAME_LEN];
511     CHAR szzFilter[2 * MAX_STRING_LEN + 100];
512     LPSTR p = szzFilter;
513
514     WINE_TRACE("()\n");
515
516     LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
517     p += strlen(p) + 1;
518     lstrcpy(p, "*.hlp");
519     p += strlen(p) + 1;
520     LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
521     p += strlen(p) + 1;
522     lstrcpy(p, "*.*");
523     p += strlen(p) + 1;
524     *p = '\0';
525
526     GetCurrentDirectory(sizeof(szDir), szDir);
527
528     szPath[0]='\0';
529
530     openfilename.lStructSize       = sizeof(OPENFILENAME);
531     openfilename.hwndOwner         = Globals.active_win->hMainWnd;
532     openfilename.hInstance         = Globals.hInstance;
533     openfilename.lpstrFilter       = szzFilter;
534     openfilename.lpstrCustomFilter = 0;
535     openfilename.nMaxCustFilter    = 0;
536     openfilename.nFilterIndex      = 1;
537     openfilename.lpstrFile         = szPath;
538     openfilename.nMaxFile          = sizeof(szPath);
539     openfilename.lpstrFileTitle    = 0;
540     openfilename.nMaxFileTitle     = 0;
541     openfilename.lpstrInitialDir   = szDir;
542     openfilename.lpstrTitle        = 0;
543     openfilename.Flags             = 0;
544     openfilename.nFileOffset       = 0;
545     openfilename.nFileExtension    = 0;
546     openfilename.lpstrDefExt       = 0;
547     openfilename.lCustData         = 0;
548     openfilename.lpfnHook          = 0;
549     openfilename.lpTemplateName    = 0;
550
551     if (GetOpenFileName(&openfilename))
552     {
553         HLPFILE*        hlpfile = WINHELP_LookupHelpFile(szPath);
554
555         WINHELP_CreateHelpWindowByHash(hlpfile, 0,
556                                        WINHELP_GetWindowInfo(hlpfile, "main"), SW_SHOWNORMAL);
557     }
558 }
559
560 void CALLBACK MACRO_Find(void)
561 {
562     WINE_FIXME("()\n");
563 }
564
565 void CALLBACK MACRO_Finder(void)
566 {
567     WINE_FIXME("()\n");
568 }
569
570 void CALLBACK MACRO_FloatingMenu(void)
571 {
572     WINE_FIXME("()\n");
573 }
574
575 void CALLBACK MACRO_Flush(void)
576 {
577     WINE_FIXME("()\n");
578 }
579
580 void CALLBACK MACRO_FocusWindow(LPCSTR lpszWindow)
581 {
582     WINHELP_WINDOW *win;
583
584     WINE_TRACE("(\"%s\")\n", lpszWindow);
585
586     if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
587
588     for (win = Globals.win_list; win; win = win->next)
589         if (win->lpszName && !lstrcmpi(win->lpszName, lpszWindow))
590             SetFocus(win->hMainWnd);
591 }
592
593 void CALLBACK MACRO_Generate(LPCSTR str, LONG w, LONG l)
594 {
595     WINE_FIXME("(\"%s\", %lx, %lx)\n", str, w, l);
596 }
597
598 void CALLBACK MACRO_GotoMark(LPCSTR str)
599 {
600     WINE_FIXME("(\"%s\")\n", str);
601 }
602
603 void CALLBACK MACRO_HelpOn(void)
604 {
605     WINE_TRACE("()\n");
606     MACRO_JumpContents((Globals.wVersion > 4) ? "winhelp32.hlp" : "winhelp.hlp", NULL);
607 }
608
609 void CALLBACK MACRO_HelpOnTop(void)
610 {
611     WINE_FIXME("()\n");
612 }
613
614 void CALLBACK MACRO_History(void)
615 {
616     WINE_TRACE("()\n");
617
618     if (Globals.active_win && !Globals.active_win->hHistoryWnd)
619     {
620         HWND hWnd = CreateWindow(HISTORY_WIN_CLASS_NAME, "History", WS_OVERLAPPEDWINDOW,
621                                  0, 0, 0, 0, 0, 0, Globals.hInstance, Globals.active_win);
622         ShowWindow(hWnd, SW_NORMAL);
623     }
624 }
625
626 void CALLBACK MACRO_IfThen(BOOL b, LPCSTR t)
627 {
628     if (b) MACRO_ExecuteMacro(t);
629 }
630
631 void CALLBACK MACRO_IfThenElse(BOOL b, LPCSTR t, LPCSTR f)
632 {
633     if (b) MACRO_ExecuteMacro(t); else MACRO_ExecuteMacro(f);
634 }
635
636 BOOL CALLBACK MACRO_InitMPrint(void)
637 {
638     WINE_FIXME("()\n");
639     return FALSE;
640 }
641
642 void CALLBACK MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
643 {
644     WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %lu)\n", str1, str2, str3, str4, u);
645 }
646
647 void CALLBACK MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
648 {
649     WINE_FIXME("(\"%s\", \"%s\", %lu)\n", str1, str2, u);
650 }
651
652 BOOL CALLBACK MACRO_IsBook(void)
653 {
654     WINE_TRACE("()\n");
655     return Globals.isBook;
656 }
657
658 BOOL CALLBACK MACRO_IsMark(LPCSTR str)
659 {
660     WINE_FIXME("(\"%s\")\n", str);
661     return FALSE;
662 }
663
664 BOOL CALLBACK MACRO_IsNotMark(LPCSTR str)
665 {
666     WINE_FIXME("(\"%s\")\n", str);
667     return TRUE;
668 }
669
670 void CALLBACK MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
671 {
672     HLPFILE*    hlpfile;
673
674     WINE_TRACE("(\"%s\", \"%s\")\n", lpszPath, lpszWindow);
675     hlpfile = WINHELP_LookupHelpFile(lpszPath);
676     WINHELP_CreateHelpWindowByHash(hlpfile, 0,
677                                    WINHELP_GetWindowInfo(hlpfile, lpszWindow),
678                                    SW_NORMAL);
679 }
680
681 void CALLBACK MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
682 {
683     WINE_FIXME("(\"%s\", \"%s\", %ld)semi-stub\n", lpszPath, lpszWindow, context);
684     return MACRO_JumpContents(lpszPath, lpszWindow);
685 }
686
687 void CALLBACK MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
688 {
689     HLPFILE*    hlpfile;
690
691     WINE_TRACE("(\"%s\", \"%s\", %lu)\n", lpszPath, lpszWindow, lHash);
692     hlpfile = WINHELP_LookupHelpFile(lpszPath);
693     WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
694                                    WINHELP_GetWindowInfo(hlpfile, lpszWindow),
695                                    SW_NORMAL);
696 }
697
698 void CALLBACK MACRO_JumpHelpOn(void)
699 {
700     WINE_FIXME("()\n");
701 }
702
703 /* FIXME: those two macros are wrong
704  * they should only contain 2 strings, path & window are coded as path>window
705  */
706 void CALLBACK MACRO_JumpID(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR topic_id)
707 {
708     WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, topic_id);
709     MACRO_JumpHash(lpszPath, lpszWindow, HLPFILE_Hash(topic_id));
710 }
711
712 void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
713 {
714     WINE_FIXME("(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, keyword);
715 }
716
717 void CALLBACK MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
718 {
719     WINE_FIXME("(\"%s\", %lu, \"%s\", \"%s\")\n", str1, u, str2, str3);
720 }
721
722 void CALLBACK MACRO_Menu(void)
723 {
724     WINE_FIXME("()\n");
725 }
726
727 void CALLBACK MACRO_MPrintHash(LONG u)
728 {
729     WINE_FIXME("(%lu)\n", u);
730 }
731
732 void CALLBACK MACRO_MPrintID(LPCSTR str)
733 {
734     WINE_FIXME("(\"%s\")\n", str);
735 }
736
737 void CALLBACK MACRO_Next(void)
738 {
739     HLPFILE_PAGE*   page;
740
741     WINE_TRACE("()\n");
742     page = Globals.active_win->page;
743     page = HLPFILE_PageByOffset(page->file, page->browse_fwd);
744     if (page)
745     {
746         page->file->wRefCount++;
747         WINHELP_CreateHelpWindow(page, Globals.active_win->info, SW_NORMAL);
748     }
749 }
750
751 void CALLBACK MACRO_NoShow(void)
752 {
753     WINE_FIXME("()\n");
754 }
755
756 void CALLBACK MACRO_PopupContext(LPCSTR str, LONG u)
757 {
758     WINE_FIXME("(\"%s\", %lu)\n", str, u);
759 }
760
761 void CALLBACK MACRO_PopupHash(LPCSTR str, LONG u)
762 {
763     WINE_FIXME("(\"%s\", %lu)\n", str, u);
764 }
765
766 void CALLBACK MACRO_PopupId(LPCSTR str1, LPCSTR str2)
767 {
768     WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
769 }
770
771 void CALLBACK MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
772 {
773     WINE_FIXME("(%li, %li, %lu, %lu, %lu, \"%s\")\n", i1, i2, u1, u2, u3, str);
774 }
775
776 void CALLBACK MACRO_Prev(void)
777 {
778     HLPFILE_PAGE*   page;
779
780     WINE_TRACE("()\n");
781     page = Globals.active_win->page;
782     page = HLPFILE_PageByOffset(page->file, page->browse_bwd);
783     if (page)
784     {
785         page->file->wRefCount++;
786         WINHELP_CreateHelpWindow(page, Globals.active_win->info, SW_NORMAL);
787     }
788 }
789
790 void CALLBACK MACRO_Print(void)
791 {
792     PRINTDLG printer;
793
794     WINE_TRACE("()\n");
795
796     printer.lStructSize         = sizeof(printer);
797     printer.hwndOwner           = Globals.active_win->hMainWnd;
798     printer.hInstance           = Globals.hInstance;
799     printer.hDevMode            = 0;
800     printer.hDevNames           = 0;
801     printer.hDC                 = 0;
802     printer.Flags               = 0;
803     printer.nFromPage           = 0;
804     printer.nToPage             = 0;
805     printer.nMinPage            = 0;
806     printer.nMaxPage            = 0;
807     printer.nCopies             = 0;
808     printer.lCustData           = 0;
809     printer.lpfnPrintHook       = 0;
810     printer.lpfnSetupHook       = 0;
811     printer.lpPrintTemplateName = 0;
812     printer.lpSetupTemplateName = 0;
813     printer.hPrintTemplate      = 0;
814     printer.hSetupTemplate      = 0;
815
816     if (PrintDlgA(&printer)) {
817         WINE_FIXME("Print()\n");
818     }
819 }
820
821 void CALLBACK MACRO_PrinterSetup(void)
822 {
823     WINE_FIXME("()\n");
824 }
825
826 void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR args)
827 {
828     FARPROC             fn = NULL;
829     int                 size;
830     WINHELP_DLL*        dll;
831
832     WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", dll_name, proc, args);
833
834     /* FIXME: are the registered DLLs global or linked to the current file ???
835      * We assume globals (as we did for macros, but is this really the case ???)
836      */
837     for (dll = Globals.dlls; dll; dll = dll->next)
838     {
839         if (!strcmp(dll->name, dll_name)) break;
840     }
841     if (!dll)
842     {
843         HANDLE hLib = LoadLibrary(dll_name);
844
845         /* FIXME: the library will not be unloaded until exit of program 
846          * We don't send the DW_TERM message
847          */
848         WINE_TRACE("Loading %s\n", dll_name);
849         /* FIXME: should look in the directory where current hlpfile
850          * is loaded from
851          */
852         if (hLib == NULL)
853         {
854             /* FIXME: internationalisation for error messages */
855             WINE_FIXME("Cannot find dll %s\n", dll_name);
856         }
857         else if ((dll = HeapAlloc(GetProcessHeap(), 0, sizeof(*dll))))
858         {
859             dll->hLib = hLib;
860             dll->name = strdup(dll_name); /* FIXME */
861             dll->next = Globals.dlls;
862             Globals.dlls = dll;
863             dll->handler = (WINHELP_LDLLHandler)GetProcAddress(dll->hLib, "LDLLHandler");
864             dll->class = dll->handler ? (dll->handler)(DW_WHATMSG, 0, 0) : DC_NOMSG;
865             WINE_TRACE("Got class %lx for DLL %s\n", dll->class, dll_name);
866             if (dll->class & DC_INITTERM) dll->handler(DW_INIT, 0, 0);
867             if (dll->class & DC_CALLBACKS) dll->handler(DW_CALLBACKS, (DWORD)Callbacks, 0);
868         }
869         else WINE_WARN("OOM\n");
870     }
871     if (dll && !(fn = GetProcAddress(dll->hLib, proc)))
872     {
873         /* FIXME: internationalisation for error messages */
874         WINE_FIXME("Cannot find proc %s in dll %s\n", dll_name, proc);
875     }
876
877     size = ++MACRO_NumLoaded * sizeof(struct MacroDesc);
878     if (!MACRO_Loaded) MACRO_Loaded = HeapAlloc(GetProcessHeap(), 0, size);
879     else MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, size);
880     MACRO_Loaded[MACRO_NumLoaded - 1].name      = strdup(proc); /* FIXME */
881     MACRO_Loaded[MACRO_NumLoaded - 1].alias     = NULL;
882     MACRO_Loaded[MACRO_NumLoaded - 1].isBool    = 0;
883     MACRO_Loaded[MACRO_NumLoaded - 1].arguments = strdup(args); /* FIXME */
884     MACRO_Loaded[MACRO_NumLoaded - 1].fn        = fn;
885     WINE_TRACE("Added %s(%s) at %p\n", proc, args, fn);
886 }
887
888 void CALLBACK MACRO_RemoveAccelerator(LONG u1, LONG u2)
889 {
890     WINE_FIXME("(%lu, %lu)\n", u1, u2);
891 }
892
893 void CALLBACK MACRO_ResetMenu(void)
894 {
895     WINE_FIXME("()\n");
896 }
897
898 void CALLBACK MACRO_SaveMark(LPCSTR str)
899 {
900     WINE_FIXME("(\"%s\")\n", str);
901 }
902
903 void CALLBACK MACRO_Search(void)
904 {
905     WINE_FIXME("()\n");
906 }
907
908 void CALLBACK MACRO_SetContents(LPCSTR str, LONG u)
909 {
910     WINE_FIXME("(\"%s\", %lu)\n", str, u);
911 }
912
913 void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
914 {
915     WINE_FIXME("(\"%s\")\n", str);
916 }
917
918 void CALLBACK MACRO_SetPopupColor(LONG u1, LONG u2, LONG u3)
919 {
920     WINE_FIXME("(%lu, %lu, %lu)\n", u1, u2, u3);
921 }
922
923 void CALLBACK MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
924 {
925     WINE_FIXME("(\"%s\", \"%s\", %lu, %lu, \"%s\", \"%s\")\n", str1, str2, u1, u2, str3, str4);
926 }
927
928 void CALLBACK MACRO_ShortCut(LPCSTR str1, LPCSTR str2, LONG w, LONG l, LPCSTR str)
929 {
930     WINE_FIXME("(\"%s\", \"%s\", %lx, %lx, \"%s\")\n", str1, str2, w, l, str);
931 }
932
933 void CALLBACK MACRO_TCard(LONG u)
934 {
935     WINE_FIXME("(%lu)\n", u);
936 }
937
938 void CALLBACK MACRO_Test(LONG u)
939 {
940     WINE_FIXME("(%lu)\n", u);
941 }
942
943 BOOL CALLBACK MACRO_TestALink(LPCSTR str)
944 {
945     WINE_FIXME("(\"%s\")\n", str);
946     return FALSE;
947 }
948
949 BOOL CALLBACK MACRO_TestKLink(LPCSTR str)
950 {
951     WINE_FIXME("(\"%s\")\n", str);
952     return FALSE;
953 }
954
955 void CALLBACK MACRO_UncheckItem(LPCSTR str)
956 {
957     WINE_FIXME("(\"%s\")\n", str);
958 }
959
960 void CALLBACK MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
961 {
962     WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
963 }