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