Page 1 of 1

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

Posted: Tue Jun 30, 2015 8:13 pm
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

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

Posted: Fri Jul 03, 2015 4:07 pm
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...