📄 disp.cpp
字号:
DWORD width = GetWordWrap() ? _xWidthView : GetWidth() + dxCaret;
// Get the view inset for adjusting the width
RECT rcInset;
_ped->TxGetViewInset(&rcInset, this);
resize.nmhdr.hwndFrom = NULL;
resize.nmhdr.idFrom = NULL;
resize.nmhdr.code = EN_REQUESTRESIZE;
resize.rc.top = 0;
resize.rc.left = 0;
// Adjust the width by the inset and selection bar
resize.rc.right = width + rcInset.left + rcInset.right
+ GetSelBarInPixels();
resize.rc.bottom = GetResizeHeight();
return _ped->TxNotify(EN_REQUESTRESIZE, &resize);
}
return S_OK;
}
/*
* CDisplay::GetViewRect(RECT &rcView, LPCRECT prcClient)
*
* Purpose:
* Compute and return the view rectangle in window's client
* area coordinates.
*
* Arguments
* rcView reference to rect to return
* prcClient client rect (in window's client coords,
* can be NULL if we are in-place)
*/
void CDisplay::GetViewRect(RECT &rcView, LPCRECT prcClient)
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::GetViewRect");
_TEST_INVARIANT_
RECT rcInset;
// If we did not get it passed in, ask the host for the
// client rect
if(prcClient)
{
rcView = *prcClient;
}
else
{
AssertSz(_ped->_fInPlaceActive, "CDisplay::GetViewRect() - Not in-place and !prcClient");
_ped->TxGetClientRect(&rcView);
}
// Make sure the height is set
_yHeightClient = rcView.bottom - rcView.top;
// Ask the host for the view inset
_ped->TxGetViewInset(&rcInset, this);
rcView.left += rcInset.left;
rcView.top += rcInset.top;
rcView.right -= rcInset.right;
rcView.bottom -= rcInset.bottom;
// Factor in selection bar space
rcView.left += GetSelBarInPixels();
}
//=================================== Scrolling =============================
/*
* CDisplay::VScroll(wCode, yPos)
*
* Purpose:
* Scroll the view vertically in response to a scrollbar event
* >>> Should be called when in-place active only <<<
*
* Note:
* No support for vertical scroll in base CDisplay. No action.
*
* Arguments:
* wCode scrollbar event code
* yPos thumb position (yPos < 0 for EM_SCROLL behavior)
*
* Return:
* LRESULT formatted for WM_VSCROLL message
*/
LRESULT CDisplay::VScroll(WORD wCode, LONG yPos)
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::VScroll");
_TEST_INVARIANT_
return 0;
}
/*
* CDisplay::HScroll(wCode, xPos)
*
* Purpose:
* Scroll the view horizontally in response to a scrollbar event
* >>> Should be called when in-place active only <<<
*
* Arguments:
* wCode scrollbar event code
* yPos thumb position
*/
VOID CDisplay::HScroll(WORD wCode, LONG xPos)
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::HScroll");
_TEST_INVARIANT_
BOOL fTracking = FALSE;
LONG xScroll = _xScroll;
if (xPos != 0)
{
// Convert x position from scroll bar to offset horizontally
// in the document.
xPos = ConvertScrollToXPos(xPos);
}
AssertSz(_ped->_fInPlaceActive, "CDisplay::HScroll() called when not in place");
switch(wCode)
{
case SB_BOTTOM:
xScroll = GetWidth();
break;
case SB_LINEDOWN:
// Future: Make this depend on a the current first visible character
xScroll += GetXWidthSys();
break;
case SB_LINEUP:
// Future: Make this depend on a the current first visible character
xScroll -= GetXWidthSys();
break;
case SB_PAGEDOWN:
xScroll += _xWidthView;
break;
case SB_PAGEUP:
xScroll -= _xWidthView;
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
if(xPos < 0)
return;
xScroll = xPos;
fTracking = TRUE;
break;
case SB_TOP:
xScroll = 0;
break;
case SB_ENDSCROLL:
UpdateScrollBar(SB_HORZ);
return;
default:
return;
}
if (xScroll < 0)
{
// xScroll is the new proposed scrolling position and
// therefore cannot be less than 0.
xScroll = 0;
}
ScrollView(xScroll, -1, fTracking, FALSE);
// force position update if we just finished a track
if(wCode == SB_THUMBPOSITION)
UpdateScrollBar(SB_HORZ);
}
/*
* CDisplayML::SmoothVScroll ( int direction, WORD cLines,
* int speedNum, int speedDenom, BOOL fAdditive )
*
* @mfunc
* Setup to handle fractional scrolls, at a particular speed. This was
* probably initiated via a Magellan mouse roller movement, or a MButton
* down message.
*/
void CDisplay::SmoothVScroll ( int direction, WORD cLines, int speedNum, int speedDenom, BOOL fMouseRoller )
{
TRACEBEGIN(TRCSUBSYSEDIT, TRCSCOPEINTERN, "CDisplay::SmoothVScroll");
int yDelta;
int cLinesAndDir;
int smoothYDelta;
Assert ( speedDenom );
if ( IsVScrollEnabled() ) // Can scroll vertically?
{
_fFinishSmoothVScroll = FALSE; // We're smoothing again.
// Get total pixels.
if ( CheckInstallSmoothVScroll() ) // Install periodic update
{
_totalSmoothVScroll = 0;
_nextSmoothVScroll = 0;
}
// Pixels per epoch
cLinesAndDir = (direction < 0) ? cLines : -cLines;
if( cLines )
{
yDelta = CalcYLineScrollDelta ( cLinesAndDir, FALSE );
}
else
{
yDelta = (direction < 0 ) ? _yHeightClient : -_yHeightClient;
cLines = 1; // for the MulDiv calculation below.
}
if ( yDelta ) // If something to scroll.
{
smoothYDelta = MulDiv( SMOOTH_PRECISION,// NB-Because no FLOAT type
MulDiv(yDelta, speedNum, speedDenom), cLines);
_smoothYDelta = smoothYDelta;
if ( fMouseRoller ) // roller event.
{ // -> additive.
_totalSmoothVScroll += yDelta;
_continuedSmoothYDelta = 0;
_continuedSmoothVScroll = 0;
} // mButton event
else
{
if ( 0 == _totalSmoothVScroll )
_totalSmoothVScroll = yDelta;
_continuedSmoothYDelta = smoothYDelta;
_continuedSmoothVScroll = yDelta;
}
}
}
}
/*
* CDisplay::SmoothVScrollUpdate()
*
* @mfunc
* Supports SmoothVScroll. Scroll a small number of pixels.
* We are called via a periodic timing task.
*/
void CDisplay::SmoothVScrollUpdate()
{
TRACEBEGIN(TRCSUBSYSEDIT, TRCSCOPEINTERN, "CDisplay::SmoothVScrollUpdate");
LONG yDelta; // Magellan mouse.
BOOL fImmediateUpdate = FALSE;
_nextSmoothVScroll += _smoothYDelta;
// Remove fractional amt.
yDelta = _nextSmoothVScroll / SMOOTH_PRECISION;
// Don't overshoot.
if ( 0 == _continuedSmoothVScroll
&& ( (_totalSmoothVScroll <= 0 && yDelta < _totalSmoothVScroll)
|| (_totalSmoothVScroll >= 0 && yDelta > _totalSmoothVScroll)) )
{
yDelta = _totalSmoothVScroll;
}
if ( yDelta ) // Scroll yDelta, the
{ // integral amount.
_totalSmoothVScroll -= yDelta;
_nextSmoothVScroll -= yDelta * SMOOTH_PRECISION;
FractionalScrollView( yDelta );
}
else if ( 0 == _totalSmoothVScroll ) // Starting to wind down?
{
_nextSmoothVScroll -= _smoothYDelta;
fImmediateUpdate = TRUE;
}
// Finished scrolling?
if ( (yDelta <= 0 && _totalSmoothVScroll >= 0) || (yDelta >= 0 && _totalSmoothVScroll <= 0 ) )
{
LONG cLinesAndDir;
if ( _continuedSmoothYDelta ) // mButton continuation.
{
_smoothYDelta = _continuedSmoothYDelta;
_totalSmoothVScroll += _continuedSmoothVScroll;
}
else
{
if ( _continuedSmoothVScroll )
{
_fFinishSmoothVScroll = TRUE; // Winding down scroll.
_continuedSmoothVScroll = 0;
// Last line's remainder...
cLinesAndDir = _smoothYDelta < 0 ? -1 : 1;
_totalSmoothVScroll = CalcYLineScrollDelta ( cLinesAndDir, TRUE );
// check for line boundry.
if ( _totalSmoothVScroll
== CalcYLineScrollDelta ( cLinesAndDir, FALSE ) )
{
_totalSmoothVScroll = 0;
}
if ( fImmediateUpdate ) // do 'this' epochs scroll.
SmoothVScrollUpdate();
}
else
{
CheckRemoveSmoothVScroll(); // All done, remove timer.
}
}
}
}
/*
* CDisplay::FinishSmoothVScroll
*
* @mfunc
* Cause smooth scroll to finish off the last fractional lines worth of
* scrolling and then stop.
*/
VOID CDisplay::FinishSmoothVScroll( )
{
TRACEBEGIN(TRCSUBSYSEDIT, TRCSCOPEINTERN, "CDisplay::FinishSmoothVScroll");
// any non-zero value.
if ( !_fFinishSmoothVScroll && _totalSmoothVScroll )
{
_fFinishSmoothVScroll = TRUE;
_continuedSmoothVScroll = 1;
_continuedSmoothYDelta = 0; // So smooth scroll stops.
_totalSmoothVScroll = 0;
}
}
/*
* CTxtEdit::CheckInstallSmoothScroll()
*
* @mfunc
* Install a new smooth scroll timer if not already scrolling.
*/
BOOL CDisplay::CheckInstallSmoothVScroll()
{
TRACEBEGIN(TRCSUBSYSEDIT, TRCSCOPEINTERN, "CDisplay::CheckInstallSmoothVScroll");
_TEST_INVARIANT_
BOOL fJustInstalled = FALSE;
if ( !_fSmoothVScroll && _ped->TxSetTimer(RETID_SMOOTHSCROLL, 25) )
{
_fSmoothVScroll = TRUE;
fJustInstalled = TRUE;
}
return fJustInstalled;
}
/*
* CTxtEdit::CheckRemoveSmoothVScroll ( )
*
* @mfunc
* Finish smooth scroll. If not a forced stop, then check
* to see if smooth scrolling should continue, and if so, setup
* to continue smooth scrolling.
*/
VOID CDisplay::CheckRemoveSmoothVScroll ( )
{
TRACEBEGIN(TRCSUBSYSEDIT, TRCSCOPEINTERN, "CDisplay::CheckRemoveSmoothVScroll");
_TEST_INVARIANT_
if( _fSmoothVScroll )
{
ScrollToLineStart( _continuedSmoothVScroll ); // Ensure stopped on a line.
_ped->TxKillTimer(RETID_SMOOTHSCROLL);
_fSmoothVScroll = FALSE;
}
}
/*
* CDisplay::LineScroll(cli, cch)
*
* Purpose:
* Scroll the view horizontally in response to a scrollbar event
*
* Note:
* No support for vertical scroll in base CDisplay. No action.
*
* Arguments:
* cli number of lines to scroll vertically
* cch number of character to scroll horizontally
*/
VOID CDisplay::LineScroll(LONG cli, LONG cch)
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::LineScroll");
_TEST_INVARIANT_
return;
}
VOID CDisplay::FractionalScrollView ( LONG yDelta )
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::FractionalScrollView");
_TEST_INVARIANT_
return;
}
VOID CDisplay::ScrollToLineStart ( LONG iDirection )
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::ScrollToLineStart");
_TEST_INVARIANT_
return;
}
LONG CDisplay::CalcYLineScrollDelta ( LONG cli, BOOL fFractionalFirst )
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::CalcYLineScrollDelta");
_TEST_INVARIANT_
return 0;
}
/*
* CDisplay::DragScroll(ppt)
*
* Purpose:
* Auto scroll when dragging the mouse out of the visible view
*
* Arguments:
* ppt mouse position (in client coordinates)
*/
BOOL CDisplay::DragScroll(const POINT * ppt)
{
TRACEBEGIN(TRCSUBSYSDISP, TRCSCOPEINTERN, "CDisplay::DragScroll");
_TEST_INVARIANT_
const DWORD dwTime = GetTickCount();
BOOL fScrolled = FALSE;
DWORD dwScroll = 0;
RECT rc;
int nScrollInset;
AssertSz(_ped->_fInPlaceActive, "CDisplay::DragScroll() called when not in-place");
GetViewRect(rc);
nScrollInset = (int)sysparam.GetScrollInset();
InflateRect(&rc, - nScrollInset, - nScrollInset);
if(_fVScrollEnabled && (_ped->TxGetScrollBars() & ES_AUTOVSCROLL))
{
const yScroll = ConvertYPosToScrollPos(GetYScroll());
if(ppt->y <= rc.top)
{
dwScroll = dwAutoScrollUp;
}
else if(ppt->y > rc.bottom)
{
LONG yMax = GetScrollRange(SB_VERT);
if(yScroll < yMax)
dwScroll = dwAutoScrollDown;
}
}
if(!dwScroll && _fHScrollEnabled && (_ped->TxGetScrollBars() & ES_AUTOHSCROLL))
{
const xScroll = ConvertXPosToScrollPos(GetXScroll());
if((ppt->x <= rc.left) && (xScroll > 0))
{
dwScroll = dwAutoScrollLeft;
}
else if(ppt->x > rc.right)
{
LONG xMax = GetScrollRange(SB_HORZ);
if(xScroll < xMax)
dwScroll = dwAutoScrollRight;
}
}
if(dwScroll)
{
if(_dwScrollLast != dwScroll)
{
// entered or moved to a different auto scroll area
// reset delay counter
TRACEINFOSZ("enter auto scroll area");
_dwTimeScrollNext = dwTime + cmsecScrollDelay;
}
else if(dwTime >= _dwTimeScrollNext)
{
WORD wScrollCode = SB_LINEDOWN;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -