Release 1.2-rc6.
[wine/gsoc-2012-control.git] / programs / winhlp32 / macro.c
blobca0fc8c54d290808d671128cc44327fa21e64170
1 /*
2 * Help Viewer
4 * Copyright 1996 Ulrich Schmid
5 * Copyright 2002, 2008 Eric Pouech
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.
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.
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
22 #define WIN32_LEAN_AND_MEAN
24 #include <stdio.h>
26 #include "windows.h"
27 #include "commdlg.h"
28 #include "shellapi.h"
29 #include "winhelp.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
35 /**************************************************/
36 /* Macro table */
37 /**************************************************/
38 struct MacroDesc {
39 const char* name;
40 const char* alias;
41 BOOL isBool;
42 const char* arguments;
43 void *fn;
46 static struct MacroDesc*MACRO_Loaded /* = NULL */;
47 static unsigned MACRO_NumLoaded /* = 0 */;
49 /******* helper functions *******/
51 static char* StrDup(const char* str)
53 char* dst;
54 dst=HeapAlloc(GetProcessHeap(),0,strlen(str)+1);
55 strcpy(dst, str);
56 return dst;
59 static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
61 WINHELP_BUTTON** b;
63 for (b = &win->first_button; *b; b = &(*b)->next)
64 if (!lstrcmpi(name, (*b)->lpszID)) break;
65 return b;
68 /******* some forward declarations *******/
69 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id);
71 /******* real macro implementation *******/
73 void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
75 WINHELP_WINDOW *win = MACRO_CurrentWindow();
76 WINHELP_BUTTON *button, **b;
77 LONG size;
78 LPSTR ptr;
80 WINE_TRACE("(\"%s\", \"%s\", %s)\n", id, name, macro);
82 size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;
84 button = HeapAlloc(GetProcessHeap(), 0, size);
85 if (!button) return;
87 button->next = 0;
88 button->hWnd = 0;
90 ptr = (char*)button + sizeof(WINHELP_BUTTON);
92 lstrcpy(ptr, id);
93 button->lpszID = ptr;
94 ptr += lstrlen(id) + 1;
96 lstrcpy(ptr, name);
97 button->lpszName = ptr;
98 ptr += lstrlen(name) + 1;
100 lstrcpy(ptr, macro);
101 button->lpszMacro = ptr;
103 button->wParam = WH_FIRST_BUTTON;
104 for (b = &win->first_button; *b; b = &(*b)->next)
105 button->wParam = max(button->wParam, (*b)->wParam + 1);
106 *b = button;
108 WINHELP_LayoutMainWindow(win);
111 static void CALLBACK MACRO_DestroyButton(LPCSTR str)
113 WINE_FIXME("(\"%s\")\n", str);
116 void CALLBACK MACRO_DisableButton(LPCSTR id)
118 WINHELP_BUTTON** b;
120 WINE_TRACE("(\"%s\")\n", id);
122 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
123 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
125 EnableWindow((*b)->hWnd, FALSE);
128 static void CALLBACK MACRO_EnableButton(LPCSTR id)
130 WINHELP_BUTTON** b;
132 WINE_TRACE("(\"%s\")\n", id);
134 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
135 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
137 EnableWindow((*b)->hWnd, TRUE);
140 void CALLBACK MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
142 HLPFILE* hlpfile;
144 WINE_TRACE("(\"%s\", \"%s\")\n", lpszPath, lpszWindow);
145 if ((hlpfile = WINHELP_LookupHelpFile(lpszPath)))
146 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, 0,
147 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
148 SW_NORMAL);
152 void CALLBACK MACRO_About(void)
154 WINE_FIXME("()\n");
157 static void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
159 WINE_FIXME("(%u, %u, \"%s\")\n", u1, u2, str);
162 static void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
164 WINE_FIXME("(\"%s\", %u, \"%s\")\n", str1, u, str2);
167 void CALLBACK MACRO_Annotate(void)
169 WINE_FIXME("()\n");
172 static void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
174 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);
177 static void CALLBACK MACRO_Back(void)
179 WINHELP_WINDOW* win = MACRO_CurrentWindow();
181 WINE_TRACE("()\n");
183 if (win && win->back.index >= 2)
184 WINHELP_CreateHelpWindow(&win->back.set[--win->back.index - 1], SW_SHOW, FALSE);
187 static void CALLBACK MACRO_BackFlush(void)
189 WINHELP_WINDOW* win = MACRO_CurrentWindow();
191 WINE_TRACE("()\n");
193 if (win) WINHELP_DeleteBackSet(win);
196 void CALLBACK MACRO_BookmarkDefine(void)
198 WINE_FIXME("()\n");
201 static void CALLBACK MACRO_BookmarkMore(void)
203 WINE_FIXME("()\n");
206 static void CALLBACK MACRO_BrowseButtons(void)
208 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
209 ULONG relative;
211 WINE_TRACE("()\n");
213 MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
214 MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
216 if (!HLPFILE_PageByOffset(page->file, page->browse_bwd, &relative))
217 MACRO_DisableButton("BTN_PREV");
218 if (!HLPFILE_PageByOffset(page->file, page->browse_fwd, &relative))
219 MACRO_DisableButton("BTN_NEXT");
222 static void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
224 WINHELP_WINDOW* win = MACRO_CurrentWindow();
225 WINHELP_BUTTON* button;
226 WINHELP_BUTTON** b;
227 LONG size;
228 LPSTR ptr;
230 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
232 b = MACRO_LookupButton(win, id);
233 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
235 size = sizeof(WINHELP_BUTTON) + lstrlen(id) +
236 lstrlen((*b)->lpszName) + lstrlen(macro) + 3;
238 button = HeapAlloc(GetProcessHeap(), 0, size);
239 if (!button) return;
241 button->next = (*b)->next;
242 button->hWnd = (*b)->hWnd;
243 button->wParam = (*b)->wParam;
245 ptr = (char*)button + sizeof(WINHELP_BUTTON);
247 lstrcpy(ptr, id);
248 button->lpszID = ptr;
249 ptr += lstrlen(id) + 1;
251 lstrcpy(ptr, (*b)->lpszName);
252 button->lpszName = ptr;
253 ptr += lstrlen((*b)->lpszName) + 1;
255 lstrcpy(ptr, macro);
256 button->lpszMacro = ptr;
258 *b = button;
260 WINHELP_LayoutMainWindow(win);
263 static void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
265 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
267 MACRO_ChangeButtonBinding(id, macro);
268 MACRO_EnableButton(id);
271 static void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
273 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
276 static void CALLBACK MACRO_CheckItem(LPCSTR str)
278 WINE_FIXME("(\"%s\")\n", str);
281 static void CALLBACK MACRO_CloseSecondarys(void)
283 WINHELP_WINDOW *win;
284 WINHELP_WINDOW *next;
286 WINE_TRACE("()\n");
287 for (win = Globals.win_list; win; win = next)
289 next = win->next;
290 if (lstrcmpi(win->info->name, "main"))
291 WINHELP_ReleaseWindow(win);
295 static void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow)
297 WINHELP_WINDOW *win;
298 WINHELP_WINDOW *next;
300 WINE_TRACE("(\"%s\")\n", lpszWindow);
302 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
304 for (win = Globals.win_list; win; win = next)
306 next = win->next;
307 if (!lstrcmpi(win->info->name, lpszWindow))
308 WINHELP_ReleaseWindow(win);
312 static void CALLBACK MACRO_Compare(LPCSTR str)
314 WINE_FIXME("(\"%s\")\n", str);
317 static void CALLBACK MACRO_Contents(void)
319 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
321 WINE_TRACE("()\n");
323 if (page)
324 MACRO_JumpContents(page->file->lpszPath, NULL);
327 static void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
329 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
332 void CALLBACK MACRO_CopyDialog(void)
334 WINE_FIXME("()\n");
337 static void CALLBACK MACRO_CopyTopic(void)
339 WINE_FIXME("()\n");
342 static void CALLBACK MACRO_DeleteItem(LPCSTR str)
344 WINE_FIXME("(\"%s\")\n", str);
347 static void CALLBACK MACRO_DeleteMark(LPCSTR str)
349 WINE_FIXME("(\"%s\")\n", str);
352 static void CALLBACK MACRO_DisableItem(LPCSTR str)
354 WINE_FIXME("(\"%s\")\n", str);
357 static void CALLBACK MACRO_EnableItem(LPCSTR str)
359 WINE_FIXME("(\"%s\")\n", str);
362 static void CALLBACK MACRO_EndMPrint(void)
364 WINE_FIXME("()\n");
367 static void CALLBACK MACRO_ExecFile(LPCSTR pgm, LPCSTR args, LONG cmd_show, LPCSTR topic)
369 HINSTANCE ret;
371 WINE_TRACE("(%s, %s, %u, %s)\n",
372 wine_dbgstr_a(pgm), wine_dbgstr_a(args), cmd_show, wine_dbgstr_a(topic));
374 ret = ShellExecuteA(Globals.active_win ? Globals.active_win->hMainWnd : NULL, "open",
375 pgm, args, ".", cmd_show);
376 if ((DWORD_PTR)ret < 32)
378 WINE_WARN("Failed with %p\n", ret);
379 if (topic) MACRO_JumpID(NULL, topic);
383 static void CALLBACK MACRO_ExecProgram(LPCSTR str, LONG u)
385 WINE_FIXME("(\"%s\", %u)\n", str, u);
388 void CALLBACK MACRO_Exit(void)
390 WINE_TRACE("()\n");
392 while (Globals.win_list)
393 WINHELP_ReleaseWindow(Globals.win_list);
396 static void CALLBACK MACRO_ExtAbleItem(LPCSTR str, LONG u)
398 WINE_FIXME("(\"%s\", %u)\n", str, u);
401 static void CALLBACK MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
403 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, str4, u1, u2);
406 static void CALLBACK MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
408 WINE_FIXME("(\"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, u1, u2);
411 static BOOL CALLBACK MACRO_FileExist(LPCSTR str)
413 WINE_TRACE("(\"%s\")\n", str);
414 return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES;
417 void CALLBACK MACRO_FileOpen(void)
419 char szFile[MAX_PATH];
421 if (WINHELP_GetOpenFileName(szFile, MAX_PATH))
423 MACRO_JumpContents(szFile, "main");
427 static void CALLBACK MACRO_Find(void)
429 WINE_FIXME("()\n");
432 static void CALLBACK MACRO_Finder(void)
434 WINHELP_CreateIndexWindow(FALSE);
437 static void CALLBACK MACRO_FloatingMenu(void)
439 WINE_FIXME("()\n");
442 static void CALLBACK MACRO_Flush(void)
444 WINE_FIXME("()\n");
447 static void CALLBACK MACRO_FocusWindow(LPCSTR lpszWindow)
449 WINHELP_WINDOW *win;
451 WINE_TRACE("(\"%s\")\n", lpszWindow);
453 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
455 for (win = Globals.win_list; win; win = win->next)
456 if (!lstrcmpi(win->info->name, lpszWindow))
457 SetFocus(win->hMainWnd);
460 static void CALLBACK MACRO_Generate(LPCSTR str, LONG w, LONG l)
462 WINE_FIXME("(\"%s\", %x, %x)\n", str, w, l);
465 static void CALLBACK MACRO_GotoMark(LPCSTR str)
467 WINE_FIXME("(\"%s\")\n", str);
470 void CALLBACK MACRO_HelpOn(void)
472 WINHELP_WINDOW *win = MACRO_CurrentWindow();
473 LPCSTR file = NULL;
475 WINE_TRACE("()\n");
476 if (win && win->page && win->page->file)
477 file = win->page->file->help_on_file;
479 if (!file)
480 file = (Globals.wVersion > 4) ? "winhlp32.hlp" : "winhelp.hlp";
482 MACRO_JumpContents(file, NULL);
485 void CALLBACK MACRO_HelpOnTop(void)
487 WINE_FIXME("()\n");
490 void CALLBACK MACRO_History(void)
492 WINE_TRACE("()\n");
494 if (Globals.active_win && !Globals.active_win->hHistoryWnd)
496 HWND hWnd = CreateWindow(HISTORY_WIN_CLASS_NAME, "History", WS_OVERLAPPEDWINDOW,
497 0, 0, 0, 0, 0, 0, Globals.hInstance, Globals.active_win);
498 ShowWindow(hWnd, SW_NORMAL);
502 static void CALLBACK MACRO_IfThen(BOOL b, LPCSTR t)
504 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
507 static void CALLBACK MACRO_IfThenElse(BOOL b, LPCSTR t, LPCSTR f)
509 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
510 else MACRO_ExecuteMacro(MACRO_CurrentWindow(), f);
513 static BOOL CALLBACK MACRO_InitMPrint(void)
515 WINE_FIXME("()\n");
516 return FALSE;
519 static void CALLBACK MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
521 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u)\n", str1, str2, str3, str4, u);
524 static void CALLBACK MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
526 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
529 static BOOL CALLBACK MACRO_IsBook(void)
531 WINE_TRACE("()\n");
532 return Globals.isBook;
535 static BOOL CALLBACK MACRO_IsMark(LPCSTR str)
537 WINE_FIXME("(\"%s\")\n", str);
538 return FALSE;
541 static BOOL CALLBACK MACRO_IsNotMark(LPCSTR str)
543 WINE_FIXME("(\"%s\")\n", str);
544 return TRUE;
547 void CALLBACK MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
549 HLPFILE* hlpfile;
551 WINE_TRACE("(\"%s\", \"%s\", %d)\n", lpszPath, lpszWindow, context);
552 hlpfile = WINHELP_LookupHelpFile(lpszPath);
553 /* Some madness: what user calls 'context', hlpfile calls 'map' */
554 WINHELP_OpenHelpWindow(HLPFILE_PageByMap, hlpfile, context,
555 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
556 SW_NORMAL);
559 void CALLBACK MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
561 HLPFILE* hlpfile;
563 WINE_TRACE("(\"%s\", \"%s\", %u)\n", lpszPath, lpszWindow, lHash);
564 if (!lpszPath || !lpszPath[0])
565 hlpfile = MACRO_CurrentWindow()->page->file;
566 else
567 hlpfile = WINHELP_LookupHelpFile(lpszPath);
568 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
569 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
570 SW_NORMAL);
573 static void CALLBACK MACRO_JumpHelpOn(void)
575 WINE_FIXME("()\n");
578 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id)
580 LPSTR ptr;
582 WINE_TRACE("(\"%s\", \"%s\")\n", lpszPathWindow, topic_id);
583 if ((ptr = strchr(lpszPathWindow, '>')) != NULL)
585 LPSTR tmp;
586 size_t sz;
588 tmp = HeapAlloc(GetProcessHeap(), 0, strlen(lpszPathWindow) + 1);
589 if (tmp)
591 strcpy(tmp, lpszPathWindow);
592 tmp[ptr - lpszPathWindow] = '\0';
593 ptr += tmp - lpszPathWindow; /* ptr now points to '>' in tmp buffer */
594 /* in some cases, we have a trailing space that we need to get rid of */
595 /* FIXME: check if it has to be done in lexer rather than here */
596 for (sz = strlen(ptr + 1); sz >= 1 && ptr[sz] == ' '; sz--) ptr[sz] = '\0';
597 MACRO_JumpHash(tmp, ptr + 1, HLPFILE_Hash(topic_id));
598 HeapFree(GetProcessHeap(), 0, tmp);
601 else
602 MACRO_JumpHash(lpszPathWindow, NULL, HLPFILE_Hash(topic_id));
605 /* FIXME: this macros is wrong
606 * it should only contain 2 strings, path & window are coded as path>window
608 static void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
610 WINE_FIXME("(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, keyword);
613 static void CALLBACK MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
615 WINE_FIXME("(\"%s\", %u, \"%s\", \"%s\")\n", str1, u, str2, str3);
618 static void CALLBACK MACRO_Menu(void)
620 WINE_FIXME("()\n");
623 static void CALLBACK MACRO_MPrintHash(LONG u)
625 WINE_FIXME("(%u)\n", u);
628 static void CALLBACK MACRO_MPrintID(LPCSTR str)
630 WINE_FIXME("(\"%s\")\n", str);
633 static void CALLBACK MACRO_Next(void)
635 WINHELP_WNDPAGE wp;
637 WINE_TRACE("()\n");
638 wp.page = MACRO_CurrentWindow()->page;
639 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_fwd, &wp.relative);
640 if (wp.page)
642 wp.page->file->wRefCount++;
643 wp.wininfo = MACRO_CurrentWindow()->info;
644 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
648 static void CALLBACK MACRO_NoShow(void)
650 WINE_FIXME("()\n");
653 void CALLBACK MACRO_PopupContext(LPCSTR str, LONG u)
655 WINE_FIXME("(\"%s\", %u)\n", str, u);
658 static void CALLBACK MACRO_PopupHash(LPCSTR str, LONG u)
660 WINE_FIXME("(\"%s\", %u)\n", str, u);
663 static void CALLBACK MACRO_PopupId(LPCSTR str1, LPCSTR str2)
665 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
668 static void CALLBACK MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
670 WINE_FIXME("(%i, %i, %u, %u, %u, \"%s\")\n", i1, i2, u1, u2, u3, str);
673 static void CALLBACK MACRO_Prev(void)
675 WINHELP_WNDPAGE wp;
677 WINE_TRACE("()\n");
678 wp.page = MACRO_CurrentWindow()->page;
679 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_bwd, &wp.relative);
680 if (wp.page)
682 wp.page->file->wRefCount++;
683 wp.wininfo = MACRO_CurrentWindow()->info;
684 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
688 void CALLBACK MACRO_Print(void)
690 PRINTDLG printer;
692 WINE_TRACE("()\n");
694 printer.lStructSize = sizeof(printer);
695 printer.hwndOwner = MACRO_CurrentWindow()->hMainWnd;
696 printer.hInstance = Globals.hInstance;
697 printer.hDevMode = 0;
698 printer.hDevNames = 0;
699 printer.hDC = 0;
700 printer.Flags = 0;
701 printer.nFromPage = 0;
702 printer.nToPage = 0;
703 printer.nMinPage = 0;
704 printer.nMaxPage = 0;
705 printer.nCopies = 0;
706 printer.lCustData = 0;
707 printer.lpfnPrintHook = 0;
708 printer.lpfnSetupHook = 0;
709 printer.lpPrintTemplateName = 0;
710 printer.lpSetupTemplateName = 0;
711 printer.hPrintTemplate = 0;
712 printer.hSetupTemplate = 0;
714 if (PrintDlgA(&printer)) {
715 WINE_FIXME("Print()\n");
719 void CALLBACK MACRO_PrinterSetup(void)
721 WINE_FIXME("()\n");
724 static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR args)
726 void *fn = NULL;
727 int size;
728 WINHELP_DLL* dll;
730 WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", dll_name, proc, args);
732 /* FIXME: are the registered DLLs global or linked to the current file ???
733 * We assume globals (as we did for macros, but is this really the case ???)
735 for (dll = Globals.dlls; dll; dll = dll->next)
737 if (!strcmp(dll->name, dll_name)) break;
739 if (!dll)
741 HANDLE hLib = LoadLibrary(dll_name);
743 /* FIXME: the library will not be unloaded until exit of program
744 * We don't send the DW_TERM message
746 WINE_TRACE("Loading %s\n", dll_name);
747 /* FIXME: should look in the directory where current hlpfile
748 * is loaded from
750 if (hLib == NULL)
752 /* FIXME: internationalisation for error messages */
753 WINE_FIXME("Cannot find dll %s\n", dll_name);
755 else if ((dll = HeapAlloc(GetProcessHeap(), 0, sizeof(*dll))))
757 dll->hLib = hLib;
758 dll->name = StrDup(dll_name); /* FIXME: never freed */
759 dll->next = Globals.dlls;
760 Globals.dlls = dll;
761 dll->handler = (WINHELP_LDLLHandler)GetProcAddress(dll->hLib, "LDLLHandler");
762 dll->class = dll->handler ? (dll->handler)(DW_WHATMSG, 0, 0) : DC_NOMSG;
763 WINE_TRACE("Got class %x for DLL %s\n", dll->class, dll_name);
764 if (dll->class & DC_INITTERM) dll->handler(DW_INIT, 0, 0);
765 if (dll->class & DC_CALLBACKS) dll->handler(DW_CALLBACKS, (LONG_PTR)&Callbacks, 0);
767 else WINE_WARN("OOM\n");
769 if (dll && !(fn = GetProcAddress(dll->hLib, proc)))
771 /* FIXME: internationalisation for error messages */
772 WINE_FIXME("Cannot find proc %s in dll %s\n", dll_name, proc);
775 size = ++MACRO_NumLoaded * sizeof(struct MacroDesc);
776 if (!MACRO_Loaded) MACRO_Loaded = HeapAlloc(GetProcessHeap(), 0, size);
777 else MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, size);
778 MACRO_Loaded[MACRO_NumLoaded - 1].name = StrDup(proc); /* FIXME: never freed */
779 MACRO_Loaded[MACRO_NumLoaded - 1].alias = NULL;
780 MACRO_Loaded[MACRO_NumLoaded - 1].isBool = 0;
781 MACRO_Loaded[MACRO_NumLoaded - 1].arguments = StrDup(args); /* FIXME: never freed */
782 MACRO_Loaded[MACRO_NumLoaded - 1].fn = fn;
783 WINE_TRACE("Added %s(%s) at %p\n", proc, args, fn);
786 static void CALLBACK MACRO_RemoveAccelerator(LONG u1, LONG u2)
788 WINE_FIXME("(%u, %u)\n", u1, u2);
791 static void CALLBACK MACRO_ResetMenu(void)
793 WINE_FIXME("()\n");
796 static void CALLBACK MACRO_SaveMark(LPCSTR str)
798 WINE_FIXME("(\"%s\")\n", str);
801 static void CALLBACK MACRO_Search(void)
803 WINHELP_CreateIndexWindow(TRUE);
806 void CALLBACK MACRO_SetContents(LPCSTR str, LONG u)
808 WINE_FIXME("(\"%s\", %u)\n", str, u);
811 static void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
813 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
815 WINE_TRACE("(\"%s\")\n", str);
817 HeapFree(GetProcessHeap(), 0, page->file->help_on_file);
818 page->file->help_on_file = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
819 if (page->file->help_on_file)
820 strcpy(page->file->help_on_file, str);
823 static void CALLBACK MACRO_SetPopupColor(LONG r, LONG g, LONG b)
825 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
827 WINE_TRACE("(%x, %x, %x)\n", r, g, b);
828 page->file->has_popup_color = TRUE;
829 page->file->popup_color = RGB(r, g, b);
832 static void CALLBACK MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
834 WINE_FIXME("(\"%s\", \"%s\", %u, %u, \"%s\", \"%s\")\n", str1, str2, u1, u2, str3, str4);
837 static void CALLBACK MACRO_ShortCut(LPCSTR str1, LPCSTR str2, LONG w, LONG l, LPCSTR str)
839 WINE_FIXME("(\"%s\", \"%s\", %x, %x, \"%s\")\n", str1, str2, w, l, str);
842 static void CALLBACK MACRO_TCard(LONG u)
844 WINE_FIXME("(%u)\n", u);
847 static void CALLBACK MACRO_Test(LONG u)
849 WINE_FIXME("(%u)\n", u);
852 static BOOL CALLBACK MACRO_TestALink(LPCSTR str)
854 WINE_FIXME("(\"%s\")\n", str);
855 return FALSE;
858 static BOOL CALLBACK MACRO_TestKLink(LPCSTR str)
860 WINE_FIXME("(\"%s\")\n", str);
861 return FALSE;
864 static void CALLBACK MACRO_UncheckItem(LPCSTR str)
866 WINE_FIXME("(\"%s\")\n", str);
869 static void CALLBACK MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
871 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
875 /**************************************************/
876 /* Macro table */
877 /**************************************************/
879 /* types:
880 * U: 32 bit unsigned int
881 * I: 32 bit signed int
882 * S: string
883 * v: unknown (32 bit entity)
886 static struct MacroDesc MACRO_Builtins[] = {
887 {"About", NULL, 0, "", MACRO_About},
888 {"AddAccelerator", "AA", 0, "UUS", MACRO_AddAccelerator},
889 {"ALink", "AL", 0, "SUS", MACRO_ALink},
890 {"Annotate", NULL, 0, "", MACRO_Annotate},
891 {"AppendItem", NULL, 0, "SSSS", MACRO_AppendItem},
892 {"Back", NULL, 0, "", MACRO_Back},
893 {"BackFlush", "BF", 0, "", MACRO_BackFlush},
894 {"BookmarkDefine", NULL, 0, "", MACRO_BookmarkDefine},
895 {"BookmarkMore", NULL, 0, "", MACRO_BookmarkMore},
896 {"BrowseButtons", NULL, 0, "", MACRO_BrowseButtons},
897 {"ChangeButtonBinding", "CBB",0, "SS", MACRO_ChangeButtonBinding},
898 {"ChangeEnable", "CE", 0, "SS", MACRO_ChangeEnable},
899 {"ChangeItemBinding", "CIB",0, "SS", MACRO_ChangeItemBinding},
900 {"CheckItem", "CI", 0, "S", MACRO_CheckItem},
901 {"CloseSecondarys", "CS", 0, "", MACRO_CloseSecondarys},
902 {"CloseWindow", "CW", 0, "S", MACRO_CloseWindow},
903 {"Compare", NULL, 0, "S", MACRO_Compare},
904 {"Contents", NULL, 0, "", MACRO_Contents},
905 {"ControlPanel", NULL, 0, "SSU", MACRO_ControlPanel},
906 {"CopyDialog", NULL, 0, "", MACRO_CopyDialog},
907 {"CopyTopic", "CT", 0, "", MACRO_CopyTopic},
908 {"CreateButton", "CB", 0, "SSS", MACRO_CreateButton},
909 {"DeleteItem", NULL, 0, "S", MACRO_DeleteItem},
910 {"DeleteMark", NULL, 0, "S", MACRO_DeleteMark},
911 {"DestroyButton", NULL, 0, "S", MACRO_DestroyButton},
912 {"DisableButton", "DB", 0, "S", MACRO_DisableButton},
913 {"DisableItem", "DI", 0, "S", MACRO_DisableItem},
914 {"EnableButton", "EB", 0, "S", MACRO_EnableButton},
915 {"EnableItem", "EI", 0, "S", MACRO_EnableItem},
916 {"EndMPrint", NULL, 0, "", MACRO_EndMPrint},
917 {"ExecFile", "EF", 0, "SSUS", MACRO_ExecFile},
918 {"ExecProgram", "EP", 0, "SU", MACRO_ExecProgram},
919 {"Exit", NULL, 0, "", MACRO_Exit},
920 {"ExtAbleItem", NULL, 0, "SU", MACRO_ExtAbleItem},
921 {"ExtInsertItem", NULL, 0, "SSSSUU", MACRO_ExtInsertItem},
922 {"ExtInsertMenu", NULL, 0, "SSSUU", MACRO_ExtInsertMenu},
923 {"FileExist", "FE", 1, "S", MACRO_FileExist},
924 {"FileOpen", "FO", 0, "", MACRO_FileOpen},
925 {"Find", NULL, 0, "", MACRO_Find},
926 {"Finder", "FD", 0, "", MACRO_Finder},
927 {"FloatingMenu", NULL, 0, "", MACRO_FloatingMenu},
928 {"Flush", "FH", 0, "", MACRO_Flush},
929 {"FocusWindow", NULL, 0, "S", MACRO_FocusWindow},
930 {"Generate", NULL, 0, "SUU", MACRO_Generate},
931 {"GotoMark", NULL, 0, "S", MACRO_GotoMark},
932 {"HelpOn", NULL, 0, "", MACRO_HelpOn},
933 {"HelpOnTop", NULL, 0, "", MACRO_HelpOnTop},
934 {"History", NULL, 0, "", MACRO_History},
935 {"InitMPrint", NULL, 1, "", MACRO_InitMPrint},
936 {"InsertItem", NULL, 0, "SSSSU", MACRO_InsertItem},
937 {"InsertMenu", NULL, 0, "SSU", MACRO_InsertMenu},
938 {"IfThen", "IF", 0, "BS", MACRO_IfThen},
939 {"IfThenElse", "IE", 0, "BSS", MACRO_IfThenElse},
940 {"IsBook", NULL, 1, "", MACRO_IsBook},
941 {"IsMark", NULL, 1, "S", MACRO_IsMark},
942 {"IsNotMark", "NM", 1, "S", MACRO_IsNotMark},
943 {"JumpContents", NULL, 0, "SS", MACRO_JumpContents},
944 {"JumpContext", "JC", 0, "SSU", MACRO_JumpContext},
945 {"JumpHash", "JH", 0, "SSU", MACRO_JumpHash},
946 {"JumpHelpOn", NULL, 0, "", MACRO_JumpHelpOn},
947 {"JumpID", "JI", 0, "SS", MACRO_JumpID},
948 {"JumpKeyword", "JK", 0, "SSS", MACRO_JumpKeyword},
949 {"KLink", "KL", 0, "SUSS", MACRO_KLink},
950 {"Menu", "MU", 0, "", MACRO_Menu},
951 {"MPrintHash", NULL, 0, "U", MACRO_MPrintHash},
952 {"MPrintID", NULL, 0, "S", MACRO_MPrintID},
953 {"Next", NULL, 0, "", MACRO_Next},
954 {"NoShow", "NS", 0, "", MACRO_NoShow},
955 {"PopupContext", "PC", 0, "SU", MACRO_PopupContext},
956 {"PopupHash", NULL, 0, "SU", MACRO_PopupHash},
957 {"PopupId", "PI", 0, "SS", MACRO_PopupId},
958 {"PositionWindow", "PW", 0, "IIUUUS", MACRO_PositionWindow},
959 {"Prev", NULL, 0, "", MACRO_Prev},
960 {"Print", NULL, 0, "", MACRO_Print},
961 {"PrinterSetup", NULL, 0, "", MACRO_PrinterSetup},
962 {"RegisterRoutine", "RR", 0, "SSS", MACRO_RegisterRoutine},
963 {"RemoveAccelerator", "RA", 0, "UU", MACRO_RemoveAccelerator},
964 {"ResetMenu", NULL, 0, "", MACRO_ResetMenu},
965 {"SaveMark", NULL, 0, "S", MACRO_SaveMark},
966 {"Search", NULL, 0, "", MACRO_Search},
967 {"SetContents", NULL, 0, "SU", MACRO_SetContents},
968 {"SetHelpOnFile", NULL, 0, "S", MACRO_SetHelpOnFile},
969 {"SetPopupColor", "SPC",0, "UUU", MACRO_SetPopupColor},
970 {"ShellExecute", "SE", 0, "SSUUSS", MACRO_ShellExecute},
971 {"ShortCut", "SH", 0, "SSUUS", MACRO_ShortCut},
972 {"TCard", NULL, 0, "U", MACRO_TCard},
973 {"Test", NULL, 0, "U", MACRO_Test},
974 {"TestALink", NULL, 1, "S", MACRO_TestALink},
975 {"TestKLink", NULL, 1, "S", MACRO_TestKLink},
976 {"UncheckItem", "UI", 0, "S", MACRO_UncheckItem},
977 {"UpdateWindow", "UW", 0, "SS", MACRO_UpdateWindow},
978 {NULL, NULL, 0, NULL, NULL}
981 static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len)
983 struct MacroDesc* md;
985 for (md = start; md->name && len != 0; md++, len--)
987 if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))
989 lr->proto = md->arguments;
990 lr->function = md->fn;
991 return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;
994 return EMPTY;
997 int MACRO_Lookup(const char* name, struct lexret* lr)
999 int ret;
1001 if ((ret = MACRO_DoLookUp(MACRO_Builtins, name, lr, -1)) != EMPTY)
1002 return ret;
1003 if (MACRO_Loaded && (ret = MACRO_DoLookUp(MACRO_Loaded, name, lr, MACRO_NumLoaded)) != EMPTY)
1004 return ret;
1006 lr->string = name;
1007 return IDENTIFIER;