home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / quotemkr / editlist.c next >
Encoding:
Text File  |  1993-06-15  |  31.6 KB  |  853 lines

  1. /*
  2.  * Copyright (c) 1990, 1991, 1992 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/QuoteMaker/RCS/editList.c,v 2.11 92/05/14 15:40:46 drapeau Exp $ */
  25. /* $Log:    editList.c,v $
  26.  * Revision 2.11  92/05/14  15:40:46  drapeau
  27.  * Updated copyright info on the source.
  28.  * 
  29.  * Revision 2.10  91/12/31  18:40:49  drapeau
  30.  * Removed the inclusion of string.h, since XView will include the
  31.  * appropriate definitions.
  32.  * 
  33.  * Revision 2.0  91/09/30  15:02:23  derek
  34.  * Version number changed to 2.0.
  35.  * 
  36.  * Revision 1.55  91/09/18  20:54:12  derek
  37.  * The Makefile is changed due to the changes made in the collab/ directory.
  38.  * 
  39.  * Revision 1.54  91/09/15  20:06:20  derek
  40.  * The following things are done:
  41.  * 1.      The foreground of mainTextPane and Quote Window are set to be black.
  42.  *         Also, the color of all the text fields are set to black.
  43.  * 2.      Now the quoted text will be shown directly on the Quote Window
  44.  *         when a panel-item selection is made.  The text will also be shown
  45.  *         while the author is highlighting a selection in the text window.
  46.  * 3.      The inconsistency problem regarding text selection is being taken
  47.  *         care of.  When the mouse cursor re-enters the text window,
  48.  *         the selection will be highlighted again.
  49.  * 4.      When the play button is pressed, the text currently selected
  50.  *         in the text window (rather than the text initially associated
  51.  *         with the edit) will be displayed.
  52.  * 5.      The name of the menu_option "Show Quote Window Specifications panel"
  53.  *         is shortened to be "Quote Window Options ..."
  54.  * 6.      A notify_interpose_destroy_func() is being added to fix the bug
  55.  *         that QuoteMaker might exit without killing the Quote Window (which
  56.  *         is also a base window).
  57.  * 7.      When a different font family or font style is selected, the change
  58.  *         will be automatically be reflected on the Quote Window (without the
  59.  *         need to "play" the edit in order to verify the font).  For font
  60.  *         size, the change will be reflected when either a return character is
  61.  *         entered at the text field or when one of those numeric "arrows"
  62.  *         are pressed.
  63.  * 8.      The play button will now flash when an edit is being played.
  64.  *         Pause button will also glow when playing is paused.
  65.  * 9.      In the course of playing, when another edit is selected,
  66.  *         the playing will be stopped.
  67.  * 10.     I have used Saber to clean up the code.
  68.  * 11.     The left-over "NewEditListPopUp" window is removed.
  69.  * 12.     The bug that when quote window is iconified, it wont be un-iconified
  70.  *         when the edit is played in timeline, is fixed.
  71.  * 13.     The DurationEstimate function is changed so that it no longer
  72.  *         needs an edit to be selected first.  It will take textWindowStart
  73.  *         and textWindowEnd directly as input parameters.
  74.  * 
  75.  * 
  76.  * 
  77.  * Revision 1.53  91/09/05  15:47:57  derek
  78.  * The following changes are made:
  79.  * 1.      The name "Quoted Text Window" has been changed to "Quote Window"
  80.  *         in the app.
  81.  * 2.      ShowApplication() and HideApplication() is changed because of the
  82.  *         the change of quote window from a popup to a basewindow.
  83.  * 3.      The QuitProc of QuoteMaker is fixed so that the quote window,
  84.  *         as a base window, will be destroyed separately.
  85.  * 4.      Now hitting return in the label field will not result in adding
  86.  *         a new edit.
  87.  * 5.      Copyright messages are included in front of every .h and .c file.
  88.  * 6.      The scrollbar and the footer of the Quote Window are hidden.
  89.  * 7.      I have changed the include openpanel.h statement in QuoteMaker.c
  90.  *         to include Browse.h.
  91.  * 8.      The delete bug corresponding to the change that the panel-list
  92.  *         must have a choice -- is fixed.  Also, the corresponding bug
  93.  *         for deleteAll is also fixed.
  94.  * 9.      Now, deleteAll and deletion of the last item in Panel_list
  95.  *         will cause the panel-list to be destroyed and a new one will
  96.  *         be created.
  97.  * 10.     GetOpt files have been removed from the directory.  Corresponding
  98.  *         changes are made.
  99.  * 11.     The start and end byte fields are removed from the main panel.
  100.  * 12.     I have put iconify, hide and show quote window to be buttons
  101.  *         instead of menu options.
  102.  * 13.     I have removed the PreviewPanelPopup and incorporated its features into
  103.  *         the main panel.  The three buttons:  pause, play and stop and
  104.  *         the DurationGauge are moved to the main panel.  But the
  105.  *         StatusMessage is removed.
  106.  * 14.     The EnableLocationChange and EnableSizeChange choice setting
  107.  *         are removed.  There are no longer such choices.
  108.  * 15.     Right now if a panel-item is selected and if another panel-item
  109.  *         is picked, the DeselectList() operation in the middle is
  110.  *         eliminated.  This operation involves updating of text fields and
  111.  *         messages and its removal speeds up the program.  The panel-list
  112.  *         must now take at least one choice.  (A choice must be selected
  113.  *         whenever there is at least one item on the list).  And now
  114.  *         there is no way to deselect a list by the user.
  115.  * 16.     The "modified bit" associated with the CurrentSelectionNumberLabel
  116.  *         is implemented.  Now, if a selection is picked, and if either
  117.  *         the quote window is moved or any text fields are changed, the
  118.  *         modified bit will be on.
  119.  * 17.     The Show-text-window button and the Show-quote-window-specifications-popup
  120.  *         button are removed.  They are now menu options under the Options Menu.
  121.  * 18.     The Modify button has its name changed to "Update Edit".
  122.  * 
  123.  * Revision 1.52  91/08/28  14:06:03  derek
  124.  * The following things are done:
  125.  * 1.    I have changed the NewEditList option to call the file browser
  126.  *     instead of giving a popup window.
  127.  * 2.    I ahve renamed all the options in the file menu so that they
  128.  *     are clearer and more informative.
  129.  * 3.    The documentFileType has been changed from "DTR" (which was
  130.  *     a copying fault :)) to "QuoteMaker".
  131.  * 4.    I ahve changed the stop button so that if it sees that 
  132.  *     HideQTWAfterPlayingEdit is true, stopplay will hide the window too.
  133.  * 5.    I have changed QuoteMaker.G (the interface) so that there is no
  134.  *     way to deselect a fontfamily and fontstyle item from the panel list
  135.  *     (ie. a choice is required.)
  136.  * 
  137.  * Revision 1.51  91/08/27  14:37:27  derek
  138.  * The following things are done:
  139.  * 1.    The QuotedTextWindow is changed from a base window to a popup window
  140.  *     (now it's called QuotedMaker_quotedTextBaseWindow).  I have also
  141.  *     added a few options: show, hide and iconify QTW and also created
  142.  *     an icon for QTW.
  143.  * 2.    The quoted text will be set in PerformSelection() instead of 
  144.  *     in SetSelection().
  145.  * 3.    I have changed the Document field and the EditList field of 
  146.  *     QuoteMaker so that they will display fill paths.
  147.  * 
  148.  * Revision 1.50  91/08/26  12:10:10  derek
  149.  * The following things are done:
  150.  * 1.    I have added a few notice_prompts to the linkProtocol (network)
  151.  *     functions to give warnings about invalid document names.
  152.  * 2.    The quoted text window will by default be hidden during "blank"
  153.  *     times. ie. when it is not displaying any text.  The interface has
  154.  *     been changed so that it now has a HideQuotedTExtWindowAfterPreview
  155.  *     check box.  The QuotedTextWindow will either stay on the screen
  156.  *     or be hidden as the author desires.
  157.  * 3.    Make the changes corresponding to the changing of name from OpenPanel
  158.  *     to Browse.
  159.  * 4.    The return value bug for OpenHandler, SaveHandler is fixed.
  160.  * 5.    I have changed the code so that Save and SaveAs will behave correctly.
  161.  *     The SaveAs PopUp/Open PopUp are removed.  Browse check is 
  162.  *     incorporated in the applications.
  163.  * 6.    The QuoteMaker file format has been changed.  An EditNumber field    
  164.  *     has been added.
  165.  * 7.    Changes corresponding to the return value by OpenDoc and SetSelection
  166.  *     are made.
  167.  * 8.    GetAppIcon() has been implemented.
  168.  * 9.    Fonts specified in the Edit-list will be preloaded in OpenDoc().
  169.  *     This will hopefully eliminate the startup delay needed to load
  170.  *     the font when we put text onto the Quoted TExt Window for the 
  171.  *     first time.
  172.  * 10.    The "play" button will now play things specified in the 
  173.  *     QuotedTExtWindowSpecificationsPopUp (instead of those specified
  174.  *     in the editList).
  175.  * 11.    The show selection button is replaced by the set selection button.
  176.  *     The Set Selection button willl now not only set the current
  177.  *     edit parameters but will also highlight the corresponding section
  178.  *     in the text.  Also, when one item on the panel-list is clicked on,
  179.  *     the corresponding segment in the text will also be highlighted.
  180.  * 12.    Notify events which tells the app to show the size and location 
  181.  *     of the Quoted Text Window are set up.  ie. those text-fields
  182.  *     on the interface will be updated instantaneously.
  183.  * 16.    editList.label is being sent across the network.
  184.  * 17.    The title bar and the footer of the QuotedTExtWindow are hidden.
  185.  * 
  186.  * Revision 1.49  91/08/13  22:52:30  derek
  187.  * I have incorporated the openpanel/savepanel stuff.
  188.  * 
  189.  * Revision 1.48  91/08/12  10:54:36  derek
  190.  * I attempted to debug the edit-list section.  This should be a more
  191.  * stable version.
  192.  * 
  193.  * Revision 1.47  91/08/09  18:18:40  derek
  194.  * I removed all the free() statements from the code to
  195.  * fix the bug and improve run-time efficiency.
  196.  * 
  197.  * Revision 1.46  91/08/08  21:47:33  derek
  198.  * I fixed an edit list bug.
  199.  * 
  200.  * Revision 1.45  91/07/15  12:18:48  derek
  201.  * 1.      I have added font selection panel to the application.
  202.  *         Now a user can specify a font by choosing a font family, a font
  203.  *         style and font size.
  204.  * 2.      Location and size fields are added to the application.  User
  205.  *         can specify the size and location of the QuotedTextWindow.
  206.  * 3.      A duration estimate button is added to estimate how long the
  207.  *         the quoted text should last.
  208.  * 4.      Interface has been redesigned to accomodate the addition of
  209.  *         font, size and location functionalities.
  210.  * 6.      EditList file format has been changed to accomodate the new
  211.  *         fields.  They are:  location (x,y), width, height, font family,
  212.  *         font style, font width for QuotedTextWindow.
  213.  * 5.      Two timers have been added in an attempt to ensure accuracy
  214.  *         of gauge-updating in the preview panel.
  215.  * 6.      Command line args are now supported.
  216.  * 7.      I have cleaned up the code by using saber.
  217.  * 8.      Several bugs from previous revision are fixed.
  218.  * 
  219.  * 
  220.  * Revision 1.44  91/07/02  15:07:48  derek
  221.  * QuoteMaker now fully speaks the new MAEstro protocol.
  222.  * 
  223.  * Revision 1.43  91/07/01  18:51:24  derek
  224.  * The following things are done:
  225.  * 1.    The interface is redesigned.  Duration fields are added to each 
  226.  *     edit list.
  227.  * 2.    The function panel (functions Window) is implemented.  The 
  228.  *     application is now capable of being "played", "stopped" and
  229.  *     "paused".  The sense of "time" is now complete.
  230.  * 3.    Makefile fixed.  
  231.  * 4.    Declaration errors left by previous author are cleaned up.
  232.  * 5.    Redundant malloc statements removed.   Certain other
  233.  *     functions are changed to improve code efficiency.
  234.  * 6.    Code cleaned up by saber.  Removed redundant
  235.  *     variables.
  236.  * 
  237.  * Revision 1.42  91/06/27  18:21:15  derek
  238.  * I have cleaned up some of the comments.  No change in code.
  239.  * 
  240.  * Revision 1.41  91/06/19  17:45:15  drapeau
  241.  * No changes; changing RCS revision numbers.
  242.  * 
  243.  * Revision 1.4  91/05/06  01:53:45  drapeau
  244.  * Using new version of RCS for this file.  No serious changes made to the file.
  245.  * 
  246.  * Revision 1.3  91/01/06  20:18:23  drapeau
  247.  * Modified DeselectList() so that it dims Delete and Modify buttons when list
  248.  * is de-selected.
  249.  * 
  250.  * Revision 1.2  90/12/05  14:51:17  drapeau
  251.  * Modified ReadEditListFromFile() -- fixed error in call to FormatEntry.
  252.  * Previous version called FormatEntry with "counter" as argument instead of
  253.  * "counter+1"; the error caused the edit list numbering to be displayed
  254.  * incorrectly (the edit list numbers started at 0 instead of 1).
  255.  * 
  256.  * Revision 1.1  90/12/04  17:21:46  drapeau
  257.  * Initial revision
  258.  *  */
  259.  
  260. static char rcsid[] = "$Header: /Source/Media/collab/QuoteMaker/RCS/editList.c,v 2.11 92/05/14 15:40:46 drapeau Exp $";
  261.  
  262. /*
  263.  * QuoteMaker.c - Notify and event callback function stubs.
  264.  * This file was copied from "QuoteMaker_stubs.c", which was
  265.  * generated by `gxv' from `QuoteMaker.G'.
  266.  * Modified by George Drapeau on October 26, 1990.
  267.  */
  268.  
  269. #include <stdio.h>
  270. #include <sys/param.h>
  271. #include <sys/types.h>
  272. #include <xview/xview.h>
  273. #include <xview/panel.h>
  274. #include <xview/textsw.h>
  275. #include <xview/xv_xrect.h>
  276. #include <gdd.h>
  277. #include "QuoteMaker_ui.h"
  278. #include <sys/stat.h>
  279. #include <xview/font.h>
  280. #include <xview/notice.h>
  281. #include <xview/notify.h>
  282. #include <xview/server.h>          
  283. #include <xview/seln.h>            
  284. #include "Sender.h"
  285. #include "Receiver.h"
  286. #include "quoteMakerDefs.h"
  287. #include <Browse.h>
  288.  
  289.  
  290. Menu_item ShowOpenEditListPopup(item, op)                /* Menu handler for `fileMenu (Open Edit List...)'. */
  291.      Menu_item        item;
  292.      Menu_generate    op;
  293. {
  294.   switch (op)
  295.   {
  296.    case MENU_DISPLAY:
  297.     break;
  298.     
  299.    case MENU_DISPLAY_DONE:
  300.     break;
  301.     
  302.    case MENU_NOTIFY:
  303.     Browse(NULL, BrowseOpen, IS_EDITLIST, documentFirstLine, documentFileType);
  304.     break;
  305.     
  306.    case MENU_NOTIFY_DONE:
  307.     break;
  308.   }
  309.   return item;
  310. }                                    /* end function ShowOpenEditListPopup */
  311.  
  312.  
  313.  
  314.  
  315. Menu_item SaveEditListHandler(item, op)                /* Menu handler for `fileMenu (Save Edit List...)'. */
  316.      Menu_item    item;
  317.      Menu_generate    op;
  318. {
  319.   switch (op)
  320.   {
  321.    case MENU_DISPLAY:
  322.     break;
  323.     
  324.    case MENU_DISPLAY_DONE:
  325.     break;
  326.     
  327.    case MENU_NOTIFY:
  328.     if (strcmp(absoluteEditListName, "NoneSpecified") == 0
  329.     || strlen(absoluteEditListName) == 0)
  330.     {
  331.       Browse(NULL, BrowseSave, IS_EDITLIST, documentFirstLine, documentFileType);
  332.     }
  333.     else
  334.     {
  335.       (void) WriteEditListToFile(absoluteEditListName, SAVE);
  336.     }
  337.     
  338.     break;
  339.     
  340.    case MENU_NOTIFY_DONE:
  341.     break;
  342.   }
  343.   return item;
  344. }                                    /* end function SaveEditListHandler */
  345.  
  346. /*
  347.  * Menu handler for `fileMenu (Save Edit List As...)'.
  348.  */
  349. Menu_item
  350. SaveEditListAsHandler(item, op)
  351.     Menu_item    item;
  352.     Menu_generate    op;
  353. {
  354.   switch (op) {
  355.    case MENU_DISPLAY:
  356.     break;
  357.  
  358.    case MENU_DISPLAY_DONE:
  359.     break;
  360.  
  361.    case MENU_NOTIFY:
  362.     Browse(NULL, BrowseSave, IS_EDITLIST, documentFirstLine, documentFileType);
  363.     break;
  364.  
  365.    case MENU_NOTIFY_DONE:
  366.     break;
  367.   }
  368.   return item;
  369. }
  370.  
  371.  
  372. /*
  373.  * Menu handler for `fileMenu (New document to annotate...)'.
  374.  */
  375. Menu_item NewDocumentToAnnotateHandler(item, op)                
  376.      Menu_item    item;
  377.      Menu_generate    op;
  378. {
  379.   switch (op)
  380.   {
  381.    case MENU_DISPLAY:
  382.     break;
  383.     
  384.    case MENU_DISPLAY_DONE:
  385.     break;
  386.     
  387.    case MENU_NOTIFY:
  388.     Browse(NULL, BrowseOpen, IS_TEXTFILE, NULL, NULL);
  389.     break;
  390.     
  391.    case MENU_NOTIFY_DONE:
  392.     break;
  393.   }
  394.   return item;
  395. }                                    /* end function NewDocumentToAnnotateHandler */
  396.  
  397.  
  398. void DeselectList()
  399. {
  400.   int selected;
  401.   
  402.   selected = Selected();
  403.   if (selected != NO_CURRENT_EDIT)
  404.   {
  405.     xv_set (QuoteMaker_baseWindow->editListScrolledList,
  406.         PANEL_LIST_SELECT, selected, FALSE,
  407.         NULL);
  408.   }
  409.   xv_set (QuoteMaker_baseWindow->currentSelectionNumberLabel,
  410.       PANEL_LABEL_STRING, "   ",
  411.       NULL);
  412.   xv_set(QuoteMaker_baseWindow->deleteButton,
  413.      PANEL_INACTIVE, TRUE, NULL);                    /* De-activate the Delete and Modify buttons */
  414.   xv_set(QuoteMaker_baseWindow->modifyButton,
  415.      PANEL_INACTIVE, TRUE, NULL);
  416. }                                    /* end function DeselectList */
  417.  
  418.  
  419.  
  420. void EmptyList()
  421. {
  422.   int size;
  423.   int counter;
  424.   
  425.   size = ListSize();
  426.   for (counter = size - 1; counter > -1; counter --)
  427.   {
  428.     xv_set (QuoteMaker_baseWindow->editListScrolledList,
  429.         PANEL_LIST_DELETE, counter,
  430.         NULL);
  431.   }
  432.   editList.numItems = 0;
  433. }                                    /* end function EmptyList */
  434.  
  435.  
  436.  
  437. int ListSize()
  438. {
  439.   return(editList.numItems);
  440. }                                    /* end function ListSize */
  441.  
  442.  
  443. int Selected()
  444. {
  445.   int selected;
  446.   int size;
  447.   int counter;
  448.   
  449.   selected = NO_CURRENT_EDIT;
  450.   size = ListSize();
  451.   counter = 0;
  452.   while ((counter < size) && (selected == NO_CURRENT_EDIT))
  453.   {
  454.     if (xv_get (QuoteMaker_baseWindow->editListScrolledList,
  455.         PANEL_LIST_SELECTED, counter) == TRUE)
  456.     {
  457.       selected = counter;
  458.       break;
  459.     }
  460.     else
  461.       counter ++;
  462.   }
  463.   return selected;
  464. }
  465.  
  466.  
  467.  
  468. int
  469.   ReadEditListFromFile(editListName, caller)
  470. char*    editListName;
  471. int    caller;
  472. {
  473.   int          size, counter, start, end;
  474.   int         locX, locY, sizeWidth, sizeHeight;
  475.   int         hideQTWAfterPlayingEdit;
  476.   double      duration;
  477.   int         fontFamily, fontStyle, fontSize;
  478.   char          fileType[MAX_FILETYPE_LEN + 1];
  479.   char          message[MAX_MESSAGE_LEN + 1];
  480.   char          documentName[MAXPATHLEN + 1];  
  481.   char          entry[MAX_ENTRY_LEN + 1];
  482.   char*          tempLabel;
  483.   FILE*          fp;
  484.   int         garbage;
  485.   int         result;
  486.   struct stat    fileInfo;
  487.   
  488.   if (editListName == NULL)                        /* Was a file name entered? */
  489.   {                                    /* No, inform author and return w/o doing anything */
  490.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,
  491.             "You need to specify an edit list.");
  492.     return FILE_NOT_OK;
  493.   }
  494.   result = stat(editListName,&fileInfo);                /* Attempt to get info about the specified file */
  495.   if ((result != 0) || (fileInfo.st_mode & S_IFDIR))            /* Is the file non-existant, or is it a directory? */
  496.   {                                    /* No, file doesn't exist, or if it exists, it's... */
  497.     sprintf (message, "Cannot find '%s'.", editListName);        /* ...a directory.  Inform author of the mistake... */
  498.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,        /* ...and return without doing anything more. */
  499.             message);
  500.     return FILE_NOT_OK;                            /* Return without doing anything more */
  501.   }
  502.  
  503.   if (strcmp(ShortName(editListName), "NoneSpecified") == 0)        
  504.   {
  505.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,
  506.             "'NoneSpecified' is an unacceptable name.");
  507.   }
  508.   
  509.  
  510.   if (unsavedChangesExist == YES)
  511.     GiveOneLastChanceToSave();
  512.  
  513.   fp = fopen (editListName, "r");                    /* Attempt to open the specified file */
  514.   if (fp == (FILE*)NULL)                        /* Did the open succeed? */
  515.   {                                    /* No, inform author and return w/o doing anything */
  516.     sprintf(message,
  517.         "Unable to open the file named %s.\n",editListName);
  518.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,
  519.             message);
  520.     return FILE_NOT_OK;
  521.   }
  522.   fscanf (fp, "#%s Edit Document#\n", fileType);            /* Is this file a QuoteMaker file? */
  523.   if (strcmp(fileType, "QuoteMaker"))                    /* No, this is not a QuoteMaker file */
  524.   {                                    /* Inform the author of the mistake and return */
  525.     if (caller == USER)
  526.     {
  527.       sprintf (message, "'%s' is not a QuoteMaker edit list.", ShortName (editListName));
  528.       AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,
  529.               message);
  530.     }
  531.     return FILE_NOT_OK;                            /* Exit regardless if called from network or by... */
  532.                                     /* ...the author. */
  533.   }
  534.   fscanf(fp,"#Annotated Document:\t%s\n",documentName);            /* Attempt to read the name of the document... */
  535.   /* ...being annotated. */
  536.   if (documentName == NULL)                        /* Was document name invalid or not there somehow? */
  537.   {                                    /* Bad document name; close the file and return... */
  538.     fclose(fp);                                /* ...without doing any further work. */
  539.     return FILE_NOT_OK;
  540.   }
  541.  
  542.   UnHighlightSelection();
  543.   DeselectList();
  544.   ResetCurrentSelection();
  545.   EmptyList();
  546.  
  547.   fscanf (fp, "#Number of Edits:\t%d\n", &size);            /* Read the size of the edit list to be read in */
  548.   editList.numItems = size;
  549.   for (counter = 0; counter < size; counter ++)                /* Read through the edit list file, loading it... */
  550.   {                                    /* ...into the edit list, entry by entry. */
  551.     fscanf(fp, "#EditNumber:\t%d\n#Start:\t%d\n#End:\t%d\n#Duration:\t%lf\n#LocX:\t%d\n#LocY:\t%d\n#SizeWidth:\t%d\n#SizeHeight:\t%d\n#FontFamily:\t%d\n#FontStyle:\t%d\n#FontSize:\t%d\n#HideQTWAfterPlayingEdit:\t%d\n", 
  552.        &garbage,
  553.        &start, &end, &duration, &locX, &locY, &sizeWidth,
  554.        &sizeHeight, &fontFamily, &fontStyle, &fontSize, &hideQTWAfterPlayingEdit);
  555.     fgets(entry,512,fp);
  556.     tempLabel = &entry[8];                        /* Skip over "#Label: " characters, point right... */
  557.     /* ...at the label. */
  558.     tempLabel[strlen(tempLabel)-1] = '\0';                /* Replace newline character with NULL character */
  559.     editList.start[counter] = start;                    /* Load this entry into the current item in the... */
  560.     /* ...edit list. */
  561.     editList.end[counter] = end;
  562.     editList.duration[counter] = duration;
  563.  
  564.     editList.locX[counter] = locX;
  565.     editList.locY[counter] = locY;
  566.     editList.sizeWidth[counter] = sizeWidth;
  567.     editList.sizeHeight[counter] = sizeHeight;
  568.  
  569.     editList.fontFamily[counter] = fontFamily;
  570.     editList.fontStyle[counter] = fontStyle;
  571.     editList.fontSize[counter] = fontSize;
  572.  
  573.     editList.hideQTWAfterPlayingEdit[counter] = hideQTWAfterPlayingEdit;
  574.  
  575.     if (editList.label[counter])
  576.       free(editList.label[counter]);
  577.     editList.label[counter] = (char*)strdup(tempLabel);
  578.     xv_set (QuoteMaker_baseWindow->editListScrolledList,
  579.         PANEL_LIST_INSERT, counter,
  580.         PANEL_LIST_STRING, counter, FormatEntry(counter+1,tempLabel, duration, hideQTWAfterPlayingEdit),
  581.         PANEL_LIST_FONT, counter, listFont,
  582.         NULL);
  583.     fgets(entry,512,fp);                        /* Skip over blank line to advance to next entry */
  584.   }
  585.  
  586.   UpdateNumEditsMessage();
  587.   SetDocument(documentName);
  588.   if (caller == USER)                            /* This test is to prevent main text window to be... */
  589.     Show(&QuoteMaker_textWindowPopup->textWindowPopup);            /* ...shown when "OpenDoc()" is called from the... */
  590.   /* ...network. */
  591.   SetEditList(editListName);
  592.   unsavedChangesExist = NO;
  593.  
  594.   if (editList.numItems >= 1)                        /* Set the current selection to be the first one.    */
  595.   {                                    /* ...This corresponds to the change that now...     */
  596.     SetCurrentSelection(0);                        /* ...the user cannot deselect a list.               */
  597.     DisplayTextOnQuoteWindow();
  598.   }
  599.   
  600.   return FILE_OK;
  601. }                                    /* end function ReadEditListFromFile */
  602.  
  603.  
  604.  
  605. /*
  606.  *  The value of saveAsFlag indicates whether we want "save" or "saveAs".
  607.  */
  608. int
  609.   WriteEditListToFile (editListName, saveAsFlag)
  610. char* editListName;
  611. int   saveAsFlag;
  612. {
  613.   int        size, counter;
  614.   char        message[MAX_MESSAGE_LEN + 1];
  615.   FILE*     fp;
  616.   char      documentName[MAXPATHLEN + 1];  
  617.   int        response;
  618.   struct stat    fileInfo;
  619.   
  620.   size = ListSize();
  621.  
  622.   if (editListName == NULL)                        /* Was the file name to save the edit list invalid? */
  623.   {                                    /* Yes, inform author of the mistake and return... */
  624.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,        /* ...without doing anything. */
  625.             "You need to specify an edit list.");
  626.     return FILE_NOT_OK;
  627.   }
  628.   
  629.   if (strcmp(ShortName(editListName),"NoneSpecified") == 0)        /* Did the author try to save the document as... */
  630.   {                                    /* ..."NoneSpecified"? */
  631.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,        /* Yes, inform author of the mistake and return... */
  632.       "'NoneSpecified' is not an acceptable name.");        /* ...without doing anything more. */
  633.     return FILE_NOT_OK;
  634.   }
  635.   strcpy(documentName,                            /* Get the name of the document being annotated */
  636.      (char *) xv_get(QuoteMaker_baseWindow->docNameLabel,
  637.              PANEL_LABEL_STRING));
  638.   if (strcmp(documentName, "None Loaded") == 0)                /* Is the author trying to save an empty document? */
  639.   {                                    /* Yes, inform author of the mistake and return... */
  640.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,        /* ...without doing anything more. */
  641.             "You have not specified the document you are annotating.");
  642.     return FILE_NOT_OK;
  643.   }
  644.  
  645.   response = stat(editListName,&fileInfo);                /* Attempt to get info about the specified file */
  646.   if (saveAsFlag == SAVE_AS &&
  647.       (response == 0) && (!(fileInfo.st_mode & S_IFDIR)))        /* Does the file exist (.. is it *not* a directory)? */
  648.   {                                    /* Yes, file exists and is not a directory. */
  649.     sprintf(message, "'%s' already exists.", ShortName(editListName));
  650.     response = notice_prompt(QuoteMaker_baseWindow->baseWindow, NULL,
  651.                  NOTICE_MESSAGE_STRINGS, message,
  652.                  "Do you wish to overwrite it?",
  653.                  NULL,
  654.                  NOTICE_BUTTON_YES, "Yes",
  655.                  NOTICE_BUTTON_NO, "No",
  656.                  NULL);
  657.     if (response == NOTICE_NO)
  658.       return FILE_NOT_OK;
  659.   }
  660.  
  661.   fp = fopen (editListName, "w");                    /* Attempt to open the edit list passed in for... */
  662.   /* ...writing. */
  663.   if (fp == (FILE*)NULL)                        /* Did the open fail? */
  664.   {                                    /* Yes, unable to open the file for writing. ... */
  665.     sprintf (message, "'%s' is a bad pathname.", editListName);        /* ...Report this to the author and return w/o... */
  666.     AlertByNoticePrompt(QuoteMaker_baseWindow->baseWindow,        /* ...doing anything. */
  667.             message);
  668.     return FILE_NOT_OK;
  669.   }
  670.  
  671.   fprintf (fp, "#QuoteMaker Edit Document#\n");                /* Write the file header determining the type... */
  672.   /* ... of this file. */
  673.   fprintf (fp, "#Annotated Document:\t%s\n", absoluteDocumentName); /* Write the name of the text file being annotated */
  674.   fprintf (fp, "#Number of Edits:\t%d\n\n", size);            /* Write the number of edits made for this document */
  675.   for (counter = 0; counter < size; counter ++)                /* Loop through each item in the edit list, ... */
  676.   {                                    /* ...writing the contents of each item to the file. */
  677.     fprintf(fp, "#EditNumber:\t%d\n#Start:\t%d\n#End:\t%d\n#Duration:\t%lf\n#LocX:\t%d\n#LocY:\t%d\n#SizeWidth:\t%d\n#SizeHeight:\t%d\n#FontFamily:\t%d\n#FontStyle:\t%d\n#FontSize:\t%d\n#HideQTWAfterPlayingEdit:\t%d\n#Label:\t%s\n\n",        
  678.         counter + 1,
  679.         editList.start[counter],
  680.         editList.end[counter],
  681.         editList.duration[counter],
  682.         editList.locX[counter],
  683.         editList.locY[counter],
  684.         editList.sizeWidth[counter],
  685.         editList.sizeHeight[counter],
  686.         editList.fontFamily[counter],
  687.         editList.fontStyle[counter],
  688.         editList.fontSize[counter],
  689.         editList.hideQTWAfterPlayingEdit[counter],
  690.         editList.label[counter]);
  691.   }
  692.   fclose (fp);                                /* Close the file just written */
  693.  
  694.   unsavedChangesExist = NO;
  695.   SetEditList(editListName);
  696.   return FILE_OK;
  697. }                                    /* end function WriteEditListToFile */
  698.  
  699.  
  700. void SetEditList(editListName)
  701.      char*    editListName;
  702. {
  703.   char    fancyEditListName[MAXPATHLEN + 1];
  704.   
  705.   if (strcmp(editListName, "NoneSpecified") != 0)
  706.   {
  707.     xv_set(QuoteMaker_baseWindow->editListNameLabel,
  708.        PANEL_LABEL_STRING, (char *) editListName,
  709.        NULL);
  710.  
  711.     realpath(editListName, absoluteEditListName);
  712.   }
  713.   else
  714.   {
  715.     sprintf(fancyEditListName, "Untitled%d", untitledEditListNum);
  716.     xv_set(QuoteMaker_baseWindow->editListNameLabel,
  717.        PANEL_LABEL_STRING, (char *) fancyEditListName,
  718.        NULL);
  719.  
  720.     strcpy(absoluteEditListName, "NoneSpecified");
  721.   }
  722.   return;
  723. }                                    /* end function SetEditList */
  724.  
  725.  
  726. void DeleteItemFromEditList(itemNumber)
  727.      int    itemNumber;
  728. {
  729.   int    i;
  730.   
  731.   if (itemNumber+1 == editList.numItems)                /* Is the last item in the last being deleted? */
  732.   {                                    /* Yes, don't need to shuffle any items up in... */
  733.     editList.numItems--;                        /* Update number of items in the edit list */
  734.     xv_set(QuoteMaker_baseWindow->editListScrolledList,            /* Clear the entry on the display so that the...    */
  735.        PANEL_LIST_STRING, itemNumber, "",                /* ..."ghost" wont show up again.                   */
  736.        PANEL_LIST_FONT, itemNumber, listFont,
  737.        NULL);
  738.     RedrawEditList(itemNumber);
  739.     return;
  740.   }
  741.  
  742.   for (i = itemNumber; i < editList.numItems; i++)            /* Shift each subsequent entry in the edit list... */
  743.   {                                    /* ...up by one. */
  744.     editList.start[i] = editList.start[i+1];
  745.     editList.end[i] = editList.end[i+1];
  746.     editList.label[i] = editList.label[i+1];
  747.     editList.duration[i] = editList.duration[i+1];
  748.     editList.locX[i] = editList.locX[i+1];
  749.     editList.locY[i] = editList.locY[i+1];
  750.     editList.sizeWidth[i] = editList.sizeHeight[i+1];
  751.     editList.fontFamily[i] = editList.fontFamily[i+1];
  752.     editList.fontStyle[i] = editList.fontStyle[i+1];
  753.     editList.fontSize[i] = editList.fontSize[i+1];
  754.     editList.hideQTWAfterPlayingEdit[i] = editList.hideQTWAfterPlayingEdit[i+1];
  755.   }
  756.  
  757.   if (atoi(xv_get(QuoteMaker_QuoteWindowSpecificationsPopup->EditNumberMessage,
  758.           PANEL_LABEL_STRING)) == itemNumber)
  759.   {
  760.     ClearQuoteWindowSpecificationsPopup();
  761.   }
  762.  
  763.   editList.numItems--;                            /* Update number of items in the edit list */
  764.   xv_set(QuoteMaker_baseWindow->editListScrolledList,            /* Clear the entry on the display so that the...    */
  765.      PANEL_LIST_STRING, itemNumber, "",                /* ..."ghost" wont show up again.                   */
  766.      PANEL_LIST_FONT, itemNumber, listFont,
  767.      NULL);
  768.   RedrawEditList(itemNumber);
  769.   return;
  770. }                                    /* end function DeleteItemFromEditList */
  771.  
  772.  
  773. void
  774.   ClearQuoteWindowSpecificationsPopup()
  775. {
  776.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->EditNumberMessage,
  777.      PANEL_LABEL_STRING, "None", NULL);
  778.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->LocationMessage,
  779.      PANEL_LABEL_STRING, "", NULL);
  780.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->SizeMessage,
  781.      PANEL_LABEL_STRING, "", NULL);
  782.  
  783.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontFamilyList,
  784.      PANEL_LIST_SELECT, currentFontFamily, FALSE, NULL);        /*  deselect font family lists.                    */
  785.   currentFontFamily = NONE_SELECTED;
  786.  
  787.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontStyleList,
  788.      PANEL_LIST_SELECT, currentFontStyle, FALSE, NULL);        /*  deselect font style lists.                     */
  789.   currentFontStyle = NONE_SELECTED;
  790.   
  791.   xv_set(QuoteMaker_QuoteWindowSpecificationsPopup->FontSizeTextField,
  792.      PANEL_VALUE, 20, NULL);
  793.  
  794.   EnableHideQTWAfterPlayingEdit();
  795.  
  796.   SetFontPanel(0, 0, 24);                        /*  Pre-set font panel to 0, 0, 24.                */
  797. }
  798.  
  799.  
  800. void    RedrawEditList(itemNumber)
  801.      int    itemNumber;
  802. {
  803.   int    i;
  804.   
  805.   for(i=itemNumber; i < editList.numItems; i++)                /* Draw all the items in the edit list starting... */
  806.   {                                    /* ...from item number "itemNumber" */
  807.     xv_set (QuoteMaker_baseWindow->editListScrolledList,
  808.         PANEL_LIST_STRING, i, FormatEntry(i + 1,
  809.                           editList.label[i],
  810.                           editList.duration[i],
  811.                           editList.hideQTWAfterPlayingEdit[i]),
  812.         PANEL_LIST_FONT, i, listFont,
  813.         NULL);
  814.   }
  815.   return;
  816. }                                    /* end function RedrawEditList */
  817.  
  818.  
  819. void
  820.   CheckIfEditModified(isTextFieldOrChoice)
  821. BOOL  isTextFieldOrChoice;
  822. {
  823.   int    selected;
  824.   
  825.   selected = Selected();
  826.   if (selected != NO_CURRENT_EDIT)
  827.   {
  828.     sprintf(msg, "%d (modified)", selected + 1);
  829.     xv_set(QuoteMaker_baseWindow->currentSelectionNumberLabel,
  830.        PANEL_LABEL_STRING, msg, NULL);
  831.     if (isTextFieldOrChoice)
  832.     {
  833.       EditTextFieldOrChoiceModified = TRUE;
  834.     }
  835.   }
  836. }
  837.  
  838.  
  839. void
  840.   ClearEditModified()
  841. {
  842.   int    selected;
  843.   
  844.   selected = Selected();
  845.   if (selected != NO_CURRENT_EDIT)
  846.   {
  847.     sprintf(msg, "%d", selected + 1);
  848.     xv_set(QuoteMaker_baseWindow->currentSelectionNumberLabel,
  849.        PANEL_LABEL_STRING, msg, NULL);
  850.     EditTextFieldOrChoiceModified = FALSE;
  851.   }
  852. }
  853.