CMvcVisualComponent Class

class CMvcVisualComponent: public IVisual, public IBounds2D

The CMvcVisualComponent class provides the basic drawing and positioning interfaces required by objects that will be drawn on a device context. CMvcVisualComponent serves as the ultimate base class for all objects that can be rendered to a DC. A visual component is a light-weight base class that gives you the ability to treat all renderable objects consistently. It maintains size and position information, provides support for hit testing, and rendering.

A visual component is a very lightweight object and is the preferred base class when you need many, light visual components that are completely managed by a more intelligent container. The container is responsible for telling the component when to draw, where to draw, how large it should be etc. The visual component knows nothing about real windows, only drawing surfaces passed in via a CDC pointer. Visual components will draw themselves whenever and whereever the container instructs. This includes visual components positioned to partially or fully overlap.

A visual component maintains a bounding rectangle that describes the area of its container the component occupies. There is a important caveat here: the size and position of the component is measured in the logical unit metrics established by the container. In other words, if the container is measuring its client area in units of inches, then a position of (2, 1) will mean the visual component is positioned 2 inches from the container's left edge and 1 inch from the containers top edge. For this reason, the units of a visual component's bounds are known as external units, denoting that the bound's unit of measure are established externally. Also, notice that the subcomponent's origin is (typically) measured relative to its container's origin. Therefore, moving the container will automatically move all subcomponents.

Defined in: MvcVisualComponent.h

Class Members

CRect m_rc

Bounds of the visual component with respect to its container. This is

virtual CPoint GetOrigin() const

Get the origin of this component relative to its container and in the container's units

virtual CPoint SetOrigin(int x, int y)

Set the origin of this component relative to its container and in the container's units

virtual CPoint OffsetOrigin(int xOff, int yOff)

Offsets the component's origin by a delta

virtual CPoint MoveOrigin(int xOff,int yOff)

Move the component's origin by a delta

virtual CSize GetSize() const

Returns the width and height of the component

virtual CSize SetSize(int cx, int cy)

Sets the width and height of the component

virtual CSize ScaleBounds(int xNum, int xDenom, int yNum, int yDenom, bool bAnchorCenter = false)

Scales the bounds of the visual component

virtual CRect GetBounds() const

Get the component's bounding rectangle in the logical units defined by the container

inline CPoint TopLeft() const

Get the origin of this component

inline CPoint TopRight() const

Get the upper, right edge of the component

inline CPoint BottomLeft() const

Get the lower, left edge of the component

inline CPoint BottomRight() const

Get the lower, right edge of the component

virtual void GetMargins(CRect& rcMargins)

Get the margins around the bounds of this visual component.

BOOL ContainsPoint(const CPoint& pt) const

Tests whether a point lies within the component's bounds

BOOL Intersects(const CRect& rc) const

Tests whether the rectangle intersects the component's bounds

virtual void Sprint(CString& strDesc)

Print a description of this visual part to the specified string

virtual void Draw(CDC* pDC)

Draw the component to a device context.

virtual void OnPrepareDC(CDC* pDC)

Prepare device context for rendering.

virtual void OnCleanupDC(CDC* pDC)

Cleanup device context after rendering.

virtual void OnInitialUpdate()

Initializes the visual component

inline void NormalizeBounds()

Normalize the bounding rectangle

virtual ULONG STDMETHODCALLTYPE AddRef()

Add a reference to this object.

virtual ULONG STDMETHODCALLTYPE Release()

Release a reference to this object.