⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cfpf.cpp

📁 Windows CE 6.0 Word Application 源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

	if(dwMaskApply & PFM_TABSTOPS)
	{
		cTabCount = min(pPF->cTabCount, MAX_TAB_STOPS);
		cTabCount = max(cTabCount, 0);
		CopyMemory(rgxTabs, pPF->rgxTabs, sizeof(LONG)*cTabCount);
		ZeroMemory(rgxTabs + cTabCount, sizeof(LONG)*(MAX_TAB_STOPS - cTabCount));
	}

	// AymanA: 11/7/96 Moved the wEffects set before the possible return NOERROR.
	wEffectMask	= (WORD)(dwMaskApply >> 16);	// Reset effect bits to be
	wEffects &= ~wEffectMask;					//  modified and OR in
	wEffects |= pPF->wEffects & wEffectMask;	//  supplied values

	if ((dwMaskApply & PFM_RTLPARA) && !(dwMaskApply & PFM_ALIGNMENT) &&
		wAlignment != PFA_CENTER)
	{
		wAlignment = (wEffects & PFE_RTLPARA) ? PFA_RIGHT : PFA_LEFT;
	}

	// PARAFORMAT check
	if(fPF && dwMaskApply & (PFM_STARTINDENT | PFM_OFFSET))
	{
		if(dxStartIndent < 0)					// Don't let indent go
			dxStartIndent = 0;					//  negative

		if(dxStartIndent + dxOffset < 0)		// Don't let indent +
			dxOffset = -dxStartIndent;			//  offset go negative

		return NOERROR;
	}

	// PARAFORMAT2 extensions
	if(dwMaskApply & PFM_SPACEBEFORE)
		dySpaceBefore	= pPF->dySpaceBefore;

	if(dwMaskApply & PFM_SPACEAFTER)
		dySpaceAfter	= pPF->dySpaceAfter;

	if(dwMaskApply & PFM_LINESPACING)
	{
		dyLineSpacing	= pPF->dyLineSpacing;
		bLineSpacingRule = pPF->bLineSpacingRule;
	}

	if(dwMaskApply & PFM_OUTLINELEVEL)
		bOutlineLevel	= pPF->bOutlineLevel;

	if(dwMaskApply & PFM_STYLE)
		HandleStyle(pPF->sStyle);

	Assert((bOutlineLevel & 1) ^ IsHeadingStyle(sStyle));

	if(dwMaskApply & PFM_SHADING)
	{
		wShadingWeight	= pPF->wShadingWeight;
		wShadingStyle	= pPF->wShadingStyle;
	}

	if(dwMaskApply & PFM_NUMBERINGSTART)
		wNumberingStart	= pPF->wNumberingStart;

	if(dwMaskApply & PFM_NUMBERINGSTYLE)
		wNumberingStyle	= pPF->wNumberingStyle;

	if(dwMaskApply & PFM_NUMBERINGTAB)
		wNumberingTab	= pPF->wNumberingTab;

	if(dwMaskApply & PFM_BORDER)
	{
		dwBorderColor	= pPF->dwBorderColor;
		wBorders		= pPF->wBorders;
		wBorderSpace	= pPF->wBorderSpace;
		wBorderWidth	= pPF->wBorderWidth;
	}

	return NOERROR;
}

/*
 *	CParaFormat::ApplyDefaultStyle(Style)
 *
 *	@mfunc	
 *		Copy default properties for Style
 */
void CParaFormat::ApplyDefaultStyle (
	LONG Style)		//@parm Style to apply
{
	Assert(IsKnownStyle(Style));

	if(IsHeadingStyle(Style))				// Set Style's dySpaceBefore,
	{										//  dySpaceAfter (in twips)
		dySpaceBefore = 12*20;				//  (same for all headings)
		dySpaceAfter  =  3*20;
		wNumbering	  = 0;					// No numbering
	}
}

/*
 *	CParaFormat::Compare(pPF)
 *
 *	@mfunc
 *		Compare this CParaFormat to *<p pPF>
 *
 *	@rdesc
 *		TRUE if they are the same
 *
 *	@devnote
 *		First compare 5 DWORDs of PARAFORMAT (wNumbering, wReserved),
 *		dxStartIndent, dxRightIndent, dxOffset, (wAlignment, cTabCount).
 *		If they are identical, compare the remaining cTabCount - 1
 *		elements of the tab array.  If they, too, are identical, compare the
 *		PARAFORMAT2 extensions. For PARAFORMAT structures, the extension values
 *		are taken to equal 0.  Return TRUE only if all comparisons succeed.
 */
