home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / DEMO / RIM22 / MACROS / MENU.RM < prev    next >
Text File  |  1993-12-17  |  12KB  |  382 lines

  1. /*
  2. ** Macro module: menu.c - Menu & toolbar support macros
  3. **
  4. ** Copyright (C) 1993 Brian L. Smith
  5. ** Copyright (C) 1993 RimStar Technology, Inc.
  6. ** All rights reserved internationally.
  7. ** Unlicensed use is a violation of applicable laws.
  8. **
  9. ** This source code is provided to licensed users of RimStar's products
  10. ** for the purpose of allowing the user to customize and/or enhance RimStar's
  11. ** products. The source code remains the property of the copyright holders
  12. ** with all rights reserved internationally.
  13. ** Any modifications to the source code are considered derivative works and
  14. ** all rights thereto are reserved to the copyright holders except
  15. ** that the purchaser may use the derivitive work in the same manner
  16. ** as permitted by the license governing the unmodified product.
  17. ** Distribution in any manner of any part of the original source code,
  18. ** whether in source or object form, is expressly prohibited without the
  19. ** express written permission of the copyright holders.
  20. **
  21. */
  22.  
  23. #define INCL_MENU
  24. #include "macro.h"
  25.  
  26.  
  27. #define IDM_CUTAPPEND    (IDM_EDIT_LAST+1)
  28. #define IDM_COPYAPPEND    (IDM_EDIT_LAST+2)
  29. #define IDM_GOTOLINE        (IDM_SB_LAST+1)
  30.  
  31.  
  32.  
  33. void
  34. _init(void) {
  35.     LibAutoload("buffer",    "EditFile",
  36.                                     "SaveBuffer",
  37.                                     "CopyToScrap",
  38.                                     "CutToScrap",
  39.                                     "CutAppendToScrap",
  40.                                     "CopyAppendToScrap"
  41.                                     );
  42.     LibAutoload("slide", "slide_in", "slide_out");
  43. } /* end _init() */
  44.  
  45.  
  46. char *
  47. GetShortcut(char *function) {
  48.     PBINDING    pBind;
  49.  
  50.     pBind = KbdQueryBinding(function, NULL);
  51.     if ( !pBind )
  52.         return NULL;
  53.     return KbdKeysToString(pBind->key, pBind->cKeys);
  54. } /* end GetShortcut() */
  55.  
  56.  
  57. void
  58. CustomizeMenu(void) {
  59.  
  60.  #if 0
  61.     #define IDM_RUN        (IDM_LASTACTION + 100)
  62.     #define IDM_RUNGREP    (IDM_RUN + 1)
  63.  
  64.       /* Add a pulldown menu to the action-bar */
  65.     MnuInsertSubMenu(NULL, NULL, 7, IDM_RUN, "~Run", "");
  66.  
  67.     /* Add an item to the pulldown just created */
  68.     MnuInsertItem(NULL, IDM_RUN, MIT_END, 0, IDM_RUNGREP, "~Grep", NULL);
  69.  #endif
  70.  
  71.     /* Add extra items to Edit pulldown */
  72.     MnuInsertItem(NULL, IDM_EDIT, 7, 0, IDM_CUTAPPEND , "Cut(append)" , NULL);
  73.     MnuSetItemText(IDM_CUTAPPEND, NULL, GetShortcut("CutAppendToScrap"));
  74.  
  75.     MnuInsertItem(NULL, IDM_EDIT, 8, 0, IDM_COPYAPPEND, "Copy(append)", NULL);
  76.     MnuSetItemText(IDM_COPYAPPEND, NULL, GetShortcut("CopyAppendToScrap"));
  77.  
  78.     /* Add extra items to Browse pulldown */
  79.     MnuInsertItem(NULL, IDM_BROWSE, MIT_END, 0, 0xffff, NULL, NULL); /* create separator line */
  80.     MnuInsertItem(NULL, IDM_BROWSE, MIT_END, 0, IDM_GOTOLINE, "Goto line" , NULL);
  81.     MnuSetItemText(IDM_GOTOLINE, NULL, GetShortcut("DlgGotoLine"));
  82. } /* end CustomizeMenu() */
  83.  
  84.  
  85. /*
  86. **    MnuSetMenuAccel - Sets hot-keys for all pulldown menu items
  87. **        according to current keyboard mapping
  88. */
  89. MnuSetMenuAccel(void) {
  90.     CustomizeMenu();
  91.     MnuSetItemText(IDM_NEW                      , NULL, GetShortcut("BufNewFile"));
  92.     MnuSetItemText(IDM_OPEN                     , NULL, GetShortcut("DlgOpenFile"));
  93.     MnuSetItemText(IDM_CLOSE                , NULL, GetShortcut("BufDeleteCurrentBuffer"));
  94.     MnuSetItemText(IDM_SAVE                     , NULL, GetShortcut("SaveBuffer"));
  95.     MnuSetItemText(IDM_SAVEAS                  , NULL, GetShortcut("DlgRenameBuffer"));
  96.     MnuSetItemText(IDM_PRINT                , NULL, GetShortcut("PrintSetup"));
  97.     MnuSetItemText(IDM_PRINT                , NULL, GetShortcut("Print"));
  98.     MnuSetItemText(IDM_LOAD_MACROFILE    , NULL, GetShortcut("LibLoadMacro"));
  99.     MnuSetItemText(IDM_EXIT                     , NULL, GetShortcut("ExitEditor"));
  100.  
  101.     MnuSetItemText(IDM_UNDO                        , NULL, GetShortcut("UndoModification"));
  102.     MnuSetItemText(IDM_REDO                        , NULL, GetShortcut("RedoModification"));
  103.     MnuSetItemText(IDM_CUT                         , NULL, GetShortcut("CutToScrap"));
  104.     MnuSetItemText(IDM_COPY                        , NULL, GetShortcut("CopyToScrap"));
  105.     MnuSetItemText(IDM_PASTE                      , NULL, GetShortcut("BufPasteScrap"));
  106.     MnuSetItemText(IDM_DELETE                     , NULL, GetShortcut("BufDeleteCharOrSelection"));
  107.     MnuSetItemText(IDM_INSERTFILE                , NULL, GetShortcut("BufInsertFile"));
  108.     MnuSetItemText(IDM_IMPORTCLIP                , NULL, GetShortcut("ImportClipboard"));
  109.     MnuSetItemText(IDM_EXPORTCLIP                , NULL, GetShortcut("ExportClipboard"));
  110.  
  111.     MnuSetItemText(IDM_SEARCH_FORWARD          , NULL, GetShortcut("SearchForward"));
  112.     MnuSetItemText(IDM_SEARCH_BACKWARD         , NULL, GetShortcut("SearchBackward"));
  113.     MnuSetItemText(IDM_SEARCH_AGAIN             , NULL, GetShortcut("SearchAgain"));
  114.     MnuSetItemText(IDM_REPLACE_FORWARD         , NULL, GetShortcut("ReplaceForward"));
  115.     MnuSetItemText(IDM_REPLACE_BACKWARD        , NULL, GetShortcut("ReplaceBackward"));
  116.     MnuSetItemText(IDM_REPLACE_AGAIN            , NULL, GetShortcut("ReplaceAgain"));
  117.     MnuSetItemText(IDM_SEARCH_NEXTERR          , NULL, GetShortcut("ErrNextError"));
  118.     MnuSetItemText(IDM_SEARCH_PREVERR          , NULL, GetShortcut("ErrPrevError"));
  119.  
  120.     MnuSetItemText(IDM_SB_GOTODEF                , NULL, GetShortcut("SbGotoDef"));
  121.     MnuSetItemText(IDM_SB_SYMBOL                 , NULL, GetShortcut("SbBrowseSymbolAtCursor"));
  122.     MnuSetItemText(IDM_SB_DEF                     , NULL, GetShortcut("SbBrowseDefs"));
  123.     MnuSetItemText(IDM_SB_REF                     , NULL, GetShortcut("SbBrowseRefs"));
  124.     MnuSetItemText(IDM_SB_MOD                     , NULL, GetShortcut("SbBrowseSymbolsDefinedInModule"));
  125.     MnuSetItemText(IDM_SB_NEXT                    , NULL, GetShortcut("SbFindNext"));
  126.     MnuSetItemText(IDM_SB_PREV                    , NULL, GetShortcut("SbFindPrev"));
  127.  
  128.     MnuSetItemText(IDM_BUFFER_NEXT            , NULL, GetShortcut("BufNextBuffer"));
  129.     MnuSetItemText(IDM_BUFFER_PREV            , NULL, GetShortcut("BufPrevBuffer"));
  130.     MnuSetItemText(IDM_BUFFER_EXECUTE        , NULL, GetShortcut("ExecAssoc"));
  131.     MnuSetItemText(IDM_BUFFER_CLOSE          , NULL, GetShortcut("BufDeleteCurrentBuffer"));
  132.     MnuSetItemText(IDM_BUFFER_LIST            , NULL, GetShortcut("DlgBufferList"));
  133.  
  134.     MnuSetItemText(IDM_WINDOW_CASCADE        , NULL, GetShortcut("WinCascade"));
  135.     MnuSetItemText(IDM_WINDOW_TILE_WIDE        , NULL, GetShortcut("WinTileAcross"));
  136.     MnuSetItemText(IDM_WINDOW_TILE_TALL        , NULL, GetShortcut("WinTileDown"));
  137.     MnuSetItemText(IDM_WINDOW_KEEP_TILED    , NULL, GetShortcut("ToggleKeepTiled"));
  138.     MnuSetItemText(IDM_WINDOW_KEEP_CASCADED, NULL, GetShortcut("ToggleKeepCascaded"));
  139.     MnuSetItemText(IDM_WINDOW_NEXT            , NULL, GetShortcut("WinNextWindow"));
  140.     MnuSetItemText(IDM_WINDOW_PREV            , NULL, GetShortcut("WinPrevWindow"));
  141.     MnuSetItemText(IDM_WINDOW_CREATE            , NULL, GetShortcut("WinNewWindow"));
  142.     MnuSetItemText(IDM_WINDOW_DELETE            , NULL, GetShortcut("WinDeleteCurrentWindow"));
  143.  
  144.     MnuSetItemText(IDM_CONFIG                , NULL, GetShortcut("DlgConfigGlobals"));
  145.     MnuSetItemText(IDM_CONFIGFONT          , NULL, GetShortcut("DlgConfigFonts"));
  146.     MnuSetItemText(IDM_CONFIGCOLORS        , NULL, GetShortcut("DlgConfigColors"));
  147.     MnuSetItemText(IDM_CONFIGCURSOR        , NULL, GetShortcut("DlgConfigCursors"));
  148.     MnuSetItemText(IDM_CONFIGASSOC         , NULL, GetShortcut("DlgConfigAssoc"));
  149.  
  150.     MnuSetItemText(IDM_KEYS_PLAY              , NULL, GetShortcut("KbdMacroPlay"));
  151.     MnuSetItemText(IDM_KEYS_RECORD        , NULL, GetShortcut("KbdMacroRecord"));
  152.     MnuSetItemText(IDM_KEYS_SAVEKBDMACRO, NULL, GetShortcut("KbdMacroSave"));
  153.     MnuSetItemText(IDM_KEYS_LOADKBDMACRO, NULL, GetShortcut("KbdMacroLoad"));
  154.  
  155.     MnuSetItemText(IDM_HELP_FOR_HELP        , NULL, GetShortcut("HelpForHelp"));
  156.     MnuSetItemText(IDM_ABOUT                  , NULL, GetShortcut("DlgVersion"));
  157. } /* end MnuSetMenuAccel() */
  158.  
  159.  
  160. /* MnuCommandHandler
  161. **        Handles WM_COMMAND messages generated by menus
  162. */
  163. int
  164. MnuCommandHandler(USHORT cmd) {
  165.     if ( cmd >= IDM_START_WINDOW_LIST ) {
  166.         /* Selecting a different window to be currently active window */
  167.         WinSetWindowFromID(cmd);
  168.         return 0;
  169.     }
  170.     if ( cmd >= IDM_START_BUFFER_LIST ) {
  171.         /* Selecting a different buffer for currently active window */
  172.         BufSetBufferFromID(cmd);
  173.         return 0;
  174.     }
  175.     switch ( cmd ) {
  176.     case IDM_NEW:
  177.         BufNewFile();                    break;
  178.     case IDM_OPEN:
  179.         DlgOpenFile();                    break;
  180.     case IDM_CLOSE:
  181.     case IDM_BUFFER_CLOSE:
  182.         BufDeleteCurrentBuffer();    break;
  183.     case IDM_SAVE:
  184.         SaveBuffer();                    break;
  185.     case IDM_SAVEAS:
  186.         DlgRenameBuffer();            break;
  187.     case IDM_PRINTER_SETUP:
  188.         PrinterSetup();                break;
  189.     case IDM_PRINT:
  190.         Print();                            break;
  191.     case IDM_LOAD_MACROFILE:
  192.         LibLoadMacro();                break;
  193.     case IDM_EXIT:
  194.         ExitEditor();                    break;
  195.  
  196.     case IDM_UNDO:
  197.         UndoModification();            break;
  198.     case IDM_REDO:
  199.         RedoModification();            break;
  200.     case IDM_CUT:
  201.         CutToScrap();                    break;    /* defined in buffer.rm */
  202.     case IDM_COPY:
  203.         CopyToScrap();                    break;    /* defined in buffer.rm */
  204.     case IDM_PASTE:
  205.         BufPasteScrap();                break;
  206.     case IDM_DELETE:
  207.         BufDeleteSelection();        break;
  208.     case IDM_INSERTFILE:
  209.         BufInsertFile();                break;
  210.     case IDM_IMPORTCLIP:
  211.         ImportClipboard();            break;
  212.     case IDM_EXPORTCLIP:
  213.         ExportClipboard();            break;
  214.     case IDM_CUTAPPEND:
  215.         CutAppendToScrap();            break;
  216.     case IDM_COPYAPPEND:
  217.         CopyAppendToScrap();            break;
  218.  
  219.  
  220.     case IDM_SEARCH_FORWARD:
  221.         SearchForward();                break;
  222.     case IDM_SEARCH_BACKWARD:
  223.         SearchBackward();                break;
  224.     case IDM_SEARCH_AGAIN:
  225.         SearchAgain();                    break;
  226.     case IDM_REPLACE_FORWARD:
  227.         ReplaceForward();                break;
  228.     case IDM_REPLACE_BACKWARD:
  229.         ReplaceBackward();            break;
  230.     case IDM_REPLACE_AGAIN:
  231.         ReplaceAgain();                break;
  232.     case IDM_SEARCH_NEXTERR:
  233.         ErrNextError();                break;
  234.     case IDM_SEARCH_PREVERR:
  235.         ErrPrevError();                break;
  236.  
  237.     case IDM_SB_GOTODEF:
  238.         SbGotoDef();                    break;
  239.     case IDM_SB_SYMBOL:
  240.         SbBrowseSymbolAtCursor();    break;
  241.     case IDM_SB_DEF:
  242.         SbBrowseDefs();                break;
  243.     case IDM_SB_REF:
  244.         SbBrowseRefs();                break;
  245.     case IDM_SB_MOD:
  246.         SbBrowseSymbolsDefinedInModule();    break;
  247.     case IDM_SB_LOAD:
  248.         SbLoadDatabase(NULL, 0);    break;
  249.     case IDM_SB_CLEAR:
  250.         SbUnloadDatabase();            break;
  251.     case IDM_SB_NEXT:
  252.         SbFindNext();                    break;
  253.     case IDM_SB_PREV:
  254.         SbFindPrev();                    break;
  255.     case IDM_GOTOLINE:
  256.         DlgGotoLine();                    break;
  257.  
  258.     case IDM_BUFFER_NEXT:
  259.         BufNextBuffer();                break;
  260.     case IDM_BUFFER_PREV:
  261.         BufPrevBuffer();                break;
  262.     case IDM_BUFFER_EXECUTE:
  263.         ExecAssoc();                    break;
  264.     case IDM_BUFFER_LIST:
  265.         DlgBufferList();                break;
  266.  
  267.     case IDM_WINDOW_CASCADE:
  268.         WinCascade();                    break;
  269.     case IDM_WINDOW_TILE_WIDE:
  270.         WinTileAcross();                break;
  271.     case IDM_WINDOW_TILE_TALL:
  272.         WinTileDown();                    break;
  273.     case IDM_WINDOW_KEEP_CASCADED:
  274.         ToggleKeepCascaded();        break;
  275.     case IDM_WINDOW_KEEP_TILED:
  276.         ToggleKeepTiled();            break;
  277.     case IDM_WINDOW_NEXT:
  278.         WinNextWindow();                break;
  279.     case IDM_WINDOW_PREV:
  280.         WinPrevWindow();                break;
  281.     case IDM_WINDOW_CREATE:
  282.         WinNewWindow();                break;
  283.     case IDM_WINDOW_DELETE:
  284.         WinDeleteCurrentWindow();    break;
  285.  
  286.     case IDM_KEYS_PLAY:
  287.         KbdMacroPlay();                break;
  288.     case IDM_KEYS_RECORD:
  289.         KbdMacroRecord();                break;
  290.     case IDM_KEYS_SAVEKBDMACRO:
  291.         KbdMacroSave();                break;
  292.     case IDM_KEYS_LOADKBDMACRO:
  293.         KbdMacroLoad();                break;
  294.  
  295.     case IDM_CONFIG:
  296.         DlgConfigGlobals();            break;
  297.     case IDM_CONFIGCOLORS:
  298.         DlgConfigColors();            break;
  299.     case IDM_CONFIGFONT:
  300.         DlgConfigFonts();                break;
  301.     case IDM_CONFIGCURSOR:
  302.         DlgConfigCursors();            break;
  303.     case IDM_CONFIGASSOC:
  304.         DlgConfigAssoc();                break;
  305.  
  306.     case IDM_HELP_FOR_HELP:
  307.         HelpForHelp();                    break;
  308.     case IDM_ABOUT:
  309.         DlgVersion();                    break;
  310.     default:
  311.         return 1;
  312.     }  /* end switch on cmd */
  313.     return 0;
  314. } /* end MnuCommandHandler() */
  315.  
  316.  
  317. int
  318. MnuInitHandler(HWND hwnd, USHORT id) {
  319.  
  320.   #if 0
  321.     switch ( id ) {
  322.     case IDM_FILE:
  323.     case IDM_EDIT:
  324.     case IDM_SEARCH:
  325.     case IDM_BROWSE:
  326.     case IDM_BUFFER:
  327.     case IDM_WINDOW:
  328.     case IDM_OPTIONS:
  329.     case IDM_HELP:
  330.     }  /* end switch */
  331.   #endif
  332.     return 0;
  333. }  /* end MnuInitMenu() */
  334.  
  335.  
  336. void
  337. ToolbarCommandHandler(USHORT cmd) {
  338.  
  339.     switch ( cmd ) {
  340.     case IDM_NEW:
  341.         BufNewFile();                    break;
  342.     case IDM_OPEN:
  343.         DlgOpenFile();                    break;
  344.     case IDM_BUFFER_NEXT:
  345.         BufNextBuffer();                break;
  346.     case IDM_BUFFER_PREV:
  347.         BufPrevBuffer();                break;
  348.     case IDM_SAVE:
  349.         BufWrite();                        break;
  350.     case IDM_BUFFER_EXECUTE:
  351.         ExecAssoc();                    break;
  352.     case IDM_PRINT:
  353.         Print();                            break;
  354.     case IDM_UNDO:
  355.         UndoModification();            break;
  356.     case IDM_REDO:
  357.         RedoModification();            break;
  358.     case IDM_CUT:
  359.         CutToScrap();                    break;
  360.     case IDM_COPY:
  361.         CopyToScrap();                    break;
  362.     case IDM_PASTE:
  363.         BufPasteScrap();                break;
  364.     case IDM_INDENT:
  365.         slide_in();                        break;
  366.     case IDM_OUTDENT:
  367.         slide_out();                    break;
  368.     case IDM_SEARCH_FORWARD:
  369.         SearchForward();                break;
  370.     case IDM_SEARCH_AGAIN:
  371.         SearchAgain();                    break;
  372.     case IDM_REPLACE_FORWARD:
  373.         ReplaceForward();                break;
  374.     } /* end switch */
  375. } /* end ToolbarCommandHandler() */
  376.  
  377.  
  378.  
  379. /*
  380. ** End module: menu.c
  381. */
  382.