home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / NewsView 1.0.0 / source / EditWindowRec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-16  |  17.3 KB  |  634 lines  |  [TEXT/KAHL]

  1. /* EditWindowRec.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Offline USENET News Viewer                                             */
  5. /*    Written by Thomas R. Lawrence, 1993 - 1994.                            */
  6. /*                                                                           */
  7. /*    This software is Public Domain; it may be used for any purpose         */
  8. /*    whatsoever without restriction.                                        */
  9. /*                                                                           */
  10. /*    This package is distributed in the hope that it will be useful,        */
  11. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  12. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   */
  13. /*                                                                           */
  14. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  15. /*                                                                           */
  16. /*****************************************************************************/
  17.  
  18. #include "MiscInfo.h"
  19. #include "Audit.h"
  20. #include "Debug.h"
  21. #include "Definitions.h"
  22.  
  23. #include "EditWindowRec.h"
  24. #include "TextEdit.h"
  25. #include "Memory.h"
  26. #include "GrowIcon.h"
  27. #include "Main.h"
  28. #include "WindowDispatcher.h"
  29. #include "Menus.h"
  30. #include "Displayer.h"
  31. #include "DataMunging.h"
  32. #include "Numbers.h"
  33. #include "FindDialog.h"
  34. #include "NumberDialog.h"
  35. #include "Files.h"
  36. #include "Alert.h"
  37.  
  38.  
  39. #define POSITIONS (5)
  40. #define HOFFSET (10)
  41. #define VOFFSET (20)
  42.  
  43.  
  44. struct EditWindowRec
  45.     {
  46.         WinType*                        ScreenID;
  47.         TextEditRec*                EditBox;
  48.         long                                PlacementIndex;
  49.         GenericWindowRec*        GenericWindow;
  50.         DisplayWindowRec*        Owner;
  51.     };
  52.  
  53.  
  54. static long                            PlacementArray[POSITIONS];
  55.  
  56. static char*                        FindString = NIL;
  57. static char*                        ReplaceString = NIL;
  58.  
  59.  
  60. /* initialize internal static structures for edit window */
  61. MyBoolean                            InitializeEditWindow(void)
  62.     {
  63.         FindString = AllocPtrCanFail(0,"FindString");
  64.         if (FindString == NIL)
  65.             {
  66.              FailurePoint1:
  67.                 return False;
  68.             }
  69.         ReplaceString = AllocPtrCanFail(0,"ReplaceString");
  70.         if (ReplaceString == NIL)
  71.             {
  72.              FailurePoint2:
  73.                 ReleasePtr(FindString);
  74.                 goto FailurePoint1;
  75.             }
  76.         return True;
  77.     }
  78.  
  79.  
  80. /* dispose of internal static structures for edit window */
  81. void                                    ShutdownEditWindow(void)
  82.     {
  83.         ReleasePtr(FindString);
  84.         ReleasePtr(ReplaceString);
  85.     }
  86.  
  87.  
  88. /* find a place to put the window */
  89. static long                        PlaceWindow(void)
  90.     {
  91.         long                                SmallestIndex;
  92.         long                                Entries;
  93.         long                                Scan;
  94.  
  95.         SmallestIndex = 0;
  96.         Entries = 0x7fffffff;
  97.         for (Scan = 0; Scan < POSITIONS; Scan += 1)
  98.             {
  99.                 if (Entries > PlacementArray[Scan])
  100.                     {
  101.                         Entries = PlacementArray[Scan];
  102.                         SmallestIndex = Scan;
  103.                     }
  104.             }
  105.         return SmallestIndex;
  106.     }
  107.  
  108.  
  109. /* create a new editing window */
  110. EditWindowRec*                NewEditWindow(char* DataBlock, char* LineFeed, char* WindowName,
  111.                                                 struct DisplayWindowRec* Owner)
  112.     {
  113.         EditWindowRec*            Window;
  114.         OrdType                            LeftEdge;
  115.         OrdType                            TopEdge;
  116.         char*                                TempStr;
  117.  
  118.         Window = (EditWindowRec*)AllocPtrCanFail(sizeof(EditWindowRec),"EditWindowRec");
  119.         if (Window == NIL)
  120.             {
  121.              FailurePoint1:
  122.                 return NIL;
  123.             }
  124.         Window->Owner = Owner;
  125.         Window->PlacementIndex = PlaceWindow();
  126.         LeftEdge = 2 + HOFFSET * (POSITIONS - Window->PlacementIndex - 1);
  127.         TopEdge = 2 + VOFFSET * Window->PlacementIndex;
  128.         Window->ScreenID = MakeNewWindow(eDocumentWindow,eWindowClosable,eWindowZoomable,
  129.             eWindowResizable,LeftEdge + WindowOtherEdgeWidths(eDocumentWindow),TopEdge
  130.             + WindowTitleBarHeight(eDocumentWindow),GetScreenWidth() - 2
  131.             * WindowOtherEdgeWidths(eDocumentWindow) - LeftEdge - 1,GetScreenHeight()
  132.             - 2 - TopEdge - WindowOtherEdgeWidths(eDocumentWindow)
  133.             - WindowTitleBarHeight(eDocumentWindow),(void (*)(void*))&EditWindowDoUpdate,
  134.             Window);
  135.         if (Window->ScreenID == NIL)
  136.             {
  137.              FailurePoint2:
  138.                 ReleasePtr((char*)Window);
  139.                 goto FailurePoint1;
  140.             }
  141.         TempStr = BlockToStringCopy(WindowName);
  142.         if (TempStr != NIL)
  143.             {
  144.                 SetWindowName(Window->ScreenID,TempStr);
  145.                 ReleasePtr(TempStr);
  146.             }
  147.         Window->EditBox = NewTextEdit(Window->ScreenID,eTEVScrollBar | eTEHScrollBar,
  148.             GetMonospacedFont(),9,-1,-1,GetWindowWidth(Window->ScreenID) + 2,
  149.             GetWindowHeight(Window->ScreenID) + 2);
  150.         if (Window->EditBox == NIL)
  151.             {
  152.              FailurePoint3:
  153.                 KillWindow(Window->ScreenID);
  154.                 goto FailurePoint2;
  155.             }
  156.         if (!TextEditNewRawData(Window->EditBox,DataBlock,LineFeed))
  157.             {
  158.              FailurePoint4:
  159.                 DisposeTextEdit(Window->EditBox);
  160.                 goto FailurePoint3;
  161.             }
  162.         Window->GenericWindow = CheckInNewWindow(Window->ScreenID,Window,
  163.             (void (*)(void*,MyBoolean,OrdType,OrdType,ModifierFlags))&EditWindowDoIdle,
  164.             (void (*)(void*))&EditWindowBecomeActive,
  165.             (void (*)(void*))&EditWindowBecomeInactive,
  166.             (void (*)(void*))&EditWindowResized,
  167.             (void (*)(OrdType,OrdType,ModifierFlags,void*))&EditWindowDoMouseDown,
  168.             (void (*)(unsigned char,ModifierFlags,void*))&EditWindowDoKeyDown,
  169.             (void (*)(void*))&EditWindowClose,
  170.             (void (*)(void*))&EditWindowMenuSetup,
  171.             (void (*)(void*,MenuItemType*))&EditWindowDoMenuCommand);
  172.         if (Window->GenericWindow == NIL)
  173.             {
  174.              FailurePoint5:
  175.                 goto FailurePoint4;
  176.             }
  177.         if (!DisplayWindowNewArticleWindow(Owner,Window))
  178.             {
  179.              FailurePoint6:
  180.                 CheckOutDyingWindow(Window->GenericWindow);
  181.                 goto FailurePoint5;
  182.             }
  183.         PlacementArray[Window->PlacementIndex] += 1;
  184.         return Window;
  185.     }
  186.  
  187.  
  188. /* dispose of the editing window */
  189. void                                    DisposeEditWindow(EditWindowRec* Window)
  190.     {
  191.         CheckPtrExistence(Window);
  192.         PlacementArray[Window->PlacementIndex] -= 1;
  193.         DisplayWindowArticleDead(Window->Owner,Window);
  194.         CheckOutDyingWindow(Window->GenericWindow);
  195.         DisposeTextEdit(Window->EditBox);
  196.         KillWindow(Window->ScreenID);
  197.         ReleasePtr((char*)Window);
  198.     }
  199.  
  200.  
  201. void                                    EditWindowDoIdle(EditWindowRec* Window,
  202.                                                 MyBoolean CheckCursorFlag, OrdType XLoc, OrdType YLoc,
  203.                                                 ModifierFlags Modifiers)
  204.     {
  205.         CheckPtrExistence(Window);
  206.         TextEditUpdateCursor(Window->EditBox);
  207.         if (CheckCursorFlag)
  208.             {
  209.                 if (TextEditIBeamTest(Window->EditBox,XLoc,YLoc))
  210.                     {
  211.                         SetIBeamCursor();
  212.                     }
  213.                  else
  214.                     {
  215.                         SetArrowCursor();
  216.                     }
  217.             }
  218.     }
  219.  
  220.  
  221. void                                    EditWindowBecomeActive(EditWindowRec* Window)
  222.     {
  223.         OrdType                            XSize;
  224.         OrdType                            YSize;
  225.  
  226.         CheckPtrExistence(Window);
  227.         EnableTextEditSelection(Window->EditBox);
  228.         XSize = GetWindowWidth(Window->ScreenID);
  229.         YSize = GetWindowHeight(Window->ScreenID);
  230.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  231.         DrawBitmap(Window->ScreenID,XSize - 15,YSize - 15,GetGrowIcon(True));
  232.     }
  233.  
  234.  
  235. void                                    EditWindowBecomeInactive(EditWindowRec* Window)
  236.     {
  237.         OrdType                            XSize;
  238.         OrdType                            YSize;
  239.  
  240.         CheckPtrExistence(Window);
  241.         DisableTextEditSelection(Window->EditBox);
  242.         XSize = GetWindowWidth(Window->ScreenID);
  243.         YSize = GetWindowHeight(Window->ScreenID);
  244.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  245.         DrawBitmap(Window->ScreenID,XSize - 15,YSize - 15,GetGrowIcon(False));
  246.     }
  247.  
  248.  
  249. void                                    EditWindowResized(EditWindowRec* Window)
  250.     {
  251.         CheckPtrExistence(Window);
  252.         SetTextEditPosition(Window->EditBox,-1,-1,GetWindowWidth(Window->ScreenID) + 2,
  253.             GetWindowHeight(Window->ScreenID) + 2);
  254.     }
  255.  
  256.  
  257. void                                    EditWindowDoMouseDown(OrdType XLoc, OrdType YLoc,
  258.                                                 ModifierFlags Modifiers, EditWindowRec* Window)
  259.     {
  260.         CheckPtrExistence(Window);
  261.         if (TextEditHitTest(Window->EditBox,XLoc,YLoc))
  262.             {
  263.                 TextEditDoMouseDown(Window->EditBox,XLoc,YLoc,Modifiers);
  264.             }
  265.     }
  266.  
  267.  
  268. void                                    EditWindowDoKeyDown(unsigned char KeyCode,
  269.                                                 ModifierFlags Modifiers, EditWindowRec* Window)
  270.     {
  271.         CheckPtrExistence(Window);
  272.         switch (KeyCode)
  273.             {
  274.                 default:
  275.                     break;
  276.                 case eLeftArrow:
  277.                 case eRightArrow:
  278.                 case eUpArrow:
  279.                 case eDownArrow:
  280.                     TextEditDoKeyPressed(Window->EditBox,KeyCode,Modifiers);
  281.                     break;
  282.                 case 3:
  283.                     TextEditShowSelection(Window->EditBox);
  284.                     break;
  285.             }
  286.     }
  287.  
  288.  
  289. void                                    EditWindowClose(EditWindowRec* Window)
  290.     {
  291.         DisposeEditWindow(Window);
  292.     }
  293.  
  294.  
  295. void                                    EditWindowMenuSetup(EditWindowRec* Window)
  296.     {
  297.         char*                                StrNumber;
  298.  
  299.         CheckPtrExistence(Window);
  300.         EnableMenuItem(mCloseFile);
  301.         ChangeItemName(mCloseFile,"Close Article");
  302.         EnableMenuItem(mCloseFile);
  303.         if (TextEditIsThereValidSelection(Window->EditBox))
  304.             {
  305.                 EnableMenuItem(mCopy);
  306.                 EnableMenuItem(mEnterSelection);
  307.             }
  308.         EnableMenuItem(mSelectAll);
  309.         EnableMenuItem(mFind);
  310.         if (PtrSize(FindString) != 0)
  311.             {
  312.                 EnableMenuItem(mFindAgain);
  313.             }
  314.         EnableMenuItem(mShowSelection);
  315.         EnableMenuItem(mBalanceParens);
  316.  
  317.         EnableMenuItem(mSaveArticle);
  318.         EnableMenuItem(mAppendArticle);
  319.         if (TextEditIsThereValidSelection(Window->EditBox))
  320.             {
  321.                 EnableMenuItem(mSaveSelection);
  322.                 EnableMenuItem(mAppendSelection);
  323.             }
  324.  
  325.         EnableMenuItem(mGotoLine);
  326.         StrNumber = IntegerToString(GetTextEditSelectStartLine(Window->EditBox) + 1);
  327.         if (StrNumber != NIL)
  328.             {
  329.                 char*                            StrKey;
  330.  
  331.                 StrKey = StringToBlockCopy("_");
  332.                 if (StrKey != NIL)
  333.                     {
  334.                         char*                            StrValue;
  335.  
  336.                         StrValue = StringToBlockCopy("Goto Line... (_)");
  337.                         if (StrValue != NIL)
  338.                             {
  339.                                 char*                            StrResult;
  340.  
  341.                                 StrResult = ReplaceBlockCopy(StrValue,StrKey,StrNumber);
  342.                                 if (StrResult != NIL)
  343.                                     {
  344.                                         char*                            Temp;
  345.  
  346.                                         Temp = BlockToStringCopy(StrResult);
  347.                                         if (Temp != NIL)
  348.                                             {
  349.                                                 ReleasePtr(StrResult);
  350.                                                 StrResult = Temp;
  351.                                                 ChangeItemName(mGotoLine,StrResult);
  352.                                             }
  353.                                         ReleasePtr(StrResult);
  354.                                     }
  355.                                 ReleasePtr(StrValue);
  356.                             }
  357.                         ReleasePtr(StrKey);
  358.                     }
  359.                 ReleasePtr(StrNumber);
  360.             }
  361.     }
  362.  
  363.  
  364. static void                        FindAgain(EditWindowRec* Window)
  365.     {
  366.         CheckPtrExistence(Window);
  367.         TextEditFindAgain(Window->EditBox,FindString);
  368.         TextEditShowSelection(Window->EditBox);
  369.     }
  370.  
  371.  
  372. void                                    EditWindowDoMenuCommand(EditWindowRec* Window,
  373.                                                 struct MenuItemType* MenuItem)
  374.     {
  375.         CheckPtrExistence(Window);
  376.         if (MenuItem == mCloseFile)
  377.             {
  378.                 DisposeEditWindow(Window);
  379.             }
  380.         else if (MenuItem == mCopy)
  381.             {
  382.                 TextEditDoMenuCopy(Window->EditBox);
  383.             }
  384.         else if (MenuItem == mSelectAll)
  385.             {
  386.                 TextEditDoMenuSelectAll(Window->EditBox);
  387.             }
  388.         else if (MenuItem == mEnterSelection)
  389.             {
  390.                 char*                        NewString;
  391.  
  392.                 NewString = TextEditGetSelection(Window->EditBox);
  393.                 if (NewString != NIL)
  394.                     {
  395.                         ReleasePtr(FindString);
  396.                         FindString = NewString;
  397.                     }
  398.             }
  399.         else if (MenuItem == mFind)
  400.             {
  401.                 switch (DoFindDialog(&FindString,&ReplaceString,mCut,mPaste,mCopy,mUndo,
  402.                     mSelectAll,mClear))
  403.                     {
  404.                         case eFindCancel:
  405.                             break;
  406.                         case eFindFromStart:
  407.                             SetTextEditInsertionPoint(Window->EditBox,0,0); /* reset selection */
  408.                             FindAgain(Window);
  409.                             break;
  410.                         case eFindAgain:
  411.                             FindAgain(Window);
  412.                             break;
  413.                         case eDontFind:
  414.                             break;
  415.                         default:
  416.                             EXECUTE(PRERR(AllowResume,"FindSomething: Unknown find opcode"));
  417.                             break;
  418.                     }
  419.             }
  420.         else if (MenuItem == mFindAgain)
  421.             {
  422.                 FindAgain(Window);
  423.             }
  424.         else if (mBalanceParens == MenuItem)
  425.             {
  426.                 TextEditBalanceParens(Window->EditBox);
  427.             }
  428.         else if (mGotoLine == MenuItem)
  429.             {
  430.                 long                        Line;
  431.  
  432.                 Line = DoNumberDialog("Goto Line:",GetTextEditSelectStartLine(
  433.                     Window->EditBox) + 1,mCut,mPaste,mCopy,mUndo,mSelectAll,mClear);
  434.                 Line -= 1;
  435.                 if (Line < 0)
  436.                     {
  437.                         Line = 0;
  438.                     }
  439.                 if (Line > GetTextEditNumLines(Window->EditBox) - 1)
  440.                     {
  441.                         Line = GetTextEditNumLines(Window->EditBox) - 1;
  442.                     }
  443.                 SetTextEditInsertionPoint(Window->EditBox,Line,0);
  444.                 TextEditShowSelection(Window->EditBox);
  445.             }
  446.         else if (MenuItem == mShowSelection)
  447.             {
  448.                 TextEditShowSelection(Window->EditBox);
  449.             }
  450.         else if (MenuItem == mSaveArticle)
  451.             {
  452.                 FileSpec*                        WhereToSave;
  453.  
  454.                 WhereToSave = PutFile("");
  455.                 if (WhereToSave != NIL)
  456.                     {
  457.                         FileType*                        FileDescriptor;
  458.  
  459.                         if (!CreateFile(WhereToSave,CODE4BYTES('?','?','?','?'),
  460.                             CODE4BYTES('T','E','X','T')))
  461.                             {
  462.                                 AlertHalt("Unable to create file.",NIL);
  463.                              SaveArticleFailurePoint1:
  464.                                 DisposeFileSpec(WhereToSave);
  465.                                 return;
  466.                             }
  467.                         if (!OpenFile(WhereToSave,&FileDescriptor,eReadAndWrite))
  468.                             {
  469.                                 AlertHalt("Unable to open file for writing.",NIL);
  470.                              SaveArticleFailurePoint2:
  471.                                 goto SaveArticleFailurePoint1;
  472.                             }
  473.                         if (!TestEditWriteDataToFile(Window->EditBox,FileDescriptor,SYSTEMLINEFEED))
  474.                             {
  475.                                 AlertHalt("Unable to write data to the file.",NIL);
  476.                              SaveArticleFailurePoint3:
  477.                                 CloseFile(FileDescriptor);
  478.                                 goto SaveArticleFailurePoint2;
  479.                             }
  480.                         CloseFile(FileDescriptor);
  481.                         DisposeFileSpec(WhereToSave);
  482.                     }
  483.             }
  484.         else if (MenuItem == mAppendArticle)
  485.             {
  486.                 FileSpec*                        WhereToSave;
  487.                 unsigned long                FileTypeArray[1] = {CODE4BYTES('T','E','X','T')};
  488.  
  489.                 WhereToSave = GetFileStandard(1,FileTypeArray);
  490.                 if (WhereToSave != NIL)
  491.                     {
  492.                         FileType*                        FileDescriptor;
  493.                         long                                OldFileLength;
  494.  
  495.                         if (!OpenFile(WhereToSave,&FileDescriptor,eReadAndWrite))
  496.                             {
  497.                                 AlertHalt("Unable to open file for writing.",NIL);
  498.                              AppendArticleFailurePoint1:
  499.                                 DisposeFileSpec(WhereToSave);
  500.                                 return;
  501.                             }
  502.                         OldFileLength = GetFileLength(FileDescriptor);
  503.                         if (!SetFilePosition(FileDescriptor,OldFileLength))
  504.                             {
  505.                                 AlertHalt("Couldn't seek to end of file.",NIL);
  506.                              AppendArticleFailurePoint2:
  507.                                 CloseFile(FileDescriptor);
  508.                                 goto AppendArticleFailurePoint1;
  509.                             }
  510.                         if (!TestEditWriteDataToFile(Window->EditBox,FileDescriptor,SYSTEMLINEFEED))
  511.                             {
  512.                                 AlertHalt("Unable to append data to the file.",NIL);
  513.                              AppendArticleFailurePoint3:
  514.                                 /* undo any damage we might have done */
  515.                                 (void)SetFileLength(FileDescriptor,OldFileLength);
  516.                                 goto AppendArticleFailurePoint2;
  517.                             }
  518.                         CloseFile(FileDescriptor);
  519.                         DisposeFileSpec(WhereToSave);
  520.                     }
  521.             }
  522.         else if (MenuItem == mSaveSelection)
  523.             {
  524.                 char*                                DataBlock;
  525.                 FileSpec*                        WhereToSave;
  526.  
  527.                 DataBlock = TextEditGetSelection(Window->EditBox);
  528.                 if (DataBlock == NIL)
  529.                     {
  530.                         AlertHalt("There is not enough memory available to save selection.",NIL);
  531.                      SaveSelectionFailurePoint1:
  532.                         return;
  533.                     }
  534.                 WhereToSave = PutFile("");
  535.                 if (WhereToSave != NIL)
  536.                     {
  537.                         FileType*                        FileDescriptor;
  538.  
  539.                         if (!CreateFile(WhereToSave,CODE4BYTES('?','?','?','?'),
  540.                             CODE4BYTES('T','E','X','T')))
  541.                             {
  542.                                 AlertHalt("Unable to create file.",NIL);
  543.                              SaveSelectionFailurePoint2:
  544.                                 ReleasePtr(DataBlock);
  545.                                 DisposeFileSpec(WhereToSave);
  546.                                 goto SaveSelectionFailurePoint1;
  547.                             }
  548.                         if (!OpenFile(WhereToSave,&FileDescriptor,eReadAndWrite))
  549.                             {
  550.                                 AlertHalt("Unable to open file for writing.",NIL);
  551.                              SaveSelectionFailurePoint3:
  552.                                 goto SaveSelectionFailurePoint2;
  553.                             }
  554.                         if (0 != WriteToFile(FileDescriptor,DataBlock,PtrSize(DataBlock)))
  555.                             {
  556.                                 AlertHalt("Unable to write data to the file.",NIL);
  557.                              SaveSelectionFailurePoint4:
  558.                                 CloseFile(FileDescriptor);
  559.                                 goto SaveSelectionFailurePoint3;
  560.                             }
  561.                         CloseFile(FileDescriptor);
  562.                         DisposeFileSpec(WhereToSave);
  563.                     }
  564.                 ReleasePtr(DataBlock);
  565.             }
  566.         else if (MenuItem == mAppendSelection)
  567.             {
  568.                 char*                                DataBlock;
  569.                 FileSpec*                        WhereToSave;
  570.                 unsigned long                FileTypeArray[1] = {CODE4BYTES('T','E','X','T')};
  571.  
  572.                 DataBlock = TextEditGetSelection(Window->EditBox);
  573.                 if (DataBlock == NIL)
  574.                     {
  575.                         AlertHalt("There is not enough memory available to append selection.",NIL);
  576.                      AppendSelectionFailurePoint1:
  577.                         return;
  578.                     }
  579.                 WhereToSave = GetFileStandard(1,FileTypeArray);
  580.                 if (WhereToSave != NIL)
  581.                     {
  582.                         FileType*                        FileDescriptor;
  583.                         long                                OldFileLength;
  584.  
  585.                         if (!OpenFile(WhereToSave,&FileDescriptor,eReadAndWrite))
  586.                             {
  587.                                 AlertHalt("Unable to open file for writing.",NIL);
  588.                              AppendSelectionFailurePoint2:
  589.                                 DisposeFileSpec(WhereToSave);
  590.                                 ReleasePtr(DataBlock);
  591.                                 goto AppendSelectionFailurePoint1;
  592.                             }
  593.                         OldFileLength = GetFileLength(FileDescriptor);
  594.                         if (!SetFilePosition(FileDescriptor,OldFileLength))
  595.                             {
  596.                                 AlertHalt("Couldn't seek to end of file.",NIL);
  597.                              AppendSelectionFailurePoint3:
  598.                                 CloseFile(FileDescriptor);
  599.                                 goto AppendSelectionFailurePoint2;
  600.                             }
  601.                         if (0 != WriteToFile(FileDescriptor,DataBlock,PtrSize(DataBlock)))
  602.                             {
  603.                                 AlertHalt("Unable to append data to the file.",NIL);
  604.                              AppendSelectionFailurePoint4:
  605.                                 /* undo any damage we might have done */
  606.                                 (void)SetFileLength(FileDescriptor,OldFileLength);
  607.                                 goto AppendSelectionFailurePoint3;
  608.                             }
  609.                         CloseFile(FileDescriptor);
  610.                         DisposeFileSpec(WhereToSave);
  611.                     }
  612.                 ReleasePtr(DataBlock);
  613.             }
  614.         else
  615.             {
  616.                 EXECUTE(PRERR(AllowResume,"EditWindowDoMenuCommand:  unknown menu command"));
  617.             }
  618.     }
  619.  
  620.  
  621. void                                    EditWindowDoUpdate(EditWindowRec* Window)
  622.     {
  623.         OrdType                            XSize;
  624.         OrdType                            YSize;
  625.  
  626.         CheckPtrExistence(Window);
  627.         TextEditFullRedraw(Window->EditBox);
  628.         XSize = GetWindowWidth(Window->ScreenID);
  629.         YSize = GetWindowHeight(Window->ScreenID);
  630.         SetClipRect(Window->ScreenID,XSize - 15,YSize - 15,XSize,YSize);
  631.         DrawBitmap(Window->ScreenID,XSize - 15,YSize - 15,
  632.             GetGrowIcon(Window->GenericWindow == GetCurrentWindowID()));
  633.     }
  634.