BOOL CParaFormat::Compare (
	const CParaFormat *pPF) const		//@parm	CParaFormat to compare this
{										//  CParaFormat to
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CParaFormat::Compare");

	DWORD	Count = 5;
	BOOL	fPF2 = pPF->cbSize == sizeof(PARAFORMAT2);
	DWORD	i;
	DWORD *	p1 = (DWORD *)this + 2;			// Bypass cbSize & dwMask fields
	DWORD *	p2 = (DWORD *)pPF  + 2;

	if(cTabCount)
		Count += cTabCount;

	for (i = 0; i < Count; i++)				// Compare first 5 DWORDs plus
	{										//  any tabs that are defined
		if(*p1++ != *p2++)
			return FALSE;
	}

	/* Compare PARAFORMAT2 extras:
	 *		1. dySpaceBefore
	 *		2. dySpaceAfter
	 *		3. dyLineSpacing
	 *		4. sStyle, bLineSpacingRule, bCRC
	 *		5. wShadingWeight,	wShadingStyle,
	 *		6. wNumberingStart, wNumberingStyle
	 *		7. wNumberingTab, wBorderSpace
	 *		8. wBorderWidth, wBorders
	 *
	 *		i.e., 8 extra DWORDs
	 *
	 * Currently internal:
	 *		1. dwBorderColors
	 *
	 *		i.e., 1 extra DWORD
	 */
	DWORD j;
	p1 = (DWORD *)&this->dySpaceBefore;
	p2 = (DWORD *)&pPF->dySpaceBefore;

	AssertSz(offsetof(CParaFormat, dySpaceBefore) == 4*(7 + MAX_TAB_STOPS),
		"CParaFormat::Compare: unpacked PARAFORMAT struct");
	AssertSz(sizeof(CParaFormat) == 4*(7 + MAX_TAB_STOPS + 8 + 1),
		"CParaFormat::Compare: unexpected CParaFormat size");

	for (i = j = 0; i < 9; i++)				// PARAFORMAT2 extensions
	{
		if(*p1++ != *p2++)
			return FALSE;
	}

	return TRUE;
}

/*
 *	CParaFormat::DeleteTab(tbPos)
 *
 *	@mfunc
 *		Delete tabstop at position <p tbPos>
 *
 *	@rdesc
 *		(success) ? NOERROR : S_FALSE
 */
HRESULT CParaFormat::DeleteTab (
	LONG	tbPos)			//@parm Tab position to delete
{
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CParaFormat::DeleteTab");

	LONG	Count	= cTabCount;
	LONG	iTab;

	if(tbPos <= 0)
		return E_INVALIDARG;

	for(iTab = 0; iTab < Count; iTab++)			// Find tabstop for position
	{
		if (GetTabPos(rgxTabs[iTab]) == tbPos)
		{
			MoveMemory(&rgxTabs[iTab],			// Shift array down
				&rgxTabs[iTab + 1],				//  (unless iTab is last tab)
				(Count - iTab - 1)*sizeof(LONG));
			cTabCount--;						// Decrement tab count and
			return NOERROR;						//  signal no error
		}
	}
	return S_FALSE;
}

/*
 *	CParaFormat::Delta(pPF)
 *
 *	@mfunc
 *		Adjust dwMask for differences between this CParaFormat and *<p pPF>
 *
 *	@devnote
 *		*<p pPF> is an external CParaFormat, i.e., it's either a PARAFORMAT
 *		or a PARAFORMAT2 with the appropriate size given by cbSize. But
 *		this CParaFormat is internal and cbSize is used as a reference count.
 */
