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

Windows GUI: Dark mode for HTML view #857

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Source/GUI/VCL/GUI_Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ bool __fastcall TMainF::WindowsDarkModeEnabled()
return DarkModeEnabled;
}

//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;
}
}

//---------------------------------------------------------------------------

//***************************************************************************
Expand Down Expand Up @@ -460,7 +475,7 @@ void __fastcall TMainF::FormResize(TObject *Sender)
{
Page_Sheet_X_Web[KindOfStream]->Top =Page_Sheet_X[KindOfStream]->Top+1;
Page_Sheet_X_Web[KindOfStream]->Left=Page_Sheet_X[KindOfStream]->Width;
}
}
if (!Page_Sheet_X[KindOfStream+1]) //reached the bottom
{
//Bottom
Expand Down Expand Up @@ -904,6 +919,9 @@ void __fastcall TMainF::Refresh(TTabSheet *Page)
//Creating file
Ztring S1=I->Inform().c_str();
File F;
if (M_Options_Darkmode->Checked) {
S1=InjectDarkModeHTMLStyle(I->Inform().c_str());
}
if (FileName_Temp==__T(""))
{
FileName_Temp=FileName::TempFileName_Create(__T("MI_"));
Expand All @@ -920,9 +938,12 @@ void __fastcall TMainF::Refresh(TTabSheet *Page)
{
Ztring TempA; TempA=Prefs->Translate(__T("At least one file"));
Ztring Temp;
Temp+=L"about:<html><body>";
Temp+=L"about:<html><head></head><body>";
Temp+=TempA.To_Unicode();
Temp+=L"</body></html>";
if (M_Options_Darkmode->Checked) {
Temp=InjectDarkModeHTMLStyle(Temp.c_str());
}
Page_HTML_HTML->Navigate((MediaInfoNameSpace::Char*)Temp.c_str());
}
}
Expand Down Expand Up @@ -980,7 +1001,7 @@ void __fastcall TMainF::Refresh(TTabSheet *Page)
I->Option_Static(__T("Inform"), Prefs->Details[Prefs_Custom].Read());
Ztring S1=I->Inform();
if (S1.empty())
S1=Prefs->Translate(__T("At least one file")).c_str();
S1=Prefs->Translate(__T("At least one file")).c_str();

if (I->Option_Static(__T("Inform_Get"), __T("")) == __T("Graph_Svg"))
{
Expand Down
1 change: 1 addition & 0 deletions Source/GUI/VCL/GUI_Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ class TMainF : public TForm
const UnicodeString LIGHT_MODE_STYLE = "Windows"; // Name of style for light mode;
const UnicodeString DARK_MODE_STYLE = "Windows11 Modern Dark"; // Name of style for dark mode
bool __fastcall WindowsDarkModeEnabled();
std::wstring __fastcall InjectDarkModeHTMLStyle(const wchar_t* HTMLDocument);
public: // User declarations
MESSAGE void __fastcall HandleDropFiles (TMessage&);
BEGIN_MESSAGE_MAP
Expand Down
Loading