VrCalendar.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:19k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrCalendar;
  10. {$I VRLIB.INC}
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   VrTypes, VrClasses, VrControls, VrSysUtils;
  15. type
  16.   TVrGridStyle = (gsRaised, gsLowered, gsSingle);
  17.   TVrCalendarGrid = class(TVrPersistent)
  18.   private
  19.     FStyle: TVrGridStyle;
  20.     FColor: TColor;
  21.     FShadow3D: TColor;
  22.     FHighlight3D: TColor;
  23.     FWidth: Integer;
  24.     procedure SetStyle(Value: TVrGridStyle);
  25.     procedure SetColor(Value: TColor);
  26.     procedure SetShadow3D(Value: TColor);
  27.     procedure SetHighlight3D(Value: TColor);
  28.     procedure SetWidth(Value: Integer);
  29.   public
  30.     constructor Create;
  31.     procedure Assign(Source: TPersistent); override;
  32.   published
  33.     property Style: TVrGridStyle read FStyle write SetStyle;
  34.     property Color: TColor read FColor write SetColor;
  35.     property Highlight3D: TColor read FHighlight3D write SetHighlight3D;
  36.     property Shadow3D: TColor read FShadow3D write SetShadow3D;
  37.     property Width: Integer read FWidth write SetWidth;
  38.   end;
  39.   TVrCalendar = class;
  40.   TVrCalendarItem = class(TVrCollectionItem)
  41.   private
  42.     FCaption: string;
  43.     FActive: Boolean;
  44.     FVisible: Boolean;
  45.     procedure SetActive(Value: Boolean);
  46.     procedure SetCaption(const Value: string);
  47.     procedure SetVisible(Value: Boolean);
  48.   public
  49.     constructor Create(Collection: TVrCollection); override;
  50.     property Caption: string read FCaption write SetCaption;
  51.     property Active: Boolean read FActive write SetActive;
  52.     property Visible: Boolean read FVisible write SetVisible;
  53.   end;
  54.   TVrCalendarItems = class(TVrCollection)
  55.   private
  56.     FOwner: TVrCalendar;
  57.     function GetItem(Index: Integer): TVrCalendarItem;
  58.   protected
  59.     procedure Update(Item: TVrCollectionItem); override;
  60.     property Owner: TVrCalendar read FOwner;
  61.   public
  62.     constructor Create(AOwner: TVrCalendar);
  63.     property Items[Index: Integer]: TVrCalendarItem read GetItem;
  64.   end;
  65.   TVrCalendarDrawEvent = procedure(Sender: TObject; Canvas: TCanvas; Rect: TRect;
  66.     Index: Integer; State: Boolean) of object;
  67.   TVrGridAlignment =
  68.     (gaUpperLeft, gaUpperRight, gaBottomLeft, gaBottomRight, gaCenter);
  69.   TVrCalendarOption = (coActiveClick, coMouseClip, coTrackMouse);
  70.   TVrCalendarOptions = set of TVrCalendarOption;
  71.   TVrCalendar = class(TVrGraphicImageControl)
  72.   private
  73.     FRows: TVrRowInt;
  74.     FColumns: TVrColInt;
  75.     FGrid: TVrCalendarGrid;
  76.     FDrawStyle: TVrDrawStyle;
  77.     FAlignment: TVrGridAlignment;
  78.     FPalette: TVrPalette;
  79.     FFirstIndex: Integer;
  80.     FOnDraw: TVrCalendarDrawEvent;
  81.     FItemIndex: Integer;
  82.     FDigits: Integer;
  83.     FOptions: TVrCalendarOptions;
  84.     FOrientation: TVrOrientation;
  85.     FNextStep: Integer;
  86.     FBevel: TVrBevel;
  87.     ViewPort: TRect;
  88.     SizeX, SizeY: Integer;
  89.     IsPressed: Boolean;
  90.     TrackLast: Integer;
  91.     CurrIndex: Integer;
  92.     Collection: TVrCalendarItems;
  93.     procedure SetRows(Value: TVrRowInt);
  94.     procedure SetColumns(Value: TVrColInt);
  95.     procedure SetDrawStyle(Value: TVrDrawStyle);
  96.     procedure SetAlignment(Value: TVrGridAlignment);
  97.     procedure SetFirstIndex(Value: Integer);
  98.     procedure SetDigits(Value: Integer);
  99.     procedure SetOrientation(Value: TVrOrientation);
  100.     procedure SetNextStep(Value: Integer);
  101.     procedure SetOptions(Value: TVrCalendarOptions);
  102.     procedure SetPalette(Value: TVrPalette);
  103.     procedure SetBevel(Value: TVrBevel);
  104.     procedure SetGrid(Value: TVrCalendarGrid);
  105.     function GetCount: Integer;
  106.     function GetItem(Index: Integer): TVrCalendarItem;
  107.     procedure StyleChanged(Sender: TObject);
  108.     procedure BevelChanged(Sender: TObject);
  109.     procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  110.   protected
  111.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  112.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  113.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  114.     procedure CreateObjects;
  115.     procedure CalcPaintParams;
  116.     procedure UpdateItem(Index: Integer);
  117.     procedure UpdateItems;
  118.     procedure Paint; override;
  119.     procedure GetItemRect(Index: Integer; var R: TRect);
  120.     function GetItemIndex(X, Y: Integer): Integer;
  121.     procedure Loaded; override;
  122.     procedure Click; override;
  123.   public
  124.     constructor Create(AOwner: TComponent); override;
  125.     destructor Destroy; override;
  126.     procedure Reset;
  127.     property Count: Integer read GetCount;
  128.     property Items[Index: Integer]: TVrCalendarItem read GetItem;
  129.     property ItemIndex: Integer read FItemIndex;
  130.   published
  131.     property Palette: TVrPalette read FPalette write SetPalette;
  132.     property Rows: TVrRowInt read FRows write SetRows default 5;
  133.     property Columns: TVrColInt read FColumns write SetColumns default 5;
  134.     property Grid: TVrCalendarGrid read FGrid write SetGrid;
  135.     property DrawStyle: TVrDrawStyle read FDrawStyle write SetDrawStyle default dsNormal;
  136.     property Alignment: TVrGridAlignment read FAlignment write SetAlignment default gaCenter;
  137.     property FirstIndex: Integer read FFirstIndex write SetFirstIndex default 1;
  138.     property Digits: Integer read FDigits write SetDigits default 2;
  139.     property Options: TVrCalendarOptions read FOptions write SetOptions default [];
  140.     property NextStep: Integer read FNextStep write SetNextStep default 1;
  141.     property Orientation: TVrOrientation read FOrientation write SetOrientation default voHorizontal;
  142.     property Bevel: TVrBevel read FBevel write SetBevel;
  143.     property OnDraw: TVrCalendarDrawEvent read FOnDraw write FOnDraw;
  144. {$IFDEF VER110}
  145.     property Anchors;
  146.     property Constraints;
  147. {$ENDIF}
  148.     property Color default clBlack;
  149.     property Enabled;
  150.     property Font;
  151.     property Cursor;
  152.     property DragMode;
  153. {$IFDEF VER110}
  154.     property DragKind;
  155. {$ENDIF}
  156.     property DragCursor;
  157.     property ParentColor default false;
  158.     property ParentFont;
  159.     property ParentShowHint;
  160.     property ShowHint;
  161.     property Visible;
  162.     property OnClick;
  163. {$IFDEF VER130}
  164.     property OnContextPopup;
  165. {$ENDIF}    
  166.     property OnDblClick;
  167.     property OnMouseMove;
  168.     property OnMouseDown;
  169.     property OnMouseUp;
  170.     property OnDragOver;
  171. {$IFDEF VER110}
  172.     property OnEndDock;
  173. {$ENDIF}
  174.     property OnDragDrop;
  175.     property OnEndDrag;
  176. {$IFDEF VER110}
  177.     property OnStartDock;
  178. {$ENDIF}
  179.     property OnStartDrag;
  180.   end;
  181. implementation
  182. const
  183.   TextAlignments: array[TVrGridAlignment] of Integer = (
  184.     DT_LEFT or DT_TOP,
  185.     DT_RIGHT or DT_TOP,
  186.     DT_LEFT or DT_BOTTOM,
  187.     DT_RIGHT or DT_BOTTOM,
  188.     DT_VCENTER or DT_CENTER);
  189. { TVrCalendarGrid }
  190. constructor TVrCalendarGrid.Create;
  191. begin
  192.   inherited Create;
  193.   FStyle := gsLowered;
  194.   FColor := clLime;
  195.   FShadow3D := clBtnShadow;
  196.   FHighlight3D := clBtnHighlight;
  197.   FWidth := 1;
  198. end;
  199. procedure TVrCalendarGrid.Assign(Source: TPersistent);
  200. begin
  201.   if (Source <> nil) and (Source is TVrCalendarGrid) then
  202.   begin
  203.     BeginUpdate;
  204.     try
  205.       Style := TVrCalendarGrid(Source).Style;
  206.       Color := TVrCalendarGrid(Source).Color;
  207.       Shadow3D := TVrCalendarGrid(Source).Shadow3D;
  208.       Highlight3D := TVrCalendarGrid(Source).Highlight3D;
  209.       Width := TVrCalendarGrid(Source).Width;
  210.     finally
  211.       EndUpdate;
  212.     end;
  213.   end else inherited Assign(Source);
  214. end;
  215. procedure TVrCalendarGrid.SetStyle(Value: TVrGridStyle);
  216. begin
  217.   if FStyle <> Value then
  218.   begin
  219.     FStyle := Value;
  220.     Changed;
  221.   end;
  222. end;
  223. procedure TVrCalendarGrid.SetColor(Value: TColor);
  224. begin
  225.   if FColor <> Value then
  226.   begin
  227.     FColor := Value;
  228.     Changed;
  229.   end;
  230. end;
  231. procedure TVrCalendarGrid.SetShadow3D(Value: TColor);
  232. begin
  233.   if FShadow3D <> Value then
  234.   begin
  235.     FShadow3D := Value;
  236.     Changed;
  237.   end;
  238. end;
  239. procedure TVrCalendarGrid.SetHighlight3D(Value: TColor);
  240. begin
  241.   if FHighlight3D <> Value then
  242.   begin
  243.     FHighlight3D := Value;
  244.     Changed;
  245.   end;
  246. end;
  247. procedure TVrCalendarGrid.SetWidth(Value: Integer);
  248. begin
  249.   if FWidth <> Value then
  250.   begin
  251.     FWidth := Value;
  252.     Changed;
  253.   end;
  254. end;
  255. { TVrCalendarItem }
  256. constructor TVrCalendarItem.Create(Collection: TVrCollection);
  257. begin
  258.   inherited Create(Collection);
  259.   FActive := false;
  260.   FVisible := True;
  261.   with (Collection as TVrCalendarItems).Owner do
  262.     FCaption := Format('%.' + IntToStr(Digits) + 'd',
  263.       [FirstIndex + (Index * NextStep)]);
  264. end;
  265. procedure TVrCalendarItem.SetActive(Value: Boolean);
  266. begin
  267.   if FActive <> Value then
  268.   begin
  269.     FActive := Value;
  270.     Changed(false);
  271.   end;
  272. end;
  273. procedure TVrCalendarItem.SetCaption(const Value: string);
  274. begin
  275.   if FCaption <> Value then
  276.   begin
  277.     FCaption := Value;
  278.     Changed(false);
  279.   end;
  280. end;
  281. procedure TVrCalendarItem.SetVisible(Value: Boolean);
  282. begin
  283.   if FVisible <> Value then
  284.   begin
  285.     FVisible := Value;
  286.     Changed(false);
  287.   end;
  288. end;
  289. { TVrCalendarItems }
  290. constructor TVrCalendarItems.Create(AOwner: TVrCalendar);
  291. begin
  292.   inherited Create;
  293.   FOwner := AOwner;
  294. end;
  295. function TVrCalendarItems.GetItem(Index: Integer): TVrCalendarItem;
  296. begin
  297.   Result := TVrCalendarItem(inherited Items[Index]);
  298. end;
  299. procedure TVrCalendarItems.Update(Item: TVrCollectionItem);
  300. begin
  301.   if Item <> nil then
  302.     FOwner.UpdateItem(Item.Index) else
  303.     FOwner.UpdateItems;
  304. end;
  305. { TVrCalendar }
  306. constructor TVrCalendar.Create(AOwner: TComponent);
  307. begin
  308.   inherited Create(AOwner);
  309.   ControlStyle := ControlStyle + [csOpaque] - [csDoubleClicks];
  310.   Height := 145;
  311.   Width := 225;
  312.   Color := clBlack;
  313.   Font.Name := 'Arial';
  314.   Font.Size := 7;
  315.   FRows := 5;
  316.   FColumns := 5;
  317.   FDrawStyle := dsNormal;
  318.   FAlignment := gaCenter;
  319.   FDigits := 2;
  320.   FOrientation := voHorizontal;
  321.   FFirstIndex := 1;
  322.   FNextStep := 1;
  323.   FOptions := [];
  324.   FPalette := TVrPalette.Create;
  325.   FPalette.OnChange := StyleChanged;
  326.   FGrid := TVrCalendarGrid.Create;
  327.   FGrid.OnChange := StyleChanged;
  328.   FBevel := TVrBevel.Create;
  329.   with FBevel do
  330.   begin
  331.     InnerStyle := bsLowered;
  332.     InnerWidth := 2;
  333.     InnerSpace := 0;
  334.     InnerColor := clBlack;
  335.     OnChange := BevelChanged;
  336.   end;
  337.   TrackLast := -1;
  338.   Collection := TVrCalendarItems.Create(Self);
  339.   CreateObjects;
  340. end;
  341. destructor TVrCalendar.Destroy;
  342. begin
  343.   FPalette.Free;
  344.   FGrid.Free;
  345.   FBevel.Free;
  346.   Collection.Free;
  347.   inherited Destroy;
  348. end;
  349. procedure TVrCalendar.Loaded;
  350. begin
  351.   inherited Loaded;
  352.   SizeX := Width div FColumns;
  353.   SizeY := Height div FRows;
  354. end;
  355. procedure TVrCalendar.Click;
  356. begin
  357. end;
  358. procedure TVrCalendar.CreateObjects;
  359. var
  360.   I, Count: Integer;
  361. begin
  362.   Collection.Clear;
  363.   Count := FColumns * FRows;
  364.   for I := 0 to Pred(Count) do
  365.     TVrCalendarItem.Create(Collection);
  366.   FItemIndex := -1;
  367.   TrackLast := -1;
  368. end;
  369. function TVrCalendar.GetCount: Integer;
  370. begin
  371.   Result := Collection.Count;
  372. end;
  373. function TVrCalendar.GetItem(Index: Integer): TVrCalendarItem;
  374. begin
  375.   Result := Collection.Items[Index];
  376. end;
  377. procedure TVrCalendar.StyleChanged(Sender: TObject);
  378. begin
  379.   UpdateControlCanvas;
  380. end;
  381. procedure TVrCalendar.BevelChanged(Sender: TObject);
  382. var
  383.   R: TRect;
  384. begin
  385.   if not Loading then
  386.   begin
  387.     R := ClientRect;
  388.     FBevel.GetVisibleArea(R);
  389.     InflateRect(ViewPort, R.Left, R.Top);
  390.     BoundsRect := Bounds(Left, Top, WidthOf(ViewPort),
  391.       HeightOf(ViewPort));
  392.   end;
  393.   UpdateControlCanvas;
  394. end;
  395. procedure TVrCalendar.SetOptions(Value: TVrCalendarOptions);
  396. begin
  397.   FOptions := Value;
  398. end;
  399. procedure TVrCalendar.UpdateItem(Index: Integer);
  400. var
  401.   Rect: TRect;
  402.   Item: TVrCalendarItem;
  403.   State: Boolean;
  404. begin
  405.   Item := Collection.Items[Index];
  406.   GetItemRect(Index, Rect);
  407.   with DestCanvas do
  408.     case FGrid.Style of
  409.       gsLowered:
  410.           DrawFrame3D(DestCanvas, Rect, FGrid.Shadow3D, FGrid.Highlight3D, FGrid.Width);
  411.         gsRaised:
  412.           DrawFrame3D(DestCanvas, Rect, FGrid.Highlight3D, FGrid.Shadow3D, FGrid.Width);
  413.         gsSingle:
  414.           begin
  415.             if FOrientation = voHorizontal then
  416.             begin
  417.               if (Index mod FColumns <> FColumns - 1) then Inc(Rect.Right);
  418.               if Index < Count - FColumns then Inc(Rect.Bottom);
  419.             end
  420.             else
  421.             begin
  422.               if (Index mod FRows <> FRows - 1) then Inc(Rect.Bottom);
  423.               if Index < Count - FRows then Inc(Rect.Right);
  424.             end;
  425.             DrawFrame3D(DestCanvas, Rect, FGrid.Color, FGrid.Color, FGrid.Width);
  426.           end;
  427.     end; //case
  428.   State := (TrackLast = Index) or Item.Active;
  429.   if FDrawStyle = dsOwnerDraw then
  430.   begin
  431.     if Assigned(FOnDraw) then
  432.       FOnDraw(Self, DestCanvas, Rect, Index, State);
  433.     Exit;
  434.   end;
  435.   if Item.Visible then
  436.     with DestCanvas do
  437.     begin
  438.       Font := Self.Font;
  439.       Font.Color := FPalette.Colors[ord(State)];
  440.       Brush.Color := Self.Color;
  441.       DrawText(handle, PChar(Item.Caption), -1, Rect,
  442.         DT_SINGLELINE or DT_EXPANDTABS or TextAlignments[FAlignment]);
  443.     end;
  444. end;
  445. procedure TVrCalendar.UpdateItems;
  446. var
  447.   I: Integer;
  448. begin
  449.   for I := 0 to Collection.Count - 1 do
  450.     UpdateItem(I);
  451. end;
  452. procedure TVrCalendar.Reset;
  453. var
  454.   I: Integer;
  455. begin
  456.   for I := 0 to Collection.Count - 1 do
  457.     Items[I].Active := false;
  458. end;
  459. procedure TVrCalendar.Paint;
  460. var
  461.   R: TRect;
  462. begin
  463.   CalcPaintParams;
  464.   ClearBitmapCanvas;
  465.   DestCanvas := BitmapCanvas;
  466.   try
  467.     R := ClientRect;
  468.     FBevel.Paint(DestCanvas, R);
  469.     UpdateItems;
  470.     inherited Paint;
  471.   finally
  472.     DestCanvas := Self.Canvas;
  473.   end;
  474. end;
  475. procedure TVrCalendar.CalcPaintParams;
  476. var
  477.   NewWidth, NewHeight, X, Y: Integer;
  478. begin
  479.   ViewPort := ClientRect;
  480.   FBevel.GetVisibleArea(ViewPort);
  481.   X := WidthOf(ViewPort) div FColumns;
  482.   NewWidth := (ViewPort.Left * 2) + (FColumns * X);
  483.   Y := HeightOf(ViewPort) div FRows;
  484.   NewHeight := (ViewPort.Top * 2) + (FRows * Y);
  485.   if (NewWidth <> Width) or (NewHeight <> Height) then
  486.     BoundsRect := Bounds(Left, Top, NewWidth, NewHeight);
  487.   SizeX := WidthOf(ViewPort) div FColumns;
  488.   SizeY := HeightOf(ViewPort) div FRows;
  489. end;
  490. procedure TVrCalendar.GetItemRect(Index: Integer; var R: TRect);
  491. var
  492.   X, Y: Integer;
  493. begin
  494.   if FOrientation = voHorizontal then
  495.   begin
  496.     X := (Index mod FColumns) * SizeX;
  497.     Y := (Index div FColumns) * SizeY;
  498.   end
  499.   else
  500.   begin
  501.     X := (Index div FRows) * SizeX;
  502.     Y := (Index mod FRows) * SizeY;
  503.   end;
  504.   R := Bounds(ViewPort.Left + X, ViewPort.Top + Y, SizeX, SizeY);
  505. end;
  506. function TVrCalendar.GetItemIndex(X, Y: Integer): Integer;
  507. begin
  508.   if X > ViewPort.Right then X := ViewPort.Right
  509.   else if X < ViewPort.Left then X := ViewPort.Left;
  510.   if Y > ViewPort.Bottom then Y := ViewPort.Bottom
  511.   else if Y < ViewPort.Top then Y := ViewPort.Top;
  512.   if Orientation = voHorizontal then
  513.   begin
  514.     X := ((Y - ViewPort.Top) div SizeY) * FColumns +
  515.          ((X - ViewPort.Left) div SizeX);
  516.     Result := X;
  517.   end
  518.   else
  519.   begin
  520.     Y := ((X - ViewPort.Left) div SizeX) * FRows +
  521.          ((Y - ViewPort.Top) div SizeY);
  522.     Result := Y;
  523.   end;
  524. end;
  525. procedure TVrCalendar.SetRows(Value: TVrRowInt);
  526. begin
  527.   if FRows <> Value then
  528.   begin
  529.     FRows := Value;
  530.     CreateObjects;
  531.     UpdateControlCanvas;
  532.   end;
  533. end;
  534. procedure TVrCalendar.SetColumns(Value: TVrColInt);
  535. begin
  536.   if FColumns <> Value then
  537.   begin
  538.     FColumns := Value;
  539.     CreateObjects;
  540.     UpdateControlCanvas;
  541.   end;
  542. end;
  543. procedure TVrCalendar.SetOrientation(Value: TVrOrientation);
  544. begin
  545.   if FOrientation <> Value then
  546.   begin
  547.     FOrientation := Value;
  548.     UpdateControlCanvas;
  549.   end;
  550. end;
  551. procedure TVrCalendar.SetDrawStyle(Value: TVrDrawStyle);
  552. begin
  553.   if FDrawStyle <> Value then
  554.   begin
  555.     FDrawStyle := Value;
  556.     UpdateControlCanvas;
  557.   end;
  558. end;
  559. procedure TVrCalendar.SetFirstIndex(Value: Integer);
  560. begin
  561.   if FFirstIndex <> Value then
  562.   begin
  563.     FFirstIndex := Value;
  564.     CreateObjects;
  565.     UpdateControlCanvas;
  566.   end;
  567. end;
  568. procedure TVrCalendar.SetDigits(Value: Integer);
  569. begin
  570.   if FDigits <> Value then
  571.   begin
  572.     FDigits := Value;
  573.     CreateObjects;
  574.     UpdateControlCanvas;
  575.   end;
  576. end;
  577. procedure TVrCalendar.SetAlignment(Value: TVrGridAlignment);
  578. begin
  579.   if FAlignment <> Value then
  580.   begin
  581.     FAlignment := Value;
  582.     UpdateControlCanvas;
  583.   end;
  584. end;
  585. procedure TVrCalendar.SetNextStep(Value: Integer);
  586. begin
  587.   if FNextStep <> Value then
  588.   begin
  589.     FNextStep := Value;
  590.     CreateObjects;
  591.     UpdateControlCanvas;
  592.   end;
  593. end;
  594. procedure TVrCalendar.SetPalette(Value: TVrPalette);
  595. begin
  596.   FPalette.Assign(Value);
  597. end;
  598. procedure TVrCalendar.SetBevel(Value: TVrBevel);
  599. begin
  600.   FBevel.Assign(Value);
  601. end;
  602. procedure TVrCalendar.SetGrid(Value: TVrCalendarGrid);
  603. begin
  604.   FGrid.Assign(Value);
  605. end;
  606. procedure TVrCalendar.MouseMove(Shift: TShiftState; X, Y: Integer);
  607. var
  608.   Index, P: Integer;
  609. begin
  610.   inherited;
  611.   if not PtInRect(ViewPort, Point(X, Y)) then
  612.     if (coTrackMouse in Options) and Enabled then
  613.     begin
  614.       if TrackLast <> -1 then
  615.       begin
  616.         P := TrackLast;
  617.         TrackLast := -1;
  618.         UpdateItem(P);
  619.       end;
  620.       Exit;
  621.     end;
  622.   if (coTrackMouse in Options) and Enabled then
  623.   begin
  624.     Index := GetItemIndex(X, Y);
  625.     if (TrackLast <> Index) then
  626.     begin
  627.       if TrackLast <> -1 then
  628.       begin
  629.         P := TrackLast;
  630.         TrackLast := -1;
  631.         UpdateItem(P);
  632.       end;
  633.       TrackLast := Index;
  634.       UpdateItem(TrackLast);
  635.     end;
  636.   end;
  637. end;
  638. procedure TVrCalendar.MouseDown(Button: TMouseButton;
  639.   Shift: TShiftState; X, Y: Integer);
  640. var
  641.   R: TRect;
  642. begin
  643.   if PtInRect(ViewPort, Point(X, Y)) then
  644.     if (Button = mbLeft) and Enabled then
  645.     begin
  646.       IsPressed := True;
  647.       CurrIndex := GetItemIndex(X, Y);
  648.       FItemIndex := -1;
  649.       if (coMouseClip in Options) then
  650.       begin
  651.         R := Bounds(ClientOrigin.X, ClientOrigin.Y,
  652.           ClientWidth, ClientHeight);
  653.         ClipCursor(@R);
  654.       end;
  655.     end;
  656.   inherited;
  657. end;
  658. procedure TVrCalendar.MouseUp(Button: TMouseButton;
  659.   Shift: TShiftState; X, Y: Integer);
  660. begin
  661.   if IsPressed then
  662.   begin
  663.     IsPressed := false;
  664.     if (coMouseClip in Options) then ClipCursor(nil);
  665.     FItemIndex := GetItemIndex(X, Y);
  666.     if CurrIndex <> FItemIndex then FItemIndex := -1
  667.     else
  668.     begin
  669.       if (coActiveClick in Options) then
  670.         Items[FItemIndex].Active := True;
  671.       inherited Click;
  672.     end;
  673.   end;
  674.   inherited;
  675. end;
  676. procedure TVrCalendar.CMMouseLeave(var Message: TMessage);
  677. var
  678.   P: Integer;
  679. begin
  680.   inherited;
  681.   if (coTrackMouse in Options) and Enabled then
  682.   begin
  683.     if TrackLast <> -1 then
  684.     begin
  685.       P := TrackLast;
  686.       TrackLast := -1;
  687.       UpdateItem(P);
  688.     end;
  689.   end;
  690. end;
  691. end.