home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / LTSMSupport.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  9.0 KB  |  261 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 "LTSMSupport.h"
  20. static Boolean                 mHasTextServices = false;
  21. static Boolean                mHasTSMTE = false;
  22. static ScriptCode            mSysScript = smRoman;
  23. static Boolean                mTSMTEisVersion1 = false;
  24. static TSMTEPreUpdateUPP     mTSMTEPreUpdateUPP = NULL;
  25. static TSMTEPostUpdateUPP     mTSMTEPostUpdateUPP = NULL;
  26.         
  27.  
  28. static Boolean TrapAvailable(short theTrap);
  29. static pascal void DefaultTSMTEPreUpdateProc(TEHandle textH, long refCon);
  30.  
  31. // ---------------------------------------------------------------------------
  32. //    Copy from InlineInputSample.c
  33. // this TSMTEPreUpdateProc only works around a bug in TSMTE 1.0, which has
  34. // been fixed in 1.1. For other possible uses, see technote TE 27.
  35. // ---------------------------------------------------------------------------
  36.  
  37. static pascal void DefaultTSMTEPreUpdateProc(TEHandle textH, long refCon)
  38. {
  39.     #pragma unused(refCon)
  40.  
  41.     
  42.     if (mTSMTEisVersion1)        // Modified here for performance 
  43.     {
  44.         ScriptCode keyboardScript;
  45.         short mode;
  46.         TextStyle theStyle;
  47.         
  48.         keyboardScript = ::GetScriptManagerVariable(smKeyScript);
  49.         mode = doFont;
  50.         if (!(::TEContinuousStyle(&mode, &theStyle, textH) &&
  51.                 ::FontToScript(theStyle.tsFont) == keyboardScript))
  52.         {
  53.             theStyle.tsFont = ::GetScriptVariable(keyboardScript, smScriptAppFond);
  54.             ::TESetStyle(doFont, &theStyle, false, textH);
  55.         };
  56.     };
  57. }
  58.  
  59. // ---------------------------------------------------------------------------
  60. //        Ñ Initialization
  61. // ---------------------------------------------------------------------------
  62. //    Default constructor
  63. void LTSMSupport::Initialize()
  64. {
  65.     mSysScript = ::GetScriptManagerVariable(smSysScript); 
  66.     CheckForTextServices();
  67.     BeginTextServices();
  68.     TSMTENewUPP();
  69. }
  70. // ---------------------------------------------------------------------------
  71. //        Ñ CheckForTextServices
  72. //        Call by constructor
  73. //        From TE27 Page 4/14
  74. // ---------------------------------------------------------------------------
  75. void LTSMSupport::CheckForTextServices(void)
  76. {
  77.         long gestaltResponse;
  78.         
  79.         if (::TrapAvailable(_Gestalt))
  80.         {
  81.                 if ((::Gestalt(gestaltTSMgrVersion, &gestaltResponse) == noErr) &&
  82.                          (gestaltResponse >= 1))
  83.                 {
  84.                         mTSMTEisVersion1 = (gestaltResponse == gestaltTSMTE1);
  85.                         mHasTextServices = true;
  86.                         if (::Gestalt(gestaltTSMTEAttr, &gestaltResponse) == noErr)
  87.                                 mHasTSMTE = ((gestaltResponse >> gestaltTSMTEPresent) & 1);
  88.                 };
  89.         };
  90. }
  91.  
  92. // ---------------------------------------------------------------------------
  93. //        Ñ TSMTENewUPP
  94. //        Modified from InlineInputSample.c
  95. // ---------------------------------------------------------------------------
  96. void LTSMSupport::TSMTENewUPP()
  97. {
  98.     if(mHasTSMTE) {
  99.         if(mTSMTEPreUpdateUPP == NULL )
  100.             mTSMTEPreUpdateUPP = NewTSMTEPreUpdateProc(DefaultTSMTEPreUpdateProc);
  101.     }
  102. }
  103. // ---------------------------------------------------------------------------
  104. //        Ñ BeginTextServices
  105. //        Call by constructor
  106. //        From TE27 Page 4/14
  107. // ---------------------------------------------------------------------------
  108. void LTSMSupport::BeginTextServices()
  109. {
  110.     if (!(mHasTSMTE && ::InitTSMAwareApplication() == noErr))
  111.     {
  112.             // if this happens, just move on without text services
  113.             mHasTextServices = false;
  114.             mHasTSMTE = false;
  115.     };
  116. }
  117. // ---------------------------------------------------------------------------
  118. //        Ñ DoQuit
  119. //        Called by DoQuit()
  120. //        From TE27 Page 4/14
  121. // ---------------------------------------------------------------------------
  122. void LTSMSupport::DoQuit(Int32    inSaveOption)
  123. {
  124.     if (mHasTextServices)
  125.         (void) ::CloseTSMAwareApplication();
  126. }
  127. // ---------------------------------------------------------------------------
  128. //        Ñ IntlTSMEvent
  129. //        From TE27 Page 11/14
  130. // ---------------------------------------------------------------------------
  131. Boolean
  132. LTSMSupport::TSMEvent(const EventRecord &inMacEvent)
  133. {
  134.         short oldFont;
  135.         ScriptCode keyboardScript;
  136.         
  137.         if(mHasTextServices)
  138.         {
  139.             // make sure we have a port and it's not the Window Manager port
  140. //            if (qd.thePort != nil && ::FrontWindow() != nil)
  141. //            {
  142. //                    oldFont = qd.thePort->txFont;
  143. //                    keyboardScript = ::GetScriptManagerVariable(smKeyScript);
  144. //                    if (::FontToScript(oldFont) != keyboardScript)
  145. //                            ::TextFont(GetScriptVariable(keyboardScript, smScriptAppFond));
  146. //            };
  147.             return ::TSMEvent((EventRecord *)&inMacEvent);
  148.         }
  149.         else
  150.         {
  151.             return false;
  152.         }
  153. }
  154. // ---------------------------------------------------------------------------
  155. //        Ñ IntlTSMEvent
  156. //        From TE27 Page 11/14
  157. // ---------------------------------------------------------------------------
  158. Boolean    LTSMSupport::SetTSMCursor(Point mousePos)
  159. {
  160.     if(mHasTextServices)
  161.         return ::SetTSMCursor(mousePos);
  162.     else
  163.         return false;
  164. }
  165. // ---------------------------------------------------------------------------
  166. //
  167. // ---------------------------------------------------------------------------
  168. Boolean    LTSMSupport::HasTextServices()
  169. {
  170.     return mHasTextServices;
  171. }
  172. // ---------------------------------------------------------------------------
  173. //
  174. // ---------------------------------------------------------------------------
  175. Boolean    LTSMSupport::HasTSMTE()
  176. {
  177.     return mHasTSMTE;
  178. }
  179. // ---------------------------------------------------------------------------
  180. //
  181. // ---------------------------------------------------------------------------
  182.  
  183. TSMTEPreUpdateUPP    LTSMSupport::GetDefaultTSMTEPreUpdateUPP()
  184. {
  185.     return mTSMTEPreUpdateUPP;
  186. }
  187. // ---------------------------------------------------------------------------
  188. //
  189. // ---------------------------------------------------------------------------
  190. TSMTEPostUpdateUPP    LTSMSupport::GetDefaultTSMTEPostUpdateUPP()
  191. {
  192.     return mTSMTEPostUpdateUPP;
  193. }
  194. // ---------------------------------------------------------------------------
  195. //
  196. // ---------------------------------------------------------------------------
  197. void LTSMSupport::StartFontScriptLimit()
  198. {
  199.     //short theFontScript = ::FontScript();
  200.     //StartFontScriptLimit(theFontScript);
  201. }
  202.  
  203. // ---------------------------------------------------------------------------
  204. //
  205. // ---------------------------------------------------------------------------
  206. void LTSMSupport::StartFontScriptLimit(  ScriptCode scriptcode)
  207. {
  208.     //    We want to disable all the script except: Roman and the Font script
  209.     //  1. we have set the system script to the font script
  210.     //    2. disable all the script except Roman and System script by calling 
  211.     //            KeyScript(smDisablKybds);
  212.     //  3. Should we also switch input method to the font script ?
  213.     //    4. restore the system script.
  214.     //if(mSysScript != scriptcode)
  215.     //{
  216.     //    ::SetScriptManagerVariable(smSysScript, scriptcode);        
  217.     //}
  218.     //if(scriptcode != ::GetScriptManagerVariable(smKeyScript))
  219.     //{
  220.     //    ::KeyScript(scriptcode);
  221.     //}
  222. //    ::KeyScript(smKeyDisableKybds);
  223. //    ::SetScriptManagerVariable(smSysScript, mSysScript);        
  224. }
  225. // ---------------------------------------------------------------------------
  226. //
  227. // ---------------------------------------------------------------------------
  228. void LTSMSupport::EndFontScriptLimit()
  229. {
  230.     // Re-enable all the script
  231.     //::KeyScript(smKeyEnableKybds);
  232.     //::SetScriptManagerVariable(smSysScript, mSysScript);        
  233. }
  234. // ---------------------------------------------------------------------------
  235. // check to see if a given trap is implemented. We follow IM VI-3-8.
  236. // ---------------------------------------------------------------------------
  237. static 
  238. Boolean TrapAvailable(short theTrap)
  239. {
  240.     TrapType theTrapType;
  241.     short numToolboxTraps;
  242.     
  243.     if ((theTrap & 0x0800) > 0)
  244.         theTrapType = ToolTrap;
  245.     else
  246.         theTrapType = OSTrap;
  247.  
  248.     if (theTrapType == ToolTrap)
  249.     {
  250.         theTrap = theTrap & 0x07ff;
  251.         if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
  252.             numToolboxTraps = 0x0200;
  253.         else
  254.             numToolboxTraps = 0x0400;
  255.         if (theTrap >= numToolboxTraps)
  256.             theTrap = _Unimplemented;
  257.     };
  258.  
  259.     return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
  260. }
  261.