home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MyTEUtils.p < prev    next >
Encoding:
Text File  |  1995-04-09  |  2.1 KB  |  81 lines  |  [TEXT/CWIE]

  1. unit MyTEUtils;
  2.  
  3. interface
  4.  
  5.     uses
  6.         TextEdit;
  7.  
  8.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  9.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  10.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  11.  
  12. implementation
  13.  
  14.     uses
  15.         Scrap, Windows, MyTypes, MyMenus;
  16.  
  17.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  18.         var
  19.             i: integer;
  20.     begin
  21.         for i := EMundo to EMselectall do begin
  22.             TESetEditMenuItem(te, static, maxsize, i);
  23.         end;
  24.         TEEditMenuEnabled := GetMenuHandle(M_Edit)^^.enableFlags <> 0;
  25.     end;
  26.  
  27.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  28.         var
  29.             offset: longInt;
  30.     begin
  31.         case item of
  32.             EMundo: 
  33.                 SetIDItemEnable(M_Edit, item, false);
  34.             EMcut, EMclear: 
  35.                 SetIDItemEnable(M_Edit, item, not static & (te^^.selStart < te^^.selEnd));  { Can cut,clear if there is a selection }
  36.             EMcopy: 
  37.                 SetIDItemEnable(M_Edit, item, te^^.selStart < te^^.selEnd);  { Can copy iff there is a selection }
  38.             EMpaste: 
  39.                 SetIDItemEnable(M_Edit, item, not static & (GetScrap(nil, 'TEXT', offset) > 0) & (TEGetScrapLength + (te^^.teLength - (te^^.selEnd - te^^.selStart)) < maxsize));
  40.             EMselectall: 
  41.                 SetIDItemEnable(M_Edit, item, te^^.teLength > 0);  { Can select all iff there is something to select }
  42.             otherwise
  43.         end;
  44.     end;
  45.  
  46.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  47.         var
  48.             loe, oe: OSErr;
  49.     begin
  50.         static := static; { UNUSED! }
  51.         maxsize := maxsize; { UNUSED! }
  52.         TEDoEditMenu := true;
  53.         case item of
  54.             EMcopy:  begin
  55.                 TECopy(te);
  56.                 loe := ZeroScrap;
  57.                 oe := TEToScrap;
  58.                 TEDoEditMenu := false;
  59.             end;
  60.             EMselectall:  begin
  61.                 SetPort(FrontWindow);
  62.                 TESetSelect(0, maxLongInt, te);
  63.                 TEDoEditMenu := false;
  64.             end;
  65.             EMcut:  begin
  66.                 TECut(te);
  67.                 loe := ZeroScrap;
  68.                 oe := TEToScrap;
  69.             end;
  70.             EMclear:  begin
  71.                 TEDelete(te);
  72.             end;
  73.             EMpaste:  begin
  74.                 oe := TEFromScrap;
  75.                 TEPaste(te);
  76.             end;
  77.             otherwise
  78.         end;
  79.     end;
  80.  
  81. end.