home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / PROG / PASCAL / SPEED2 / SAMPLES / PMEDIT / PMEDIT.PAS < prev    next >
Pascal/Delphi Source File  |  1994-10-06  |  6KB  |  238 lines

  1. PROGRAM PmEdit;
  2.  
  3. {***************************************************************************
  4. *                                                                          *
  5. *                Speed-Pascal/2 Sample program "PMEdit"                    *
  6. *                                                                          *
  7. *           (C) 1993,94 Rene Nürnberger. All rights reserved.              *
  8. *                                                                          *
  9. *                                                                          *
  10. *  This program implements a small text-Editor which can be extended       *
  11. *  easily (it's the same editor the IDE has)                               *
  12. *                                                                          *
  13. *                                                                          *
  14. ****************************************************************************}
  15.  
  16. {$m 32768}    {Set stack size}
  17.  
  18. USES Api,PMobject,PmDialog,PmEditor,Dos,Crt,PmTypes;
  19.  
  20. RESOURCE PmEdit;
  21.  
  22. TYPE TMyApp=OBJECT(TEditorApplication)
  23.                  CONSTRUCTOR Init;
  24.                  DESTRUCTOR Done;
  25.                  PROCEDURE HandleCommand(Win:HWND;Command:WORD);VIRTUAL;
  26.                  PROCEDURE AppCreateNotify(AppFrWin,AppWin:HWND);VIRTUAL;
  27.                  PROCEDURE AppRunNotify(AppFrWin:HWND);VIRTUAL;
  28.                  PROCEDURE SetPosText(Win:HWND;Extra:PEditor);VIRTUAL;
  29.                  PROCEDURE SetupMenu(Frame,Client:HWND);VIRTUAL;
  30.                  PROCEDURE About;
  31.             END;
  32.  
  33.  
  34. VAR
  35.     MyApp:TMyApp;
  36.  
  37.  
  38. PROCEDURE TMyApp.SetPosText(Win:HWND;Extra:PEditor);
  39. VAR s:string;
  40. BEGIN
  41.      s:=tostr(Extra^.CursorY+Extra^.VSlider.acvalue)+':'+
  42.         tostr(Extra^.CursorX+Extra^.HSlider.acvalue);
  43.      StatusBarSetText(1,s,-1);
  44.      IF not Extra^.Insertmode THEN StatusBarSetText(2,'Insert',-1)
  45.      ELSE StatusBarSetText(2,'Overwrite',-1);
  46.      IF Extra^.Modified THEN StatusbarSetText(3,'Modified',-1)
  47.      ELSE StatusBarSetText(3,'',-1);
  48. END;
  49.  
  50. PROCEDURE TMyApp.About;
  51. VAR Dlg:TDialog;
  52.     r:LONGWORD;
  53. BEGIN
  54.      Dlg.Init(1,AppWinFrameHandle,0,1004,NIL);
  55.      Dlg.ExecDialog(r);
  56.      Dlg.Done;
  57. END;
  58.  
  59.  
  60. PROCEDURE TMyApp.HandleCommand(Win:HWND;command:WORD);
  61. VAR
  62.     s:string;
  63.     w:word;
  64.     e:PEditor;
  65.     name:namestr;
  66.     dir:dirstr;
  67.     ext:extstr;
  68. BEGIN
  69.      Inherited.HandleCommand(Win,Command);
  70.      CASE command OF
  71.          CM_ABOUT:About;
  72.          CM_NEW:OpenNewFile;
  73.          CM_OPEN:IF FileOpenDialog(AppWinHandle,s) THEN OpenFile(s);
  74.          CM_SAVEAS:SaveFileAs;
  75.          CM_SAVE:SaveFile;
  76.          CM_SAVEALL:SaveAllFiles;
  77.      END; {case}
  78. END;
  79.  
  80. PROCEDURE TMyApp.SetupMenu(Frame,Client:HWND);
  81. BEGIN
  82.      InsertMenuHelp(4,65535,'',-1);  {Default menu help}
  83.      InsertMenuHelp(4,CM_OPEN,'Locate and open a file in an Edit window',-1);
  84.      InsertMenuHelp(4,CM_NEW,'Create a new file in a new Edit window',-1);
  85.      InsertMenuHelp(4,CM_SAVE,'Save the file in the active Edit window',-1);
  86.      InsertMenuHelp(4,CM_SAVEAS,
  87.        'Save the current file under a different name, directory or drive',-1);
  88.      InsertMenuHelp(4,CM_SAVEALL,'Save all modified files in all Edit windows',-1);
  89.      InsertMenuHelp(4,CM_TILE,'Arrange windows on desktop by tiling',-1);
  90.      InsertMenuHelp(4,CM_CASCADE,'Arrange windows on desktop by cascading',-1);
  91.      InsertMenuHelp(4,CM_CLOSE,'Close the active window',-1);
  92.      InsertMenuHelp(4,CM_CLOSEALL,'Close all windows on the desktop',-1);
  93.      InsertMenuHelp(4,CM_GOTO,'Move the cursor to a specified line number',-1);
  94.      InsertMenuHelp(4,CM_FIND,'Search for specified text',-1);
  95.      InsertMenuHelp(4,CM_REPLACE,'Search for text and replace it with new text',-1);
  96.      InsertMenuHelp(4,CM_ABOUT,'Display Copyright notice',-1);
  97.  
  98.      InsertMenuHelp(4,CM_NEXT,'Make the next Edit window active',-1);
  99.  
  100.      SetMenuState(CM_FIND,FALSE);
  101.      SetMenuState(CM_REPLACE,FALSE);
  102.      SetMenuState(CM_CUT,FALSE);
  103.      SetmenuState(CM_UNDO,FALSE);
  104.      SetMenuState(CM_REDO,FALSE);
  105.      SetMenuState(CM_SEARCHAGAIN,FALSE);
  106.      SetMenuState(CM_GOTO,FALSE);
  107.  
  108. END;
  109.  
  110. PROCEDURE TMyApp.AppCreateNotify(AppFrWin,AppWin:HWND);
  111. BEGIN
  112.      ChildIconRes:=1001;
  113.      WinSetWindowPos(SWP_SPEED,400,500,50,50,HWND_TOP,AppFrWin);
  114.      CreateToolBar(30);
  115.      ToolBarInsertButton(CM_OPEN,2001,10,3,28,24);
  116.      ToolBarInsertButton(CM_SAVE,2000,45,3,28,24);
  117.      ToolBarInsertButton(CM_FIND,2002,80,3,28,24);
  118.      ToolBarInsertButton(CM_SEARCHAGAIN,2003,115,3,28,24);
  119.      CreateStatusBar(22);
  120.      StatusBarInsertItem(1,10,3,60,16);
  121.      StatusBarInsertItem(2,80,3,50,16);
  122.      StatusBarInsertItem(3,140,3,50,16);
  123.      StatusBarInsertItem(4,200,3,430,16);
  124.  
  125.      SetEditorPtr(2009,0); {Mouse pointer for editor window}
  126. END;
  127.  
  128. PROCEDURE TMyApp.AppRunNotify(AppFrWin:HWND);
  129. BEGIN
  130.      About;
  131. END;
  132.  
  133. CONSTRUCTOR TMyApp.Init;
  134. BEGIN
  135.      Inherited.Init;
  136.      EditorCol:=CLR_BLACK;
  137.      EditorBackCol:=CLR_CYAN;
  138.      StdExt:='.PAS';
  139.      FileOpenDlgWildCards:='*.*';
  140.      FilesaveDlgWildCards:='*.*';
  141.  
  142.      InsertResources(TRUE,TRUE,TRUE);  {Application has menus}
  143. END;
  144.  
  145. DESTRUCTOR TMyApp.Done;
  146. BEGIN
  147. END;
  148.  
  149. var p:pointer;
  150.  
  151. BEGIN
  152.      MyApp.Init;
  153.      MyApp.Run(1000,'Speed-386 Sample Application PMEdit',CLR_BLACK,CLR_DARKGRAY);
  154.      MyApp.Done;
  155. END.
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.