macro.c

来自「这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统」· C语言 代码 · 共 929 行 · 第 1/2 页

C
929
字号
/* * Help Viewer * * Copyright 1996 Ulrich Schmid * Copyright 2002 Eric Pouech * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */#define WIN32_LEAN_AND_MEAN#include <stdio.h>#include "windows.h"#include "commdlg.h"#include "winhelp.h"#include "wine/debug.h"WINE_DEFAULT_DEBUG_CHANNEL(winhelp);/**************************************************//*               Macro table                      *//**************************************************/struct MacroDesc {    const char* name;    const char* alias;    BOOL        isBool;    const char* arguments;    FARPROC     fn;};/* types: *      U:      32 bit unsigned int *      I:      32 bit signed int *      S:      string *      v:      unknown (32 bit entity) */static struct MacroDesc MACRO_Builtins[] = {    {"About",               NULL, 0, "",       (FARPROC)MACRO_About},    {"AddAccelerator",      "AA", 0, "UUS",    (FARPROC)MACRO_AddAccelerator},    {"ALink",               "AL", 0, "SUS",    (FARPROC)MACRO_ALink},    {"Annotate",            NULL, 0, "",       (FARPROC)MACRO_Annotate},    {"AppendItem",          NULL, 0, "SSSS",   (FARPROC)MACRO_AppendItem},    {"Back",                NULL, 0, "",       (FARPROC)MACRO_Back},    {"BackFlush",           "BF", 0, "",       (FARPROC)MACRO_BackFlush},    {"BookmarkDefine",      NULL, 0, "",       (FARPROC)MACRO_BookmarkDefine},    {"BookmarkMore",        NULL, 0, "",       (FARPROC)MACRO_BookmarkMore},    {"BrowseButtons",       NULL, 0, "",       (FARPROC)MACRO_BrowseButtons},    {"ChangeButtonBinding", "CBB",0, "SS",     (FARPROC)MACRO_ChangeButtonBinding},    {"ChangeEnable",        "CE", 0, "SS",     (FARPROC)MACRO_ChangeEnable},    {"ChangeItemBinding",   "CIB",0, "SS",     (FARPROC)MACRO_ChangeItemBinding},    {"CheckItem",           "CI", 0, "S",      (FARPROC)MACRO_CheckItem},    {"CloseSecondarys",     "CS", 0, "",       (FARPROC)MACRO_CloseSecondarys},    {"CloseWindow",         "CW", 0, "S",      (FARPROC)MACRO_CloseWindow},    {"Compare",             NULL, 0, "S",      (FARPROC)MACRO_Compare},    {"Contents",            NULL, 0, "",       (FARPROC)MACRO_Contents},    {"ControlPanel",        NULL, 0, "SSU",    (FARPROC)MACRO_ControlPanel},    {"CopyDialog",          NULL, 0, "",       (FARPROC)MACRO_CopyDialog},    {"CopyTopic",           "CT", 0, "",       (FARPROC)MACRO_CopyTopic},    {"CreateButton",        "CB", 0, "SSS",    (FARPROC)MACRO_CreateButton},    {"DeleteItem",          NULL, 0, "S",      (FARPROC)MACRO_DeleteItem},    {"DeleteMark",          NULL, 0, "S",      (FARPROC)MACRO_DeleteMark},    {"DestroyButton",       NULL, 0, "S",      (FARPROC)MACRO_DestroyButton},    {"DisableButton",       "DB", 0, "S",      (FARPROC)MACRO_DisableButton},    {"DisableItem",         "DI", 0, "S",      (FARPROC)MACRO_DisableItem},    {"EnableButton",        "EB", 0, "S",      (FARPROC)MACRO_EnableButton},    {"EnableItem",          "EI", 0, "S",      (FARPROC)MACRO_EnableItem},    {"EndMPrint",           NULL, 0, "",       (FARPROC)MACRO_EndMPrint},    {"ExecFile",            "EF", 0, "SSUS",   (FARPROC)MACRO_ExecFile},    {"ExecProgram",         "EP", 0, "SU",     (FARPROC)MACRO_ExecProgram},    {"Exit",                NULL, 0, "",       (FARPROC)MACRO_Exit},    {"ExtAbleItem",         NULL, 0, "SU",     (FARPROC)MACRO_ExtAbleItem},    {"ExtInsertItem",       NULL, 0, "SSSSUU", (FARPROC)MACRO_ExtInsertItem},    {"ExtInsertMenu",       NULL, 0, "SSSUU",  (FARPROC)MACRO_ExtInsertMenu},    {"FileExist",           "FE", 1, "S",      (FARPROC)MACRO_FileExist},    {"FileOpen",            "FO", 0, "",       (FARPROC)MACRO_FileOpen},    {"Find",                NULL, 0, "",       (FARPROC)MACRO_Find},    {"Finder",              "FD", 0, "",       (FARPROC)MACRO_Finder},    {"FloatingMenu",        NULL, 0, "",       (FARPROC)MACRO_FloatingMenu},    {"Flush",               "FH", 0, "",       (FARPROC)MACRO_Flush},    {"FocusWindow",         NULL, 0, "S",      (FARPROC)MACRO_FocusWindow},    {"Generate",            NULL, 0, "SUU",    (FARPROC)MACRO_Generate},    {"GotoMark",            NULL, 0, "S",      (FARPROC)MACRO_GotoMark},    {"HelpOn",              NULL, 0, "",       (FARPROC)MACRO_HelpOn},    {"HelpOnTop",           NULL, 0, "",       (FARPROC)MACRO_HelpOnTop},    {"History",             NULL, 0, "",       (FARPROC)MACRO_History},    {"InitMPrint",          NULL, 1, "",       (FARPROC)MACRO_InitMPrint},    {"InsertItem",          NULL, 0, "SSSSU",  (FARPROC)MACRO_InsertItem},    {"InsertMenu",          NULL, 0, "SSU",    (FARPROC)MACRO_InsertMenu},    {"IfThen",              "IF", 0, "BS",     (FARPROC)MACRO_IfThen},    {"IfThenElse",          "IE", 0, "BSS",    (FARPROC)MACRO_IfThenElse},    {"IsBook",              NULL, 1, "",       (FARPROC)MACRO_IsBook},    {"IsMark",              NULL, 1, "S",      (FARPROC)MACRO_IsMark},    {"IsNotMark",           "NM", 1, "S",      (FARPROC)MACRO_IsNotMark},    {"JumpContents",        NULL, 0, "SS",     (FARPROC)MACRO_JumpContents},    {"JumpContext",         "JC", 0, "SSU",    (FARPROC)MACRO_JumpContext},    {"JumpHash",            "JH", 0, "SSU",    (FARPROC)MACRO_JumpHash},    {"JumpHelpOn",          NULL, 0, "",       (FARPROC)MACRO_JumpHelpOn},    {"JumpID",              "JI", 0, "SSS",    (FARPROC)MACRO_JumpID},    {"JumpKeyword",         "JK", 0, "SSS",    (FARPROC)MACRO_JumpKeyword},    {"KLink",               "KL", 0, "SUSS",   (FARPROC)MACRO_KLink},    {"Menu",                "MU", 0, "",       (FARPROC)MACRO_Menu},    {"MPrintHash",          NULL, 0, "U",      (FARPROC)MACRO_MPrintHash},    {"MPrintID",            NULL, 0, "S",      (FARPROC)MACRO_MPrintID},    {"Next",                NULL, 0, "",       (FARPROC)MACRO_Next},    {"NoShow",              NULL, 0, "",       (FARPROC)MACRO_NoShow},    {"PopupContext",        "PC", 0, "SU",     (FARPROC)MACRO_PopupContext},    {"PopupHash",           NULL, 0, "SU",     (FARPROC)MACRO_PopupHash},    {"PopupId",             "PI", 0, "SS",     (FARPROC)MACRO_PopupId},    {"PositionWindow",      "PW", 0, "IIUUUS", (FARPROC)MACRO_PositionWindow},    {"Prev",                NULL, 0, "",       (FARPROC)MACRO_Prev},    {"Print",               NULL, 0, "",       (FARPROC)MACRO_Print},    {"PrinterSetup",        NULL, 0, "",       (FARPROC)MACRO_PrinterSetup},    {"RegisterRoutine",     "RR", 0, "SSS",    (FARPROC)MACRO_RegisterRoutine},    {"RemoveAccelerator",   "RA", 0, "UU",     (FARPROC)MACRO_RemoveAccelerator},    {"ResetMenu",           NULL, 0, "",       (FARPROC)MACRO_ResetMenu},    {"SaveMark",            NULL, 0, "S",      (FARPROC)MACRO_SaveMark},    {"Search",              NULL, 0, "",       (FARPROC)MACRO_Search},    {"SetContents",         NULL, 0, "SU",     (FARPROC)MACRO_SetContents},    {"SetHelpOnFile",       NULL, 0, "S",      (FARPROC)MACRO_SetHelpOnFile},    {"SetPopupColor",       "SPC",0, "UUU",    (FARPROC)MACRO_SetPopupColor},    {"ShellExecute",        "SE", 0, "SSUUSS", (FARPROC)MACRO_ShellExecute},    {"ShortCut",            "SH", 0, "SSUUS",  (FARPROC)MACRO_ShortCut},    {"TCard",               NULL, 0, "U",      (FARPROC)MACRO_TCard},    {"Test",                NULL, 0, "U",      (FARPROC)MACRO_Test},    {"TestALink",           NULL, 1, "S",      (FARPROC)MACRO_TestALink},    {"TestKLink",           NULL, 1, "S",      (FARPROC)MACRO_TestKLink},    {"UncheckItem",         "UI", 0, "S",      (FARPROC)MACRO_UncheckItem},    {"UpdateWindow",        "UW", 0, "SS",     (FARPROC)MACRO_UpdateWindow},    {NULL,                  NULL, 0, NULL,     NULL}};static struct MacroDesc*MACRO_Loaded /* = NULL */;static unsigned         MACRO_NumLoaded /* = 0 */;static int MACRO_DoLookUp(struct MacroDesc* start, const char* name, struct lexret* lr, unsigned len){    struct MacroDesc*   md;    for (md = start; md->name && len != 0; md++, len--)    {        if (strcasecmp(md->name, name) == 0 || (md->alias != NULL && strcasecmp(md->alias, name) == 0))        {            lr->proto = md->arguments;            lr->function = md->fn;            return md->isBool ? BOOL_FUNCTION : VOID_FUNCTION;        }    }    return EMPTY;}int MACRO_Lookup(const char* name, struct lexret* lr){    int ret;    if ((ret = MACRO_DoLookUp(MACRO_Builtins, name, lr, -1)) != EMPTY)        return ret;    if (MACRO_Loaded && (ret = MACRO_DoLookUp(MACRO_Loaded, name, lr, MACRO_NumLoaded)) != EMPTY)        return ret;    lr->string = name;    return IDENTIFIER;}/*******      helper functions     *******/static WINHELP_BUTTON**        MACRO_LookupButton(WINHELP_WINDOW* win, LPCSTR name){    WINHELP_BUTTON**    b;    for (b = &win->first_button; *b; b = &(*b)->next)        if (!lstrcmpi(name, (*b)->lpszID)) break;    return b;}/******* real macro implementation *******/void CALLBACK MACRO_About(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_AddAccelerator(LONG u1, LONG u2, LPCSTR str){    WINE_FIXME("(%u, %u, \"%s\")\n", u1, u2, str);}void CALLBACK MACRO_ALink(LPCSTR str1, LONG u, LPCSTR str2){    WINE_FIXME("(\"%s\", %u, \"%s\")\n", str1, u, str2);}void CALLBACK MACRO_Annotate(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_AppendItem(LPCSTR str1, LPCSTR str2, LPCSTR str3, LPCSTR str4){    WINE_FIXME("(\"%s\", \"%s\", \"%s\", \"%s\")\n", str1, str2, str3, str4);}void CALLBACK MACRO_Back(void){    WINHELP_WINDOW* win = Globals.active_win;    WINE_TRACE("()\n");    if (win && win->backIndex >= 2)        WINHELP_CreateHelpWindow(win->back[--win->backIndex - 1],                                 win->info, SW_SHOW);}void CALLBACK MACRO_BackFlush(void){    WINHELP_WINDOW* win = Globals.active_win;    WINE_TRACE("()\n");    if (win)    {        int     i;        for (i = 0; i < win->backIndex; i++)        {            HLPFILE_FreeHlpFile(win->back[i]->file);            win->back[i] = NULL;        }        win->backIndex = 0;    }}void CALLBACK MACRO_BookmarkDefine(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_BookmarkMore(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_BrowseButtons(void){    WINE_TRACE("()\n");    MACRO_CreateButton("BTN_PREV", "&<<", "Prev()");    MACRO_CreateButton("BTN_NEXT", "&>>", "Next()");}void CALLBACK MACRO_ChangeButtonBinding(LPCSTR id, LPCSTR macro){    WINHELP_WINDOW*     win = Globals.active_win;    WINHELP_BUTTON*     button;    WINHELP_BUTTON**    b;    LONG                size;    LPSTR               ptr;    WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);    b = MACRO_LookupButton(win, id);    if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}    size = sizeof(WINHELP_BUTTON) + lstrlen(id) +        lstrlen((*b)->lpszName) + lstrlen(macro) + 3;    button = HeapAlloc(GetProcessHeap(), 0, size);    if (!button) return;    button->next  = (*b)->next;    button->hWnd  = (*b)->hWnd;    button->wParam = (*b)->wParam;    ptr = (char*)button + sizeof(WINHELP_BUTTON);    lstrcpy(ptr, id);    button->lpszID = ptr;    ptr += lstrlen(id) + 1;    lstrcpy(ptr, (*b)->lpszName);    button->lpszName = ptr;    ptr += lstrlen((*b)->lpszName) + 1;    lstrcpy(ptr, macro);    button->lpszMacro = ptr;    *b = button;    SendMessage(win->hMainWnd, WM_USER, 0, 0);}void CALLBACK MACRO_ChangeEnable(LPCSTR id, LPCSTR macro){    WINE_TRACE("(\"%s\", \"%s\")\n", id, macro);    MACRO_ChangeButtonBinding(id, macro);    MACRO_EnableButton(id);}void CALLBACK MACRO_ChangeItemBinding(LPCSTR str1, LPCSTR str2){    WINE_FIXME("(\"%s\", \"%s\")\n", str1, str2);}void CALLBACK MACRO_CheckItem(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_CloseSecondarys(void){    WINHELP_WINDOW *win;    WINE_TRACE("()\n");    for (win = Globals.win_list; win; win = win->next)        if (win->lpszName && lstrcmpi(win->lpszName, "main"))            DestroyWindow(win->hMainWnd);}void CALLBACK MACRO_CloseWindow(LPCSTR lpszWindow){    WINHELP_WINDOW *win;    WINE_TRACE("(\"%s\")\n", lpszWindow);    if (!lpszWindow || !lpszWindow[0]) lpszWindow = "main";    for (win = Globals.win_list; win; win = win->next)        if (win->lpszName && !lstrcmpi(win->lpszName, lpszWindow))            DestroyWindow(win->hMainWnd);}void CALLBACK MACRO_Compare(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_Contents(void){    WINE_TRACE("()\n");    if (Globals.active_win->page)        MACRO_JumpContents(Globals.active_win->page->file->lpszPath, NULL);}void CALLBACK MACRO_ControlPanel(LPCSTR str1, LPCSTR str2, LONG u){    WINE_FIXME("(\"%s\", \"%s\", %u)\n", str1, str2, u);}void CALLBACK MACRO_CopyDialog(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_CopyTopic(void){    WINE_FIXME("()\n");}void CALLBACK MACRO_CreateButton(LPCSTR id, LPCSTR name, LPCSTR macro){    WINHELP_WINDOW *win = Globals.active_win;    WINHELP_BUTTON *button, **b;    LONG            size;    LPSTR           ptr;    WINE_TRACE("(\"%s\", \"%s\", %s)\n", id, name, macro);    size = sizeof(WINHELP_BUTTON) + lstrlen(id) + lstrlen(name) + lstrlen(macro) + 3;    button = HeapAlloc(GetProcessHeap(), 0, size);    if (!button) return;    button->next  = 0;    button->hWnd  = 0;    ptr = (char*)button + sizeof(WINHELP_BUTTON);    lstrcpy(ptr, id);    button->lpszID = ptr;    ptr += lstrlen(id) + 1;    lstrcpy(ptr, name);    button->lpszName = ptr;    ptr += lstrlen(name) + 1;    lstrcpy(ptr, macro);    button->lpszMacro = ptr;    button->wParam = WH_FIRST_BUTTON;    for (b = &win->first_button; *b; b = &(*b)->next)        button->wParam = max(button->wParam, (*b)->wParam + 1);    *b = button;    SendMessage(win->hMainWnd, WM_USER, 0, 0);}void CALLBACK MACRO_DeleteItem(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_DeleteMark(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_DestroyButton(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_DisableButton(LPCSTR id){    WINHELP_BUTTON**    b;    WINE_FIXME("(\"%s\")\n", id);    b = MACRO_LookupButton(Globals.active_win, id);    if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}    EnableWindow((*b)->hWnd, FALSE);}void CALLBACK MACRO_DisableItem(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_EnableButton(LPCSTR id){    WINHELP_BUTTON**    b;    WINE_TRACE("(\"%s\")\n", id);    b = MACRO_LookupButton(Globals.active_win, id);    if (!*b) {WINE_FIXME("Couldn't find button '%s'\n", id); return;}    EnableWindow((*b)->hWnd, TRUE);}void CALLBACK MACRO_EnableItem(LPCSTR str){    WINE_FIXME("(\"%s\")\n", str);}void CALLBACK MACRO_EndMPrint(void){    WINE_FIXME("()\n");}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?