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