home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / quotemkr / timer.c < prev   
Encoding:
Text File  |  1993-06-15  |  15.7 KB  |  404 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/timer.c,v 2.13 92/09/12 18:43:41 drapeau Exp $*/
  25. /* $Log:    timer.c,v $
  26.  * Revision 2.13  92/09/12  18:43:41  drapeau
  27.  * Replaced non-portable "irint()" function with simple cast-to-integer syntax.
  28.  * 
  29.  * Revision 2.12  92/05/14  15:43:42  drapeau
  30.  * * Updated copyright information.
  31.  * 
  32.  * Revision 2.11  92/01/09  18:25:31  drapeau
  33.  * Slight modifications to make code ANSI-compliant.
  34.  * 
  35.  * Revision 2.10  91/12/31  18:46:03  drapeau
  36.  * Removed the inclusion of string.h, since XView will include the
  37.  * appropriate definitions.
  38.  * 
  39.  * Revision 2.0  91/09/30  15:02:49  derek
  40.  * Version number changed to 2.0.
  41.  * 
  42.  * Revision 1.9  91/09/15  20:06:36  derek
  43.  * The following things are done:
  44.  * 1.      The foreground of mainTextPane and Quote Window are set to be black.
  45.  *         Also, the color of all the text fields are set to black.
  46.  * 2.      Now the quoted text will be shown directly on the Quote Window
  47.  *         when a panel-item selection is made.  The text will also be shown
  48.  *         while the author is highlighting a selection in the text window.
  49.  * 3.      The inconsistency problem regarding text selection is being taken
  50.  *         care of.  When the mouse cursor re-enters the text window,
  51.  *         the selection will be highlighted again.
  52.  * 4.      When the play button is pressed, the text currently selected
  53.  *         in the text window (rather than the text initially associated
  54.  *         with the edit) will be displayed.
  55.  * 5.      The name of the menu_option "Show Quote Window Specifications panel"
  56.  *         is shortened to be "Quote Window Options ..."
  57.  * 6.      A notify_interpose_destroy_func() is being added to fix the bug
  58.  *         that QuoteMaker might exit without killing the Quote Window (which
  59.  *         is also a base window).
  60.  * 7.      When a different font family or font style is selected, the change
  61.  *         will be automatically be reflected on the Quote Window (without the
  62.  *         need to "play" the edit in order to verify the font).  For font
  63.  *         size, the change will be reflected when either a return character is
  64.  *         entered at the text field or when one of those numeric "arrows"
  65.  *         are pressed.
  66.  * 8.      The play button will now flash when an edit is being played.
  67.  *         Pause button will also glow when playing is paused.
  68.  * 9.      In the course of playing, when another edit is selected,
  69.  *         the playing will be stopped.
  70.  * 10.     I have used Saber to clean up the code.
  71.  * 11.     The left-over "NewEditListPopUp" window is removed.
  72.  * 12.     The bug that when quote window is iconified, it wont be un-iconified
  73.  *         when the edit is played in timeline, is fixed.
  74.  * 13.     The DurationEstimate function is changed so that it no longer
  75.  *         needs an edit to be selected first.  It will take textWindowStart
  76.  *         and textWindowEnd directly as input parameters.
  77.  * 
  78.  * 
  79.  * 
  80.  * Revision 1.8  91/09/05  15:48:07  derek
  81.  * The following changes are made:
  82.  * 1.      The name "Quoted Text Window" has been changed to "Quote Window"
  83.  *         in the app.
  84.  * 2.      ShowApplication() and HideApplication() is changed because of the
  85.  *         the change of quote window from a popup to a basewindow.
  86.  * 3.      The QuitProc of QuoteMaker is fixed so that the quote window,
  87.  *         as a base window, will be destroyed separately.
  88.  * 4.      Now hitting return in the label field will not result in adding
  89.  *         a new edit.
  90.  * 5.      Copyright messages are included in front of every .h and .c file.
  91.  * 6.      The scrollbar and the footer of the Quote Window are hidden.
  92.  * 7.      I have changed the include openpanel.h statement in QuoteMaker.c
  93.  *         to include Browse.h.
  94.  * 8.      The delete bug corresponding to the change that the panel-list
  95.  *         must have a choice -- is fixed.  Also, the corresponding bug
  96.  *         for deleteAll is also fixed.
  97.  * 9.      Now, deleteAll and deletion of the last item in Panel_list
  98.  *         will cause the panel-list to be destroyed and a new one will
  99.  *         be created.
  100.  * 10.     GetOpt files have been removed from the directory.  Corresponding
  101.  *         changes are made.
  102.  * 11.     The start and end byte fields are removed from the main panel.
  103.  * 12.     I have put iconify, hide and show quote window to be buttons
  104.  *         instead of menu options.
  105.  * 13.     I have removed the PreviewPanelPopup and incorporated its features into
  106.  *         the main panel.  The three buttons:  pause, play and stop and
  107.  *         the DurationGauge are moved to the main panel.  But the
  108.  *         StatusMessage is removed.
  109.  * 14.     The EnableLocationChange and EnableSizeChange choice setting
  110.  *         are removed.  There are no longer such choices.
  111.  * 15.     Right now if a panel-item is selected and if another panel-item
  112.  *         is picked, the DeselectList() operation in the middle is
  113.  *         eliminated.  This operation involves updating of text fields and
  114.  *         messages and its removal speeds up the program.  The panel-list
  115.  *         must now take at least one choice.  (A choice must be selected
  116.  *         whenever there is at least one item on the list).  And now
  117.  *         there is no way to deselect a list by the user.
  118.  * 16.     The "modified bit" associated with the CurrentSelectionNumberLabel
  119.  *         is implemented.  Now, if a selection is picked, and if either
  120.  *         the quote window is moved or any text fields are changed, the
  121.  *         modified bit will be on.
  122.  * 17.     The Show-text-window button and the Show-quote-window-specifications-popup
  123.  *         button are removed.  They are now menu options under the Options Menu.
  124.  * 18.     The Modify button has its name changed to "Update Edit".
  125.  * 
  126.  * Revision 1.7  91/08/27  14:37:42  derek
  127.  * The following things are done:
  128.  * 1.    The QuotedTextWindow is changed from a base window to a popup window
  129.  *     (now it's called QuotedMaker_quotedTextBaseWindow).  I have also
  130.  *     added a few options: show, hide and iconify QTW and also created
  131.  *     an icon for QTW.
  132.  * 2.    The quoted text will be set in PerformSelection() instead of 
  133.  *     in SetSelection().
  134.  * 3.    I have changed the Document field and the EditList field of 
  135.  *     QuoteMaker so that they will display fill paths.
  136.  * 
  137.  * Revision 1.6  91/08/26  12:10:26  derek
  138.  * The following things are done:
  139.  * 1.    I have added a few notice_prompts to the linkProtocol (network)
  140.  *     functions to give warnings about invalid document names.
  141.  * 2.    The quoted text window will by default be hidden during "blank"
  142.  *     times. ie. when it is not displaying any text.  The interface has
  143.  *     been changed so that it now has a HideQuotedTExtWindowAfterPreview
  144.  *     check box.  The QuotedTextWindow will either stay on the screen
  145.  *     or be hidden as the author desires.
  146.  * 3.    Make the changes corresponding to the changing of name from OpenPanel
  147.  *     to Browse.
  148.  * 4.    The return value bug for OpenHandler, SaveHandler is fixed.
  149.  * 5.    I have changed the code so that Save and SaveAs will behave correctly.
  150.  *     The SaveAs PopUp/Open PopUp are removed.  Browse check is 
  151.  *     incorporated in the applications.
  152.  * 6.    The QuoteMaker file format has been changed.  An EditNumber field    
  153.  *     has been added.
  154.  * 7.    Changes corresponding to the return value by OpenDoc and SetSelection
  155.  *     are made.
  156.  * 8.    GetAppIcon() has been implemented.
  157.  * 9.    Fonts specified in the Edit-list will be preloaded in OpenDoc().
  158.  *     This will hopefully eliminate the startup delay needed to load
  159.  *     the font when we put text onto the Quoted TExt Window for the 
  160.  *     first time.
  161.  * 10.    The "play" button will now play things specified in the 
  162.  *     QuotedTExtWindowSpecificationsPopUp (instead of those specified
  163.  *     in the editList).
  164.  * 11.    The show selection button is replaced by the set selection button.
  165.  *     The Set Selection button willl now not only set the current
  166.  *     edit parameters but will also highlight the corresponding section
  167.  *     in the text.  Also, when one item on the panel-list is clicked on,
  168.  *     the corresponding segment in the text will also be highlighted.
  169.  * 12.    Notify events which tells the app to show the size and location 
  170.  *     of the Quoted Text Window are set up.  ie. those text-fields
  171.  *     on the interface will be updated instantaneously.
  172.  * 16.    editList.label is being sent across the network.
  173.  * 17.    The title bar and the footer of the QuotedTExtWindow are hidden.
  174.  * 
  175.  * Revision 1.5  91/07/15  12:20:19  derek
  176.  * 1.      I have added font selection panel to the application.
  177.  *         Now a user can specify a font by choosing a font family, a font
  178.  *         style and font size.
  179.  * 2.      Location and size fields are added to the application.  User
  180.  *         can specify the size and location of the QuotedTextWindow.
  181.  * 3.      A duration estimate button is added to estimate how long the
  182.  *         the quoted text should last.
  183.  * 4.      Interface has been redesigned to accomodate the addition of
  184.  *         font, size and location functionalities.
  185.  * 6.      EditList file format has been changed to accomodate the new
  186.  *         fields.  They are:  location (x,y), width, height, font family,
  187.  *         font style, font width for QuotedTextWindow.
  188.  * 5.      Two timers have been added in an attempt to ensure accuracy
  189.  *         of gauge-updating in the preview panel.
  190.  * 6.      Command line args are now supported.
  191.  * 7.      I have cleaned up the code by using saber.
  192.  * 8.      Several bugs from previous revision are fixed.
  193.  * 
  194.  * 
  195.  * Revision 1.4  91/07/02  15:08:00  derek
  196.  * QuoteMaker now fully speaks the new MAEstro protocol.
  197.  * 
  198.  * Revision 1.3  91/07/01  19:12:02  derek
  199.  * The following things are done:
  200.  * 1.    The interface is redesigned.  Duration fields are added to each
  201.  *     edit list.
  202.  * 2.    The function panel (functions Window) is implemented.  The
  203.  *     application is now capable of being "played", "stopped"
  204.  *     and "Paused".  The sense of "time" is now complete.
  205.  * 3.    Makefile fixed.
  206.  * 4.    Declaration errors left by previous author are cleaned up.
  207.  * 5.    Redundant malloc statements removed.  Certain other
  208.  *     functions are changed to improve code efficiency.
  209.  * 6.    Code cleaned up by saber.  Removed redundant variables.
  210.  *  */
  211.  
  212. static char rcsid[] = "$Header: /Source/Media/collab/QuoteMaker/RCS/timer.c,v 2.13 92/09/12 18:43:41 drapeau Exp $";
  213.  
  214.  
  215. #include <stdio.h>
  216. #include <sys/param.h>
  217. #include <sys/types.h>
  218. #include <xview/xview.h>
  219. #include <xview/panel.h>
  220. #include <xview/textsw.h>
  221. #include <xview/xv_xrect.h>
  222. #include <gdd.h>
  223. #include "QuoteMaker_ui.h"
  224. #include <sys/stat.h>
  225. #include <xview/font.h>
  226. #include <xview/notice.h>
  227. #include <xview/notify.h>
  228. #include <xview/server.h>          
  229. #include <xview/seln.h>            
  230. #include <sys/time.h>
  231. #include "quoteMakerDefs.h"
  232. #include <math.h>
  233.  
  234. double   currentTime;
  235. double   timerInterval;
  236. double   endTime;
  237. static struct itimerval    timer;
  238. static struct itimerval updater;
  239.  
  240. void
  241.   InitTimer()
  242. {
  243.   currentTime = 0.0;
  244.   timerInterval = 0.05;
  245.   endTime = 0.0;
  246.   xv_set(QuoteMaker_baseWindow->EndTimeMessage, PANEL_LABEL_STRING, "0:00", NULL);
  247. }
  248.  
  249.  
  250. /*
  251.  * Timer Handler.  It handles time explicitly.
  252.  */
  253. Notify_value
  254.   TimerHandler(client, which)
  255. Notify_client client;
  256. int           which;
  257. {
  258.   currentTime += timerInterval;
  259. /********
  260.   printf("Timer Handler --> %lf\n", currentTime);
  261. ********/
  262.   return(NOTIFY_DONE);
  263. }
  264.  
  265.  
  266. /*
  267.  * Update Gauge handler.  Entered whenever it is time to do gauge updating
  268.  */
  269. Notify_value
  270.   UpdateGaugeHandler(client, which)
  271. Notify_client client;
  272. int           which;
  273. {
  274.   xv_set(QuoteMaker_baseWindow->DurationGauge, PANEL_VALUE,
  275.      (int)((currentTime / ((double)endTime)) * 100.0), NULL);
  276.     
  277.   if (currentTime >= endTime)
  278.   {
  279.     CancelTimer();
  280.     CancelButtonGlowTimer();
  281.     CancelButtonGlow();
  282.  
  283.     if (HideQTWAfterPlayingEdit)
  284.     {
  285.       xv_set(QuoteMaker_quotedTextBaseWindow->quotedTextBaseWindow, XV_SHOW, FALSE, NULL);
  286.     }
  287.     
  288.     ClearStatusMessage();
  289.     ClearQuotedTextWindow();
  290.     Playing = FALSE;
  291.   }
  292.  
  293.   return(NOTIFY_DONE);
  294. }
  295.  
  296. /*
  297.  * Set a periodic timer to poll for device open availability
  298.  */
  299. void
  300.   SetTimer(time)
  301. double time;
  302. {
  303.   int              mins;
  304.   double                secs;
  305.     
  306.   endTime = time;
  307.     
  308.   mins = (int)(floor(endTime / 60.0));
  309.   secs = endTime - mins * 60.0;
  310.     
  311.   sprintf(msg, "%d:%.1lf", mins, secs);
  312.   xv_set(QuoteMaker_baseWindow->EndTimeMessage,
  313.      PANEL_LABEL_STRING, msg, NULL);
  314.   
  315.   timer.it_value.tv_usec = 50000;
  316.   timer.it_value.tv_sec = 0;
  317.   timer.it_interval.tv_usec = 50000;
  318.   timer.it_interval.tv_sec = 0;
  319.   notify_set_itimer_func(QuoteMaker_baseWindow->baseWindow,
  320.              TimerHandler,
  321.              ITIMER_REAL, &timer, NULL);
  322.   
  323.   updater.it_value.tv_usec = 50000;
  324.   updater.it_value.tv_sec = 0;
  325.   updater.it_interval.tv_usec = 50000;
  326.   updater.it_interval.tv_sec = 0;
  327.   notify_set_itimer_func(QuoteMaker_QuoteWindowSpecificationsPopup->QuoteWindowSpecificationsPopup,
  328.              UpdateGaugeHandler,
  329.              ITIMER_REAL, &updater, NULL);
  330. }
  331.  
  332. /* 
  333.  * Cancel any outstanding periodic timer
  334.  */
  335. void
  336.   CancelTimer()
  337. {
  338.   (void) notify_set_itimer_func(QuoteMaker_baseWindow->baseWindow,
  339.                 NOTIFY_FUNC_NULL,
  340.                 ITIMER_REAL, 
  341.                 NULL, NULL);
  342.   (void) notify_set_itimer_func(QuoteMaker_QuoteWindowSpecificationsPopup->QuoteWindowSpecificationsPopup,
  343.                 NOTIFY_FUNC_NULL,
  344.                 ITIMER_REAL,
  345.                 NULL, NULL);
  346. }
  347.   
  348.  
  349. /*
  350.  * Button glow Time handler.  Entered whenever it is time to make the button glow.
  351.  */
  352. Notify_value
  353.   ButtonGlowTimerHandler(client, which)
  354. Notify_client client;
  355. int           which;
  356. {
  357.   UpdateButtonGlow();
  358.   return(NOTIFY_DONE);
  359. }
  360.  
  361. /*
  362.  * Set a periodic timer to poll for device open availability.  This
  363.  * timer is mainly for updating the Button glow.
  364.  */
  365. void
  366.   SetButtonGlowTimer(time)
  367. double time;
  368. {
  369.   static  struct itimerval    timer;
  370.   int            secs;
  371.   int            usecs;
  372.   extern  QuoteMaker_quotedTextBaseWindow_objects *QuoteMaker_quotedTextBaseWindow;
  373.   
  374.   secs = (int)time;
  375.   usecs = (int)((time - (double)secs) * 1000000.);
  376.   
  377.   timer.it_value.tv_usec = usecs;
  378.   timer.it_value.tv_sec = secs;
  379.   timer.it_interval.tv_usec = usecs;
  380.   timer.it_interval.tv_sec = secs;
  381.   (void)notify_set_itimer_func((Notify_client)QuoteMaker_quotedTextBaseWindow, /*  EditListPanel  used as a dummy client to be...  */
  382.                    (Notify_func)ButtonGlowTimerHandler, /*  ...notified.                                    */
  383.                    ITIMER_REAL, &timer, 
  384.                    ((struct itimerval *)0));
  385. }
  386.  
  387. /* 
  388.  * Cancel any outstanding periodic timer.  This is used for
  389.  * cancelling the timer which updates the button color.
  390.  */
  391. void
  392.   CancelButtonGlowTimer()
  393. {
  394.   extern  QuoteMaker_quotedTextBaseWindow_objects *QuoteMaker_quotedTextBaseWindow;
  395.  
  396.   (void)notify_set_itimer_func((Notify_client)QuoteMaker_quotedTextBaseWindow, /*  EditListPanelPopUp is used as a dummy to be...  */
  397.                    (Notify_func)ButtonGlowTimerHandler, /*  ...notified.                                    */
  398.                    ITIMER_REAL, 
  399.                    ((struct itimerval *)0), 
  400.                    ((struct itimerval *)0));
  401. }
  402.  
  403.  
  404.