tomrange.cpp

来自「Windows CE 6.0 Word Application 源码」· C++ 代码 · 共 2,345 行 · 第 1/5 页

CPP
2,345 行
字号
	HRESULT hr = GetLong(0, pIndex);
	if(hr != NOERROR)
		return hr;

	LONG	  cp;
	LONG	  cUnit = tomBackward;
	CTxtRange rg(*this);

	hr = rg.Expander(Unit, FALSE, NULL,			// Go to Start of Unit; else
							 &cp, NULL);		//  UnitCounter gives 1 extra
	if(FAILED(hr))
		return hr;								// Unit not recognized

	LONG cch = rg.UnitCounter(Unit, cUnit, 0);
	
	if(cch == tomForward)						// UnitCounter() doesn't know
		return E_NOTIMPL;						//  Unit

	if(cch == tomBackward)						// Unit not in story
		return S_FALSE;

	*pIndex = -cUnit + 1;						// Make count positive and
												//  1-based
	return NOERROR;
}

/*
 *	CTxtRange::GetPara (ppPara)
 *
 *	@mfunc
 *		Get an ITextPara object with the paragraph attributes of this range		
 *
 *	@rdesc
 *		HRESULT = <p ppPara> ? NOERROR : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::GetPara (
	ITextPara ** ppPara)	//@parm Out parm to receive ITextPara object  
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::GetPara");
 
	HRESULT hr = GetLong(NULL, (LONG *)ppPara);
	if(hr != NOERROR)
		return hr;

	*ppPara = (ITextPara *) new CTxtPara(this);
	return *ppPara ? NOERROR : E_OUTOFMEMORY;
}

/*
 *	CTxtRange::GetPoint (px, py, Type)
 *
 *	@mfunc
 *		Get point for selection Start or End and intraline position
 *		as determined by <p Type>.
 *
 *	@rdesc
 *		HRESULT = (!<p px> or !<p py>) ? E_INVALIDARG :
 *				  (if success) ? NOERROR : S_FALSE
 */
STDMETHODIMP CTxtRange::GetPoint (
	long 	Type, 		//@parm Type of point
	long *	px,			//@parm Out parm for x coordinate
	long *	py)			//@parm Out parm for y coordinate
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtSelection::GetPoint");

	if(!px || !py)
		return E_INVALIDARG;

	*px = *py = 0;

 	if(IsZombie())
		return CO_E_RELEASED;

	LONG		ili;
	BOOL		fAtEnd = _cch > 0;				// Default value for IP
	POINT		pt;
	CRchTxtPtr	tp(*this);						// Default active end
	CTxtEdit *	ped = GetPed();
	CDisplay *	pdp = ped->_pdp;				// Save indirections

	if(!pdp || !ped->fInplaceActive())
		return E_FAIL;							// No display or not active
												// then we can do nothing.

	if (fAtEnd ^ !(Type & tomStart))			// Move tp to active end
		tp.Advance(-_cch);

	ili = pdp->PointFromTp(tp, NULL, fAtEnd, pt, NULL, Type & 0x1f);


	RECT rcView;								// Verify return value makes
												// sense since PointFromTp
												// will return values outside
												// client rect.
	pdp->GetViewRect(rcView, NULL);

	if((ili >= 0)								// Function succeeded
		&& ((pt.x <= rcView.right) && (pt.x >= rcView.left))
		&& ((pt.y <= rcView.bottom) && (pt.y >= rcView.top)))
	{
		ped->TxClientToScreen(&pt);	
		*px = pt.x;
		*py = pt.y;
		return NOERROR;
	}
	return S_FALSE;								// Function failed
}

/*
 *	CTxtRange::GetStart	(pcpFirst)
 *
 *	@mfunc
 *		Get this range's Start (cpMin) cp
 *
 *	@rdesc
 *		HRESULT = (<p pcpFirst>) ? NOERROR : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::GetStart (
	long * pcpFirst) 		//@parm Out parm to receive Start cp value
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::GetStart");
 
	return GetLong(GetCpMin(), pcpFirst);
}

/*
 *	CTxtRange::GetStoryLength (pcch)
 *
 *	@mfunc
 *		Set *<p pcch> = count of chars in this range's story
 *
 *	@rdesc
 *		HRESULT = (<p pcch>) ? NOERROR : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::GetStoryLength (
	long * pcch)		//@parm Out parm to get length of this range's story
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::GetStoryLength");

	return GetLong(GetTextLength(), pcch);
}

/*
 *	ITextRange::GetStoryType (pValue) 
 *
 *	@mfunc
 *		Property get method that gets the type of this range's
 *		story.
 *
 *	@rdesc
 *		HRESULT = (pValue) NOERROR ? E_INVALIDARG
 */
STDMETHODIMP CTxtRange::GetStoryType (
	long *pValue)		//@parm Out parm to get type of this range's story
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::GetStoryType");

	return GetLong(tomUnknownStory, pValue);
}

