Using event handlers - (obsolete version)

Developed or developing a new product in PureBasic? Tell the world about it.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Ok thanks.

Will try it later.

Off to work :(
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

Just downloaded your actual version and it works fine here.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Just got in and tried it.

Works brilliantly, will use in some programs for sure.

Thanks for sharing.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

**Small update: 1st september 2006.

Have added one extra event (#OnErase) to assist with custom painting and reducing flicker etc.

Also added an example on drag/drop using Windows ImageLists.

See first post for the download link.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

**Update : 8 October 2006.

Have fixed a few bugs over the last few weeks and incorporated some improvements from Clipper (with thanks) in regards to editing tree labels.

Bugs fixed relate to drag/drop and panel gadget selection etc.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

**Update : 11 October 2006.

On request, I have added a new event: #OnUnhandledWinMessage
which allows the developer to easily trap all unhandled Windows messages (and those for which there is no corresponding EasyVENT event) and most unhandled EasyVENT events.

This avoids having to mix EasyVENT with PB callback functions, although there's no reason why you cannot mix the two.
It does avoid duplication however.

Please see the user guide for more details.
I may look like a mule, but I'm not a complete ass.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

hello srod,

Can you add some extra fields to the PB_Sender structure such as UserData ?

Code: Select all

Structure PB_Sender
  hwnd.l      ; 
  message.l   ; 
  mousex.l    ; Client co-ordinates relative to the underlying control (not the parent window)
  mousey.l    ; Client co-ordinates relative to the underlying control (not the parent window)
  button.l    ; For click events this indicates which mouse button was clicked etc.
              ; #EVENT_LEFTBUTTON etc.
  item.l      ; Used with certain events \ controls to indicate a particular item. 
  state.l     ; Gives extra information for certain events.
  text$       ; Gives extra information for certain events.
  uMsg.l      ; Windows callback message parameter (when appropriate)
  wParam.l    ; Windows callback message parameter (when appropriate)
  lParam.l    ; Windows callback message parameter (when appropriate)
  userData1.l ; * 
  userData2.l ; * UserData - For user private use.
  userData3.l ; * 
EndStructure

No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

the PB_Sender structure is only valid within the underlying event handler so I am not sure where such fields would be initialised and where they would be stored between calls?

If you are looking for static data that can be shared between the different event handlers, then you could combine multiple handlers into one procedure and then use static variables etc.

**EDIT**
I've had a look and it is easy enough to do what you're after by declaring the 'sender' variable as static within the EventDespatcher procedure within the EasyVENT library.

However, this causes problems in that the EventDespatcher proc needs to remain fully re-entrant in the sense that one event can cause others to fire before the original event handler has completed it's work etc. This makes using such a static structure quite precarious as the fields of the *sender variable within your event handler will thus appear to change for no good reason and at almost random times.

For this reason I would suggest that you adopt the ploy detailed above. :)
I may look like a mule, but I'm not a complete ass.
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

ok thank you srod for all those explanations (my request was intended to be use for drag'n'drop between two listicongadgets).

another question :

is it possible to drag'n'drop more than one items at once between two listicons (with the flag #PB_ListIcon_MultiSelect) ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Flype wrote:is it possible to drag'n'drop more than one items at once between two listicons (with the flag #PB_ListIcon_MultiSelect) ?
i've written a small demo for multiselection.
do you think it's a good way to do this ?

Code: Select all

XIncludeFile "EasyVENT.pbi" : DisableExplicit

Declare.l DragItem(*sender.PB_Sender)
Declare.l DropItem(*sender.PB_Sender)

;-
;-

Enumeration 1
  #gStore
  #gBasket
EndEnumeration

If OpenWindow(0, 100, 100, 350, 320, "MultiSelect Drag'n'Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  LoadImage(0, "icon.ico")
  
  If CreateGadgetList(WindowID(0))
    ListIconGadget(#gStore,   10, 10, 160, 300, "Store",  150, #PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
    ListIconGadget(#gBasket, 180, 10, 160, 300, "Basket", 150, #PB_ListIcon_FullRowSelect|#PB_ListIcon_MultiSelect)
    SetGadgetColor(#gStore,  #PB_Gadget_BackColor, (#Green|$DFDFDF))
    SetGadgetColor(#gBasket, #PB_Gadget_BackColor, (#Blue |$DFDFDF))
  EndIf
  
  For i = 1 To 15
    AddGadgetItem(#gStore, -1, StringField("Apple,Apricot,Banana,Blackberry,Cherry,Grape,Kiwi,Lemon,Mango,Orange,Peach,Pear,Pineapple,Strawberry,Vanilla", i, ","), ImageID(0))
  Next
  
  SetEventHandler(GadgetID(#gStore),  #OnDragItemStart, @DragItem())
  SetEventHandler(GadgetID(#gStore),  #OnDragItemEnd,   @DropItem())
  SetEventHandler(GadgetID(#gBasket), #OnDragItemStart, @DragItem())
  SetEventHandler(GadgetID(#gBasket), #OnDragItemEnd,   @DropItem())
  
  Repeat
  Until WaitWindowEvent() = #PB_Event_CloseWindow
  
EndIf

;-
;-

Procedure.l DragItem(*sender.PB_Sender)
  Protected i.l, a.l = GetDlgCtrlID_(*sender\hwnd)
  For i = 0 To CountGadgetItems(a) - 1
    If GetGadgetItemState(a, i) & #PB_ListIcon_Selected
      *sender\text$ + GetGadgetItemText(a, i, 0) + ", "
    EndIf
  Next
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure.l DropItem(*sender.PB_Sender)
  Protected i.l, a.l = #gStore, b.l = #gBasket
  If *sender\hwnd = GadgetID(#gStore) : Swap a, b : EndIf
  For i = CountGadgetItems(a) - 1 To 0 Step -1
    If GetGadgetItemState(a, i) & #PB_ListIcon_Selected
      AddGadgetItem(b, -1, GetGadgetItemText(a, i, 0), ImageID(0))
      RemoveGadgetItem(a, i)
    EndIf
  Next
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

I'm trying to use this offering (looks great! Thanks!) but I get an error: Structure not found: PB_Sender. I'm believing it's because I have not installed the files in the proper area. I put such inside of the PureBasic main directory. I then did a copy of the exact path to the EasyVENT.pbi file. It then gives that error I stated above.

If someone would clue me into what I am doing wrong or have overlooked to get this going proper like. I am using PB 4.01 (will update here to 4.02)

TIA
Intrigued - Registered PureBasic, lifetime updates user
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 »

G'day. You put the EasyVent stuff in the same directory as the application you are developing. Or modify any IncludFile directives in your code and the EasyVent files to point to the right directories that all the files are in.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Post by NoahPhense »

Who wrote this crap.



j/k VERY nice..


- np

:shock:
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

Fangbeast wrote:G'day. You put the EasyVent stuff in the same directory as the application you are developing. Or modify any IncludFile directives in your code and the EasyVent files to point to the right directories that all the files are in.
I am just trying to run one of the demos (have tried to get several going) running.

I put the Easyvent folder (the unzipped contents of Easyvent are in here) onto my system's Desktop (and the root (C:\) directory) and opened the folder and tried to run those demos and see get the same error. That's why I'm scratching my head in confusion. All the files including the EasyVENT.pbi file and still no go.

Surely I am overlooking something?

TIA
Intrigued - Registered PureBasic, lifetime updates user
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 »

I said above "Or modify any IncludFile directives in your code and the EasyVent files to point to the right directories that all the files are in."


because some of the code in EasyVent has some lines as in below.

"XIncludeFile "c:\Pure basic\Easyvent\EasyVENTResident.pbi"


See the path it is pointing to? You must modify that path to either point to your own directory (where you put the files) or turn it into a relative path.

"XIncludeFile "EasyVENTResident.pbi"

Check all "XIncludeFile" lines to make sure they are correct for your system.
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Post Reply