Skip to content

Commit

Permalink
Bug 1696: Dark theme
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/1696

Source commit: 5093ac8f9a61e0c632fbe5f2d3c55f03a3393dcf
  • Loading branch information
martinprikryl committed Dec 7, 2018
1 parent 946d644 commit 71340fa
Show file tree
Hide file tree
Showing 19 changed files with 358 additions and 47 deletions.
67 changes: 61 additions & 6 deletions source/forms/CustomScpExplorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,8 @@ void __fastcall TCustomScpExplorerForm::UpdateSessionsPageControlHeight()
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::ConfigurationChanged()
{
Color = WinConfiguration->UseDarkTheme() ? TColor(RGB(43, 43, 43)) : clBtnFace;

DebugAssert(Configuration && RemoteDirView);
RemoteDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
RemoteDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
Expand Down Expand Up @@ -8318,6 +8320,31 @@ UnicodeString __fastcall TCustomScpExplorerForm::PathForCaption()
return Result;
}
//---------------------------------------------------------------------------
TColor __fastcall TCustomScpExplorerForm::DefaultPanelColor()
{
TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x20, 0x20, 0x20)) : clWindow);
return Result;
}
//---------------------------------------------------------------------------
TColor __fastcall TCustomScpExplorerForm::PanelColor()
{
TColor Result = (FSessionColor != 0 ? FSessionColor : DefaultPanelColor());
return Result;
}
//---------------------------------------------------------------------------
TColor __fastcall TCustomScpExplorerForm::PanelFontColor(TColor BackgroundColor)
{
TColor Result = (IsDarkColor(BackgroundColor) ? clWhite : clWindowText);
SetContrast(Result, BackgroundColor, 180);
return Result;
}
//---------------------------------------------------------------------------
TColor __fastcall TCustomScpExplorerForm::DisabledPanelColor()
{
TColor Result = (WinConfiguration->UseDarkTheme() ? static_cast<TColor>(RGB(0x40, 0x40, 0x40)) : clBtnFace);
return Result;
}
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::UpdateControls()
{
TTerminalManager::Instance()->UpdateAppTitle();
Expand All @@ -8343,9 +8370,7 @@ void __fastcall TCustomScpExplorerForm::UpdateControls()
ActiveControl = RemoteDirView;
}
}
RemoteDriveView->Enabled = true;
RemoteDirView->Color = (FSessionColor != 0 ? FSessionColor : clWindow);
RemoteDriveView->Color = RemoteDirView->Color;
RemoteDirView->Color = PanelColor();
}
else
{
Expand All @@ -8356,12 +8381,30 @@ void __fastcall TCustomScpExplorerForm::UpdateControls()
// but the false is overriden in the constructor later.
// An even later in TScpCommanderForm::DoShow()
FRemoteDirViewWasFocused = (ActiveControl == RemoteDirView);
EnableControl(RemoteDirView, false);
RemoteDirView->Enabled = false;
RemoteDirView->Color = DisabledPanelColor();
}
EnableControl(RemoteDriveView, false);
}
EnableControl(QueueView3, HasTerminal && Terminal->IsCapable[fsBackgroundTransfers]);

RemoteDirView->Font->Color = PanelFontColor(RemoteDirView->Color);

RemoteDriveView->Enabled = RemoteDirView->Enabled;
RemoteDriveView->Color = RemoteDirView->Color;
RemoteDriveView->Font->Color = RemoteDirView->Font->Color;

QueueView3->Enabled = HasTerminal && Terminal->IsCapable[fsBackgroundTransfers];
QueueView3->Color = QueueView3->Enabled ? DefaultPanelColor() : DisabledPanelColor();
QueueLabelUpdateStatus();

bool UseDarkTheme = WinConfiguration->UseDarkTheme();
AllowDarkModeForWindow(RemoteDirView, UseDarkTheme);
AllowDarkModeForWindow(RemoteDriveView, UseDarkTheme);
AllowDarkModeForWindow(SessionsPageControl, UseDarkTheme);
if (QueueView3->HandleAllocated())
{
AllowDarkModeForWindow(QueueView3, UseDarkTheme);
}