/*
 *	CTxtRange::GetText (pbstr)
 *
 *	@mfunc
 *		Get plain text in this range. The Text property is the default
 *		property for ITextRange.
 *
 *	@rdesc
 *		HRESULT = (if success) ? NOERROR :
 *				  (!<p pbstr>) ? E_INVALIDARG : E_OUTOFMEMORY
 */
STDMETHODIMP CTxtRange::GetText (
	BSTR * pbstr)				//@parm Out parm to receive bstr
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::GetText");

	HRESULT hr = GetLong(NULL, (LONG *)pbstr);
	if(hr != NOERROR)
		return hr;

	if(!GetCch())
		return NOERROR;
		
	LONG cpMin, cpMost;
	LONG cch = GetRange(cpMin, cpMost);

	*pbstr = pSysAllocStringLen(NULL, cch);
	if(!*pbstr)
		return E_OUTOFMEMORY;

	CTxtPtr	tp(_rpTX);
	tp.SetCp(cpMin);
	tp.GetText( cch, (TCHAR*) * pbstr );
	return NOERROR;
}

/*
 *	CTxtRange::InRange (pRange, pB)
 *
 *	@mfunc
 *		Returns *<p pB> = tomTrue iff this range points within or at the same
 *		text as <p pRange> does
 *
 *	@rdesc
 *		HRESULT = (within range) ? NOERROR : S_FALSE
 */
STDMETHODIMP CTxtRange::InRange (
	ITextRange * pRange,		//@parm ITextRange to compare with
	long *		 pB)			//@parm Out parm for comparison result
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::InRange");

	return IsTrue(Comparer(pRange), pB);
}


/*
 *	CTxtRange::InStory (pRange, pB)
 *
 *	@mfunc
 *		Return *pB = tomTrue iff this range's story is the same as
 *		<p pRange>'s
 *
 *	@rdesc
 *		HRESULT = (in story) ? NOERROR : S_FALSE
 *
 *	@future
 *		If RichEdit acquires the ability to have multiple stories and 
 *		therefore ranges get a _story member, then compare that member
 *		instead of calling _rpTX.SameRuns().
 */
STDMETHODIMP CTxtRange::InStory (
	ITextRange *pRange,		//@parm ITextRange to query for private interface
	long *		pB)			//@parm Out parm to receive tomBool result
{
#ifndef PEGASUS
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::InStory");
 
	return IsTrue(SameVtables(this, pRange) &&			// Same vtables,
		_rpTX.SameRuns(&((CTxtRange *)pRange)->_rpTX),	//  same Runs
		pB);
#else
	return 0;
#endif
}

/*
 *	CTxtRange::IsEqual (pRange, pB)
 *
 *	@mfunc
 *		Returns *<p pB> = tomTrue iff this range points at the same text (cp's
 *		and story) as <p pRange> does and pB isn't NULL.
 *
 *	@rdesc
 *		HRESULT = (equal objects) ? NOERROR : S_FALSE
 */
STDMETHODIMP CTxtRange::IsEqual (
	ITextRange * pRange,		//@parm ITextRange to compare with
	long *		 pB)			//@parm Out parm for comparison result
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::IsEqual");

	return IsTrue(Comparer(pRange) < 0, pB);
}

/*
 *	CTxtRange::Move (Unit, Count, pDelta)
 *
 *	@mfunc
 *		Move end(s) <p Count> <p Unit>'s, returning *<p pDelta> = # units
 *		actually moved. In general, this method converts a range into an
 *		insertion point if it isn't already, and moves the insertion point.
 *		If <p Count> <gt> 0, motion is forward toward the end of the story;
 *		if <p Count> <lt> 0, motion is backward toward the beginning.
 *		<p Count> = 0 moves cpFirst to the beginning of the <p Unit>
 *		containing cpFirst.
 *  
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if Unit supported) ? S_FALSE	: E_NOTIMPL
 *	@devnote
 *		Argument validation of the three Move methods is done by the helper
 *		function CTxtRange::Mover(Unit, Count, pDelta, Mode)
 */
STDMETHODIMP CTxtRange::Move (
	long 	Unit,			//@parm Unit to use
	long 	Count,			//@parm Number of Units to move
	long *	pDelta)			//@parm Out parm to receive actual count of
							//		Units end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::Move");
	CCallMgr	callmgr(GetPed());

	return Mover(Unit, Count, pDelta, MOVE_IP);
}

/*
 *	CTxtRange::MoveEnd (Unit, Count, pDelta)
 *
 *	@mfunc
 *		Move End end <p Count> <p Unit>'s, returning *<p pDelta> = # units
 *		actually moved
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if Unit supported) ? S_FALSE	: E_NOTIMPL
 */
STDMETHODIMP CTxtRange::MoveEnd (
	long 	Unit,			//@parm Unit to use
	long 	Count,			//@parm Number of Units to move
	long *	pDelta)			//@parm Out parm to receive actual count of
							//		Units end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveEnd");
	CCallMgr	callmgr(GetPed());

	return Mover(Unit, Count, pDelta, MOVE_END);
}

