Browse Source

Visual feedback when control (drop down list particularly) is focused via keyboard accelerator

Source commit: 077c007c019dd890dcb3bad8ff44e5947aa265f3
Martin Prikryl 2 years ago
parent
commit
5cdd6617fa
2 changed files with 26 additions and 0 deletions
  1. 25 0
      source/windows/GUITools.cpp
  2. 1 0
      source/windows/GUITools.h

+ 25 - 0
source/windows/GUITools.cpp

@@ -2319,6 +2319,31 @@ void __fastcall TUIStateAwareLabel::DoDrawText(TRect & Rect, int Flags)
   TLabel::DoDrawText(Rect, Flags);
 }
 //---------------------------------------------------------------------------
+void __fastcall TUIStateAwareLabel::Dispatch(void * AMessage)
+{
+  TMessage * Message = static_cast<TMessage*>(AMessage);
+  // WORKAROUND: Particularly when focusing csDropDownList-style combobox via label, there's no visual feedback
+  // that the combobox was selected (strangely, there is, when the previous focus was on TTreeView).
+  // For consistency, we enable focus display for all controls types (like checkboxes).
+  if (Message->Msg == CM_DIALOGCHAR)
+  {
+    bool WasFocused = (FocusControl != NULL) ? FocusControl->Focused() : false;
+    TLabel::Dispatch(AMessage);
+    if (!WasFocused && (FocusControl != NULL) && FocusControl->Focused())
+    {
+      TCustomForm * ParentForm = GetParentForm(this);
+      if (ParentForm != NULL)
+      {
+        ParentForm->Perform(WM_CHANGEUISTATE, MAKELONG(UIS_CLEAR, UISF_HIDEFOCUS), 0);
+      }
+    }
+  }
+  else
+  {
+    TLabel::Dispatch(AMessage);
+  }
+}
+//---------------------------------------------------------------------------
 void __fastcall FindComponentClass(
   void *, TReader *, const UnicodeString DebugUsedArg(ClassName), TComponentClass & ComponentClass)
 {

+ 1 - 0
source/windows/GUITools.h

@@ -193,6 +193,7 @@ public:
 
 protected:
   DYNAMIC void __fastcall DoDrawText(TRect & Rect, int Flags);
+  virtual void __fastcall Dispatch(void * AMessage);
 };
 // FindComponentClass takes parameter by reference and as such it cannot be implemented in
 // an inline method without a compiler warning, which we cannot suppress in a macro.