/** * @file XTPMarkupTextBlock.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPMARKUPTEXTBLOCK_H__) # define __XTPMARKUPTEXTBLOCK_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" class CXTPMarkupBrush; class CXTPMarkupInlineCollection; class CXTPMarkupInline; class CXTPMarkupDrawingContext; class CXTPMarkupRenderTransform; template class CXTPMarkupTypedSimpleStack; /** * @brief * Text trimming type. * * Example: *
pTexBlock->SetTextTrimming(xtpMarkupTextTrimmingCharacterEllipsis)
* @see * CXTPMarkupTextBlock */ enum XTPMarkupTextTrimming { xtpMarkupTextTrimmingNone, /**< Drawing without trimming. */ xtpMarkupTextTrimmingCharacterEllipsis, /**< Replaces part of the given string with ellipses, if necessary. */ xtpMarkupTextTrimmingWordEllipsis, /**< Replaces last word of the given string with ellipses, if necessary. */ }; /** * @brief * Text wrapping type. * * Example: *
pTexBlock->SetTextWrapping(xtpMarkupTextWrap)
* @see * CXTPMarkupTextBlock */ enum XTPMarkupTextWrapping { xtpMarkupTextNoWrap, /**< No line wrapping is performed. */ xtpMarkupTextWrap, /**< Line-breaking occurs if the line overflows beyond the available block width, even if the standard line breaking algorithm cannot determine any line break opportunity. */ xtpMarkupTextWrapWithOverflow /**< Line-breaking occurs if the line overflows beyond the available block width. However, a line may overflow beyond the block width if the line breaking algorithm cannot determine a line break opportunity. */ }; /** * @brief * CXTPMarkupTextBlock is a CXTPMarkupFrameworkElement derived class. * It implements the TextBlock XAML Tag. */ class _XTP_EXT_CLASS CXTPMarkupTextBlock : public CXTPMarkupFrameworkElement { /** @cond */ DECLARE_MARKUPCLASS(CXTPMarkupTextBlock) /** @endcond */ private: struct CLine; struct CLineIterator; struct CLinePart; protected: /** * @brief * Constructs a CXTPMarkupTextBlock object. */ CXTPMarkupTextBlock(); /** * @brief * Destroys a CXTPMarkupTextBlock object, handles cleanup and deallocation. */ virtual ~CXTPMarkupTextBlock(); public: /** * @brief * Sets the text for the TextBlock object. * @param lpszText New text to be set. */ void SetText(LPCWSTR lpszText); /** * @brief * Gets the current text of the TextBlock object. * @return * A CString object containing the current text of the TextBlock object. */ CString GetText() const; /** * @brief * Gets a pointer to the CXTPMarkupInlineCollection object containing * the TextBlock object's inline blocks. * @return * A pointer to the CXTPMarkupInlineCollection object containing * the TextBlock object's inline blocks. */ CXTPMarkupInlineCollection* GetInlines() const; /** * @brief * Sets the background brush for the TextBlock object. * @param pBrush Pointer to a CBrush object. */ void SetBackground(CXTPMarkupBrush* pBrush); /** * @brief * Gets the background brush of the TextBlock object. * @return * A pointer to the background brush of the TextBlock object. */ CXTPMarkupBrush* GetBackground() const; /** * @brief * Sets the default text brush for the TextBlock object. * @param pBrush Pointer to a CBrush object. */ void SetForeground(CXTPMarkupBrush* pBrush); /** * @brief * Gets the default text brush of the TextBlock object. * @return * A pointer to the default text brush of the TextBlock object. */ CXTPMarkupBrush* GetForeground() const; /** * @brief * Sets the text alignment for the TextBlock object. * @param alignment New alignment to be set; must be one of the values * defined by the XTPMarkupTextAlignment enumeration. * @see * XTPMarkupTextAlignment, GetTextAlignment */ void SetTextAlignment(XTPMarkupTextAlignment alignment); /** * @brief * Gets the text alignment of the TextBlock object. * @return * The text alignment of the TextBlock object; returns one of the * values defined by the XTPMarkupTextAlignment enumeration. * @see * XTPMarkupTextAlignment, SetTextAlignment */ XTPMarkupTextAlignment GetTextAlignment() const; /** * @brief * Sets the text wrapping type for the bounding rectangle * (how text will be wrapped inside the bounding rectangle). * @param nTextWrapping New text wrapping type to be set; must be one of the values * defined by the XTPMarkupTextWrapping enumeration. * @see * XTPMarkupTextWrapping, SetTextWrapping */ void SetTextWrapping(XTPMarkupTextWrapping nTextWrapping); /** * @brief * Sets the text wrapping type for the bounding rectangle * (how text will be wrapped inside the bounding rectangle). * @param bTextWrapping TRUE for text wrapping. * @see * XTPMarkupTextWrapping, SetTextWrapping */ void SetTextWrapping(BOOL bTextWrapping); /** * @brief * Gets the text wrapping type of the bounding rectangle * (how text is wrapped inside the bounding rectangle). * @return * The text wrapping type; returns one of the values defined by * the XTPMarkupTextWrapping enumeration. * @see * XTPMarkupTextWrapping, SetTextWrapping */ XTPMarkupTextWrapping GetTextWrapping() const; /** * @brief * Sets the text trimming style * (how text will be trimmed when content overflows the content area). * @param bTextTrimming New text trimming style to be set; must be one of the values * defined by the XTPMarkupTextTrimming enumeration. * @details * The TextTrimming property has no effect unless the TextWrapping * property is set to NoWrap. */ void SetTextTrimming(XTPMarkupTextTrimming bTextTrimming); /** * @brief * Gets the current text trimming style * (how text is trimmed when content overflows the content area). * @return * The current text trimming style; returns one of the values defined by * the XTPMarkupTextTrimming enumeration. */ XTPMarkupTextTrimming GetTextTrimming() const; /** * @brief * Sets a value that indicates the thickness of the padding space * between the boundaries of the content area and the content * displayed by a TextBlock. * @param nLeft Left space. * @param nTop Top space. * @param nRight Right space. * @param nBottom Bottom space. */ void SetPadding(int nLeft, int nTop, int nRight, int nBottom); /** * @brief * Sets a value that indicates the thickness of the padding space * between the boundaries of the content area and the content * displayed by a TextBlock. * @param nPadding All borders. */ void SetPadding(int nPadding); /** * @brief * Retrieves a value that indicates the thickness of the padding space * between the boundaries of the content area and the content * displayed by a TextBlock. * @return * A pointer to a CXTPMarkupThickness object that indicates the thickness * of the padding space between the boundaries of the content area * and the content displayed by a TextBlock. * @see * SetPadding */ CXTPMarkupThickness* GetPadding() const; /** * @brief * Sets the font size for the TextBlock object. * @param nFontSize New font size to be set. */ void SetFontSize(int nFontSize); /** * @brief * Gets the font size of the TextBlock object. * @return * The font size of the TextBlock object if it was set. */ int GetFontSize() const; /** * @brief * Sets the font weight for the TextBlock object. * @param nFontWeight New font weight to be set. */ void SetFontWeight(int nFontWeight); /** * @brief * Gets the font weight of the TextBlock object. * @return * The font weight of the TextBlock object if it was set. */ int GetFontWeight() const; /** * @brief * Sets the typeface name for the font. * @param lpszFontFamily New typeface name to be set. */ void SetFontFamily(LPCWSTR lpszFontFamily); /** * @brief * Gets the typeface name of the font. * @return * The typeface name of the font if it was set, otherwise NULL. */ LPCWSTR GetFontFamily() const; /** * @brief * Sets the font style for the TextBlock object. * @param nFontStyle New font style to be set. * @details * Italic (nFontStyle = 1) and Normal (FontStyle = 0) are supported. */ void SetFontStyle(int nFontStyle); /** * @brief * Gets the font style of the TextBlock object. * @return * The font style of the TextBlock object if it was set. */ int GetFontStyle() const; /** * @brief * Sets the font text decoration for the TextBlock object. * * @param nTextDecorations New font text decoration to be set. * @details * Underline (1) and Strikethrough(2) are supported. */ void SetTextDecorations(int nTextDecorations); /** * @brief * Gets the font text decoration of the TextBlock object. * * @return The font text decoration of the TextBlock object if it was set. */ int GetTextDecorations() const; /** @cond */ // Internal methods public: CXTPMarkupInline* GetFirstInline() const; public: virtual void SetContentObject(CXTPMarkupBuilder* pBuilder, CXTPMarkupObject* pContent); virtual BOOL HasContentObject() const; protected: virtual CSize MeasureOverride(CXTPMarkupDrawingContext* pDC, CSize szAvailableSize); virtual CSize ArrangeOverride(CSize szFinal); virtual void OnRender(CXTPMarkupDrawingContext* pDC); virtual BOOL AllowWhiteSpaceContent() const; virtual void OnPropertyChanged(CXTPMarkupDependencyProperty* pProperty, CXTPMarkupObject* pOldValue, CXTPMarkupObject* pNewValue); virtual int GetLogicalChildrenCount() const; virtual CXTPMarkupObject* GetLogicalChild(int nIndex) const; CXTPMarkupInputElement* InputHitTestOverride(CPoint point) const; void InvalidateMeasureOverride(CXTPMarkupDrawingContext* pDC); /** @endcond */ private: void RemoveAllLines(); void CloseLine(CLineIterator& li, int nWidth); void TrimLine(CLineIterator& li, int nWidth); void PushLinePart(CLineIterator& li, int nWidth); void CalculateLines(CXTPMarkupDrawingContext* pDC, int nWidth); void RenderTextDecorations(CXTPMarkupDrawingContext* pDC, CLinePart* part); FLOAT GetStackWidth(CLineIterator& li) const; void AddEmptyRun(CLineIterator& li); /** @cond */ public: DECLARE_DISPATCH_MAP() # ifdef _XTP_ACTIVEX DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPMarkupTextBlock); # endif afx_msg VARIANT OleGetText(); afx_msg void OleSetText(const VARIANT& lpCaption); afx_msg long OleGetTextWrapping(); afx_msg void OleSetTextWrapping(long nValue); afx_msg long OleGetTextTrimming(); afx_msg void OleSetTextTrimming(long nValue); afx_msg long OleGetTextAlignment(); afx_msg void OleSetTextAlignment(long nValue); afx_msg long OleGetTextDecorations(); afx_msg void OleSetTextDecorations(long nValue); afx_msg long OleGetFontSize(); afx_msg void OleSetFontSize(long nValue); afx_msg long OleGetFontWeight(); afx_msg void OleSetFontWeight(long nValue); afx_msg BSTR OleGetFontFamily(); afx_msg void OleSetFontFamily(LPCTSTR lpszValue); afx_msg long OleGetFontStyle(); afx_msg void OleSetFontStyle(long nValue); afx_msg LPDISPATCH OleGetPadding(); afx_msg void OleSetPadding(LPDISPATCH lpPaddingDisp); afx_msg long OleGetFontQuality(); afx_msg void OleSetFontQuality(long nValue); afx_msg LPDISPATCH OleGetBackground(); afx_msg void OleSetBackground(LPDISPATCH lpBackground); afx_msg LPDISPATCH OleGetForeground(); afx_msg void OleSetForeground(LPDISPATCH lpBackground); afx_msg LPDISPATCH OleGetInlines(); /** @endcond */ protected: CXTPMarkupInlineCollection* m_pInlines; /**< Inline collection of TextBlock. */ public: static CXTPMarkupDependencyProperty* m_pBackgroundProperty; static CXTPMarkupDependencyProperty* m_pForegroundProperty; static CXTPMarkupDependencyProperty* m_pTextWrappingProperty; static CXTPMarkupDependencyProperty* m_pTextTrimmingProperty; static CXTPMarkupDependencyProperty* m_pTextAlignmentProperty; static CXTPMarkupDependencyProperty* m_pTextDecorationsProperty; static CXTPMarkupDependencyProperty* m_pFontSizeProperty; static CXTPMarkupDependencyProperty* m_pFontWeightProperty; static CXTPMarkupDependencyProperty* m_pFontFamilyProperty; static CXTPMarkupDependencyProperty* m_pFontStyleProperty; static CXTPMarkupDependencyProperty* m_pPaddingProperty; static CXTPMarkupDependencyProperty* m_pTextProperty; static CXTPMarkupDependencyProperty* m_pFontQualityProperty; static CXTPMarkupDependencyProperty* m_pFontCharsetProperty; private: CXTPMarkupTypedSimpleStack* m_pLineList; int m_nLastWidth; CSize m_szBlockSize; }; AFX_INLINE CXTPMarkupInlineCollection* CXTPMarkupTextBlock::GetInlines() const { return m_pInlines; } /** @cond */ AFX_INLINE int CXTPMarkupTextBlock::GetLogicalChildrenCount() const { return m_pInlines != NULL ? 1 : 0; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // !defined(__XTPMARKUPTEXTBLOCK_H__) /** @endcond */