home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / Chip_1998-03_cd.bin / zkuste / SVET_GEO / TEXTDESK / TEXTDESK.ZIP / TEXT.GOC < prev    next >
Text File  |  1996-04-06  |  17KB  |  433 lines

  1. /********************************************************************
  2.  *
  3.  * Copyright (C) 1996 Blue Marsh Softworks -- All Rights Reserved.
  4.  * Portions Copyright (c) Geoworks 1992 -- All Rights Reserved
  5.  *
  6.  * PROJECT:      Text Editor
  7.  * MODULE:       Text Methods
  8.  * FILE:         text.goc
  9.  *
  10.  * AUTHORS:      Lawrence Hosken
  11.  *               Nathan Fiedler
  12.  *
  13.  * REVISION HISTORY:
  14.  *      Name     Date      Description
  15.  *      ----     ----      -----------
  16.  *       LH      09/21/92  Initial version
  17.  *       EB      12/16/93  Fixed up scrolling, default focus, and
  18.  *                         targeting Text object for EditControl.
  19.  *       NF      04/01/95  Started work on Zoomer Text File Editor
  20.  *       NF      06/06/95  Started desktop version
  21.  *
  22.  * DESCRIPTION:
  23.  *      These are the function definitions and method definitions
  24.  *      for the text object.
  25.  *
  26.  *******************************************************************/
  27.  
  28. /********************************************************************
  29.  *                 Headers
  30.  *******************************************************************/
  31.     @include <stdapp.goh>
  32.     @include <objects/vltextc.goh> /* VisLargeText definitions */
  33.        /*
  34.         * Comment out when not OmniGo version.
  35.         */
  36. /*    #include "hwr.h"               /* Handwriting recognition */
  37. /*    #include "grafhwr.h"           /* Graffitti recognition */
  38.     @include "app.goh"             /* Includes classes and constants. */
  39.     @include "global.goh"          /* Must be after app.goh. Includes
  40.                                     * globals, objects, prototypes. */
  41.  
  42. /********************************************************************
  43.  *                 Local Function Definitions
  44.  *******************************************************************/
  45.  
  46. @ifdef OMNIGO
  47. /********************************************************************
  48.  *                 DoHWR
  49.  ********************************************************************
  50.  * SYNOPSIS:     Performs HWR on the passed ink block
  51.  * PARAMETERS:   ( MemHandle       blockHandle,
  52.  *                 VisTextHWRFlags flags,
  53.  *                 optr            oself );
  54.  * RETURNS:      MemHandle
  55.  * STRATEGY:
  56.  * REVISION HISTORY:
  57.  *    Name    Date        Description
  58.  *    ----    ----        -----------
  59.  *    EB    3/1/96        Initial version
  60.  *******************************************************************/
  61. MemHandle DoHWR
  62.   (
  63.   MemHandle       blockHandle,
  64.   VisTextHWRFlags flags,
  65.   optr            oself
  66.   )
  67. {
  68.   GeodeHandle libHandle;
  69.   word error;
  70.   InkHeader * inkInfo;
  71.   MemHandle recognizedBlock = NullHandle;
  72.      /* recognizedBlock will hold string of recognized chars */
  73.   char * recognizedChar;
  74.      /* high-word = char or blockhandle of string,
  75.       * low-word = gestureType */
  76.   dword gestureInfo;
  77.  
  78.      /*
  79.       * If no HWR library exists, then there's nothing to do.
  80.       */
  81.   libHandle = UserGetHWRLibraryHandle();
  82.   if ( libHandle ) {
  83.     error = CallHWRLibrary_NoArgs( libHandle, HWRR_BEGIN_INTERACTION );
  84.        /*
  85.         * Begin interaction returns 0 if everything okay.
  86.         */
  87.     if ( error == 0 ) {
  88.       CallHWRLibrary_NoArgs( libHandle, HWRR_RESET );
  89.       @call oself::MSG_VIS_TEXT_SET_HWR_FILTER();
  90.       inkInfo = MemLock( blockHandle );
  91.       CallHWRLibrary_TwoArgs( libHandle, HWRR_ADD_POINTS,
  92.                               inkInfo->IH_count,
  93.                               &(inkInfo->IH_data) );
  94.       MemUnlock( blockHandle );
  95.          /*
  96.           * First try to do multi-char recognition.
  97.           */
  98.       recognizedBlock = CallHWRLibrary_NoArgs( libHandle,
  99.                             HWRR_DO_MULTIPLE_CHAR_RECOGNITION );
  100.          /*
  101.           * If mult-char recognition didn't work, then see if
  102.           * ink is a gesture (like the graffiti HRW engine).
  103.           */
  104.       if ( recognizedBlock == 0 ) {
  105.         gestureInfo = CallHWRLibrary_NoArgs( libHandle,
  106.                           HWRR_DO_GESTURE_RECOGNITION );
  107.         switch ( gestureInfo & 0xffff ) {
  108.           case GT_STRING_MACRO :
  109.             recognizedBlock = ( gestureInfo >> 16 );
  110.             break;
  111.           case GT_CHAR :
  112.             recognizedBlock = MemAlloc( 16, 0,
  113.                                         (HAF_ZERO_INIT|HAF_LOCK) );
  114.                /* if allocation was successful then ... */
  115.             if( recognizedBlock ) {
  116.               recognizedChar = MemDeref( recognizedBlock );
  117.               recognizedChar[0] = ( gestureInfo >> 16 );
  118.               MemUnlock( recognizedBlock );
  119.             }
  120.             break;
  121.           default :
  122.                /*
  123.                 * The gesture may be something special like
  124.                 * GT_CUT, GT_COPY, GT_PASTE, GT_DELETE, etc.
  125.                 * This example doesn't handle those situations,
  126.                 * so we mark the block as null-handle.
  127.                 */
  128.             recognizedBlock = NullHandle;
  129.         } /* switch */
  130.       }
  131.       CallHWRLibrary_NoArgs( libHandle, HWRR_END_INTERACTION );
  132.     }
  133.   }
  134.   return( recognizedBlock );
  135. } /* DoHWR */
  136. @endif
  137.  
  138. /********************************************************************
  139.  *                 Most of the Code for TFETextClass
  140.  * Some code is in the DOCUMENT.GOC file.
  141.  ********************************************************************
  142.  
  143. /********************************************************************
  144.  *                 MSG_META_TEXT_USER_MODIFIED
  145.  ********************************************************************
  146.  * SYNOPSIS:     Tell parent (GenDocument) that text has been
  147.  *               modified.
  148.  * PARAMETERS:   void ( void )
  149.  * STRATEGY:     Send message to VisParent.
  150.  *******************************************************************/
  151. @extern method TFETextClass, MSG_META_TEXT_USER_MODIFIED {
  152.  
  153.   @callsuper();
  154.  
  155.      /*
  156.       * Check if we can set document dirty. Set document dirty
  157.       * if we are allowed to.
  158.       */
  159.   pself = ObjDerefVis( oself );
  160.   if ( pself->TFETI_allowChanges ) {
  161.     @send @visParent::MSG_GEN_DOCUMENT_MARK_DIRTY();
  162.   }
  163. } /* MSG_META_TEXT_USER_MODIFIED */
  164.  
  165. /********************************************************************
  166.  *                 MSG_PRINT_START_PRINTING
  167.  ********************************************************************
  168.  * SYNOPSIS:     Print the text object.
  169.  * CALLED BY:    PrintControl
  170.  * PARAMETERS:   void ( optr printControlOD, GStateHandle gstate )
  171.  * STRATEGY:     Get printer margins, then send MSG_VIS_DRAW to
  172.  *               text object with the DF_PRINT flag, then signal
  173.  *               printing completed.
  174.  *******************************************************************/
  175. @extern method TFETextClass, MSG_PRINT_START_PRINTING {
  176.   dword          curPage;      /* Current page being printed. */
  177.   int            numPages;     /* Number of pages. */
  178.   PageSizeReport psr;          /* Size of page from PrintControl. */
  179.   word           pageWidth;    /* Width of paper. */
  180.   dword          pageHeight;   /* Height of print area in points. */
  181.   Boolean        continu;      /* Indicates when to stop printing. */
  182.   XYValueAsDWord textSize;     /* Image size of text. */
  183.   Boolean        textModified; /* TRUE if text modified. */
  184.   optr           printConOD;   /* Pointer to TFEPrintControl. */
  185.   WWFixed        newPtSize;    /* Used to set point size. */
  186.   WWFixed        savedSize;    /* Current point size, saved. */
  187.   FontID         savedFont;    /* Current font, saved. */
  188.      /* Returned by MSG_VIS_LARGE_TEXT_GET_REGION_POS. */
  189.   VisLargeTextGetRegionPosReturnStruct regPos;
  190.  
  191.      /*
  192.       * Get the paper size as set by the user and find the
  193.       * page width and height without margins. Then set the
  194.       * document size to reflect current paper size.
  195.       */
  196.   printConOD = GeodeGetOptrNS( @TFEPrintControl );
  197.   @call printConOD::MSG_PRINT_CONTROL_GET_PAPER_SIZE_INFO( &psr );
  198.   pageWidth  = psr.PSR_width -
  199.                psr.PSR_margins.PCMP_left -
  200.                psr.PSR_margins.PCMP_right;
  201.   pageHeight = psr.PSR_height -
  202.                psr.PSR_margins.PCMP_top -
  203.                psr.PSR_margins.PCMP_bottom;
  204.   @call printConOD::MSG_PRINT_CONTROL_SET_DOC_SIZE(
  205.                              psr.PSR_width, psr.PSR_height );
  206.  
  207.      /*
  208.       * Have Undo ignore next changes to text object.
  209.       * False to have it not flush queue.
  210.       * Set flag so text won't mark document dirty.
  211.       * Save text modified state.
  212.       * Save text image size (width).
  213.       */
  214.   @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
  215.   pself = ObjDerefVis( oself );
  216.   pself->TFETI_allowChanges = FALSE;
  217.   textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
  218.   textSize = @call self::MSG_VIS_LARGE_TEXT_GET_DRAFT_REGION_SIZE( 0 );
  219.  
  220.      /*
  221.       * Freeze text. Set text width to printer page width.
  222.       */
  223.   @send self::MSG_META_SUSPEND();
  224.   savedFont = fontID_g;
  225.   @send self::MSG_VIS_TEXT_SET_FONT_ID( TFE_PRINT_FONT,
  226.                                         TEXT_ADDRESS_PAST_END, 1 );
  227.   newPtSize.WWF_int  = TFE_PRINT_PS;
  228.   newPtSize.WWF_frac = 0;
  229.   savedSize = pointSize_g;
  230.   @send self::MSG_VIS_TEXT_SET_POINT_SIZE( newPtSize,
  231.                                            TEXT_ADDRESS_PAST_END, 1 );
  232.   @send self::MSG_VIS_LARGE_TEXT_SET_DRAFT_REGION_SIZE(
  233.                   pageWidth, pageHeight );
  234.   @call self::MSG_META_UNSUSPEND();
  235.  
  236.      /*
  237.       * Set number of pages to print.
  238.       */
  239.   numPages = @call self::MSG_VIS_LARGE_TEXT_GET_REGION_COUNT();
  240.   @call printConOD::MSG_PRINT_CONTROL_SET_TOTAL_PAGE_RANGE(
  241.                         1, numPages );
  242.  
  243.      /*
  244.       * This loop is from Concepts Vol2 Code Display 23-1 on p809.
  245.       * It is the main printing loop. It translates the text up
  246.       * one page at a time while printing it.
  247.       */
  248.   for( curPage = 0; curPage < numPages; curPage++ ) {
  249.     continu = @call printConOD::MSG_PRINT_CONTROL_REPORT_PROGRESS(
  250.                                     PCPT_PAGE, curPage+1 );
  251.     if ( continu == FALSE ) {
  252.       break;
  253.     }
  254.        /*
  255.         * Shift text up number of pages and draw text. This is done
  256.         * by using the regions of the VisLargeText, which are each
  257.         * a page of the text. Form feed to next page.
  258.         */
  259.     GrSaveState( gstate );
  260.     @call self::MSG_VIS_LARGE_TEXT_GET_REGION_POS( ®Pos, curPage );
  261.     GrSetClipRect( gstate, PCT_REPLACE,
  262.                    psr.PSR_margins.PCMP_left,
  263.                    psr.PSR_margins.PCMP_top,
  264.                    pageWidth +
  265.                        psr.PSR_margins.PCMP_right,
  266.                    regPos.VLTGRPRS_height +
  267.                        psr.PSR_margins.PCMP_bottom );
  268.     GrApplyTranslationDWord( gstate, psr.PSR_margins.PCMP_left,
  269.                              -( regPos.VLTGRPRS_yPosition -
  270.                                 psr.PSR_margins.PCMP_top ) );
  271.     GrInitDefaultTransform( gstate );
  272.     @call self::MSG_VIS_DRAW( DF_PRINT, gstate );
  273.     GrRestoreState( gstate );
  274.     GrNewPage( gstate, PEC_FORM_FEED );
  275.   }
  276.  
  277.      /*
  278.       * Restore previous text settings.
  279.       */
  280.   @send self::MSG_META_SUSPEND();
  281.   @send self::MSG_VIS_TEXT_SET_FONT_ID( savedFont,
  282.                                         TEXT_ADDRESS_PAST_END, 1 );
  283.   @send self::MSG_VIS_TEXT_SET_POINT_SIZE( savedSize,
  284.                                            TEXT_ADDRESS_PAST_END, 1 );
  285.   @send self::MSG_VIS_LARGE_TEXT_SET_DRAFT_REGION_SIZE(
  286.                   DWORD_X( textSize ), DWORD_Y( textSize ) );
  287.   @send self::MSG_META_UNSUSPEND();
  288.  
  289.      /*
  290.       * Restore text modified state and re-enable undo.
  291.       */
  292.   pself->TFETI_allowChanges = TRUE;
  293.   if ( textModified == FALSE ) {
  294.     @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
  295.   }
  296.   @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
  297.  
  298.      /*
  299.       * Wrap up the printing (tell PC if done or cancelled).
  300.       */
  301.   if ( continu ) {
  302.     @send printConOD::MSG_PRINT_CONTROL_PRINTING_COMPLETED();
  303.   }
  304.   else {
  305.     @send printConOD::MSG_PRINT_CONTROL_PRINTING_CANCELLED();
  306.   }
  307. } /* MSG_PRINT_START_PRINTING */
  308.  
  309. /********************************************************************
  310.  *                 MSG_VIS_TEXT_SET_POINT_SIZE
  311.  ********************************************************************
  312.  * SYNOPSIS:     Intercept the set point size message so we can
  313.  *               tell Undo to ignore the change.
  314.  * CALLED BY:    PointSizeControl
  315.  * PARAMETERS:   void ( WWFixed pointSize, dword rangeEnd,
  316.  *                      dword rangeStart )
  317.  * SIDE EFFECTS: Tells Undo to ignore point size change.
  318.  * STRATEGY:     Send message to process telling it to ignore the
  319.  *               next change to the target, then call superclass,
  320.  *               then turn Undo back on.
  321.  *******************************************************************/
  322. @extern method TFETextClass, MSG_VIS_TEXT_SET_POINT_SIZE {
  323.   Boolean textModified; /* TRUE if text modified. */
  324.  
  325.      /* Update our copy of the current point size. */
  326.   pointSize_g = pointSize;
  327.  
  328.      /*
  329.       * Have Undo ignore next changes to text object.
  330.       * False to have it not flush queue.
  331.       */
  332.   @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
  333.   pself = ObjDerefVis( oself );
  334.   pself->TFETI_allowChanges = FALSE;
  335.   textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
  336.  
  337.   @callsuper();
  338.  
  339.      /*
  340.       * Check if text was modified previously and set appropriately.
  341.       * Re-enable undo actions.
  342.       */
  343.   if ( textModified == FALSE ) {
  344.     @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
  345.   }
  346.   pself->TFETI_allowChanges = TRUE;
  347.   @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
  348. } /* MSG_VIS_TEXT_SET_POINT_SIZE */
  349.  
  350. /********************************************************************
  351.  *                 MSG_VIS_TEXT_SET_FONT_ID
  352.  ********************************************************************
  353.  * SYNOPSIS:     Intercept the set font message so we can save the
  354.  *               new font ID and tell Undo to ignore the change.
  355.  * CALLED BY:    FontControl
  356.  * PARAMETERS:   void ( FontID fid,
  357.  *                      dword  rangeEnd,
  358.  *                      dword  rangeStart )
  359.  * SIDE EFFECTS: Tells Undo to ignore font change.
  360.  * STRATEGY:     Send message to process telling it to ignore the
  361.  *               next change to the target, then call superclass,
  362.  *               then turn Undo back on.
  363.  *******************************************************************/
  364. @extern method TFETextClass, MSG_VIS_TEXT_SET_FONT_ID {
  365.   Boolean textModified; /* TRUE if text modified. */
  366.  
  367.      /* Update our copy of the current font ID. */
  368.   fontID_g = fid;
  369.  
  370.      /*
  371.       * Have Undo ignore next changes to text object.
  372.       * False to have it not flush queue.
  373.       */
  374.   @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
  375.   pself = ObjDerefVis( oself );
  376.   pself->TFETI_allowChanges = FALSE;
  377.   textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
  378.  
  379.   @callsuper();
  380.  
  381.      /*
  382.       * Check if text was modified previously and set appropriately.
  383.       * Re-enable undo actions.
  384.       */
  385.   if ( textModified == FALSE ) {
  386.     @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
  387.   }
  388.   pself->TFETI_allowChanges = TRUE;
  389.   @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
  390. } /* MSG_VIS_TEXT_SET_FONT_ID */
  391.  
  392. /********************************************************************
  393.  *                 MSG_VIS_TEXT_REPLACE_WITH_HWR
  394.  ********************************************************************
  395.  * SYNOPSIS:     Performs HWR on the passed ink block
  396.  * PARAMETERS:   ( HWRContext      context,
  397.  *                 MemHandle       ink,
  398.  *                 VisTextHWRFlags flags,
  399.  *                 VisTextRange    range );
  400.  * RETURNS:      void
  401.  * STRATEGY:
  402.  * REVISION HISTORY:
  403.  *    Name    Date        Description
  404.  *    ----    ----        -----------
  405.  *    EB    3/1/96        Initial version
  406.  *******************************************************************/
  407. @extern method TFETextClass, MSG_VIS_TEXT_REPLACE_WITH_HWR {
  408. @ifdef OMNIGO
  409.   MemHandle textBlock;
  410.   char * textPtr;
  411.  
  412.   if ( pself->VTI_state & VTS_EDITABLE ) {
  413.     textBlock = DoHWR( ink, flags, oself );
  414.     if ( textBlock ) {
  415.       textPtr = MemLock( textBlock );
  416.       if( textPtr[0] == 0 ) {
  417.         UserStandardSound( SST_NOTIFY );
  418.       }
  419.       else {
  420.         @call self::MSG_VIS_TEXT_REPLACE_SELECTION_PTR( textPtr, 0 );
  421.       }
  422.          /* Free the recognized text. */
  423.       MemFree( textBlock );
  424.     }
  425.     else {
  426.       UserStandardSound( SST_NOTIFY );
  427.     }
  428.   }
  429.   MemDecRefCount( ink );
  430. @endif
  431. } /* MSG_VIS_TEXT_REPLACE_WITH_HWR */
  432.  
  433.