From 35bf1396b29bd75111409a76e27d8c8e545ac550 Mon Sep 17 00:00:00 2001 From: dmitry Date: Sun, 12 Jan 2020 01:06:54 +0000 Subject: [PATCH] cocoa: hiding focus ring, if borderstyle is none. bug #34828 git-svn-id: trunk@62531 - --- lcl/interfaces/cocoa/cocoaint.pas | 2 ++ lcl/interfaces/cocoa/cocoawschecklst.pas | 1 + lcl/interfaces/cocoa/cocoawscomctrls.pas | 2 ++ lcl/interfaces/cocoa/cocoawscommon.pas | 12 ++++++++++++ lcl/interfaces/cocoa/cocoawsstdctrls.pas | 6 ++++++ 5 files changed, 23 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoaint.pas b/lcl/interfaces/cocoa/cocoaint.pas index 265fa096fd..ac30113b45 100644 --- a/lcl/interfaces/cocoa/cocoaint.pas +++ b/lcl/interfaces/cocoa/cocoaint.pas @@ -245,6 +245,8 @@ var CocoaToggleBezel : NSBezelStyle = NSRoundedBezelStyle; CocoaToggleType : NSButtonType = NSPushOnPushOffButton; + CocoaHideFocusNoBorder : Boolean = true; + {$ifdef COCOALOOPHIJACK} // The flag is set to true once hi-jacked loop is finished (at the end of app) // The flag is checked in Menus to avoid "double" Cmd+Q menu diff --git a/lcl/interfaces/cocoa/cocoawschecklst.pas b/lcl/interfaces/cocoa/cocoawschecklst.pas index 30d98511b9..be4df77939 100644 --- a/lcl/interfaces/cocoa/cocoawschecklst.pas +++ b/lcl/interfaces/cocoa/cocoawschecklst.pas @@ -244,6 +244,7 @@ begin scroll.setAutohidesScrollers(true); ScrollViewSetBorderStyle(scroll, TCustomCheckListBox(AWinControl).BorderStyle); + UpdateFocusRing(list, TCustomCheckListBox(AWinControl).BorderStyle); Result := TLCLIntfHandle(scroll); end; diff --git a/lcl/interfaces/cocoa/cocoawscomctrls.pas b/lcl/interfaces/cocoa/cocoawscomctrls.pas index 470fd6cf2c..db15e9968f 100644 --- a/lcl/interfaces/cocoa/cocoawscomctrls.pas +++ b/lcl/interfaces/cocoa/cocoawscomctrls.pas @@ -1027,6 +1027,7 @@ begin lCocoaLV.callback := lclcb; ScrollViewSetBorderStyle(lCocoaLV, TCustomListView(AWinControl).BorderStyle); + UpdateFocusRing(lTableLV, TCustomListView(AWinControl).BorderStyle); {$IFDEF COCOA_DEBUG_LISTVIEW} WriteLn(Format('[TCocoaWSCustomListView.CreateHandle] headerView=%d', [PtrInt(lTableLV.headerView)])); @@ -1039,6 +1040,7 @@ class procedure TCocoaWSCustomListView.SetBorderStyle( begin if not Assigned(AWinControl) or not AWinControl.HandleAllocated then Exit; ScrollViewSetBorderStyle(NSScrollView(AWinControl.Handle), ABorderStyle); + UpdateFocusRing(NSView(NSScrollView(AWinControl.Handle).documentView), ABorderStyle); end; class procedure TCocoaWSCustomListView.ColumnDelete(const ALV: TCustomListView; diff --git a/lcl/interfaces/cocoa/cocoawscommon.pas b/lcl/interfaces/cocoa/cocoawscommon.pas index 95939eefce..40f19f3ae4 100644 --- a/lcl/interfaces/cocoa/cocoawscommon.pas +++ b/lcl/interfaces/cocoa/cocoawscommon.pas @@ -160,6 +160,7 @@ function EmbedInManualScrollHost(AView: TCocoaManualScrollView): TCocoaManualScr function HWNDToTargetObject(AFormHandle: HWND): TObject; procedure ScrollViewSetBorderStyle(sv: NSScrollView; astyle: TBorderStyle); +procedure UpdateFocusRing(v: NSView; astyle: TBorderStyle); function ButtonStateToShiftState(BtnState: PtrUInt): TShiftState; function CocoaModifiersToKeyState(AModifiers: NSUInteger): PtrInt; @@ -218,6 +219,17 @@ begin sv.setBorderType( NSBorderStyle[astyle] ); end; +procedure UpdateFocusRing(v: NSView; astyle: TBorderStyle); +const + NSFocusRing : array [TBorderStyle] of NSBorderType = ( + NSFocusRingTypeNone, // bsNone + NSFocusRingTypeDefault // bsSingle s + ); +begin + if Assigned(v) and CocoaHideFocusNoBorder then + v.setFocusRingType( NSFocusRing[astyle] ); +end; + function EmbedInScrollView(AView: NSView; AReleaseView: Boolean): TCocoaScrollView; var r: TRect; diff --git a/lcl/interfaces/cocoa/cocoawsstdctrls.pas b/lcl/interfaces/cocoa/cocoawsstdctrls.pas index b408055a99..26b3b386fc 100644 --- a/lcl/interfaces/cocoa/cocoawsstdctrls.pas +++ b/lcl/interfaces/cocoa/cocoawsstdctrls.pas @@ -943,6 +943,7 @@ begin end; TextFieldSetAllignment(field, TCustomEdit(AWinControl).Alignment); TextFieldSetBorderStyle(field, TCustomEdit(AWinControl).BorderStyle); + UpdateFocusRing(field, TCustomEdit(AWinControl).BorderStyle); Result:=TLCLIntfHandle(field); end; @@ -969,6 +970,7 @@ begin if not Assigned(field) then Exit; field.setBordered_( ObjCBool(ABorderStyle <> bsNone) ); field.setBezeled_( ObjCBool(ABorderStyle <> bsNone) ); + UpdateFocusRing(field, ABorderStyle); end; class function TCocoaWSCustomEdit.GetSelStart(const ACustomEdit: TCustomEdit): integer; @@ -1440,6 +1442,7 @@ begin scr.setDrawsBackground(false); ScrollViewSetBorderStyle(scr, TCustomMemo(AWinControl).BorderStyle); + UpdateFocusRing(txt, TCustomMemo(AWinControl).BorderStyle); nr:=scr.documentVisibleRect; txt.setFrame(nr); @@ -1531,6 +1534,7 @@ begin if not Assigned(sv) then Exit; ScrollViewSetBorderStyle(sv, ABorderStyle); + UpdateFocusRing(NSView(sv.documentView), ABorderStyle); end; class function TCocoaWSCustomMemo.GetCaretPos(const ACustomEdit: TCustomEdit): TPoint; @@ -2086,6 +2090,7 @@ begin scroll.setHasVerticalScroller(true); scroll.setAutohidesScrollers(true); ScrollViewSetBorderStyle(scroll, lclListBox.BorderStyle); + UpdateFocusRing(list, lclListBox.BorderStyle); Result := TLCLIntfHandle(scroll); end; @@ -2198,6 +2203,7 @@ begin if not Assigned(list) then Exit; ScrollViewSetBorderStyle(list.enclosingScrollView, ABorderStyle); + UpdateFocusRing(list, ABorderStyle); end; class procedure TCocoaWSCustomListBox.SetItemIndex(const ACustomListBox: TCustomListBox; const AIndex: integer);