Pārlūkot izejas kodu

Allow user to override locale bidi mode and children flipping

Source commit: 5da071248b50f2655dce1d68531373034d5e8b7d
Martin Prikryl 10 gadi atpakaļ
vecāks
revīzija
20c8bd5d18

+ 2 - 2
source/windows/GUITools.cpp

@@ -290,7 +290,7 @@ static UnicodeString __fastcall GetWineHomeFolder()
 UnicodeString __fastcall GetPersonalFolder()
 {
   UnicodeString Result;
-  SpecialFolderLocation(CSIDL_PERSONAL, Result);
+  ::SpecialFolderLocation(CSIDL_PERSONAL, Result);
 
   if (IsWine())
   {
@@ -316,7 +316,7 @@ UnicodeString __fastcall GetPersonalFolder()
 UnicodeString __fastcall GetDesktopFolder()
 {
   UnicodeString Result;
-  SpecialFolderLocation(CSIDL_DESKTOPDIRECTORY, Result);
+  ::SpecialFolderLocation(CSIDL_DESKTOPDIRECTORY, Result);
 
   if (IsWine())
   {

+ 4 - 10
source/windows/UserInterface.cpp

@@ -14,6 +14,7 @@
 #include "WinConfiguration.h"
 #include "TerminalManager.h"
 #include "TextsWin.h"
+#include "WinInterface.h"
 #include "TBXThemes.hpp"
 #include "TBXOfficeXPTheme.hpp"
 #include "TBXOffice2003Theme.hpp"
@@ -300,16 +301,9 @@ void __fastcall ShowNotification(TTerminal * Terminal, const UnicodeString & Str
 //---------------------------------------------------------------------------
 void __fastcall ConfigureInterface()
 {
-  UnicodeString S;
-  S = LoadStr(BIDI_MODE);
-  if (!S.IsEmpty())
-  {
-    Application->BiDiMode = static_cast<TBiDiMode>(StrToInt(S));
-  }
-  else
-  {
-    Application->BiDiMode = bdLeftToRight;
-  }
+  int BidiModeFlag =
+    AdjustLocaleFlag(LoadStr(BIDI_MODE), WinConfiguration->BidiModeOverride, false, bdRightToLeft, bdLeftToRight);
+  Application->BiDiMode = static_cast<TBiDiMode>(BidiModeFlag);
   SetTBXSysParam(TSP_XPVISUALSTYLE, XPVS_AUTOMATIC);
   // Can be called during configuration creation.
   // Skip now, will be called again later.

+ 3 - 2
source/windows/VCLCommon.cpp

@@ -743,8 +743,9 @@ static void FlipAnchors(TControl * Control)
 void __fastcall UseSystemSettingsPost(TCustomForm * Control)
 {
   UnicodeString FlipStr = LoadStr(FLIP_CHILDREN);
-  bool Flip = !FlipStr.IsEmpty() && static_cast<bool>(StrToInt(FlipStr));
-  if (Flip)
+  int FlipChildrenFlag =
+    AdjustLocaleFlag(FlipStr, WinConfiguration->FlipChildrenOverride, false, true, false);
+  if (static_cast<bool>(FlipChildrenFlag))
   {
     Control->FlipChildren(true);
 

+ 14 - 0
source/windows/WinConfiguration.cpp

@@ -548,6 +548,8 @@ void __fastcall TWinConfiguration::Default()
   FExternalSessionInExistingInstance = true;
   FKeepOpenWhenNoSession = false;
   FLocalIconsByExt = false;
+  FBidiModeOverride = lfoLanguageIfRecommended;
+  FFlipChildrenOverride = lfoLanguageIfRecommended;
   FShowTips = true;
   FTipsSeen = L"";
   FTipsShown = Now();
@@ -943,6 +945,8 @@ THierarchicalStorage * TWinConfiguration::CreateScpStorage(bool & SessionList)
     KEY(Bool,     ExternalSessionInExistingInstance); \
     KEY(Bool,     KeepOpenWhenNoSession); \
     KEY(Bool,     LocalIconsByExt); \
+    KEY(Integer,  BidiModeOverride); \
+    KEY(Integer,  FlipChildrenOverride); \
     KEY(Bool,     ShowTips); \
     KEY(String,   TipsSeen); \
     KEY(DateTime, TipsShown); \
@@ -1945,6 +1949,16 @@ void __fastcall TWinConfiguration::SetLocalIconsByExt(bool value)
   SET_CONFIG_PROPERTY(LocalIconsByExt);
 }
 //---------------------------------------------------------------------------
+void __fastcall TWinConfiguration::SetBidiModeOverride(TLocaleFlagOverride value)
+{
+  SET_CONFIG_PROPERTY(BidiModeOverride);
+}
+//---------------------------------------------------------------------------
+void __fastcall TWinConfiguration::SetFlipChildrenOverride(TLocaleFlagOverride value)
+{
+  SET_CONFIG_PROPERTY(FlipChildrenOverride);
+}
+//---------------------------------------------------------------------------
 void __fastcall TWinConfiguration::SetShowTips(bool value)
 {
   SET_CONFIG_PROPERTY(ShowTips);

+ 7 - 0
source/windows/WinConfiguration.h

@@ -8,6 +8,7 @@
 enum TEditor { edInternal, edExternal, edOpen };
 enum TGenerateUrlCodeTarget { guctUrl, guctScript, guctAssembly };
 enum TScriptFormat { sfScriptFile, sfBatchFile, sfCommandLine };
+enum TLocaleFlagOverride { lfoLanguageIfRecommended, lfoLanguage, lfoAlways, lfoNever };
 //---------------------------------------------------------------------------
 #define C(Property) (Property != rhc.Property) ||
 struct TScpExplorerConfiguration {
@@ -421,6 +422,8 @@ private:
   bool FExternalSessionInExistingInstance;
   bool FKeepOpenWhenNoSession;
   bool FLocalIconsByExt;
+  TLocaleFlagOverride FBidiModeOverride;
+  TLocaleFlagOverride FFlipChildrenOverride;
   bool FShowTips;
   UnicodeString FTipsSeen;
   TDateTime FTipsShown;
@@ -510,6 +513,8 @@ private:
   void __fastcall SetExternalSessionInExistingInstance(bool value);
   void __fastcall SetKeepOpenWhenNoSession(bool value);
   void __fastcall SetLocalIconsByExt(bool value);
+  void __fastcall SetBidiModeOverride(TLocaleFlagOverride value);
+  void __fastcall SetFlipChildrenOverride(TLocaleFlagOverride value);
   void __fastcall SetShowTips(bool value);
   void __fastcall SetTipsSeen(UnicodeString value);
   void __fastcall SetTipsShown(TDateTime value);
@@ -673,6 +678,8 @@ public:
   __property bool ExternalSessionInExistingInstance = { read = FExternalSessionInExistingInstance, write = SetExternalSessionInExistingInstance };
   __property bool KeepOpenWhenNoSession = { read = FKeepOpenWhenNoSession, write = SetKeepOpenWhenNoSession };
   __property bool LocalIconsByExt = { read = FLocalIconsByExt, write = SetLocalIconsByExt };
+  __property TLocaleFlagOverride BidiModeOverride = { read = FBidiModeOverride, write = SetBidiModeOverride };
+  __property TLocaleFlagOverride FlipChildrenOverride = { read = FFlipChildrenOverride, write = SetFlipChildrenOverride };
   __property bool ShowTips = { read = FShowTips, write = SetShowTips };
   __property UnicodeString TipsSeen = { read = FTipsSeen, write = SetTipsSeen };
   __property TDateTime TipsShown = { read = FTipsShown, write = SetTipsShown };

+ 28 - 1
source/windows/WinInterface.cpp

@@ -18,7 +18,6 @@
 #include <DateUtils.hpp>
 
 #include "WinInterface.h"
-#include "CustomWinConfiguration.h"
 #include "GUITools.h"
 #include "JclDebug.hpp"
 #include "JclHookExcept.hpp"
@@ -1127,6 +1126,34 @@ void __fastcall CenterButtonImage(TButton * Button)
   }
 }
 //---------------------------------------------------------------------------
+int __fastcall AdjustLocaleFlag(const UnicodeString & S, TLocaleFlagOverride LocaleFlagOverride, bool Recommended, int On, int Off)
+{
+  int Result = !S.IsEmpty() && StrToInt(S);
+  switch (LocaleFlagOverride)
+  {
+    default:
+    case lfoLanguageIfRecommended:
+      if (!Recommended)
+      {
+        Result = Off;
+      }
+      break;
+
+    case lfoLanguage:
+      // noop = as configured in locale
+      break;
+
+    case lfoAlways:
+      Result = On;
+      break;
+
+    case lfoNever:
+      Result = Off;
+      break;
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 void __fastcall SetGlobalMinimizeHandler(TCustomForm * /*Form*/, TNotifyEvent OnMinimize)
 {
   if (GlobalOnMinimize == NULL)

+ 3 - 1
source/windows/WinInterface.h

@@ -5,7 +5,7 @@
 #include <Classes.hpp>
 #include <Buttons.hpp>
 #include <Interface.h>
-#include <GUIConfiguration.h>
+#include <WinConfiguration.h>
 #include <SynchronizeController.h>
 
 #ifdef LOCALINTERFACE
@@ -452,6 +452,8 @@ void __fastcall CenterButtonImage(TButton * Button);
 
 void __fastcall UpgradeSpeedButton(TSpeedButton * Button);
 
+int __fastcall AdjustLocaleFlag(const UnicodeString & S, TLocaleFlagOverride LocaleFlagOverride, bool Recommended, int On, int Off);
+
 void __fastcall SetGlobalMinimizeHandler(TCustomForm * Form, TNotifyEvent OnMinimize);
 void __fastcall ClearGlobalMinimizeHandler(TNotifyEvent OnMinimize);
 void __fastcall CallGlobalMinimizeHandler(TObject * Sender);