Re: [PB Cocoa] Methods, Tips & Tricks
Posted: Fri Jul 03, 2015 4:02 pm
Detect left click into ListIconGadget, display row and column of the clicked cell in StatusBar and display a focus ring around the clicked cell (successfully tested on Snow Leopard, Lion, Mountain Lion and Mavericks; on Mavericks no focus ring around the border of the ListIconGadget will be displayed; how to disable the focus ring for Snow Leopard up to Mountain Lion I have already demonstrated here):
Problems on Yosemite: Unfortunately this solution doesn't work on Yosemite. Wilbert sent me a PM (thank you, Wilbert!) describing the problems on Yosemite:
Code: Select all
EnableExplicit
#NSTableViewSelectionHighlightStyleNone = -1
Define CursorLocation.NSPoint
Define SelectedColumn.I
Define SelectedRow.I
OpenWindow(0, 200, 100, 430, 119, "Display focus ring around selected cell")
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
ListIconGadget(0, 10, 10, WindowWidth(0) - 20,
WindowHeight(0) - 20 - StatusBarHeight(0), "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
#PB_ListIcon_ColumnWidth) - 8)
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),
"setSelectionHighlightStyle:", #NSTableViewSelectionHighlightStyleNone)
CocoaMessage(0, GadgetID(0), "setBackgroundColor:", CocoaMessage(0, 0,
"NSColor clearColor"))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
SelectedRow = GetGadgetState(0)
CursorLocation\x = WindowMouseX(0)
CursorLocation\y = WindowHeight(0) - WindowMouseY(0)
CocoaMessage(@CursorLocation, GadgetID(0),
"convertPoint:@", @CursorLocation, "fromView:", 0)
SelectedColumn = CocoaMessage(0, GadgetID(0),
"columnAtPoint:@", @CursorLocation)
If SelectedColumn > -1
CocoaMessage(0, GadgetID(0), "setFocusedColumn:", SelectedColumn)
StatusBarText(0, 0, "Selected cell: " + Str(SelectedRow) + "," +
Str(SelectedColumn), #PB_StatusBar_Center)
EndIf
EndIf
EndSelect
ForEver
Wilbert wrote:At first it shows a focus ring around the entire gadget when you click a cell. When I click another application and then back to the copied one it shows a focus ring around the last clicked cell but there's no realtime update when I click another cell. The focus ring only seems to update if the application regains focus.