/*
 *	CTxtRange::MoveEndUntil (Cset, Count, pDelta)
 *
 *	@mfunc
 *		Move the End just past all contiguous characters that are not found
 *		in the set of characters specified by the VARIANT <p Cset> parameter.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if <p Cset> valid) ? S_FALSE : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::MoveEndUntil (
	VARIANT * Cset,				//@parm Character match set to use
	long 	  Count,			//@parm Max number of characters to move past
	long *	  pDelta)			//@parm Out parm to receive actual count of
								//		characters end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveEndUntil");

	return Matcher(Cset, Count, pDelta, MOVE_END, MATCH_UNTIL);
}

/*
 *	CTxtRange::MoveEndWhile (Cset, Count, pDelta)
 *
 *	@mfunc
 *		Move the End just past all contiguous characters that are found in
 *		the set of characters specified by the VARIANT <p Cset> parameter.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if <p Cset> valid) ? S_FALSE : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::MoveEndWhile (
	VARIANT * Cset,				//@parm Character match set to use
	long 	  Count,			//@parm Max number of characters to move past
	long *	  pDelta)			//@parm Out parm to receive actual count of
								//		characters end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveEndWhile");

	return Matcher(Cset, Count, pDelta, MOVE_END, MATCH_WHILE);
}

/*
 *	CTxtRange::MoveStart (Unit, Count, pDelta)
 *
 *	@mfunc
 *		Move Start end <p Count> <p Unit>'s, returning *<p pDelta> = # units
 *		actually moved
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if Unit supported) ? S_FALSE	: E_NOTIMPL
 */
STDMETHODIMP CTxtRange::MoveStart (
	long 	Unit,			//@parm Unit to use
	long 	Count,			//@parm Number of Units to move
	long *	pDelta)			//@parm Out parm to receive actual count of
							//		Units end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveStart");
	CCallMgr	callmgr(GetPed());

	return Mover(Unit, Count, pDelta, MOVE_START);
}

/*
 *	CTxtRange::MoveStartUntil (Cset, Count, pDelta)
 *
 *	@mfunc
 *		Move the Start just past all contiguous characters that are not found
 *		in the set of characters specified by the VARIANT <p Cset> parameter.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if <p Cset> valid) ? S_FALSE : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::MoveStartUntil (
	VARIANT * Cset,				//@parm Character match set to use
	long 	  Count,			//@parm Max number of characters to move past
	long *	  pDelta)			//@parm Out parm to receive actual count of
								//		characters end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveStartUntil");

	return Matcher(Cset, Count, pDelta, MOVE_START, MATCH_UNTIL);
}

/*
 *	CTxtRange::MoveStartWhile (Cset, Count, pDelta)
 *
 *	@mfunc
 *		Move the Start just past all contiguous characters that are found in
 *		the set of characters specified by the VARIANT <p Cset> parameter.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if <p Cset> valid) ? S_FALSE : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::MoveStartWhile (
	VARIANT * Cset,				//@parm Character match set to use
	long 	  Count,			//@parm Max number of characters to move past
	long *	  pDelta)			//@parm Out parm to receive actual count of
								//		characters end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveStartWhile");

	return Matcher(Cset, Count, pDelta, MOVE_START, MATCH_WHILE);
}

/*
 *	CTxtRange::MoveUntil (Cset,Count, pDelta)
 *
 *	@mfunc
 *		Convert this range into an insertion point if it isn't already,
 *		and keep moving the insertion point until encountering any
 *		character in the set of characters specified by the VARIANT cset
 *		parameter.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :
 *				  (if <p Cset> valid) ? S_FALSE : E_INVALIDARG
 */
STDMETHODIMP CTxtRange::MoveUntil (
	VARIANT * Cset,				//@parm Character match set to use
	long 	  Count,			//@parm Max number of characters to move past
	long *	  pDelta)			//@parm Out parm to receive actual count of
								//		characters end is moved
{
	TRACEBEGIN(TRCSUBSYSTOM, TRCSCOPEEXTERN, "CTxtRange::MoveUntil");
							
	return Matcher(Cset, Count, pDelta, MOVE_IP, MATCH_UNTIL);
}

/*
 *	CTxtRange::MoveWhile (Cset, Count, pDelta)
 *
 *	@mfunc
 *		Convert this range into an insertion point if it isn't already,
 *		and keep moving the insertion point so long as (while) the
 *		characters past by are found in set of characters specified by
 *		the VARIANT cset parameter.  Such a contiguous set of characters
 *		is known as a span of characters.  The magnitude of the <p Count>
 *		parameter gives the maximum number of characters to move past and
 *		the sign of <p Count> specifies the direction to move in.
 *
 *	@rdesc
 *		HRESULT = (if change) ? NOERROR :

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?