winmm: dwBytesRecorded controls how much is played, not dwBufferLength.
[wine/hramrach.git] / programs / winhlp32 / macro.c
blob0e48ca8643ad78ed94e1323fd6681dfdb6a8c1c7
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 "winhelp.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
34 /**************************************************/
35 /* Macro table */
36 /**************************************************/
37 struct MacroDesc {
38 const char* name;
39 const char* alias;
40 BOOL isBool;
41 const char* arguments;
42 void *fn;
45 static struct MacroDesc*MACRO_Loaded /* = NULL */;
46 static unsigned MACRO_NumLoaded /* = 0 */;
48 /******* helper functions *******/
50 static char* StrDup(const char* str)
52 char* dst;
53 dst=HeapAlloc(GetProcessHeap(),0,strlen(str)+1);
54 strcpy(dst, str);
55 return dst;
58 static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
60 WINHELP_BUTTON** b;
62 for (b = &win->first_button; *b; b = &(*b)->next)
63 if (!lstrcmpi(name, (*b)->lpszID)) break;
64 return b;
67 /******* real macro implementation *******/
69 void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
71 WINHELP_WINDOW *win = MACRO_CurrentWindow();
72 WINHELP_BUTTON *button, **b;
73 LONG size;
74 LPSTR ptr;
76 WINE_TRACE("(\"%s\", \"%s\", %s)\n", id, name, macro);
78 size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;
80 button = HeapAlloc(GetProcessHeap(), 0, size);
81 if (!button) return;
83 button->next = 0;
84 button->hWnd = 0;
86 ptr = (char*)button + sizeof(WINHELP_BUTTON);
88 lstrcpy(ptr, id);
89 button->lpszID = ptr;
90 ptr += lstrlen(id) + 1;
92 lstrcpy(ptr, name);
93 button->lpszName = ptr;
94 ptr += lstrlen(name) + 1;
96 lstrcpy(ptr, macro);
97 button->lpszMacro = ptr;
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;
104 WINHELP_LayoutMainWindow(win);
107 static void CALLBACK MACRO_DestroyButton(LPCSTR str)
109 WINE_FIXME("(\"%s\")\n", str);
112 void CALLBACK MACRO_DisableButton(LPCSTR id)
114 WINHELP_BUTTON** b;
116 WINE_TRACE("(\"%s\")\n", id);
118 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
119 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
121 EnableWindow((*b)->hWnd, FALSE);
124 static void CALLBACK MACRO_EnableButton(LPCSTR id)
126 WINHELP_BUTTON** b;
128 WINE_TRACE("(\"%s\")\n", id);
130 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
131 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
133 EnableWindow((*b)->hWnd, TRUE);
136 void CALLBACK MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
138 HLPFILE* hlpfile;
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);
148 void CALLBACK MACRO_About(void)
150 WINE_FIXME("()\n");
153 static void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
155 WINE_FIXME("(%u, %u, \"%s\")\n", u1, u2, str);
158 static void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
160 WINE_FIXME("(\"%s\", %u, \"%s\")\n", str1, u, str2);
163 void CALLBACK MACRO_Annotate(void)
165 WINE_FIXME("()\n");
168 static void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
170 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);
173 static void CALLBACK MACRO_Back(void)
175 WINHELP_WINDOW* win = MACRO_CurrentWindow();
177 WINE_TRACE("()\n");
179 if (win && win->back.index >= 2)
180 WINHELP_CreateHelpWindow(&win->back.set[--win->back.index - 1], SW_SHOW, FALSE);
183 static void CALLBACK MACRO_BackFlush(void)
185 WINHELP_WINDOW* win = MACRO_CurrentWindow();
187 WINE_TRACE("()\n");
189 if (win) WINHELP_DeleteBackSet(win);
192 void CALLBACK MACRO_BookmarkDefine(void)
194 WINE_FIXME("()\n");
197 static void CALLBACK MACRO_BookmarkMore(void)
199 WINE_FIXME("()\n");
202 static void CALLBACK MACRO_BrowseButtons(void)
204 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
205 ULONG relative;
207 WINE_TRACE("()\n");
209 MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
210 MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
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");
218 static void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
220 WINHELP_WINDOW* win = MACRO_CurrentWindow();
221 WINHELP_BUTTON* button;
222 WINHELP_BUTTON** b;
223 LONG size;
224 LPSTR ptr;
226 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
228 b = MACRO_LookupButton(win, id);
229 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
231 size = sizeof(WINHELP_BUTTON) + lstrlen(id) +
232 lstrlen((*b)->lpszName) + lstrlen(macro) + 3;
234 button = HeapAlloc(GetProcessHeap(), 0, size);
235 if (!button) return;
237 button->next = (*b)->next;
238 button->hWnd = (*b)->hWnd;
239 button->wParam = (*b)->wParam;
241 ptr = (char*)button + sizeof(WINHELP_BUTTON);
243 lstrcpy(ptr, id);
244 button->lpszID = ptr;
245 ptr += lstrlen(id) + 1;
247 lstrcpy(ptr, (*b)->lpszName);
248 button->lpszName = ptr;
249 ptr += lstrlen((*b)->lpszName) + 1;
251 lstrcpy(ptr, macro);
252 button->lpszMacro = ptr;
254 *b = button;
256 WINHELP_LayoutMainWindow(win);
259 static void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
261 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
263 MACRO_ChangeButtonBinding(id, macro);
264 MACRO_EnableButton(id);
267 static void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
269 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
272 static void CALLBACK MACRO_CheckItem(LPCSTR str)
274 WINE_FIXME("(\"%s\")\n", str);
277 static void CALLBACK MACRO_CloseSecondarys(void)
279 WINHELP_WINDOW *win;
281 WINE_TRACE("()\n");
282 for (win = Globals.win_list; win; win = win->next)
283 if (lstrcmpi(win->info->name, "main"))
284 WINHELP_ReleaseWindow(win);
287 static void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow)
289 WINHELP_WINDOW *win;
291 WINE_TRACE("(\"%s\")\n", lpszWindow);
293 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
295 for (win = Globals.win_list; win; win = win->next)
296 if (!lstrcmpi(win->info->name, lpszWindow))
297 WINHELP_ReleaseWindow(win);
300 static void CALLBACK MACRO_Compare(LPCSTR str)
302 WINE_FIXME("(\"%s\")\n", str);
305 static void CALLBACK MACRO_Contents(void)
307 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
309 WINE_TRACE("()\n");
311 if (page)
312 MACRO_JumpContents(page->file->lpszPath, NULL);
315 static void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
317 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
320 void CALLBACK MACRO_CopyDialog(void)
322 WINE_FIXME("()\n");
325 static void CALLBACK MACRO_CopyTopic(void)
327 WINE_FIXME("()\n");
330 static void CALLBACK MACRO_DeleteItem(LPCSTR str)
332 WINE_FIXME("(\"%s\")\n", str);
335 static void CALLBACK MACRO_DeleteMark(LPCSTR str)
337 WINE_FIXME("(\"%s\")\n", str);
340 static void CALLBACK MACRO_DisableItem(LPCSTR str)
342 WINE_FIXME("(\"%s\")\n", str);
345 static void CALLBACK MACRO_EnableItem(LPCSTR str)
347 WINE_FIXME("(\"%s\")\n", str);
350 static void CALLBACK MACRO_EndMPrint(void)
352 WINE_FIXME("()\n");
355 static void CALLBACK MACRO_ExecFile(LPCSTR str1, LPCSTR str2, LONG u, LPCSTR str3)
357 WINE_FIXME("(\"%s\", \"%s\", %u, \"%s\")\n", str1, str2, u, str3);
360 static void CALLBACK MACRO_ExecProgram(LPCSTR str, LONG u)
362 WINE_FIXME("(\"%s\", %u)\n", str, u);
365 void CALLBACK MACRO_Exit(void)
367 WINE_TRACE("()\n");
369 while (Globals.win_list)
370 WINHELP_ReleaseWindow(Globals.win_list);
373 static void CALLBACK MACRO_ExtAbleItem(LPCSTR str, LONG u)
375 WINE_FIXME("(\"%s\", %u)\n", str, u);
378 static void CALLBACK MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
380 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, str4, u1, u2);
383 static void CALLBACK MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
385 WINE_FIXME("(\"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, u1, u2);
388 static BOOL CALLBACK MACRO_FileExist(LPCSTR str)
390 WINE_TRACE("(\"%s\")\n", str);
391 return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES;
394 void CALLBACK MACRO_FileOpen(void)
396 char szFile[MAX_PATH];
398 if (WINHELP_GetOpenFileName(szFile, MAX_PATH))
400 MACRO_JumpContents(szFile, "main");
404 static void CALLBACK MACRO_Find(void)
406 WINE_FIXME("()\n");
409 static void CALLBACK MACRO_Finder(void)
411 WINHELP_CreateIndexWindow(FALSE);
414 static void CALLBACK MACRO_FloatingMenu(void)
416 WINE_FIXME("()\n");
419 static void CALLBACK MACRO_Flush(void)
421 WINE_FIXME("()\n");
424 static void CALLBACK MACRO_FocusWindow(LPCSTR lpszWindow)
426 WINHELP_WINDOW *win;
428 WINE_TRACE("(\"%s\")\n", lpszWindow);
430 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
432 for (win = Globals.win_list; win; win = win->next)
433 if (!lstrcmpi(win->info->name, lpszWindow))
434 SetFocus(win->hMainWnd);
437 static void CALLBACK MACRO_Generate(LPCSTR str, LONG w, LONG l)
439 WINE_FIXME("(\"%s\", %x, %x)\n", str, w, l);
442 static void CALLBACK MACRO_GotoMark(LPCSTR str)
444 WINE_FIXME("(\"%s\")\n", str);
447 void CALLBACK MACRO_HelpOn(void)
449 WINHELP_WINDOW *win = MACRO_CurrentWindow();
450 LPCSTR file = NULL;
452 WINE_TRACE("()\n");
453 if (win && win->page && win->page->file)
454 file = win->page->file->help_on_file;
456 if (!file)
457 file = (Globals.wVersion > 4) ? "winhlp32.hlp" : "winhelp.hlp";
459 MACRO_JumpContents(file, NULL);
462 void CALLBACK MACRO_HelpOnTop(void)
464 WINE_FIXME("()\n");
467 void CALLBACK MACRO_History(void)
469 WINE_TRACE("()\n");
471 if (Globals.active_win && !Globals.active_win->hHistoryWnd)
473 HWND hWnd = CreateWindow(HISTORY_WIN_CLASS_NAME, "History", WS_OVERLAPPEDWINDOW,
474 0, 0, 0, 0, 0, 0, Globals.hInstance, Globals.active_win);
475 ShowWindow(hWnd, SW_NORMAL);
479 static void CALLBACK MACRO_IfThen(BOOL b, LPCSTR t)
481 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
484 static void CALLBACK MACRO_IfThenElse(BOOL b, LPCSTR t, LPCSTR f)
486 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
487 else MACRO_ExecuteMacro(MACRO_CurrentWindow(), f);
490 static BOOL CALLBACK MACRO_InitMPrint(void)
492 WINE_FIXME("()\n");
493 return FALSE;
496 static void CALLBACK MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
498 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u)\n", str1, str2, str3, str4, u);
501 static void CALLBACK MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
503 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
506 static BOOL CALLBACK MACRO_IsBook(void)
508 WINE_TRACE("()\n");
509 return Globals.isBook;
512 static BOOL CALLBACK MACRO_IsMark(LPCSTR str)
514 WINE_FIXME("(\"%s\")\n", str);
515 return FALSE;
518 static BOOL CALLBACK MACRO_IsNotMark(LPCSTR str)
520 WINE_FIXME("(\"%s\")\n", str);
521 return TRUE;
524 void CALLBACK MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
526 HLPFILE* hlpfile;
528 WINE_TRACE("(\"%s\", \"%s\", %d)\n", lpszPath, lpszWindow, context);
529 hlpfile = WINHELP_LookupHelpFile(lpszPath);
530 /* Some madness: what user calls 'context', hlpfile calls 'map' */
531 WINHELP_OpenHelpWindow(HLPFILE_PageByMap, hlpfile, context,
532 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
533 SW_NORMAL);
536 void CALLBACK MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
538 HLPFILE* hlpfile;
540 WINE_TRACE("(\"%s\", \"%s\", %u)\n", lpszPath, lpszWindow, lHash);
541 if (!lpszPath || !lpszPath[0])
542 hlpfile = MACRO_CurrentWindow()->page->file;
543 else
544 hlpfile = WINHELP_LookupHelpFile(lpszPath);
545 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
546 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
547 SW_NORMAL);
550 static void CALLBACK MACRO_JumpHelpOn(void)
552 WINE_FIXME("()\n");
555 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id)
557 LPSTR ptr;
559 WINE_TRACE("(\"%s\", \"%s\")\n", lpszPathWindow, topic_id);
560 if ((ptr = strchr(lpszPathWindow, '>')) != NULL)
562 LPSTR tmp;
563 size_t sz = ptr - lpszPathWindow;
565 tmp = HeapAlloc(GetProcessHeap(), 0, sz + 1);
566 if (tmp)
568 memcpy(tmp, lpszPathWindow, sz);
569 tmp[sz] = '\0';
570 MACRO_JumpHash(tmp, ptr + 1, HLPFILE_Hash(topic_id));
571 HeapFree(GetProcessHeap(), 0, tmp);
574 else
575 MACRO_JumpHash(lpszPathWindow, NULL, HLPFILE_Hash(topic_id));
578 /* FIXME: this macros is wrong
579 * it should only contain 2 strings, path & window are coded as path>window
581 static void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
583 WINE_FIXME("(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, keyword);
586 static void CALLBACK MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
588 WINE_FIXME("(\"%s\", %u, \"%s\", \"%s\")\n", str1, u, str2, str3);
591 static void CALLBACK MACRO_Menu(void)
593 WINE_FIXME("()\n");
596 static void CALLBACK MACRO_MPrintHash(LONG u)
598 WINE_FIXME("(%u)\n", u);
601 static void CALLBACK MACRO_MPrintID(LPCSTR str)
603 WINE_FIXME("(\"%s\")\n", str);
606 static void CALLBACK MACRO_Next(void)
608 WINHELP_WNDPAGE wp;
610 WINE_TRACE("()\n");
611 wp.page = MACRO_CurrentWindow()->page;
612 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_fwd, &wp.relative);
613 if (wp.page)
615 wp.page->file->wRefCount++;
616 wp.wininfo = MACRO_CurrentWindow()->info;
617 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
621 static void CALLBACK MACRO_NoShow(void)
623 WINE_FIXME("()\n");
626 void CALLBACK MACRO_PopupContext(LPCSTR str, LONG u)
628 WINE_FIXME("(\"%s\", %u)\n", str, u);
631 static void CALLBACK MACRO_PopupHash(LPCSTR str, LONG u)
633 WINE_FIXME("(\"%s\", %u)\n", str, u);
636 static void CALLBACK MACRO_PopupId(LPCSTR str1, LPCSTR str2)
638 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
641 static void CALLBACK MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
643 WINE_FIXME("(%i, %i, %u, %u, %u, \"%s\")\n", i1, i2, u1, u2, u3, str);
646 static void CALLBACK MACRO_Prev(void)
648 WINHELP_WNDPAGE wp;
650 WINE_TRACE("()\n");
651 wp.page = MACRO_CurrentWindow()->page;
652 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_bwd, &wp.relative);
653 if (wp.page)
655 wp.page->file->wRefCount++;
656 wp.wininfo = MACRO_CurrentWindow()->info;
657 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
661 void CALLBACK MACRO_Print(void)
663 PRINTDLG printer;
665 WINE_TRACE("()\n");
667 printer.lStructSize = sizeof(printer);
668 printer.hwndOwner = MACRO_CurrentWindow()->hMainWnd;
669 printer.hInstance = Globals.hInstance;
670 printer.hDevMode = 0;
671 printer.hDevNames = 0;
672 printer.hDC = 0;
673 printer.Flags = 0;
674 printer.nFromPage = 0;
675 printer.nToPage = 0;
676 printer.nMinPage = 0;
677 printer.nMaxPage = 0;
678 printer.nCopies = 0;
679 printer.lCustData = 0;
680 printer.lpfnPrintHook = 0;
681 printer.lpfnSetupHook = 0;
682 printer.lpPrintTemplateName = 0;
683 printer.lpSetupTemplateName = 0;
684 printer.hPrintTemplate = 0;
685 printer.hSetupTemplate = 0;
687 if (PrintDlgA(&printer)) {
688 WINE_FIXME("Print()\n");
692 void CALLBACK MACRO_PrinterSetup(void)
694 WINE_FIXME("()\n");
697 static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR args)
699 void *fn = NULL;
700 int size;
701 WINHELP_DLL* dll;
703 WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", dll_name, proc, args);
705 /* FIXME: are the registered DLLs global or linked to the current file ???
706 * We assume globals (as we did for macros, but is this really the case ???)
708 for (dll = Globals.dlls; dll; dll = dll->next)
710 if (!strcmp(dll->name, dll_name)) break;
712 if (!dll)
714 HANDLE hLib = LoadLibrary(dll_name);
716 /* FIXME: the library will not be unloaded until exit of program
717 * We don't send the DW_TERM message
719 WINE_TRACE("Loading %s\n", dll_name);
720 /* FIXME: should look in the directory where current hlpfile
721 * is loaded from
723 if (hLib == NULL)
725 /* FIXME: internationalisation for error messages */
726 WINE_FIXME("Cannot find dll %s\n", dll_name);
728 else if ((dll = HeapAlloc(GetProcessHeap(), 0, sizeof(*dll))))
730 dll->hLib = hLib;
731 dll->name = StrDup(dll_name); /* FIXME: never freed */
732 dll->next = Globals.dlls;
733 Globals.dlls = dll;
734 dll->handler = (WINHELP_LDLLHandler)GetProcAddress(dll->hLib, "LDLLHandler");
735 dll->class = dll->handler ? (dll->handler)(DW_WHATMSG, 0, 0) : DC_NOMSG;
736 WINE_TRACE("Got class %x for DLL %s\n", dll->class, dll_name);
737 if (dll->class & DC_INITTERM) dll->handler(DW_INIT, 0, 0);
738 if (dll->class & DC_CALLBACKS) dll->handler(DW_CALLBACKS, (LONG_PTR)&Callbacks, 0);
740 else WINE_WARN("OOM\n");
742 if (dll && !(fn = GetProcAddress(dll->hLib, proc)))
744 /* FIXME: internationalisation for error messages */
745 WINE_FIXME("Cannot find proc %s in dll %s\n", dll_name, proc);
748 size = ++MACRO_NumLoaded * sizeof(struct MacroDesc);
749 if (!MACRO_Loaded) MACRO_Loaded = HeapAlloc(GetProcessHeap(), 0, size);
750 else MACRO_Loaded = HeapReAlloc(GetProcessHeap(), 0, MACRO_Loaded, size);
751 MACRO_Loaded[MACRO_NumLoaded - 1].name = StrDup(proc); /* FIXME: never freed */
752 MACRO_Loaded[MACRO_NumLoaded - 1].alias = NULL;
753 MACRO_Loaded[MACRO_NumLoaded - 1].isBool = 0;
754 MACRO_Loaded[MACRO_NumLoaded - 1].arguments = StrDup(args); /* FIXME: never freed */
755 MACRO_Loaded[MACRO_NumLoaded - 1].fn = fn;
756 WINE_TRACE("Added %s(%s) at %p\n", proc, args, fn);
759 static void CALLBACK MACRO_RemoveAccelerator(LONG u1, LONG u2)
761 WINE_FIXME("(%u, %u)\n", u1, u2);
764 static void CALLBACK MACRO_ResetMenu(void)
766 WINE_FIXME("()\n");
769 static void CALLBACK MACRO_SaveMark(LPCSTR str)
771 WINE_FIXME("(\"%s\")\n", str);
774 static void CALLBACK MACRO_Search(void)
776 WINHELP_CreateIndexWindow(TRUE);
779 void CALLBACK MACRO_SetContents(LPCSTR str, LONG u)
781 WINE_FIXME("(\"%s\", %u)\n", str, u);
784 static void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
786 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
788 WINE_TRACE("(\"%s\")\n", str);
790 HeapFree(GetProcessHeap(), 0, page->file->help_on_file);
791 page->file->help_on_file = HeapAlloc(GetProcessHeap(), 0, strlen(str) + 1);
792 if (page->file->help_on_file)
793 strcpy(page->file->help_on_file, str);
796 static void CALLBACK MACRO_SetPopupColor(LONG r, LONG g, LONG b)
798 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
800 WINE_TRACE("(%x, %x, %x)\n", r, g, b);
801 page->file->has_popup_color = TRUE;
802 page->file->popup_color = RGB(r, g, b);
805 static void CALLBACK MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
807 WINE_FIXME("(\"%s\", \"%s\", %u, %u, \"%s\", \"%s\")\n", str1, str2, u1, u2, str3, str4);
810 static void CALLBACK MACRO_ShortCut(LPCSTR str1, LPCSTR str2, LONG w, LONG l, LPCSTR str)
812 WINE_FIXME("(\"%s\", \"%s\", %x, %x, \"%s\")\n", str1, str2, w, l, str);
815 static void CALLBACK MACRO_TCard(LONG u)
817 WINE_FIXME("(%u)\n", u);
820 static void CALLBACK MACRO_Test(LONG u)
822 WINE_FIXME("(%u)\n", u);
825 static BOOL CALLBACK MACRO_TestALink(LPCSTR str)
827 WINE_FIXME("(\"%s\")\n", str);
828 return FALSE;
831 static BOOL CALLBACK MACRO_TestKLink(LPCSTR str)
833 WINE_FIXME("(\"%s\")\n", str);
834 return FALSE;
837 static void CALLBACK MACRO_UncheckItem(LPCSTR str)
839 WINE_FIXME("(\"%s\")\n", str);
842 static void CALLBACK MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
844 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
848 /**************************************************/
849 /* Macro table */
850 /**************************************************/
852 /* types:
853 * U: 32 bit unsigned int
854 * I: 32 bit signed int
855 * S: string
856 * v: unknown (32 bit entity)
859 static struct MacroDesc MACRO_Builtins[] = {
860 {"About", NULL, 0, "", MACRO_About},
861 {"AddAccelerator", "AA", 0, "UUS", MACRO_AddAccelerator},
862 {"ALink", "AL", 0, "SUS", MACRO_ALink},
863 {"Annotate", NULL, 0, "", MACRO_Annotate},
864 {"AppendItem", NULL, 0, "SSSS", MACRO_AppendItem},
865 {"Back", NULL, 0, "", MACRO_Back},
866 {"BackFlush", "BF", 0, "", MACRO_BackFlush},
867 {"BookmarkDefine", NULL, 0, "", MACRO_BookmarkDefine},
868 {"BookmarkMore", NULL, 0, "", MACRO_BookmarkMore},
869 {"BrowseButtons", NULL, 0, "", MACRO_BrowseButtons},
870 {"ChangeButtonBinding", "CBB",0, "SS", MACRO_ChangeButtonBinding},
871 {"ChangeEnable", "CE", 0, "SS", MACRO_ChangeEnable},
872 {"ChangeItemBinding", "CIB",0, "SS", MACRO_ChangeItemBinding},
873 {"CheckItem", "CI", 0, "S", MACRO_CheckItem},
874 {"CloseSecondarys", "CS", 0, "", MACRO_CloseSecondarys},
875 {"CloseWindow", "CW", 0, "S", MACRO_CloseWindow},
876 {"Compare", NULL, 0, "S", MACRO_Compare},
877 {"Contents", NULL, 0, "", MACRO_Contents},
878 {"ControlPanel", NULL, 0, "SSU", MACRO_ControlPanel},
879 {"CopyDialog", NULL, 0, "", MACRO_CopyDialog},
880 {"CopyTopic", "CT", 0, "", MACRO_CopyTopic},
881 {"CreateButton", "CB", 0, "SSS", MACRO_CreateButton},
882 {"DeleteItem", NULL, 0, "S", MACRO_DeleteItem},
883 {"DeleteMark", NULL, 0, "S", MACRO_DeleteMark},
884 {"DestroyButton", NULL, 0, "S", MACRO_DestroyButton},
885 {"DisableButton", "DB", 0, "S", MACRO_DisableButton},
886 {"DisableItem", "DI", 0, "S", MACRO_DisableItem},
887 {"EnableButton", "EB", 0, "S", MACRO_EnableButton},
888 {"EnableItem", "EI", 0, "S", MACRO_EnableItem},
889 {"EndMPrint", NULL, 0, "", MACRO_EndMPrint},
890 {"ExecFile", "EF", 0, "SSUS", MACRO_ExecFile},
891 {"ExecProgram", "EP", 0, "SU", MACRO_ExecProgram},
892 {"Exit", NULL, 0, "", MACRO_Exit},
893 {"ExtAbleItem", NULL, 0, "SU", MACRO_ExtAbleItem},
894 {"ExtInsertItem", NULL, 0, "SSSSUU", MACRO_ExtInsertItem},
895 {"ExtInsertMenu", NULL, 0, "SSSUU", MACRO_ExtInsertMenu},
896 {"FileExist", "FE", 1, "S", MACRO_FileExist},
897 {"FileOpen", "FO", 0, "", MACRO_FileOpen},
898 {"Find", NULL, 0, "", MACRO_Find},
899 {"Finder", "FD", 0, "", MACRO_Finder},
900 {"FloatingMenu", NULL, 0, "", MACRO_FloatingMenu},
901 {"Flush", "FH", 0, "", MACRO_Flush},
902 {"FocusWindow", NULL, 0, "S", MACRO_FocusWindow},
903 {"Generate", NULL, 0, "SUU", MACRO_Generate},
904 {"GotoMark", NULL, 0, "S", MACRO_GotoMark},
905 {"HelpOn", NULL, 0, "", MACRO_HelpOn},
906 {"HelpOnTop", NULL, 0, "", MACRO_HelpOnTop},
907 {"History", NULL, 0, "", MACRO_History},
908 {"InitMPrint", NULL, 1, "", MACRO_InitMPrint},
909 {"InsertItem", NULL, 0, "SSSSU", MACRO_InsertItem},
910 {"InsertMenu", NULL, 0, "SSU", MACRO_InsertMenu},
911 {"IfThen", "IF", 0, "BS", MACRO_IfThen},
912 {"IfThenElse", "IE", 0, "BSS", MACRO_IfThenElse},
913 {"IsBook", NULL, 1, "", MACRO_IsBook},
914 {"IsMark", NULL, 1, "S", MACRO_IsMark},
915 {"IsNotMark", "NM", 1, "S", MACRO_IsNotMark},
916 {"JumpContents", NULL, 0, "SS", MACRO_JumpContents},
917 {"JumpContext", "JC", 0, "SSU", MACRO_JumpContext},
918 {"JumpHash", "JH", 0, "SSU", MACRO_JumpHash},
919 {"JumpHelpOn", NULL, 0, "", MACRO_JumpHelpOn},
920 {"JumpID", "JI", 0, "SS", MACRO_JumpID},
921 {"JumpKeyword", "JK", 0, "SSS", MACRO_JumpKeyword},
922 {"KLink", "KL", 0, "SUSS", MACRO_KLink},
923 {"Menu", "MU", 0, "", MACRO_Menu},
924 {"MPrintHash", NULL, 0, "U", MACRO_MPrintHash},
925 {"MPrintID", NULL, 0, "S", MACRO_MPrintID},
926 {"Next", NULL, 0, "", MACRO_Next},
927 {"NoShow", "NS", 0, "", MACRO_NoShow},
928 {"PopupContext", "PC", 0, "SU", MACRO_PopupContext},
929 {"PopupHash", NULL, 0, "SU", MACRO_PopupHash},
930 {"PopupId", "PI", 0, "SS", MACRO_PopupId},
931 {"PositionWindow", "PW", 0, "IIUUUS", MACRO_PositionWindow},
932 {"Prev", NULL, 0, "", MACRO_Prev},
933 {"Print", NULL, 0, "", MACRO_Print},
934 {"PrinterSetup", NULL, 0, "", MACRO_PrinterSetup},
935 {"RegisterRoutine", "RR", 0, "SSS", MACRO_RegisterRoutine},
936 {"RemoveAccelerator", "RA", 0, "UU", MACRO_RemoveAccelerator},
937 {"ResetMenu", NULL, 0, "", MACRO_ResetMenu},
938 {"SaveMark", NULL, 0, "S", MACRO_SaveMark},
939 {"Search", NULL, 0, "", MACRO_Search},
940 {"SetContents", NULL, 0, "SU", MACRO_SetContents},
941 {"SetHelpOnFile", NULL, 0, "S", MACRO_SetHelpOnFile},
942 {"SetPopupColor", "SPC",0, "UUU", MACRO_SetPopupColor},
943 {"ShellExecute", "SE", 0, "SSUUSS", MACRO_ShellExecute},
944 {"ShortCut", "SH", 0, "SSUUS", MACRO_ShortCut},
945 {"TCard", NULL, 0, "U", MACRO_TCard},
946 {"Test", NULL, 0, "U", MACRO_Test},
947 {"TestALink", NULL, 1, "S", MACRO_TestALink},
948 {"TestKLink", NULL, 1, "S", MACRO_TestKLink},
949 {"UncheckItem", "UI", 0, "S", MACRO_UncheckItem},
950 {"UpdateWindow", "UW", 0, "SS", MACRO_UpdateWindow},
951 {NULL, NULL, 0, NULL, NULL}
954 static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len)
956 struct MacroDesc* md;
958 for (md = start; md->name && len != 0; md++, len--)
960 if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))
962 lr->proto = md->arguments;
963 lr->function = md->fn;
964 return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;
967 return EMPTY;
970 int MACRO_Lookup(const char* name, struct lexret* lr)
972 int ret;
974 if ((ret = MACRO_DoLookUp(MACRO_Builtins, name, lr, -1)) != EMPTY)
975 return ret;
976 if (MACRO_Loaded && (ret = MACRO_DoLookUp(MACRO_Loaded, name, lr, MACRO_NumLoaded)) != EMPTY)
977 return ret;
979 lr->string = name;
980 return IDENTIFIER;