void CParaFormat::Delta (
	CParaFormat *pPF) const 		//@parm	CParaFormat to compare this
{									//  CParaFormat to
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CParaFormat::Delta");

	BOOL	fPF2 = pPF->cbSize == sizeof(PARAFORMAT2);
	LONG	dwT = 0;								// Collect mask bits for
													//  properties that change
	if(wNumbering	 != pPF->wNumbering)
		dwT |= PFM_NUMBERING;

	if(dxStartIndent != pPF->dxStartIndent)
		dwT |= PFM_STARTINDENT;

	if(dxRightIndent != pPF->dxRightIndent)
		dwT |= PFM_RIGHTINDENT;

	if(dxOffset		 != pPF->dxOffset)
		dwT |= PFM_OFFSET;

	if(wAlignment	 != pPF->wAlignment)
		dwT |= PFM_ALIGNMENT;

	AssertSz(pPF->cTabCount >= 0 && pPF->cTabCount <= MAX_TAB_STOPS,
		"RTR::GetParaFormat(): illegal tab count");

	if (pPF->dwMask & PFM_TABSTOPS &&
		(cTabCount != pPF->cTabCount ||
			(cTabCount > 0 && CompareMemory(rgxTabs, pPF->rgxTabs,
										cTabCount * sizeof(LONG)))))
	{
		dwT |= PFM_TABSTOPS;
	}

	dwT |= (wEffects ^ pPF->wEffects) << 16;


	if(fPF2)
	{
		if(dySpaceBefore	!= pPF->dySpaceBefore)
			dwT |= PFM_SPACEBEFORE;

		if(dySpaceAfter	 	!= pPF->dySpaceAfter)
			dwT |= PFM_SPACEAFTER;

		if(dyLineSpacing	!= pPF->dyLineSpacing ||
		   bLineSpacingRule	!= pPF->bLineSpacingRule)
		{
			dwT |= PFM_LINESPACING;
		}

		if(sStyle			!= pPF->sStyle)
			dwT |= PFM_STYLE;

		if (wShadingWeight	!= pPF->wShadingWeight ||
			wShadingStyle	!= pPF->wShadingStyle)
		{
			dwT |= PFM_SHADING;
		}

		if(wNumberingStart	!= pPF->wNumberingStart)
			dwT |= PFM_NUMBERINGSTART;

		if(wNumberingStyle	!= pPF->wNumberingStyle)
			dwT |= PFM_NUMBERINGSTYLE;

		if(wNumberingTab	!= pPF->wNumberingTab)
			dwT |= PFM_NUMBERINGTAB;

		if (wBorders		!= pPF->wBorders	 ||
			wBorderWidth	!= pPF->wBorderWidth ||
			wBorderSpace	!= pPF->wBorderSpace ||
			dwBorderColor	!= pPF->dwBorderColor)
		{
			dwT |= PFM_BORDER;
		}
	}

	pPF->dwMask &= ~dwT;						// Reset mask bits for
}												//  properties that differ

/*
 *	CParaFormat::fSetStyle()
 *
 *	@mfunc
 *		Return TRUE iff this PF specifies that the style should be set.
 *		See code for list of conditions for this to be true
 *
 *	@rdesc
 *		TRUE iff pCF specifies that the style sStyle should be set
 */
BOOL CParaFormat::fSetStyle() const
{
	return	(dwMask & ~(PFM_OUTLINELEVEL | PFM_COLLAPSED)) != PFM_ALL2 &&
			dwMask &  PFM_STYLE			  &&
			cbSize == sizeof(PARAFORMAT2) &&
			IsKnownStyle(sStyle);
}

/*
 *	CParaFormat::Get(pPF)
 *
 *	@mfunc
 *		Copy this CParaFormat to *<p pPF>
 */
void CParaFormat::Get (
	CParaFormat *pPF) const		//@parm	CParaFormat to copy this CParaFormat to
{
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEINTERN, "CParaFormat::Get");

	UINT cb = pPF->cbSize;

	pPF->dwMask = PFM_ALL2;						// Default PARAFORMAT2
	if(cb != sizeof(PARAFORMAT2))				// It isn't
	{
		pPF->dwMask = PFM_ALL;					// Make it PARAFORMAT
		ASSERT(cb == sizeof(PARAFORMAT));		// It better be a PARAFORMAT
	}

    // Bound the copy
    cb = min(cb, sizeof(CParaFormat));

	CopyFormat(pPF, this, cb);					// Copy this to pPF
	pPF->dwBorderColor = dwBorderColor;
}

