ListIconGadget questions...

Everything else that doesn't fall into one of the other PB categories.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

ListIconGadget questions...

Post by Joakim Christiansen »

I need to know if the ListIconGadget header was right clicked, how should I do this?

And btw the ListIconGadget is a HELL to work with, I think we should be able to use the same code to fill it even if a column was deleted! :evil:
Because now I have to check exactly how the columns is and make a super duper big procedure with every combination to fill it right!

Code: Select all

AddGadgetItem(0,-1,"Item 1"+#LF$+"Item 2"+#LF$+"Item 3")
This doesn't fill right if I remove column 2, because then column 3 will receive the item which was supposed to be in column 2!
Is there any way I can use API to fill it in a more intelligent way maybe, or any other suggestions?
Yes, I really need my users to be able to choose which columns they want visible, move them too.

And btw, how can my program change the columns positions after they are created?
I like logic, hence I dislike humans but love computers.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

I need to know if the ListIconGadget header was right clicked, how should I do this?
Like this: :wink:

Code: Select all

; Subclassing the ListIcon Gadget Header Control
; 03/2007 by netmaestro

Procedure callback(hwnd, msg, wparam, lparam)
  Protected oldproc = GetProp_(hwnd, "oldproc")
  result=CallWindowProc_(oldproc,hwnd,msg,wparam,lparam)
  If msg = #WM_RBUTTONUP
    hti.hd_hittestinfo
    hti\pt\x = lparam&$FFFF
    hti\pt\y = lparam>>16
    SendMessage_(hwnd, #HDM_HITTEST,0,@hti)
    Debug "Right Button Up On Header item: "+Str(hti\iItem)
  ElseIf msg = #WM_RBUTTONDOWN
    hti.hd_hittestinfo
    hti\pt\x = lparam&$FFFF
    hti\pt\y = lparam>>16
    SendMessage_(hwnd, #HDM_HITTEST,0,@hti)
    Debug "Right Button Down On Header item: "+Str(hti\iItem)
  EndIf
  ProcedureReturn result
EndProcedure

OpenWindow(0,0,0,300,400,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ListIconGadget(0,0,0,300,400,"Column 0",100)
AddGadgetColumn(0, 1,"Column 1",200)

; find header control hwnd and subclass it
header = GetWindow_(GadgetID(0),#GW_CHILD)
oldproc=SetWindowLong_(header,#GWL_WNDPROC, @callback())
SetProp_(header, "oldproc", oldproc)

Repeat:Until WaitWindowEvent()=#WM_CLOSE
And btw the ListIconGadget is a HELL to work with
Welcome to the wonderful world of Windows programming, JLC! :D
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Joakim Christiansen wrote:And btw, how can my program change the columns positions after they are created?
That can be done using API #LVM_SETCOLUMNORDERARRAY. ;)

Code: Select all

#LVM_SETCOLUMNORDERARRAY = #LVM_FIRST + 58

;...Array for holding default column order
Dim colArray(2)

If OpenWindow(0, 100, 100, 500, 400, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
  ListIconGadget(0, 5, 5, 490, 290, "Column A", 160, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection | #PB_ListIcon_GridLines)
  AddGadgetColumn(0, 1, "Column B", 160)
  AddGadgetColumn(0, 2, "Column C", 160)
  ButtonGadget(1, 10, 360, 200, 25, "Change column order")
  Repeat
    Event = WaitWindowEvent()
    If Event = #PB_Event_Gadget And EventGadget() = 1
      
      colArray(0) = 1
      colArray(1) = 0
      colArray(2) = 2
      
      ;...Switch column 0 with column 1
      ;...This allows us to edit the reminder data
      SendMessage_(GadgetID(0), #LVM_SETCOLUMNORDERARRAY, 3, colArray())
      DisableGadget(1, 1)
    EndIf
  Until Event = #PB_Event_CloseWindow
EndIf
End
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Holy slow coach, beaten by the deadly duo; batman + netmaestro yet again!

:)

Oh well, I'll post what I hacked up anyhow:

Code: Select all

#LVM_GETHEADER = #LVM_FIRST+31

Procedure.l callback(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *nmh.NMHDR=lParam
        Select *nmh\code
          Case #NM_RCLICK
             If *nmh\hwndFrom = SendMessage_(GadgetID(0),#LVM_GETHEADER,0,0)
               ;Now identify which item was clicked.
                GetCursorPos_(hdhittest.HD_HITTESTINFO\pt) 
                ScreenToClient_(*nmh\hwndFrom, hdhittest\pt) 
                SendMessage_(*nmh\hwndFrom, #HDM_HITTEST, 0, @hdhittest)
                Debug "Clicked header item " + Str(hdhittest\iItem)
             EndIf
        EndSelect
  EndSelect
  ProcedureReturn result
EndProcedure

If OpenWindow(0, 100, 100, 300, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ListIconGadget(0, 5, 5, 290, 90, "Name", 100, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
    AddGadgetColumn(0, 1, "Address", 250)
    AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
    AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
    SetWindowCallback(@callback())
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf
EndIf
@Joakim Christiansen: to alleviate your AddGadgetItem() woes, you could simply use AddGadgetItem() with an empty string and then set individual cells with SetGadgetItemText() etc. This might be slightly less problematic.
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

srod wrote:Holy slow coach, beaten by batman yet again!
It's been a while since anyone has beaten the Great ListIconGadgetGuru named srod. 8)

I figure you must have been taking a little snooze...zzzzzzz :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

It's well posted anyway as srod and I chose different avenues to achieve the rightclick test.
BERESHEIT
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

No time for sleep... must work... must debug spahgetti code... must co... zzzzzz!

Actually, I realised after I posted that it was netmaestro who had already produced code to solve the problem I was working on. Must have got your avatars mixed up somehow!

I was getting to the set column order array, but was way too slow for that one! :)
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Hey srod...I want to swap rankings with you...here's my PureBasic Expert which you have more than earned. Now if you will kindly hand over your Addict ranking I'll be on my way. :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

grrr... Mitts off mine, it hasn't had time to get dusty yet!
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Not to worry netmaestro. Yours suits you just fine. Mine just doesn't feel right. I don't know.... maybe it's the weight I gained since I quit smoking 8)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Sparkie wrote:Hey srod...I want to swap rankings with you...here's my PureBasic Expert which you have more than earned. Now if you will kindly hand over your Addict ranking I'll be on my way. :)
Are you kidding man? :) Your knowledge of api stuff far outweigh's mine and on a technical level, some of your posts are beyond reproach. Beside's one of my posts in the bug section this week warrants that I get busted back down to 'Novice' at best! :wink: No, in as much as the rankings are pretty meaningless, you two are the real experts here. I just don't have a great deal of time at the moment to help out in the forums as I once did.

No, I could list half a dozen users who should be elevated way before myself - and there are undoubtedly many more.

Now, how about we swap bank accounts instead? :D
I may look like a mule, but I'm not a complete ass.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

srod wrote:Now, how about we swap bank accounts instead?
Two weeks ago maybe I'd have said yes....but now that I have deposited my tax refund check...hmmmm....I don't think so my friend :P
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

srod wrote:Beside's one of my posts in the bug section this week warrants that I get busted back down to 'Novice' at best!
Done that once or twice myself. No need for :oops: as it just shows that we are human just like everyone else :wink:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Not even if I throw my 'Addict' ranking in for free?

Oh well, worth a try!

:)
I may look like a mule, but I'm not a complete ass.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Done that once or twice myself. No need for :oops: as it just shows that we are human just like everyone else
Human?? We have a frog, a bat, a homer simpsons character and a visiting fanged beast in the room!!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply