cxtrackbar.pas
来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,699 行 · 第 1/5 页
PAS
1,699 行
AViewInfo.ThumbLargeSize := FThumbLargeSize;
AViewInfo.TickOffset := FTickOffset;
Properties.FTickOffset := FTickOffset;
end;
procedure TcxCustomTrackBarViewData.CalculateThumbRect(ACanvas: TcxCanvas;
AViewInfo: TcxCustomTrackBarViewInfo);
var
FCurrentTickOffset: Integer;
FDelta: Integer;
begin
if Properties.Orientation = tboHorizontal then
begin
FCurrentTickOffset := Trunc((AViewInfo.TickOffset * (AViewInfo.Position - Properties.Min)) +
AViewInfo.TrackRect.Left) + (AViewInfo.ThumbSize div 2);
AViewInfo.ThumbRect.Left := FCurrentTickOffset - (AViewInfo.ThumbSize div 2);
AViewInfo.ThumbRect.Right := FCurrentTickOffset + (AViewInfo.ThumbSize div 2);
AViewInfo.ThumbRect.Top := AViewInfo.TrackRect.Top + (AViewInfo.TrackSize div 2) -
(AViewInfo.ThumbLargeSize div 2);
AViewInfo.ThumbRect.Bottom := AViewInfo.ThumbRect.Top + AViewInfo.ThumbLargeSize;
end
else
begin
FCurrentTickOffset := Trunc((AViewInfo.TickOffset * (AViewInfo.Position - Properties.Min)) +
AViewInfo.TrackRect.Top) + (AViewInfo.ThumbSize div 2);
AViewInfo.ThumbRect.Top := FCurrentTickOffset - (AViewInfo.ThumbSize div 2);
AViewInfo.ThumbRect.Bottom := FCurrentTickOffset + (AViewInfo.ThumbSize div 2);
case Properties.TickMarks of
cxtmTopLeft:
if AViewInfo.Painter = nil then
FDelta := -1
else
FDelta := 0;
else
FDelta := 0;
end;
AViewInfo.ThumbRect.Left := AViewInfo.TrackRect.Left + (AViewInfo.TrackSize -
AViewInfo.ThumbLargeSize) div 2 + FDelta;
AViewInfo.ThumbRect.Right := AViewInfo.ThumbRect.Left + AViewInfo.ThumbLargeSize + FDelta;
end;
if NativeStyle then
begin
if Properties.Orientation = tboHorizontal then
InflateRectEx(AViewInfo.ThumbRect, 1, 0, 1, 0)
else
InflateRectEx(AViewInfo.ThumbRect, 0, 1, 0, 1);
end;
Properties.FThumbRect := AViewInfo.DrawingThumbRectToRealThumbRect(ACanvas);
end;
procedure TcxCustomTrackBarViewData.CalculateSelectionRect(
AViewInfo: TcxCustomTrackBarViewInfo);
begin
if AViewInfo.SelectionStart < Properties.Min then
AViewInfo.SelectionStart := Properties.Min;
if AViewInfo.SelectionEnd < Properties.Min then
AViewInfo.SelectionEnd := Properties.Min;
if AViewInfo.SelectionStart > Properties.Max then
AViewInfo.SelectionStart := Properties.Max;
if AViewInfo.SelectionEnd > Properties.Max then
AViewInfo.SelectionEnd := Properties.Max;
AViewInfo.FShowSelection := (AViewInfo.SelectionStart < AViewInfo.SelectionEnd);
if AViewInfo.FShowSelection then
begin
if Properties.Orientation = tboHorizontal then
begin
AViewInfo.SelectionRect.Left := Trunc((AViewInfo.TickOffset * (AViewInfo.SelectionStart - Properties.Min)) +
AViewInfo.TrackRect.Left) + (AViewInfo.ThumbSize div 2);
AViewInfo.SelectionRect.Right := Trunc((AViewInfo.TickOffset * (AViewInfo.SelectionEnd - Properties.Min)) +
AViewInfo.TrackRect.Left) + (AViewInfo.ThumbSize div 2) + 1;
AViewInfo.SelectionRect.Top := AViewInfo.TrackRect.Top;
AViewInfo.SelectionRect.Bottom := AViewInfo.TrackRect.Bottom;
if AViewInfo.Painter = nil then
begin
Inc(AViewInfo.SelectionRect.Top, 2);
Dec(AViewInfo.SelectionRect.Bottom);
end;
end
else
begin
AViewInfo.SelectionRect.Top := Trunc((AViewInfo.TickOffset * (AViewInfo.SelectionStart - Properties.Min)) +
AViewInfo.TrackRect.Top) + (AViewInfo.ThumbSize div 2);
AViewInfo.SelectionRect.Bottom := Trunc((AViewInfo.TickOffset * (AViewInfo.SelectionEnd - Properties.Min)) +
AViewInfo.TrackRect.Top) + (AViewInfo.ThumbSize div 2) + 1;
AViewInfo.SelectionRect.Left := AViewInfo.TrackRect.Left;
AViewInfo.SelectionRect.Right := AViewInfo.TrackRect.Right;
if AViewInfo.Painter = nil then
begin
Inc(AViewInfo.SelectionRect.Left, 2);
Dec(AViewInfo.SelectionRect.Right, 2);
end;
end;
end;
end;
procedure TcxCustomTrackBarViewData.DoOnGetThumbRect(var ARect: TRect);
var
AOnGetThumbRect: TcxGetThumbRectEvent;
begin
GetOnGetThumbRect(AOnGetThumbRect);
AOnGetThumbRect(Properties, ARect);
end;
function TcxCustomTrackBarViewData.IsOnGetThumbRectEventAssigned: Boolean;
var
AOnGetThumbRect: TcxGetThumbRectEvent;
begin
GetOnGetThumbRect(AOnGetThumbRect);
Result := Assigned(AOnGetThumbRect);
end;
procedure TcxCustomTrackBarViewData.CalculateCustomTrackBarRects(ACanvas: TcxCanvas;
AViewInfo: TcxCustomTrackBarViewInfo);
begin
CalculateTrackBarRect(AViewInfo);
CalculateTrackZoneRect(ACanvas, AViewInfo);
CalculateTrackRect(AViewInfo);
CalculateThumbSize(AViewInfo);
CalculateThumbRect(ACanvas, AViewInfo);
CalculateSelectionRect(AViewInfo);
end;
procedure TcxCustomTrackBarViewData.Calculate(ACanvas: TcxCanvas; const ABounds: TRect;
const P: TPoint; Button: TcxMouseButton; Shift: TShiftState; AViewInfo: TcxCustomEditViewInfo;
AIsMouseEvent: Boolean);
var
FViewInfo : TcxCustomTrackBarViewInfo;
FDisplayValue: TcxEditValue;
begin
inherited Calculate(ACanvas, ABounds, P, Button, Shift, AViewInfo, AIsMouseEvent);
FViewInfo := TcxCustomTrackBarViewInfo(AViewInfo);
{Standart properties}
FViewInfo.LookAndFeel.Assign(Style.LookAndFeel);
FViewInfo.IsEditClass := False;
FViewInfo.DrawSelectionBar := False;
FViewInfo.HasPopupWindow := False;
FViewInfo.DrawTextFlags := 0;
FViewInfo.DrawSelectionBar := False;
if not FViewInfo.Enabled then
FViewInfo.TrackBarState := TUS_DISABLED
else
begin
if tbmpSliding in FViewInfo.MouseStates then
FViewInfo.TrackBarState := TUS_PRESSED
else
if tbmpUnderThumb in FViewInfo.MouseStates then
FViewInfo.TrackBarState := TUS_HOT
else
FViewInfo.TrackBarState := TUS_NORMAL;
end;
{TrackBar properties}
if Assigned(Edit) and not FViewInfo.IsDBEditPaintCopyDrawing then
begin
Properties.PrepareDisplayValue(Edit.EditValue, FDisplayValue, Focused);
FViewInfo.Position := FDisplayValue;
end;
CalculateTBViewInfoProps(AViewInfo);
CalculateCustomTrackBarViewInfo(ACanvas, Self, FViewInfo);
CalculateCustomTrackBarRects(ACanvas, FViewInfo);
end;
procedure TcxCustomTrackBarViewData.EditValueToDrawValue(ACanvas: TcxCanvas;
const AEditValue: TcxEditValue; AViewInfo: TcxCustomEditViewInfo);
var
ADisplayValue: TcxEditValue;
begin
Properties.PrepareDisplayValue(AEditValue, ADisplayValue, InternalFocused);
TcxCustomTrackBarViewInfo(AViewInfo).Position := ADisplayValue;
end;
function TcxCustomTrackBarViewData.InternalGetEditConstantPartSize(ACanvas: TcxCanvas;
AIsInplace: Boolean; AEditSizeProperties: TcxEditSizeProperties;
var MinContentSize: TSize; AViewInfo: TcxCustomEditViewInfo): TSize;
var
ASize1: TSize;
begin
Result := inherited InternalGetEditConstantPartSize(ACanvas, AIsInplace,
AEditSizeProperties, MinContentSize, AViewInfo);
ASize1.cx := RectWidth(TcxCustomTrackBarViewInfo(AViewInfo).ThumbRect);
ASize1.cy := GetTextEditContentSize(ACanvas, Self, 'Wg', 0,
AEditSizeProperties, 0, False).cy;
Result.cx := Result.cx + ASize1.cx;
Result.cy := Result.cy + ASize1.cy;
end;
procedure TcxCustomTrackBarViewData.GetOnGetThumbRect(out AValue: TcxGetThumbRectEvent);
begin
if Edit = nil then
AValue := Properties.OnGetThumbRect
else
TcxCustomTrackBar(Edit).GetOnGetThumbRect(AValue);
end;
function TcxCustomTrackBarViewData.GetProperties: TcxCustomTrackBarProperties;
begin
Result := TcxCustomTrackBarProperties(FProperties);
end;
{ TcxCustomTrackBarProperties }
constructor TcxCustomTrackBarProperties.Create(AOwner: TPersistent);
begin
inherited Create(AOwner);
FAutoSize := True;
FBorderWidth := 0;
FFrequency := 1;
FMin := 0;
FMax := 10;
FOrientation := tboHorizontal;
FTextOrientation := tbtoHorizontal;
FPageSize := 1;
FTrackColor := clWindow;
FTrackSize := 5;
FTickColor := clWindowText;
FSelectionStart := 0;
FSelectionEnd := 0;
FSelectionColor := clHighlight;
FShowTicks := True;
FThumbType := cxttRegular;
FShowTrack := True;
FTickType := tbttTicks;
FTickMarks := cxtmBottomRight;
FTickSize := 3;
FThumbHeight := 12;
FThumbWidth := 7;
FThumbColor := clBtnFace;
FThumbHighlightColor := clSilver;
FThumbStep := cxtsNormal;
end;
destructor TcxCustomTrackBarProperties.Destroy;
begin
inherited Destroy;
end;
procedure TcxCustomTrackBarProperties.Assign(Source: TPersistent);
begin
if Source is TcxCustomTrackBarProperties then
begin
BeginUpdate;
try
inherited Assign(Source);
with Source as TcxCustomTrackBarProperties do
begin
Self.AutoSize := AutoSize;
Self.BorderWidth := BorderWidth;
Self.Frequency := Frequency;
Self.Min := Min;
Self.Max := Max;
Self.Orientation := Orientation;
Self.TextOrientation := TextOrientation;
Self.PageSize := PageSize;
Self.SelectionStart := SelectionStart;
Self.SelectionEnd := SelectionEnd;
Self.SelectionColor := SelectionColor;
Self.ShowTicks := ShowTicks;
Self.ThumbStep := ThumbStep;
Self.ThumbType := ThumbType;
Self.ShowTrack := ShowTrack;
Self.TickColor := TickColor;
Self.TickType := TickType;
Self.TickMarks := TickMarks;
Self.TickSize := TickSize;
Self.TrackColor := TrackColor;
Self.TrackSize := TrackSize;
Self.ThumbHeight := ThumbHeight;
Self.ThumbWidth := ThumbWidth;
Self.ThumbColor := ThumbColor;
Self.ThumbHighlightColor := ThumbHighlightColor;
Self.OnGetThumbRect := OnGetThumbRect;
Self.OnDrawThumb := OnDrawThumb;
end;
finally
EndUpdate;
end
end
else
inherited Assign(Source);
end;
function TcxCustomTrackBarProperties.CanCompareEditValue: Boolean;
begin
Result := True;
end;
class function TcxCustomTrackBarProperties.GetContainerClass: TcxContainerClass;
begin
Result := TcxTrackBar;
end;
function TcxCustomTrackBarProperties.GetDisplayText(const AEditValue: TcxEditValue;
AFullText: Boolean = False; AIsInplace: Boolean = True): WideString;
var
ADisplayValue: TcxEditValue;
begin
PrepareDisplayValue(AEditValue, ADisplayValue, False);
Result := ADisplayValue;
end;
class function TcxCustomTrackBarProperties.GetStyleClass: TcxCustomEditStyleClass;
begin
Result := TcxTrackBarStyle;
end;
function TcxCustomTrackBarProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
Result := [esoAlwaysHotTrack, esoEditing, esoFiltering, esoSorting,
esoTransparency];
end;
class function TcxCustomTrackBarProperties.GetViewInfoClass: TcxContainerViewInfoClass;
begin
Result := TcxCustomTrackBarViewInfo;
end;
function TcxCustomTrackBarProperties.IsEditValueValid(var EditValue: TcxEditValue;
AEditFocused: Boolean): Boolean;
begin
Result := inherited IsEditValueValid(EditValue, AEditFocused);
end;
procedure TcxCustomTrackBarProperties.PrepareDisplayValue(const AEditValue:
TcxEditValue; var DisplayValue: TcxEditValue; AEditFocused: Boolean);
begin
LockUpdate(True);
try
DisplayValue := FixPosition(EditValueToPosition(AEditValue));
finally
LockUpdate(False);
end;
end;
function TcxCustomTrackBarProperties.EditValueToPosition(
const AEditValue: TcxEditValue): Integer;
begin
if IsVarEmpty(AE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?