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