mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 20:59:12 +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);
|
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
|
// Preparations
|
||||||
StepsCount := AStateEx.Max - AStateEx.Min + 1;
|
StepsCount := AStateEx.PosCount;
|
||||||
if StepsCount > 0 then pStepWidth := (lMeasureSize.cx - CDBarSpacing) div (StepsCount-1)
|
if StepsCount > 0 then pStepWidth := (lMeasureSize.cx - CDBarSpacing) div (StepsCount-1)
|
||||||
else pStepWidth := 0;
|
else pStepWidth := 0;
|
||||||
|
|
||||||
@ -836,7 +832,7 @@ begin
|
|||||||
ADest.Line(lTickmarkTop, lTickmarkLeft, lTickmarkTop+3, lTickmarkLeft);
|
ADest.Line(lTickmarkTop, lTickmarkLeft, lTickmarkTop+3, lTickmarkLeft);
|
||||||
|
|
||||||
// Draw the slider
|
// Draw the slider
|
||||||
if i + AStateEx.Min = AStateEx.Position then
|
if i = AStateEx.Position then
|
||||||
DrawSlider(ADest,
|
DrawSlider(ADest,
|
||||||
Point(lTickmarkLeft-5, GetMeasures(TCDTRACKBAR_TOP_SPACING)-2),
|
Point(lTickmarkLeft-5, GetMeasures(TCDTRACKBAR_TOP_SPACING)-2),
|
||||||
Size(11, GetMeasures(TCDTRACKBAR_FRAME_HEIGHT)+5), AStateEx.Orientation);
|
Size(11, GetMeasures(TCDTRACKBAR_FRAME_HEIGHT)+5), AStateEx.Orientation);
|
||||||
|
@ -131,12 +131,8 @@ begin
|
|||||||
CDBarEdge := GetMeasures(TCDTRACKBAR_LEFT_SPACING)
|
CDBarEdge := GetMeasures(TCDTRACKBAR_LEFT_SPACING)
|
||||||
+ GetMeasures(TCDTRACKBAR_RIGHT_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
|
// Preparations
|
||||||
StepsCount := AStateEx.Max - AStateEx.Min + 1;
|
StepsCount := AStateEx.PosCount;
|
||||||
pStepWidth := (ASize.cx - CDBarEdge) div StepsCount;
|
pStepWidth := (ASize.cx - CDBarEdge) div StepsCount;
|
||||||
pHalfStepWidth := (ASize.cx - CDBarEdge) div (StepsCount * 2);
|
pHalfStepWidth := (ASize.cx - CDBarEdge) div (StepsCount * 2);
|
||||||
|
|
||||||
@ -183,7 +179,7 @@ begin
|
|||||||
ADest.Brush.Style := bsSolid;
|
ADest.Brush.Style := bsSolid;
|
||||||
ADest.Pen.Style := psSolid;
|
ADest.Pen.Style := psSolid;
|
||||||
ADest.Pen.Color := clBlack;
|
ADest.Pen.Color := clBlack;
|
||||||
if i + AStateEx.Min <= AStateEx.Position then
|
if i <= AStateEx.Position then
|
||||||
ADest.Brush.Color := clDkGray
|
ADest.Brush.Color := clDkGray
|
||||||
else
|
else
|
||||||
ADest.Brush.Color := clWhite;
|
ADest.Brush.Color := clWhite;
|
||||||
@ -192,7 +188,7 @@ begin
|
|||||||
|
|
||||||
// Draw the slider
|
// Draw the slider
|
||||||
|
|
||||||
if i + AStateEx.Min = AStateEx.Position then
|
if i = AStateEx.Position then
|
||||||
begin
|
begin
|
||||||
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6));
|
ADest.Brush.FPColor := TColorToFPColor(ColorToRGB($006BB6E6));
|
||||||
ADest.Brush.Style := bsSolid;
|
ADest.Brush.Style := bsSolid;
|
||||||
|
@ -348,17 +348,25 @@ type
|
|||||||
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
property OnChange: TNotifyEvent read FOnChange write FOnChange;
|
||||||
property Orientation: TProgressBarOrientation read FOrientation write SetOrientation;// default prHorizontal;
|
property Orientation: TProgressBarOrientation read FOrientation write SetOrientation;// default prHorizontal;
|
||||||
property Position: integer read FPosition write SetPosition;
|
property Position: integer read FPosition write SetPosition;
|
||||||
property TabStop default True;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCDListView }
|
{ TCDListView }
|
||||||
|
|
||||||
(* TCDListView = class(TCDControl)
|
TCDListView = class(TCDControl)
|
||||||
private
|
private
|
||||||
DragDropStarted: boolean;
|
DragDropStarted: boolean;
|
||||||
// fields
|
// 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
|
protected
|
||||||
// keyboard
|
{ // keyboard
|
||||||
procedure DoEnter; override;
|
procedure DoEnter; override;
|
||||||
procedure DoExit; override;
|
procedure DoExit; override;
|
||||||
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
procedure KeyDown(var Key: word; Shift: TShiftState); override;
|
||||||
@ -369,16 +377,23 @@ type
|
|||||||
procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
|
procedure MouseMove(Shift: TShiftState; X, Y: integer); override;
|
||||||
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: integer); override;
|
||||||
procedure MouseEnter; override;
|
procedure MouseEnter; override;
|
||||||
procedure MouseLeave; override;
|
procedure MouseLeave; override;}
|
||||||
|
protected
|
||||||
|
FLVState: TCDListViewStateEx;
|
||||||
|
function GetControlId: TCDControlID; override;
|
||||||
|
procedure CreateControlStateEx; override;
|
||||||
|
procedure PrepareControlStateEx; override;
|
||||||
public
|
public
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
procedure EraseBackground(DC: HDC); override;
|
|
||||||
procedure Paint; override;
|
|
||||||
published
|
published
|
||||||
property Color;
|
property Color;
|
||||||
property TabStop default True;
|
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}
|
{TCDTabControl}
|
||||||
|
|
||||||
@ -500,6 +515,65 @@ implementation
|
|||||||
resourcestring
|
resourcestring
|
||||||
sTABSHEET_DEFAULT_NAME = 'CTabSheet';
|
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 }
|
{ TCDProgressBar }
|
||||||
|
|
||||||
procedure TCDProgressBar.SetMax(Value: integer);
|
procedure TCDProgressBar.SetMax(Value: integer);
|
||||||
@ -524,7 +598,7 @@ end;
|
|||||||
|
|
||||||
function TCDProgressBar.GetControlId: TCDControlID;
|
function TCDProgressBar.GetControlId: TCDControlID;
|
||||||
begin
|
begin
|
||||||
Result:=inherited GetControlId;
|
Result := cidProgressBar;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCDProgressBar.CreateControlStateEx;
|
procedure TCDProgressBar.CreateControlStateEx;
|
||||||
@ -535,12 +609,15 @@ end;
|
|||||||
|
|
||||||
procedure TCDProgressBar.PrepareControlStateEx;
|
procedure TCDProgressBar.PrepareControlStateEx;
|
||||||
begin
|
begin
|
||||||
// FPBState.Min:=;
|
FPBState.PercentPosition := (FPosition-FMin)/FMax;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TCDProgressBar.Create(AOwner: TComponent);
|
constructor TCDProgressBar.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
Width := 100;
|
||||||
|
Height := 20;
|
||||||
|
TabStop := False;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TCDProgressBar.Destroy;
|
destructor TCDProgressBar.Destroy;
|
||||||
@ -1266,7 +1343,10 @@ end;
|
|||||||
procedure TCDTrackBar.SetMax(Value: integer);
|
procedure TCDTrackBar.SetMax(Value: integer);
|
||||||
begin
|
begin
|
||||||
if Value = FMax then Exit;
|
if Value = FMax then Exit;
|
||||||
FMax := Value;
|
// Sanity check
|
||||||
|
if Value < FMin then FMax := FMin
|
||||||
|
else FMax := Value;
|
||||||
|
|
||||||
PrepareControlStateEx;
|
PrepareControlStateEx;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -1274,7 +1354,10 @@ end;
|
|||||||
procedure TCDTrackBar.SetMin(Value: integer);
|
procedure TCDTrackBar.SetMin(Value: integer);
|
||||||
begin
|
begin
|
||||||
if Value = FMin then Exit;
|
if Value = FMin then Exit;
|
||||||
FMin := Value;
|
// Sanity check
|
||||||
|
if Value > FMax then FMin := FMax
|
||||||
|
else FMin := Value;
|
||||||
|
|
||||||
PrepareControlStateEx;
|
PrepareControlStateEx;
|
||||||
Invalidate;
|
Invalidate;
|
||||||
end;
|
end;
|
||||||
@ -1350,9 +1433,8 @@ end;
|
|||||||
procedure TCDTrackBar.PrepareControlStateEx;
|
procedure TCDTrackBar.PrepareControlStateEx;
|
||||||
begin
|
begin
|
||||||
inherited PrepareControlStateEx;
|
inherited PrepareControlStateEx;
|
||||||
FTBState.Min := FMin;
|
FTBState.PosCount := FMax - FMin + 1;
|
||||||
FTBState.Max := FMax;
|
FTBState.Position := FPosition - FMin;
|
||||||
FTBState.Position := FPosition;
|
|
||||||
FTBState.Orientation := FOrientation;
|
FTBState.Orientation := FOrientation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -121,20 +121,40 @@ type
|
|||||||
|
|
||||||
TCDTrackBarStateEx = class(TCDControlStateEx)
|
TCDTrackBarStateEx = class(TCDControlStateEx)
|
||||||
public
|
public
|
||||||
Min: integer;
|
PosCount: integer; // The number of positions, calculated as Max - Min + 1
|
||||||
Max: integer;
|
Position: integer; // A zero-based position, therefore it is = Position - Min
|
||||||
Position: integer;
|
|
||||||
Orientation: TTrackBarOrientation;
|
Orientation: TTrackBarOrientation;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TCDProgressBarStateEx = class(TCDControlStateEx)
|
TCDProgressBarStateEx = class(TCDControlStateEx)
|
||||||
public
|
public
|
||||||
Min: integer;
|
PercentPosition: Double;
|
||||||
Max: integer;
|
|
||||||
Position: integer;
|
|
||||||
Orientation: TProgressBarOrientation;
|
Orientation: TProgressBarOrientation;
|
||||||
end;
|
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)
|
TCDCTabControlStateEx = class(TCDControlStateEx)
|
||||||
public
|
public
|
||||||
LeftmostTabVisibleIndex: Integer;
|
LeftmostTabVisibleIndex: Integer;
|
||||||
@ -150,22 +170,12 @@ type
|
|||||||
TCDControlID = (
|
TCDControlID = (
|
||||||
cidControl,
|
cidControl,
|
||||||
// Standard
|
// Standard
|
||||||
cidMenu,
|
cidMenu, cidPopUp, cidButton, cidEdit, cidCheckBox, cidRadioButton,
|
||||||
cidPopUp,
|
cidListBox, cidComboBox, cidGroupBox,
|
||||||
cidButton,
|
|
||||||
cidEdit,
|
|
||||||
cidCheckBox,
|
|
||||||
cidRadioButton,
|
|
||||||
cidListBox,
|
|
||||||
cidComboBox,
|
|
||||||
cidGroupBox,
|
|
||||||
// Additional
|
// Additional
|
||||||
cidStaticText,
|
cidStaticText,
|
||||||
// Common Controls
|
// Common Controls
|
||||||
cidTrackBar,
|
cidTrackBar, cidProgressBar, cidListView, cidCTabControl
|
||||||
cidProgressBar,
|
|
||||||
cidListView,
|
|
||||||
cidCTabControl
|
|
||||||
);
|
);
|
||||||
|
|
||||||
TCDColorPalette = class
|
TCDColorPalette = class
|
||||||
@ -307,6 +317,36 @@ end;
|
|||||||
var
|
var
|
||||||
i: Integer;
|
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 }
|
{ TCDDrawer }
|
||||||
|
|
||||||
constructor TCDDrawer.Create;
|
constructor TCDDrawer.Create;
|
||||||
|
@ -188,7 +188,7 @@ begin
|
|||||||
// Additional
|
// Additional
|
||||||
TCDStaticText,
|
TCDStaticText,
|
||||||
// Common Controls
|
// Common Controls
|
||||||
TCDTrackBar, TCDPageControl, TCDTabControl]);
|
TCDTrackBar, TCDProgressBar, TCDListView, TCDPageControl, TCDTabControl]);
|
||||||
RegisterComponentEditor(TCDPageControl, TCDPageControlEditor);
|
RegisterComponentEditor(TCDPageControl, TCDPageControlEditor);
|
||||||
RegisterComponentEditor(TCDTabSheet, TCDPageControlEditor);
|
RegisterComponentEditor(TCDTabSheet, TCDPageControlEditor);
|
||||||
RegisterNoIcon([TCDTabSheet]);
|
RegisterNoIcon([TCDTabSheet]);
|
||||||
|
Loading…
Reference in New Issue
Block a user