ntdll: Implement NtCreateToken().
[wine.git] / programs / winhlp32 / macro.c
blob36bda654afddcf2524ca2c14d101ef1f0399270b
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>
25 #include <stdlib.h>
27 #include "windows.h"
28 #include "commdlg.h"
29 #include "shellapi.h"
30 #include "winhelp.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
36 /**************************************************/
37 /* Macro table */
38 /**************************************************/
39 struct MacroDesc {
40 const char* name;
41 const char* alias;
42 BOOL isBool;
43 const char* arguments;
44 void *fn;
47 static struct MacroDesc*MACRO_Loaded /* = NULL */;
48 static unsigned MACRO_NumLoaded /* = 0 */;
50 /******* helper functions *******/
52 static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
54 WINHELP_BUTTON** b;
56 for (b = &win->first_button; *b; b = &(*b)->next)
57 if (!lstrcmpiA(name, (*b)->lpszID)) break;
58 return b;
61 /******* some forward declarations *******/
62 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id);
64 /******* real macro implementation *******/
66 void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
68 WINHELP_WINDOW *win = MACRO_CurrentWindow();
69 WINHELP_BUTTON *button, **b;
70 LONG size;
71 LPSTR ptr;
73 WINE_TRACE("(%s, %s, %s)\n", debugstr_a(id), debugstr_a(name), debugstr_a(macro));
75 size = sizeof(WINHELP_BUTTON) + strlen(id) + strlen(name) + strlen(macro) + 3;
77 button = malloc(size);
78 if (!button) return;
80 button->next = 0;
81 button->hWnd = 0;
83 ptr = (char*)button + sizeof(WINHELP_BUTTON);
85 strcpy(ptr, id);
86 button->lpszID = ptr;
87 ptr += strlen(id) + 1;
89 strcpy(ptr, name);
90 button->lpszName = ptr;
91 ptr += strlen(name) + 1;
93 strcpy(ptr, macro);
94 button->lpszMacro = ptr;
96 button->wParam = WH_FIRST_BUTTON;
97 for (b = &win->first_button; *b; b = &(*b)->next)
98 button->wParam = max(button->wParam, (*b)->wParam + 1);
99 *b = button;
101 WINHELP_LayoutMainWindow(win);
104 static void CALLBACK MACRO_DestroyButton(LPCSTR str)
106 WINE_FIXME("(%s)\n", debugstr_a(str));
109 void CALLBACK MACRO_DisableButton(LPCSTR id)
111 WINHELP_BUTTON** b;
113 WINE_TRACE("(%s)\n", debugstr_a(id));
115 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
116 if (!*b) {WINE_FIXME("Couldn't find button %s\n", debugstr_a(id)); return;}
118 EnableWindow((*b)->hWnd, FALSE);
121 static void CALLBACK MACRO_EnableButton(LPCSTR id)
123 WINHELP_BUTTON** b;
125 WINE_TRACE("(%s)\n", debugstr_a(id));
127 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
128 if (!*b) {WINE_FIXME("Couldn't find button %s\n", debugstr_a(id)); return;}
130 EnableWindow((*b)->hWnd, TRUE);
133 void CALLBACK MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
135 HLPFILE* hlpfile;
137 WINE_TRACE("(%s, %s)\n", debugstr_a(lpszPath), debugstr_a(lpszWindow));
138 if ((hlpfile = WINHELP_LookupHelpFile(lpszPath)))
139 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, 0,
140 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
141 SW_NORMAL);
145 void CALLBACK MACRO_About(void)
147 WCHAR name[256];
148 HICON icon = LoadImageW( Globals.hInstance, MAKEINTRESOURCEW(IDI_WINHELP),
149 IMAGE_ICON, 48, 48, LR_SHARED );
150 LoadStringW( Globals.hInstance, STID_WINE_HELP, name, ARRAY_SIZE( name ));
151 ShellAboutW( MACRO_CurrentWindow()->hMainWnd, name, NULL, icon );
154 static void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
156 WINE_FIXME("(%lu, %lu, %s)\n", u1, u2, debugstr_a(str));
159 static void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
161 WINE_FIXME("(%s, %lu, %s)\n", debugstr_a(str1), u, debugstr_a(str2));
164 void CALLBACK MACRO_Annotate(void)
166 WINE_FIXME("()\n");
169 static void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
171 WINE_FIXME("(%s, %s, %s, %s)\n", debugstr_a(str1), debugstr_a(str2), debugstr_a(str3), debugstr_a(str4));
174 static void CALLBACK MACRO_Back(void)
176 WINHELP_WINDOW* win = MACRO_CurrentWindow();
178 WINE_TRACE("()\n");
180 if (win && win->back.index >= 2)
181 WINHELP_CreateHelpWindow(&win->back.set[--win->back.index - 1], SW_SHOW, FALSE);
184 static void CALLBACK MACRO_BackFlush(void)
186 WINHELP_WINDOW* win = MACRO_CurrentWindow();
188 WINE_TRACE("()\n");
190 if (win) WINHELP_DeleteBackSet(win);
193 void CALLBACK MACRO_BookmarkDefine(void)
195 WINE_FIXME("()\n");
198 static void CALLBACK MACRO_BookmarkMore(void)
200 WINE_FIXME("()\n");
203 static void CALLBACK MACRO_BrowseButtons(void)
205 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
206 ULONG relative;
208 WINE_TRACE("()\n");
210 MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
211 MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
213 if (!HLPFILE_PageByOffset(page->file, page->browse_bwd, &relative))
214 MACRO_DisableButton("BTN_PREV");
215 if (!HLPFILE_PageByOffset(page->file, page->browse_fwd, &relative))
216 MACRO_DisableButton("BTN_NEXT");
219 static void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
221 WINHELP_WINDOW* win = MACRO_CurrentWindow();
222 WINHELP_BUTTON* button;
223 WINHELP_BUTTON** b;
224 LONG size;
225 LPSTR ptr;
227 WINE_TRACE("(%s, %s)\n", debugstr_a(id), debugstr_a(macro));
229 b = MACRO_LookupButton(win, id);
230 if (!*b) {WINE_FIXME("Couldn't find button %s\n", debugstr_a(id)); return;}
232 size = sizeof(WINHELP_BUTTON) + strlen(id) +
233 strlen((*b)->lpszName) + strlen(macro) + 3;
235 button = malloc(size);
236 if (!button) return;
238 button->next = (*b)->next;
239 button->hWnd = (*b)->hWnd;
240 button->wParam = (*b)->wParam;
242 ptr = (char*)button + sizeof(WINHELP_BUTTON);
244 strcpy(ptr, id);
245 button->lpszID = ptr;
246 ptr += strlen(id) + 1;
248 strcpy(ptr, (*b)->lpszName);
249 button->lpszName = ptr;
250 ptr += strlen((*b)->lpszName) + 1;
252 strcpy(ptr, macro);
253 button->lpszMacro = ptr;
255 *b = button;
257 WINHELP_LayoutMainWindow(win);
260 static void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
262 WINE_TRACE("(%s, %s)\n", debugstr_a(id), debugstr_a(macro));
264 MACRO_ChangeButtonBinding(id, macro);
265 MACRO_EnableButton(id);
268 static void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
270 WINE_FIXME("(%s, %s)\n", debugstr_a(str1), debugstr_a(str2));
273 static void CALLBACK MACRO_CheckItem(LPCSTR str)
275 WINE_FIXME("(%s)\n", debugstr_a(str));
278 static void CALLBACK MACRO_CloseSecondarys(void)
280 WINHELP_WINDOW *win;
281 WINHELP_WINDOW *next;
283 WINE_TRACE("()\n");
284 for (win = Globals.win_list; win; win = next)
286 next = win->next;
287 if (lstrcmpiA(win->info->name, "main"))
288 WINHELP_ReleaseWindow(win);
292 static void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow)
294 WINHELP_WINDOW *win;
295 WINHELP_WINDOW *next;
297 WINE_TRACE("(%s)\n", debugstr_a(lpszWindow));
299 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
301 for (win = Globals.win_list; win; win = next)
303 next = win->next;
304 if (!lstrcmpiA(win->info->name, lpszWindow))
305 WINHELP_ReleaseWindow(win);
309 static void CALLBACK MACRO_Compare(LPCSTR str)
311 WINE_FIXME("(%s)\n", debugstr_a(str));
314 static void CALLBACK MACRO_Contents(void)
316 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
318 WINE_TRACE("()\n");
320 if (page)
321 MACRO_JumpContents(page->file->lpszPath, NULL);
324 static void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
326 WINE_FIXME("(%s, %s, %lu)\n", debugstr_a(str1), debugstr_a(str2), u);
329 void CALLBACK MACRO_CopyDialog(void)
331 WINE_FIXME("()\n");
334 static void CALLBACK MACRO_CopyTopic(void)
336 WINE_FIXME("()\n");
339 static void CALLBACK MACRO_DeleteItem(LPCSTR str)
341 WINE_FIXME("(%s)\n", debugstr_a(str));
344 static void CALLBACK MACRO_DeleteMark(LPCSTR str)
346 WINE_FIXME("(%s)\n", debugstr_a(str));
349 static void CALLBACK MACRO_DisableItem(LPCSTR str)
351 WINE_FIXME("(%s)\n", debugstr_a(str));
354 static void CALLBACK MACRO_EnableItem(LPCSTR str)
356 WINE_FIXME("(%s)\n", debugstr_a(str));
359 static void CALLBACK MACRO_EndMPrint(void)
361 WINE_FIXME("()\n");
364 static void CALLBACK MACRO_ExecFile(LPCSTR pgm, LPCSTR args, LONG cmd_show, LPCSTR topic)
366 HINSTANCE ret;
368 WINE_TRACE("(%s, %s, %lu, %s)\n",
369 debugstr_a(pgm), debugstr_a(args), cmd_show, debugstr_a(topic));
371 ret = ShellExecuteA(Globals.active_win ? Globals.active_win->hMainWnd : NULL, "open",
372 pgm, args, ".", cmd_show);
373 if ((DWORD_PTR)ret < 32)
375 WINE_WARN("Failed with %p\n", ret);
376 if (topic) MACRO_JumpID(NULL, topic);
380 static void CALLBACK MACRO_ExecProgram(LPCSTR str, LONG u)
382 WINE_FIXME("(%s, %lu)\n", debugstr_a(str), u);
385 void CALLBACK MACRO_Exit(void)
387 WINE_TRACE("()\n");
389 while (Globals.win_list)
390 WINHELP_ReleaseWindow(Globals.win_list);
393 static void CALLBACK MACRO_ExtAbleItem(LPCSTR str, LONG u)
395 WINE_FIXME("(%s, %lu)\n", debugstr_a(str), u);
398 static void CALLBACK MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
400 WINE_FIXME("(%s, %s, %s, %s, %lu, %lu)\n", debugstr_a(str1), debugstr_a(str2), debugstr_a(str3), debugstr_a(str4), u1, u2);
403 static void CALLBACK MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
405 WINE_FIXME("(%s, %s, %s, %lu, %lu)\n", debugstr_a(str1), debugstr_a(str2), debugstr_a(str3), u1, u2);
408 static BOOL CALLBACK MACRO_FileExist(LPCSTR str)
410 WINE_TRACE("(%s)\n", debugstr_a(str));
411 return GetFileAttributesA(str) != INVALID_FILE_ATTRIBUTES;
414 void CALLBACK MACRO_FileOpen(void)
416 char szFile[MAX_PATH];
418 if (WINHELP_GetOpenFileName(szFile, MAX_PATH))
420 MACRO_JumpContents(szFile, "main");
424 static void CALLBACK MACRO_Find(void)
426 WINE_FIXME("()\n");
429 static void CALLBACK MACRO_Finder(void)
431 WINHELP_CreateIndexWindow(FALSE);
434 static void CALLBACK MACRO_FloatingMenu(void)
436 WINE_FIXME("()\n");
439 static void CALLBACK MACRO_Flush(void)
441 WINE_FIXME("()\n");
444 static void CALLBACK MACRO_FocusWindow(LPCSTR lpszWindow)
446 WINHELP_WINDOW *win;
448 WINE_TRACE("(%s)\n", debugstr_a(lpszWindow));
450 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
452 for (win = Globals.win_list; win; win = win->next)
453 if (!lstrcmpiA(win->info->name, lpszWindow))
454 SetFocus(win->hMainWnd);
457 static void CALLBACK MACRO_Generate(LPCSTR str, LONG w, LONG l)
459 WINE_FIXME("(%s, %lx, %lx)\n", debugstr_a(str), w, l);
462 static void CALLBACK MACRO_GotoMark(LPCSTR str)
464 WINE_FIXME("(%s)\n", debugstr_a(str));
467 void CALLBACK MACRO_HelpOn(void)
469 WINHELP_WINDOW *win = MACRO_CurrentWindow();
470 LPCSTR file = NULL;
472 WINE_TRACE("()\n");
473 if (win && win->page && win->page->file)
474 file = win->page->file->help_on_file;
476 if (!file)
477 file = (Globals.wVersion > 4) ? "winhlp32.hlp" : "winhelp.hlp";
479 MACRO_JumpContents(file, NULL);
482 void CALLBACK MACRO_HelpOnTop(void)
484 static BOOL on_top = FALSE;
485 WINHELP_WINDOW *win;
486 HWND main_wnd = NULL;
487 HMENU menu;
489 for (win = Globals.win_list; win; win = win->next)
490 if (!lstrcmpiA(win->info->name, "main"))
491 main_wnd = win->hMainWnd;
492 if (!main_wnd)
494 WINE_ERR("could not find the main window!\n");
495 return;
497 menu = GetMenu(main_wnd);
499 on_top = !on_top;
500 if (on_top) {
501 CheckMenuItem(menu, MNID_HELP_HELPTOP, MF_BYCOMMAND|MF_CHECKED);
502 SetWindowPos(main_wnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
503 } else {
504 CheckMenuItem(menu, MNID_HELP_HELPTOP, MF_BYCOMMAND|MF_UNCHECKED);
505 SetWindowPos(main_wnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
509 void CALLBACK MACRO_History(void)
511 WINE_TRACE("()\n");
513 if (Globals.active_win && !Globals.active_win->hHistoryWnd)
515 HWND hWnd = CreateWindowA(HISTORY_WIN_CLASS_NAME, "History", WS_OVERLAPPEDWINDOW,
516 0, 0, 0, 0, 0, 0, Globals.hInstance, Globals.active_win);
517 ShowWindow(hWnd, SW_NORMAL);
521 static void CALLBACK MACRO_IfThen(BOOL b, LPCSTR t)
523 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
526 static void CALLBACK MACRO_IfThenElse(BOOL b, LPCSTR t, LPCSTR f)
528 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
529 else MACRO_ExecuteMacro(MACRO_CurrentWindow(), f);
532 static BOOL CALLBACK MACRO_InitMPrint(void)
534 WINE_FIXME("()\n");
535 return FALSE;
538 static void CALLBACK MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
540 WINE_FIXME("(%s, %s, %s, %s, %lu)\n", debugstr_a(str1), debugstr_a(str2), debugstr_a(str3), debugstr_a(str4), u);
543 static void CALLBACK MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
545 WINE_FIXME("(%s, %s, %lu)\n", debugstr_a(str1), debugstr_a(str2), u);
548 static BOOL CALLBACK MACRO_IsBook(void)
550 WINE_TRACE("()\n");
551 return Globals.isBook;
554 static BOOL CALLBACK MACRO_IsMark(LPCSTR str)
556 WINE_FIXME("(%s)\n", debugstr_a(str));
557 return FALSE;
560 static BOOL CALLBACK MACRO_IsNotMark(LPCSTR str)
562 WINE_FIXME("(%s)\n", debugstr_a(str));
563 return TRUE;
566 void CALLBACK MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
568 HLPFILE* hlpfile;
570 WINE_TRACE("(%s, %s, %ld)\n", debugstr_a(lpszPath), debugstr_a(lpszWindow), context);
571 if ((hlpfile = WINHELP_LookupHelpFile(lpszPath)))
572 /* Some madness: what user calls 'context', hlpfile calls 'map' */
573 WINHELP_OpenHelpWindow(HLPFILE_PageByMap, hlpfile, context,
574 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
575 SW_NORMAL);
578 void CALLBACK MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
580 HLPFILE* hlpfile;
582 WINE_TRACE("(%s, %s, %lu)\n", debugstr_a(lpszPath), debugstr_a(lpszWindow), lHash);
583 if (!lpszPath || !lpszPath[0])
584 hlpfile = MACRO_CurrentWindow()->page->file;
585 else
586 hlpfile = WINHELP_LookupHelpFile(lpszPath);
587 if (hlpfile)
588 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
589 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
590 SW_NORMAL);
593 static void CALLBACK MACRO_JumpHelpOn(void)
595 WINE_FIXME("()\n");
598 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id)
600 LPSTR ptr;
602 WINE_TRACE("(%s, %s)\n", debugstr_a(lpszPathWindow), debugstr_a(topic_id));
603 if (lpszPathWindow && (ptr = strchr(lpszPathWindow, '>')) != NULL)
605 LPSTR tmp;
606 size_t sz;
608 tmp = strdup(lpszPathWindow);
609 if (tmp)
611 tmp[ptr - lpszPathWindow] = '\0';
612 ptr += tmp - lpszPathWindow; /* ptr now points to '>' in tmp buffer */
613 /* in some cases, we have a trailing space that we need to get rid of */
614 /* FIXME: check if it has to be done in lexer rather than here */
615 for (sz = strlen(ptr + 1); sz >= 1 && ptr[sz] == ' '; sz--) ptr[sz] = '\0';
616 MACRO_JumpHash(tmp, ptr + 1, HLPFILE_Hash(topic_id));
617 free(tmp);
620 else
621 MACRO_JumpHash(lpszPathWindow, NULL, HLPFILE_Hash(topic_id));
624 /* FIXME: this macros is wrong
625 * it should only contain 2 strings, path & window are coded as path>window
627 static void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
629 WINE_FIXME("(%s, %s, %s)\n", debugstr_a(lpszPath), debugstr_a(lpszWindow), debugstr_a(keyword));
632 static void CALLBACK MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
634 WINE_FIXME("(%s, %lu, %s, %s)\n", debugstr_a(str1), u, debugstr_a(str2), debugstr_a(str3));
637 static void CALLBACK MACRO_Menu(void)
639 WINE_FIXME("()\n");
642 static void CALLBACK MACRO_MPrintHash(LONG u)
644 WINE_FIXME("(%lu)\n", u);
647 static void CALLBACK MACRO_MPrintID(LPCSTR str)
649 WINE_FIXME("(%s)\n", debugstr_a(str));
652 static void CALLBACK MACRO_Next(void)
654 WINHELP_WNDPAGE wp;
656 WINE_TRACE("()\n");
657 wp.page = MACRO_CurrentWindow()->page;
658 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_fwd, &wp.relative);
659 if (wp.page)
661 wp.page->file->wRefCount++;
662 wp.wininfo = MACRO_CurrentWindow()->info;
663 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
667 static void CALLBACK MACRO_NoShow(void)
669 WINE_FIXME("()\n");
672 void CALLBACK MACRO_PopupContext(LPCSTR str, LONG u)
674 WINE_FIXME("(%s, %lu)\n", debugstr_a(str), u);
677 static void CALLBACK MACRO_PopupHash(LPCSTR str, LONG u)
679 WINE_FIXME("(%s, %lu)\n", debugstr_a(str), u);
682 static void CALLBACK MACRO_PopupId(LPCSTR str1, LPCSTR str2)
684 WINE_FIXME("(%s, %s)\n", debugstr_a(str1), debugstr_a(str2));
687 static void CALLBACK MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
689 WINE_FIXME("(%li, %li, %lu, %lu, %lu, %s)\n", i1, i2, u1, u2, u3, debugstr_a(str));
692 static void CALLBACK MACRO_Prev(void)
694 WINHELP_WNDPAGE wp;
696 WINE_TRACE("()\n");
697 wp.page = MACRO_CurrentWindow()->page;
698 wp.page = HLPFILE_PageByOffset(wp.page->file, wp.page->browse_bwd, &wp.relative);
699 if (wp.page)
701 wp.page->file->wRefCount++;
702 wp.wininfo = MACRO_CurrentWindow()->info;
703 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
707 void CALLBACK MACRO_Print(void)
709 PRINTDLGW printer;
711 WINE_TRACE("()\n");
713 printer.lStructSize = sizeof(printer);
714 printer.hwndOwner = MACRO_CurrentWindow()->hMainWnd;
715 printer.hInstance = Globals.hInstance;
716 printer.hDevMode = 0;
717 printer.hDevNames = 0;
718 printer.hDC = 0;
719 printer.Flags = 0;
720 printer.nFromPage = 0;
721 printer.nToPage = 0;
722 printer.nMinPage = 0;
723 printer.nMaxPage = 0;
724 printer.nCopies = 0;
725 printer.lCustData = 0;
726 printer.lpfnPrintHook = 0;
727 printer.lpfnSetupHook = 0;
728 printer.lpPrintTemplateName = 0;
729 printer.lpSetupTemplateName = 0;
730 printer.hPrintTemplate = 0;
731 printer.hSetupTemplate = 0;
733 if (PrintDlgW(&printer)) {
734 WINE_FIXME("Print()\n");
738 void CALLBACK MACRO_PrinterSetup(void)
740 WINE_FIXME("()\n");
743 static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR args)
745 void *fn = NULL;
746 int size;
747 WINHELP_DLL* dll;
749 WINE_TRACE("(%s, %s, %s)\n", debugstr_a(dll_name), debugstr_a(proc), debugstr_a(args));
751 /* FIXME: are the registered DLLs global or linked to the current file ???
752 * We assume globals (as we did for macros, but is this really the case ???)
754 for (dll = Globals.dlls; dll; dll = dll->next)
756 if (!strcmp(dll->name, dll_name)) break;
758 if (!dll)
760 HANDLE hLib = LoadLibraryA(dll_name);
762 /* FIXME: the library will not be unloaded until exit of program
763 * We don't send the DW_TERM message
765 WINE_TRACE("Loading %s\n", debugstr_a(dll_name));
766 /* FIXME: should look in the directory where current hlpfile
767 * is loaded from
769 if (hLib == NULL)
771 /* FIXME: internationalisation for error messages */
772 WINE_FIXME("Cannot find dll %s\n", debugstr_a(dll_name));
774 else if ((dll = malloc(sizeof(*dll))))
776 dll->hLib = hLib;
777 dll->name = strdup(dll_name); /* FIXME: never freed */
778 dll->next = Globals.dlls;
779 Globals.dlls = dll;
780 dll->handler = (WINHELP_LDLLHandler)GetProcAddress(dll->hLib, "LDLLHandler");
781 dll->class = dll->handler ? (dll->handler)(DW_WHATMSG, 0, 0) : DC_NOMSG;
782 WINE_TRACE("Got class %lx for DLL %s\n", dll->class, debugstr_a(dll_name));
783 if (dll->class & DC_INITTERM) dll->handler(DW_INIT, 0, 0);
784 if (dll->class & DC_CALLBACKS) dll->handler(DW_CALLBACKS, (LONG_PTR)&Callbacks, 0);
786 else WINE_WARN("OOM\n");
788 if (dll && !(fn = GetProcAddress(dll->hLib, proc)))
790 /* FIXME: internationalisation for error messages */
791 WINE_FIXME("Cannot find proc %s in dll %s\n", debugstr_a(dll_name), debugstr_a(proc));
794 size = ++MACRO_NumLoaded * sizeof(struct MacroDesc);
795 MACRO_Loaded = realloc(MACRO_Loaded, size);
796 MACRO_Loaded[MACRO_NumLoaded - 1].name = strdup(proc); /* FIXME: never freed */
797 MACRO_Loaded[MACRO_NumLoaded - 1].alias = NULL;
798 MACRO_Loaded[MACRO_NumLoaded - 1].isBool = FALSE;
799 MACRO_Loaded[MACRO_NumLoaded - 1].arguments = strdup(args); /* FIXME: never freed */
800 MACRO_Loaded[MACRO_NumLoaded - 1].fn = fn;
801 WINE_TRACE("Added %s(%s) at %p\n", debugstr_a(proc), debugstr_a(args), fn);
804 static void CALLBACK MACRO_RemoveAccelerator(LONG u1, LONG u2)
806 WINE_FIXME("(%lu, %lu)\n", u1, u2);
809 static void CALLBACK MACRO_ResetMenu(void)
811 WINE_FIXME("()\n");
814 static void CALLBACK MACRO_SaveMark(LPCSTR str)
816 WINE_FIXME("(%s)\n", debugstr_a(str));
819 static void CALLBACK MACRO_Search(void)
821 WINHELP_CreateIndexWindow(TRUE);
824 void CALLBACK MACRO_SetContents(LPCSTR str, LONG u)
826 WINE_FIXME("(%s, %lu)\n", debugstr_a(str), u);
829 static void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
831 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
833 WINE_TRACE("(%s)\n", debugstr_a(str));
835 free(page->file->help_on_file);
836 page->file->help_on_file = strdup(str);
839 static void CALLBACK MACRO_SetPopupColor(LONG r, LONG g, LONG b)
841 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
843 WINE_TRACE("(%lx, %lx, %lx)\n", r, g, b);
844 page->file->has_popup_color = TRUE;
845 page->file->popup_color = RGB(r, g, b);
848 static void CALLBACK MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
850 WINE_FIXME("(%s, %s, %lu, %lu, %s, %s)\n", debugstr_a(str1), debugstr_a(str2), u1, u2, debugstr_a(str3), debugstr_a(str4));
853 static void CALLBACK MACRO_ShortCut(LPCSTR str1, LPCSTR str2, LONG w, LONG l, LPCSTR str)
855 WINE_FIXME("(%s, %s, %lx, %lx, %s)\n", debugstr_a(str1), debugstr_a(str2), w, l, debugstr_a(str));
858 static void CALLBACK MACRO_TCard(LONG u)
860 WINE_FIXME("(%lu)\n", u);
863 static void CALLBACK MACRO_Test(LONG u)
865 WINE_FIXME("(%lu)\n", u);
868 static BOOL CALLBACK MACRO_TestALink(LPCSTR str)
870 WINE_FIXME("(%s)\n", debugstr_a(str));
871 return FALSE;
874 static BOOL CALLBACK MACRO_TestKLink(LPCSTR str)
876 WINE_FIXME("(%s)\n", debugstr_a(str));
877 return FALSE;
880 static void CALLBACK MACRO_UncheckItem(LPCSTR str)
882 WINE_FIXME("(%s)\n", debugstr_a(str));
885 static void CALLBACK MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
887 WINE_FIXME("(%s, %s)\n", debugstr_a(str1), debugstr_a(str2));
891 /**************************************************/
892 /* Macro table */
893 /**************************************************/
895 /* types:
896 * U: 32 bit unsigned int
897 * I: 32 bit signed int
898 * S: string
899 * v: unknown (32 bit entity)
902 static struct MacroDesc MACRO_Builtins[] = {
903 {"About", NULL, 0, "", MACRO_About},
904 {"AddAccelerator", "AA", 0, "UUS", MACRO_AddAccelerator},
905 {"ALink", "AL", 0, "SUS", MACRO_ALink},
906 {"Annotate", NULL, 0, "", MACRO_Annotate},
907 {"AppendItem", NULL, 0, "SSSS", MACRO_AppendItem},
908 {"Back", NULL, 0, "", MACRO_Back},
909 {"BackFlush", "BF", 0, "", MACRO_BackFlush},
910 {"BookmarkDefine", NULL, 0, "", MACRO_BookmarkDefine},
911 {"BookmarkMore", NULL, 0, "", MACRO_BookmarkMore},
912 {"BrowseButtons", NULL, 0, "", MACRO_BrowseButtons},
913 {"ChangeButtonBinding", "CBB",0, "SS", MACRO_ChangeButtonBinding},
914 {"ChangeEnable", "CE", 0, "SS", MACRO_ChangeEnable},
915 {"ChangeItemBinding", "CIB",0, "SS", MACRO_ChangeItemBinding},
916 {"CheckItem", "CI", 0, "S", MACRO_CheckItem},
917 {"CloseSecondarys", "CS", 0, "", MACRO_CloseSecondarys},
918 {"CloseWindow", "CW", 0, "S", MACRO_CloseWindow},
919 {"Compare", NULL, 0, "S", MACRO_Compare},
920 {"Contents", NULL, 0, "", MACRO_Contents},
921 {"ControlPanel", NULL, 0, "SSU", MACRO_ControlPanel},
922 {"CopyDialog", NULL, 0, "", MACRO_CopyDialog},
923 {"CopyTopic", "CT", 0, "", MACRO_CopyTopic},
924 {"CreateButton", "CB", 0, "SSS", MACRO_CreateButton},
925 {"DeleteItem", NULL, 0, "S", MACRO_DeleteItem},
926 {"DeleteMark", NULL, 0, "S", MACRO_DeleteMark},
927 {"DestroyButton", NULL, 0, "S", MACRO_DestroyButton},
928 {"DisableButton", "DB", 0, "S", MACRO_DisableButton},
929 {"DisableItem", "DI", 0, "S", MACRO_DisableItem},
930 {"EnableButton", "EB", 0, "S", MACRO_EnableButton},
931 {"EnableItem", "EI", 0, "S", MACRO_EnableItem},
932 {"EndMPrint", NULL, 0, "", MACRO_EndMPrint},
933 {"ExecFile", "EF", 0, "SSUS", MACRO_ExecFile},
934 {"ExecProgram", "EP", 0, "SU", MACRO_ExecProgram},
935 {"Exit", NULL, 0, "", MACRO_Exit},
936 {"ExtAbleItem", NULL, 0, "SU", MACRO_ExtAbleItem},
937 {"ExtInsertItem", NULL, 0, "SSSSUU", MACRO_ExtInsertItem},
938 {"ExtInsertMenu", NULL, 0, "SSSUU", MACRO_ExtInsertMenu},
939 {"FileExist", "FE", 1, "S", MACRO_FileExist},
940 {"FileOpen", "FO", 0, "", MACRO_FileOpen},
941 {"Find", NULL, 0, "", MACRO_Find},
942 {"Finder", "FD", 0, "", MACRO_Finder},
943 {"FloatingMenu", NULL, 0, "", MACRO_FloatingMenu},
944 {"Flush", "FH", 0, "", MACRO_Flush},
945 {"FocusWindow", NULL, 0, "S", MACRO_FocusWindow},
946 {"Generate", NULL, 0, "SUU", MACRO_Generate},
947 {"GotoMark", NULL, 0, "S", MACRO_GotoMark},
948 {"HelpOn", NULL, 0, "", MACRO_HelpOn},
949 {"HelpOnTop", NULL, 0, "", MACRO_HelpOnTop},
950 {"History", NULL, 0, "", MACRO_History},
951 {"InitMPrint", NULL, 1, "", MACRO_InitMPrint},
952 {"InsertItem", NULL, 0, "SSSSU", MACRO_InsertItem},
953 {"InsertMenu", NULL, 0, "SSU", MACRO_InsertMenu},
954 {"IfThen", "IF", 0, "BS", MACRO_IfThen},
955 {"IfThenElse", "IE", 0, "BSS", MACRO_IfThenElse},
956 {"IsBook", NULL, 1, "", MACRO_IsBook},
957 {"IsMark", NULL, 1, "S", MACRO_IsMark},
958 {"IsNotMark", "NM", 1, "S", MACRO_IsNotMark},
959 {"JumpContents", NULL, 0, "SS", MACRO_JumpContents},
960 {"JumpContext", "JC", 0, "SSU", MACRO_JumpContext},
961 {"JumpHash", "JH", 0, "SSU", MACRO_JumpHash},
962 {"JumpHelpOn", NULL, 0, "", MACRO_JumpHelpOn},
963 {"JumpID", "JI", 0, "SS", MACRO_JumpID},
964 {"JumpKeyword", "JK", 0, "SSS", MACRO_JumpKeyword},
965 {"KLink", "KL", 0, "SUSS", MACRO_KLink},
966 {"Menu", "MU", 0, "", MACRO_Menu},
967 {"MPrintHash", NULL, 0, "U", MACRO_MPrintHash},
968 {"MPrintID", NULL, 0, "S", MACRO_MPrintID},
969 {"Next", NULL, 0, "", MACRO_Next},
970 {"NoShow", "NS", 0, "", MACRO_NoShow},
971 {"PopupContext", "PC", 0, "SU", MACRO_PopupContext},
972 {"PopupHash", NULL, 0, "SU", MACRO_PopupHash},
973 {"PopupId", "PI", 0, "SS", MACRO_PopupId},
974 {"PositionWindow", "PW", 0, "IIUUUS", MACRO_PositionWindow},
975 {"Prev", NULL, 0, "", MACRO_Prev},
976 {"Print", NULL, 0, "", MACRO_Print},
977 {"PrinterSetup", NULL, 0, "", MACRO_PrinterSetup},
978 {"RegisterRoutine", "RR", 0, "SSS", MACRO_RegisterRoutine},
979 {"RemoveAccelerator", "RA", 0, "UU", MACRO_RemoveAccelerator},
980 {"ResetMenu", NULL, 0, "", MACRO_ResetMenu},
981 {"SaveMark", NULL, 0, "S", MACRO_SaveMark},
982 {"Search", NULL, 0, "", MACRO_Search},
983 {"SetContents", NULL, 0, "SU", MACRO_SetContents},
984 {"SetHelpOnFile", NULL, 0, "S", MACRO_SetHelpOnFile},
985 {"SetPopupColor", "SPC",0, "UUU", MACRO_SetPopupColor},
986 {"ShellExecute", "SE", 0, "SSUUSS", MACRO_ShellExecute},
987 {"ShortCut", "SH", 0, "SSUUS", MACRO_ShortCut},
988 {"TCard", NULL, 0, "U", MACRO_TCard},
989 {"Test", NULL, 0, "U", MACRO_Test},
990 {"TestALink", NULL, 1, "S", MACRO_TestALink},
991 {"TestKLink", NULL, 1, "S", MACRO_TestKLink},
992 {"UncheckItem", "UI", 0, "S", MACRO_UncheckItem},
993 {"UpdateWindow", "UW", 0, "SS", MACRO_UpdateWindow},
994 {NULL, NULL, 0, NULL, NULL}
997 static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len)
999 struct MacroDesc* md;
1001 for (md = start; md->name && len != 0; md++, len--)
1003 if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))
1005 lr->proto = md->arguments;
1006 lr->function = md->fn;
1007 return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;
1010 return EMPTY;
1013 int MACRO_Lookup(const char* name, struct lexret* lr)
1015 int ret;
1017 if ((ret = MACRO_DoLookUp(MACRO_Builtins, name, lr, -1)) != EMPTY)
1018 return ret;
1019 if (MACRO_Loaded && (ret = MACRO_DoLookUp(MACRO_Loaded, name, lr, MACRO_NumLoaded)) != EMPTY)
1020 return ret;
1021 if (!strcmp(name, "hwndApp"))
1023 WINHELP_WINDOW* win;
1024 lr->integer = 0;
1025 for (win = Globals.win_list; win; win = win->next)
1027 if (!strcmp(win->info->name, "main"))
1029 lr->integer = (LONG_PTR)win->hMainWnd;
1030 break;
1033 return INTEGER;
1035 if (!strcmp(name, "hwndContext"))
1037 lr->integer = Globals.active_win ?
1038 (LONG_PTR)Globals.active_win->hMainWnd : 0;
1039 return INTEGER;
1041 if (!strcmp(name, "qchPath") || !strcmp(name, "qError") || !strcmp(name, "lTopicNo") ||
1042 !strcmp(name, "hfs") || !strcmp(name, "coForeground") || !strcmp(name, "coBackground"))
1044 WINE_FIXME("keyword %s not substituted in macro parsing\n", debugstr_a(name));
1045 return EMPTY;
1048 lr->string = name;
1049 return IDENTIFIER;