Browse Source

Bug fix: Caption of permissions group labels disappears when hovered over on Windows 11

Might be Windows 11 glitch, but the implementation of the labels/buttons was so clumsy, it was worth fixing anyway

Source commit: 972bb0c34180fa63a618466fcb451dd31cce6732
Martin Prikryl 1 year ago
parent
commit
33096a57b4
3 changed files with 104 additions and 36 deletions
  1. 85 2
      source/forms/Rights.cpp
  2. 10 31
      source/forms/Rights.dfm
  3. 9 3
      source/forms/Rights.h

+ 85 - 2
source/forms/Rights.cpp

@@ -428,6 +428,7 @@ void __fastcall TRightsFrame::CreateWnd()
     Height += 2 * GetSystemMetricsForControl(Parent, SM_CYBORDER);
   }
   TFrame::CreateWnd();
+  UpdateButtons();
 }
 //---------------------------------------------------------------------------
 void __fastcall TRightsFrame::SetPopup(bool value)
@@ -508,6 +509,36 @@ void __fastcall TRightsFrame::CMDialogKey(TCMDialogKey & Message)
   {
     TFrame::Dispatch(&Message);
   }
+
+  if (Message.CharCode == VK_MENU)
+  {
+    UpdateButtons();
+  }
+}
+//---------------------------------------------------------------------------
+bool TRightsFrame::IsButtonAccel(TCMDialogChar & Message, TSpeedButton * Button, TWinControl * FocusControl)
+{
+  bool Result = IsAccel(Message.CharCode, Button->Caption) && Button->Visible && Button->Enabled;
+  if (Result)
+  {
+    Perform(WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR, UISF_HIDEFOCUS), 0);
+    FocusControl->SetFocus();
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
+void TRightsFrame::CMDialogChar(TCMDialogChar & Message)
+{
+  if (IsButtonAccel(Message, OwnerButton, OwnerReadCheck) ||
+      IsButtonAccel(Message, GroupButton, GroupReadCheck) ||
+      IsButtonAccel(Message, OthersButton, OthersReadCheck))
+  {
+    Message.Result = 1;
+  }
+  else
+  {
+    TFrame::Dispatch(&Message);
+  }
 }
 //---------------------------------------------------------------------------
 void __fastcall TRightsFrame::CMCancelMode(TCMCancelMode & Message)
@@ -523,6 +554,45 @@ void __fastcall TRightsFrame::CMCancelMode(TCMCancelMode & Message)
   TFrame::Dispatch(&Message);
 }
 //---------------------------------------------------------------------------
