ListIconGadget
-
- Enthusiast
- Posts: 349
- Joined: Thu Jul 02, 2009 5:42 am
ListIconGadget
Is there anyway to make the ListIconGadget editable so I can type stuff in.
Re: ListIconGadget
There's no way without knowing exactly how PB does things internally.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
Re: ListIconGadget
A left click onto any cell (except header cells) makes it editable. Modify the cell's content and end this action with <Enter> or <Tab> or a click onto another cell. The modified text will be copied from the edit field into the ListIcon cell.spacebuddy wrote:Is there anyway to make the ListIconGadget editable so I can type stuff in.
I have tested this code example successfully on MacOS X 10.6.8 (Snow Leopard) and MacOS X 10.9.4 (Mavericks) in both ASCII and Unicode mode with PB 5.22 x86 and x64 and PB 5.30 x86 Beta 7.
Code: Select all
EnableExplicit
ImportC ""
sel_registerName(MethodName.S)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.S)
EndImport
Procedure.S ConvertToUTF8(String.S)
Protected UTF8String.S = Space(StringByteLength(String))
PokeS(@UTF8String, String, -1, #PB_UTF8)
ProcedureReturn UTF8String
EndProcedure
ProcedureC EditingFinishedCallback(Object.I, Selector.I, Notification.I)
Protected EditedCell.I
Protected EditedColumn.I = CocoaMessage(0, GadgetID(0), "editedColumn")
Protected EditedRow.I = CocoaMessage(0, GadgetID(0), "editedRow")
Protected EditedText.S
EditedCell = CocoaMessage(0, Notification, "object")
EditedText = PeekS(CocoaMessage(0, CocoaMessage(0, EditedCell, "stringValue"),
"UTF8String"), -1, #PB_UTF8)
SetGadgetItemText(0, EditedRow, EditedText, EditedColumn)
EndProcedure
Define CursorLocation.NSPoint
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
"NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
Define NotificationCenter.I = CocoaMessage(0, 0,
"NSNotificationCenter defaultCenter")
Define SelectedColumn.I
Define Selector.I = sel_registerName(ConvertToUTF8("textDidEndEditing:"))
OpenWindow(0, 200, 100, 430, 95, "Editable ListIconGadget demo")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Name", 110)
AddGadgetColumn(0, 1, "Address", 292)
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:", -1)
class_addMethod(DelegateClass, Selector, @EditingFinishedCallback(), "v@:@")
CocoaMessage(0, NotificationCenter,
"addObserver:", AppDelegate,
"selector:", Selector,
"name:$", @"NSControlTextDidEndEditingNotification",
"object:", GadgetID(0))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
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)
CocoaMessage(0, GadgetID(0),
"editColumn:", SelectedColumn,
"row:", GetGadgetState(0),
"withEvent:", 0,
"select:", #YES)
EndIf
EndSelect
ForEver
-
- Enthusiast
- Posts: 349
- Joined: Thu Jul 02, 2009 5:42 am
Re: ListIconGadget
Thanks, that works
Re: ListIconGadget
Very nice, thanks Shardik!
Re: ListIconGadget
It is possible to use pseudotypes
instead of
to remove the ConvertToUTF8() function?
Code: Select all
ImportC ""
sel_registerName(MethodName.p-utf8)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.p-utf8)
EndImport
Code: Select all
ImportC ""
sel_registerName(MethodName.S)
class_addMethod(Class.I, Selector.I, Implementation.I, Types.S)
EndImport
Re: ListIconGadget
Yes, now the procedure ConvertToUTF8() isn't necessary anymore because Fred has fixed a bug in P-UTF8 in PB 5.24 and PB 5.31 for MacOS. In older PB versions ConvertToUTF8() is still necessary so that I won't change my code example from above as it is working fine in both older and current PB versions (x86 and x64 PB compiler and in both ASCII and Unicode mode).
Re: ListIconGadget
Hey, that's pretty cool!
Can it be made to work with a ListView gadget?
Hmm, I'm thinking of the possibilities.
[later]
I just tried it and it seems to work fine using ListView.
Can it be made to work with a ListView gadget?
Hmm, I'm thinking of the possibilities.
[later]
I just tried it and it seems to work fine using ListView.
MacBook Pro-M1 (2021), Sonoma 14.4.1, PB 6.10LTS M1
Re: ListIconGadget
William,
the ListViewGadget() and the ListIconGadget() in PB for MacOS X are utilising the same underlying Cocoa framework control: an NSTableView. So in essence the ListViewGadget is a ListIconGadget with only one column and editing a cell therefore should work the same in both gadgets.
If you need to know the underlying Cocoa control of a PB gadget you may take a look into this table...
the ListViewGadget() and the ListIconGadget() in PB for MacOS X are utilising the same underlying Cocoa framework control: an NSTableView. So in essence the ListViewGadget is a ListIconGadget with only one column and editing a cell therefore should work the same in both gadgets.
If you need to know the underlying Cocoa control of a PB gadget you may take a look into this table...