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