Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save window position and dimensions. Improve Preferences Form. #903

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions Source/Common/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ int Preferences::Config_Save()
if (Config(__T("ShellExtension")).empty()) Config(__T("ShellExtension"))=__T("1");
if (Config(__T("ShellExtension_Folder")).empty()) Config(__T("ShellExtension_Folder"))=__T("0");
if (Config(__T("ShellInfoTip")).empty()) Config(__T("ShellInfoTip"))=__T("0");
if (Config(__T("RememberWindowPosition")).empty()) Config(__T("RememberWindowPosition"))=__T("0");
if (Config(__T("RememberWindowDimensions")).empty()) Config(__T("RememberWindowDimensions"))=__T("1");
if (Config(__T("ShowToolBar")).empty()) Config(__T("ShowToolBar"))=__T("1");
if (Config(__T("ShowMenu")).empty()) Config(__T("ShowMenu"))=__T("1");
if (Config(__T("CloseAllAuto")).empty()) Config(__T("CloseAllAuto"))=__T("1");
Expand Down
132 changes: 97 additions & 35 deletions Source/GUI/VCL/GUI_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

//---------------------------------------------------------------------------
#include <vcl.h>
#include <Math.hpp>
#pragma hdrstop
#include "GUI/VCL/GUI_Main.h"
#ifndef MEDIAINFOGUI_PREFS_NO
Expand Down Expand Up @@ -276,6 +277,11 @@ __fastcall TMainF::TMainF(TComponent* Owner)
for (int I1 = 1; I1 < ParamCount(); I1++)
I->Open(Ztring().From_Local(ParamStr(I1).c_str()));
#endif

//Refresh global
FormResize(NULL);
Refresh();

}

//***************************************************************************
Expand Down Expand Up @@ -397,7 +403,7 @@ void __fastcall TMainF::GUI_Configure()

//Configure theme
ConfigTheme();

//Set monospaced font to Cascadia Mono SemiBold if available on current system
if (Screen->Fonts->IndexOf("Cascadia Mono SemiBold") != -1) {
TFont* MonoFont = new TFont;
Expand All @@ -407,42 +413,82 @@ void __fastcall TMainF::GUI_Configure()
Page_Custom_Text->Font = MonoFont;
Page_Sheet_Text->Font = MonoFont;
}
}

