📄 select.cpp
字号:
chCode = 0;
// Take the same action as the edit control does here.
nShift = KeyStateDownFlag;
// Key goes down...
PostKeybdMessage(hWndRE, vkCode, nShift, 1, &nShift, &chCode);
nShift &= ~KeyStateDownFlag;
nShift |= KeyStatePrevDownFlag | KeyShiftNoCharacterFlag;
// Key goes up...
PostKeybdMessage(hWndRE, vkCode, nShift, 1, &nShift, &chCode);
}
}
if(hIMC)
{
ped->TxImmReleaseContext(hIMC);
}
}
else
{
HIMC hIMC = ped->TxImmGetContext();
if(!hIMC || !ImmEscape((HKL)NULL, hIMC, IME_ESC_SETCURSOR, (LPVOID)cpMove))
{
// Freeze the display to stop the caret running around. This
// gets thawed later when we process the last key up.
_pdp->Freeze();
ped->_fDisplayFrozen = TRUE;
chCode = 0;
// Take the same action as the edit control does here.
nShift = KeyStateDownFlag;
// Key goes down...
PostKeybdMessage(hWndRE, VK_RIGHT, nShift, 1, &nShift, &chCode);
nShift &= ~KeyStateDownFlag;
nShift |= KeyStatePrevDownFlag | KeyShiftNoCharacterFlag;
// Key goes up...
PostKeybdMessage(hWndRE, VK_RIGHT, nShift, 1, &nShift, &chCode);
// Take the same action as the edit control does here.
nShift = KeyStateDownFlag;
// Key goes down...
PostKeybdMessage(hWndRE, VK_LEFT, nShift, 1, &nShift, &chCode);
nShift &= ~KeyStateDownFlag;
nShift |= KeyStatePrevDownFlag | KeyShiftNoCharacterFlag;
// Key goes up...
PostKeybdMessage(hWndRE, VK_LEFT, nShift, 1, &nShift, &chCode);
}
if(hIMC)
{
ped->TxImmReleaseContext(hIMC);
}
}
return FALSE;
}
/*
* CTxtSelection::SetIMEHighlight(pcpNew, pt, ptp);
*
* GUYBARK ADD THIS!
*
* Select a clause in the undetermined ime text following a tap.
*
* Returns FALSE if we highlighted a clause, else TRUE.
*/
BOOL CTxtSelection::SetIMEHighlight(LONG *pcpNew, const POINT pt, CRchTxtPtr *ptp)
{
CTxtEdit *ped;
HIMC hIMC = 0;
LONG cpUndeterminedStart, cchUndetermined;
POINT ptNew;
LONG clauseInfo[256];
BYTE attribInfo[256];
int i, cpStart = 0, cpEnd = 0, cbClause, cchAttrib, cClause;
BOOL bRet = TRUE;
// Validate input and current ime context.
if(!pcpNew || !ptp || !(ped = GetPed()))
{
goto Error;
}
hIMC = ped->TxImmGetContext();
if(!hIMC)
{
goto Error;
}
// Don't do anything here if we're not in undetermined text.
if(!ped->IsIMEComposition())
{
goto Error;
}
// Windows CE Platforms Bug #10084 v-holee
//
// MSPY2 : Complete undetermined text while L buttom is not in the undetermined text.
//
if( LANG_CHINESE == PRIMARYLANGID( LOWORD( GetKeyboardLayout(0) ) ))
{
if(ped->_ime->GetUndeterminedInfo((INT*)&cpUndeterminedStart, (INT*)&cchUndetermined))
goto Error;
if(*pcpNew < cpUndeterminedStart || *pcpNew > cpUndeterminedStart + cchUndetermined)
{
BOOL retCode;
retCode = pImmNotifyIME( hIMC, NI_COMPOSITIONSTR,
CPS_COMPLETE, 0);
if ( !retCode && !ped->_fIMECancelComplete )
{
// CPS_COMPLETE fail, try CPS_CANCEL. This happen with some ime which do not support
// CPS_COMPLETE option (e.g. ABC IME version 4 with Win95 simplified Chinese)
retCode = pImmNotifyIME( hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
}
bRet = FALSE;
}
goto Error;
}
// Get the current ime undetermined text attributes.
if((cchAttrib = pImmGetCompositionString(hIMC, GCS_COMPATTR, attribInfo, 255)) <= 0)
{
// Couldn't get attributes.
goto Error;
}
// Try to find some converted ime text.
for(i = 0; i < cchAttrib; i++)
{
if(attribInfo[i] == ATTR_TARGET_CONVERTED ||
attribInfo[i] == ATTR_CONVERTED)
{
break;
}
}
// If we didn't find any converted text, then we don't need to bother
// settings ime attributes, (ie highlighting anything).
if(i == cchAttrib)
{
goto Error;
}
// Round up the cp to always be to the right of where the user tapped.
_pdp->PointFromTp(*ptp, NULL, FALSE, ptNew, NULL, TA_TOP);
if(ptNew.x < pt.x)
{
// Move caret from left to right of character.
*pcpNew += 1;
}
// Force the caret to stay in the undetermined text.
if(ped->_ime->GetUndeterminedInfo((INT*)&cpUndeterminedStart, (INT*)&cchUndetermined))
{
goto Error;
}
if(*pcpNew < cpUndeterminedStart)
{
*pcpNew = cpUndeterminedStart;
}
else if(*pcpNew > cpUndeterminedStart + cchUndetermined)
{
*pcpNew = cpUndeterminedStart + cchUndetermined;
}
// Get the clause info for the undetermined text.
if((cbClause = pImmGetCompositionString(hIMC, GCS_COMPCLAUSE, clauseInfo, 255 * sizeof(LONG))) <= 0)
{
goto Error;
}
// Each clause datum is a cp which is LONG big here.
cClause = cbClause / sizeof(LONG);
// Figure out which clause the user tapped on.
for(i = 0; i < (cClause - 1); i++)
{
// REMEMBER! The clause is relative to the START of the undetermined text!
if((*pcpNew >= clauseInfo[i] + cpUndeterminedStart) && (*pcpNew <= clauseInfo[i + 1] + cpUndeterminedStart))
{
cpStart = clauseInfo[i];
cpEnd = clauseInfo[i+1];
// Return the end of the clause, to display the caret where the user expects.
*pcpNew = cpEnd + cpUndeterminedStart;
break;
}
}
// Now highlight the tapped clause.
for(i = 0; i < cchAttrib; i++)
{
if((i >= cpStart) && (i < cpEnd))
{
// Highlight the clause we tapped on
attribInfo[i] = ATTR_TARGET_CONVERTED;
}
else
{
// All other clauses are marked converted, but not highlighted.
attribInfo[i] = ATTR_CONVERTED;
}
}
// Now tell IME about it.
ImmSetCompositionString(hIMC, SCS_CHANGEATTR, attribInfo, cchAttrib, NULL, 0);
// No errors.
bRet = FALSE;
Error:
if(hIMC)
{
ped->TxImmReleaseContext(hIMC);
}
return bRet;
}
#endif // !TARGET_NT
/*
* CTxtSelection::SelectWord(pt)
*
* @mfunc
* Select word around a given point
*/
void CTxtSelection::SelectWord (
const POINT pt) //@parm Point of click
{
TRACEBEGIN(TRCSUBSYSSEL, TRCSCOPEINTERN, "CTxtSelection::SelectWord");
_TEST_INVARIANT_
// Get rp where the hit is
if (_pdp->CpFromPoint(pt, NULL, this, NULL, FALSE) >= 0)
{
// Extend both active and dead ends on word boundaries
_cch = 0; // Start with IP at pt
SetExtend(FALSE);
FindWordBreak(WB_MOVEWORDRIGHT); // Go to end of word
SetExtend(TRUE);
FindWordBreak(WB_MOVEWORDLEFT); // Extend to start of word
GetRange(_cpAnchorMin, _cpAnchorMost);
GetRange(_cpWordMin, _cpWordMost);
if(!_fInAutoWordSel)
_SelMode = smWord;
// cpMost needs to be the active end
if( _cch < 0 )
{
FlipRange();
}
Update(FALSE);
}
}
/*
* CTxtSelection::SelectUnit(pt, Unit)
*
* @mfunc
* Select line/paragraph around a given point and enter
* line/paragraph selection mode. In Outline View, convert
* SelectLine to SelectPara, and SelectPara to SelectPara
* along with all subordinates
*/
void CTxtSelection::SelectUnit (
const POINT pt, //@parm Point of click
LONG Unit) //@parm tomLine or tomParagraph
{
TRACEBEGIN(TRCSUBSYSSEL, TRCSCOPEINTERN, "CTxtSelection::SelectPara");
_TEST_INVARIANT_
AssertSz(Unit == tomLine || Unit == tomParagraph,
"CTxtSelection::SelectPara: Unit must equal tomLine/tomParagraph");
LONG nHeading;
CLinePtr rp(_pdp);
// Get rp and selection active end where the hit is
if (_pdp->CpFromPoint(pt, NULL, this, &rp, FALSE) >= 0)
{
LONG cchBackward, cchForward;
BOOL fOutline = IsInOutlineView();
if(Unit == tomLine && !fOutline) // SelectLine
{
_cch = 0; // Start with insertion
cchBackward = -rp.RpGetIch(); // point at pt
cchForward = rp->_cch;
_SelMode = smLine;
}
else // SelectParagraph
{
cchBackward = rp.FindParagraph(FALSE); // Go to start of para
cchForward = rp.FindParagraph(TRUE); // Extend to end of para
_SelMode = smPara;
}
SetExtend(FALSE);
Advance(cchBackward);
if(Unit == tomParagraph && fOutline) // Move para in outline
{ // view
rp.AdjustBackward(); // If heading, include
nHeading = rp.GetHeading(); // subordinate paras
if(nHeading)
{
for(; rp.NextRun(); cchForward += rp->_cch)
{
LONG n = rp.GetHeading();
if(n && n <= nHeading)
break;
}
}
}
SetExtend(TRUE);
Advance(cchForward);
GetRange(_cpAnchorMin, _cpAnchorMost);
Update(FALSE);
}
}
/*
* CTxtSelection::SelectAll()
*
* @mfunc
* Select all text in story
*/
void CTxtSelection::SelectAll()
{
TRACEBEGIN(TRCSUBSYSSEL, TRCSCOPEINTERN, "CTxtSelection::SelectAll");
_TEST_INVARIANT_
StopGroupTyping();
LONG cchText = GetTextLength();
Set( cchText, cchText );
Update(FALSE);
}
/*
* CTxtSelection::ExtendSelection(pt)
*
* @mfunc
* Extend/Shrink selection (moves active end) to given point
*/
void CTxtSelection::ExtendSelection (
const POINT pt) //@parm Point to extend to
{
TRACEBEGIN(TRCSUBSYSSEL, TRCSCOPEINTERN, "CTxtSelection::ExtendSelection");
_TEST_INVARIANT_
LONG cch;
LONG cchPrev = _cch;
LONG cp;
LONG cpMin, cpMost;
BOOL fAfterEOP;
const BOOL fWasInAutoWordSel = _fInAutoWordSel;
INT iDir = 0;
CTxtEdit * ped = GetPed();
CLinePtr rp(_pdp);
CRchTxtPtr rtp(ped);
// GuyBark JupiterJ IME: Mimic the edit control's behavior here, and do
// not allow the selection to be extended while undetermined text exists.
if(ped->IsIMEComposition())
{
return;
}
StopGroupTyping();
// Get rp and rtp at the point pt
if (_pdp->CpFromPoint(pt, NULL, &rtp, &rp, TRUE) < 0)
return;
// If we are in word, line, or paragraph select mode, we need to make
// sure the active end is correct. If we are extending backward from
// the first Unit selected, we want the active end to be at cpMin. If
// we are extending forward from the first Unit selected, we want the
// active end to be at cpMost.
if (_SelMode != smNone)
{
cch = _cpAnchorMost - _cpAnchorMin;
GetRange(cpMin, cpMost);
cp = rtp.GetCp();
if(cp <= cpMin && _cch > 0) // If active end changes,
Set(_cpAnchorMin, -cch); // select the original
// Unit (will be extended
if(cp >= cpMost && _cch < 0) // below)
Set(_cpAnchorMost, cch);
}
SetExtend(TRUE);
cch = rp.RpGetIch();
if((_SelMode > smWord) && // If in line or para select
cch == (LONG)rp->_cch) // modes and pt at EOL,
{ // make sure we stay on that
rtp.Advance(-cch); // line
rp.RpAdvanceCp(-cch);
cch = 0;
}
SetCp(rtp.GetCp()); // Move active end to pt
// Caret OK at BOL _unless_
_fCaretNotAtBOL = _cch > 0; // forward selection
// Now adjust selection
if(_SelMode == smLine) // depending on mode
{ // Extend selection by line
if(_cch >= 0) // Active end at cpMost
cch -= rp->_cch; // Setup to add chars to EOL
Advance(-cch);
}
else if(_SelMode == smPara)
Advance(rp.FindParagraph(_cch >= 0)); // Extend selection by para
else
{
// If the sign of _cch has changed this means that the direction
// of the selection is changing and we want to reset the auto
// selection information.
if ((_cch ^ cchPrev) < 0)
{
_fAutoSelectAborted = FALSE;
_cpWordMin = _cpAnchorMin;
_cpWordMost = _cpAnchorMost;
}
cp = rtp.GetCp();
fAfterEOP = rtp._rpTX.IsAfterEOP();
_fInAutoWordSel = _SelMode != smWord && GetPed()->TxGetAutoWordSel()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -