From c31cae206042ae00b97e41f43baf7421693d2e46 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Thu, 18 Jul 2019 20:53:53 +0200 Subject: [PATCH] Giving up on high DPI readiness - remove tweaks which mostly don't work as expected, and even differently on various computers. Instead, let Windows blur fonts. --- res/manifest.xml | 7 ------- source/bineditor.pas | 4 ++-- source/column_selection.pas | 4 ++-- source/connections.pas | 6 +++--- source/copytable.pas | 4 ++-- source/data_sorting.pas | 10 +++++----- source/editvar.pas | 4 ++-- source/exportgrid.pas | 4 ++-- source/extra_controls.pas | 11 ++--------- source/insertfiles.pas | 4 ++-- source/loaddata.pas | 4 ++-- source/main.pas | 33 ++++++--------------------------- source/options.pas | 4 ++-- source/routine_editor.pas | 4 ++-- source/selectdbobject.pas | 4 ++-- source/sqlhelp.pas | 8 ++++---- source/table_editor.pas | 2 +- source/tabletools.pas | 6 +++--- source/texteditor.pas | 4 ++-- source/trigger_editor.pas | 2 +- source/usermanager.pas | 6 +++--- 21 files changed, 50 insertions(+), 85 deletions(-) diff --git a/res/manifest.xml b/res/manifest.xml index 36996eaa..81263128 100644 --- a/res/manifest.xml +++ b/res/manifest.xml @@ -2,13 +2,6 @@ - - - true/pm - PerMonitorV2 - - - A lightweight, fast and flexible interface to MySQL diff --git a/source/bineditor.pas b/source/bineditor.pas index c9f74e99..b6165b40 100644 --- a/source/bineditor.pas +++ b/source/bineditor.pas @@ -96,8 +96,8 @@ end; procedure TfrmBinEditor.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asMemoEditorWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asMemoEditorHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asMemoEditorWidth, Width); + AppSettings.WriteInt(asMemoEditorHeight, Height); AppSettings.WriteBool(asMemoEditorWrap, btnWrap.Down); end; diff --git a/source/column_selection.pas b/source/column_selection.pas index 6b9f6191..b4812c4d 100644 --- a/source/column_selection.pas +++ b/source/column_selection.pas @@ -55,8 +55,8 @@ end; procedure TColumnSelectionForm.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asColumnSelectorWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asColumnSelectorHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asColumnSelectorWidth, Width); + AppSettings.WriteInt(asColumnSelectorHeight, Height); FCheckedColumns.Free; end; diff --git a/source/connections.pas b/source/connections.pas index 143443ad..245ce23c 100644 --- a/source/connections.pas +++ b/source/connections.pas @@ -348,9 +348,9 @@ end; procedure Tconnform.FormDestroy(Sender: TObject); begin // Save GUI stuff - AppSettings.WriteInt(asSessionManagerListWidth, Round(ListSessions.Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSessionManagerWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSessionManagerWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asSessionManagerListWidth, ListSessions.Width); + AppSettings.WriteInt(asSessionManagerWindowWidth, Width); + AppSettings.WriteInt(asSessionManagerWindowHeight, Height); AppSettings.WriteInt(asSessionManagerWindowLeft, Left); AppSettings.WriteInt(asSessionManagerWindowTop, Top); MainForm.SaveListSetup(ListSessions); diff --git a/source/copytable.pas b/source/copytable.pas index 95c10780..f5612e3d 100644 --- a/source/copytable.pas +++ b/source/copytable.pas @@ -83,8 +83,8 @@ end; procedure TCopyTableForm.FormDestroy(Sender: TObject); begin // Save GUI stuff - AppSettings.WriteInt(asCopyTableWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asCopyTableWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asCopyTableWindowWidth, Width); + AppSettings.WriteInt(asCopyTableWindowHeight, Height); end; diff --git a/source/data_sorting.pas b/source/data_sorting.pas index cf5c1a6e..649b807e 100644 --- a/source/data_sorting.pas +++ b/source/data_sorting.pas @@ -83,12 +83,12 @@ begin Components[i].Free; end; - Margin := Round(3 * DpiScaleFactor(Self)); + Margin := 3; MarginBig := Margin * 2; - Width1 := Round(15 * DpiScaleFactor(Self)); - Width2 := Round(160 * DpiScaleFactor(Self)); - Width3 := Round(23 * DpiScaleFactor(Self)); - Width4 := Round(23 * DpiScaleFactor(Self)); + Width1 := 15; + Width2 := 160; + Width3 := 23; + Width4 := 23; // Set initial width to avoid resizing form to 0 TopPos := pnlBevel.BorderWidth + MarginBig; diff --git a/source/editvar.pas b/source/editvar.pas index c320c3a5..c6f869d7 100644 --- a/source/editvar.pas +++ b/source/editvar.pas @@ -64,8 +64,8 @@ end; procedure TfrmEditVariable.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asEditVarWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asEditVarWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asEditVarWindowWidth, Width); + AppSettings.WriteInt(asEditVarWindowHeight, Height); end; diff --git a/source/exportgrid.pas b/source/exportgrid.pas index 692a9733..cf2eee1b 100644 --- a/source/exportgrid.pas +++ b/source/exportgrid.pas @@ -149,8 +149,8 @@ procedure TfrmExportGrid.FormDestroy(Sender: TObject); begin // Store settings if not FHiddenCopyMode then begin - AppSettings.WriteInt(asGridExportWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asGridExportWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asGridExportWindowWidth, Width); + AppSettings.WriteInt(asGridExportWindowHeight, Height); if ModalResult = mrOK then begin AppSettings.WriteBool(asGridExportOutputCopy, radioOutputCopyToClipboard.Checked); AppSettings.WriteBool(asGridExportOutputFile, radioOutputFile.Checked); diff --git a/source/extra_controls.pas b/source/extra_controls.pas index e927c900..073f08ba 100644 --- a/source/extra_controls.pas +++ b/source/extra_controls.pas @@ -15,7 +15,6 @@ type public constructor Create(AOwner: TComponent); override; procedure AddSizeGrip; - function DpiScaleFactor(Form: TForm=nil): Double; procedure InheritFont(AFont: TFont); protected procedure DoShow; override; @@ -64,12 +63,6 @@ begin end; -function TExtForm.DpiScaleFactor(Form: TForm=nil): Double; -begin - Result := Monitor.PixelsPerInch / FPixelsPerInchOnDefaultMonitor; -end; - - procedure TExtForm.InheritFont(AFont: TFont); var LogFont: TLogFont; @@ -84,12 +77,12 @@ begin // Apply user specified font AFont.Name := GUIFontName; // Set size on top of automatic dpi-increased size - AFont.Size := Round(AppSettings.ReadInt(asGUIFontSize) * DpiScaleFactor); + AFont.Size := AppSettings.ReadInt(asGUIFontSize); end else begin // Apply system font. See issue #3204. // Code taken from http://www.gerixsoft.com/blog/delphi/system-font if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(TLogFont), @LogFont, 0) then begin - AFont.Height := Round(LogFont.lfHeight * DpiScaleFactor); + AFont.Height := LogFont.lfHeight; AFont.Orientation := LogFont.lfOrientation; AFont.Charset := TFontCharset(LogFont.lfCharSet); AFont.Name := PChar(@LogFont.lfFaceName); diff --git a/source/insertfiles.pas b/source/insertfiles.pas index 9e9bbd9e..65696085 100644 --- a/source/insertfiles.pas +++ b/source/insertfiles.pas @@ -129,8 +129,8 @@ end; procedure TfrmInsertFiles.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asFileImportWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asFileImportWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asFileImportWindowWidth, Width); + AppSettings.WriteInt(asFileImportWindowHeight, Height); MainForm.SaveListSetup(ListColumns); MainForm.SaveListSetup(listFiles); end; diff --git a/source/loaddata.pas b/source/loaddata.pas index ef15b30d..cf55ce76 100644 --- a/source/loaddata.pas +++ b/source/loaddata.pas @@ -117,8 +117,8 @@ end; procedure Tloaddataform.FormDestroy(Sender: TObject); begin // Save settings - AppSettings.WriteInt(asCSVImportWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asCSVImportWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asCSVImportWindowWidth, Width); + AppSettings.WriteInt(asCSVImportWindowHeight, Height); AppSettings.WriteString(asCSVImportFilename, editFilename.Text); AppSettings.WriteString(asCSVImportSeparator, editFieldTerminator.Text); AppSettings.WriteString(asCSVImportEncloser, editFieldEncloser.Text); diff --git a/source/main.pas b/source/main.pas index db9116e1..aaa8377a 100644 --- a/source/main.pas +++ b/source/main.pas @@ -658,7 +658,6 @@ type procedure actExitApplicationExecute(Sender: TObject); procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA; procedure CMStyleChanged(var Msg: TMessage); message CM_STYLECHANGED; - procedure DPIChanged(var Msg: TMessage); message WM_DPICHANGED; procedure FormDestroy(Sender: TObject); procedure FormCreate(Sender: TObject); procedure AfterFormCreate; @@ -1922,8 +1921,8 @@ begin // Data-Font: DataGrid.Font.Name := AppSettings.ReadString(asDataFontName); QueryGrid.Font.Name := AppSettings.ReadString(asDataFontName); - DataGrid.Font.Size := Round(AppSettings.ReadInt(asDataFontSize) * DpiScaleFactor(Self)); - QueryGrid.Font.Size := Round(AppSettings.ReadInt(asDataFontSize) * DpiScaleFactor(Self)); + DataGrid.Font.Size := AppSettings.ReadInt(asDataFontSize); + QueryGrid.Font.Size := AppSettings.ReadInt(asDataFontSize); FixVT(DataGrid, AppSettings.ReadInt(asGridRowLineCount)); FixVT(QueryGrid, AppSettings.ReadInt(asGridRowLineCount)); // Load color settings @@ -2537,7 +2536,7 @@ var function CalcPanelWidth(PreferredWidth, Percentage: Integer): Integer; begin - Result := Round(Min(PreferredWidth * DpiScaleFactor(Self), Width / 100 * Percentage)); + Result := Round(Min(PreferredWidth, Width / 100 * Percentage)); end; begin // Exit early when user pressed "Cancel" on connection dialog @@ -7537,8 +7536,6 @@ var i, ColWidth: Integer; ColWidths, ColsVisible, ColPos, Regname: String; OwnerForm: TWinControl; - IsFrame: Boolean; - ScaleDownFactor: Double; begin // Prevent sporadic crash on startup if List = nil then @@ -7547,16 +7544,12 @@ begin ColsVisible := ''; ColPos := ''; OwnerForm := GetParentFormOrFrame(List); - IsFrame := OwnerForm is TFrame; - ScaleDownFactor := DpiScaleFactor(GetParentForm(List) as TForm); for i := 0 to List.Header.Columns.Count - 1 do begin // Column widths if ColWidths <> '' then ColWidths := ColWidths + ','; ColWidth := List.Header.Columns[i].Width; - if IsFrame then - ColWidth := Round(ColWidth / ScaleDownFactor); ColWidths := ColWidths + IntToStr(ColWidth); // Column visibility @@ -8012,14 +8005,14 @@ var begin // Apply somehow changed font settings to all existing grids DataGrid.Font.Name := AppSettings.ReadString(asDataFontName); - DataGrid.Font.Size := Round(AppSettings.ReadInt(asDataFontSize) * DpiScaleFactor(Self)); + DataGrid.Font.Size := AppSettings.ReadInt(asDataFontSize); FixVT(Mainform.DataGrid, AppSettings.ReadInt(asGridRowLineCount)); for i:=Mainform.tabQuery.PageIndex to Mainform.PageControlMain.PageCount-1 do begin QueryTab := Mainform.QueryTabs[i-Mainform.tabQuery.PageIndex]; for j:=0 to QueryTab.ResultTabs.Count-1 do begin Grid := QueryTab.ResultTabs[j].Grid; Grid.Font.Name := AppSettings.ReadString(asDataFontName); - Grid.Font.Size := Round(AppSettings.ReadInt(asDataFontSize) * DpiScaleFactor(Self)); + Grid.Font.Size := AppSettings.ReadInt(asDataFontSize); FixVT(Grid, AppSettings.ReadInt(asGridRowLineCount)); end; end; @@ -11521,7 +11514,7 @@ begin Editor.Color := GetThemeColor(clWindow); Editor.ScrollHintColor := GetThemeColor(clInfoBk); Editor.Font.Name := AppSettings.ReadString(asFontName); - Editor.Font.Size := Round(AppSettings.ReadInt(asFontSize) * DpiScaleFactor(Self)); + Editor.Font.Size := AppSettings.ReadInt(asFontSize); Editor.Gutter.BorderColor := GetThemeColor(clWindow); Editor.Gutter.Color := GetThemeColor(clBtnFace); Editor.Gutter.Font.Name := Editor.Font.Name; @@ -11839,20 +11832,6 @@ begin end; -procedure TMainForm.DPIChanged(var Msg: TMessage); -const - DesignedToolbarHeight = 22; - DesignedToolbarWidth = 23; -begin - inherited; - LogSQL('New PPI:'+ Monitor.PixelsPerInch.ToString, lcDebug); - - // Fix wrong calculated height and width of tool buttons after DPI change / move between monitors - ToolBarMainButtons.ButtonHeight := Round(DesignedToolbarHeight * DpiScaleFactor(Self)); - ToolBarMainButtons.ButtonWidth := Round(DesignedToolbarWidth * DpiScaleFactor(Self)); -end; - - procedure TMainForm.DefaultHandler(var Message); begin if TMessage(Message).Msg = SecondInstMsgId then begin diff --git a/source/options.pas b/source/options.pas index 7fdb9c4c..b59d75a3 100644 --- a/source/options.pas +++ b/source/options.pas @@ -610,8 +610,8 @@ end; procedure Toptionsform.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asPreferencesWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asPreferencesWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asPreferencesWindowWidth, Width); + AppSettings.WriteInt(asPreferencesWindowHeight, Height); end; procedure Toptionsform.FormShow(Sender: TObject); diff --git a/source/routine_editor.pas b/source/routine_editor.pas index a3e3ebcc..d097df75 100644 --- a/source/routine_editor.pas +++ b/source/routine_editor.pas @@ -184,11 +184,11 @@ begin btnSave.Enabled := Modified; btnDiscard.Enabled := Modified; // Buttons are randomly moved, since VirtualTree update, see #440 - btnSave.Top := Height - btnSave.Height - Round(3 * MainForm.DpiScaleFactor); + btnSave.Top := Height - btnSave.Height - 3; btnHelp.Top := btnSave.Top; btnDiscard.Top := btnSave.Top; btnRunProc.Top := btnSave.Top; - btnRunProc.Left := Width - btnRunProc.Width - Round(3 * MainForm.DpiScaleFactor); + btnRunProc.Left := Width - btnRunProc.Width - 3; Mainform.actRunRoutines.Enabled := DBObject.Name <> ''; Mainform.ShowStatusMsg; Screen.Cursor := crDefault; diff --git a/source/selectdbobject.pas b/source/selectdbobject.pas index 1cf355ab..54a770c6 100644 --- a/source/selectdbobject.pas +++ b/source/selectdbobject.pas @@ -74,8 +74,8 @@ end; procedure TfrmSelectDBObject.FormDestroy(Sender: TObject); begin - AppSettings.WriteInt(asSelectDBOWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSelectDBOWindowHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asSelectDBOWindowWidth, Width); + AppSettings.WriteInt(asSelectDBOWindowHeight, Height); end; diff --git a/source/sqlhelp.pas b/source/sqlhelp.pas index 077f22fd..bfe97850 100644 --- a/source/sqlhelp.pas +++ b/source/sqlhelp.pas @@ -265,10 +265,10 @@ procedure TfrmSQLhelp.FormDestroy(Sender: TObject); begin AppSettings.WriteInt(asSQLHelpWindowLeft, Left ); AppSettings.WriteInt(asSQLHelpWindowTop, Top ); - AppSettings.WriteInt(asSQLHelpWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSQLHelpWindowHeight, Round(Height / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSQLHelpPnlLeftWidth, Round(pnlLeft.Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asSQLHelpPnlRightTopHeight, Round(memoDescription.Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asSQLHelpWindowWidth, Width); + AppSettings.WriteInt(asSQLHelpWindowHeight, Height); + AppSettings.WriteInt(asSQLHelpPnlLeftWidth, pnlLeft.Width); + AppSettings.WriteInt(asSQLHelpPnlRightTopHeight, memoDescription.Height); SqlHelpDialog := nil; end; diff --git a/source/table_editor.pas b/source/table_editor.pas index 4cfbeae5..06ecab6f 100644 --- a/source/table_editor.pas +++ b/source/table_editor.pas @@ -353,7 +353,7 @@ begin AlterCodeValid := False; PageControlMainChange(Self); // Foreign key editor needs a hit // Buttons are randomly moved, since VirtualTree update, see #440 - btnSave.Top := Height - btnSave.Height - Round(3 * MainForm.DpiScaleFactor); + btnSave.Top := Height - btnSave.Height - 3; btnHelp.Top := btnSave.Top; btnDiscard.Top := btnSave.Top; UpdateSQLCode; diff --git a/source/tabletools.pas b/source/tabletools.pas index fb363a9e..4411ee72 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -304,9 +304,9 @@ end; procedure TfrmTableTools.FormDestroy(Sender: TObject); begin // Save GUI setup - AppSettings.WriteInt(asTableToolsWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asTableToolsWindowHeight, Round(Height / DpiScaleFactor(Self))); - AppSettings.WriteInt(asTableToolsTreeWidth, Round(TreeObjects.Width / DpiScaleFactor(Self))); + AppSettings.WriteInt(asTableToolsWindowWidth, Width); + AppSettings.WriteInt(asTableToolsWindowHeight, Height); + AppSettings.WriteInt(asTableToolsTreeWidth, TreeObjects.Width); end; diff --git a/source/texteditor.pas b/source/texteditor.pas index 80eedc47..3997b8a2 100644 --- a/source/texteditor.pas +++ b/source/texteditor.pas @@ -225,8 +225,8 @@ end; procedure TfrmTextEditor.FormDestroy(Sender: TObject); begin if WindowState <> wsMaximized then begin - AppSettings.WriteInt(asMemoEditorWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asMemoEditorHeight, Round(Height / DpiScaleFactor(Self))); + AppSettings.WriteInt(asMemoEditorWidth, Width); + AppSettings.WriteInt(asMemoEditorHeight, Height); end; AppSettings.WriteBool(asMemoEditorMaximized, WindowState=wsMaximized); AppSettings.WriteBool(asMemoEditorWrap, btnWrap.Down); diff --git a/source/trigger_editor.pas b/source/trigger_editor.pas index aac34cf9..664808d4 100644 --- a/source/trigger_editor.pas +++ b/source/trigger_editor.pas @@ -164,7 +164,7 @@ begin end; end; // Buttons are randomly moved, since VirtualTree update, see #440 - btnSave.Top := Height - btnSave.Height - Round(3 * MainForm.DpiScaleFactor); + btnSave.Top := Height - btnSave.Height - 3; btnHelp.Top := btnSave.Top; btnDiscard.Top := btnSave.Top; Modification(Self); diff --git a/source/usermanager.pas b/source/usermanager.pas index 1fcb87d7..adbce3f6 100644 --- a/source/usermanager.pas +++ b/source/usermanager.pas @@ -225,9 +225,9 @@ end; procedure TUserManagerForm.FormDestroy(Sender: TObject); begin // FormDestroy: Save GUI setup - AppSettings.WriteInt(asUsermanagerWindowWidth, Round(Width / DpiScaleFactor(Self))); - AppSettings.WriteInt(asUsermanagerWindowHeight, Round(Height / DpiScaleFactor(Self))); - AppSettings.WriteInt(asUsermanagerListWidth, Round(pnlLeft.Width / DpiScaleFactor(Self))); + AppSettings.WriteInt(asUsermanagerWindowWidth, Width); + AppSettings.WriteInt(asUsermanagerWindowHeight, Height); + AppSettings.WriteInt(asUsermanagerListWidth, pnlLeft.Width); Mainform.SaveListSetup(listUsers); end;