浏览代码

Transfer settings hint popup uses the same font as the underlying label

Source commit: aad9d91e06d8cedeef592ca6f90e7c76dd52b994
Martin Prikryl 9 年之前
父节点
当前提交
6536644703

+ 1 - 4
source/forms/Copy.cpp

@@ -332,10 +332,7 @@ void __fastcall TCopyDialog::UpdateControls()
   }
 
   UnicodeString InfoStr = FCopyParams.GetInfoStr(L"; ", FCopyParamAttrs);
-  CopyParamLabel->Caption = InfoStr;
-  CopyParamLabel->Hint = InfoStr;
-  CopyParamLabel->ShowHint =
-    (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
+  SetLabelHintPopup(CopyParamLabel, InfoStr);
 
   bool RemoteTransfer = FLAGSET(FOutputOptions, cooRemoteTransfer);
   EnableControl(QueueCheck2,

+ 2 - 4
source/forms/FullSynchronize.cpp

@@ -109,10 +109,8 @@ void __fastcall TFullSynchronizeDialog::UpdateControls()
     !RemoteDirectoryEdit->Text.IsEmpty());
 
   UnicodeString InfoStr = FCopyParams.GetInfoStr(L"; ", ActualCopyParamAttrs());
-  CopyParamLabel->Caption = InfoStr;
-  CopyParamLabel->Hint = InfoStr;
-  CopyParamLabel->ShowHint =
-    (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
+  SetLabelHintPopup(CopyParamLabel, InfoStr);
+
   SynchronizeBySizeCheck->Caption = SynchronizeTimestampsButton->Checked ?
     LoadStr(SYNCHRONIZE_SAME_SIZE) : UnicodeString(FSynchronizeBySizeCaption);
 

+ 1 - 4
source/forms/Preferences.cpp

@@ -1159,10 +1159,7 @@ void __fastcall TPreferencesDialog::UpdateControls()
         }
       }
     }
-    CopyParamLabel->Caption = InfoStr;
-    CopyParamLabel->Hint = InfoStr;
-    CopyParamLabel->ShowHint =
-      (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
+    SetLabelHintPopup(CopyParamLabel, InfoStr);
 
     EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
     EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);

+ 1 - 4
source/forms/Synchronize.cpp

@@ -154,10 +154,7 @@ void __fastcall TSynchronizeDialog::UpdateControls()
     OptionsGroup->Enabled && FLAGSET(FOptions, soAllowSelectedOnly));
 
   UnicodeString InfoStr = CopyParams.GetInfoStr(L"; ", ActualCopyParamAttrs());
-  CopyParamLabel->Caption = InfoStr;
-  CopyParamLabel->Hint = InfoStr;
-  CopyParamLabel->ShowHint =
-    (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
+  SetLabelHintPopup(CopyParamLabel, InfoStr);
 
   TransferSettingsButton->Style =
     FLAGCLEAR(Options, soDoNotUsePresets) ?

+ 91 - 16
source/windows/GUITools.cpp

@@ -1152,12 +1152,11 @@ __fastcall TScreenTipHintWindow::TScreenTipHintWindow(TComponent * Owner) :
   THintWindow(Owner)
 {
   FParentPainting = false;
-  FMargin = ScaleByPixelsPerInch(6);
 }
 //---------------------------------------------------------------------------
-int __fastcall TScreenTipHintWindow::GetTextFlags()
+int __fastcall TScreenTipHintWindow::GetTextFlags(TControl * Control)
 {
-  return DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DrawTextBiDiModeFlagsReadingOnly();
+  return DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | Control->DrawTextBiDiModeFlagsReadingOnly();
 }
 //---------------------------------------------------------------------------
 bool __fastcall TScreenTipHintWindow::UseBoldShortHint(TControl * HintControl)
@@ -1167,22 +1166,69 @@ bool __fastcall TScreenTipHintWindow::UseBoldShortHint(TControl * HintControl)
     (dynamic_cast<TTBPopupWindow *>(HintControl) != NULL);
 }
 //---------------------------------------------------------------------------