reinterpret_cast<TTBCustomItem *>(GetComponent(fcRemotePathComboBox))->Enabled = HasTerminal;
}
}
Expand Down Expand Up @@ -8689,6 +8732,14 @@ void __fastcall TCustomScpExplorerForm::QueueSplitterDblClick(TObject * /*Sender
PostComponentHide(fcQueueView);
}
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::WMWinIniChange(TMessage & Message)
{
WinConfiguration->ResetSysDarkTheme();
ConfigurationChanged();
ConfigureInterface();
TForm::Dispatch(&Message);
}
//---------------------------------------------------------------------------
void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
{
TMessage * M = static_cast<TMessage*>(Message);
Expand Down Expand Up @@ -8773,6 +8824,10 @@ void __fastcall TCustomScpExplorerForm::Dispatch(void * Message)
CMDpiChanged(*M);
break;

case WM_WININICHANGE:
WMWinIniChange(*M);
break;

default:
TForm::Dispatch(Message);
break;
Expand Down
2 changes: 0 additions & 2 deletions source/forms/CustomScpExplorer.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ object CustomScpExplorerForm: TCustomScpExplorerForm
Height = 240
Cursor = crSizeWE
AutoSnap = False
Color = clBtnFace
MinSize = 70
ParentColor = False
ResizeStyle = rsUpdate
end
object RemoteStatusBar: TTBXStatusBar
Expand Down
5 changes: 5 additions & 0 deletions source/forms/CustomScpExplorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ friend class TAutoBatch;
void __fastcall CloseSessionTab(int Index);
void __fastcall DoFileColorsChanged(TCustomDirView * DirView);
virtual void __fastcall FileColorsChanged();
TColor __fastcall DefaultPanelColor();
TColor __fastcall PanelColor();
TColor __fastcall PanelFontColor(TColor BackgroundColor);
TColor __fastcall DisabledPanelColor();
void __fastcall WMWinIniChange(TMessage & Message);

public:
virtual __fastcall ~TCustomScpExplorerForm();
Expand Down
4 changes: 4 additions & 0 deletions source/forms/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,8 @@ void __fastcall TPreferencesDialog::LoadConfiguration()
BOOLPROP(CopyParamAutoSelectNotice);

// interface
ComboAutoSwitchLoad(ThemeCombo, WinConfiguration->DarkTheme);

switch (CustomWinConfiguration->Interface)
{
case ifCommander:
Expand Down Expand Up @@ -877,6 +879,8 @@ void __fastcall TPreferencesDialog::SaveConfiguration()
BOOLPROP(CopyParamAutoSelectNotice);

// interface
WinConfiguration->DarkTheme = ComboAutoSwitchSave(ThemeCombo);

if (GetInterface() != CustomWinConfiguration->Interface)
{
Configuration->Usage->Inc(L"InterfaceChanges");
Expand Down
39 changes: 36 additions & 3 deletions source/forms/Preferences.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -503,19 +503,19 @@ object PreferencesDialog: TPreferencesDialog
398)
object InterfaceChangeLabel: TLabel
Left = 8
Top = 222
Top = 280
Width = 177
Height = 13
Caption = 'Changes will apply on the next start.'
end
object InterfaceGroup: TGroupBox
Left = 8
Top = 8
Top = 66
Width = 389
Height = 208
Anchors = [akLeft, akTop, akRight, akBottom]
Caption = 'User Interface'
TabOrder = 0
TabOrder = 1
DesignSize = (
389
208)
Expand Down Expand Up @@ -584,6 +584,39 @@ object PreferencesDialog: TPreferencesDialog
OnClick = ControlChange
end
end
object ThemeGroup: TGroupBox
Left = 8
Top = 8
Width = 389
Height = 52
Anchors = [akLeft, akTop, akRight]
Caption = 'Theme'
TabOrder = 0
DesignSize = (
389
52)
object Label7: TLabel
Left = 16
Top = 23
Width = 82
Height = 13
Caption = 'Interface &theme:'
FocusControl = ThemeCombo
end
object ThemeCombo: TComboBox
Left = 132
Top = 18
Width = 141
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
TabOrder = 0
Items.Strings = (
'Automatic'
'Light'
'Dark')
end
end
end
object PanelsSheet: TTabSheet
Tag = 4
Expand Down
3 changes: 3 additions & 0 deletions source/forms/Preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ class TPreferencesDialog : public TForm
TButton *UpFileColorButton;
TButton *DownFileColorButton;
TButton *EditFileColorButton;
TGroupBox *ThemeGroup;
TLabel *Label7;
TComboBox *ThemeCombo;
void __fastcall FormShow(TObject *Sender);
void __fastcall ControlChange(TObject *Sender);
void __fastcall EditorFontButtonClick(TObject *Sender);
Expand Down
12 changes: 11 additions & 1 deletion source/forms/ScpCommander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,18 @@ void __fastcall TScpCommanderForm::UpdateControls()
// command line combo width needs to be updated as caption width has probably changed
ToolBarResize(CommandLineToolbar);
}
LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
if (LocalDirView->HandleAllocated())
{
AllowDarkModeForWindow(LocalDirView, WinConfiguration->UseDarkTheme());
}
if (LocalDriveView->HandleAllocated())
{
AllowDarkModeForWindow(LocalDriveView, WinConfiguration->UseDarkTheme());
}
LocalDirView->Color = PanelColor();
LocalDriveView->Color = LocalDirView->Color;
LocalDirView->Font->Color = PanelFontColor(LocalDirView->Color);
LocalDriveView->Font->Color = LocalDirView->Font->Color;

bool LocalSide = (FCurrentSide == osLocal);
TAction * CurrentCopyAction = LocalSide ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
Expand Down
10 changes: 3 additions & 7 deletions source/forms/ScpCommander.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ inherited ScpCommanderForm: TScpCommanderForm
Height = 298
Constraints.MinHeight = 220
Constraints.MinWidth = 185
ParentColor = True
TabOrder = 1
object RemotePathLabel: TPathLabel [0]
Left = 0
Expand Down Expand Up @@ -1118,7 +1119,6 @@ inherited ScpCommanderForm: TScpCommanderForm
Top = 0
Width = 458
Height = 79
Color = clBtnFace
FixAlign = True
OnContextPopup = DockContextPopup
object RemoteHistoryToolbar: TTBXToolbar
Expand Down Expand Up @@ -1313,7 +1313,6 @@ inherited ScpCommanderForm: TScpCommanderForm
Top = 270
Width = 458
Height = 9
Color = clBtnFace
FixAlign = True
Position = dpBottom
end
Expand All @@ -1322,6 +1321,7 @@ inherited ScpCommanderForm: TScpCommanderForm
Top = 532
Width = 898
Height = 116
ParentColor = True
TabOrder = 2
inherited QueueLabel: TPathLabel
Width = 898
Expand All @@ -1346,10 +1346,10 @@ inherited ScpCommanderForm: TScpCommanderForm
Height = 298
Align = alLeft
BevelOuter = bvNone
Color = clWindow
Constraints.MinHeight = 220
Constraints.MinWidth = 185
ParentBackground = False
ParentColor = True
TabOrder = 0
object LocalPathLabel: TPathLabel
Left = 0
Expand Down Expand Up @@ -1378,9 +1378,7 @@ inherited ScpCommanderForm: TScpCommanderForm
'ctory trees equal.'
Align = alTop
AutoSnap = False
Color = clBtnFace
MinSize = 70
ParentColor = False
ResizeStyle = rsUpdate
end
object LocalStatusBar: TTBXStatusBar
Expand Down Expand Up @@ -1467,7 +1465,6 @@ inherited ScpCommanderForm: TScpCommanderForm
Top = 0
Width = 435
Height = 79
Color = clBtnFace
FixAlign = True
OnContextPopup = DockContextPopup
object LocalHistoryToolbar: TTBXToolbar
Expand Down Expand Up @@ -1676,7 +1673,6 @@ inherited ScpCommanderForm: TScpCommanderForm
Top = 270
Width = 435
Height = 9
Color = clBtnFace
FixAlign = True
Position = dpBottom
end
Expand Down
27 changes: 24 additions & 3 deletions source/packages/filemng/CustomDirView.pas
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ TCustomDirView = class(TCustomIEListView)
procedure LVMSetExtendedListViewStyle(var Message: TMessage); message LVM_SETEXTENDEDLISTVIEWSTYLE;
procedure CMRecreateWnd(var Message: TMessage); message CM_RECREATEWND;
procedure CMDPIChanged(var Message: TMessage); message CM_DPICHANGED;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;

procedure DumbCustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
Expand Down Expand Up @@ -1115,6 +1116,27 @@ procedure TCustomDirView.CMDPIChanged(var Message: TMessage);
NeedImageLists(True);
end;

const
RequiredStyles = LVS_EX_DOUBLEBUFFER or LVS_EX_TRANSPARENTBKGND;

procedure TCustomDirView.CMEnabledChanged(var Message: TMessage);
var
ListViewStyle: DWORD;
begin
inherited;
// We need this so that we can control background color of disabled file panel for dark theme.
// See comment in LVMSetExtendedListViewStyle for an explanation.
ListViewStyle := ListView_GetExtendedListViewStyle(Handle);
if Enabled then
begin
ListView_SetExtendedListViewStyle(Handle, (ListViewStyle or RequiredStyles));
end
else
begin
ListView_SetExtendedListViewStyle(Handle, (ListViewStyle and (not RequiredStyles)));
end;
end;

procedure TCustomDirView.FreeImageLists;
begin
FreeAndNil(FImageList16);
Expand Down Expand Up @@ -1143,11 +1165,10 @@ procedure TCustomDirView.LVMSetExtendedListViewStyle(var Message: TMessage);
// keyboard (Page-up/Down). This gets fixed by LVS_EX_TRANSPARENTBKGND,
// but that works on Vista and newer only. See WMKeyDown
// for workaround on earlier systems.
const
RequiredStyles = LVS_EX_DOUBLEBUFFER or LVS_EX_TRANSPARENTBKGND;
begin
// This prevents TCustomListView.ResetExStyles resetting our styles
if (Message.WParam = 0) and
if Enabled and
(Message.WParam = 0) and
((Message.LParam and RequiredStyles) <> RequiredStyles) then
begin
ListView_SetExtendedListViewStyle(Handle, Message.LParam or RequiredStyles);
Expand Down
1 change: 1 addition & 0 deletions source/packages/tbx/TBX.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,7 @@ function CreateTBXPopupMenu(Owner: TComponent): TTBXPopupMenu;
initialization
FixPlaySoundDelay;
RegisterTBXTheme('OfficeXP', TTBXOfficeXPTheme);
RegisterTBXTheme('DarkOfficeXP', TTBXDarkOfficeXPTheme);
TBXNexus := TTBXNexus.Create('OfficeXP');
TBXMenuAnimation := TTBXMenuAnimation.Create;

Expand Down
4 changes: 2 additions & 2 deletions source/packages/tbx/TBXExtItems.pas
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,8 @@ procedure TTBXEditItemViewer.Paint(const Canvas: TCanvas;
Fnt := Item.EditorFontSettings.CreateTransformedFont(TTBViewAccess(View).GetFont.Handle, C);
OldFnt := SelectObject(DC, Fnt);
SetBkMode(DC, TRANSPARENT);
SetBkColor(DC, GetSysColor(FillColors[Item.Enabled]));
SetTextColor(DC, GetSysColor(TextColors[Item.Enabled]));
SetBkColor(DC, CurrentTheme.GetSysColor(FillColors[Item.Enabled]));
SetTextColor(DC, CurrentTheme.GetSysColor(TextColors[Item.Enabled]));
// WinSCP: Align edit text with toolbar labels
InflateRect(R, 0, -1);
DrawText(DC, PChar(S), Length(S), R, DT_SINGLELINE or DT_NOPREFIX or Alignments[Item.Alignment]);
Expand Down
Loading

0 comments on commit 71340fa

Please sign in to comment.