It is currently Sat Aug 15, 2020 8:59 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Re: ListIconGadget
PostPosted: Wed Jul 16, 2014 2:32 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1753
Location: Germany
spacebuddy wrote:
Is there anyway to make the ListIconGadget editable so I can type stuff in.

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.

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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Wed Jul 16, 2014 3:44 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Jul 02, 2009 5:42 am
Posts: 327
Thanks, that works :D


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Wed Jul 16, 2014 7:14 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2991
Location: Planet Earth
Very nice, thanks Shardik!


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Fri Nov 14, 2014 2:02 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Jun 11, 2004 7:07 am
Posts: 636
It is possible to use pseudotypes
Code:
ImportC ""
  sel_registerName(MethodName.p-utf8)
  class_addMethod(Class.I, Selector.I, Implementation.I, Types.p-utf8)
EndImport
instead of
Code:
ImportC ""
  sel_registerName(MethodName.S)
  class_addMethod(Class.I, Selector.I, Implementation.I, Types.S)
EndImport
to remove the ConvertToUTF8() function?


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Fri Nov 14, 2014 7:08 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1753
Location: Germany
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).


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Fri Nov 14, 2014 7:17 pm 
Offline
Addict
Addict

Joined: Mon Aug 04, 2008 10:56 pm
Posts: 1124
Location: Seattle, USA
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.

_________________
MacBook Pro-r, OSX 10.14.6 , PB 5.70LTS


Top
 Profile  
Reply with quote  
 Post subject: Re: ListIconGadget
PostPosted: Sun Nov 16, 2014 9:09 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1753
Location: Germany
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...


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye