Skip to content

Commit 753ebf9

Browse files
authored
Merge pull request #9 from Embarcadero/hidpi
The export forms dialog has the checkboxes misaligned in HiDPI under …
2 parents c8d6163 + c83e8da commit 753ebf9

File tree

2 files changed

+69
-19
lines changed

2 files changed

+69
-19
lines changed

Source/Design/PythonTools.Design.Forms.pas

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,33 +69,71 @@ implementation
6969

7070
uses
7171
System.Generics.Collections, System.Math,
72-
CommCtrl, UxTheme,
72+
CommCtrl, Vcl.Themes,
7373
ShellApi,
7474
Winapi.Windows,
7575
Vcl.Graphics,
7676
PythonTools.Common;
7777

78+
var
79+
gCheckBoxElement: TCheckBox;
80+
7881
{$R *.dfm}
7982

80-
procedure DrawCheckBox(const ADBGrid: TDBGrid; const AColumn: TColumn; ARect: TRect; const AChecked: boolean);
83+
function RectVCenter(var R: TRect; Bounds: TRect): TRect;
84+
begin
85+
OffsetRect(R, -R.Left, -R.Top);
86+
OffsetRect(R, Bounds.Right - (R.Width div 2), (Bounds.Height - R.Height) div 2);
87+
OffsetRect(R, Bounds.Left, Bounds.Top);
88+
89+
Result := R;
90+
end;
91+
92+
procedure DrawCheckBox(const ADBGrid: TDBGrid; const AColumn: TColumn;
93+
ARect: TRect; const AChecked: boolean; AState: TGridDrawState);
8194
const
8295
IS_CHECKED: array[boolean] of integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
8396
var
8497
LhTheme: Cardinal;
8598
LSize: TSize;
99+
LStyle: TCustomStyleServices;
100+
LBoxSize: TSize;
101+
LDetail: TThemedButton;
102+
LDetails: TThemedElementDetails;
103+
LRect: TRect;
86104
begin
87105
ADBGrid.Canvas.FillRect(ARect);
88-
if UseThemes then begin
89-
LhTheme := OpenThemeData(ADBGrid.Handle, 'BUTTON');
90-
if LhTheme <> 0 then
91-
try
92-
GetThemePartSize(LhTheme, ADBGrid.Canvas.Handle, BP_CHECKBOX, CBS_CHECKEDNORMAL, nil, TS_DRAW, LSize);
93-
DrawThemeBackground(LhTheme, ADBGrid.Canvas.Handle, BP_CHECKBOX,
94-
IfThen(AChecked, CBS_CHECKEDNORMAL, CBS_UNCHECKEDNORMAL),
95-
ARect, nil);
96-
finally
97-
CloseThemeData(LhTheme);
98-
end;
106+
107+
LStyle := StyleServices;
108+
if LStyle.Available then begin
109+
LDetail := tbCheckBoxUncheckedNormal;
110+
111+
if (gdPressed in AState) then
112+
LDetail := tbCheckBoxUncheckedPressed
113+
else if (gdFocused in AState) then
114+
LDetail := tbCheckBoxUncheckedHot;
115+
116+
if AChecked then
117+
LDetail := TThemedButton(Integer(LDetail) + 4);
118+
119+
LDetails := LStyle.GetElementDetails(tbCheckBoxUncheckedNormal);
120+
if not LStyle.GetElementSize(gCheckBoxElement.Handle, LDetails, esActual, LBoxSize, ADBGrid.CurrentPPI) then
121+
begin
122+
LBoxSize.cx := GetSystemMetrics(SM_CXMENUCHECK);
123+
LBoxSize.cy := GetSystemMetrics(SM_CYMENUCHECK);
124+
end;
125+
126+
if LStyle.IsSystemStyle then
127+
LBoxSize := ADBGrid.ScaleValue(LBoxSize);
128+
129+
LRect := Rect(0, 0, LBoxSize.cx, LBoxSize.cy);
130+
RectVCenter(LRect, Rect(0, ARect.Top, ARect.Right, ARect.Bottom));
131+
132+
LDetails := LStyle.GetElementDetails(LDetail);
133+
LStyle.DrawElement(ADBGrid.Canvas.Handle, LDetails, LRect, nil, ADBGrid.CurrentPPI);
134+
135+
if not (gdFocused in AState) then
136+
ADBGrid.Canvas.Brush.Color := LStyle.GetSystemColor(clHighlight);
99137
end else
100138
DrawFrameControl(ADBGrid.Canvas.Handle, ARect, DFC_BUTTON, IS_CHECKED[AChecked]);
101139
end;
@@ -177,8 +215,15 @@ procedure TFormsExportDialog.grFormsDrawColumnCell(Sender: TObject;
177215
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
178216
begin
179217
inherited;
180-
if Column.Field.DataType = ftBoolean then
181-
DrawCheckBox(TDBGrid(Sender), Column, Rect, Column.Field.AsBoolean);
218+
if Column.Field.DataType = ftBoolean then begin
219+
var LRect := System.Classes.Rect(
220+
Rect.Left,
221+
Rect.Top,
222+
Rect.Right - (Column.Width div 2),
223+
Rect.Bottom
224+
);
225+
DrawCheckBox(TDBGrid(Sender), Column, LRect, Column.Field.AsBoolean, State);
226+
end;
182227
end;
183228

184229
procedure TFormsExportDialog.grFormsKeyPress(Sender: TObject; var Key: Char);
@@ -289,13 +334,16 @@ function TFormsExportDialog.Execute(const AModel: TExportFormsDesignModel): bool
289334
procedure TFormsExportDialog.FormCreate(Sender: TObject);
290335
begin
291336
inherited;
337+
gCheckBoxElement := cbShowExportedFiles;
292338
cdsForms.CreateDataSet();
293339
end;
294340

295341
{ TDBGrid }
296342

297343
procedure TDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
298344
AState: TGridDrawState);
345+
const
346+
TEXT_LEFT_OFFSET = 15;
299347
var
300348
LRect: TRect;
301349
LChecked: Boolean;
@@ -305,9 +353,13 @@ procedure TDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect;
305353
if ARow < 0 then
306354
if Columns[ACol].Field.DataType = ftBoolean then begin
307355
LRect := ARect;
308-
LRect.Right := LRect.Right - Canvas.TextWidth(Columns[ACol].Title.Caption) - 25;
356+
LRect.Right := LRect.Right - (
357+
(ColWidths[ACol] div 2)
358+
+ (Canvas.TextWidth(Columns[ACol].Title.Caption) div 2)
359+
+ ScaleValue(TEXT_LEFT_OFFSET)
360+
);
309361
LChecked := Boolean(Columns[ACol].Field.Tag);
310-
DrawCheckBox(Self, Columns[ACol], LRect, LChecked);
362+
DrawCheckBox(Self, Columns[ACol], LRect, LChecked, AState);
311363
end;
312364
end;
313365

Source/Design/PythonTools.Design.dfm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,5 @@ object DesignForm: TDesignForm
1010
Font.Height = -12
1111
Font.Name = 'Segoe UI'
1212
Font.Style = []
13-
OldCreateOrder = True
14-
PixelsPerInch = 96
1513
TextHeight = 15
1614
end

0 commit comments

Comments
 (0)