0e48ca8643ad78ed94e1323fd6681dfdb6a8c1c7
[reactos.git] / reactos / base / applications / 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 void *fn;
43 };
44
45 static struct MacroDesc*MACRO_Loaded /* = NULL */;
46 static unsigned MACRO_NumLoaded /* = 0 */;
47
48 /******* helper functions *******/
49
50 static char* StrDup(const char* str)
51 {
52 char* dst;
53 dst=HeapAlloc(GetProcessHeap(),0,strlen(str)+1);
54 strcpy(dst, str);
55 return dst;
56 }
57
58 static WINHELP_BUTTON** MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
59 {
60 WINHELP_BUTTON** b;
61
62 for (b = &win->first_button; *b; b = &(*b)->next)
63 if (!lstrcmpi(name, (*b)->lpszID)) break;
64 return b;
65 }
66
67 /******* real macro implementation *******/
68
69 void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
70 {
71 WINHELP_WINDOW *win = MACRO_CurrentWindow();
72 WINHELP_BUTTON *button, **b;
73 LONG size;
74 LPSTR ptr;
75
76 WINE_TRACE("(\"%s\", \"%s\", %s)\n", id, name, macro);
77
78 size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;
79
80 button = HeapAlloc(GetProcessHeap(), 0, size);
81 if (!button) return;
82
83 button->next = 0;
84 button->hWnd = 0;
85
86 ptr = (char*)button + sizeof(WINHELP_BUTTON);
87
88 lstrcpy(ptr, id);
89 button->lpszID = ptr;
90 ptr += lstrlen(id) + 1;
91
92 lstrcpy(ptr, name);
93 button->lpszName = ptr;
94 ptr += lstrlen(name) + 1;
95
96 lstrcpy(ptr, macro);
97 button->lpszMacro = ptr;
98
99 button->wParam = WH_FIRST_BUTTON;
100 for (b = &win->first_button; *b; b = &(*b)->next)
101 button->wParam = max(button->wParam, (*b)->wParam + 1);
102 *b = button;
103
104 WINHELP_LayoutMainWindow(win);
105 }
106
107 static void CALLBACK MACRO_DestroyButton(LPCSTR str)
108 {
109 WINE_FIXME("(\"%s\")\n", str);
110 }
111
112 void CALLBACK MACRO_DisableButton(LPCSTR id)
113 {
114 WINHELP_BUTTON** b;
115
116 WINE_TRACE("(\"%s\")\n", id);
117
118 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
119 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
120
121 EnableWindow((*b)->hWnd, FALSE);
122 }
123
124 static void CALLBACK MACRO_EnableButton(LPCSTR id)
125 {
126 WINHELP_BUTTON** b;
127
128 WINE_TRACE("(\"%s\")\n", id);
129
130 b = MACRO_LookupButton(MACRO_CurrentWindow(), id);
131 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
132
133 EnableWindow((*b)->hWnd, TRUE);
134 }
135
136 void CALLBACK MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
137 {
138 HLPFILE* hlpfile;
139
140 WINE_TRACE("(\"%s\", \"%s\")\n", lpszPath, lpszWindow);
141 if ((hlpfile = WINHELP_LookupHelpFile(lpszPath)))
142 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, 0,
143 WINHELP_GetWindowInfo(hlpfile, lpszWindow),
144 SW_NORMAL);
145 }
146
147
148 void CALLBACK MACRO_About(void)
149 {
150 WINE_FIXME("()\n");
151 }
152
153 static void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
154 {
155 WINE_FIXME("(%u, %u, \"%s\")\n", u1, u2, str);
156 }
157
158 static void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
159 {
160 WINE_FIXME("(\"%s\", %u, \"%s\")\n", str1, u, str2);
161 }
162
163 void CALLBACK MACRO_Annotate(void)
164 {
165 WINE_FIXME("()\n");
166 }
167
168 static void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
169 {
170 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);
171 }
172
173 static void CALLBACK MACRO_Back(void)
174 {
175 WINHELP_WINDOW* win = MACRO_CurrentWindow();
176
177 WINE_TRACE("()\n");
178
179 if (win && win->back.index >= 2)
180 WINHELP_CreateHelpWindow(&win->back.set[--win->back.index - 1], SW_SHOW, FALSE);
181 }
182
183 static void CALLBACK MACRO_BackFlush(void)
184 {
185 WINHELP_WINDOW* win = MACRO_CurrentWindow();
186
187 WINE_TRACE("()\n");
188
189 if (win) WINHELP_DeleteBackSet(win);
190 }
191
192 void CALLBACK MACRO_BookmarkDefine(void)
193 {
194 WINE_FIXME("()\n");
195 }
196
197 static void CALLBACK MACRO_BookmarkMore(void)
198 {
199 WINE_FIXME("()\n");
200 }
201
202 static void CALLBACK MACRO_BrowseButtons(void)
203 {
204 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
205 ULONG relative;
206
207 WINE_TRACE("()\n");
208
209 MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
210 MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
211
212 if (!HLPFILE_PageByOffset(page->file, page->browse_bwd, &relative))
213 MACRO_DisableButton("BTN_PREV");
214 if (!HLPFILE_PageByOffset(page->file, page->browse_fwd, &relative))
215 MACRO_DisableButton("BTN_NEXT");
216 }
217
218 static void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
219 {
220 WINHELP_WINDOW* win = MACRO_CurrentWindow();
221 WINHELP_BUTTON* button;
222 WINHELP_BUTTON** b;
223 LONG size;
224 LPSTR ptr;
225
226 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
227
228 b = MACRO_LookupButton(win, id);
229 if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
230
231 size = sizeof(WINHELP_BUTTON) + lstrlen(id) +
232 lstrlen((*b)->lpszName) + lstrlen(macro) + 3;
233
234 button = HeapAlloc(GetProcessHeap(), 0, size);
235 if (!button) return;
236
237 button->next = (*b)->next;
238 button->hWnd = (*b)->hWnd;
239 button->wParam = (*b)->wParam;
240
241 ptr = (char*)button + sizeof(WINHELP_BUTTON);
242
243 lstrcpy(ptr, id);
244 button->lpszID = ptr;
245 ptr += lstrlen(id) + 1;
246
247 lstrcpy(ptr, (*b)->lpszName);
248 button->lpszName = ptr;
249 ptr += lstrlen((*b)->lpszName) + 1;
250
251 lstrcpy(ptr, macro);
252 button->lpszMacro = ptr;
253
254 *b = button;
255
256 WINHELP_LayoutMainWindow(win);
257 }
258
259 static void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
260 {
261 WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);
262
263 MACRO_ChangeButtonBinding(id, macro);
264 MACRO_EnableButton(id);
265 }
266
267 static void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
268 {
269 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
270 }
271
272 static void CALLBACK MACRO_CheckItem(LPCSTR str)
273 {
274 WINE_FIXME("(\"%s\")\n", str);
275 }
276
277 static void CALLBACK MACRO_CloseSecondarys(void)
278 {
279 WINHELP_WINDOW *win;
280
281 WINE_TRACE("()\n");
282 for (win = Globals.win_list; win; win = win->next)
283 if (lstrcmpi(win->info->name, "main"))
284 WINHELP_ReleaseWindow(win);
285 }
286
287 static void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow)
288 {
289 WINHELP_WINDOW *win;
290
291 WINE_TRACE("(\"%s\")\n", lpszWindow);
292
293 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
294
295 for (win = Globals.win_list; win; win = win->next)
296 if (!lstrcmpi(win->info->name, lpszWindow))
297 WINHELP_ReleaseWindow(win);
298 }
299
300 static void CALLBACK MACRO_Compare(LPCSTR str)
301 {
302 WINE_FIXME("(\"%s\")\n", str);
303 }
304
305 static void CALLBACK MACRO_Contents(void)
306 {
307 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
308
309 WINE_TRACE("()\n");
310
311 if (page)
312 MACRO_JumpContents(page->file->lpszPath, NULL);
313 }
314
315 static void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
316 {
317 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
318 }
319
320 void CALLBACK MACRO_CopyDialog(void)
321 {
322 WINE_FIXME("()\n");
323 }
324
325 static void CALLBACK MACRO_CopyTopic(void)
326 {
327 WINE_FIXME("()\n");
328 }
329
330 static void CALLBACK MACRO_DeleteItem(LPCSTR str)
331 {
332 WINE_FIXME("(\"%s\")\n", str);
333 }
334
335 static void CALLBACK MACRO_DeleteMark(LPCSTR str)
336 {
337 WINE_FIXME("(\"%s\")\n", str);
338 }
339
340 static void CALLBACK MACRO_DisableItem(LPCSTR str)
341 {
342 WINE_FIXME("(\"%s\")\n", str);
343 }
344
345 static void CALLBACK MACRO_EnableItem(LPCSTR str)
346 {
347 WINE_FIXME("(\"%s\")\n", str);
348 }
349
350 static void CALLBACK MACRO_EndMPrint(void)
351 {
352 WINE_FIXME("()\n");
353 }
354
355 static void CALLBACK MACRO_ExecFile(LPCSTR str1, LPCSTR str2, LONG u, LPCSTR str3)
356 {
357 WINE_FIXME("(\"%s\", \"%s\", %u, \"%s\")\n", str1, str2, u, str3);
358 }
359
360 static void CALLBACK MACRO_ExecProgram(LPCSTR str, LONG u)
361 {
362 WINE_FIXME("(\"%s\", %u)\n", str, u);
363 }
364
365 void CALLBACK MACRO_Exit(void)
366 {
367 WINE_TRACE("()\n");
368
369 while (Globals.win_list)
370 WINHELP_ReleaseWindow(Globals.win_list);
371 }
372
373 static void CALLBACK MACRO_ExtAbleItem(LPCSTR str, LONG u)
374 {
375 WINE_FIXME("(\"%s\", %u)\n", str, u);
376 }
377
378 static void CALLBACK MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
379 {
380 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, str4, u1, u2);
381 }
382
383 static void CALLBACK MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
384 {
385 WINE_FIXME("(\"%s\", \"%s\", \"%s\", %u, %u)\n", str1, str2, str3, u1, u2);
386 }
387
388 static BOOL CALLBACK MACRO_FileExist(LPCSTR str)
389 {
390 WINE_TRACE("(\"%s\")\n", str);
391 return GetFileAttributes(str) != INVALID_FILE_ATTRIBUTES;
392 }
393
394 void CALLBACK MACRO_FileOpen(void)
395 {
396 char szFile[MAX_PATH];
397
398 if (WINHELP_GetOpenFileName(szFile, MAX_PATH))
399 {
400 MACRO_JumpContents(szFile, "main");
401 }
402 }
403
404 static void CALLBACK MACRO_Find(void)
405 {
406 WINE_FIXME("()\n");
407 }
408
409 static void CALLBACK MACRO_Finder(void)
410 {
411 WINHELP_CreateIndexWindow(FALSE);
412 }
413
414 static void CALLBACK MACRO_FloatingMenu(void)
415 {
416 WINE_FIXME("()\n");
417 }
418
419 static void CALLBACK MACRO_Flush(void)
420 {
421 WINE_FIXME("()\n");
422 }
423
424 static void CALLBACK MACRO_FocusWindow(LPCSTR lpszWindow)
425 {
426 WINHELP_WINDOW *win;
427
428 WINE_TRACE("(\"%s\")\n", lpszWindow);
429
430 if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
431
432 for (win = Globals.win_list; win; win = win->next)
433 if (!lstrcmpi(win->info->name, lpszWindow))
434 SetFocus(win->hMainWnd);
435 }
436
437 static void CALLBACK MACRO_Generate(LPCSTR str, LONG w, LONG l)
438 {
439 WINE_FIXME("(\"%s\", %x, %x)\n", str, w, l);
440 }
441
442 static void CALLBACK MACRO_GotoMark(LPCSTR str)
443 {
444 WINE_FIXME("(\"%s\")\n", str);
445 }
446
447 void CALLBACK MACRO_HelpOn(void)
448 {
449 WINHELP_WINDOW *win = MACRO_CurrentWindow();
450 LPCSTR file = NULL;
451
452 WINE_TRACE("()\n");
453 if (win && win->page && win->page->file)
454 file = win->page->file->help_on_file;
455
456 if (!file)
457 file = (Globals.wVersion > 4) ? "winhlp32.hlp" : "winhelp.hlp";
458
459 MACRO_JumpContents(file, NULL);
460 }
461
462 void CALLBACK MACRO_HelpOnTop(void)
463 {
464 WINE_FIXME("()\n");
465 }
466
467 void CALLBACK MACRO_History(void)
468 {
469 WINE_TRACE("()\n");
470
471 if (Globals.active_win && !Globals.active_win->hHistoryWnd)
472 {
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);
476 }
477 }
478
479 static void CALLBACK MACRO_IfThen(BOOL b, LPCSTR t)
480 {
481 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
482 }
483
484 static void CALLBACK MACRO_IfThenElse(BOOL b, LPCSTR t, LPCSTR f)
485 {
486 if (b) MACRO_ExecuteMacro(MACRO_CurrentWindow(), t);
487 else MACRO_ExecuteMacro(MACRO_CurrentWindow(), f);
488 }
489
490 static BOOL CALLBACK MACRO_InitMPrint(void)
491 {
492 WINE_FIXME("()\n");
493 return FALSE;
494 }
495
496 static void CALLBACK MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
497 {
498 WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\", %u)\n", str1, str2, str3, str4, u);
499 }
500
501 static void CALLBACK MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
502 {
503 WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);
504 }
505
506 static BOOL CALLBACK MACRO_IsBook(void)
507 {
508 WINE_TRACE("()\n");
509 return Globals.isBook;
510 }
511
512 static BOOL CALLBACK MACRO_IsMark(LPCSTR str)
513 {
514 WINE_FIXME("(\"%s\")\n", str);
515 return FALSE;
516 }
517
518 static BOOL CALLBACK MACRO_IsNotMark(LPCSTR str)
519 {
520 WINE_FIXME("(\"%s\")\n", str);
521 return TRUE;
522 }
523
524 void CALLBACK MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
525 {
526 HLPFILE* hlpfile;
527
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);
534 }
535
536 void CALLBACK MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
537 {
538 HLPFILE* hlpfile;
539
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);
548 }
549
550 static void CALLBACK MACRO_JumpHelpOn(void)
551 {
552 WINE_FIXME("()\n");
553 }
554
555 static void CALLBACK MACRO_JumpID(LPCSTR lpszPathWindow, LPCSTR topic_id)
556 {
557 LPSTR ptr;
558
559 WINE_TRACE("(\"%s\", \"%s\")\n", lpszPathWindow, topic_id);
560 if ((ptr = strchr(lpszPathWindow, '>')) != NULL)
561 {
562 LPSTR tmp;
563 size_t sz = ptr - lpszPathWindow;
564
565 tmp = HeapAlloc(GetProcessHeap(), 0, sz + 1);
566 if (tmp)
567 {
568 memcpy(tmp, lpszPathWindow, sz);
569 tmp[sz] = '\0';
570 MACRO_JumpHash(tmp, ptr + 1, HLPFILE_Hash(topic_id));
571 HeapFree(GetProcessHeap(), 0, tmp);
572 }
573 }
574 else
575 MACRO_JumpHash(lpszPathWindow, NULL, HLPFILE_Hash(topic_id));
576 }
577
578 /* FIXME: this macros is wrong
579 * it should only contain 2 strings, path & window are coded as path>window
580 */
581 static void CALLBACK MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
582 {
583 WINE_FIXME("(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, keyword);
584 }
585
586 static void CALLBACK MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
587 {
588 WINE_FIXME("(\"%s\", %u, \"%s\", \"%s\")\n", str1, u, str2, str3);
589 }
590
591 static void CALLBACK MACRO_Menu(void)
592 {
593 WINE_FIXME("()\n");
594 }
595
596 static void CALLBACK MACRO_MPrintHash(LONG u)
597 {
598 WINE_FIXME("(%u)\n", u);
599 }
600
601 static void CALLBACK MACRO_MPrintID(LPCSTR str)
602 {
603 WINE_FIXME("(\"%s\")\n", str);
604 }
605
606 static void CALLBACK MACRO_Next(void)
607 {
608 WINHELP_WNDPAGE wp;
609
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)
614 {
615 wp.page->file->wRefCount++;
616 wp.wininfo = MACRO_CurrentWindow()->info;
617 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
618 }
619 }
620
621 static void CALLBACK MACRO_NoShow(void)
622 {
623 WINE_FIXME("()\n");
624 }
625
626 void CALLBACK MACRO_PopupContext(LPCSTR str, LONG u)
627 {
628 WINE_FIXME("(\"%s\", %u)\n", str, u);
629 }
630
631 static void CALLBACK MACRO_PopupHash(LPCSTR str, LONG u)
632 {
633 WINE_FIXME("(\"%s\", %u)\n", str, u);
634 }
635
636 static void CALLBACK MACRO_PopupId(LPCSTR str1, LPCSTR str2)
637 {
638 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
639 }
640
641 static void CALLBACK MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
642 {
643 WINE_FIXME("(%i, %i, %u, %u, %u, \"%s\")\n", i1, i2, u1, u2, u3, str);
644 }
645
646 static void CALLBACK MACRO_Prev(void)
647 {
648 WINHELP_WNDPAGE wp;
649
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)
654 {
655 wp.page->file->wRefCount++;
656 wp.wininfo = MACRO_CurrentWindow()->info;
657 WINHELP_CreateHelpWindow(&wp, SW_NORMAL, TRUE);
658 }
659 }
660
661 void CALLBACK MACRO_Print(void)
662 {
663 PRINTDLG printer;
664
665 WINE_TRACE("()\n");
666
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;
686
687 if (PrintDlgA(&printer)) {
688 WINE_FIXME("Print()\n");
689 }
690 }
691
692 void CALLBACK MACRO_PrinterSetup(void)
693 {
694 WINE_FIXME("()\n");
695 }
696
697 static void CALLBACK MACRO_RegisterRoutine(LPCSTR dll_name, LPCSTR proc, LPCSTR args)
698 {
699 void *fn = NULL;
700 int size;
701 WINHELP_DLL* dll;
702
703 WINE_TRACE("(\"%s\", \"%s\", \"%s\")\n", dll_name, proc, args);
704
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 ???)
707 */
708 for (dll = Globals.dlls; dll; dll = dll->next)
709 {
710 if (!strcmp(dll->name, dll_name)) break;
711 }
712 if (!dll)
713 {
714 HANDLE hLib = LoadLibrary(dll_name);
715
716 /* FIXME: the library will not be unloaded until exit of program
717 * We don't send the DW_TERM message
718 */
719 WINE_TRACE("Loading %s\n", dll_name);
720 /* FIXME: should look in the directory where current hlpfile
721 * is loaded from
722 */
723 if (hLib == NULL)
724 {
725 /* FIXME: internationalisation for error messages */
726 WINE_FIXME("Cannot find dll %s\n", dll_name);
727 }
728 else if ((dll = HeapAlloc(GetProcessHeap(), 0, sizeof(*dll))))
729 {
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);
739 }
740 else WINE_WARN("OOM\n");
741 }
742 if (dll && !(fn = GetProcAddress(dll->hLib, proc)))
743 {
744 /* FIXME: internationalisation for error messages */
745 WINE_FIXME("Cannot find proc %s in dll %s\n", dll_name, proc);
746 }
747
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);
757 }
758
759 static void CALLBACK MACRO_RemoveAccelerator(LONG u1, LONG u2)
760 {
761 WINE_FIXME("(%u, %u)\n", u1, u2);
762 }
763
764 static void CALLBACK MACRO_ResetMenu(void)
765 {
766 WINE_FIXME("()\n");
767 }
768
769 static void CALLBACK MACRO_SaveMark(LPCSTR str)
770 {
771 WINE_FIXME("(\"%s\")\n", str);
772 }
773
774 static void CALLBACK MACRO_Search(void)
775 {
776 WINHELP_CreateIndexWindow(TRUE);
777 }
778
779 void CALLBACK MACRO_SetContents(LPCSTR str, LONG u)
780 {
781 WINE_FIXME("(\"%s\", %u)\n", str, u);
782 }
783
784 static void CALLBACK MACRO_SetHelpOnFile(LPCSTR str)
785 {
786 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
787
788 WINE_TRACE("(\"%s\")\n", str);
789
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);
794 }
795
796 static void CALLBACK MACRO_SetPopupColor(LONG r, LONG g, LONG b)
797 {
798 HLPFILE_PAGE* page = MACRO_CurrentWindow()->page;
799
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);
803 }
804
805 static void CALLBACK MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
806 {
807 WINE_FIXME("(\"%s\", \"%s\", %u, %u, \"%s\", \"%s\")\n", str1, str2, u1, u2, str3, str4);
808 }
809
810 static void CALLBACK MACRO_ShortCut(LPCSTR str1, LPCSTR str2, LONG w, LONG l, LPCSTR str)
811 {
812 WINE_FIXME("(\"%s\", \"%s\", %x, %x, \"%s\")\n", str1, str2, w, l, str);
813 }
814
815 static void CALLBACK MACRO_TCard(LONG u)
816 {
817 WINE_FIXME("(%u)\n", u);
818 }
819
820 static void CALLBACK MACRO_Test(LONG u)
821 {
822 WINE_FIXME("(%u)\n", u);
823 }
824
825 static BOOL CALLBACK MACRO_TestALink(LPCSTR str)
826 {
827 WINE_FIXME("(\"%s\")\n", str);
828 return FALSE;
829 }
830
831 static BOOL CALLBACK MACRO_TestKLink(LPCSTR str)
832 {
833 WINE_FIXME("(\"%s\")\n", str);
834 return FALSE;
835 }
836
837 static void CALLBACK MACRO_UncheckItem(LPCSTR str)
838 {
839 WINE_FIXME("(\"%s\")\n", str);
840 }
841
842 static void CALLBACK MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
843 {
844 WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);
845 }
846
847
848 /**************************************************/
849 /* Macro table */
850 /**************************************************/
851
852 /* types:
853 * U: 32 bit unsigned int
854 * I: 32 bit signed int
855 * S: string
856 * v: unknown (32 bit entity)
857 */
858
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}
952 };
953
954 static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len)
955 {
956 struct MacroDesc* md;
957
958 for (md = start; md->name && len != 0; md++, len--)
959 {
960 if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))
961 {
962 lr->proto = md->arguments;
963 lr->function = md->fn;
964 return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;
965 }
966 }
967 return EMPTY;
968 }
969
970 int MACRO_Lookup(const char* name, struct lexret* lr)
971 {
972 int ret;
973
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;
978
979 lr->string = name;
980 return IDENTIFIER;
981 }