//---------------------------------------------------------------------------
void __fastcall TMainF::FormShow(TObject *Sender)
{
//Set window size and position
OSVERSIONINFO osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
int DPI;
if (osvi.dwMajorVersion >= 10 && (osvi.dwMajorVersion > 10 || osvi.dwMinorVersion > 0 || osvi.dwBuildNumber >= 14939))
DPI=GetDpiForWindow(WindowHandle);
else
DPI=GetDeviceCaps(GetDC(NULL), LOGPIXELSX);
float DPIScale=static_cast<float>(DPI)/96;
float ScaledScreenWidth=Screen->Width/DPIScale;
float ScaledScreenHeight=Screen->Height/DPIScale;
Width=500;
Height=400;
if (ScaledScreenWidth>=1024)
Width=700;
if (ScaledScreenWidth>=1280)
Width=830;
if (ScaledScreenHeight>=768)
Height=500;
if (ScaledScreenHeight>=1024)
Height=600;
Width*=DPIScale;
Height*=DPIScale;
Left=(Screen->Width-Width)/2;
Top=(Screen->Height-Height)/2;
//Set window size and position
if (Prefs->Config(__T("RememberWindowDimensions")) == __T("1")) {

int nPrefWidth = Width;
int nPrefHeight = Height;

if (Prefs->Config(__T("FormWidth")).IsNumber())
nPrefWidth = Prefs->Config(__T("FormWidth")).To_int32s();
if (Prefs->Config(__T("FormHeight")).IsNumber())
nPrefHeight = Prefs->Config(__T("FormHeight")).To_int32s();

nPrefWidth = Min(Monitor->WorkareaRect.Width(), nPrefWidth);
nPrefHeight = Min(Monitor->WorkareaRect.Height(), nPrefHeight);

SetBounds(Left, Top, nPrefWidth, nPrefHeight);

}
else {

// using VCL
float fpUnscaledMonitorWidth = Monitor->Width / ScaleFactor;
float fpUnscaledMonitorHeight = Monitor->Height / ScaleFactor;

Width=500;
Height=400;
if (fpUnscaledMonitorWidth>=1024)
Width=700;
if (fpUnscaledMonitorWidth>=1280)
Width=830;
if (fpUnscaledMonitorHeight>=768)
Height=500;
if (fpUnscaledMonitorHeight>=1024)
Height=600;
if (fpUnscaledMonitorHeight>=1440)
Height=900;
Width *= ScaleFactor;
Height *= ScaleFactor;
// note: just use poScreenCenter
// Left=(Screen->Width-Width)/2;
// Top=(Screen->Height-Height)/2;

}
if (Prefs->Config(__T("RememberWindowPosition")) == __T("1")) {

int nPrefTop = 0;
int nPrefLeft = 0;

if (Prefs->Config(__T("FormTop")).IsNumber())
nPrefTop = Prefs->Config(__T("FormTop")).To_int32s();
if (Prefs->Config(__T("FormLeft")).IsNumber())
nPrefLeft = Prefs->Config(__T("FormLeft")).To_int32s();

nPrefTop = Max(nPrefTop, 0);
nPrefTop = Min(nPrefTop, Monitor->WorkareaRect.Height() - Height);
nPrefLeft = Max(nPrefLeft, 0);
nPrefLeft = Min(nPrefLeft, Monitor->WorkareaRect.Width() - Width);
SetBounds(nPrefLeft, nPrefTop, Width, Height);

Position = poDesigned;

}
else {
Position = poScreenCenter;
}

// debug: Dimensions won't restore properly from Maximized state
if ( ((Prefs->Config(__T("RememberWindowPosition")) == __T("1")) ||
(Prefs->Config(__T("RememberWindowDimensions")) == __T("1"))) ) {
int nPrefWindowState = 0;
if (Prefs->Config(__T("WindowState")).IsNumber())
nPrefWindowState = Prefs->Config(__T("WindowState")).To_int32s();
if (nPrefWindowState == (int)TWindowState::wsMaximized)
WindowState = wsMaximized;
}

//Refresh global
FormResize(NULL);
Refresh();
}

//---------------------------------------------------------------------------
Expand All @@ -452,6 +498,22 @@ void __fastcall TMainF::FormClose(TObject *Sender, TCloseAction &Action)
if (FileName_Temp!=__T(""))
File::Delete(FileName_Temp);

if ( ((Prefs->Config(__T("RememberWindowPosition")) == __T("1")) ||
(Prefs->Config(__T("RememberWindowDimensions")) == __T("1"))) ) {
Prefs->Config(__T("WindowState")).From_Number((int)WindowState);
if (WindowState != wsMaximized) {
if (Prefs->Config(__T("RememberWindowPosition")) == __T("1")) {
Prefs->Config(__T("FormTop")).From_Number((int)this->Top);
Prefs->Config(__T("FormLeft")).From_Number((int)this->Left);
}
if (Prefs->Config(__T("RememberWindowDimensions")) == __T("1")) {
Prefs->Config(__T("FormWidth")).From_Number((int)this->Width);
Prefs->Config(__T("FormHeight")).From_Number((int)this->Height);
}
}
Prefs->Config.Save();
}

