Skip to content

Commit

Permalink
Merge pull request #892 from cjee21/GUI-fix
Browse files Browse the repository at this point in the history
Windows GUI: Various improvements/fixes
  • Loading branch information
JeromeMartinez authored Jun 29, 2024
2 parents b13a280 + 62df94a commit dda61d6
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 121 deletions.
40 changes: 0 additions & 40 deletions Project/BCB/GUI/MediaInfo_GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,6 @@
#include <tchar.h>
//---------------------------------------------------------------------------









































#include <Vcl.Styles.hpp>
#include <Vcl.Themes.hpp>
USEFORM("..\..\..\Source\GUI\VCL\GUI_Preferences_Language.cpp", Preferences_LanguageF);
Expand Down
38 changes: 19 additions & 19 deletions Source/GUI/VCL/GUI_About.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ object AboutF: TAboutF
OnShow = FormShow
TextHeight = 14
object Translator: TLabel
Left = 278
Left = 275
Top = 497
Width = 247
Width = 245
Height = 15
Alignment = taRightJustify
AutoSize = False
Expand All @@ -31,9 +31,9 @@ object AboutF: TAboutF
ParentFont = False
end
object Memo: TMemo
Left = 142
Top = 1
Width = 385
Left = 144
Top = 4
Width = 376
Height = 313
TabStop = False
BevelEdges = []
Expand All @@ -52,9 +52,9 @@ object AboutF: TAboutF
TabOrder = 2
end
object OK: TButton
Left = 445
Top = 573
Width = 81
Left = 441
Top = 567
Width = 79
Height = 27
Caption = 'OK'
Default = True
Expand All @@ -63,7 +63,7 @@ object AboutF: TAboutF
end
object WebSite: TButton
Left = 80
Top = 489
Top = 486
Width = 193
Height = 27
Caption = 'Go to WebSite'
Expand All @@ -72,7 +72,7 @@ object AboutF: TAboutF
end
object ToolBar1: TToolBar
Left = 6
Top = 489
Top = 486
Width = 73
Height = 89
Align = alNone
Expand All @@ -95,7 +95,7 @@ object AboutF: TAboutF
end
object NewVersion: TButton
Left = 80
Top = 516
Top = 513
Width = 193
Height = 27
Caption = 'Check for newest version'
Expand All @@ -104,16 +104,16 @@ object AboutF: TAboutF
end
object Donate: TButton
Left = 80
Top = 543
Top = 540
Width = 193
Height = 27
Caption = 'Donate'
TabOrder = 5
OnClick = DonateClick
end
object ToolBar2: TToolBar
Left = 0
Top = 1
Left = 4
Top = 4
Width = 136
Height = 161
Align = alNone
Expand All @@ -136,26 +136,26 @@ object AboutF: TAboutF
end
object WriteMe: TButton
Left = 80
Top = 570
Top = 567
Width = 193
Height = 27
Caption = 'Write me'
TabOrder = 7
OnClick = WriteMeClick
end
object WriteToTranslator: TButton
Left = 334
Left = 329
Top = 516
Width = 193
Width = 191
Height = 27
Caption = 'Write To translator'
TabOrder = 8
OnClick = WriteToTranslatorClick
end
object Sponsor_Label: TLinkLabel
Left = 145
Left = 142
Top = 380
Width = 380
Width = 378
Height = 18
Alignment = taRightJustify
AutoSize = False
Expand Down
63 changes: 35 additions & 28 deletions Source/GUI/VCL/GUI_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,29 @@ void __fastcall TMainF::ConfigTheme()
}
}