+void TRightsFrame::CMDPIChanged(TMessage & Message)
+{
+  TFrame::Dispatch(&Message);
+  UpdateButtons();
+}
+//---------------------------------------------------------------------------
+void TRightsFrame::WMUpdateUIState(TMessage & Message)
+{
+  TFrame::Dispatch(&Message);
+  UpdateButtons();
+}
+//---------------------------------------------------------------------------
+void TRightsFrame::UpdateButton(TSpeedButton * Button, UnicodeString & Caption)
+{
+  if (Caption.IsEmpty())
+  {
+    Caption = Button->Caption;
+    DebugAssert(Caption.Pos(L"&") >= 0);
+  }
+  int Padding = ScaleByTextHeight(Button, 4);
+  std::unique_ptr<TCanvas> Canvas(CreateControlCanvas(Button));
+  UnicodeString ACaption = Caption;
+  UnicodeString StrippedCaption = StripHotkey(ACaption);
+  if ((SendMessage(Handle, WM_QUERYUISTATE, 0, 0) & UISF_HIDEACCEL) != 0)
+  {
+    ACaption = StrippedCaption;
+  }
+  Button->Caption = ACaption;
+  Button->Width = Padding + Canvas->TextWidth(StrippedCaption) + Padding;
+  Button->Left = OctalLabel->Left - Padding;
+}
+//---------------------------------------------------------------------------
+void TRightsFrame::UpdateButtons()
+{
+  UpdateButton(OwnerButton, FOwnerCaption);
+  UpdateButton(GroupButton, FGroupCaption);
+  UpdateButton(OthersButton, FOthersCaption);
+}
+//---------------------------------------------------------------------------
 void __fastcall TRightsFrame::Dispatch(void * Message)
 {
   TMessage & AMessage = *static_cast<TMessage *>(Message);
@@ -537,10 +607,22 @@ void __fastcall TRightsFrame::Dispatch(void * Message)
       CMDialogKey(*(TCMDialogKey *)Message);
       break;
 
+    case CM_DIALOGCHAR:
+      CMDialogChar(*(TCMDialogChar *)Message);
+      break;
+
     case WM_CONTEXTMENU:
       WMContextMenu(*(TWMContextMenu *)Message);
       break;
 
+    case CM_DPICHANGED:
+      CMDPIChanged(AMessage);
+      break;
+
+    case WM_UPDATEUISTATE:
+      WMUpdateUIState(AMessage);
+      break;
+
     default:
       TFrame::Dispatch(Message);
       break;
@@ -749,8 +831,9 @@ void TRightsFrame::DisplayAsAcl(TRights::TRight ReadRight, TRights::TRight Write
   WriteAclCheck->Hint = LoadStr(PROPERTIES_S3_W_ACL_HINT);
   WriteAclCheck->ShowHint = true;
 
-  GroupLabel->Caption = LoadStr(PROPERTIES_S3_USERS);
-  OthersLabel->Caption = LoadStr(PROPERTIES_S3_EVERYONE);
+  FGroupCaption = LoadStr(PROPERTIES_S3_USERS);
+  FOthersCaption = LoadStr(PROPERTIES_S3_EVERYONE);
+  UpdateButtons();
 }
 //---------------------------------------------------------------------------
 void TRightsFrame::DisplayAsAcl()

+ 10 - 31
source/forms/Rights.dfm

@@ -5,54 +5,33 @@ object RightsFrame: TRightsFrame
   Height = 109
   TabOrder = 0
   OnContextPopup = FrameContextPopup
-  object OwnerLabel: TLabel
-    Left = 4
-    Top = 4
-    Width = 32
-    Height = 13
-    Caption = '&Owner'
-    FocusControl = OwnerReadCheck
-  end
-  object GroupLabel: TLabel
-    Left = 4
-    Top = 24
-    Width = 29
-    Height = 13
-    Caption = '&Group'
-    FocusControl = GroupReadCheck
-  end
-  object OthersLabel: TLabel
-    Left = 4
-    Top = 44
-    Width = 33
-    Height = 13
-    Caption = 'Ot&hers'
-    FocusControl = OthersReadCheck
-  end
   object OthersButton: TSpeedButton
     Tag = 3
     Left = 0
-    Top = 41
-    Width = 56
-    Height = 19
+    Top = 42
+    Width = 43
+    Height = 18
+    Caption = 'Ot&hers'
     Flat = True
     OnClick = RightsButtonsClick
   end
   object GroupButton: TSpeedButton
     Tag = 2
     Left = 0
-    Top = 21
-    Width = 56
+    Top = 22
+    Width = 39
     Height = 19
+    Caption = '&Group'
     Flat = True
     OnClick = RightsButtonsClick
   end
   object OwnerButton: TSpeedButton
     Tag = 1
     Left = 0
-    Top = 1
-    Width = 56
+    Top = 2
+    Width = 40
     Height = 19
+    Caption = '&Owner'
     Flat = True
     OnClick = RightsButtonsClick
   end

+ 9 - 3
source/forms/Rights.h

@@ -20,9 +20,6 @@
 class TRightsFrame : public TFrame
 {
 __published:
-  TLabel *GroupLabel;
-  TLabel *OthersLabel;
-  TLabel *OwnerLabel;
   TGrayedCheckBox *OwnerReadCheck;
   TGrayedCheckBox *OwnerWriteCheck;
   TGrayedCheckBox *OwnerExecuteCheck;
@@ -85,6 +82,9 @@ private:
   UnicodeString FAddXToDirectoriesSuffix;
   bool FInitialized;
   bool FAcl;
+  UnicodeString FOwnerCaption;
+  UnicodeString FGroupCaption;
+  UnicodeString FOthersCaption;
 
   void CycleRights(TRights::TRightGroup RightGroup);
   bool __fastcall GetAddXToDirectories();
@@ -128,6 +128,9 @@ protected:
   void __fastcall CMCancelMode(TCMCancelMode & Message);
   void __fastcall CMDialogKey(TCMDialogKey & Message);
   void __fastcall WMContextMenu(TWMContextMenu & Message);
+  void CMDPIChanged(TMessage & Message);
+  void CMDialogChar(TCMDialogChar & Message);
+  void WMUpdateUIState(TMessage & Message);
   bool __fastcall IsAncestor(TControl * Control, TControl * Ancestor);
   DYNAMIC void __fastcall DoExit();
   void __fastcall SetPopup(bool value);
@@ -137,6 +140,9 @@ protected:
   void __fastcall UpdateOctalEdit();
   void __fastcall UpdateByOctal();
   void DisplayAsAcl(TRights::TRight ReadRight, TRights::TRight WriteRight, TRights::TRight ExecRight, TRights::TRight SpecialRight);
+  void UpdateButtons();
+  void UpdateButton(TSpeedButton * Button, UnicodeString & Caption);
+  bool IsButtonAccel(TCMDialogChar & Message, TSpeedButton * Button, TWinControl * FocusControl);
 
   INTERFACE_HOOK_CUSTOM(TFrame);