//The form is closed and all allocated memory for the form is freed.
Action = caFree;
}
Expand Down
1 change: 0 additions & 1 deletion Source/GUI/VCL/GUI_Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ object MainF: TMainF
OnClose = FormClose
OnDestroy = FormDestroy
OnResize = FormResize
OnShow = FormShow
TextHeight = 13
object Page: TPageControl
Left = 40
Expand Down
1 change: 0 additions & 1 deletion Source/GUI/VCL/GUI_Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ class TMainF : public TForm
void __fastcall M_Debug_HeaderClick(TObject *Sender);
void __fastcall M_File_ExitClick(TObject *Sender);
void __fastcall M_File_Open_FileClick(TObject *Sender);
void __fastcall FormShow(TObject *Sender);
void __fastcall M_Debug_AdvancedClick(TObject *Sender);
void __fastcall M_Options_ShowToolBarClick(TObject *Sender);
void __fastcall M_View_EasyClick(TObject *Sender);
Expand Down
55 changes: 40 additions & 15 deletions Source/GUI/VCL/GUI_Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ __fastcall TPreferencesF::TPreferencesF(TComponent* Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::FormCreate(TObject *Sender)
{

GUI_Configure();

}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::ComboBox_Update(TComboBox *CB, Prefs_t List)
{
Expand Down Expand Up @@ -388,6 +396,18 @@ void __fastcall TPreferencesF::CB_InfoTipClick(TObject *Sender)
Prefs->Config(__T("ShellInfoTip"), 1)=__T("0");
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::CB_RememberWindowPositionClick(TObject *Sender)
{
Prefs->Config(__T("RememberWindowPosition"), 1) = CB_RememberWindowPosition->Checked ? __T("1") : __T("0");
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::CB_RememberWindowDimensionsClick(TObject *Sender)
{
Prefs->Config(__T("RememberWindowDimensions"), 1) = CB_RememberWindowDimensions->Checked ? __T("1") : __T("0");
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::CB_ShowToolBarClick(TObject *Sender)
{
Expand Down Expand Up @@ -581,7 +601,7 @@ void __fastcall TPreferencesF::TreeChange(TObject *Sender,
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::General_Language_MoreClick(TObject *Sender)
{
Tree->Select(Tree->Items->Item[7]);
Page->ActivePage = Customize_Language;
}

//---------------------------------------------------------------------------
Expand All @@ -600,25 +620,20 @@ void __fastcall TPreferencesF::General_Output_MoreClick(TObject *Sender)
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::FormShow(TObject *Sender)
void __fastcall TPreferencesF::FormAfterMonitorDpiChanged(TObject *Sender, int OldDPI, int NewDPI)
{
GUI_Configure();
General_Output_SelChange(NULL);

//Not done with BCB because I want to easy select tabs in it
//Page->Top=-6;
//Page->TabHeight=1;
Page->Top=-(Page->TabHeight*1.15); //Replaced above with this to hide tabs better on high-DPI
Page->Height=Page->Height+(Page->TabHeight*1.15); //Required with above line
Cancel->Top=Page->Top+Page->Height+(Cancel->Height*0.15);
OK->Top=Cancel->Top;
ClientHeight=OK->Top+(OK->Height*1.15);

//Make them same size after DPI scaling
General_Language_More->Height=General_Language_Sel->Height;
General_Output_More->Height=General_Output_Sel->Height;
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::FormShow(TObject *Sender)
{
// review: GUI_Configure should be in FormCreate
// GUI_Configure();
General_Output_SelChange(NULL);
}

//---------------------------------------------------------------------------
void __fastcall TPreferencesF::Setup_GeneralShow(TObject *Sender)
{
Expand All @@ -632,6 +647,8 @@ void __fastcall TPreferencesF::Setup_GeneralShow(TObject *Sender)
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::Setup_AdvancedShow(TObject *Sender)
{
CB_RememberWindowPosition->Checked=Prefs->Config(__T("RememberWindowPosition")).To_int32s();
CB_RememberWindowDimensions->Checked=Prefs->Config(__T("RememberWindowDimensions")).To_int32s();
CB_ShowToolBar->Checked=Prefs->Config(__T("ShowToolBar")).To_int32s();
CB_ShowMenu->Checked=Prefs->Config(__T("ShowMenu")).To_int32s();
Advanced_CloseAllAuto->Checked=Prefs->Config(__T("CloseAllAuto")).To_int32s();
Expand Down Expand Up @@ -674,6 +691,10 @@ void __fastcall TPreferencesF::Customize_GraphShow(TObject *Sender)
void __fastcall TPreferencesF::GUI_Configure()
{
//Preparation of GUI

for (int cTabIndex = 0; cTabIndex <= Page->PageCount-1; cTabIndex++)
Page->Pages[cTabIndex]->TabVisible = False;

Tree->FullExpand();
Page->ActivePage=Setup;

Expand Down Expand Up @@ -786,6 +807,10 @@ void __fastcall TPreferencesF::GUI_Configure()
Custom_Edit->Caption=(Prefs->Translate(__T("Edit"))+__T("...")).c_str();
Custom_Delete->Caption=Prefs->Translate(__T("Delete")).c_str();
Custom_New->Caption=(Prefs->Translate(__T("New"))+__T("...")).c_str();

General_Language_More->Height=General_Language_Sel->Height;
General_Output_More->Height=General_Output_Sel->Height;

}

//***************************************************************************
Expand Down
Loading