Prechádzať zdrojové kódy

Improved design of About window

Source commit: 68b9244ac13c1cbdce21302eba27d774983358b6
Martin Prikryl 7 rokov pred
rodič
commit
ec5977ba27

+ 37 - 7
source/forms/About.cpp

@@ -72,17 +72,35 @@ __fastcall TAboutDialog::TAboutDialog(TComponent * AOwner,
   UseSystemSettings(this);
   LinkLabel(HomepageLabel, LoadStr(HOMEPAGE_URL));
   LinkLabel(ForumUrlLabel, LoadStr(FORUM_URL));
-  ApplicationLabel->ParentFont = true;
-  ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
+
   ApplicationLabel->Caption = AppName;
+  TColor MainInstructionColor;
+  HFONT MainInstructionFont;
+  HFONT InstructionFont;
+  GetInstrutionsTheme(MainInstructionColor, MainInstructionFont, InstructionFont);
+  if (MainInstructionFont != 0)
+  {
+    int PrevHeight = ApplicationLabel->Height;
+    ApplicationLabel->Font->Handle = MainInstructionFont;
+    if (MainInstructionColor != Graphics::clNone)
+    {
+      ApplicationLabel->Font->Color = MainInstructionColor;
+    }
+    ShiftControls(ApplicationLabel->Top + 1, (ApplicationLabel->Height - PrevHeight));
+  }
+  else
+  {
+    ApplicationLabel->ParentFont = true;
+    ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
+  }
+
   WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
 
   if (Registration == NULL)
   {
     RegistrationLabel->Visible = false;
     RegistrationBox->Visible = false;
-    ClientHeight = ClientHeight -
-      (ThirdPartyPanel->Top - RegistrationBox->Top);
+    ShiftControls(RegistrationLabel->Top, (RegistrationBox->Top - ThirdPartyPanel->Top));
   }
   else
   {
@@ -129,7 +147,7 @@ __fastcall TAboutDialog::TAboutDialog(TComponent * AOwner,
     CreateLabelPanel(ThirdPartyPanel, LoadStr(MESSAGE_DISPLAY_ERROR));
   }
 
-  int IconSize = DialogImageSize(this);
+  int IconSize = ScaleByPixelsPerInch(48, this);
   FIconHandle = (HICON)LoadImage(MainInstance, L"MAINICON", IMAGE_ICON, IconSize, IconSize, 0);
   IconPaintBox->Width = IconSize;
   IconPaintBox->Height = IconSize;
@@ -140,6 +158,18 @@ __fastcall TAboutDialog::~TAboutDialog()
   DestroyIcon(FIconHandle);
 }
 //---------------------------------------------------------------------------
+void __fastcall TAboutDialog::ShiftControls(int From, int Diff)
+{
+  for (int Index = 0; Index < Panel->ControlCount; Index++)
+  {
+    if (Panel->Controls[Index]->Top > From)
+    {
+      Panel->Controls[Index]->Top = Panel->Controls[Index]->Top + Diff;
+    }
+  }
+  ClientHeight = ClientHeight + Diff;
+}
+//---------------------------------------------------------------------------
 void __fastcall TAboutDialog::LoadData()
 {
   UnicodeString Version = FConfiguration->VersionStr;
@@ -156,7 +186,7 @@ void __fastcall TAboutDialog::LoadThirdParty()
 {
   FThirdPartyWebBrowser = CreateBrowserViewer(ThirdPartyPanel, L"");
 
-  reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = clBtnFace;
+  reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = ThirdPartyPanel->Color;
 
   NavigateBrowserToUrl(FThirdPartyWebBrowser, L"about:blank");
   DoLoadThirdParty();
@@ -186,7 +216,7 @@ void __fastcall TAboutDialog::DoLoadThirdParty()
     L"{\n"
     L"  font-family: '" + DefaultFont->Name + L"';\n"
     L"  margin: 0.5em;\n"
-    L"  background-color: " + ColorToWebColorStr(Color) + L";\n"
+    L"  background-color: " + ColorToWebColorStr(ThirdPartyPanel->Color) + L";\n"
     L"}\n"
     L"\n"
     L"body\n"

+ 134 - 119
source/forms/About.dfm

@@ -6,99 +6,20 @@ object AboutDialog: TAboutDialog
   BorderIcons = [biSystemMenu, biMinimize, biMaximize, biHelp]
   BorderStyle = bsDialog
   Caption = 'About application'
-  ClientHeight = 487
-  ClientWidth = 394
+  ClientHeight = 501
+  ClientWidth = 410
   Color = clBtnFace
   ParentFont = True
   OldCreateOrder = True
   Position = poOwnerFormCenter
   DesignSize = (
-    394
-    487)
+    410
+    501)
   PixelsPerInch = 96
   TextHeight = 13
-  object ApplicationLabel: TLabel
-    Left = 46
-    Top = 12
-    Width = 52
-    Height = 13
-    Caption = 'Application'
-  end
-  object VersionLabel: TLabel
-    Left = 46
-    Top = 28
-    Width = 127
-    Height = 13
-    Caption = 'Version 2.0.0 (Build 12) XX'
-  end
-  object WinSCPCopyrightLabel: TLabel
-    Left = 46
-    Top = 56
-    Width = 180
-    Height = 13
-    Caption = 'Copyright '#169' 2000-2003 Martin Prikryl'
-  end
-  object ProductSpecificMessageLabel: TLabel
-    Left = 46
-    Top = 100
-    Width = 277
-    Height = 13
-    Caption = 'To send comments and report bugs use support forum at:'
-  end
-  object Label3: TLabel
-    Left = 46
-    Top = 259
-    Width = 91
-    Height = 13
-    Anchors = [akLeft, akBottom]
-    Caption = 'Portions copyright:'
-  end
-  object RegistrationLabel: TLabel
-    Left = 46
-    Top = 144
-    Width = 127
-    Height = 13
-    Anchors = [akLeft, akBottom]
-    Caption = 'This product is licensed to:'
-  end
-  object IconPaintBox: TPaintBox
-    Left = 8
-    Top = 11
-    Width = 32
-    Height = 32
-    OnPaint = IconPaintBoxPaint
-  end
-  object HomepageLabel: TStaticText
-    Left = 46
-    Top = 72
-    Width = 128
-    Height = 17
-    Caption = 'http://XXXXXXwinscp.net/'
-    TabOrder = 2
-    TabStop = True
-  end
-  object ForumUrlLabel: TStaticText
-    Left = 46
-    Top = 116
-    Width = 148
-    Height = 17
-    Caption = 'http://XXXXwinscp.net/forum/'
-    TabOrder = 3
-    TabStop = True
-  end
-  object ThirdPartyPanel: TPanel
-    Left = 46
-    Top = 277
-    Width = 338
-    Height = 168
-    Anchors = [akLeft, akRight, akBottom]
-    BevelKind = bkTile
-    BevelOuter = bvNone
-    TabOrder = 6
-  end
   object OKButton: TButton
-    Left = 227
-    Top = 454
+    Left = 243
+    Top = 468
     Width = 75
     Height = 25
     Anchors = [akRight, akBottom]
@@ -110,18 +31,18 @@ object AboutDialog: TAboutDialog
     OnMouseDown = OKButtonMouseDown
   end
   object LicenseButton: TButton
-    Left = 46
-    Top = 454
+    Left = 62
+    Top = 468
     Width = 75
     Height = 25
     Anchors = [akLeft, akBottom]
     Caption = '&License...'
-    TabOrder = 5
+    TabOrder = 2
     OnClick = LicenseButtonClick
   end
   object HelpButton: TButton
-    Left = 309
-    Top = 454
+    Left = 325
+    Top = 468
     Width = 75
     Height = 25
     Anchors = [akRight, akBottom]
@@ -129,43 +50,137 @@ object AboutDialog: TAboutDialog
     TabOrder = 1
     OnClick = HelpButtonClick
   end
-  object RegistrationBox: TPanel
-    Left = 46
-    Top = 162
-    Width = 338
-    Height = 89
-    Anchors = [akLeft, akTop, akRight]
-    BevelKind = bkTile
+  object Panel: TPanel
+    Left = 0
+    Top = 0
+    Width = 410
+    Height = 460
+    Anchors = [akLeft, akTop, akRight, akBottom]
     BevelOuter = bvNone
-    TabOrder = 4
+    Color = clWindow
+    ParentBackground = False
+    TabOrder = 3
     DesignSize = (
-      334
-      85)
-    object RegistrationSubjectLabel: TLabel
-      Left = 8
-      Top = 8
-      Width = 245
-      Height = 65
-      Anchors = [akLeft, akTop, akRight]
-      AutoSize = False
-      Caption = 'Someone'#13#10'Somewhere, some city'
-      WordWrap = True
+      410
+      460)
+    object ApplicationLabel: TLabel
+      Left = 62
+      Top = 12
+      Width = 52
+      Height = 13
+      Caption = 'Application'
     end
-    object RegistrationLicensesLabel: TLabel
-      Left = 8
-      Top = 43
-      Width = 106
+    object VersionLabel: TLabel
+      Left = 62
+      Top = 28
+      Width = 127
+      Height = 13
+      Caption = 'Version 2.0.0 (Build 12) XX'
+    end
+    object WinSCPCopyrightLabel: TLabel
+      Left = 62
+      Top = 56
+      Width = 180
+      Height = 13
+      Caption = 'Copyright '#169' 2000-2003 Martin Prikryl'
+    end
+    object ProductSpecificMessageLabel: TLabel
+      Left = 62
+      Top = 100
+      Width = 277
+      Height = 13
+      Caption = 'To send comments and report bugs use support forum at:'
+    end
+    object Label3: TLabel
+      Left = 62
+      Top = 259
+      Width = 91
+      Height = 13
+      Caption = 'Portions copyright:'
+    end
+    object RegistrationLabel: TLabel
+      Left = 62
+      Top = 144
+      Width = 127
       Height = 13
-      Caption = 'Number of Licenses: X'
+      Caption = 'This product is licensed to:'
     end
-    object RegistrationProductIdLabel: TStaticText
+    object IconPaintBox: TPaintBox
       Left = 8
-      Top = 65
-      Width = 148
+      Top = 11
+      Width = 48
+      Height = 48
+      OnPaint = IconPaintBoxPaint
+    end
+    object HomepageLabel: TStaticText
+      Left = 62
+      Top = 72
+      Width = 128
       Height = 17
-      Caption = 'Product ID: xxxx-xxxx-xxxxx'
+      Caption = 'http://XXXXXXwinscp.net/'
       TabOrder = 0
-      OnClick = RegistrationProductIdLabelClick
+      TabStop = True
+    end
+    object ForumUrlLabel: TStaticText
+      Left = 62
+      Top = 116
+      Width = 148
+      Height = 17
+      Caption = 'http://XXXXwinscp.net/forum/'
+      TabOrder = 1
+      TabStop = True
+    end
+    object ThirdPartyPanel: TPanel
+      Left = 62
+      Top = 277
+      Width = 338
+      Height = 168
+      Anchors = [akLeft, akTop, akRight]
+      BevelKind = bkTile
+      BevelOuter = bvNone
+      ParentColor = True
+      TabOrder = 2
+    end
+    object RegistrationBox: TPanel
+      Left = 62
+      Top = 162
+      Width = 338
+      Height = 89
+      Anchors = [akLeft, akTop, akRight]
+      BevelKind = bkTile
+      BevelOuter = bvNone
+      ParentBackground = False
+      ParentColor = True
+      TabOrder = 3
+      DesignSize = (
+        334
+        85)
+      object RegistrationSubjectLabel: TLabel
+        Left = 8
+        Top = 8
+        Width = 245
+        Height = 65
+        Anchors = [akLeft, akTop, akRight]
+        AutoSize = False
+        Caption = 'Someone'#13#10'Somewhere, some city'
+        WordWrap = True
+      end
+      object RegistrationLicensesLabel: TLabel
+        Left = 8
+        Top = 43
+        Width = 106
+        Height = 13
+        Caption = 'Number of Licenses: X'
+      end
+      object RegistrationProductIdLabel: TStaticText
+        Left = 8
+        Top = 65
+        Width = 148
+        Height = 17
+        Caption = 'Product ID: xxxx-xxxx-xxxxx'
+        TabOrder = 0
+        OnClick = RegistrationProductIdLabelClick
+      end
     end
   end
 end

+ 2 - 0
source/forms/About.h

@@ -32,6 +32,7 @@ __published:
   TLabel *RegistrationSubjectLabel;
   TPanel *ThirdPartyPanel;
   TPaintBox *IconPaintBox;
+  TPanel *Panel;
   void __fastcall LicenseButtonClick(TObject *Sender);
   void __fastcall HelpButtonClick(TObject *Sender);
   void __fastcall RegistrationProductIdLabelClick(TObject *Sender);
@@ -52,6 +53,7 @@ private:
   void __fastcall AccessViolationTest();
   void __fastcall LookupAddress();
   void __fastcall DoLoadThirdParty();
+  void __fastcall ShiftControls(int From, int Diff);
 
 protected:
   virtual void __fastcall Dispatch(void * Message);

+ 4 - 31
source/forms/MessageDlg.cpp

@@ -16,7 +16,6 @@
 #include <StrUtils.hpp>
 #include <PasTools.hpp>
 #include <Math.hpp>
-#include <vssym32.h>
 #include <WebBrowserEx.hpp>
 #include <Setup.h>
 #include <WinApi.h>
@@ -788,36 +787,10 @@ TForm * __fastcall TMessageForm::Create(const UnicodeString & Msg,
     *TimeoutButton = NULL;
   }
 
-  TColor MainInstructionColor = Graphics::clNone;
-  HFONT MainInstructionFont = 0;
-  HFONT InstructionFont = 0;
-  HTHEME Theme = OpenThemeData(0, L"TEXTSTYLE");
-  if (Theme != NULL)
-  {
-    LOGFONT AFont;
-    COLORREF AColor;
-
-    memset(&AFont, 0, sizeof(AFont));
-    // Using Canvas->Handle in the 2nd argument we can get scales font,
-    // but at this point the form is sometime not scaled yet (difference is particularly for standalone messages like
-    // /UninstallCleanup), so the results are inconsistent.
-    if (GetThemeFont(Theme, NULL, TEXT_MAININSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
-    {
-      MainInstructionFont = CreateFontIndirect(&AFont);
-    }
-    if (GetThemeColor(Theme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &AColor) == S_OK)
-    {
-      MainInstructionColor = (TColor)AColor;
-    }
-
-    memset(&AFont, 0, sizeof(AFont));
-    if (GetThemeFont(Theme, NULL, TEXT_INSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
-    {
-      InstructionFont = CreateFontIndirect(&AFont);
-    }
-
-    CloseThemeData(Theme);
-  }
+  TColor MainInstructionColor;
+  HFONT MainInstructionFont;
+  HFONT InstructionFont;
+  GetInstrutionsTheme(MainInstructionColor, MainInstructionFont, InstructionFont);
 
   TMessageForm * Result = SafeFormCreate<TMessageForm>();
   if (InstructionFont != 0)

+ 36 - 0
source/windows/GUITools.cpp

@@ -23,6 +23,7 @@
 #include <VCLCommon.h>
 #include <WinApi.h>
 #include <Vcl.ScreenTips.hpp>
+#include <vssym32.h>
 
 #include "Animations96.h"
 #include "Animations120.h"
@@ -1010,6 +1011,41 @@ TComponent * __fastcall FindComponentRecursively(TComponent * Root, const Unicod
   return NULL;
 }
 //---------------------------------------------------------------------------
+void __fastcall GetInstrutionsTheme(
+  TColor & MainInstructionColor, HFONT & MainInstructionFont, HFONT & InstructionFont)
+{
+  MainInstructionColor = Graphics::clNone;
+  MainInstructionFont = 0;
+  InstructionFont = 0;
+  HTHEME Theme = OpenThemeData(0, L"TEXTSTYLE");
+  if (Theme != NULL)
+  {
+    LOGFONT AFont;
+    COLORREF AColor;
+
+    memset(&AFont, 0, sizeof(AFont));
+    // Using Canvas->Handle in the 2nd argument we can get scaled font,
+    // but at this point the form is sometime not scaled yet (difference is particularly for standalone messages like
+    // /UninstallCleanup), so the results are inconsistent.
+    if (GetThemeFont(Theme, NULL, TEXT_MAININSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
+    {
+      MainInstructionFont = CreateFontIndirect(&AFont);
+    }
+    if (GetThemeColor(Theme, TEXT_MAININSTRUCTION, 0, TMT_TEXTCOLOR, &AColor) == S_OK)
+    {
+      MainInstructionColor = (TColor)AColor;
+    }
+
+    memset(&AFont, 0, sizeof(AFont));
+    if (GetThemeFont(Theme, NULL, TEXT_INSTRUCTION, 0, TMT_FONT, &AFont) == S_OK)
+    {
+      InstructionFont = CreateFontIndirect(&AFont);
+    }
+
+    CloseThemeData(Theme);
+  }
+}
+//---------------------------------------------------------------------------
 TLocalCustomCommand::TLocalCustomCommand()
 {
 }

+ 2 - 0
source/windows/GUITools.h

@@ -51,6 +51,8 @@ void __fastcall AddBrowserLinkHandler(TWebBrowserEx * WebBrowser,
   const UnicodeString & Url, TNotifyEvent Handler);
 void __fastcall NavigateBrowserToUrl(TWebBrowserEx * WebBrowser, const UnicodeString & Url);
 TComponent * __fastcall FindComponentRecursively(TComponent * Root, const UnicodeString & Name);
+void __fastcall GetInstrutionsTheme(
+  TColor & MainInstructionColor, HFONT & MainInstructionFont, HFONT & InstructionFont);
 //---------------------------------------------------------------------------
 class TLocalCustomCommand : public TFileCustomCommand
 {