1
0
mirror of https://github.com/winscp/winscp.git synced 2026-10-24 02:28:55 +03:00

Improvements for right-to-left languages

Source commit: 4c5b18055f4a135e7c8d657905e72cdaf380c059
This commit is contained in:
Martin Prikryl
2015-11-27 09:14:48 +00:00
parent 0b509dbcae
commit 5d86eacb06
5 changed files with 76 additions and 9 deletions

View File

@@ -23,7 +23,7 @@ object LoginDialog: TLoginDialog
Top = 0
Width = 361
Height = 368
Align = alClient
Align = alRight
BevelOuter = bvNone
TabOrder = 0
object ContentsPanel: TPanel
@@ -409,8 +409,7 @@ object LoginDialog: TLoginDialog
Top = 0
Width = 269
Height = 368
Align = alLeft
Anchors = [akLeft, akTop, akRight, akBottom]
Align = alClient
BevelOuter = bvNone
TabOrder = 1
DesignSize = (

View File

@@ -130,6 +130,8 @@ __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
UseDesktopFont(StatusBar);
NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
// particularly to reorder panels on right-to-left bidi mode
ConfigurationChanged();
}
//---------------------------------------------------------------------------
__fastcall TScpCommanderForm::~TScpCommanderForm()
@@ -568,13 +570,15 @@ void __fastcall TScpCommanderForm::ConfigurationChanged()
LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler =
!WinConfiguration->DDExtEnabled;
if ((LocalPanel->Left > RemotePanel->Left) != WinConfiguration->ScpCommander.SwappedPanels)
if (Panel(true)->Left > Panel(false)->Left)
{
DisableAlign();
try
{
int AWidth = ClientWidth;
Panel(false)->Align = alClient;
// In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
Splitter->Align = alLeft;
Panel(true)->Align = alLeft;
TControl * ControlsOrder[] =
{ Panel(true), Splitter, Panel(false) };
@@ -665,8 +669,12 @@ void __fastcall TScpCommanderForm::SetShortcuts()
//---------------------------------------------------------------------------
TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
{
return (WinConfiguration->ScpCommander.SwappedPanels == Left ?
RemotePanel : LocalPanel);
bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
if (IsRightToLeft())
{
SwappedPanels = !SwappedPanels;
}
return (SwappedPanels == Left ? RemotePanel : LocalPanel);
}
//---------------------------------------------------------------------------
TPanel * __fastcall TScpCommanderForm::CurrentPanel()

View File

@@ -65,6 +65,7 @@ type
public
constructor Create(AnOwner: TComponent); override;
procedure UpdateStatus;
function UseRightToLeftAlignment: Boolean; override;
property ActiveColor: TColor index 1 read GetColors write SetColors
default clActiveCaption;
@@ -484,7 +485,7 @@ begin
if (Flags and DT_CALCRECT <> 0) and ((S = '') or ShowAccelChar and
(S[1] = '&') and (S[2] = #0)) then S := S + ' ';
if not ShowAccelChar then Flags := Flags or DT_NOPREFIX;
Flags := DrawTextBiDiModeFlags(Flags);
// have to apply DrawTextBiDiModeFlags if we ever deal with dibi
Canvas.Font := Font;
Width := (Rect.Right - Rect.Left);
@@ -656,6 +657,13 @@ begin
Result := FColors[Index];
end; { GetColors }
function TCustomPathLabel.UseRightToLeftAlignment: Boolean;
begin
// Not sure how to properly deal with RTL atm.
// See also a comment on DrawTextBiDiModeFlags in DoDrawTextIntern
Result := False;
end;
procedure TCustomPathLabel.Paint;
const
Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);

View File

@@ -565,7 +565,18 @@ void __fastcall VerifyControl(TControl * Control)
// check for the presence of items as while the listview does not have
// a handle allocated, item count querying does not work
// (see also a check below)
DebugAssert(!ControlHasRecreationPersistenceData(Control));
if (ControlHasRecreationPersistenceData(Control))
{
// Though is RTL bidi mode is set, the controls are recreated always,
// as we cannot really prevent it. So we force creation here.
DebugAssert(Application->BiDiMode != bdLeftToRight);
TWinControl * WinControl = dynamic_cast<TWinControl *>(Control);
// It must be TWinControl if ControlHasRecreationPersistenceData returned true
if (ALWAYS_TRUE(WinControl != NULL))
{
WinControl->HandleNeeded();
}
}
TCustomListView * ListView = dynamic_cast<TCustomListView *>(Control);
if (ListView != NULL)
@@ -699,6 +710,35 @@ void __fastcall UseSystemSettingsPre(TCustomForm * Control)
ApplySystemSettingsOnControl(Control);
};
//---------------------------------------------------------------------------
static void FlipAnchors(TControl * Control)
{
// WORKAROUND VCL flips the Align, but not the Anchors
TAnchors Anchors = Control->Anchors;
if (Anchors.Contains(akLeft) != Anchors.Contains(akRight))
{
if (Anchors.Contains(akLeft))
{
Anchors << akRight;
Anchors >> akLeft;
}
else
{
Anchors << akLeft;
Anchors >> akRight;
}
}
Control->Anchors = Anchors;
TWinControl * WinControl = dynamic_cast<TWinControl *>(Control);
if (WinControl != NULL)
{
for (int Index = 0; Index < WinControl->ControlCount; Index++)
{
FlipAnchors(WinControl->Controls[Index]);
}
}
}
//---------------------------------------------------------------------------
// Settings that must be set only after whole form is constructed
void __fastcall UseSystemSettingsPost(TCustomForm * Control)
{
@@ -707,6 +747,8 @@ void __fastcall UseSystemSettingsPost(TCustomForm * Control)
if (Flip)
{
Control->FlipChildren(true);
FlipAnchors(Control);
}
ResetSystemSettings(Control);
@@ -1353,6 +1395,9 @@ static void __fastcall FocusableLabelCanvas(TStaticText * StaticText,
}
R.Bottom = R.Top + TextSize.cy;
// Should call ChangeBiDiModeAlignment when UseRightToLeftAlignment(),
// but the label seems to draw the text wrongly aligned, even though
// the alignment is correctly flipped in TCustomStaticText.CreateParams
switch (StaticText->Alignment)
{
case taLeftJustify:

View File

@@ -1099,7 +1099,14 @@ void __fastcall CenterButtonImage(TButton * Button)
{
Padding += L" ";
}
Caption = Padding + Caption;
if (Button->IsRightToLeft())
{
Caption = Caption + Padding;
}
else
{
Caption = Padding + Caption;
}
Button->Caption = Caption;
int CaptionWidth = Canvas->TextWidth(Caption);