home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************
- *
- * Copyright (C) 1996 Blue Marsh Softworks -- All Rights Reserved.
- * Portions Copyright (c) Geoworks 1992 -- All Rights Reserved
- *
- * PROJECT: Text Editor
- * MODULE: Text Methods
- * FILE: text.goc
- *
- * AUTHORS: Lawrence Hosken
- * Nathan Fiedler
- *
- * REVISION HISTORY:
- * Name Date Description
- * ---- ---- -----------
- * LH 09/21/92 Initial version
- * EB 12/16/93 Fixed up scrolling, default focus, and
- * targeting Text object for EditControl.
- * NF 04/01/95 Started work on Zoomer Text File Editor
- * NF 06/06/95 Started desktop version
- *
- * DESCRIPTION:
- * These are the function definitions and method definitions
- * for the text object.
- *
- *******************************************************************/
-
- /********************************************************************
- * Headers
- *******************************************************************/
- @include <stdapp.goh>
- @include <objects/vltextc.goh> /* VisLargeText definitions */
- /*
- * Comment out when not OmniGo version.
- */
- /* #include "hwr.h" /* Handwriting recognition */
- /* #include "grafhwr.h" /* Graffitti recognition */
- @include "app.goh" /* Includes classes and constants. */
- @include "global.goh" /* Must be after app.goh. Includes
- * globals, objects, prototypes. */
-
- /********************************************************************
- * Local Function Definitions
- *******************************************************************/
-
- @ifdef OMNIGO
- /********************************************************************
- * DoHWR
- ********************************************************************
- * SYNOPSIS: Performs HWR on the passed ink block
- * PARAMETERS: ( MemHandle blockHandle,
- * VisTextHWRFlags flags,
- * optr oself );
- * RETURNS: MemHandle
- * STRATEGY:
- * REVISION HISTORY:
- * Name Date Description
- * ---- ---- -----------
- * EB 3/1/96 Initial version
- *******************************************************************/
- MemHandle DoHWR
- (
- MemHandle blockHandle,
- VisTextHWRFlags flags,
- optr oself
- )
- {
- GeodeHandle libHandle;
- word error;
- InkHeader * inkInfo;
- MemHandle recognizedBlock = NullHandle;
- /* recognizedBlock will hold string of recognized chars */
- char * recognizedChar;
- /* high-word = char or blockhandle of string,
- * low-word = gestureType */
- dword gestureInfo;
-
- /*
- * If no HWR library exists, then there's nothing to do.
- */
- libHandle = UserGetHWRLibraryHandle();
- if ( libHandle ) {
- error = CallHWRLibrary_NoArgs( libHandle, HWRR_BEGIN_INTERACTION );
- /*
- * Begin interaction returns 0 if everything okay.
- */
- if ( error == 0 ) {
- CallHWRLibrary_NoArgs( libHandle, HWRR_RESET );
- @call oself::MSG_VIS_TEXT_SET_HWR_FILTER();
- inkInfo = MemLock( blockHandle );
- CallHWRLibrary_TwoArgs( libHandle, HWRR_ADD_POINTS,
- inkInfo->IH_count,
- &(inkInfo->IH_data) );
- MemUnlock( blockHandle );
- /*
- * First try to do multi-char recognition.
- */
- recognizedBlock = CallHWRLibrary_NoArgs( libHandle,
- HWRR_DO_MULTIPLE_CHAR_RECOGNITION );
- /*
- * If mult-char recognition didn't work, then see if
- * ink is a gesture (like the graffiti HRW engine).
- */
- if ( recognizedBlock == 0 ) {
- gestureInfo = CallHWRLibrary_NoArgs( libHandle,
- HWRR_DO_GESTURE_RECOGNITION );
- switch ( gestureInfo & 0xffff ) {
- case GT_STRING_MACRO :
- recognizedBlock = ( gestureInfo >> 16 );
- break;
- case GT_CHAR :
- recognizedBlock = MemAlloc( 16, 0,
- (HAF_ZERO_INIT|HAF_LOCK) );
- /* if allocation was successful then ... */
- if( recognizedBlock ) {
- recognizedChar = MemDeref( recognizedBlock );
- recognizedChar[0] = ( gestureInfo >> 16 );
- MemUnlock( recognizedBlock );
- }
- break;
- default :
- /*
- * The gesture may be something special like
- * GT_CUT, GT_COPY, GT_PASTE, GT_DELETE, etc.
- * This example doesn't handle those situations,
- * so we mark the block as null-handle.
- */
- recognizedBlock = NullHandle;
- } /* switch */
- }
- CallHWRLibrary_NoArgs( libHandle, HWRR_END_INTERACTION );
- }
- }
- return( recognizedBlock );
- } /* DoHWR */
- @endif
-
- /********************************************************************
- * Most of the Code for TFETextClass
- * Some code is in the DOCUMENT.GOC file.
- ********************************************************************
-
- /********************************************************************
- * MSG_META_TEXT_USER_MODIFIED
- ********************************************************************
- * SYNOPSIS: Tell parent (GenDocument) that text has been
- * modified.
- * PARAMETERS: void ( void )
- * STRATEGY: Send message to VisParent.
- *******************************************************************/
- @extern method TFETextClass, MSG_META_TEXT_USER_MODIFIED {
-
- @callsuper();
-
- /*
- * Check if we can set document dirty. Set document dirty
- * if we are allowed to.
- */
- pself = ObjDerefVis( oself );
- if ( pself->TFETI_allowChanges ) {
- @send @visParent::MSG_GEN_DOCUMENT_MARK_DIRTY();
- }
- } /* MSG_META_TEXT_USER_MODIFIED */
-
- /********************************************************************
- * MSG_PRINT_START_PRINTING
- ********************************************************************
- * SYNOPSIS: Print the text object.
- * CALLED BY: PrintControl
- * PARAMETERS: void ( optr printControlOD, GStateHandle gstate )
- * STRATEGY: Get printer margins, then send MSG_VIS_DRAW to
- * text object with the DF_PRINT flag, then signal
- * printing completed.
- *******************************************************************/
- @extern method TFETextClass, MSG_PRINT_START_PRINTING {
- dword curPage; /* Current page being printed. */
- int numPages; /* Number of pages. */
- PageSizeReport psr; /* Size of page from PrintControl. */
- word pageWidth; /* Width of paper. */
- dword pageHeight; /* Height of print area in points. */
- Boolean continu; /* Indicates when to stop printing. */
- XYValueAsDWord textSize; /* Image size of text. */
- Boolean textModified; /* TRUE if text modified. */
- optr printConOD; /* Pointer to TFEPrintControl. */
- WWFixed newPtSize; /* Used to set point size. */
- WWFixed savedSize; /* Current point size, saved. */
- FontID savedFont; /* Current font, saved. */
- /* Returned by MSG_VIS_LARGE_TEXT_GET_REGION_POS. */
- VisLargeTextGetRegionPosReturnStruct regPos;
-
- /*
- * Get the paper size as set by the user and find the
- * page width and height without margins. Then set the
- * document size to reflect current paper size.
- */
- printConOD = GeodeGetOptrNS( @TFEPrintControl );
- @call printConOD::MSG_PRINT_CONTROL_GET_PAPER_SIZE_INFO( &psr );
- pageWidth = psr.PSR_width -
- psr.PSR_margins.PCMP_left -
- psr.PSR_margins.PCMP_right;
- pageHeight = psr.PSR_height -
- psr.PSR_margins.PCMP_top -
- psr.PSR_margins.PCMP_bottom;
- @call printConOD::MSG_PRINT_CONTROL_SET_DOC_SIZE(
- psr.PSR_width, psr.PSR_height );
-
- /*
- * Have Undo ignore next changes to text object.
- * False to have it not flush queue.
- * Set flag so text won't mark document dirty.
- * Save text modified state.
- * Save text image size (width).
- */
- @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
- pself = ObjDerefVis( oself );
- pself->TFETI_allowChanges = FALSE;
- textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
- textSize = @call self::MSG_VIS_LARGE_TEXT_GET_DRAFT_REGION_SIZE( 0 );
-
- /*
- * Freeze text. Set text width to printer page width.
- */
- @send self::MSG_META_SUSPEND();
- savedFont = fontID_g;
- @send self::MSG_VIS_TEXT_SET_FONT_ID( TFE_PRINT_FONT,
- TEXT_ADDRESS_PAST_END, 1 );
- newPtSize.WWF_int = TFE_PRINT_PS;
- newPtSize.WWF_frac = 0;
- savedSize = pointSize_g;
- @send self::MSG_VIS_TEXT_SET_POINT_SIZE( newPtSize,
- TEXT_ADDRESS_PAST_END, 1 );
- @send self::MSG_VIS_LARGE_TEXT_SET_DRAFT_REGION_SIZE(
- pageWidth, pageHeight );
- @call self::MSG_META_UNSUSPEND();
-
- /*
- * Set number of pages to print.
- */
- numPages = @call self::MSG_VIS_LARGE_TEXT_GET_REGION_COUNT();
- @call printConOD::MSG_PRINT_CONTROL_SET_TOTAL_PAGE_RANGE(
- 1, numPages );
-
- /*
- * This loop is from Concepts Vol2 Code Display 23-1 on p809.
- * It is the main printing loop. It translates the text up
- * one page at a time while printing it.
- */
- for( curPage = 0; curPage < numPages; curPage++ ) {
- continu = @call printConOD::MSG_PRINT_CONTROL_REPORT_PROGRESS(
- PCPT_PAGE, curPage+1 );
- if ( continu == FALSE ) {
- break;
- }
- /*
- * Shift text up number of pages and draw text. This is done
- * by using the regions of the VisLargeText, which are each
- * a page of the text. Form feed to next page.
- */
- GrSaveState( gstate );
- @call self::MSG_VIS_LARGE_TEXT_GET_REGION_POS( ®Pos, curPage );
- GrSetClipRect( gstate, PCT_REPLACE,
- psr.PSR_margins.PCMP_left,
- psr.PSR_margins.PCMP_top,
- pageWidth +
- psr.PSR_margins.PCMP_right,
- regPos.VLTGRPRS_height +
- psr.PSR_margins.PCMP_bottom );
- GrApplyTranslationDWord( gstate, psr.PSR_margins.PCMP_left,
- -( regPos.VLTGRPRS_yPosition -
- psr.PSR_margins.PCMP_top ) );
- GrInitDefaultTransform( gstate );
- @call self::MSG_VIS_DRAW( DF_PRINT, gstate );
- GrRestoreState( gstate );
- GrNewPage( gstate, PEC_FORM_FEED );
- }
-
- /*
- * Restore previous text settings.
- */
- @send self::MSG_META_SUSPEND();
- @send self::MSG_VIS_TEXT_SET_FONT_ID( savedFont,
- TEXT_ADDRESS_PAST_END, 1 );
- @send self::MSG_VIS_TEXT_SET_POINT_SIZE( savedSize,
- TEXT_ADDRESS_PAST_END, 1 );
- @send self::MSG_VIS_LARGE_TEXT_SET_DRAFT_REGION_SIZE(
- DWORD_X( textSize ), DWORD_Y( textSize ) );
- @send self::MSG_META_UNSUSPEND();
-
- /*
- * Restore text modified state and re-enable undo.
- */
- pself->TFETI_allowChanges = TRUE;
- if ( textModified == FALSE ) {
- @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
- }
- @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
-
- /*
- * Wrap up the printing (tell PC if done or cancelled).
- */
- if ( continu ) {
- @send printConOD::MSG_PRINT_CONTROL_PRINTING_COMPLETED();
- }
- else {
- @send printConOD::MSG_PRINT_CONTROL_PRINTING_CANCELLED();
- }
- } /* MSG_PRINT_START_PRINTING */
-
- /********************************************************************
- * MSG_VIS_TEXT_SET_POINT_SIZE
- ********************************************************************
- * SYNOPSIS: Intercept the set point size message so we can
- * tell Undo to ignore the change.
- * CALLED BY: PointSizeControl
- * PARAMETERS: void ( WWFixed pointSize, dword rangeEnd,
- * dword rangeStart )
- * SIDE EFFECTS: Tells Undo to ignore point size change.
- * STRATEGY: Send message to process telling it to ignore the
- * next change to the target, then call superclass,
- * then turn Undo back on.
- *******************************************************************/
- @extern method TFETextClass, MSG_VIS_TEXT_SET_POINT_SIZE {
- Boolean textModified; /* TRUE if text modified. */
-
- /* Update our copy of the current point size. */
- pointSize_g = pointSize;
-
- /*
- * Have Undo ignore next changes to text object.
- * False to have it not flush queue.
- */
- @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
- pself = ObjDerefVis( oself );
- pself->TFETI_allowChanges = FALSE;
- textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
-
- @callsuper();
-
- /*
- * Check if text was modified previously and set appropriately.
- * Re-enable undo actions.
- */
- if ( textModified == FALSE ) {
- @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
- }
- pself->TFETI_allowChanges = TRUE;
- @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
- } /* MSG_VIS_TEXT_SET_POINT_SIZE */
-
- /********************************************************************
- * MSG_VIS_TEXT_SET_FONT_ID
- ********************************************************************
- * SYNOPSIS: Intercept the set font message so we can save the
- * new font ID and tell Undo to ignore the change.
- * CALLED BY: FontControl
- * PARAMETERS: void ( FontID fid,
- * dword rangeEnd,
- * dword rangeStart )
- * SIDE EFFECTS: Tells Undo to ignore font change.
- * STRATEGY: Send message to process telling it to ignore the
- * next change to the target, then call superclass,
- * then turn Undo back on.
- *******************************************************************/
- @extern method TFETextClass, MSG_VIS_TEXT_SET_FONT_ID {
- Boolean textModified; /* TRUE if text modified. */
-
- /* Update our copy of the current font ID. */
- fontID_g = fid;
-
- /*
- * Have Undo ignore next changes to text object.
- * False to have it not flush queue.
- */
- @call process::MSG_GEN_PROCESS_UNDO_IGNORE_ACTIONS( FALSE );
- pself = ObjDerefVis( oself );
- pself->TFETI_allowChanges = FALSE;
- textModified = @call self::MSG_VIS_TEXT_GET_USER_MODIFIED_STATE();
-
- @callsuper();
-
- /*
- * Check if text was modified previously and set appropriately.
- * Re-enable undo actions.
- */
- if ( textModified == FALSE ) {
- @send self::MSG_VIS_TEXT_SET_NOT_USER_MODIFIED();
- }
- pself->TFETI_allowChanges = TRUE;
- @send process::MSG_GEN_PROCESS_UNDO_ACCEPT_ACTIONS();
- } /* MSG_VIS_TEXT_SET_FONT_ID */
-
- /********************************************************************
- * MSG_VIS_TEXT_REPLACE_WITH_HWR
- ********************************************************************
- * SYNOPSIS: Performs HWR on the passed ink block
- * PARAMETERS: ( HWRContext context,
- * MemHandle ink,
- * VisTextHWRFlags flags,
- * VisTextRange range );
- * RETURNS: void
- * STRATEGY:
- * REVISION HISTORY:
- * Name Date Description
- * ---- ---- -----------
- * EB 3/1/96 Initial version
- *******************************************************************/
- @extern method TFETextClass, MSG_VIS_TEXT_REPLACE_WITH_HWR {
- @ifdef OMNIGO
- MemHandle textBlock;
- char * textPtr;
-
- if ( pself->VTI_state & VTS_EDITABLE ) {
- textBlock = DoHWR( ink, flags, oself );
- if ( textBlock ) {
- textPtr = MemLock( textBlock );
- if( textPtr[0] == 0 ) {
- UserStandardSound( SST_NOTIFY );
- }
- else {
- @call self::MSG_VIS_TEXT_REPLACE_SELECTION_PTR( textPtr, 0 );
- }
- /* Free the recognized text. */
- MemFree( textBlock );
- }
- else {
- UserStandardSound( SST_NOTIFY );
- }
- }
- MemDecRefCount( ink );
- @endif
- } /* MSG_VIS_TEXT_REPLACE_WITH_HWR */
-
-