//Function to inject a CSS style into html documents to make their look match the dark mode style
std::wstring __fastcall TMainF::InjectDarkModeHTMLStyle(const wchar_t* HTMLDocument) {
const wchar_t* InsertionPoint = wcsstr(HTMLDocument, L"<head>");
const wchar_t* StyleContent = L"<style>body { background-color: #1F1F1F; color: #FFFFFF; }</style>";

if (InsertionPoint != nullptr) {
size_t InsertionPos = InsertionPoint - HTMLDocument + wcslen(L"<head>");
std::wstring ModifiedHTML(HTMLDocument);
ModifiedHTML.insert(InsertionPos, StyleContent);
return ModifiedHTML;
} else {
return HTMLDocument;
}
//Function to inject a CSS style into HTML documents to workaround GUI HTML rendering issues
std::wstring __fastcall TMainF::InjectHTMLStyle(const wchar_t* HTMLDocument) {

auto InsertText = [](std::wstring Text, const wchar_t* InsertPointText, const wchar_t* TextToInsert) -> std::wstring {
auto InsertionPoint = std::search(Text.begin(), Text.end(), InsertPointText, InsertPointText + wcslen(InsertPointText));
if (InsertionPoint != Text.end()) {
size_t InsertionPos = InsertionPoint - Text.begin() + wcslen(InsertPointText);
Text.insert(InsertionPos, TextToInsert);
}
return Text;
};

std::wstring modifiedHTML(HTMLDocument);
const wchar_t* StyleContent = L"";

//IE Engine workarounds
if (TStyleManager::ActiveStyle == TStyleManager::Style[DARK_MODE_STYLE]) //app is currently in dark mode
StyleContent = L"<meta http-equiv='X-UA-Compatible' content='IE=edge'><style>body { background-color: #121212; color: #FFFFFF; } table { border:1px solid blue; }</style>";
else
StyleContent = L"<meta http-equiv='X-UA-Compatible' content='IE=edge'><style>table { border:1px solid navy; }</style>";
modifiedHTML = InsertText(modifiedHTML, L"<head>", StyleContent);

return modifiedHTML;
}

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -243,8 +253,9 @@ __fastcall TMainF::TMainF(TComponent* Owner)
Footer_Button->Visible=false;

//Configuration of properties
Page->Top=-6; //Not done with BCB because I want to easy select tabs in it
Page->TabHeight=1; //Not done with BCB because I want to easy select tabs in it
//Page->Top=-6; //Not done with BCB because I want to easy select tabs in it
//Page->TabHeight=1; //Not done with BCB because I want to easy select tabs in it
Page->Top=-(Page->TabHeight*1.15); //Replaced above with this to hide tabs better on high-DPI
Page_Position=-1;
Caption=MEDIAINFO_TITLE;

Expand Down Expand Up @@ -321,15 +332,15 @@ void __fastcall TMainF::GUI_Configure()
language_source_path = language_source_path / "Plugin\\Language";
if (fs::exists(language_path) && fs::is_directory(language_path)) {
try {
for (const auto& entry : fs::directory_iterator(language_source_path)) {
fs::path current = entry.path();
fs::path target = language_path / current.filename();
for (const auto& entry : fs::directory_iterator(language_source_path)) {
fs::path current = entry.path();
fs::path target = language_path / current.filename();
if (fs::is_regular_file(current)) {
fs::copy_file(current, target, fs::copy_options::overwrite_existing);
fs::copy_file(current, target, fs::copy_options::overwrite_existing);
}
}
//ShowMessage("Success updating translations!");
} catch (const fs::filesystem_error& e) {
}
//ShowMessage("Success updating translations!");
} catch (const fs::filesystem_error& e) {
ShowMessage("Error updating translations in %APPDATA%!");
}
}
Expand Down Expand Up @@ -1000,9 +1011,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page)
//Creating file
Ztring S1=I->Inform().c_str();
File F;
if (TStyleManager::ActiveStyle == TStyleManager::Style[DARK_MODE_STYLE]) {
S1=InjectDarkModeHTMLStyle(I->Inform().c_str());
}
S1=InjectHTMLStyle(I->Inform().c_str());
if (FileName_Temp==__T(""))
{
FileName_Temp=FileName::TempFileName_Create(__T("MI_"));
Expand All @@ -1022,9 +1031,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page)
Temp+=L"about:<html><head></head><body>";
Temp+=TempA.To_Unicode();
Temp+=L"</body></html>";
if (TStyleManager::ActiveStyle == TStyleManager::Style[DARK_MODE_STYLE]) {
Temp=InjectDarkModeHTMLStyle(Temp.c_str());
}
Temp=InjectHTMLStyle(Temp.c_str());
Page_HTML_HTML->Navigate((MediaInfoNameSpace::Char*)Temp.c_str());
}
}
Expand Down
2 changes: 1 addition & 1 deletion Source/GUI/VCL/GUI_Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ object MainF: TMainF
ParentFont = False
ParentShowHint = False
ShowHint = False
TabHeight = 20
TabHeight = 22
TabOrder = 0
TabStop = False
object Page_Easy: TTabSheet
Expand Down
2 changes: 1 addition & 1 deletion Source/GUI/VCL/GUI_Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class TMainF : public TForm
const UnicodeString DARK_MODE_STYLE = "Windows11 Modern Dark"; // Name of style for dark mode
bool __fastcall WindowsDarkModeEnabled();
void __fastcall ConfigTheme();
std::wstring __fastcall InjectDarkModeHTMLStyle(const wchar_t* HTMLDocument);
std::wstring __fastcall InjectHTMLStyle(const wchar_t* HTMLDocument);
public: // User declarations
MESSAGE void __fastcall HandleDropFiles (TMessage&);
BEGIN_MESSAGE_MAP
Expand Down
8 changes: 5 additions & 3 deletions Source/GUI/VCL/GUI_Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void __fastcall TPreferencesF::TreeChange(TObject *Sender,
//---------------------------------------------------------------------------
void __fastcall TPreferencesF::General_Language_MoreClick(TObject *Sender)
{
Tree->Select(Tree->Items->Item[6]);
Tree->Select(Tree->Items->Item[7]);
}

//---------------------------------------------------------------------------
Expand All @@ -606,8 +606,10 @@ void __fastcall TPreferencesF::FormShow(TObject *Sender)
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=-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;
OK->Top=Cancel->Top;
ClientHeight=OK->Top+OK->Height;
Expand Down
Loading

0 comments on commit dda61d6

Please sign in to comment.