|
ItemView
By this time you may be asking your self, if the CoolControl
does not draw the items and the ICoolItem interface does not draw the
item, and the Grid does not draw the item, what draws the item? The
answer is the concept of an ICoolItemView. The Item View is again
accessed and set through the ManagerLink. What this concept allows is
the instantaneous switching of the user interface associated with the
item. The best example of this is using CoolContol as a Listview
clone with all of the many different views it has to offer. If the UI
was associated with the ICoolItem interface and its associated object
then every time the view was switched the all the items would need to
be destroyed and new objects created that implemented the correct UI.
The other choice would be to have all the views embedded into the
same ICooItem implementation. This is very restrictive since in the
next version of Windows a new view may be introduced. By separating
the UI from the actual Item the way an item is displayed can be
changed by simply assigning a new ICoolItemView to the ManagerLink
and invalidating the control.
Lets take a look at the interface and see what it entails.
First the Item Paint interface is similar to the Grid at the next
level. The Grid defines where the items will be positioned and the
Item Paint interface defines where the elements of the item UI are
defined. These elements include the Text, the Image, Borders, etc.

For this the interface defines a couple of methods.
|
function ItemRect(const Item: ICoolItem; RectType:
TCoolCellRectType; PaintInfo: ICoolItemPaintInfo): TRect;
procedure ItemRectArray(const Item: ICoolItem; PaintInfo:
ICoolItemPaintInfo; var RectArray: TCoolObjectRectArray); |
|
TCoolObjectRectArray = packed record
BoundsR, // The bounds of the item minus
the border
IconR, // The bounds of the icon image
LabelR, // The bounds of the area
dedicated to the text
// (will be static based on grid)
ClickSelectBoundsR, // The bounds of the
area dedicated to a click
// selection (may be possible the area
is not
// definable by a simple rectangle)
DragSelectBoundsR, // The bounds of the
area dedicated to a drag
// selection (may be possible the area
is not
// definable by a simple rectangle)
TextR, // The bounds of the text for the
item (will be
// dynamic based on current text)
SelectionR, // The bounds of the area
that is painted in the
// highlighted selection color
FocusTextR, // The bounds of the actual
text for the item (will
// be dynamic based on current text)
FullFocusTextR: TRect; // The bounds of
the largest rect of text that
// can be shown (Icon view when item has
focus the
// entire text is shown, overlapping
other items)
FocusChangeInvalidR: TRect; // The
Rectangle to invalidate if the item
// changes focus or selection
end; |
These methods are called when the CoolControl, or other
managers need to know the layout of the item. The defined elements are:
|
TCoolObjectRectArray = packed record
BoundsR, // The bounds of the item minus
the border
IconR, // The bounds of the icon image
LabelR, // The bounds of the area
dedicated to the text
// (will be static based on grid)
ClickSelectBoundsR, // The bounds of the
area dedicated to a click
// selection (may be possible the area
is not
// definable by a simple rectangle)
DragSelectBoundsR, // The bounds of the
area dedicated to a drag
// selection (may be possible the area
is not
// definable by a simple rectangle)
TextR, // The bounds of the text for the
item (will be
// dynamic based on current text)
SelectionR, // The bounds of the area
that is painted in the
// highlighted selection color
FocusTextR, // The bounds of the actual
text for the item (will
// be dynamic based on current text)
FullFocusTextR: TRect; // The bounds of
the largest rect of text that
// can be shown (Icon view when item has
focus the
// entire text is shown, overlapping
other items)
FocusChangeInvalidR: TRect; // The
Rectangle to invalidate if the item
// changes focus or selection
end; |
Next comes methods that handle the user callback
interface ICoolItemPaintInfo.
|
procedure FillPaintInfo(const Item: ICoolItem;
PaintInfo: ICoolItemPaintInfo);
procedure LoadDefaultInfo(const Item: ICoolItem;
PaintInfo: ICoolItemPaintInfo); |
The first method, LoadDefaultInfo, fills the PaintInfo with
defaults values for the particular instance of the object. The second
actually fires the callback for the application to modifiy or fill
based on the users data.
After the object has aquired the information from the
application to know how to present itself it is time to do the
drawing. The interface defines a number of methods to handle the
drawing of the item.
|
procedure Paint(const Item: ICoolItem; ACanvas:
TCanvas; PaintInfo: ICoolItemPaintInfo);
procedure PaintAfter(const Item: ICoolItem; ACanvas:
TCanvas; RectArray: TCoolObjectRectArray;
PaintInfo: ICoolItemPaintInfo);
procedure PaintBefore(const Item: ICoolItem; ACanvas:
TCanvas; RectArray: TCoolObjectRectArray;
PaintInfo: TCoolItemPaintInfo);
procedure PaintFocusRect(const Item: ICoolItem;
RectArray: TCoolObjectRectArray; ACanvas: TCanvas;
PaintInfo: TCoolItemPaintInfo);
procedure PaintImage(const Item: ICoolItem; RectArray: TCoolObjectRectArray;
ImageSize: TCoolImageSize; ACanvas: TCanvas; PaintInfo: ICoolItemPaintInfo);
function PaintImageSize(const Item: ICoolItem;
PaintInfo: ICoolItemPaintInfo): TCoolImageSize;
function PaintLineCount(const Item: ICoolItem;
PaintInfo: ICoolItemPaintInfo): Integer;
procedure PaintSelectionRect(const Item: ICoolItem;
RectArray: TCoolObjectRectArray;
ACanvas: TCanvas; PaintInfo: ICoolItemPaintInfo);
procedure PaintText(const Item: ICoolItem; RectArray: TCoolObjectRectArray;
ACanvas: TCanvas; PaintInfo: ICoolItemPaintInfo; LinesToDraw: Integer); |
The default implementation of ICoolItemView provides a core
set of painting services such as drawing the image, drawing the text,
and drawing the selection rectangle normally or alpha blended.
Some of these methods will handle the default drawing for you
in TCoolItemView, which is the base object that implements the
interface, while others are empty stubs that can be overriden.
Next the ItemView must be able to perform hit tests. These
tests are for mouse click activation as well as drag and drop, and
drag selection.
|
function PtInRect(const Item: ICoolItem; Pt: TPoint): Integer;
function SelectionHit(const Item: ICoolItem;
SelectRect: TRect;
SelectType: TCoolSelectHitType): Boolean;
function SelectionHitPt(const Item: ICoolItem;
ViewportPoint: TPoint;
SelectType: TCoolSelectHitType): Boolean; |
Lastly the object should be able to temporarily cache
some of the more important rectangles to improve performance during
drag operations
|
procedure CacheRectangle(const Item: ICoolItem;
ARectType: TCoolCellRectType;
var ARect: TRect; Operation: TCoolCacheDragRectOperation); |
CoolControl implements this interface with the
TCoolItemView object. Again you are free to use this implementation
of create an implementation of ICoolItemView from scratch. If
defining a new object or deriving a new object it is recommended that
as many of the options defined in the callback interface,
ICoolItemPaintInfo, be implemented as possible.
|