home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CDrawingState.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.4 KB  |  156 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 "CDrawingState.h"
  20.  
  21. #include <UTextTraits.h>
  22.  
  23. // ---------------------------------------------------------------------------
  24. //        Ñ StMercutioMDEFTextState
  25. // ---------------------------------------------------------------------------
  26.  
  27. StMercutioMDEFTextState::StMercutioMDEFTextState()
  28. {
  29.     SetUpForMercurtioMDEF();
  30. }
  31.  
  32. // ---------------------------------------------------------------------------
  33. //        Ñ StMercutioMDEFTextState
  34. // ---------------------------------------------------------------------------
  35.  
  36. StMercutioMDEFTextState::~StMercutioMDEFTextState()
  37. {
  38.     Restore();
  39. }    
  40.  
  41. // ---------------------------------------------------------------------------
  42. //        Ñ SetUpForMercurtioMDEF
  43. // ---------------------------------------------------------------------------
  44.  
  45. void
  46. StMercutioMDEFTextState::SetUpForMercurtioMDEF()
  47. {
  48.     mPort = UQDGlobals::GetCurrentPort();
  49.  
  50.     ::GetWMgrPort(&mWMgrPort);
  51.     ::SetPort(mWMgrPort);
  52.     mWMgrFont = mWMgrPort->txFont;
  53.     mWMgrSize = mWMgrPort->txSize;
  54.     ::TextFont(systemFont);
  55.     ::TextSize(0);
  56.  
  57.     if (UEnvironment::HasFeature(env_SupportsColor))
  58.     {
  59.         ::GetCWMgrPort(&mWMgrCPort);
  60.         ::SetPort((GrafPtr)mWMgrCPort);
  61.         mCWMgrFont = mWMgrCPort->txFont;
  62.         mCWMgrSize = mWMgrCPort->txSize;
  63.         ::TextFont(systemFont);
  64.         ::TextSize(0);
  65.     }
  66.     
  67.     ::SetPort(mPort);
  68. }
  69.  
  70. // ---------------------------------------------------------------------------
  71. //        Ñ Restore
  72. // ---------------------------------------------------------------------------
  73.  
  74. void
  75. StMercutioMDEFTextState::Restore()
  76. {
  77.     ::SetPort(mWMgrPort);
  78.     ::TextFont(mWMgrFont);
  79.     ::TextSize(mWMgrSize);
  80.  
  81.     if (UEnvironment::HasFeature(env_SupportsColor))
  82.     {
  83.         ::SetPort((GrafPtr)mWMgrCPort);
  84.         ::TextFont(mCWMgrFont);
  85.         ::TextSize(mCWMgrSize);
  86.     }
  87.  
  88.     ::SetPort(mPort);
  89. }
  90.  
  91. #pragma mark -
  92.  
  93. // ---------------------------------------------------------------------------
  94. //        Ñ StSysFontState
  95. // ---------------------------------------------------------------------------
  96.  
  97. StSysFontState::StSysFontState()
  98. {
  99.     Save();
  100. }
  101.  
  102. // ---------------------------------------------------------------------------
  103. //        Ñ StSysFontState
  104. // ---------------------------------------------------------------------------
  105.  
  106. StSysFontState::~StSysFontState()
  107. {
  108.     Restore();
  109. }    
  110.  
  111. // ---------------------------------------------------------------------------
  112. //        Ñ Save
  113. // ---------------------------------------------------------------------------
  114.  
  115. void
  116. StSysFontState::Save()
  117. {
  118.     mFont = ::LMGetSysFontFam();
  119.     mSize = ::LMGetSysFontSize();
  120. }
  121.  
  122. // ---------------------------------------------------------------------------
  123. //        Ñ Restore
  124. // ---------------------------------------------------------------------------
  125.  
  126. void
  127. StSysFontState::Restore()
  128. {
  129.     ::LMSetSysFontFam(mFont);
  130.     ::LMSetSysFontSize(mSize);
  131.     ::LMSetLastSPExtra(-1L);
  132. }
  133.  
  134. // ---------------------------------------------------------------------------
  135. //        Ñ SetTextTraits
  136. // ---------------------------------------------------------------------------
  137. //    Make sure port has been set (via FocusDraw()) before calling SetTextTraits.
  138.  
  139. void
  140. StSysFontState::SetTextTraits(
  141.     ResIDT inTextTraitsID)
  142. {
  143.     TextTraitsH traitsH = UTextTraits::LoadTextTraits ( 130 );
  144.     if ( traitsH ) 
  145.     {
  146.         // Bug #64133 kellys
  147.         // If setting to application font, get the application font for current script
  148.         if((**traitsH).fontNumber == 1)
  149.             ::LMSetSysFontFam ( ::GetScriptVariable(::FontToScript(1), smScriptAppFond) );
  150.         else
  151.             ::LMSetSysFontFam ( (**traitsH).fontNumber );
  152.         ::LMSetSysFontSize ( (**traitsH).size );
  153.         ::LMSetLastSPExtra ( -1L );
  154.     }
  155. }
  156.