jvcllaz: Fix lcl scaling of TJvTimeLine; previous scaling solution could not be switched off.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7273 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-01-12 14:47:52 +00:00
parent a023e35566
commit 8cd74ec918
2 changed files with 47 additions and 105 deletions

View File

@ -10,6 +10,7 @@ uses
{$R *.res} {$R *.res}
begin begin
RequireDerivedFormResource:=True;
Application.Scaled := True; Application.Scaled := True;
Application.Initialize; Application.Initialize;
Application.CreateForm(TTimelineMainForm, TimelineMainForm); Application.CreateForm(TTimelineMainForm, TimelineMainForm);

View File

@ -51,6 +51,20 @@ uses
Graphics, Controls, Forms, StdCtrls, ExtCtrls, ImgList, Graphics, Controls, Forms, StdCtrls, ExtCtrls, ImgList,
JvConsts, JvComponent; JvConsts, JvComponent;
const
DEFAULT_TL_ITEM_MARGIN = 2;
DEFAULT_TL_ITEM_WIDTH = 50;
DEFAULT_TL_DAY_LINELENGTH = 4;
DEFAULT_TL_DAY_TEXT_TOP = 5;
DEFAULT_TL_MONTH_LINELENGTH = 10;
DEFAULT_TL_MONTH_TEXT_TOP = 24;
DEFAULT_TL_TOP_OFFSET = 21;
DEFAULT_TL_YEAR_WIDTH = 140;
DEFAULT_TL_YEAR_LINELENGTH = 24;
DEFAULT_TL_YEAR_FONT_SIZE = 18;
DEFAULT_TL_YEAR_TEXT_TOP = 32;
DEFAULT_TL_SCROLL_EDGE_OFFSET = 8;
type type
TJvTimeItems = class; TJvTimeItems = class;
TJvCustomTimeLine = class; TJvCustomTimeLine = class;
@ -77,7 +91,6 @@ type
FSelected: Boolean; FSelected: Boolean;
FEnabled: Boolean; FEnabled: Boolean;
FOnDestroy: TNotifyEvent; FOnDestroy: TNotifyEvent;
function IsStoredWidth: Boolean;
procedure SetEnabled(Value: Boolean); procedure SetEnabled(Value: Boolean);
procedure SetImageOffset(Value: Integer); procedure SetImageOffset(Value: Integer);
procedure SetStyle(Value: TJvTimeItemType); procedure SetStyle(Value: TJvTimeItemType);
@ -115,7 +128,7 @@ type
property Selected: Boolean read FSelected write SetSelected default False; property Selected: Boolean read FSelected write SetSelected default False;
property TextColor: TColor read FTextColor write SetTextColor default clBlack; property TextColor: TColor read FTextColor write SetTextColor default clBlack;
property WidthAs: TJvTimeItemType read FStyle write SetStyle default asPixels; property WidthAs: TJvTimeItemType read FStyle write SetStyle default asPixels;
property Width: Integer read FWidth write SetWidth stored IsStoredWidth; property Width: Integer read FWidth write SetWidth default DEFAULT_TL_ITEM_WIDTH;
property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy; property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
end; end;
@ -191,7 +204,6 @@ type
FList: TList; FList: TList;
FBmp: TBitmap; FBmp: TBitmap;
FYearWidth: TJvYearWidth; FYearWidth: TJvYearWidth;
// FBorderStyle: TBorderStyle;
FUpdate: Integer; FUpdate: Integer;
FMonthWidth: Extended; FMonthWidth: Extended;
FTopOffset: Integer; FTopOffset: Integer;
@ -257,13 +269,9 @@ type
FShowSelection: Boolean; FShowSelection: Boolean;
FOnItemMouseMove: TJvItemMouseMove; FOnItemMouseMove: TJvItemMouseMove;
FSupportsColor: TColor; FSupportsColor: TColor;
function IsStoredTopOffset: Boolean;
function IsStoredYearFont: Boolean;
function IsStoredYearWidth: Boolean;
procedure SetHelperYears(Value: Boolean); procedure SetHelperYears(Value: Boolean);
procedure SetFlat(Value: Boolean); procedure SetFlat(Value: Boolean);
procedure SetScrollArrows(Value: TJvScrollArrows); procedure SetScrollArrows(Value: TJvScrollArrows);
// procedure SetBorderStyle(Value: TBorderStyle);
procedure SetYearFont(Value: TFont); procedure SetYearFont(Value: TFont);
procedure SetYearWidth(Value: TJvYearWidth); procedure SetYearWidth(Value: TJvYearWidth);
procedure SetFirstDate(Value: TDate); procedure SetFirstDate(Value: TDate);
@ -370,10 +378,6 @@ type
property Selected: TJvTimeItem read FSelectedItem write SetSelectedItem; property Selected: TJvTimeItem read FSelectedItem write SetSelectedItem;
property ShowHiddenItemHints: Boolean read FShowHiddenItemHints write property ShowHiddenItemHints: Boolean read FShowHiddenItemHints write
SetShowHiddenItemHints default True; SetShowHiddenItemHints default True;
{
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle
default bsSingle;
}
property DragLine: Boolean read FDragLine write FDragLine default True; property DragLine: Boolean read FDragLine write FDragLine default True;
property ShowItemHint: Boolean read FShowItemHint write FShowItemHint default False; property ShowItemHint: Boolean read FShowItemHint write FShowItemHint default False;
property AutoSize: Boolean read FAutoSize write SetAutoSize default False; property AutoSize: Boolean read FAutoSize write SetAutoSize default False;
@ -381,9 +385,9 @@ type
property MultiSelect: Boolean read FMultiSelect write SetMultiSelect default False; property MultiSelect: Boolean read FMultiSelect write SetMultiSelect default False;
property Flat: Boolean read FFlat write SetFlat default False; property Flat: Boolean read FFlat write SetFlat default False;
// property Hint: TTranslateString read GetHint write SetHint; // property Hint: TTranslateString read GetHint write SetHint;
property YearFont: TFont read FYearFont write SetYearFont stored IsStoredYearFont; property YearFont: TFont read FYearFont write SetYearFont;
property YearWidth: TJvYearWidth read FYearWidth write SetYearWidth stored IsStoredYearWidth; property YearWidth: TJvYearWidth read FYearWidth write SetYearWidth default DEFAULT_TL_YEAR_WIDTH;
property TopOffset: Integer read FTopOffset write SetTopOffset stored IsStoredTopOffset; property TopOffset: Integer read FTopOffset write SetTopOffset default DEFAULT_TL_TOP_OFFSET;
property ShowMonthNames: Boolean read FShowMonths write SetShowMonths; property ShowMonthNames: Boolean read FShowMonths write SetShowMonths;
property ShowSelection: Boolean read FShowSelection write SetShowSelection default False; property ShowSelection: Boolean read FShowSelection write SetShowSelection default False;
property ShowDays: Boolean read FShowDays write SetShowDays default False; property ShowDays: Boolean read FShowDays write SetShowDays default False;
@ -416,7 +420,6 @@ type
property OnItemMoving: TJvItemMovingEvent read FOnItemMoving write FOnItemMoving; property OnItemMoving: TJvItemMovingEvent read FOnItemMoving write FOnItemMoving;
{ LCL scaling } { LCL scaling }
{$IF LCL_FullVersion >= 1080000}
protected protected
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy; procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); override; const AXProportion, AYProportion: Double); override;
@ -426,7 +429,6 @@ type
{$IF LCL_FullVersion >= 2010000} {$IF LCL_FullVersion >= 2010000}
procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override; procedure FixDesignFontsPPI(const ADesignTimePPI: Integer); override;
{$IFEND} {$IFEND}
{$IFEND}
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
@ -539,20 +541,6 @@ uses
Math, Types, DateUtils, Themes, Math, Types, DateUtils, Themes,
JvJCLUtils, JvJVCLUtils; JvJCLUtils, JvJVCLUtils;
const
DEFAULT_ITEM_MARGIN = 2;
DEFAULT_ITEM_WIDTH = 50;
DEFAULT_DAY_LINELENGTH = 4;
DEFAULT_DAY_TEXT_TOP = 5;
DEFAULT_MONTH_LINELENGTH = 10;
DEFAULT_MONTH_TEXT_TOP = 24;
DEFAULT_TOP_OFFSET = 21;
DEFAULT_YEAR_WIDTH = 140;
DEFAULT_YEAR_LINELENGTH = 24;
DEFAULT_YEAR_FONT_SIZE = 18;
DEFAULT_YEAR_TEXT_TOP = 32;
DEFAULT_SCROLL_EDGE_OFFSET = 8;
var var
FInitRepeatPause: Cardinal = 140; FInitRepeatPause: Cardinal = 140;
FRepeatPause: Cardinal = 30; FRepeatPause: Cardinal = 30;
@ -604,7 +592,7 @@ begin
FSelected := False; FSelected := False;
FImageIndex := ACollection.Count - 1; FImageIndex := ACollection.Count - 1;
FLevel := FImageIndex; FLevel := FImageIndex;
FWidth := DEFAULT_ITEM_WIDTH; // will be scaled by TimeLine FWidth := DEFAULT_TL_ITEM_WIDTH; // will be scaled by TimeLine
FStyle := asPixels; FStyle := asPixels;
FImageOffset := 0; FImageOffset := 0;
Update; Update;
@ -743,12 +731,6 @@ begin
end; end;
end; end;
function TJvTimeItem.IsStoredWidth: Boolean;
begin
Result := (WidthAs = asDays) or
(FWidth <> FParent.FTimeLine.Scale96ToFont(DEFAULT_ITEM_WIDTH));
end;
procedure TJvTimeItem.SetWidth(Value: Integer); procedure TJvTimeItem.SetWidth(Value: Integer);
begin begin
if FWidth <> Value then if FWidth <> Value then
@ -813,8 +795,6 @@ end;
function TJvTimeItems.Add: TJvTimeItem; function TJvTimeItems.Add: TJvTimeItem;
begin begin
Result := TJvTimeItem(inherited Add); Result := TJvTimeItem(inherited Add);
if Result.WidthAs = asPixels then
Result.Width := FTimeLine.Scale96ToFont(Result.Width);
Update(Result); Update(Result);
end; end;
@ -1150,15 +1130,12 @@ begin
FBmp := TBitmap.Create; FBmp := TBitmap.Create;
FList := TList.Create; FList := TList.Create;
FHelperYears := True; FHelperYears := True;
ControlStyle := [csOpaque, csClickEvents, csDoubleClicks, ControlStyle := [csOpaque, csClickEvents, csDoubleClicks, csCaptureMouse, csDisplayDragImage];
csCaptureMouse, csDisplayDragImage];
// FBorderStyle := bsSingle;
Color := clWhite; Color := clWhite;
SetLength(FYearList, 0); SetLength(FYearList, 0);
// FYearList := TList.Create;
FScrollArrows := [scrollLeft..scrollDown]; FScrollArrows := [scrollLeft..scrollDown];
FSupportLines := False; FSupportLines := False;
FTopOffset := Scale96ToFont(DEFAULT_TOP_OFFSET); FTopOffset := DEFAULT_TL_TOP_OFFSET;
FShowDays := False; FShowDays := False;
FItemHeight := 0; FItemHeight := 0;
FTopLevel := 0; FTopLevel := 0;
@ -1166,10 +1143,10 @@ begin
FShowItemHint := False; FShowItemHint := False;
FShowHiddenItemHints := True; FShowHiddenItemHints := True;
FFlat := False; FFlat := False;
FYearWidth := Scale96ToFont(DEFAULT_YEAR_WIDTH); FYearWidth := DEFAULT_TL_YEAR_WIDTH;
FYearTextTop := Scale96ToFont(DEFAULT_YEAR_TEXT_TOP); FYearTextTop := DEFAULT_TL_YEAR_TEXT_TOP;
FMonthTextTop := Scale96ToFont(DEFAULT_MONTH_TEXT_TOP); FMonthTextTop := DEFAULT_TL_MONTH_TEXT_TOP;
FDayTextTop := Scale96ToFont(DEFAULT_DAY_TEXT_TOP); FDayTextTop := DEFAULT_TL_DAY_TEXT_TOP;
FMonthWidth := FYearWidth / 12; FMonthWidth := FYearWidth / 12;
FMultiSelect := False; FMultiSelect := False;
FDragLine := True; FDragLine := True;
@ -1177,15 +1154,15 @@ begin
FImageChangeLink := TChangeLink.Create; FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @ImagesChanged; FImageChangeLink.OnChange := @ImagesChanged;
FYearFont := TFont.Create; FYearFont := TFont.Create;
FYearFont.Size := DEFAULT_YEAR_FONT_SIZE; // is scaled automatically FYearFont.Size := DEFAULT_TL_YEAR_FONT_SIZE;
FYearFont.OnChange := @DoYearFontChange; FYearFont.OnChange := @DoYearFontChange;
FYearLineLength := Scale96ToFont(DEFAULT_YEAR_LINELENGTH); FYearLineLength := DEFAULT_TL_YEAR_LINELENGTH;
FMonthLineLength := Scale96ToFont(DEFAULT_MONTH_LINELENGTH); FMonthLineLength := DEFAULT_TL_MONTH_LINELENGTH;
FDayLineLength := Scale96ToFont(DEFAULT_DAY_LINELENGTH); FDayLineLength := DEFAULT_TL_DAY_LINELENGTH;
FItemMargin := Scale96ToFont(DEFAULT_ITEM_MARGIN); FItemMargin := DEFAULT_TL_ITEM_MARGIN;
FNewHeight := 0; FNewHeight := 0;
FAutoSize := False; FAutoSize := False;
FScrollEdgeOffset := Scale96ToFont(DEFAULT_SCROLL_EDGE_OFFSET); FScrollEdgeOffset := DEFAULT_TL_SCROLL_EDGE_OFFSET;
FScrollWidth := GetSystemMetrics(SM_CXHSCROLL); FScrollWidth := GetSystemMetrics(SM_CXHSCROLL);
FScrollHeight := GetSystemMetrics(SM_CXVSCROLL); FScrollHeight := GetSystemMetrics(SM_CXVSCROLL);
UpdateOffset; UpdateOffset;
@ -1199,7 +1176,6 @@ begin
SetLength(FYearList, 0); SetLength(FYearList, 0);
FDragImages.Free; FDragImages.Free;
FCanvas.Free; FCanvas.Free;
// FYearList.Free;
FBmp.Free; FBmp.Free;
FList.Free; FList.Free;
FTimeItems.Free; FTimeItems.Free;
@ -1209,7 +1185,6 @@ begin
inherited Destroy; inherited Destroy;
end; end;
{$IF LCL_FullVersion >= 1080000}
procedure TJvCustomTimeLine.DoAutoAdjustLayout( procedure TJvCustomTimeLine.DoAutoAdjustLayout(
const AMode: TLayoutAdjustmentPolicy; const AMode: TLayoutAdjustmentPolicy;
const AXProportion, AYProportion: Double); const AXProportion, AYProportion: Double);
@ -1220,29 +1195,26 @@ begin
inherited; inherited;
if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then if AMode in [lapAutoAdjustWithoutHorizontalScrolling, lapAutoAdjustForDPI] then
begin begin
if FItemHeight <> 0 then
FItemHeight := round(FItemHeight * AYProportion); FItemHeight := round(FItemHeight * AYProportion);
if IsStoredTopOffset then SetTopOffset(round(FTopOffset * AYProportion));
FTopOffset := round(FTopOffset * AYProportion); SetYearWidth(round(FYearWidth * AXProportion));
if IsStoredYearWidth then
FYearWidth := round(FYearWidth * AYProportion);
for i := 0 to FTimeItems.Count - 1 do for i := 0 to FTimeItems.Count - 1 do
begin begin
item := TJvTimeItem(FTimeItems[i]); item := TJvTimeItem(FTimeItems[i]);
if item.IsStoredWidth and (item.WidthAs = asPixels) then if (item.WidthAs = asPixels) then
item.Width := round(item.Width * AXProportion); item.Width := round(item.Width * AXProportion);
end; end;
// geometries, not stored // geometries, not stored
FYearLineLength := round(DEFAULT_YEAR_LINELENGTH * AYProportion); FYearLineLength := round(DEFAULT_TL_YEAR_LINELENGTH * AYProportion);
FMonthLineLength := round(DEFAULT_MONTH_LINELENGTH * AYProportion); FMonthLineLength := round(DEFAULT_TL_MONTH_LINELENGTH * AYProportion);
FDayLineLength := round(DEFAULT_DAY_LINELENGTH * AYProportion); FDayLineLength := round(DEFAULT_TL_DAY_LINELENGTH * AYProportion);
FYearTextTop := round(DEFAULT_YEAR_TEXT_TOP * AYProportion); FYearTextTop := round(DEFAULT_TL_YEAR_TEXT_TOP * AYProportion);
FMonthTextTop := round(DEFAULT_MONTH_TEXT_TOP * AYProportion); FMonthTextTop := round(DEFAULT_TL_MONTH_TEXT_TOP * AYProportion);
FDayTextTop := round(DEFAULT_DAY_TEXT_TOP * AYProportion); FDayTextTop := round(DEFAULT_TL_DAY_TEXT_TOP * AYProportion);
FScrollEdgeOffset := round(DEFAULT_SCROLL_EDGE_OFFSET * AXProportion); FScrollEdgeOffset := round(DEFAULT_TL_SCROLL_EDGE_OFFSET * AXProportion);
FItemMargin := round(DEFAULT_ITEM_MARGIN * AXProportion); FItemMargin := round(DEFAULT_TL_ITEM_MARGIN * AXProportion);
end; end;
end; end;
@ -1261,7 +1233,6 @@ begin
inherited; inherited;
DoScaleFontPPI(FYearFont, AToPPI, AProportion); DoScaleFontPPI(FYearFont, AToPPI, AProportion);
end; end;
{$IFEND}
procedure TJvCustomTimeLine.DoYearFontChange(Sender: TObject); procedure TJvCustomTimeLine.DoYearFontChange(Sender: TObject);
begin begin
@ -1339,21 +1310,6 @@ begin
FArrows[scrollDown].Visible := FArrows[scrollDown].Visible :=
(scrollDown in ScrollArrows) and (FNewHeight >= Height) and not AutoSize; (scrollDown in ScrollArrows) and (FNewHeight >= Height) and not AutoSize;
end; end;
{
procedure TJvCustomTimeLine.SetBorderStyle(Value: TBorderStyle);
begin
inherited;
exit;
if FBorderStyle <> Value then
begin
FBorderStyle := Value;
// Invalidate;
CreateWnd;
// RecreateWnd; -- wp: Invalidate instead of RecreateWnd
end;
end;
}
procedure TJvCustomTimeLine.SetTopLevel(Value: Integer); procedure TJvCustomTimeLine.SetTopLevel(Value: Integer);
begin begin
@ -1815,7 +1771,7 @@ begin
if csDestroying in ComponentState then if csDestroying in ComponentState then
Exit; Exit;
ACanvas.Pen.Width := 1; ACanvas.Pen.Width := 1;
if (FYearWidth >= 140) or (M mod 3 = 1) then if (FYearWidth >= DEFAULT_TL_YEAR_WIDTH) or (M mod 3 = 1) then
{ draw every month only if it fits } { draw every month only if it fits }
begin begin
ACanvas.MoveTo(StartAt, FTopOffset); ACanvas.MoveTo(StartAt, FTopOffset);
@ -1989,9 +1945,9 @@ begin
if M <> 1 then if M <> 1 then
begin { not a new year, so it's a month } begin { not a new year, so it's a month }
DrawMonth(ACanvas, I, M); DrawMonth(ACanvas, I, M);
if FSupportLines and ((FYearWidth >= 140) or (M mod 3 = 1)) then if FSupportLines and ((FYearWidth >= DEFAULT_TL_YEAR_WIDTH) or (M mod 3 = 1)) then
DrawVertSupport(ACanvas, I); DrawVertSupport(ACanvas, I);
if FShowMonths and (FYearWidth >= 140) then if FShowMonths and (FYearWidth >= DEFAULT_TL_YEAR_WIDTH) then
DrawMonthName(ACanvas, M, I); DrawMonthName(ACanvas, M, I);
if FShowDays and (FYearWidth >= 1200) then if FShowDays and (FYearWidth >= 1200) then
DrawDays(ACanvas, MonthDays[IsLeapYear(Y), M], I); DrawDays(ACanvas, MonthDays[IsLeapYear(Y), M], I);
@ -2768,21 +2724,6 @@ begin
Result := False; Result := False;
end; end;
function TJvCustomTimeLine.IsStoredTopOffset: Boolean;
begin
Result := FTopOffset <> Scale96ToFont(DEFAULT_TOP_OFFSET);
end;
function TJvCustomTimeLine.IsStoredYearFont: Boolean;
begin
Result := true;
end;
function TJvCustomTimeLine.IsStoredYearWidth: Boolean;
begin
Result := FYearWidth <> Scale96ToFont(DEFAULT_YEAR_WIDTH);
end;
procedure TJvCustomTimeLine.SetHorzSupport(const Value: Boolean); procedure TJvCustomTimeLine.SetHorzSupport(const Value: Boolean);
begin begin
if FHorzSupport <> Value then if FHorzSupport <> Value then