mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-11 10:35:58 +02:00
customdrawn: Simplifies the state info for TCDTrackBar and TCDProgressBar and adds the skeleton of TCDListView
git-svn-id: trunk@33423 -
This commit is contained in:
parent
6656513df2
commit
3056f03bc6
@ -788,12 +788,8 @@ begin
|
||||
|
||||
CDBarSpacing := GetMeasures(TCDTRACKBAR_LEFT_SPACING) + GetMeasures(TCDTRACKBAR_RIGHT_SPACING);
|
||||
|
||||
// Sanity check
|
||||
if AStateEx.Max - AStateEx.Min <= 0 then
|
||||
raise Exception.Create('[TCDDrawerCommon.DrawTrackBar] Max-Min must be at least 1');
|
||||
|
||||
// Preparations
|
||||
StepsCount := AStateEx.Max - AStateEx.Min + 1;
|
||||
StepsCount := AStateEx.PosCount;
|
||||
if StepsCount > 0 then pStepWidth := (lMeasureSize.cx - CDBarSpacing) div (StepsCount-1)
|
||||
else pStepWidth := 0;
|
||||
|
||||
@ -836,7 +832,7 @@ begin
|
||||
ADest.Line(lTickmarkTop, lTickmarkLeft, lTickmarkTop+3, lTickmarkLeft);
|
||||
|
||||
// Draw the slider
|
||||
if i + AStateEx.Min = AStateEx.Position then
|
||||
if i = AStateEx.Position then
|
||||
DrawSlider(ADest,
|
||||
Point(lTickmarkLeft-5, GetMeasures(TCDTRACKBAR_TOP_SPACING)-2),
|
||||
Size(11, GetMeasures(TCDTRACKBAR_FRAME_HEIGHT)+5), AStateEx.Orientation);
|
||||
|
@ -131,12 +131,8 @@ begin
|
||||
CDBarEdge := GetMeasures(TCDTRACKBAR_LEFT_SPACING)
|
||||
+ GetMeasures(TCDTRACKBAR_RIGHT_SPACING);
|
||||
|
||||
// Sanity check
|
||||
if AStateEx.Max - AStateEx.Min <= 0 then
|
||||
raise Exception.Create('[TCDTrackBarDrawerGraph.DrawToIntfImage] Max-Min must be at least 1');
|
||||
|
||||
// Preparations
|
||||
StepsCount := AStateEx.Max - AStateEx.Min + 1;
|
||||
StepsCount := AStateEx.PosCount;
|
||||
pStepWidth := (ASize.cx - CDBarEdge) div StepsCount;
|
||||
pHalfStepWidth := (ASize.cx - CDBarEdge) div (StepsCount * 2);
|
||||
|
||||
@ -183,7 +179,7 @@ begin
|
||||
ADest.Brush.Style := bsSolid;
|
||||
ADest.Pen.Style := psSolid;
|
||||
ADest.Pen.Color := clBlack;
|
||||
if i + AStateEx.Min <= AStateEx.Position then
|
||||
if i <= AStateEx.Position then
|
||||
ADest.Brush.Color := clDkGray
|
||||
else
|
||||
ADest.Brush.Color := clWhite;
|
||||
@ -192,7 +188,7 @@ begin
|
||||
|
||||
// Draw the slider
|
||||
|
||||
if i + AStateEx.Min = AStateEx.Position then
|
||||
if i = AStateEx.Position then
|
||||
begin
|
||||
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6));
|
||||
ADest.Brush.Style := bsSolid;
|
||||
|
@ -348,17 +348,25 @@ type
|
||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||
property Orientation: TProgressBarOrientation read FOrientation write SetOrientation;// default prHorizontal;
|
||||
property Position: integer read FPosition write SetPosition;
|
||||
property TabStop default True;
|
||||
end;
|
||||
|
||||
{ TCDListView }
|
||||
|
||||
(* TCDListView = class(TCDControl)
|
||||
TCDListView = class(TCDControl)
|
||||
private
|
||||
DragDropStarted: boolean;
|
||||
// fields
|
||||
FColumns: TListColumns;
|
||||
FIconOptions: TIconOptions;
|
||||
FListItems: TCDListItems;
|
||||
FProperties: TListViewProperties;
|
||||
FViewStyle: TViewStyle;
|
||||
function GetProperty(AIndex: Integer): Boolean;
|
||||
procedure SetColumns(AValue: TListColumns);
|
||||
procedure SetProperty(AIndex: Integer; AValue: Boolean);
|
||||
procedure SetViewStyle(AValue: TViewStyle);
|
||||
protected
|
||||
// keyboard
|
||||
{ // keyboard
|
||||
procedure DoEnter; override;
|
||||
procedure DoExit; override;
|
||||
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||
@ -369,16 +377,23 @@ type
|
||||
procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
|
||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
||||
procedure MouseEnter; override;
|
||||
procedure MouseLeave; override;
|
||||
procedure MouseLeave; override;}
|
||||
protected
|
||||
FLVState: TCDListViewStateEx;
|
||||
function GetControlId: TCDControlID; override;
|
||||
procedure CreateControlStateEx; override;
|
||||
procedure PrepareControlStateEx; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure EraseBackground(DC: HDC); override;
|
||||
procedure Paint; override;
|
||||
published
|
||||
property Color;
|
||||
property TabStop default True;
|
||||
end;*)
|
||||
property Columns: TListColumns read FColumns write SetColumns;
|
||||
//property GridLines: Boolean index Ord(lvpGridLines) read GetProperty write SetProperty default False;
|
||||
property Items: TCDListItems read FListItems;
|
||||
property ViewStyle: TViewStyle read FViewStyle default vsList;
|
||||
end;
|
||||
|
||||
{TCDTabControl}
|
||||
|
||||
@ -500,6 +515,65 @@ implementation
|
||||
resourcestring
|
||||
sTABSHEET_DEFAULT_NAME = 'CTabSheet';
|
||||
|
||||
{ TCDListView }
|
||||
|
||||
function TCDListView.GetProperty(AIndex: Integer): Boolean;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TCDListView.SetColumns(AValue: TListColumns);
|
||||
begin
|
||||
if FColumns=AValue then Exit;
|
||||
FColumns:=AValue;
|
||||
end;
|
||||
|
||||
procedure TCDListView.SetProperty(AIndex: Integer; AValue: Boolean);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TCDListView.SetViewStyle(AValue: TViewStyle);
|
||||
begin
|
||||
if FViewStyle=AValue then Exit;
|
||||
FViewStyle:=AValue;
|
||||
end;
|
||||
|
||||
function TCDListView.GetControlId: TCDControlID;
|
||||
begin
|
||||
Result := cidListView;
|
||||
end;
|
||||
|
||||
procedure TCDListView.CreateControlStateEx;
|
||||
begin
|
||||
FLVState := TCDListViewStateEx.Create;
|
||||
FStateEx := FLVState;
|
||||
end;
|
||||
|
||||
procedure TCDListView.PrepareControlStateEx;
|
||||
begin
|
||||
FLVState.Items := FListItems;
|
||||
FLVState.Columns := FColumns;
|
||||
FLVState.ViewStyle := FViewStyle;
|
||||
end;
|
||||
|
||||
constructor TCDListView.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Width := 250;
|
||||
Height := 150;
|
||||
FColumns := TListColumns.Create(nil);
|
||||
FListItems := TCDListItems.Create();
|
||||
TabStop := True;
|
||||
// FProperties: TListViewProperties;
|
||||
// FViewStyle: TViewStyle;
|
||||
end;
|
||||
|
||||
destructor TCDListView.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TCDProgressBar }
|
||||
|
||||
procedure TCDProgressBar.SetMax(Value: integer);
|
||||
@ -524,7 +598,7 @@ end;
|
||||
|
||||
function TCDProgressBar.GetControlId: TCDControlID;
|
||||
begin
|
||||
Result:=inherited GetControlId;
|
||||
Result := cidProgressBar;
|
||||
end;
|
||||
|
||||
procedure TCDProgressBar.CreateControlStateEx;
|
||||
@ -535,12 +609,15 @@ end;
|
||||
|
||||
procedure TCDProgressBar.PrepareControlStateEx;
|
||||
begin
|
||||
// FPBState.Min:=;
|
||||
FPBState.PercentPosition := (FPosition-FMin)/FMax;
|
||||
end;
|
||||
|
||||
constructor TCDProgressBar.Create(AOwner: TComponent);
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Width := 100;
|
||||
Height := 20;
|
||||
TabStop := False;
|
||||
end;
|
||||
|
||||
destructor TCDProgressBar.Destroy;
|
||||
@ -1266,7 +1343,10 @@ end;
|
||||
procedure TCDTrackBar.SetMax(Value: integer);
|
||||
begin
|
||||
if Value = FMax then Exit;
|
||||
FMax := Value;
|
||||
// Sanity check
|
||||
if Value < FMin then FMax := FMin
|
||||
else FMax := Value;
|
||||
|
||||
PrepareControlStateEx;
|
||||
Invalidate;
|
||||
end;
|
||||
@ -1274,7 +1354,10 @@ end;
|
||||
procedure TCDTrackBar.SetMin(Value: integer);
|
||||
begin
|
||||
if Value = FMin then Exit;
|
||||
FMin := Value;
|
||||
// Sanity check
|
||||
if Value > FMax then FMin := FMax
|
||||
else FMin := Value;
|
||||
|
||||
PrepareControlStateEx;
|
||||
Invalidate;
|
||||
end;
|
||||
@ -1350,9 +1433,8 @@ end;
|
||||
procedure TCDTrackBar.PrepareControlStateEx;
|
||||
begin
|
||||
inherited PrepareControlStateEx;
|
||||
FTBState.Min := FMin;
|
||||
FTBState.Max := FMax;
|
||||
FTBState.Position := FPosition;
|
||||
FTBState.PosCount := FMax - FMin + 1;
|
||||
FTBState.Position := FPosition - FMin;
|
||||
FTBState.Orientation := FOrientation;
|
||||
end;
|
||||
|
||||
|
@ -121,20 +121,40 @@ type
|
||||
|
||||
TCDTrackBarStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
Min: integer;
|
||||
Max: integer;
|
||||
Position: integer;
|
||||
PosCount: integer; // The number of positions, calculated as Max - Min + 1
|
||||
Position: integer; // A zero-based position, therefore it is = Position - Min
|
||||
Orientation: TTrackBarOrientation;
|
||||
end;
|
||||
|
||||
TCDProgressBarStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
Min: integer;
|
||||
Max: integer;
|
||||
Position: integer;
|
||||
PercentPosition: Double;
|
||||
Orientation: TProgressBarOrientation;
|
||||
end;
|
||||
|
||||
// TCDListItems are implemented as a tree with 2 levels beyond the first node
|
||||
TCDListItems = class
|
||||
private
|
||||
procedure DoFreeItem(data,arg:pointer);
|
||||
public
|
||||
// These fields are not used in the first node of the tree
|
||||
Caption: string;
|
||||
ImageIndex: Integer;
|
||||
StateIndex: Integer;
|
||||
//
|
||||
Childs: TFPList;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function Add(ACaption: string; AImageIndex, AStateIndex: Integer): TCDListItems;
|
||||
end;
|
||||
|
||||
TCDListViewStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
Columns: TListColumns; // just a reference, never free
|
||||
Items: TCDListItems; // just a reference, never free
|
||||
ViewStyle: TViewStyle;
|
||||
end;
|
||||
|
||||
TCDCTabControlStateEx = class(TCDControlStateEx)
|
||||
public
|
||||
LeftmostTabVisibleIndex: Integer;
|
||||
@ -150,22 +170,12 @@ type
|
||||
TCDControlID = (
|
||||
cidControl,
|
||||
// Standard
|
||||
cidMenu,
|
||||
cidPopUp,
|
||||
cidButton,
|
||||
cidEdit,
|
||||
cidCheckBox,
|
||||
cidRadioButton,
|
||||
cidListBox,
|
||||
cidComboBox,
|
||||
cidGroupBox,
|
||||
cidMenu, cidPopUp, cidButton, cidEdit, cidCheckBox, cidRadioButton,
|
||||
cidListBox, cidComboBox, cidGroupBox,
|
||||
// Additional
|
||||
cidStaticText,
|
||||
// Common Controls
|
||||
cidTrackBar,
|
||||
cidProgressBar,
|
||||
cidListView,
|
||||
cidCTabControl
|
||||
cidTrackBar, cidProgressBar, cidListView, cidCTabControl
|
||||
);
|
||||
|
||||
TCDColorPalette = class
|
||||
@ -307,6 +317,36 @@ end;
|
||||
var
|
||||
i: Integer;
|
||||
|
||||
{ TCDListItems }
|
||||
|
||||
procedure TCDListItems.DoFreeItem(data, arg: pointer);
|
||||
begin
|
||||
TCDListItems(data).Free;
|
||||
end;
|
||||
|
||||
constructor TCDListItems.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
Childs := TFPList.Create;
|
||||
end;
|
||||
|
||||
destructor TCDListItems.Destroy;
|
||||
begin
|
||||
Childs.ForEachCall(@DoFreeItem, nil);
|
||||
Childs.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TCDListItems.Add(ACaption: string; AImageIndex, AStateIndex: Integer
|
||||
): TCDListItems;
|
||||
begin
|
||||
Result := TCDListItems.Create;
|
||||
Result.Caption := ACaption;
|
||||
Result.ImageIndex := AImageIndex;
|
||||
Result.StateIndex := AStateIndex;
|
||||
Childs.Add(Pointer(Result));
|
||||
end;
|
||||
|
||||
{ TCDDrawer }
|
||||
|
||||
constructor TCDDrawer.Create;
|
||||
|
@ -188,7 +188,7 @@ begin
|
||||
// Additional
|
||||
TCDStaticText,
|
||||
// Common Controls
|
||||
TCDTrackBar, TCDPageControl, TCDTabControl]);
|
||||
TCDTrackBar, TCDProgressBar, TCDListView, TCDPageControl, TCDTabControl]);
|
||||
RegisterComponentEditor(TCDPageControl, TCDPageControlEditor);
|
||||
RegisterComponentEditor(TCDTabSheet, TCDPageControlEditor);
|
||||
RegisterNoIcon([TCDTabSheet]);
|
||||
|
Loading…
Reference in New Issue
Block a user