listicons: right-click --> copy, possible?

Just starting out? Need help? Post your questions and find answers here.
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

listicons: right-click --> copy, possible?

Post by morosh »

Hello:
sorry if this has been asked before, is it possible to right-click a cell in a listicons and copy it with a popup menu? no need to be editable

thank you
PureBasic: Surprisingly simple, diabolically powerful
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: listicons: right-click --> copy, possible?

Post by Shardik »

Have you already taken a look into this code example from TerryHough (combined with code from RASHAD) which detects a right click onto a cell in a ListIconGadget, displays a popup menu and allows you to cut, copy, paste or edit the cell content?
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: listicons: right-click --> copy, possible?

Post by CELTIC88 »

you want that?

Code: Select all

#Window = 0
#ListIcon = 0
#Menu = 0
#MenuItemCopy = 1

If OpenWindow(#Window, 100, 100, 300, 100, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(#ListIcon, 5, 5, 290, 90, "Nom", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
  AddGadgetColumn(#ListIcon, 1, "Adresse", 250)
  AddGadgetItem(#ListIcon, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(#ListIcon, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
  CreatePopupMenu(#Menu)
  MenuItem(#MenuItemCopy,"Copy")
  
  Repeat
    Evenement = WaitWindowEvent()
    Select Evenement
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #ListIcon
            Select EventType()
              Case #PB_EventType_RightClick 
                DisplayPopupMenu(#Menu,WindowID(#Window))
                
            EndSelect
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case #MenuItemCopy
            SetClipboardText(GetGadgetItemText(#ListIcon,GetGadgetState(#ListIcon)))
        EndSelect
    EndSelect
  Until Evenement = #PB_Event_CloseWindow
EndIf

interested in Cybersecurity..
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: listicons: right-click --> copy, possible?

Post by mk-soft »

with multiselection

Code: Select all

#Window = 0
#ListIcon = 0
#Menu = 0
#MenuItemCopy = 1

If OpenWindow(#Window, 100, 100, 600, 300, "ListIconGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(#ListIcon, 5, 5, 590, 290, "Num", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection |  #PB_ListIcon_MultiSelect)
  AddGadgetColumn(#ListIcon, 1, "Inf0", 450)
  For i = 1 To 20
    AddGadgetItem(#ListIcon, -1, Str(i)+#LF$+"Info " + Str(i))
  Next
  CreatePopupMenu(#Menu)
  MenuItem(#MenuItemCopy,"Copy")
 
  Repeat
    Evenement = WaitWindowEvent()
    Select Evenement
      Case #PB_Event_Gadget
        Select EventGadget()
          Case #ListIcon
            Select EventType()
              Case #PB_EventType_RightClick
                DisplayPopupMenu(#Menu,WindowID(#Window))
               
            EndSelect
        EndSelect
      Case #PB_Event_Menu
        Select EventMenu()
          Case #MenuItemCopy
            cnt = CountGadgetItems(#ListIcon) - 1
            col = GetGadgetAttribute(#ListIcon, #PB_ListIcon_ColumnCount) - 1
            text.s = ""
            For i = 0 To cnt
              If GetGadgetItemState(#ListIcon, i)
                For n = 0 To col
                  text + GetGadgetItemText(#ListIcon, i, n)
                  If n < col
                    text + #TAB$
                  EndIf
                Next
                If n < cnt
                  text + #CRLF$
                EndIf
              EndIf
            Next
            Debug text
            SetClipboardText(text)
        EndSelect
    EndSelect
  Until Evenement = #PB_Event_CloseWindow
EndIf
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: listicons: right-click --> copy, possible?

Post by morosh »

Thanks all

In fact i want to copy a single cell, not the entire line, I'll dig in Shardik'suggestion.
PureBasic: Surprisingly simple, diabolically powerful
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: listicons: right-click --> copy, possible?

Post by RASHAD »

Simple and straight forward

Code: Select all

LoadFont(0,"Tahoma",16)
OpenWindow(0,0,0,640,480,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ListIconGadget(0,10,10,620,460,"",0,#PB_ListIcon_GridLines)
gx = GadgetX(0) : gy = GadgetY(0)
SetGadgetFont(0,FontID(0))
AddGadgetColumn(0,1,"Column 1",210)
AddGadgetColumn(0,2,"Column 2",200)
AddGadgetColumn(0,3,"Column 3",200)
For i = 1 To 16
  linestr.s = LSet(Str(i),3," ")
  AddGadgetItem(0, -1, Chr(10)+"Text on Line "+linestr+" in Column 1"+Chr(10)+"Text on Line "+linestr+" in Column 2"+Chr(10)+"Text on Line "+linestr+" in Column 3")
Next

CreatePopupMenu(0)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
MenuItem(4, "Edit")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      End
     
    Case #PB_Event_RightClick

    Case #PB_Event_Menu     
      Select EventMenu()         
        Case 1                 
        Case 2   
          SetGadgetItemColor(0,Row,#PB_Gadget_FrontColor,$0 ,Col)
          SetGadgetItemColor(0,Row, #PB_Gadget_BackColor,$FFFFFF,Col)
          Debug GetGadgetItemText(0,row,col)
         
        Case 3         
        Case 4
      EndSelect
     
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Select EventType()
            Case #PB_EventType_RightClick
              pInfo.LVHITTESTINFO
              pInfo\pt\x = WindowMouseX(0)-gx : pInfo\pt\y = WindowMouseY(0)-gy
              SendMessage_(GadgetID(0),#LVM_SUBITEMHITTEST,0,@pInfo) 
              row = pInfo\iItem : col = pInfo\iSubItem
              SetGadgetItemColor(0,Row,#PB_Gadget_FrontColor,$FFFFFF ,Col)
              SetGadgetItemColor(0,Row, #PB_Gadget_BackColor,$FF9933,Col)
              DisplayPopupMenu(0, WindowID(0))
          EndSelect
      EndSelect
  EndSelect
ForEver
Egypt my love
morosh
Enthusiast
Enthusiast
Posts: 293
Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon

Re: listicons: right-click --> copy, possible?

Post by morosh »

Thank you Rashad

Really simple and awesome as always
PureBasic: Surprisingly simple, diabolically powerful
Post Reply