📄 w32mac.cpp
字号:
CStrOutW::Convert()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOutW::Convert");
int cch;
if (!_pwstr)
return 0;
WCHAR *pwstr = _pwstr;
int cchBuf = _cchBuf;
cch = W32->MbcsFromUnicode(_pstr, cchBuf, _pwstr, -1, _uiCodePage);
Free();
return cch - 1;
}
//+---------------------------------------------------------------------------
//
// Member: CStrOutW::~CStrOutW
//
// Synopsis: Converts the buffer from Unicode to MBCS.
//
// Note: Don't inline this function, or you'll increase code size as
// both Convert() and CConvertStr::~CConvertStr will be called
// inline.
//
//----------------------------------------------------------------------------
CStrOutW::~CStrOutW()
{
TRACEBEGIN(TRCSUBSYSWRAP, TRCSCOPEINTERN, "CStrOutW::~CStrOutW");
Convert();
}
#if 0
// flags
#pragma message ("JMO Review : Should be same as has nlsprocs, initialize in constructor")
unsigned _fIntlKeyboard : 1;
// From nlsprocs.h
// TranslateCharsetInfo
// typedef WINGDIAPI BOOL (WINAPI*TCI_CAST)( DWORD FAR *, LPCHARSETINFO, DWORD);
// #define pTranslateCharsetInfo(a,b,c) (( TCI_CAST) nlsProcTable[iTranslateCharsetInfo])(a,b,c)
//#define pTranslateCharsetInfo() (*()nlsProcTable[iTranslateCharsetInfo])()
/*
* W32Imp::CheckChangeKeyboardLayout ( BOOL fChangedFont )
*
* @mfunc
* Change keyboard for new font, or font at new character position.
* @comm
* Using only the currently loaded KBs, locate one that will support
* the insertion points font. This is called anytime a character format
* change occurs, or the insert font (caret position) changes.
* @devnote
* The current KB is preferred. If a previous association
* was made, see if the KB is still loaded in the system and if so use
* it. Otherwise, locate a suitable KB, preferring KB's that have
* the same charset ID as their default, preferred charset. If no match
* can be made then nothing changes.
*
* This routine is only useful on Windows 95.
*/
#ifndef MACPORT
#define MAX_HKLS 256 // It will be awhile
// before we have more KBs
CTxtEdit * const ped = GetPed(); // Document context.
INT i, totalLayouts, // For matching KBs.
iBestLayout = -1;
WORD preferredKB; // LCID of preferred KB.
HKL hklList[MAX_HKLS]; // Currently loaded KBs.
const CCharFormat *pcf; // Current font.
CHARSETINFO csi; // Font's CodePage bits.
AssertSz(ped, "no ped?"); // hey now!
if (!ped || !ped->IsRich() || !ped->_fFocus || // EXIT if no ped or focus or
!ped->IsAutoKeyboard()) // auto keyboard is turn off
return;
pcf = ped->GetCharFormat(_iFormat); // Get insert font's data
hklList[0] = pGetKeyboardLayout(0); // Current hkl preferred?
preferredKB = fc().GetPreferredKB( pcf->bCharSet );
if ( preferredKB != LOWORD(hklList[0]) ) // Not correct KB?
{
// Get loaded HKLs.
totalLayouts = 1 + pGetKeyboardLayoutList(MAX_HKLS, &hklList[1]);
// Know which KB?
if ( preferredKB ) // then locate it.
{ // Sequential match because
for ( i = 1; i < totalLayouts; i++ ) // HKL may be unloaded.
{ // Match LCIDs.
if ( preferredKB == LOWORD( hklList[i]) )
{
iBestLayout = i;
break; // Matched it.
}
}
if ( i >= totalLayouts ) // Old KB is missing.
{ // Reset to locate new KB.
fc().SetPreferredKB ( pcf->bCharSet, 0 );
}
}
if ( iBestLayout < 0 ) // Attempt to find new KB.
{
for ( i = 0; i < totalLayouts; i++ )
{
pTranslateCharsetInfo( // Get KB's charset.
(DWORD *) ConvertLanguageIDtoCodePage(LOWORD(hklList[iBestLayout])),
&csi, TCI_SRCCODEPAGE);
if( csi.ciCharset == pcf->bCharSet) // If charset IDs match?
{
iBestLayout = i;
break; // then this KB is best.
}
}
if ( iBestLayout >= 0) // Bind new KB.
{
fChangedFont = TRUE;
fc().SetPreferredKB(pcf->bCharSet, LOWORD(hklList[iBestLayout]));
}
}
if ( fChangedFont && iBestLayout >= 0) // Bind font.
{
ICharFormatCache * pCF;
if(SUCCEEDED(GetCharFormatCache(&pCF)))
{
pCF->AddRefFormat(_iFormat);
fc().SetPreferredFont(
LOWORD(hklList[iBestLayout]), _iFormat );
}
}
if( iBestLayout > 0 ) // If == 0 then
{ // it's already active.
// Activate KB.
ActivateKeyboardLayout( hklList[iBestLayout], 0);
}
}
#endif // MACPORT -- the mac needs its own code.
/*
* CTxtSelection::CheckChangeFont ( CTxtEdit * const ped, const WORD lcID )
*
* @mfunc
* Change font for new keyboard layout.
* @comm
* If no previous preferred font has been associated with this KB, then
* locate a font in the document suitable for this KB.
* @devnote
* This routine is called via WM_INPUTLANGCHANGEREQUEST message
* (a keyboard layout switch). This routine can also be called
* from WM_INPUTLANGCHANGE, but we are called more, and so this
* is less efficient.
*
* Exact match is done via charset ID bitmask. If a match was previously
* made, use it. A user can force the insertion font to be associated
* to a keyboard if the control key is held through the KB changing
* process. The association is broken when another KB associates to
* the font. If no match can be made then nothing changes.
*
* This routine is only useful on Windows 95.
*
*/
#ifndef MACPORT
LOCALESIGNATURE ls, curr_ls; // KB's code page bits.
CCharFormat cf, // For creating new font.
currCF; // For searching
const CCharFormat *pPreferredCF;
CHARSETINFO csi; // with code page bits.
LONG iFormat, iBestFormat = -1; // Loop support.
INT i;
BOOL fLastTime; // Loop support.
BOOL fSetPreferred = FALSE;
HKL currHKL; // current KB;
BOOL fLookUpFaceName = FALSE; // when picking a new font.
ICharFormatCache * pCF;
#ifdef UNDER_CE // mikegins
LPCTSTR lpszFaceName = NULL;
#else
LPTSTR lpszFaceName = NULL;
#endif
BYTE bCharSet;
BYTE bPitchAndFamily;
BOOL fFaceNameIsDBCS;
AssertSz (ped, "No ped?");
if (!ped->IsRich() || !ped->IsAutoFont()) // EXIT if not running W95.
return; // EXIT if auto font is turn off
if(FAILED(GetCharFormatCache(&pCF))) // Get CharFormat Cache.
return;
cf.InitDefault(0);
// An alternate approach would be to get the key state from the corresponding
// message; FUTURE (alexgo): we can consider doing this, but we need to make sure
// everything works with windowless controls..
BOOL fReassign = fEnableReassign
&& (GetAsyncKeyState(VK_CONTROL)<0);// Is user holding CTRL?
currHKL = pGetKeyboardLayout(0);
ped->GetCharFormat(_iFormat)->Get(&currCF);
GetLocaleInfoA( lcID, LOCALE_FONTSIGNATURE, (char *) &ls, sizeof(ls));
if ( fReassign ) // Force font/KB assoc.
{ // If font supports KB
// in any way,
// Note: test Unicode bits.
GetLocaleInfoA( fc().GetPreferredKB (currCF.bCharSet),
LOCALE_FONTSIGNATURE, (char *) &curr_ls, sizeof(ls));
if ( CountMatchingBits(curr_ls.lsUsb, ls.lsUsb, 4) )
{ // Break old font/KB assoc.
fc().SetPreferredFont( fc().GetPreferredKB (currCF.bCharSet), -1 );
// Bind KB and font.
fc().SetPreferredKB( currCF.bCharSet, lcID );
pCF->AddRefFormat(_iFormat);
fc().SetPreferredFont( lcID, _iFormat );
}
}
else // Lookup preferred font.
{
// Attempt to Find new
{ // preferred font.
CFormatRunPtr rp(_rpCF); // Nondegenerate range
fLastTime = TRUE;
if ( _rpCF.IsValid() ) // If doc has cf runs.
{
fLastTime = FALSE;
rp.AdjustBackward();
}
pTranslateCharsetInfo( // charset.
(DWORD *)cpg, &csi, TCI_SRCCODEPAGE);
iFormat = _iFormat; // Search _iFormat,
// then backwards.
i = MAX_RUNTOSEARCH; // Don't be searching for
while ( 1 ) // years...
{ // Get code page bits.
pPreferredCF = ped->GetCharFormat(iFormat);
if (csi.ciCharset == pPreferredCF->bCharSet) // Equal charset ids?
{
fSetPreferred = TRUE;
break;
}
if ( fLastTime ) // Done searching?
break;
iFormat = rp.GetFormat(); // Keep searching backward.
fLastTime = !rp.PrevRun() && i--;
}
if ( !fSetPreferred && _rpCF.IsValid()) // Try searching forward.
{
rp = _rpCF;
rp.AdjustBackward();
i = MAX_RUNTOSEARCH; // Don't be searching for
while (i-- && rp.NextRun() ) // years...
{
iFormat = rp.GetFormat(); // Get code page bits.
pPreferredCF = ped->GetCharFormat(iFormat);
// Equal charset ids?
if (csi.ciCharset == pPreferredCF->bCharSet)
{
fSetPreferred = TRUE;
break;
}
}
}
}
if ( !fSetPreferred )
{
iFormat = fc().GetPreferredFont( lcID );
// Set preferred if usable.
if (iFormat >= 0 &&
csi.ciCharset == ped->GetCharFormat(iFormat)->bCharSet)
{
fSetPreferred = TRUE;
pPreferredCF = ped->GetCharFormat(iFormat);
}
}
// setup cf needed for creating a new format run
cf = currCF;
// We know that the facename is not tagged IsDBCS in all cases
// unless explicitly set below.
fFaceNameIsDBCS = FALSE;
if ( fSetPreferred )
{
// pick face name from the previous preferred format
bPitchAndFamily = pPreferredCF->bPitchAndFamily;
bCharSet = pPreferredCF->bCharSet;
lpszFaceName = (LPTSTR)pPreferredCF->szFaceName;
fFaceNameIsDBCS = pPreferredCF->bInternalEffects & CFMI_FACENAMEISDBCS;
}
else // Still don't have a font?
{ // For FE, use hard coded defaults.
// else get charset right.
WORD CurrentCodePage = cpg;
switch (CurrentCodePage)
{ // FE hard codes from Word.
case _JAPAN_CP:
bCharSet = SHIFTJIS_CHARSET;
lpszFaceName = lpJapanFontName;
bPitchAndFamily = 17;
break;
case _KOREAN_CP:
bCharSet = HANGEUL_CHARSET;
lpszFaceName = lpKoreanFontName;
bPitchAndFamily = 49;
break;
case _CHINESE_TRAD_CP:
bCharSet = CHINESEBIG5_CHARSET;
lpszFaceName = lpTChineseFontName;
bPitchAndFamily = 54;
break;
case _CHINESE_SIM_CP:
bCharSet = GB2312_CHARSET;
lpszFaceName = lpSChineseFontName;
bPitchAndFamily = 54;
break;
default: // Use translate to get
pTranslateCharsetInfo( // charset.
(DWORD *) CurrentCodePage, &csi, TCI_SRCCODEPAGE);
bCharSet = csi.ciCharset;
if (IsFECharset(currCF.bCharSet) && !IsFECharset(bCharSet))
{
// fall back to default
lpszFaceName = L"Arial";
bPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
}
else
{
bPitchAndFamily = currCF.bPitchAndFamily;
lpszFaceName = currCF.szFaceName;
fFaceNameIsDBCS = currCF.bInternalEffects & CFEI_FACENAMEISDBCS;
}
fLookUpFaceName = TRUE; // Get Font's real name.
break;
}
}
// setup the rest of cf
cf.bPitchAndFamily = bPitchAndFamily;
cf.bCharSet = (BYTE) bCharSet;
_tcscpy ( cf.szFaceName, lpszFaceName );
if(fFaceNameIsDBCS)
{
cf.bInternalEffects |= CFEI_FACENAMEISDBCS;
}
else
{
cf.bInternalEffects &= ~CFEI_FACENAMEISDBCS;
}
cf.lcid = lcID;
// If we relied on GDI to match a font, get the font's real name...
if ( fLookUpFaceName )
{
const CDevDesc *pdd = _pdp->GetDdRender();
HDC hdc;
CCcs *pccs;
HFONT hfontOld;
OUTLINETEXTMETRICA *potm;
CTempBuf mem;
UINT otmSize;
hdc = pdd->GetDC();
// Select logfont into DC,
if( hdc) // for OutlineTextMetrics.
{
cf.SetCRC();
pccs = fc().GetCcs(hdc, &cf, _pdp->GetZoomNumerator(),
_pdp->GetZoomDenominator(),
GetDeviceCaps(hdc, LOGPIXELSY));
if( pccs )
{
hfontOld = SelectFont(hdc, pccs->_hfont);
if( otmSize = ::GetOutlineTextMetricsA(hdc, 0, NULL) )
{
potm = (OUTLINETEXTMETRICA *) mem.GetBuf(otmSize);
if ( NULL != potm )
{
::GetOutlineTextMetricsA(hdc, otmSize, potm);
CStrInW strinw( &((CHAR *)(potm))[ BYTE(potm->otmpFaceName)] );
cf.bPitchAndFamily
= potm->otmTextMetrics.tmPitchAndFamily;
cf.bCharSet
= (BYTE) potm->otmTextMetrics.tmCharSet;
_tcscpy ( cf.szFaceName, (WCHAR *)strinw );
cf.bInternalEffects &= ~CFEI_FACENAMEISDBCS;
}
}
SelectFont( hdc, hfontOld );
pccs->Release();
}
pdd->ReleaseDC(hdc);
}
}
if ( SUCCEEDED(pCF->Cache(&cf, &iFormat)) )
{
// This is redundent if ed.IsAutoKeyboard() == TRUE.
pCF->AddRefFormat(_iFormat);
fc().SetPreferredFont ( LOWORD (currHKL), _iFormat );
fc().SetPreferredKB( cf.bCharSet, lcID );
pCF->AddRefFormat(iFormat);
fc().SetPreferredFont ( lcID, iFormat );
pCF->ReleaseFormat(_iFormat);
_iFormat = iFormat;
ped->GetCallMgr()->SetSelectionChanged();
}
}
#endif // MACPORT -- the mac needs its own code.
if (W32->FormatMatchesKeyboard(pcfForward))
LOCALESIGNATURE ls; // Per HKL, CodePage bits.
CHARSETINFO csi; // Font's CodePage bits.
// Font's code page bits.
pTranslateCharsetInfo((DWORD *) pcfForward->bCharSet, &csi, TCI_SRCCHARSET);
// Current KB's code page bits.
GetLocaleInfoA( LOWORD(pGetKeyboardLayout(0)), LOCALE_FONTSIGNATURE, (CHAR *) &ls, sizeof(ls));
if ( (csi.fs.fsCsb[0] & ls.lsCsbDefault[0]) ||
(csi.fs.fsCsb[1] & ls.lsCsbDefault[1]) )
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -