How to disable the focus ring on a ListIconGadget?

Mac OSX specific forum
User avatar
thinkitsimple
User
User
Posts: 89
Joined: Mon Aug 13, 2012 6:12 pm
Location: Berlin, Germany
Contact:

How to disable the focus ring on a ListIconGadget?

Post by thinkitsimple »

How can i remove the blue focus ring on a ListIconGadget an OS X?

Is there a Cocoa Message for this?
Michael

PureBasic 5.51, macOS 10.12.2 Sierra
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to disable the focus ring on a ListIconGadget?

Post by Shardik »

Code: Select all

CocoaMessage(0, GadgetID(ListIconID), "setSelectionHighlightStyle:", -1)
You may also take a look into this code example from wilbert.
User avatar
thinkitsimple
User
User
Posts: 89
Joined: Mon Aug 13, 2012 6:12 pm
Location: Berlin, Germany
Contact:

Re: How to disable the focus ring on a ListIconGadget?

Post by thinkitsimple »

This is not what i mean. Your example disables the selection of the listicons rows. i want to disable the blue ring around the whole listicon gadget when its getting the focus. this is called the focusring.
Michael

PureBasic 5.51, macOS 10.12.2 Sierra
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to disable the focus ring on a ListIconGadget?

Post by Shardik »

thinkitsimple wrote:This is not what i mean. Your example disables the selection of the listicons rows. i want to disable the blue ring around the whole listicon gadget when its getting the focus. this is called the focusring.
Sorry, I know quite well what a focus ring is. But the situation is not so clear as you might think because it's also possible to draw a focus ring around a single cell (not just selecting a complete row by changing the background to a different color as PureBasic does by default). And that's what I do in some of my programs:

Image

But of course it's also possible to enable and disable the focus ring around the whole ListIconGadget. Unfortunately this solution doesn't work anymore beginning with Mavericks. When releasing Mavericks Apple did some changes in its API for NSViews with layer-backed views which could be the culprit...

Code: Select all

Enumeration NSFocusRingType
  #NSFocusRingTypeDefault = 0
  #NSFocusRingTypeNone
  #NSFocusRingTypeExterior
EndEnumeration

If OSVersion() > #PB_OS_MacOSX_10_8
  MessageRequester("Info", "Sorry, this solution works only up to Mountain Lion!")
  End
EndIf

OpenWindow(0, 200, 100, 440, 130, "ListIcon Example")
ListIconGadget(0, 10, 10, 420, 80, "Name", 110)
AddGadgetColumn(0, 1, "Address", 302)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ + "321 Logo Drive, Mouse House, Downtown")
ButtonGadget(1, 110, 100, 200, 25, "Disable ListIcon's focus ring")

SetActiveGadget(0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1 And EventType() = #PB_EventType_LeftClick
        FocusRingType = CocoaMessage(0, GadgetID(0), "focusRingType") ! 1
        CocoaMessage(0, GadgetID(0), "setFocusRingType:", FocusRingType)

        If FocusRingType = #NSFocusRingTypeNone
          SetGadgetText(1, "Enable ListIcon's focus ring")
        Else
          SetGadgetText(1, "Disable ListIcon's focus ring")
        EndIf
      EndIf
  EndSelect
ForEver
Last edited by Shardik on Fri Jul 03, 2015 4:21 pm, edited 1 time in total.
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: How to disable the focus ring on a ListIconGadget?

Post by Shardik »

I have found a solution for Mavericks (and presumably also for Yosemite which I currently can't test) to disable the focus ring around the ListIconGadget although I still wasn't able to toggle between the states like in my example above for Snow Leopard up to Mountain Lion:

Code: Select all

OpenWindow(0, 200, 100, 440, 95, "ListIcon Example")
ListIconGadget(0, 10, 10, 420, 75, "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 302)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ + "12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ + "130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ + "321 Logo Drive, Mouse House, Downtown")
CocoaMessage(0, GadgetID(0), "setBackgroundColor:", CocoaMessage(0, 0,
  "NSColor clearColor"))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Update: Unfortunately I have been too overoptimistic. The solution above doesn't seem to work on Yosemite regarding this observation from Wilbert at the bottom of my posting...
Post Reply