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

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrTrackBar;
  10. {$I VRLIB.INC}
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  14.   VrConst, VrTypes, VrClasses, VrControls, VrSysUtils, VrSystem;
  15. type
  16.   TVrTrackBarOption = (toActiveClick, toMouseClip, toHandPoint,
  17.     toFixedPoints, toThumbOpaque);
  18.   TVrTrackBarOptions = set of TVrTrackBarOption;
  19.   TVrTrackBar = class(TVrCustomImageControl)
  20.   private
  21.     FMinValue: Integer;
  22.     FMaxValue: Integer;
  23.     FPosition: Integer;
  24.     FStyle: TVrProgressStyle;
  25.     FOrientation: TVrOrientation;
  26.     FOptions: TVrTrackBarOptions;
  27.     FFrequency: Integer;
  28.     FBorderWidth: Integer;
  29.     FGutterBevel: TVrBevel;
  30.     FGutterWidth: Integer;
  31.     FGutterColor: TColor;
  32.     FTickMarks: TVrTickMarks;
  33.     FTickColor: TColor;
  34.     FScaleOffset: Integer;
  35.     FFocusColor: TColor;
  36.     FFocusOffset: Integer;
  37.     FBackImageIndex: Integer;
  38.     FThumbImageIndex: Integer;
  39.     FBitmapList: TVrBitmapList;
  40.     FBitmapListLink: TVrChangeLink;
  41.     FOnChange: TNotifyEvent;
  42.     FHit: Integer;
  43.     FClipOn: Boolean;
  44.     FFocused: Boolean;
  45.     FThumbRect: TRect;
  46.     FThumbWidth: Integer;
  47.     FThumbHeight: Integer;
  48.     FThumbImage: TBitmap;
  49.     FThumbDown: Boolean;
  50.     FThumbHasMouse: Boolean;
  51.     FThumbStates: TVrNumGlyphs;
  52.     procedure SetMinValue(Value: Integer);
  53.     procedure SetMaxValue(Value: Integer);
  54.     procedure SetPosition(Value: Integer);
  55.     procedure SetStyle(Value: TVrProgressStyle);
  56.     procedure SetOrientation(Value: TVrOrientation);
  57.     procedure SetOptions(Value: TVrTrackBarOptions);
  58.     procedure SetFrequency(Value: Integer);
  59.     procedure SetBorderWidth(Value: Integer);
  60.     procedure SetGutterWidth(Value: Integer);
  61.     procedure SetGutterColor(Value: TColor);
  62.     procedure SetGutterBevel(Value: TVrBevel);
  63.     procedure SetTickMarks(Value: TVrTickMarks);
  64.     procedure SetTickColor(Value: TColor);
  65.     procedure SetScaleOffset(Value: Integer);
  66.     procedure SetThumbStates(Value: TVrNumGlyphs);
  67.     procedure SetFocusColor(Value: TColor);
  68.     procedure SetFocusOffset(Value: Integer);
  69.     procedure SetBackImageIndex(Value: Integer);
  70.     procedure SetThumbImageIndex(Value: Integer);
  71.     procedure SetBitmapList(Value: TVrBitmapList);
  72.     procedure DrawScale(Canvas: TCanvas; Offset, ThumbOffset,
  73.       RulerLength, PointsStep, PointsHeight, ExtremePointsHeight: Integer);
  74.     procedure GutterBevelChanged(Sender: TObject);
  75.     procedure BitmapListChanged(Sender: TObject);
  76.     procedure WMSize(var Message: TWMSize); message WM_SIZE;
  77.     procedure WMSetCursor(var Message: TWMSetCursor); message WM_SETCURSOR;
  78.     procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
  79.     procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
  80.     procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  81.   protected
  82.     procedure CreateParams(var Params: TCreateParams); override;
  83.     procedure GetThumbImage;
  84.     procedure SetThumbTop(ATop: Integer);
  85.     procedure SetThumbLeft(ALeft: Integer);
  86.     procedure CenterThumb;
  87.     procedure Paint; override;
  88.     procedure PaintThumb;
  89.     procedure Change; dynamic;
  90.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  91.     function GetViewWidth: Integer;
  92.     function GetOffsetByValue(Value: Integer): Integer;
  93.     function GetValueByOffset(Offset: Integer): Integer;
  94.     function GetBitmap(Index: Integer): TBitmap;
  95.     function GetSliderRect: TRect;
  96.     function GetMinIndent(Rect: TRect): Integer;
  97.     procedure SetThumbOffset(Value: Integer);
  98.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  99.     procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  100.     procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  101.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  102.   public
  103.     constructor Create(AOwner: TComponent); override;
  104.     destructor Destroy; override;
  105.   published
  106.     property MaxValue: Integer read FMaxValue write SetMaxValue default 100;
  107.     property MinValue: Integer read FMinValue write SetMinValue default 0;
  108.     property Position: Integer read FPosition write SetPosition default 0;
  109.     property Orientation: TVrOrientation read FOrientation write SetOrientation default voHorizontal;
  110.     property Style: TVrProgressStyle read FStyle write SetStyle default psBottomLeft;
  111.     property Options: TVrTrackBarOptions read FOptions write SetOptions
  112.       default [toActiveClick, toMouseClip, toHandPoint, toThumbOpaque];
  113.     property Frequency: Integer read FFrequency write SetFrequency default 10;
  114.     property BorderWidth: Integer read FBorderWidth write SetBorderWidth default 10;
  115.     property GutterBevel: TVrBevel read FGutterBevel write SetGutterBevel;
  116.     property GutterWidth: Integer read FGutterWidth write SetGutterWidth default 9;
  117.     property GutterColor: TColor read FGutterColor write SetGutterColor default clBlack;
  118.     property TickMarks: TVrTickMarks read FTickMarks write SetTickMarks default tmBoth;
  119.     property TickColor: TColor read FTickColor write SetTickColor default clBlack;
  120.     property ThumbStates: TVrNumGlyphs read FThumbStates write SetThumbStates default 1;
  121.     property BackImageIndex: Integer read FBackImageIndex write SetBackImageIndex default -1;
  122.     property ThumbImageIndex: Integer read FThumbImageIndex write SetThumbImageIndex default -1;
  123.     property BitmapList: TVrBitmapList read FBitmapList write SetBitmapList;
  124.     property ScaleOffset: Integer read FScaleOffset write SetScaleOffset default 5;
  125.     property FocusColor: TColor read FFocusColor write SetFocusColor default clBlack;
  126.     property FocusOffset: Integer read FFocusOffset write SetFocusOffset default 0;
  127.     property OnChange: TNotifyEvent read FOnChange write FOnChange;
  128.     property Align;
  129. {$IFDEF VER110}
  130.     property Anchors;
  131.     property Constraints;
  132. {$ENDIF}
  133.     property Enabled;
  134.     property Color;
  135.     property Cursor;
  136.     property DragMode;
  137. {$IFDEF VER110}
  138.     property DragKind;
  139. {$ENDIF}
  140.     property DragCursor;
  141.     property ParentColor;
  142.     property ParentShowHint;
  143.     property ShowHint;
  144.     property TabOrder;
  145.     property TabStop default false;
  146.     property Visible;
  147.     property OnClick;
  148. {$IFDEF VER130}
  149.     property OnContextPopup;
  150. {$ENDIF}
  151.     property OnEnter;
  152.     property OnExit;
  153.     property OnMouseMove;
  154.     property OnMouseDown;
  155.     property OnMouseUp;
  156.     property OnKeyDown;
  157.     property OnKeyUp;
  158.     property OnKeyPress;
  159.     property OnDragOver;
  160. {$IFDEF VER110}
  161.     property OnEndDock;
  162. {$ENDIF}
  163.     property OnDragDrop;
  164.     property OnEndDrag;
  165. {$IFDEF VER110}
  166.     property OnStartDock;
  167. {$ENDIF}
  168.     property OnStartDrag;
  169.   end;
  170. implementation
  171. {$R VRTRACKBAR.D32}
  172. const
  173.   ThumbNames: array[0..1] of PChar =
  174.     ('VRTB_VERT', 'VRTB_HORI');
  175. { TVrTrackBar }
  176. constructor TVrTrackBar.Create(AOwner: TComponent);
  177. begin
  178.   inherited Create(AOwner);
  179.   ControlStyle := ControlStyle + [csOpaque];
  180.   Width := 175;
  181.   Height := 45;
  182.   TabStop := false;
  183.   FMinValue := 0;
  184.   FMaxValue := 100;
  185.   FPosition := 0;
  186.   FStyle := psBottomLeft;
  187.   FOrientation := voHorizontal;
  188.   FOptions := [toActiveClick, toMouseClip, toHandPoint, ToThumbOpaque];
  189.   FFrequency := 10;
  190.   FBorderWidth := 10;
  191.   FTickMarks := tmBoth;
  192.   FTickColor := clBlack;
  193.   FScaleOffset := 5;
  194.   FFocusColor := clBlack;
  195.   FFocusOffset := 0;
  196.   FGutterWidth := 9;
  197.   FGutterColor := clBlack;
  198.   FGutterBevel := TVrBevel.Create;
  199.   with FGutterBevel do
  200.   begin
  201.     InnerStyle := bsNone;
  202.     InnerSpace := 0;
  203.     InnerOutline := osNone;
  204.     OuterStyle := bsLowered;
  205.     OuterSpace := 0;
  206.     OuterOutline := osNone;
  207.     OnChange := GutterBevelChanged;
  208.   end;
  209.   FBackImageIndex := -1;
  210.   FThumbImageIndex := -1;
  211.   FBitmapListLink := TVrChangeLink.Create;
  212.   FBitmapListLink.OnChange := BitmapListChanged;
  213.   FThumbImage := TBitmap.Create;
  214.   FThumbStates := 1;
  215.   GetThumbImage;
  216. end;
  217. destructor TVrTrackBar.Destroy;
  218. begin
  219.   FThumbImage.Free;
  220.   FGutterBevel.Free;
  221.   FBitmapListLink.Free;
  222.   inherited Destroy;
  223. end;
  224. procedure TVrTrackBar.CreateParams(var Params: TCreateParams);
  225. begin
  226.   inherited CreateParams(Params);
  227.   with Params do
  228.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  229. end;
  230. procedure TVrTrackBar.GetThumbImage;
  231. begin
  232.   FThumbImage.Assign(GetBitmap(FThumbImageIndex));
  233.   if FThumbImage.Empty then
  234.   begin
  235.     if Orientation = voVertical then
  236.     FThumbImage.LoadFromResourceName(hInstance, ThumbNames[0])
  237.     else FThumbImage.LoadFromResourceName(hInstance, ThumbNames[1]);
  238.   end;
  239.   FThumbHeight := FThumbImage.Height;
  240.   FThumbWidth := FThumbImage.Width div ThumbStates;
  241.   CenterThumb;
  242. end;
  243. function TVrTrackBar.GetBitmap(Index: Integer): TBitmap;
  244. begin
  245.   Result := nil;
  246.   if Assigned(FBitmapList) then
  247.     Result := FBitmapList.GetBitmap(Index);
  248. end;
  249. procedure TVrTrackBar.SetThumbLeft(ALeft: Integer);
  250. begin
  251.   FThumbRect := Bounds(ALeft, FThumbRect.Top, FThumbWidth, FThumbHeight);
  252. end;
  253. procedure TVrTrackBar.SetThumbTop(ATop: Integer);
  254. begin
  255.   FThumbRect := Bounds(FThumbRect.Left, ATop, FThumbWidth, FThumbHeight);
  256. end;
  257. procedure TVrTrackBar.CenterThumb;
  258. begin
  259.   if Orientation = voVertical then
  260.     SetThumbLeft((Width - FThumbWidth) div 2)
  261.   else SetThumbTop((Height - FThumbHeight) div 2);
  262. end;
  263. function TVrTrackBar.GetSliderRect: TRect;
  264. begin
  265.   Result := ClientRect;
  266.   InflateRect(Result, -BorderWidth, -BorderWidth);
  267. end;
  268. function TVrTrackBar.GetMinIndent(Rect: TRect): Integer;
  269. begin
  270.   if Orientation = voVertical then
  271.     Result := MaxIntVal(0, Rect.Top)
  272.   else
  273.     Result := MaxIntVal(0, Rect.Left);
  274. end;
  275. function TVrTrackBar.GetViewWidth: Integer;
  276. var
  277.   R: TRect;
  278. begin
  279.   R := GetSliderRect;
  280.   if Orientation = voVertical then
  281.   Result := HeightOf(R) - FThumbHeight
  282.   else Result := WidthOf(R) - FThumbWidth;
  283. end;
  284. function TVrTrackBar.GetOffsetByValue(Value: Integer): Integer;
  285. var
  286.   Range: Double;
  287.   R: TRect;
  288.   MinIndent: Integer;
  289. begin
  290.   R := GetSliderRect;
  291.   MinIndent := GetMinIndent(R);
  292.   Range := MaxValue - MinValue;
  293.   Result := Round((Value - MinValue) / Range * GetViewWidth) + MinIndent;
  294.   if (FOrientation = voVertical) and (FStyle = psBottomLeft) then
  295.     Result := R.Top + R.Bottom - Result - FThumbHeight
  296.   else
  297.   if (FOrientation = voHorizontal) and (FStyle = psTopRight) then
  298.     Result := R.Left + R.Right - Result - FThumbWidth;
  299. end;
  300. function TVrTrackBar.GetValueByOffset(Offset: Integer): Integer;
  301. var
  302.   R: TRect;
  303.   Range: Double;
  304.   MinIndent: Integer;
  305. begin
  306.   R := GetSliderRect;
  307.   MinIndent := GetMinIndent(R);
  308.   if Orientation = voVertical then
  309.     Offset := ClientHeight - Offset - FThumbHeight;
  310.   Range := FMaxValue - FMinValue;
  311.   Result := Round((Offset - MinIndent) * Range / GetViewWidth);
  312.   if (toFixedPoints in Options) then
  313.     Result := Round(Result / Frequency) * Frequency;
  314.   Result := MinIntVal(FMinValue + MaxIntVal(Result, 0), FMaxValue);
  315. end;
  316. procedure TVrTrackBar.SetThumbOffset(Value: Integer);
  317. var
  318.   R: TRect;
  319.   MinIndent: Integer;
  320. begin
  321.   R := GetSliderRect;
  322.   MinIndent := GetMinIndent(R);
  323.   Value := MinIntVal(MaxIntVal(Value, MinIndent),
  324.     MinIndent + GetViewWidth);
  325.   if (toFixedPoints in Options) then
  326.   begin
  327.     if FStyle = psBottomLeft then Value := GetValueByOffset(Value)
  328.     else Value := FMaxValue - GetValueByOffset(Value) + FMinValue;
  329.     Value := MinIntVal(GetOffsetByValue(Value), GetViewWidth);
  330.   end;
  331.   if FStyle = psBottomLeft then Position := GetValueByOffset(Value)
  332.   else Position := FMaxValue - GetValueByOffset(Value) + FMinValue;
  333. end;
  334. procedure TVrTrackBar.Paint;
  335. var
  336.   R: TRect;
  337.   Bmp: TBitmap;
  338.   Offset, Value: Integer;
  339. begin
  340.   with BitmapImage, BitmapCanvas do
  341.   begin
  342.     Bmp := GetBitmap(BackImageIndex);
  343.     if Bmp = nil then
  344.     begin
  345.       Brush.Color := Self.Color;
  346.       FillRect(ClientRect);
  347.     end else StretchDraw(ClientRect, Bmp);
  348.     Pen.Color := TickColor;
  349.     case Orientation of
  350.       voVertical:
  351.         begin
  352.           Offset := (ClientWidth - FGutterWidth) div 2;
  353.           R := Bounds(Offset, BorderWidth, GutterWidth,
  354.             ClientHeight - FBorderWidth * 2);
  355.           if (FTickMarks in [tmBoth, tmTopLeft]) then
  356.             DrawScale(BitmapCanvas, R.Left - FScaleOffset, FThumbHeight div 2,
  357.                       GetViewWidth, Frequency, -3, -4);
  358.           if (FTickMarks in [tmBoth, tmBottomRight]) then
  359.             DrawScale(BitmapCanvas, R.Right + FScaleOffset, FThumbHeight div 2,
  360.                       GetViewWidth, Frequency, 3, 4);
  361.         end;
  362.       voHorizontal:
  363.         begin
  364.           Offset := (ClientHeight - FGutterWidth) div 2;
  365.           R := Bounds(BorderWidth, Offset,
  366.             ClientWidth - FBorderWidth * 2, GutterWidth);
  367.           if (FTickMarks in [tmBoth, tmTopLeft]) then
  368.             DrawScale(BitmapCanvas, R.Top - FScaleOffset, FThumbWidth div 2,
  369.                       GetViewWidth, Frequency, -3, -4);
  370.           if (FTickMarks in [tmBoth, tmBottomRight]) then
  371.             DrawScale(BitmapCanvas, R.Bottom + FScaleOffset, FThumbWidth div 2,
  372.                       GetViewWidth, Frequency, 3, 4);
  373.         end;
  374.     end;
  375.     if GutterBevel.Visible then
  376.     begin
  377.       GutterBevel.Paint(BitmapCanvas, R);
  378.       Brush.Color := GutterColor;
  379.       FillRect(R);
  380.     end;
  381.     if (Focused) and (FocusOffset > -1) then
  382.     begin
  383.       R := ClientRect;
  384.       InflateRect(R, -FocusOffset, -FocusOffset);
  385.       Brush.Color := FocusColor;
  386.       FrameRect(R);
  387.     end;
  388.   end; { Bitmap, BitmapCanvas }
  389.   Value := GetOffsetByValue(Position);
  390.   if Orientation = voVertical then
  391.     SetThumbTop(Value) else SetThumbLeft(Value);
  392.   PaintThumb;
  393.   inherited Paint;
  394. end;
  395. procedure TVrTrackBar.PaintThumb;
  396. var
  397.   Index: Integer;
  398.   SrcRect: TRect;
  399.   TransColor: TColor;
  400. begin
  401.   Index := 0;
  402.   if not Enabled then Index := 1;
  403.   if FThumbDown then Index := 2;
  404.   if (FThumbHasMouse) and (not FThumbDown) then Index := 3;
  405.   if Index > ThumbStates - 1 then Index := 0;
  406.   SrcRect := Bounds(Index * FThumbWidth, 0, FThumbWidth, FThumbHeight);
  407.   with BitmapCanvas do
  408.   begin
  409.     TransColor := FThumbImage.TransparentColor;
  410.     Brush.Color := TransColor;
  411.     if toThumbOpaque in Options then Brush.Style := bsSolid
  412.     else Brush.Style := bsClear;
  413.     BrushCopy(FThumbRect, FThumbImage, SrcRect, TransColor);
  414.   end;
  415. end;
  416. procedure TVrTrackBar.DrawScale(Canvas: TCanvas; Offset, ThumbOffset,
  417.   RulerLength, PointsStep, PointsHeight, ExtremePointsHeight: Integer);
  418. const
  419.   MinInterval = 3;
  420. var
  421.   Interval, Scale, Cnt, I, Value: Integer;
  422.   X, H, X1, X2, Y1, Y2, Tmp: Integer;
  423.   Range: Double;
  424. begin
  425.   Scale := 0;
  426.   Range := FMaxValue - FMinValue;
  427.   repeat
  428.     Inc(Scale);
  429.     Cnt := Round(Range / (Scale * PointsStep)) + 1;
  430.     if Cnt > 1 then
  431.       Interval := RulerLength div (Cnt - 1)
  432.     else Interval := RulerLength;
  433.   until (Interval >= MinInterval + 1) or (Interval >= RulerLength);
  434.   Value := FMinValue;
  435.   for I := 1 to Cnt do
  436.   begin
  437.     H := PointsHeight;
  438.     if I = Cnt then Value := FMaxValue;
  439.     if (Value = FMaxValue) or (Value = FMinValue) then H := ExtremePointsHeight;
  440.     X := GetOffsetByValue(Value);
  441.     if Orientation = voHorizontal then
  442.     begin
  443.       X1 := X + ThumbOffset;
  444.       Y1 := Offset;
  445.       X2 := X1;
  446.       Y2 := Y1 + H;
  447.       if Y1 > Y2 then
  448.       begin
  449.         Tmp := Y1;
  450.         Y1 := Y2;
  451.         Y2 := Tmp;
  452.       end;
  453.     end
  454.     else
  455.     begin
  456.       X1 := Offset;
  457.       Y1 := X + ThumbOffset;
  458.       X2 := X1 + H;
  459.       Y2 := Y1;
  460.       if X1 > X2 then
  461.       begin
  462.         Tmp := X1;
  463.         X1 := X2;
  464.         X2 := Tmp;
  465.       end;
  466.     end;
  467.     Canvas.MoveTo(X1, Y1);
  468.     Canvas.LineTo(X2, Y2);
  469.     Inc(Value, Scale * PointsStep);
  470.   end;
  471. end;
  472. procedure TVrTrackBar.WMSize(var Message: TWMSize);
  473. begin
  474.   inherited;
  475.   CenterThumb;
  476.   UpdateControlCanvas;
  477. end;
  478. procedure TVrTrackBar.WMSetCursor(var Message: TWMSetCursor);
  479. var
  480.   P: TPoint;
  481. begin
  482.   GetCursorPos(P);
  483.   if (not Designing) and PtInRect(FThumbRect, ScreenToClient(P)) then
  484.   begin
  485.     if (toHandPoint in Options) then
  486.       Windows.SetCursor(Screen.Cursors[VrCursorHandPoint]);
  487.   end else inherited;
  488. end;
  489. procedure TVrTrackBar.WMGetDlgCode(var Msg: TWMGetDlgCode);
  490. begin
  491.   Msg.Result := DLGC_WANTARROWS;
  492. end;
  493. procedure TVrTrackBar.CMFocusChanged(var Message: TCMFocusChanged);
  494. var
  495.   Active: Boolean;
  496. begin
  497.   with Message do Active := (Sender = Self);
  498.   if Active <> FFocused then
  499.   begin
  500.     FFocused := Active;
  501.     UpdateControlCanvas;
  502.   end;
  503.   inherited;
  504. end;
  505. procedure TVrTrackBar.CMEnabledChanged(var Message: TMessage);
  506. begin
  507.   inherited;
  508.   UpdateControlCanvas;
  509. end;
  510. procedure TVrTrackBar.Change;
  511. begin
  512.   if Assigned(FOnChange) then FOnChange(Self);
  513. end;
  514. procedure TVrTrackBar.GutterBevelChanged(Sender: TObject);
  515. begin
  516.   UpdateControlCanvas;
  517. end;
  518. procedure TVrTrackBar.Notification(AComponent: TComponent;
  519.   Operation: TOperation);
  520. begin
  521.   inherited Notification(AComponent, Operation);
  522.   if (Operation = opRemove) then
  523.     if AComponent = BitmapList then BitmapList := nil;
  524. end;
  525. procedure TVrTrackBar.BitmapListChanged(Sender: TObject);
  526. begin
  527.   GetThumbImage;
  528.   UpdateControlCanvas;
  529. end;
  530. procedure TVrTrackBar.SetBackImageIndex(Value: Integer);
  531. begin
  532.   if FBackImageIndex <> Value then
  533.   begin
  534.     FBackImageIndex := Value;
  535.     UpdateControlCanvas;
  536.   end;
  537. end;
  538. procedure TVrTrackBar.SetThumbImageIndex(Value: Integer);
  539. begin
  540.   if FThumbImageIndex <> Value then
  541.   begin
  542.     FThumbImageIndex := Value;
  543.     GetThumbImage;
  544.     UpdateControlCanvas;
  545.   end;
  546. end;
  547. procedure TVrTrackBar.SetBitmapList(Value: TVrBitmapList);
  548. begin
  549.   if FBitmapList <> nil then
  550.     FBitmapList.RemoveLink(FBitmapListLink);
  551.   FBitmapList := Value;
  552.   if FBitmapList <> nil then
  553.     FBitmapList.InsertLink(FBitmapListLink);
  554.   GetThumbImage;
  555.   UpdateControlCanvas;
  556. end;
  557. procedure TVrTrackBar.SetMaxValue(Value: Integer);
  558. begin
  559.   if FMaxValue <> Value then
  560.   begin
  561.     FMaxValue := Value;
  562.     if FPosition > FMaxValue then Position := FMaxValue
  563.     else UpdateControlCanvas;
  564.   end;
  565. end;
  566. procedure TVrTrackBar.SetMinValue(Value: Integer);
  567. begin
  568.   if FMinValue <> Value then
  569.   begin
  570.     FMinValue := Value;
  571.     if FPosition < FMinValue then Position := FMinValue
  572.     else UpdateControlCanvas;
  573.   end;
  574. end;
  575. procedure TVrTrackBar.SetPosition(Value: Integer);
  576. begin
  577.   if Value < FMinValue then Value := FMinValue;
  578.   if Value > FMaxValue then Value := FMaxValue;
  579.   if FPosition <> Value then
  580.   begin
  581.     FPosition := Value;
  582.     UpdateControlCanvas;
  583.     Change;
  584.   end;
  585. end;
  586. procedure TVrTrackBar.SetOrientation(Value: TVrOrientation);
  587. begin
  588.   if FOrientation <> Value then
  589.   begin
  590.     FOrientation := Value;
  591.     if not Loading then
  592.       BoundsRect := Bounds(Left, Top, Height, Width);
  593.     GetThumbImage;
  594.     UpdateControlCanvas;
  595.   end;
  596. end;
  597. procedure TVrTrackBar.SetStyle(Value: TVrProgressStyle);
  598. begin
  599.   if FStyle <> Value then
  600.   begin
  601.     FStyle := Value;
  602.     UpdateControlCanvas;
  603.   end;
  604. end;
  605. procedure TVrTrackBar.SetOptions(Value: TVrTrackBarOptions);
  606. begin
  607.   if FOptions <> Value then
  608.   begin
  609.     FOptions := Value;
  610.     UpdateControlCanvas;
  611.   end;
  612. end;
  613. procedure TVrTrackBar.SetFrequency(Value: Integer);
  614. begin
  615.   if FFrequency <> Value then
  616.   begin
  617.     FFrequency := Value;
  618.     UpdateControlCanvas;
  619.   end;
  620. end;
  621. procedure TVrTrackBar.SetBorderWidth(Value: Integer);
  622. begin
  623.   if FBorderWidth <> Value then
  624.   begin
  625.     FBorderWidth := Value;
  626.     UpdateControlCanvas;
  627.   end;
  628. end;
  629. procedure TVrTrackBar.SetGutterWidth(Value: Integer);
  630. begin
  631.   if FGutterWidth <> Value then
  632.   begin
  633.     FGutterWidth := Value;
  634.     UpdateControlCanvas;
  635.   end;
  636. end;
  637. procedure TVrTrackBar.SetGutterColor(Value: TColor);
  638. begin
  639.   if FGutterColor <> Value then
  640.   begin
  641.     FGutterColor := Value;
  642.     UpdateControlCanvas;
  643.   end;
  644. end;
  645. procedure TVrTrackBar.SetGutterBevel(Value: TVrBevel);
  646. begin
  647.   FGutterBevel.Assign(Value);
  648. end;
  649. procedure TVrTrackBar.SetTickMarks(Value: TVrTickMarks);
  650. begin
  651.   if FTickMarks <> Value then
  652.   begin
  653.     FTickMarks := Value;
  654.     UpdateControlCanvas;
  655.   end;
  656. end;
  657. procedure TVrTrackBar.SetTickColor(Value: TColor);
  658. begin
  659.   if FTickColor <> Value then
  660.   begin
  661.     FTickColor := Value;
  662.     UpdateControlCanvas;
  663.   end;
  664. end;
  665. procedure TVrTrackBar.SetFocusColor(Value: TColor);
  666. begin
  667.   if FFocusColor <> Value then
  668.   begin
  669.     FFocusColor := Value;
  670.     UpdateControlCanvas;
  671.   end;
  672. end;
  673. procedure TVrTrackBar.SetScaleOffset(Value: Integer);
  674. begin
  675.   if FScaleOffset <> Value then
  676.   begin
  677.     FScaleOffset := Value;
  678.     UpdateControlCanvas;
  679.   end;
  680. end;
  681. procedure TVrTrackBar.SetFocusOffset(Value: Integer);
  682. begin
  683.   if FFocusOffset <> Value then
  684.   begin
  685.     FFocusOffset := Value;
  686.     UpdateControlCanvas;
  687.   end;
  688. end;
  689. procedure TVrTrackBar.SetThumbStates(Value: TVrNumGlyphs);
  690. begin
  691.   if FThumbStates <> Value then
  692.   begin
  693.     FThumbStates := Value;
  694.     if not Loading then
  695.       GetThumbImage;
  696.     UpdateControlCanvas;
  697.   end;
  698. end;
  699. procedure TVrTrackBar.MouseDown(Button: TMouseButton; Shift: TShiftState;
  700.   X, Y: Integer);
  701. var
  702.   R: TRect;
  703.   P: TPoint;
  704. begin
  705.   inherited MouseDown(Button, Shift, X, Y);
  706.   if (Button = mbLeft) then
  707.   begin
  708.     if TabStop then SetFocus;
  709.     P := Point(X, Y);
  710.     if PtInRect(FThumbRect, P) then
  711.     begin
  712.       FThumbDown := True;
  713.       if Orientation = voHorizontal then FHit := X - FThumbRect.Left
  714.       else FHit := Y - FThumbRect.Top;
  715.       if (toMouseClip in Options) then
  716.       begin
  717.         R := Bounds(ClientOrigin.X, ClientOrigin.Y,
  718.           ClientWidth, ClientHeight);
  719.         ClipCursor(@R);
  720.         FClipOn := True;
  721.       end;
  722.       UpdateControlCanvas;
  723.     end
  724.     else
  725.     if (toActiveClick in Options) then
  726.     begin
  727.       if Orientation = voHorizontal then
  728.         FHit := X - FThumbWidth div 2
  729.       else FHit := Y - FThumbHeight div 2;
  730.       SetThumbOffset(FHit);
  731.     end;
  732.   end;
  733. end;
  734. procedure TVrTrackBar.MouseMove(Shift: TShiftState; X, Y: Integer);
  735. var
  736.   OldValue: Boolean;
  737. begin
  738.   if FThumbDown then
  739.   begin
  740.     if FOrientation = voVertical then
  741.       SetThumbOffset(Y - FHit)
  742.     else
  743.       SetThumbOffset(X - FHit);
  744.   end
  745.   else
  746.   begin
  747.     OldValue := FThumbHasMouse;
  748.     FThumbHasMouse := PtInRect(FThumbRect, Point(X, Y));
  749.     if OldValue <> FThumbHasMouse then UpdateControlCanvas;
  750.   end;
  751.   inherited MouseMove(Shift, X, Y);
  752. end;
  753. procedure TVrTrackBar.MouseUp(Button: TMouseButton; Shift: TShiftState;
  754.   X, Y: Integer);
  755. begin
  756.   if FThumbDown then
  757.   begin
  758.     FThumbDown := false;
  759.     UpdateControlCanvas;
  760.   end;
  761.   if FClipOn then
  762.   begin
  763.     ClipCursor(nil);
  764.     FClipOn := false;
  765.   end;
  766.   inherited MouseUp(Button, Shift, X, Y);
  767. end;
  768. procedure TVrTrackBar.KeyDown(var Key: Word; Shift: TShiftState);
  769.   function Adjust(Value: Integer): Integer;
  770.   begin
  771.     Result := Value;
  772.     if Style = psTopRight then Result := -Result;
  773.   end;
  774. begin
  775.   if Shift = [] then
  776.   begin
  777.     if Key = VK_HOME then Position := FMaxValue
  778.     else if Key = VK_END then Position := FMinValue;
  779.     if Orientation = voHorizontal then
  780.     begin
  781.       if Key = VK_LEFT then Position := Position + Adjust(-Frequency)
  782.       else if Key = VK_RIGHT then Position := Position + Adjust(Frequency);
  783.     end
  784.     else
  785.     begin
  786.       if Key = VK_UP then Position := Position + Adjust(Frequency)
  787.       else if Key = VK_DOWN then Position := Position + Adjust(-Frequency);
  788.     end;
  789.   end;
  790.   inherited KeyDown(Key, Shift);
  791. end;
  792. end.