/*
 *	CParaFormat::GetTab (iTab, ptbPos, ptbAln, ptbLdr)
 *
 *	@mfunc
 *		Get tab parameters for the <p iTab> th tab, that is, set *<p ptbPos>,
 *		*<p ptbAln>, and *<p ptbLdr> equal to the <p iTab> th tab's
 *		displacement, alignment type, and leader style, respectively.  The
 *		displacement is given in twips.
 *
 *	@rdesc
 *		HRESULT = (no <p iTab> tab)	? E_INVALIDARG : NOERROR
 */
HRESULT CParaFormat::GetTab (
	long	iTab,			//@parm Index of tab to retrieve info for
	long *	ptbPos,			//@parm Out parm to receive tab displacement
	long *	ptbAln,			//@parm Out parm to receive tab alignment type
	long *	ptbLdr) const	//@parm Out parm to receive tab leader style
{
	TRACEBEGIN(TRCSUBSYSBACK, TRCSCOPEEXTERN, "CParaFormat::GetTab");

	AssertSz(ptbPos && ptbAln && ptbLdr,
		"CParaFormat::GetTab: illegal arguments");

	if(iTab < 0)									// Get tab previous to, at,
	{												//  or subsequent to the
		if(iTab < tomTabBack)						//  position *ptbPos
			return E_INVALIDARG;

		LONG i;
		LONG tbPos = *ptbPos;
		LONG tbPosi;

		*ptbPos = 0;								// Default tab not found
		for(i = 0; i < cTabCount &&					// Find *ptbPos
			tbPos > GetTabPos(rgxTabs[i]); 
			i++) ;

		tbPosi = GetTabPos(rgxTabs[i]);				// tbPos <= tbPosi
		if(iTab == tomTabBack)						// Get tab info for tab
			i--;									//  previous to tbPos
		else if(iTab == tomTabNext)					// Get tab info for tab
		{											//  following tbPos
			if(tbPos == tbPosi)
				i++;
		}
		else if(tbPos != tbPosi)					// tomTabHere
			return S_FALSE;

		iTab = i;		
	}
	if((DWORD)iTab >= (DWORD)cTabCount)				// DWORD cast also
		return E_INVALIDARG;						//  catches values < 0

	iTab = rgxTabs[iTab];
	*ptbPos = GetTabPos(iTab);
	if((iTab & PFT_DEFAULT) == PFT_DEFAULT)			// Default tab is left
		iTab = 0;									//  aligned, no leader
	*ptbAln = GetTabAlign(iTab);
	*ptbLdr = GetTabLdr(iTab);
	return NOERROR;
}

/*
 *	CParaFormat::HandleStyle(Style)
 *
 *	@func
 *		If Style is a promote/demote command, i.e., if abs((char)Style)
 *			<= # heading styles - 1, add (char)Style to	sStyle (if heading)
 *			and to bOutlineLevel (subject to defined max and min values);
 *		else sStyle = Style.
 *
 *	@rdesc
 *		return TRUE iff sStyle or bOutlineLevel changed
 *
 *	@devnote
 *		Heading styles are -2 (heading 1) through -10 (heading 9), which
 *		with TOM and WOM. Heading outline levels are 0, 2,..., 16,
 *		corresponding to headings 1 through 9 (NHSTYLES), respectively,
 *		while text that follows has outline levels 1, 3,..., 17.  This value
 *		is used for indentation. Collapsed text has the PFE_COLLAPSED bit set.
 */
BOOL CParaFormat::HandleStyle(
	LONG Style)		//@parm Style, promote/demote code, or collapse-level code
{
	if(IsStyleCommand(Style))					// Set collapse level
	{											
		WORD wEffectsSave = wEffects;			

		Style = (char)Style;					// Sign extend low byte
		if(IN_RANGE(1, Style, NHSTYLES))
		{
			wEffects &= ~PFE_COLLAPSED;
			if((bOutlineLevel & 1) || bOutlineLevel > 2*(Style - 1))
				wEffects |= PFE_COLLAPSED;		// Collapse nonheadings and
		}										//  higher numbered headings
		else if(Style == -1)
			wEffects &= ~PFE_COLLAPSED;			// Expand all

⌨️ 快捷键说明

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