No longer using explicit values for resource identification.
[wine] / programs / winhelp / macro.c
1 /*
2  * Help Viewer
3  *
4  * Copyright 1996 Ulrich Schmid
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "windows.h"
22 #include "commdlg.h"
23 #include "winhelp.h"
24 #include "macro.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
29
30 /*******      helper functions     *******/
31 WINHELP_BUTTON**        MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name)
32 {
33     WINHELP_BUTTON**    b;
34
35     for (b = &win->first_button; *b; b = &(*b)->next)
36         if (!lstrcmpi(name, (*b)->lpszID)) break;
37     return b;
38 }
39
40 /******* real macro implementation *******/
41
42 void MACRO_About(void)
43 {
44     WINE_FIXME("About()\n");
45 }
46
47 void MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str)
48 {
49     WINE_FIXME("AddAccelerator(%lu, %lu, \"%s\")\n", u1, u2, str);
50 }
51
52 void MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2)
53 {
54     WINE_FIXME("ALink(\"%s\", %lu, \"%s\")\n", str1, u, str2);
55 }
56
57 void MACRO_Annotate(void)
58 {
59     WINE_FIXME("Annotate()\n");
60 }
61
62 void MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4)
63 {
64     WINE_FIXME("AppendItem(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);
65 }
66
67 void MACRO_Back(void)
68 {
69     WINE_FIXME("Back()\n");
70 }
71
72 void MACRO_BackFlush(void)
73 {
74     WINE_FIXME("BackFlush()\n");
75 }
76
77 void MACRO_BookmarkDefine(void)
78 {
79     WINE_FIXME("BookmarkDefine()\n");
80 }
81
82 void MACRO_BookmarkMore(void)
83 {
84     WINE_FIXME("BookmarkMore()\n");
85 }
86
87 void MACRO_BrowseButtons(void)
88 {
89     MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");
90     MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");
91 }
92
93 void MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro)
94 {
95     WINHELP_WINDOW*     win = Globals.active_win;
96     WINHELP_BUTTON*     button;
97     WINHELP_BUTTON**    b;
98     LONG                size;
99     LPSTR               ptr;
100
101     b = MACRO_LookupButton(win, id);
102     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
103
104     size = sizeof(WINHELP_BUTTON) + lstrlen(id) + 
105         lstrlen((*b)->lpszName) + lstrlen(macro) + 3;
106
107     button = HeapAlloc(GetProcessHeap(), 0, size);
108     if (!button) return;
109
110     button->next  = (*b)->next;
111     button->hWnd  = (*b)->hWnd;
112     button->wParam = (*b)->wParam;
113
114     ptr = (char*)button + sizeof(WINHELP_BUTTON);
115
116     lstrcpy(ptr, (LPSTR) id);
117     button->lpszID = ptr;
118     ptr += lstrlen(id) + 1;
119
120     lstrcpy(ptr, (LPSTR) (*b)->lpszName);
121     button->lpszName = ptr;
122     ptr += lstrlen((*b)->lpszName) + 1;
123
124     lstrcpy(ptr, (LPSTR) macro);
125     button->lpszMacro = ptr;
126
127     *b = button;
128
129     SendMessage(win->hMainWnd, WM_USER, 0, 0);
130 }
131
132 void MACRO_ChangeEnable(LPCSTR id, LPCSTR macro)
133 {
134     MACRO_ChangeButtonBinding(id, macro);
135     MACRO_EnableButton(id);
136 }
137
138 void MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2)
139 {
140     WINE_FIXME("ChangeItemBinding(\"%s\", \"%s\")\n", str1, str2);
141 }
142
143 void MACRO_CheckItem(LPCSTR str)
144 {
145     WINE_FIXME("CheckItem(\"%s\")\n", str);
146 }
147
148 void MACRO_CloseSecondarys(void)
149 {
150     WINHELP_WINDOW *win;
151     for (win = Globals.win_list; win; win = win->next)
152         if (win->lpszName && lstrcmpi(win->lpszName, "main"))
153             DestroyWindow(win->hMainWnd);
154 }
155
156 void MACRO_CloseWindow(LPCSTR lpszWindow)
157 {
158     WINHELP_WINDOW *win;
159     if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";
160
161     for (win = Globals.win_list; win; win = win->next)
162         if (win->lpszName && !lstrcmpi(win->lpszName, lpszWindow))
163             DestroyWindow(win->hMainWnd);
164 }
165
166 void MACRO_Compare(LPCSTR str)
167 {
168     WINE_FIXME("Compare(\"%s\")\n", str);
169 }
170
171 void MACRO_Contents(void)
172 {
173     if (Globals.active_win->page)
174         MACRO_JumpContents(Globals.active_win->page->file->lpszPath, NULL);
175 }
176
177 void MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u)
178 {
179     WINE_FIXME("ControlPanel(\"%s\", \"%s\", %lu)\n", str1, str2, u);
180 }
181
182 void MACRO_CopyDialog(void)
183 {
184     WINE_FIXME("CopyDialog()\n");
185 }
186
187 void MACRO_CopyTopic(void)
188 {
189     WINE_FIXME("CopyTopic()\n");
190 }
191
192 void MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro)
193 {
194     WINHELP_WINDOW *win = Globals.active_win;
195     WINHELP_BUTTON *button, **b;
196     LONG            size;
197     LPSTR           ptr;
198
199     size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;
200
201     button = HeapAlloc(GetProcessHeap(), 0, size);
202     if (!button) return;
203
204     button->next  = 0;
205     button->hWnd  = 0;
206
207     ptr = (char*)button + sizeof(WINHELP_BUTTON);
208
209     lstrcpy(ptr, (LPSTR) id);
210     button->lpszID = ptr;
211     ptr += lstrlen(id) + 1;
212
213     lstrcpy(ptr, (LPSTR) name);
214     button->lpszName = ptr;
215     ptr += lstrlen(name) + 1;
216
217     lstrcpy(ptr, (LPSTR) macro);
218     button->lpszMacro = ptr;
219
220     button->wParam = WH_FIRST_BUTTON;
221     for (b = &win->first_button; *b; b = &(*b)->next)
222         button->wParam = max(button->wParam, (*b)->wParam + 1);
223     *b = button;
224
225     SendMessage(win->hMainWnd, WM_USER, 0, 0);
226 }
227
228 void MACRO_DeleteItem(LPCSTR str)
229 {
230     WINE_FIXME("DeleteItem(\"%s\")\n", str);
231 }
232
233 void MACRO_DeleteMark(LPCSTR str)
234 {
235     WINE_FIXME("DeleteMark(\"%s\")\n", str);
236 }
237
238 void MACRO_DestroyButton(LPCSTR str)
239 {
240     WINE_FIXME("DestroyButton(\"%s\")\n", str);
241 }
242
243 void MACRO_DisableButton(LPCSTR id)
244 {
245     WINHELP_BUTTON**    b;
246
247     b = MACRO_LookupButton(Globals.active_win, id);
248     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
249
250     EnableWindow((*b)->hWnd, FALSE);
251 }
252
253 void MACRO_DisableItem(LPCSTR str)
254 {
255     WINE_FIXME("DisableItem(\"%s\")\n", str);
256 }
257
258 void MACRO_EnableButton(LPCSTR id)
259 {
260     WINHELP_BUTTON**    b;
261
262     b = MACRO_LookupButton(Globals.active_win, id);
263     if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}
264
265     EnableWindow((*b)->hWnd, TRUE);
266 }
267
268 void MACRO_EnableItem(LPCSTR str)
269 {
270     WINE_FIXME("EnableItem(\"%s\")\n", str);
271 }
272
273 void MACRO_EndMPrint(void)
274 {
275     WINE_FIXME("EndMPrint()\n");
276 }
277
278 void MACRO_ExecFile(LPCSTR str1, LPCSTR str2, LONG u, LPCSTR str3)
279 {
280     WINE_FIXME("ExecFile(\"%s\", \"%s\", %lu, \"%s\")\n", str1, str2, u, str3);
281 }
282
283 void MACRO_ExecProgram(LPCSTR str, LONG u)
284 {
285     WINE_FIXME("ExecProgram(\"%s\", %lu)\n", str, u);
286 }
287
288 void MACRO_Exit(void)
289 {
290     while (Globals.win_list)
291         DestroyWindow(Globals.win_list->hMainWnd);
292 }
293
294 void MACRO_ExtAbleItem(LPCSTR str, LONG u)
295 {
296     WINE_FIXME("ExtAbleItem(\"%s\", %lu)\n", str, u);
297 }
298
299 void MACRO_ExtInsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u1, LONG u2)
300 {
301     WINE_FIXME("ExtInsertItem(\"%s\", \"%s\", \"%s\", \"%s\", %lu, %lu)\n", str1, str2, str3, str4, u1, u2);
302 }
303
304 void MACRO_ExtInsertMenu(LPCSTR str1, LPCSTR str2, LPCSTR str3, LONG u1, LONG u2)
305 {
306     WINE_FIXME("ExtInsertMenu(\"%s\", \"%s\", \"%s\", %lu, %lu)\n", str1, str2, str3, u1, u2);
307 }
308
309 BOOL MACRO_FileExist(LPCSTR str)
310 {
311     return GetFileAttributes(str) != 0xFFFFFFFF;
312 }
313
314 void MACRO_FileOpen(void)
315 {
316     OPENFILENAME openfilename;
317     CHAR szPath[MAX_PATHNAME_LEN];
318     CHAR szDir[MAX_PATHNAME_LEN];
319     CHAR szzFilter[2 * MAX_STRING_LEN + 100];
320     LPSTR p = szzFilter;
321
322     LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
323     p += strlen(p) + 1;
324     lstrcpy(p, "*.hlp");
325     p += strlen(p) + 1;
326     LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
327     p += strlen(p) + 1;
328     lstrcpy(p, "*.*");
329     p += strlen(p) + 1;
330     *p = '\0';
331
332     GetCurrentDirectory(sizeof(szDir), szDir);
333
334     szPath[0]='\0';
335
336     openfilename.lStructSize       = 0;
337     openfilename.hwndOwner         = Globals.active_win->hMainWnd;
338     openfilename.hInstance         = Globals.hInstance;
339     openfilename.lpstrFilter       = szzFilter;
340     openfilename.lpstrCustomFilter = 0;
341     openfilename.nMaxCustFilter    = 0;
342     openfilename.nFilterIndex      = 1;
343     openfilename.lpstrFile         = szPath;
344     openfilename.nMaxFile          = sizeof(szPath);
345     openfilename.lpstrFileTitle    = 0;
346     openfilename.nMaxFileTitle     = 0;
347     openfilename.lpstrInitialDir   = szDir;
348     openfilename.lpstrTitle        = 0;
349     openfilename.Flags             = 0;
350     openfilename.nFileOffset       = 0;
351     openfilename.nFileExtension    = 0;
352     openfilename.lpstrDefExt       = 0;
353     openfilename.lCustData         = 0;
354     openfilename.lpfnHook          = 0;
355     openfilename.lpTemplateName    = 0;
356
357     if (GetOpenFileName(&openfilename))
358         WINHELP_CreateHelpWindowByHash(szPath, 0, "main", FALSE, 0, NULL, SW_SHOWNORMAL);
359 }
360
361 void MACRO_Find(void)
362 {
363     WINE_FIXME("Find()\n");
364 }
365
366 void MACRO_Finder(void)
367 {
368     WINE_FIXME("Finder()\n");
369 }
370
371 void MACRO_FloatingMenu(void)
372 {
373     WINE_FIXME("FloatingMenu()\n");
374 }
375
376 void MACRO_Flush(void)
377 {
378     WINE_FIXME("Flush()\n");
379 }
380
381 void MACRO_FocusWindow(LPCSTR str)
382 {
383     WINE_FIXME("FocusWindow(\"%s\")\n", str);
384 }
385
386 void MACRO_Generate(LPCSTR str, WPARAM w, LPARAM l)
387 {
388     WINE_FIXME("Generate(\"%s\", %x, %lx)\n", str, w, l);
389 }
390
391 void MACRO_GotoMark(LPCSTR str)
392 {
393     WINE_FIXME("GotoMark(\"%s\")\n", str);
394 }
395
396 void MACRO_HelpOn(void)
397 {
398     MACRO_JumpContents((Globals.wVersion > 4) ? "winhelp32.hlp" : "winhelp.hlp", NULL);
399 }
400
401 void MACRO_HelpOnTop(void)
402 {
403     WINE_FIXME("HelpOnTop()\n");
404 }
405
406 void MACRO_History(void)
407 {
408     WINE_FIXME("History()\n");
409 }
410
411 BOOL MACRO_InitMPrint(void)
412 {
413     WINE_FIXME("InitMPrint()\n");
414     return FALSE;
415 }
416
417 void MACRO_InsertItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4, LONG u)
418 {
419     WINE_FIXME("InsertItem(\"%s\", \"%s\", \"%s\", \"%s\", %lu)\n", str1, str2, str3, str4, u);
420 }
421
422 void MACRO_InsertMenu(LPCSTR str1, LPCSTR str2, LONG u)
423 {
424     WINE_FIXME("InsertMenu(\"%s\", \"%s\", %lu)\n", str1, str2, u);
425 }
426
427 BOOL MACRO_IsBook(void)
428 {
429     WINE_FIXME("IsBook()\n");
430     return TRUE;
431 }
432
433 BOOL MACRO_IsMark(LPCSTR str)
434 {
435     WINE_FIXME("IsMark(\"%s\")\n", str);
436     return FALSE;
437 }
438
439 BOOL MACRO_IsNotMark(LPCSTR str)
440 {
441     WINE_FIXME("IsNotMark(\"%s\")\n", str);
442     return TRUE;
443 }
444
445 void MACRO_JumpContents(LPCSTR lpszPath, LPCSTR lpszWindow)
446 {
447     WINHELP_CreateHelpWindowByHash(lpszPath, 0, lpszWindow, FALSE, 0, NULL, SW_NORMAL);
448 }
449
450 void MACRO_JumpContext(LPCSTR lpszPath, LPCSTR lpszWindow, LONG context)
451 {
452     WINE_FIXME("JumpContext(\"%s\", \"%s\", %lu)\n", lpszPath, lpszWindow, context);
453 }
454
455 void MACRO_JumpHash(LPCSTR lpszPath, LPCSTR lpszWindow, LONG lHash)
456 {
457     WINHELP_CreateHelpWindowByHash(lpszPath, lHash, lpszWindow, FALSE, 0, NULL, SW_NORMAL);
458 }
459
460 void MACRO_JumpHelpOn(void)
461 {
462     WINE_FIXME("JumpHelpOn()\n");
463 }
464
465 void MACRO_JumpID(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR topic_id)
466 {
467     MACRO_JumpHash(lpszPath, lpszWindow, HLPFILE_Hash(topic_id));
468 }
469
470 void MACRO_JumpKeyword(LPCSTR lpszPath, LPCSTR lpszWindow, LPCSTR keyword)
471 {
472     WINE_FIXME("JumpKeyword(\"%s\", \"%s\", \"%s\")\n", lpszPath, lpszWindow, keyword);
473 }
474
475 void MACRO_KLink(LPCSTR str1, LONG u, LPCSTR str2, LPCSTR str3)
476 {
477     WINE_FIXME("KLink(\"%s\", %lu, \"%s\", \"%s\")\n", str1, u, str2, str3);
478 }
479
480 void MACRO_Menu(void)
481 {
482     WINE_FIXME("Menu()\n");
483 }
484
485 void MACRO_MPrintHash(LONG u)
486 {
487     WINE_FIXME("MPrintHash(%lu)\n", u);
488 }
489
490 void MACRO_MPrintID(LPCSTR str)
491 {
492     WINE_FIXME("MPrintID(\"%s\")\n", str);
493 }
494
495 void MACRO_Next(void)
496 {
497     if (Globals.active_win->page->next)
498         WINHELP_CreateHelpWindowByPage(Globals.active_win->page->next, "main", FALSE, 0, NULL, SW_NORMAL);
499 }
500
501 void MACRO_NoShow(void)
502 {
503     WINE_FIXME("NoShow()\n");
504 }
505
506 void MACRO_PopupContext(LPCSTR str, LONG u)
507 {
508     WINE_FIXME("PopupContext(\"%s\", %lu)\n", str, u);
509 }
510
511 void MACRO_PopupHash(LPCSTR str, LONG u)
512 {
513     WINE_FIXME("PopupHash(\"%s\", %lu)\n", str, u);
514 }
515
516 void MACRO_PopupId(LPCSTR str1, LPCSTR str2)
517 {
518     WINE_FIXME("PopupId(\"%s\", \"%s\")\n", str1, str2);
519 }
520
521 void MACRO_PositionWindow(LONG i1, LONG i2, LONG u1, LONG u2, LONG u3, LPCSTR str)
522 {
523     WINE_FIXME("PositionWindow(%li, %li, %lu, %lu, %lu, \"%s\")\n", i1, i2, u1, u2, u3, str);
524 }
525
526 void MACRO_Prev(void)
527 {
528     if (Globals.active_win->page->prev)
529         WINHELP_CreateHelpWindowByPage(Globals.active_win->page->prev, "main", FALSE, 0, NULL, SW_NORMAL);
530 }
531
532 void MACRO_Print(void)
533 {
534     PRINTDLG printer;
535
536     printer.lStructSize         = sizeof(printer);
537     printer.hwndOwner           = Globals.active_win->hMainWnd;
538     printer.hInstance           = Globals.hInstance;
539     printer.hDevMode            = 0;
540     printer.hDevNames           = 0;
541     printer.hDC                 = 0;
542     printer.Flags               = 0;
543     printer.nFromPage           = 0;
544     printer.nToPage             = 0;
545     printer.nMinPage            = 0;
546     printer.nMaxPage            = 0;
547     printer.nCopies             = 0;
548     printer.lCustData           = 0;
549     printer.lpfnPrintHook       = 0;
550     printer.lpfnSetupHook       = 0;
551     printer.lpPrintTemplateName = 0;
552     printer.lpSetupTemplateName = 0;
553     printer.hPrintTemplate      = 0;
554     printer.hSetupTemplate      = 0;
555
556     if (PrintDlgA(&printer)) {
557         WINE_FIXME("Print()\n");
558     }
559 }
560
561 void MACRO_PrinterSetup(void)
562 {
563     WINE_FIXME("PrinterSetup()\n");
564 }
565
566 void MACRO_RegisterRoutine(LPCSTR str1, LPCSTR str2, LPCSTR str3)
567 {
568     WINE_FIXME("RegisterRoutine(\"%s\", \"%s\", \"%s\")\n", str1, str2, str3);
569 }
570
571 void MACRO_RemoveAccelerator(LONG u1, LONG u2)
572 {
573     WINE_FIXME("RemoveAccelerator(%lu, %lu)\n", u1, u2);
574 }
575
576 void MACRO_ResetMenu(void)
577 {
578     WINE_FIXME("ResetMenu()\n");
579 }
580
581 void MACRO_SaveMark(LPCSTR str)
582 {
583     WINE_FIXME("SaveMark(\"%s\")\n", str);
584 }
585
586 void MACRO_Search(void)
587 {
588     WINE_FIXME("Search()\n");
589 }
590
591 void MACRO_SetContents(LPCSTR str, LONG u)
592 {
593     WINE_FIXME("SetContents(\"%s\", %lu)\n", str, u);
594 }
595
596 void MACRO_SetHelpOnFile(LPCSTR str)
597 {
598     WINE_FIXME("SetHelpOnFile(\"%s\")\n", str);
599 }
600
601 void MACRO_SetPopupColor(LONG u1, LONG u2, LONG u3)
602 {
603     WINE_FIXME("SetPopupColor(%lu, %lu, %lu)\n", u1, u2, u3);
604 }
605
606 void MACRO_ShellExecute(LPCSTR str1, LPCSTR str2, LONG u1, LONG u2, LPCSTR str3, LPCSTR str4)
607 {
608     WINE_FIXME("ShellExecute(\"%s\", \"%s\", %lu, %lu, \"%s\", \"%s\")\n", str1, str2, u1, u2, str3, str4);
609 }
610
611 void MACRO_ShortCut(LPCSTR str1, LPCSTR str2, WPARAM w, LPARAM l, LPCSTR str)
612 {
613     WINE_FIXME("ShortCut(\"%s\", \"%s\", %x, %lx, \"%s\")\n", str1, str2, w, l, str);
614 }
615
616 void MACRO_TCard(LONG u)
617 {
618     WINE_FIXME("TCard(%lu)\n", u);
619 }
620
621 void MACRO_Test(LONG u)
622 {
623     WINE_FIXME("Test(%lu)\n", u);
624 }
625
626 BOOL MACRO_TestALink(LPCSTR str)
627 {
628     WINE_FIXME("TestALink(\"%s\")\n", str);
629     return FALSE;
630 }
631
632 BOOL MACRO_TestKLink(LPCSTR str)
633 {
634     WINE_FIXME("TestKLink(\"%s\")\n", str);
635     return FALSE;
636 }
637
638 void MACRO_UncheckItem(LPCSTR str)
639 {
640     WINE_FIXME("UncheckItem(\"%s\")\n", str);
641 }
642
643 void MACRO_UpdateWindow(LPCSTR str1, LPCSTR str2)
644 {
645     WINE_FIXME("UpdateWindow(\"%s\", \"%s\")\n", str1, str2);
646 }