Browse Source

Making more space for long donate/buy pledges

(cherry picked from commit 99972dbf76bb8cf66214609179f614ab21627881)

Source commit: bc5991492c37419b30bff81cf894f8e975ce6204
Martin Prikryl 6 years ago
parent
commit
e6f20b672c
4 changed files with 54 additions and 15 deletions
  1. 18 0
      source/forms/MessageDlg.cpp
  2. 1 0
      source/forms/MessageDlg.h
  3. 34 15
      source/windows/Setup.cpp
  4. 1 0
      source/windows/WinInterface.h

+ 18 - 0
source/forms/MessageDlg.cpp

@@ -656,6 +656,18 @@ void __fastcall TMessageForm::InsertPanel(TPanel * Panel)
   }
 }
 //---------------------------------------------------------------------------
+int __fastcall TMessageForm::GetContentWidth()
+{
+  int Result = 0;
+  if (DebugAlwaysTrue(MessageBrowser != NULL))
+  {
+    // we currently use this for updates message box only
+    TControl * ContentsControl = static_cast<TControl *>(DebugNotNull(MessageBrowser))->Parent;
+    Result = ContentsControl->Width;
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 void __fastcall TMessageForm::NavigateToUrl(const UnicodeString & Url)
 {
   if (DebugAlwaysTrue(MessageBrowser != NULL))
@@ -1244,3 +1256,9 @@ void __fastcall NavigateMessageDialogToUrl(TCustomForm * Form, const UnicodeStri
   TMessageForm * MessageForm = DebugNotNull(dynamic_cast<TMessageForm *>(Form));
   MessageForm->NavigateToUrl(Url);
 }
+//---------------------------------------------------------------------------
+int __fastcall GetMessageDialogContentWidth(TCustomForm * Form)
+{
+  TMessageForm * MessageForm = DebugNotNull(dynamic_cast<TMessageForm *>(Form));
+  return MessageForm->GetContentWidth();
+}

+ 1 - 0
source/forms/MessageDlg.h

@@ -20,6 +20,7 @@ public:
 
   virtual int __fastcall ShowModal();
   void __fastcall InsertPanel(TPanel * Panel);
+  int __fastcall GetContentWidth();
   void __fastcall NavigateToUrl(const UnicodeString & Url);
 
 protected:

+ 34 - 15
source/windows/Setup.cpp

@@ -32,6 +32,7 @@
 #include <DateUtils.hpp>
 #include <OperationWithTimeout.hpp>
 #include <Soap.HTTPUtil.hpp>
+#include <Web.HTTPApp.hpp>
 //---------------------------------------------------------------------------
 #define KEY _T("SYSTEM\\CurrentControlSet\\Control\\") \
             _T("Session Manager\\Environment")
@@ -1520,6 +1521,31 @@ static void __fastcall InsertDonateLink(void * /*Data*/, TObject * Sender)
   // OnShow can happen multiple times, for example when showing dialog on start up (being main window)
   if (FindComponentRecursively(Dialog, DonatePanelName) == NULL)
   {
+    UnicodeString DocumentBody = LoadStr(UPDATES_DONATE_HTML);
+    DocumentBody = ReplaceStr(DocumentBody, L"%DONATE_URL%", AppendUrlParams(LoadStr(DONATE_URL), L"automaticupdates=1"));
+    UnicodeString AboutStoreUrl = LoadStr(ABOUT_STORE_URL);
+    DocumentBody = ReplaceStr(DocumentBody, L"%STORE_URL%", AboutStoreUrl);
+    UnicodeString StoreButtonUrl = ProgramUrl(LoadStr(STORE_GET_IMG_URL));
+    StoreButtonUrl = HTMLEscape(StoreButtonUrl);
+    UnicodeString StoreButton =
+      FORMAT(L"<img src=\"%s\" style=\"height: 1.8em; vertical-align: -0.4em; padding-top: 0.2em; border: 0;\">", (StoreButtonUrl));
+    UnicodeString StoreUrl = FMTLOAD(STORE_URL, (L"update"));
+    UnicodeString StoreLink = FORMAT(L"<a href=\"%s\">%s</a>", (StoreUrl, StoreButton));
+
+    UnicodeString PlainBody = HTMLDecode(DocumentBody);
+    int P1, P2;
+    while (((P1 = PlainBody.Pos(L"<")) > 0) && ((P2 = PlainBody.Pos(L">")) > 0) && (P1 < P2))
+    {
+      PlainBody.Delete(P1, P2 - P1 + 1);
+    }
+    while ((P1 = PlainBody.Pos(L"  ")) > 0)
+    {
+      PlainBody.Delete(P1, 1);
+    }
+
+    DocumentBody = ReplaceStr(DocumentBody, L"%GET_IMG% ", FORMAT(L"%s&nbsp;", (StoreLink)));
+    DocumentBody = FORMAT(L"<p>%s</p>", (DocumentBody));
+
     TPanel * Panel = CreateBlankPanel(Dialog);
     Panel->Name = DonatePanelName;
     Panel->Caption = UnicodeString(); // override default use of Name
@@ -1528,7 +1554,14 @@ static void __fastcall InsertDonateLink(void * /*Data*/, TObject * Sender)
     ReadyBrowserForStreaming(DonateBrowser);
     WaitBrowserToIdle(DonateBrowser);
 
-    DonateBrowser->Height = ScaleByTextHeight(Dialog, 36);
+    int Height = 36;
+    int TextWidth = Dialog->Canvas->TextWidth(PlainBody);
+    int ContentLimit = (GetMessageDialogContentWidth(Dialog) * 5 / 3);
+    if (TextWidth > ContentLimit)
+    {
+      Height = Height * 3 / 2;
+    }
+    DonateBrowser->Height = ScaleByTextHeight(Dialog, Height);
 
     DonateBrowser->Top = 0;
     DonateBrowser->Left = 0;
@@ -1539,20 +1572,6 @@ static void __fastcall InsertDonateLink(void * /*Data*/, TObject * Sender)
     // (what should not happen)
     InsertPanelToMessageDialog(Dialog, Panel);
 
-    UnicodeString DocumentBody = LoadStr(UPDATES_DONATE_HTML);
-    DocumentBody = ReplaceStr(DocumentBody, L"%DONATE_URL%", AppendUrlParams(LoadStr(DONATE_URL), L"automaticupdates=1"));
-    UnicodeString AboutStoreUrl = LoadStr(ABOUT_STORE_URL);
-    DocumentBody = ReplaceStr(DocumentBody, L"%STORE_URL%", AboutStoreUrl);
-    UnicodeString StoreButtonUrl = ProgramUrl(LoadStr(STORE_GET_IMG_URL));
-    StoreButtonUrl = HTMLEscape(StoreButtonUrl);
-    UnicodeString StoreButton =
-      FORMAT(L"<img src=\"%s\" style=\"height: 1.8em; vertical-align: -0.4em; padding-top: 0.2em; border: 0;\">", (StoreButtonUrl));
-    UnicodeString StoreUrl = FMTLOAD(STORE_URL, (L"update"));
-    UnicodeString StoreLink = FORMAT(L"<a href=\"%s\">%s</a>", (StoreUrl, StoreButton));
-    DocumentBody = ReplaceStr(DocumentBody, L"%GET_IMG% ", FORMAT(L"%s&nbsp;", (StoreLink)));
-
-    DocumentBody = FORMAT(L"<p>%s</p>", (DocumentBody));
-
     UnicodeString Document = GenerateAppHtmlPage(Dialog->Font, Panel, DocumentBody, true);
     LoadBrowserDocument(DonateBrowser, Document);
     HideBrowserScrollbars(DonateBrowser);

+ 1 - 0
source/windows/WinInterface.h

@@ -411,6 +411,7 @@ TForm * __fastcall CreateMoreMessageDialogEx(const UnicodeString Message, TStrin
   TQueryType Type, unsigned int Answers, UnicodeString HelpKeyword, const TMessageParams * Params);
 unsigned int __fastcall ExecuteMessageDialog(TForm * Dialog, unsigned int Answers, const TMessageParams * Params);
 void __fastcall InsertPanelToMessageDialog(TCustomForm * Form, TPanel * Panel);
+int __fastcall GetMessageDialogContentWidth(TCustomForm * Form);
 void __fastcall NavigateMessageDialogToUrl(TCustomForm * Form, const UnicodeString & Url);
 extern const UnicodeString MessagePanelName;
 extern const UnicodeString MainMessageLabelName;