home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CTSMEditField.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.7 KB  |  283 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "CTSMEditField.h"
  20.  
  21.  
  22. Boolean                        CTSMEditField::sInitialized     = false;
  23. Boolean                     CTSMEditField::sHasTSM                 = false;
  24. TSMTEPreUpdateUPP    CTSMEditField::sPreUpdateUPP     = NewTSMTEPreUpdateProc( CTSMEditField::PreUpdate );
  25. TSMTEPostUpdateUPP    CTSMEditField::sPostUpdateUPP     = NewTSMTEPostUpdateProc( CTSMEditField::PostUpdate );
  26.  
  27.  
  28. //    Default constructor
  29.  
  30. CTSMEditField::CTSMEditField ()
  31. {
  32. }    //    CTSMEditField::CTSMEditField
  33.  
  34. CTSMEditField::CTSMEditField( LStream* inStream )
  35.  
  36.     :    LEditField( inStream )
  37.  
  38.     {
  39.  
  40.         if ( !sInitialized )
  41.             Initialize();
  42.             
  43.         OSErr        result                    = noErr;
  44.         OSType    theServiceTypes = kTSMTEInterfaceType;
  45.         
  46.         mTSMDocID = 0;
  47.         mTSMTEHandle = NULL;
  48.         
  49.  
  50.         Try_ 
  51.             {
  52.             
  53.               if ( sHasTSM )
  54.                   {
  55.                   
  56.                         result = ::NewTSMDocument( 1, &theServiceTypes, &mTSMDocID, static_cast<long>(&mTSMTEHandle) );
  57.                         ThrowIfOSErr_( result );
  58.  
  59.                         if ( !mTSMTEHandle && mTSMDocID )
  60.                             {
  61.                             
  62.                                 ::DeleteTSMDocument( mTSMDocID );
  63.                                 mTSMDocID = 0;
  64.                                 
  65.                                 Throw_( paramErr );
  66.                             
  67.                             }
  68.                         
  69.                         (*mTSMTEHandle)->textH = mTextEditH;
  70.                         (*mTSMTEHandle)->preUpdateProc = sPreUpdateUPP;
  71.                         (*mTSMTEHandle)->postUpdateProc = sPostUpdateUPP;
  72.                         (*mTSMTEHandle)->updateFlag = kTSMTEAutoScroll;
  73.                         (*mTSMTEHandle)->refCon = (Int32)this;
  74.                                 
  75.                     }
  76.                     
  77.             } 
  78.                 
  79.         Catch_( inErr ) 
  80.             {
  81.             
  82. // Failure just means that this edit field won't support TSMTE
  83.     
  84.             } 
  85.             
  86.         EndCatch_;
  87.                 
  88.     }
  89.  
  90. //
  91. //    Parameterized constructor
  92.  
  93. CTSMEditField::CTSMEditField (    const SPaneInfo&    inPaneInfo,
  94.                                         Str255                inString,
  95.                                         ResIDT                inTextTraitsID,
  96.                                         Int16                    inMaxChars,
  97.                                         Uint8                    inAttributes,
  98.                                         TEKeyFilterFunc        inKeyFilter,
  99.                                         LCommander*            inSuper)
  100.                     : LEditField (     inPaneInfo, 
  101.                                     inString, 
  102.                                     inTextTraitsID,
  103.                                     inMaxChars, 
  104.                                     inAttributes,
  105.                                     inKeyFilter, 
  106.                                     inSuper )
  107.  
  108. {
  109. }    //    CTSMEditField::CTSMEditField
  110.  
  111.  
  112. CTSMEditField::~CTSMEditField()
  113.     {
  114.     
  115.         OSErr    result = noErr;
  116.         
  117.         try
  118.             {
  119.             
  120.                 if ( mTSMDocID != 0 )
  121.                     {
  122.                     
  123.                         ::FixTSMDocument( mTSMDocID );
  124.                         ::DeactivateTSMDocument( mTSMDocID ); //    for a bug in TSM.  See TE27
  125.                         
  126.                         result = ::DeleteTSMDocument( mTSMDocID );
  127.                         Assert_( result == noErr );
  128.                     
  129.                         mTSMDocID = 0;
  130.                         
  131.                     }
  132.                     
  133.             }
  134.             
  135.         catch ( ... )
  136.             {
  137.             
  138.             
  139.             }
  140.             
  141.     }
  142.  
  143.  
  144. pascal void 
  145. CTSMEditField::PreUpdate( TEHandle inTEHandle, Int32 inRefCon )
  146.     {
  147.     
  148.         CTSMEditField    *theOwnerEditField = NULL;
  149.  
  150.         if ( inRefCon != NULL )
  151.             {
  152.                     
  153.                 theOwnerEditField = reinterpret_cast<CTSMEditField *>( inRefCon );
  154.             
  155.                 theOwnerEditField->FocusDraw();
  156.                 
  157.             }
  158.     
  159.     }
  160.  
  161.  
  162. pascal void
  163. CTSMEditField::PostUpdate( 
  164.     TEHandle inTEHandle, 
  165.     Int32 fixLen, 
  166.     Int32 inputAreaStart, 
  167.     Int32 inputAreaEnd, 
  168.     Int32 pinStart, 
  169.     Int32 pinEnd, 
  170.     Int32 inRefCon )
  171.     {
  172.     
  173.         CTSMEditField    *theOwnerEditField = NULL;
  174.  
  175.         if ( inRefCon != NULL && fixLen > 0 )
  176.             {
  177.                     
  178.                 theOwnerEditField = reinterpret_cast<CTSMEditField *>( inRefCon );
  179.             
  180.                 // Undo of TSM input is currently not supported.
  181.                 //
  182.                 if (theOwnerEditField->mTypingAction != NULL)
  183.                     theOwnerEditField->mTypingAction->Reset();
  184.                 
  185.             }
  186.     
  187.     }
  188.  
  189.                                                                             
  190. void CTSMEditField::BeTarget( void )
  191.     {
  192.  
  193.         OSErr    result = noErr;
  194.         short    oldScript = ::GetScriptManagerVariable(smKeyScript);
  195.         
  196.         #ifdef Debug_Signal
  197.  
  198.             OSErr    err;
  199.  
  200.             //    check to see if a bug in TSM will be encountered
  201.             ProcessSerialNumber    psn,
  202.                                 csn;
  203.             err = GetCurrentProcess(&psn);
  204.             err = GetFrontProcess(&csn);
  205.             Assert_((psn.highLongOfPSN == csn.highLongOfPSN) && (psn.lowLongOfPSN == csn.lowLongOfPSN));
  206.         #endif
  207.  
  208.         FocusDraw();
  209.         
  210.         LEditField::BeTarget();
  211.         
  212.         if ( mTSMDocID != NULL )    
  213.             {
  214.             
  215.                 result = ::ActivateTSMDocument( mTSMDocID );
  216.                 Assert_( result == noErr );
  217.                 
  218.             }
  219.             
  220.  
  221.     if (oldScript != ::GetScriptManagerVariable(smKeyScript))
  222.         ::KeyScript(oldScript);
  223.     }
  224.  
  225.  
  226. void 
  227. CTSMEditField::DontBeTarget( void )
  228.     {
  229.     
  230.         OSErr    result = noErr;
  231.         
  232.         FocusDraw();
  233.         
  234.         if ( mTSMDocID != NULL )
  235.             {
  236.             
  237.                 ::FixTSMDocument( mTSMDocID );
  238.                 
  239.                 result = ::DeactivateTSMDocument( mTSMDocID );
  240.                 Assert_( result == noErr );
  241.                 
  242.             }
  243.             
  244.         LEditField::DontBeTarget();
  245.     
  246.     }
  247.     
  248.  
  249. void
  250. CTSMEditField::Initialize()
  251.     {
  252.     
  253.         OSErr        result                        = noErr;
  254.         SInt32    gestaltResponse        = 0;
  255.         
  256.         Assert_( sInitialized == false );
  257.         
  258.         if ( sInitialized == false )
  259.             {
  260.             
  261.                 sInitialized = true;
  262.                 
  263.                  result = ::Gestalt( gestaltTSMgrVersion, &gestaltResponse );
  264.                   
  265.                 if ( (result == noErr) && (gestaltResponse >= 1) ) 
  266.                     {
  267.                         
  268.                         result = ::Gestalt( gestaltTSMTEAttr, &gestaltResponse );
  269.                 
  270.                         if ( (result == noErr) && ((gestaltResponse >> gestaltTSMTEPresent) & 1) )    
  271.                             {
  272.                             
  273.                                 sHasTSM = true;
  274.                                 
  275.                             }
  276.                             
  277.                     }
  278.                     
  279.             }
  280.     
  281.     }
  282.     
  283.