home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / NOTEPAD2.ZIP / NPCMD.C < prev    next >
C/C++ Source or Header  |  1989-02-08  |  7KB  |  292 lines

  1. /***************************************************************************\
  2. * npcmd.c - notepad command processing
  3. *
  4. * Created by Microsoft Corporation, 1989
  5. \***************************************************************************/
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <opendlg.h>
  12. #include "notepad.h"
  13. #include "npcmd.h"
  14. #include "npabout.h"
  15.  
  16. /************* PROCEDURE DECLARATIONS   */
  17.  
  18. static VOID SetShowMsg(char *psz)
  19. {
  20.     int i;
  21.  
  22.     /* This is for debugging.  Print the string, as you wish */
  23.     i = strlen(psz);
  24. }
  25.  
  26. VOID CmdNew(VOID)
  27. {
  28.         switch (NPCheckSave()) {
  29.         case MBID_CANCEL:
  30.                 SetShowMsg("New command -- cancel");
  31.                 break;
  32.         default:
  33.                 SetShowMsg("New command -- going through");
  34.                 fNamed = FALSE;
  35.                 NPClear();
  36.                 break;
  37.         }
  38.         return;
  39. }
  40.  
  41. VOID CmdOpen(VOID)
  42. {
  43.         switch (NPCheckSave()) {
  44.         case MBID_CANCEL:
  45.                 SetShowMsg("Open command -- cancel");
  46.                 break;
  47.         default:
  48.                 SetShowMsg("Going through with open-read");
  49.                 NPOpenRead();
  50.                 break;
  51.         }
  52.         return;
  53. }
  54.  
  55. VOID CmdSave(VOID)
  56. {
  57.         if (fNamed)
  58.             NPSave();
  59.         else
  60.             NPSaveAs();
  61.         return;
  62. }
  63.  
  64. VOID CmdSaveAs(VOID)
  65. {
  66.         NPSaveAs();
  67.         return;
  68. }
  69.  
  70. VOID CmdPrint(VOID)
  71. {
  72.         SetShowMsg("Print command");
  73.         NPPrint();
  74.         return;
  75. }
  76.  
  77. VOID CmdExit(VOID)
  78. {
  79.         WinSendMsg(hwndNP,WM_CLOSE,0l,0l);
  80. }
  81.  
  82. VOID CmdAbout(VOID)
  83. {
  84.         SetShowMsg("About... command");
  85.         WinDlgBox(HWND_DESKTOP,
  86.                   hwndNP,
  87.                   WinDefDlgProc,
  88.                   NULL,
  89.                   DLG_ABOUT,
  90.                   NULL);
  91.         return;
  92. }
  93.  
  94. VOID CmdUndo(VOID)
  95. {
  96.         SetShowMsg("Undo command");
  97.         return;
  98. }
  99.  
  100. VOID CmdCut(VOID)
  101. {
  102.         SetShowMsg("Cut command");
  103.         WinSendMsg(hwndNPEdit, EM_SETSEL,
  104.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)3L, NULL),
  105.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)4L, NULL));
  106.         if (!WinSendMsg(hwndNPEdit, EM_CUT, 0L, 0L)) {
  107.                 WinAlarm(HWND_DESKTOP,WA_WARNING);
  108.         }
  109.         return;
  110. }
  111.  
  112. VOID CmdCopy(VOID)
  113. {
  114.         if (!WinSendMsg(hwndNPEdit, EM_COPY, 0L, 0L)) {
  115.                 WinAlarm(HWND_DESKTOP,WA_WARNING);
  116.         }
  117.         return;
  118. }
  119.  
  120. VOID CmdPaste(VOID)
  121. {
  122.         SetShowMsg("Paste command");
  123.         WinSendMsg(hwndNPEdit, EM_SETSEL,
  124.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)3L, NULL),
  125.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)4L, NULL));
  126.         if (!WinSendMsg(hwndNPEdit, EM_PASTE, 0L, 0L)) {
  127.                 WinAlarm(HWND_DESKTOP,WA_WARNING);
  128.         }
  129.         return;
  130. }
  131.  
  132. VOID CmdClear(VOID)
  133. {
  134.         SetShowMsg("Clear command");
  135.         WinSendMsg(hwndNPEdit, EM_SETSEL,
  136.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)3L, NULL),
  137.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)4L, NULL));
  138.         if (!WinSendMsg(hwndNPEdit, EM_CLEAR, 0L, 0L)) {
  139.                 WinAlarm(HWND_DESKTOP,WA_WARNING);
  140.         }
  141.         return;
  142. }
  143.  
  144. VOID CmdSelectAll(VOID)
  145. {
  146.         SetShowMsg("SelectAll command");
  147.         if (!WinSendMsg(hwndNPEdit, EM_SETSEL,
  148.                         (MPARAM)(0),
  149.                         (MPARAM)WinSendMsg(hwndNPEdit,EM_QTL,NULL,NULL))) {
  150.                 WinAlarm(HWND_DESKTOP,WA_WARNING);
  151.         }
  152.         return;
  153. }
  154.  
  155. VOID CmdDateTime(VOID)
  156. {
  157.         char dtBuff[40];
  158.         IPT iptBegin;
  159.  
  160.         fmtDateTime(dtBuff);
  161.  
  162.         WinSendMsg(hwndNPEdit, EM_CLEAR, 0L, 0L);
  163.         iptBegin = LONGFROMMR(WinSendMsg(hwndNPEdit, EM_QUERYSEL,
  164.                                          MPFROMSHORT(2), NULL));
  165.         WinSendMsg(hwndNPEdit, EM_SETIMPORTEXPORT,
  166.                    MPFROMP(dtBuff), MPFROMSHORT(40));
  167.         WinSendMsg(hwndNPEdit, EM_SETSEL,
  168.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)3L, NULL),
  169.                 WinSendMsg(hwndNPEdit, EM_QUERYSEL, (MPARAM)4L, NULL));
  170.         WinSendMsg(hwndNPEdit, EM_IMPORT, MPFROMLONG(iptBegin),
  171.                 MPFROMSHORT(lstrlen(dtBuff)));
  172. }
  173.  
  174. VOID CmdFind(VOID)
  175. {
  176.         SetShowMsg("Find command");
  177.         switch (WinDlgBox(HWND_DESKTOP,
  178.                   hwndNP,
  179.                   SearchDlgProc,
  180.                   NULL,
  181.                   DLG_SEARCH,
  182.                   NULL)) {
  183.         case MBID_OK:
  184.                 DoSearch();
  185.                 break;
  186.         case MBID_CANCEL:
  187.                 break;
  188.         default:
  189.                 break;
  190.         }
  191.         return;
  192. }
  193.  
  194. VOID CmdReplace(VOID)
  195. {
  196.         SetShowMsg("Replace command");
  197.         switch (WinDlgBox(HWND_DESKTOP,
  198.                   hwndNP,
  199.                   ReplaceDlgProc,
  200.                   NULL,
  201.                   DLG_REPLACE,
  202.                   NULL)) {
  203.         case MBID_OK:
  204.                 DoReplace();
  205.                 break;
  206.         case MBID_CANCEL:
  207.                 break;
  208.         default:
  209.                 break;
  210.         }
  211.         return;
  212. }
  213.  
  214. VOID CmdNextSearch(VOID)
  215. {
  216.         SetShowMsg("NextSearch command");
  217.         DoNextSearchRep();
  218.         return;
  219. }
  220.  
  221. VOID CmdWordWrap(VOID)
  222. {
  223.         SetWordWrap(!fWordWrapOn);
  224.         SetShowMsg("WordWrapCommand");
  225. }
  226.  
  227. VOID SetWordWrap(BOOL fOn)
  228. {
  229.         fWordWrapOn = fOn;
  230.         WinSendMsg(hwndNPMenu,
  231.                    MM_SETITEMATTR,
  232.                    MPFROM2SHORT(CMD_WRAPTOGGLE,TRUE),
  233.                    MPFROM2SHORT(MIA_CHECKED,fOn?MIA_CHECKED:0));
  234.         WinSendMsg(hwndNPEdit,
  235.                    EM_SETWRAP,
  236.                    MPFROMSHORT(fWordWrapOn),
  237.                    NULL);
  238. }
  239.  
  240.  
  241. VOID CmdSetTab(VOID)
  242. {
  243.         SetShowMsg("Set tab command");
  244.         WinDlgBox(HWND_DESKTOP,
  245.                   hwndNP,
  246.                   TabDlgProc,
  247.                   NULL,
  248.                   DLG_TAB,
  249.                   NULL);
  250.         return;
  251. }
  252.  
  253.  
  254. VOID CmdQueryFont(VOID)
  255. {
  256. }
  257.  
  258. VOID CmdParseLine(int argc, char **argv)
  259. {
  260.         if (argc <= 1) {
  261.                 return;
  262.         } else if (argc > 2) {
  263.                 fInitError = TRUE;
  264.         } else {
  265.                 lstrcpy(szLoadFileName,*(argv+1));
  266.                 fInitLoad = TRUE;
  267.         }
  268. }
  269.  
  270. VOID CmdCmdLine(VOID) {
  271.  
  272.         if (fInitError) {
  273.                 WinAlarm(HWND_DESKTOP, WA_WARNING);
  274.                 WinMessageBox(HWND_DESKTOP,
  275.                     hwndNP,
  276.                     "Usage: np [file]",
  277.                     NULL,
  278.                     0,
  279.                     MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  280.         } else if (fInitLoad) {
  281.                 if (!NPLoadNamedFile((PSZ)szLoadFileName)) {
  282.                     WinAlarm(HWND_DESKTOP, WA_WARNING);
  283.                     WinMessageBox(HWND_DESKTOP,
  284.                         hwndNP,
  285.                         "Couldn't load startup file",
  286.                         NULL,
  287.                         0,
  288.                         MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL);
  289.                 }
  290.         }
  291. }
  292.