home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xtici.zip / xtici / gesture.c < prev    next >
C/C++ Source or Header  |  1991-08-28  |  7KB  |  249 lines

  1. /*
  2.  * Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
  3.  *     All Rights Reserved
  4.  * 
  5.  * This file is a component of an X Window System client which uses the Xcms 
  6.  * Color Management System.  TekColor is a trademark of Tektronix, Inc.  The
  7.  * TekColor Editor is the subject of U.S. and foreign patents pending.  The
  8.  * term "TekHVC" designates a particular color space that is the subject of
  9.  * U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
  10.  * Permission is hereby granted to use, copy, modify, sell, and otherwise
  11.  * distribute this software and its documentation for the X Window System
  12.  * environment, for any purpose and without fee, provided that:
  13.  * 
  14.  * 1.    The code and documentation are only used to implement a 
  15.  *      TekColor Editor in an X Window System environment; and
  16.  * 2.    This copyright and permission notice is reproduced in all copies
  17.  *     of the code and in supporting documentation.
  18.  * 
  19.  * Permission is granted to modify this code as required to allow it to
  20.  * be compiled on any host computer, provided that the functionality of
  21.  * the TekColor Editor is not modified in any way.  A description of any 
  22.  * modifications must be sent to Tektronix, Inc.  Contact 
  23.  * Tektronix Inc., P.O. Box 1000, Mail Station 60-850, 
  24.  * Network Displays Division Engineering, Wilsonville, OR 97070.
  25.  *
  26.  * Tektronix makes no representation about the suitability of this software
  27.  * for any purpose.  It is provided "as is" and with all faults.
  28.  * 
  29.  * TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
  30.  * INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  31.  * PARTICULAR PURPOSE.  IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
  32.  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  33.  * RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
  34.  * CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  35.  * CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
  36.  * 
  37.  *    NAME
  38.  *        gesture.c -- various routines to handle specific actions
  39.  *
  40.  *    DESCRIPTION
  41.  *        
  42.  *
  43.  *    HISTORY
  44.  *
  45.  *    HISTORY END
  46.  *
  47.  */
  48.  
  49. #ifndef LINT
  50. static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
  51. #ifdef RCS_ID
  52. static char *rcsid=  "$Header: gesture.c,v 1.1 91/08/22 11:15:04 adamsc Exp $";
  53. #endif /* RCS_ID */
  54. #endif /* LINT */
  55.  
  56. #include "xtici.h"
  57. #include <X11/Xaw/AsciiText.h>
  58.  
  59. /* indicates if the user is in the middle of a gesture */
  60. int gesture = GestureNone;
  61.  
  62. Bool restoreFill = False;
  63.  
  64. /* This is a routine that looks to see if a valid entry has 
  65.  * been made in a text widget.
  66.  */
  67. /* ARGSUSED */
  68. void Leave (wid, event)
  69. Widget wid;
  70. XAnyEvent event;
  71. {
  72.     switch (gesture) {
  73.       case GestureHue:
  74.       case GestureValue:
  75.       case GestureChroma:
  76.       case GestureRed:
  77.       case GestureGreen:
  78.       case GestureBlue:
  79.       case GestureUprime:
  80.       case GestureVprime:
  81.       case GestureCapY:
  82.       case GestureCell0:
  83.       case GestureCell1:
  84.           break;
  85.       default:
  86.       return;
  87.     }
  88.     TerminateGesture();
  89.     gesture = GestureNone;
  90. }
  91.       
  92. /*
  93.  * The user has begun a new gesture.
  94.  * Examine the current state to determine if an existing gesture must be
  95.  * terminated.  Set the passed undo state and new gesture.
  96.  */
  97. void BeginGesture(gestureFlag)
  98. int gestureFlag;
  99. {
  100.     if (gesture != GestureNone)
  101.     TerminateGesture();
  102.  
  103.     if ( (gestureFlag == GestureMouse) && (leafState & LeafFilled) ) {
  104.     restoreFill = True;
  105.     NewLeafState(leafState & ~LeafFilled, NoWidget);
  106.     }
  107.  
  108.     gesture = gestureFlag;
  109. }
  110.  
  111. /*
  112.  * A gesture which changed the color has ended.  Adjust state and interface.
  113.  * Assumes currentHvc contains the latest values.
  114.  */
  115. void EndColor(from)
  116. int from;
  117. {
  118.     gesture = GestureNone;
  119.  
  120.     if (restoreFill) {
  121.     restoreFill = False;
  122.     NewLeafState(leafState | LeafFilled, NoWidget);
  123.     }
  124.  
  125.     if (RgbShowing && (from != RgbWidget) )
  126.     UpdateShowWidget(RgbWidget);
  127.     if (UvyShowing && (from != UvyWidget) )
  128.     UpdateShowWidget(UvyWidget);
  129. }
  130.  
  131. void EndIndex(from)
  132. int from;
  133. {
  134.     gesture = GestureNone;
  135.  
  136.     /* May have ended on a reserved index, don't allow that */
  137.     if (IndexProtected(currentIndex)) {
  138.     return;
  139.     }
  140.  
  141.     EndColor(from);
  142. }
  143.  
  144. /*
  145.  * Take action to force user to terminate a gesture or abort it.
  146.  * Mouse gestures are automatically terminated by the constraints of
  147.  * button transition reporting when dragging.
  148.  * What we are really addressing here is when the user types in text
  149.  * and then moves off to somewhere else without entering (CR).
  150.  * We cannot allow this because this leaves text in the widget that
  151.  * does not accurately reflect current values.
  152.  */
  153. static char *returnHelp = "\
  154. Values entered into text sensitive fields are not applied until a the\n\
  155. carriage return key is used.  If you choose OK, the text will be applied\n\
  156. as if you had typed the return.  If you choose Cancel, the entered text\n\
  157. will be discarded.";
  158.  
  159. void TerminateGesture()
  160. {
  161.     XcmsColor hvc;
  162.     int change = 0;
  163.     XColor rgb;
  164.     XcmsCIEuvY uvy;
  165.     Pixel newIndex;
  166.  
  167.     /* This should not happen */
  168.     if (gesture <= GestureMouse) {
  169.     return;
  170.     }
  171.  
  172.     if (Ask("Apply last keyboard input?", returnHelp) == MessageOK) {
  173.     /* get text value and apply */
  174.     /* does no good to set undo here, user has started another gesture */
  175.     switch (gesture) {
  176.         case GestureHue:
  177.         case GestureValue:
  178.         case GestureChroma:
  179.         GetShowHvc(&hvc);
  180.         if (hvc.spec.TekHVC.H != currentHvc.spec.TekHVC.H)
  181.             change |= HueChange;
  182.         if (hvc.spec.TekHVC.V != currentHvc.spec.TekHVC.V)
  183.             change |= ValueChange;
  184.         if (hvc.spec.TekHVC.C != currentHvc.spec.TekHVC.C)
  185.             change |= ChromaChange;
  186.         if (change) {
  187.             hvc.pixel = currentHvc.pixel;
  188.             NewHvc(&hvc, NoWidget, change);
  189.         }
  190.         break;
  191.         case GestureRed:
  192.         case GestureGreen:
  193.         case GestureBlue:
  194.         GetShowRgb(&rgb);
  195.         if (rgb.red != currentRgb.red)
  196.             NewRgb(RedChange, rgb.red, NoWidget);
  197.         if (rgb.green != currentRgb.green)
  198.             NewRgb(GreenChange, rgb.green, NoWidget);
  199.         if (rgb.blue != currentRgb.blue)
  200.             NewRgb(BlueChange, rgb.blue, NoWidget);
  201.         break;
  202.         case GestureUprime:
  203.         case GestureVprime:
  204.         case GestureCapY:
  205.         GetShowUvy(&uvy);
  206.         if (uvy.u_prime != currentUvy.u_prime)
  207.             NewUvy(UprimeChange, uvy.u_prime, NoWidget);
  208.         if (uvy.v_prime != currentUvy.v_prime)
  209.             NewUvy(VprimeChange, uvy.v_prime, NoWidget);
  210.         if (uvy.Y != currentUvy.Y)
  211.             NewUvy(CapYChange, uvy.Y, NoWidget);
  212.         break;
  213.         case GestureCell0:
  214.         case GestureCell1:
  215.         newIndex = GetPatchIndex(gesture - GestureCell0);
  216.         if (newIndex != currentIndex)
  217.             NewIndex((int)newIndex, NoWidget);
  218.         else
  219.             UpdatePatchWidget(NoWidget);
  220.         break;
  221.     }
  222. #ifdef LATER
  223.     } else {
  224.     /* reset text value */
  225.     switch (gesture) {
  226.     case GestureHue:
  227.     case GestureValue:
  228.     case GestureChroma:
  229.         UpdateShowWidget(HvcWidget);
  230.         break;
  231.     case GestureRed:
  232.     case GestureGreen:
  233.     case GestureBlue:
  234.         UpdateShowWidget(RgbWidget);
  235.         break;
  236.     case GestureUprime:
  237.     case GestureVprime:
  238.     case GestureCapY:
  239.         UpdateShowWidget(UvyWidget);
  240.         break;
  241.     case GestureCell0:
  242.     case GestureCell1:
  243.         UpdatePatchWidget(NoWidget);
  244.         break;
  245.     }
  246. #endif
  247.     }
  248. }
  249.