CODTextComponent Class

class CODTextComponent: public CODPointComponent

The text component supports single and multiple lines of text, horizontal and vertical alignment, rotation, and editing. The following properties can be used to configure its behavior.

OD_PROP_FONT - Determines the font to use for the text.

OD_PROP_MULTILINE - Boolean property that toggles between single and muliple line text.

OD_PROP_WORDBREAK - Boolean property that enables and disables automatic word wrap.

OD_PROP_VERT_ALIGNMENT - Integer property that can have the following values (DT_TOP, DT_VCENTER, DT_BOTTOM).

OD_PROP_HORZ_ALIGNMENT - Integer property that can have the following values (DT_LEFT, DT_CENTER, DT_RIGHT).

Like most other components, the text component also supports edit, line, and fill properties (OD_PROP_EDIT, OD_PROP_LINE, OD_PROP_FILL).

The GetFormat method examines the properties and returns a flag value compatible with the Windows GDI function DrawText. The DrawText method is similar in behavior to the Windows GDI DrawText function.

When BeginEdit is called to the edit the text, an edit control is created and the component is rotated back to zero degrees for the duration of the edit action. The m_nSaveAngle member variable saves the rotation value so that when editing is complete, the component can be rotated back to the original angle.

The CalcLineBreaks method is used to determine where line breaks occur in the text buffer. It populates a CODLineBreakSet object that describes the position and size of each line. The text buffer may contain hard line breaks (carriage returns). If the OD_PROP_WORDBREAK property is TRUE, then CalcLineBreaks will determine where lines wrap as well.

The following properties are added to the component by this class:

OD_PROP_LINE, OD_PROP_FILL, OD_PROP_FONT, OD_PROP_WORDBREAK, OD_PROP_MULTILINE, OD_PROP_HORZ_ALIGNMENT, OD_PROP_VERT_ALIGNMENT, OD_PROP_AUTOSIZE

Defined in: OdTextComp.h

See Also

Component Property Identifiers

Component Property Identifiers

Class Members

VIEWS_API CODTextComponent()

Constructor.

VIEWS_API CODTextComponent(const CODTextComponent& src)

Copy constructor.

VIEWS_API virtual ~CODTextComponent()

Destructor.

VIEWS_API BOOL Create(CRect& rcBox, CDC* pDC)

Creates the text component given a bounding box.

VIEWS_API BOOL Create(CPoint ptLog, CDC* pDC)

Creates the text component given a center point.

VIEWS_API CODTextComponent& operator=(const CODTextComponent& src)

Assignment operator.

VIEWS_API virtual CODComponent* Dup() const

Create a duplicate copy of this object.

CString m_strText

The text to draw.

CODTextCompEdit* m_pEdit

Edit control for modifying text.

CFont* m_pEditFont

Edit font used for modifying the text.

int m_nSaveAngle

Saves the angle of rotation while text component is in edit mode.

State for enabling or disabling font scaling. False by default.

VIEWS_API const CString& GetText() const

Gets the text that is drawn.

VIEWS_API virtual void SetText(const LPCTSTR lpszText)

Sets the text to be drawn.

VIEWS_API UINT GetFormat() const

Returns the format properties as a bit field.

Returns a boolean for whether or not font scaling is enabled.

Enable or disable font scaling.

VIEWS_API virtual CSize CalcTextSize(CDC* pDC)

Calculate the size occupied by the text in logical units.

VIEWS_API virtual CRect CalcTextMargins(CDC* pDC)

Calculate the margins in logical units.

VIEWS_API virtual CSize CalcTextBorder(CDC* pDC)

Calculate the size of the text border in logical units.

VIEWS_API virtual void SizeToText(const OD_CONTROL_POINT ctlPt = OD_CENTER, CDC* pDC = 0)

Calculate the bounding points so that they match the dimensions of the text.

VIEWS_API virtual void GrowToText(const OD_CONTROL_POINT ctlPt = OD_CENTER, CDC* pDC = 0)

Calculate the bounding points so that the width/height are greater than or equal to the size of the text.

VIEWS_API CRect GetTextBox() const

Gets the dimensions of the text box.

VIEWS_API void SetTextBox(CRect rcBox)

Sets the dimensions of the text box.

VIEWS_API int GetAngle() const

Returns the current angle of rotation for the text.

VIEWS_API virtual void GetHandles(CODPointArray* pHandleArray, BOOL bVertexHandles = FALSE)

Return handle points (none for edit mode).

VIEWS_API virtual void Scale(float fScaleX, float fScaleY, float fOriginX, float fOriginY)

Scales the component in reference to a point.

VIEWS_API virtual int CalcFontPointSizeByRect(const CRect& rcTextBox, const CString& strText)

Calculates the size of font on a single line that will fit in the given rect.

VIEWS_API virtual int CalcAnnotationFontPointSize(const CRect& rcTextBox, const CString& strText)

Calculates the size of font that will fit, with multiple or single lines, for the given rect.

VIEWS_API int CalcLineBreaks(CDC* pDC, CODLineBreakSet& setBreaks)

Calculates the line breaks for the text buffer.

VIEWS_API BOOL IsEditing() const

Indicates whether text component in edit mode or not.

VIEWS_API virtual BOOL BeginEdit(sfl::MvcViewport* pContainer)

Puts the text component into edit mode.

VIEWS_API CString GetEditText() const

Returns the text in the edit control.

VIEWS_API virtual void SetEditText(const LPCTSTR lpszText)

Sets the text in the edit control.

VIEWS_API virtual void SaveEdit()

Transfers the text from the edit control to the text component.

VIEWS_API virtual void CancelEdit()

Closes the edit control and ends edit mode.

VIEWS_API virtual void UpdateEdit(const sfl::MvcViewport* pContainer)

Updates the edit control to reflect change in text component properties.

VIEWS_API CEdit* GetEditControl()

Gets a pointer to the edit control.

VIEWS_API virtual HBRUSH GetCtlBrush(CDC* pDC)

Return a brush that can be used to paint the edit control.

VIEWS_API virtual OD_MOVEVERTEX_RC CalculateMovedVertices(int nIndex, int nOffsetX, int nOffsetY)

Adjust other vertices to stay synchronized with the move of the given vertex.

VIEWS_API virtual void OnDraw(CDC* pDC)

Draws the text.

VIEWS_API virtual void Serialize(CArchive& ar)

Serializes the text component.

VIEWS_API void DrawText(CDC* pDC)

Draws the text.

VIEWS_API void DrawEdit(CDC* pDC)

Positions the edit control and makes it visible.