XCanvases unit of XCL is containing definition of XCanvas class,
which is very similar to TCanvas of VCL. But in XCL, XCanvas is not necessarily part of
applet. If You are using only MFC-based controls, You do not need in this unit. To make
possible to include or not to include XCanvases unit into applet optionally, Canvas
property of XWindow is of type Pointer and creating of Canvas for it is impemented like
add-on. I.e., if You use canvases, global object GlobalCanvasManager is created and
intercepts events OnCreateWindow, OnDestroyWindow, OnBeginPaint and OnEndPaint of global
object GlobalWindowsManager and intercepting ones, performs necessary tasks of creating,
destroying XCanvas object, allocating and releasing its handle.
In differ to other add-ons, You must delete reference to XCanvases unit
from everywhere to ensure that it is not in use (because GlobalCanvasManager is created in
'initialization' section). And You do not need to include it in uses clause if You do not
work with it directly. It can be included just by using XControls.pas unit (where
self-painted not windowed controls are defined).
You may get Canvas : Pointer with typecast XCanvas( SomeWindow.Canvas )
to obtain Canvas property of XWindow (if You need it). I suggest to use for this function
XCanvases.GetWindowCanvas( W : XWindow ) : XCanvas. This will ensure that XCanvases unit
is in use and Canvas property of XWindow is setuped to properly created XCanvas object.
XCanvas = class( TObject );
Properties of XCanvas:
- This property returns Windows handle of device context, allocated to XCanvas
object if it is allocated. If add-on XCanvasObjects.pas is not used, new Windows GDI object is created for every graphic object. Add-on XCanvasObjects.pas allows multiple usage of GDI objects with the same properties and economize GDI resources (this can be important in Win95/98 environment). It is possible to assign to this property handle of properly created (obtained) device context safely. In this case, if handle of XCanvas is already allocated it is freeing calling API DeleteDC. This can be used to refer XCanvas to any device context (e.g., memory device context) and use XCanvas capabilities to perform painting on it. Assign 0 to Handle to forse freeing of it. Do not so for XWindow Canvas, because it is allocating only during painting, and than is freeing automatically. |
- These three properties below are presenting the XGraphicObject descendents, defined in XGraphics unit. Its handles are allocated only when it is needed. Thus, when painting is finished and device context is releasing, its handles also are freeing. |
Methods of XCanvas:
- all methods above are very similar to those the same in TCanvas of VCL. But
procedure TextArea is intended here to provide correct calculating of
parameters for output text even if it is rotated. This does not mean that using of this
function is sufficient to show rotated text correctly, because in case if add-on XRotateFonts.pas is not in use, this
function just sets Sz to TextExtent of given string and returnes (0,0) as P0. Only if
UseFontRotator is called, this procedure returnes correct size of rectangle to place
rotated text and trigonometrically calculated by the add-on origin point P0. In any case, TextExtent, TextWidth and TextHeight functions are returning size of text without rotating. Important, that these three functions perform its task correctly in XCL (vs VCL) even if canvas handle is not yet allocated (by creating temporarily DC for this). This allows to calculate correct size for autosizing controls before creating of parent window. |
Events of XCanvas:
- these events are called when XCanvas object properties are changed or when painting is occure. It is privilege for owner of XCanvas object to set this event and it is used usually by master object which is keeping XCanvas object as readable property. It is not recommended to set this event for XCanvas objects, which are owned by another object and available as public property of this last. |
XCanvasManager = class( TObject );
XGraphicsManager events:
A single global variable GlobalCanvasManager : XCanvasManager is declared here. It is only used to keep these events above. These events are called by XCanvas objects. Thus, if add-on XRotateFonts.pas is included, it uses event OnTextArea to provide correct calculating of text output parameters for rotated fonts.