+bool __fastcall TScreenTipHintWindow::IsHintPopup(TControl * HintControl, const UnicodeString & Hint)
+{
+  TLabel * HintLabel = dynamic_cast<TLabel *>(HintControl);
+  return (HintLabel != NULL) && HasLabelHintPopup(HintLabel, Hint);
+}
+//---------------------------------------------------------------------------
+int __fastcall TScreenTipHintWindow::GetMargin(TControl * HintControl, const UnicodeString & Hint)
+{
+  int Result;
+
+  if (IsHintPopup(HintControl, Hint))
+  {
+    Result = 3;
+  }
+  else
+  {
+    Result = 6;
+  }
+
+  Result = ScaleByPixelsPerInch(Result);
+
+  return Result;
+}
+//---------------------------------------------------------------------------
+TFont * __fastcall TScreenTipHintWindow::GetFont(TControl * HintControl, const UnicodeString & Hint)
+{
+  bool HintPopup = IsHintPopup(HintControl, Hint);
+  TFont * Result;
+  if (HintPopup)
+  {
+    Result = dynamic_cast<TLabel *>(HintControl)->Font;
+  }
+  else
+  {
+    Result = Screen->HintFont;
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
+void __fastcall TScreenTipHintWindow::CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint)
+{
+  const int Flags = DT_CALCRECT | GetTextFlags(Control);
+  DrawText(Canvas->Handle, Hint.c_str(), -1, &Rect, Flags);
+}
+//---------------------------------------------------------------------------
 TRect __fastcall TScreenTipHintWindow::CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData)
 {
+  TControl * HintControl = GetHintControl(AData);
+  int Margin = GetMargin(HintControl, AHint);
   const UnicodeString ShortHint = GetShortHint(AHint);
   const UnicodeString LongHint = GetLongHintIfAny(AHint);
 
+  Canvas->Font->Assign(GetFont(HintControl, AHint));
+
   // we do not have a parent form here, so we cannot scale by text height
   const int ScreenTipTextOnlyWidth = ScaleByPixelsPerInch(cScreenTipTextOnlyWidth);
 
   if (!LongHint.IsEmpty())
   {
     // double-margin on the right
-    MaxWidth = ScreenTipTextOnlyWidth - (3 * FMargin);
+    MaxWidth = ScreenTipTextOnlyWidth - (3 * Margin);
   }
 
-  const int Flags = DT_CALCRECT | GetTextFlags();
-
   // Multi line short hints can be twice as wide, to not break the individual lines unless really necessary.
   // (login site tree, clean up dialog list, preferences custom command list, persistent hint, etc).
   // And they also can be twice as wide, to not break the individual lines unless really necessary.
@@ -1191,12 +1237,18 @@ TRect __fastcall TScreenTipHintWindow::CalcHintRect(int MaxWidth, const UnicodeS
     MaxWidth *= 2;
   }
 
-  if (UseBoldShortHint(GetHintControl(AData)))
+  bool HintPopup = IsHintPopup(HintControl, AHint);
+  if (HintPopup)
+  {
+    MaxWidth = HintControl->Width;
+  }
+
+  if (UseBoldShortHint(HintControl))
   {
     Canvas->Font->Style = TFontStyles() << fsBold;
   }
   TRect ShortRect(0, 0, MaxWidth, 0);
-  DrawText(Canvas->Handle, ShortHint.c_str(), -1, &ShortRect, Flags);
+  CalcHintTextRect(this, Canvas, ShortRect, ShortHint);
   Canvas->Font->Style = TFontStyles();
 
   TRect Result;
@@ -1204,17 +1256,26 @@ TRect __fastcall TScreenTipHintWindow::CalcHintRect(int MaxWidth, const UnicodeS
   if (LongHint.IsEmpty())
   {
     Result = ShortRect;
-    Result.Right += 3 * FMargin;
-    Result.Bottom += 2 * FMargin;
+
+    if (HintPopup)
+    {
+      Result.Right = MaxWidth + 2 * Margin;
+    }
+    else
+    {
+      Result.Right += 3 * Margin;
+    }
+
+    Result.Bottom += 2 * Margin;
   }
   else
   {
-    const int LongIndentation = FMargin * 3 / 2;
+    const int LongIndentation = Margin * 3 / 2;
     TRect LongRect(0, 0, MaxWidth - LongIndentation, 0);
-    DrawText(Canvas->Handle, LongHint.c_str(), -1, &LongRect, Flags);
+    CalcHintTextRect(this, Canvas, LongRect, LongHint);
 
     Result.Right = ScreenTipTextOnlyWidth;
-    Result.Bottom = FMargin + ShortRect.Height() + (FMargin / 3 * 5) + LongRect.Height() + FMargin;
+    Result.Bottom = Margin + ShortRect.Height() + (Margin / 3 * 5) + LongRect.Height() + Margin;
   }
 
   // To counter the increase in THintWindow::ActivateHintData
@@ -1228,8 +1289,19 @@ void __fastcall TScreenTipHintWindow::ActivateHintData(const TRect & ARect, cons
   FShortHint = GetShortHint(AHint);
   FLongHint = GetLongHintIfAny(AHint);
   FHintControl = GetHintControl(AData);
+  FMargin = GetMargin(FHintControl, AHint);
+  FHintPopup = IsHintPopup(FHintControl, AHint);
+
+  Canvas->Font->Assign(GetFont(FHintControl, AHint));
+
+  TRect Rect = ARect;
 
-  THintWindow::ActivateHintData(ARect, FShortHint, AData);
+  if (FHintPopup)
+  {
+    Rect.SetLocation(FHintControl->ClientToScreen(TPoint(-FMargin, -FMargin)));
+  }
+
+  THintWindow::ActivateHintData(Rect, FShortHint, AData);
 }
 //---------------------------------------------------------------------------
 TControl * __fastcall TScreenTipHintWindow::GetHintControl(void * Data)
@@ -1279,12 +1351,15 @@ void __fastcall TScreenTipHintWindow::Paint()
     THintWindow::Paint();
   }
 
-  const int Flags = GetTextFlags();
+  const int Flags = GetTextFlags(this);
   const int Margin = FMargin - 1; // 1 = border
 
   TRect Rect = ClientRect;
   Rect.Inflate(-Margin, -Margin);
-  Rect.Right -= FMargin;
+  if (!FHintPopup)
+  {
+    Rect.Right -= FMargin;
+  }
   if (UseBoldShortHint(FHintControl))
   {
     Canvas->Font->Style = TFontStyles() << fsBold;

+ 7 - 1
source/windows/GUITools.h

@@ -126,6 +126,8 @@ public:
   virtual TRect __fastcall CalcHintRect(int MaxWidth, const UnicodeString AHint, void * AData);
   virtual void __fastcall ActivateHintData(const TRect & Rect, const UnicodeString AHint, void * AData);
 
+  static void __fastcall CalcHintTextRect(TControl * Control, TCanvas * Canvas, TRect & Rect, const UnicodeString & Hint);
+
 protected:
   virtual void __fastcall Paint();
   virtual void __fastcall Dispatch(void * AMessage);
@@ -136,10 +138,14 @@ private:
   UnicodeString FShortHint;
   UnicodeString FLongHint;
   TControl * FHintControl;
+  bool FHintPopup;
 
   UnicodeString __fastcall GetLongHintIfAny(const UnicodeString & AHint);
-  int __fastcall GetTextFlags();
+  static int __fastcall GetTextFlags(TControl * Control);
+  bool __fastcall IsHintPopup(TControl * HintControl, const UnicodeString & Hint);
   bool __fastcall UseBoldShortHint(TControl * HintControl);
+  int __fastcall GetMargin(TControl * HintControl, const UnicodeString & Hint);
+  TFont * __fastcall GetFont(TControl * HintControl, const UnicodeString & Hint);
   TControl * __fastcall GetHintControl(void * Data);
 };
 //---------------------------------------------------------------------------

+ 1 - 3
source/windows/TerminalManager.cpp

@@ -758,12 +758,10 @@ void __fastcall TTerminalManager::ApplicationShowHint(UnicodeString & HintStr,
 {
   HintInfo.HintData = HintInfo.HintControl;
   TLabel * HintLabel = dynamic_cast<TLabel *>(HintInfo.HintControl);
-  if ((HintLabel != NULL) && (HintLabel->Caption == HintStr))
+  if ((HintLabel != NULL) && HasLabelHintPopup(HintLabel, HintStr))
   {
     // Hack for transfer setting labels.
     // Should be converted to something like HintLabel()
-    HintInfo.HintPos = HintLabel->ClientToScreen(TPoint(0, 0));
-    HintInfo.HintMaxWidth = HintLabel->Width;
     HintInfo.HideTimeout = 100000; // "almost" never
   }
   else if (dynamic_cast<TProgressBar *>(HintInfo.HintControl) != NULL)

+ 14 - 0
source/windows/VCLCommon.cpp

@@ -1879,6 +1879,20 @@ void __fastcall HotTrackLabel(TLabel * Label)
   Label->OnMouseLeave = MakeMethod<TNotifyEvent>(NULL, HotTrackLabelMouseLeave);
 }
 //---------------------------------------------------------------------------
+void __fastcall SetLabelHintPopup(TLabel * Label, const UnicodeString & Hint)
+{
+  Label->Caption = Hint;
+  Label->Hint = Hint;
+  TRect Rect(0, 0, Label->Width, 0);
+  TScreenTipHintWindow::CalcHintTextRect(Label, Label->Canvas, Rect, Label->Caption);
+  Label->ShowHint = (Rect.Bottom > Label->Height);
+}
+//---------------------------------------------------------------------------
+bool __fastcall HasLabelHintPopup(TLabel * Label, const UnicodeString & HintStr)
+{
+  return (Label->Caption == HintStr);
+}
+//---------------------------------------------------------------------------
 Forms::TMonitor *  __fastcall FormMonitor(TCustomForm * Form)
 {
   Forms::TMonitor * Result;

+ 2 - 0
source/windows/VCLCommon.h

@@ -25,6 +25,8 @@ void __fastcall LinkLabel(TStaticText * StaticText, UnicodeString Url = L"",
 void __fastcall LinkAppLabel(TStaticText * StaticText);
 void __fastcall HintLabel(TStaticText * StaticText, UnicodeString Hint = L"");
 void __fastcall HotTrackLabel(TLabel * Label);
+void __fastcall SetLabelHintPopup(TLabel * Label, const UnicodeString & Hint);
+bool __fastcall HasLabelHintPopup(TLabel * Label, const UnicodeString & HintStr);
 void __fastcall FixComboBoxResizeBug(TCustomComboBox * ComboBox);
 void __fastcall ShowAsModal(TForm * Form, void *& Storage);
 void __fastcall HideAsModal(TForm * Form, void *& Storage);