?? ime.cpp
字號:
fInvertStyleUsed = TRUE;
}
}
else // default styles when no IMEShare.dll exist.
#endif //MACPORT
{
//#ifndef MACPORT
#ifdef JUPITER
defaultStyle:
#endif
switch ( attribute )
{ // Apply underline style.
case ATTR_INPUT:
case ATTR_CONVERTED:
CF.dwEffects |= CFE_UNDERLINE;
CF.bUnderlineType = CFU_UNDERLINEDOTTED;
break;
case ATTR_TARGET_NOTCONVERTED:
CF.dwEffects |= CFE_UNDERLINE;
CF.bUnderlineType = CFU_UNDERLINE;
break;
case ATTR_TARGET_CONVERTED: // Target *is* selection.
{
CF.dwEffects &= ~CFE_AUTOCOLOR;
CF.crTextColor = ed.TxGetSysColor(COLOR_HIGHLIGHTTEXT);
CF.dwEffects &= ~CFE_AUTOBACKCOLOR;
CF.crBackColor = ed.TxGetSysColor(COLOR_HIGHLIGHT);
fInvertStyleUsed = TRUE;
}
break;
}
}
return fInvertStyleUsed;
#else
return TRUE;
#endif
}
/*
* HRESULT CIme_Lev3::IMENotify( const WPARAM wparam, const LPARAM lparam,
* CTxtEdit &ed)
*
* @mfunc
* Handle Level 3 WM_IME_NOTIFY messages.
*
* @comm
* Currently we are only interested in knowing when to update
* the n window's position.
*
* @rdesc
* HRESULT-S_FALSE for DefWindowProc processing, S_OK if not.
*/
HRESULT CIme_Lev3::IMENotify(
const WPARAM wparam, // @parm associated with message.
const LPARAM lparam, // @parm associated with message.
CTxtEdit &ed) // @parm the containing text edit.
{
TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "CIme_Lev3::IMENotify");
if ( IMN_OPENCANDIDATE == wparam || IMN_CLOSECANDIDATE == wparam )
{
Assert ( 0 != lparam );
#ifndef MACPORT
HIMC hIMC; // Host's IME context.
INT index; // Candidate window index.
CANDIDATEFORM cdCandForm;
CTxtSelection *psel;
POINT caretPt;
hIMC = ed.TxImmGetContext(); // Get host's IME context.
if ( hIMC )
{
// Convert bitID to INDEX.
for (index = 0; index < 32; index++ ) // because of API.
{
if ( 0 != ((1 << index) & lparam) )
break;
}
Assert ( ((1 << index) & lparam) == lparam); // Only 1 set?
Assert ( index < 32 );
if ( IMN_OPENCANDIDATE == wparam) // Set candidate to caret.
{
GetCaretPos( &caretPt ); // Start at caret.
psel = ed.GetSel();
cdCandForm.dwStyle = CFS_CANDIDATEPOS;
// Move pt below descent.
if ( psel && psel->GetCurrentDescent() >= 0 && psel->GetCaretHt() > 1 )
{
// change style to CFS_EXCLUDE, this is to
// prevent the candidate window from covering
// the current selection.
cdCandForm.dwStyle = CFS_EXCLUDE;
cdCandForm.rcArea.left = caretPt.x;
// FUTURE: for verticle text, need to adjust
// the rcArea to include the character width.
cdCandForm.rcArea.right =
cdCandForm.rcArea.left + 2;
cdCandForm.rcArea.top = caretPt.y;
caretPt.y += psel->GetCaretHt() + 2;
cdCandForm.rcArea.bottom = caretPt.y;
}
// Most IMEs will have only 1, #0, candidate window. However, some IMEs
// may want to have a window organized alphabetically, by stroke, and
// by radical.
cdCandForm.dwIndex = index;
cdCandForm.ptCurrentPos = caretPt;
pImmSetCandidateWindow(hIMC, &cdCandForm);
// GuyBark JupiterJ IME:
// Make sure we know the index of the open candidate list.
ed._ime->_dwIndex = index;
}
else // Reset back to CFS_DEFAULT.
{
if ( pImmGetCandidateWindow( hIMC, index, &cdCandForm)
&& CFS_DEFAULT != cdCandForm.dwStyle )
{
cdCandForm.dwStyle = CFS_DEFAULT;
pImmSetCandidateWindow(hIMC, &cdCandForm);
}
// GuyBark JupiterJ IME:
// The candidate list is about to close. Make sure we know that later.
ed._ime->_dwIndex = 0xFFFF;
}
ed.TxImmReleaseContext( hIMC ); // Done with IME context.
}
#endif
}
return S_FALSE; // Allow DefWindowProc
} // processing.
/*
* BOOL CIme_Lev3::IMESetCandidateWindowPos(CTxtEdit &ed)
*
* GUYBARK ADD THIS!
*
* Move the hwx candidate window to a stored cp.
*
* Returns FALSE if no errors, else TRUE
*/
BOOL CIme_Lev3::IMESetCandidateWindowPos(CTxtEdit &ed)
{
CTxtSelection *psel;
CANDIDATEFORM cdCandForm;
HIMC hIMC;
POINT caretPt;
BOOL bErr = TRUE;
// Take exactly the same action here, as when the candidate window first appears.
// Get host's IME context.
hIMC = ed.TxImmGetContext();
if(hIMC)
{
// Use the cp stored when the when the caret was last moved.
caretPt = ed._ime->_pt;
if(ed._ime->_dwIndex == 0xFFFF)
{
ed._ime->_dwIndex = 0;
}
cdCandForm.dwStyle = CFS_CANDIDATEPOS;
psel = ed.GetSel();
// Move pt below descent.
if ( psel && psel->GetCurrentDescent() >= 0 && psel->GetCaretHt() > 1 )
{
// Change style to CFS_EXCLUDE, this is to prevent the
// candidate window from covering the current selection.
cdCandForm.dwStyle = CFS_EXCLUDE;
cdCandForm.rcArea.left = caretPt.x;
// FUTURE: for verticle text, need to adjust the rcArea
// to include the character width.
cdCandForm.rcArea.right = cdCandForm.rcArea.left + 2;
cdCandForm.rcArea.top = caretPt.y;
caretPt.y += psel->GetCaretHt() + 2;
cdCandForm.rcArea.bottom = caretPt.y;
}
// Most IMEs will have only 1, #0, candidate window. However, some IMEs may
// want to have a window organized alphabetically, by stroke, and by radical.
// Use the index of the last list opened.
cdCandForm.dwIndex = ed._ime->_dwIndex;
cdCandForm.ptCurrentPos = caretPt;
// Now move the window!
pImmSetCandidateWindow(hIMC, &cdCandForm);
// Done with IME context.
ed.TxImmReleaseContext(hIMC);
// Assume that all worked ok.
bErr = FALSE;
}
return bErr;
}
/*
* BOOL IMEHangeulToHanja ( CTxtEdit &ed, IUndoBuilder &undobldr )
*
* @func
* Initiates an IME composition string edit to convert Korean Hanguel to Hanja.
* @comm
* Called from the message loop to handle VK_KANJI_KEY.
*
* @devnote
* We decide if we need to do a conversion by checking:
* - the Fonot is a Korean font,
* - the character is a valid SBC or DBC,
* - pImmEscape accepts the character and bring up a candidate window
*
* @rdesc
* BOOL - FALSE for no conversion. TRUE if OK.
*/
BOOL IMEHangeulToHanja (
CTxtEdit &ed , // @parm the containing text edit.
IUndoBuilder &undobldr) // @parm required to modify the text.
{
TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "IMEHangeulToHanja");
#ifndef MACPORT
CTxtSelection * const psel = ed.GetSel();
long CurrentChar;
HDC hdc;
CCcs *pccs; // Font cache.
int result = FALSE;
if ( ed.IsIMEComposition() || !fHaveIMMProcs || !psel )
return FALSE;
// Collapse to cpMin
psel->Collapser(tomStart);
// get the current character
CurrentChar = psel->_rpTX.GetChar();
// check if there is any Hanja conversion
HKL hKL = GetKeyboardLayout(0);
HIMC hIMC = ed.TxImmGetContext();
LONG xWidth = dxCaret;
result = FALSE;
if ( hIMC )
{
result = pImmEscape(hKL, hIMC, IME_ESC_HANJA_MODE, &CurrentChar);
ed.TxImmReleaseContext( hIMC );
}
if (result)
{
// advance one char to get the correct format
psel->SetExtend( FALSE );
psel->Advance( 1 );
// get the Hanguel character width
hdc = ed.TxGetDC(); // Get the font cache
if ( hdc )
{
pccs = fc().GetCcs(hdc, psel->GetCF(), ed._pdp->GetZoomNumerator(),
ed._pdp->GetZoomDenominator(), GetDeviceCaps(hdc, LOGPIXELSY));
if( pccs ) // If font cache exist...
{
pccs->Include( (TCHAR)CurrentChar, xWidth);
pccs->Release();
}
ed.TxReleaseDC( hdc );
}
// start the CIme_HangeulToHanja composition mode
ed._ime = new CIme_HangeulToHanja ( ed, xWidth );
if ( ed.IsIMEComposition() )
ed._ime->StartComposition ( ed, undobldr );
}
else
{
ed.Sound();
}
return result;
#else // MACPORT
return FALSE;
#endif
}
/*
* CIme_HangeulToHanja::CIme_HangeulToHanja()
*
* @mfunc
* CIme_HangeulToHanja Constructor.
*
* @comm
* Needed to save Hangeul character width for Block caret
*
*/
CIme_HangeulToHanja::CIme_HangeulToHanja( CTxtEdit &ed , LONG xWidth ) :
CIme_Lev3( ed )
{
_xWidth = xWidth;
}
/*
* HRESULT CIme_HangeulToHanja::StartComposition( CTxtEdit &ed, IUndoBuilder &undobldr )
*
* @mfunc
* Begin CIme_HangeulToHanja composition string processing.
*
* @comm
* Call Level3::StartComposition. Then setup the Korean block
* caret for the Hanguel character.
*
* @rdesc
* Need to adjust _ichStart and _cchCompStr to make the Hanguel character
* "become" a composition character.
*
* @rdesc
* HRESULT-S_FALSE for DefWindowProc processing, S_OK if not.
*/
HRESULT CIme_HangeulToHanja::StartComposition(
CTxtEdit &ed , // @parm the containing text edit.
IUndoBuilder &undobldr) // @parm required to modify the text.
{
TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "CIme_HangeulToHanja::StartComposition");
HRESULT hr;
CTxtSelection * const psel = ed.GetSel();
hr = CIme_Lev3::StartComposition( ed, undobldr );
// fix up starting point to select the current character
if (_ichStart)
_ichStart--;
_cchCompStr = 1;
// Set-up Korean Block cursor.
if ( psel )
{
DWORD cp = psel->GetCpMin();
POINT ptCurrentPos; // caret position of previous character
INT CurrentCaretHt; // caret height of current character
INT NewCaretHt; // caret height of previous character
INT CurrentDescent; // descent of current character
INT NewDescent; // descent of previous character
psel->SetSelection( cp, cp );
CurrentDescent = psel->GetCurrentDescent();
CurrentCaretHt = (INT)psel->GetCaretHt();
// move the cp back since we moved it forward in IMEHangeulToHanja
// to get the Hangeul character and format
if (cp)
cp--;
psel->SetSelection( cp, cp );
NewDescent = psel->GetCurrentDescent();
NewCaretHt = (INT)psel->GetCaretHt();
psel->ShowCaret(FALSE); // Because create turns off
if ( ::GetCaretPos( &ptCurrentPos ) && CurrentCaretHt != NewCaretHt )
{
// current character font size is bigger, adjust the caret position
// before using the new caret height
ptCurrentPos.y -= (( CurrentCaretHt - NewCaretHt ) -
( CurrentDescent - NewDescent ));
ed.TxSetCaretPos ( ptCurrentPos.x, ptCurrentPos.y );
NewCaretHt = CurrentCaretHt;
}
SetIMECaretWidth ( _xWidth ); // setup Korean block caret width
ed.TxCreateCaret(0, (INT) _xWidth, NewCaretHt);
ed.TxSetCaretPos ( ptCurrentPos.x, ptCurrentPos.y );
psel->ShowCaret(TRUE);
}
return hr;
}
/*
* HRESULT CIme_HangeulToHanja::CompositionString( const LPARAM lparam, CTxtEdit &ed,
* IUndoBuilder &undobldr )
*
* @mfunc
* Handle CIme_HangeulToHanja WM_IME_COMPOSITION messages.
*
* @comm
* call CIme_Lev3::CompositionString to get rid of the selected Hanguel character,
* then setup the format for the next Composition message.
*
* @devnote
* When the next Composition message comes in and that we are no longer in IME,
* the new character will use the format as set here.
*
*
*/
HRESULT CIme_HangeulToHanja::CompositionString(
const LPARAM lparam, // @parm associated with message.
CTxtEdit &ed, // @parm the containing text edit.
IUndoBuilder &undobldr) // @parm required to modify the text.
{
TRACEBEGIN(TRCSUBSYSFE, TRCSCOPEINTERN, "CIme_HangeulToHanja::CompositionString");
CIme_Lev3::CompositionString( lparam, ed, undobldr);
CTxtSelection * const psel = ed.GetSel();
if (psel)
psel->Set_iCF(_iFormatSave);
return S_OK;
}
/*
* HRESULT CIme_Protected::CompositionString( const LPARAM lparam, CTxtEdit &ed,
* IUndoBuilder &undobldr )
*
* @mfunc
* Handle CIme_Protected WM_IME_COMPO
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -