Page 1 of 2

Posted: Thu May 07, 2009 6:25 pm
by Niffo
A solution :

Code: Select all

#kEventClassMouse = 'mous'
#kEventClassControl = 'cntl'
#kEventMouseDown = 1
#kEventMouseUp = 2
#kEventMouseMoved = 5
#kEventMouseDragged = 6
#kEventControlTrackingAreaEntered = 23
#kEventControlTrackingAreaExited = 24

ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
   GetEventClass.i(inEvent.l)
   HIViewNewTrackingArea(inView.l, inShape.l, inID.q, *outRef)
EndImport

Structure EventTypeSpec
   eventClass.l
   eventKind.l
EndStructure

OpenWindow(0, 100,100, 300, 200, "Test Window")
ContainerGadget(0, 100, 100, 50, 50, #PB_Container_Single)

ProcedureCDLL CallBackEventsHandler(*nextHandler, theEvent, *CallBackProc)
   Static OnTheControl.b

   Select GetEventClass(theEvent)
      Case #kEventClassMouse
         If OnTheControl
            Select GetEventKind_(theEvent)
               Case #kEventMouseDown
                  Debug "MouseDown"
               Case #kEventMouseMoved, #kEventMouseDragged
                  Debug "MouseMove"
               Case #kEventMouseUp
                  Debug "MouseUp"
            EndSelect
         EndIf

      Case #kEventClassControl ;{
         Select GetEventKind_(theEvent)
            Case #kEventControlTrackingAreaEntered
               OnTheControl = #True
            Case #kEventControlTrackingAreaExited
               OnTheControl = #False
         EndSelect         
   EndSelect

  If *nexthandler : CallNextEventHandler_(*nextHandler, theEvent) : EndIf
EndProcedure

; Window handler
EventHandlerUPP = NewEventHandlerUPP_(@CallBackEventsHandler())
Events_Count = 4
Dim eventTypes.EventTypeSpec(Events_Count - 1)
eventTypes(0)\eventClass = #kEventClassMouse
eventtypes(0)\eventKind = #kEventMouseDown
eventTypes(1)\eventClass = #kEventClassMouse
eventtypes(1)\eventKind = #kEventMouseMoved
eventTypes(2)\eventClass = #kEventClassMouse
eventtypes(2)\eventKind = #kEventMouseDragged
eventTypes(3)\eventClass = #kEventClassMouse
eventtypes(3)\eventKind = #kEventMouseUp
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), EventHandlerUPP, Events_Count, @eventtypes(), @CallBackEventsHandler(), @handlerref)

; Gadget hanlder
EventHandlerUPP = NewEventHandlerUPP_(@CallBackEventsHandler())
Events_Count = 2
Dim eventTypes.EventTypeSpec(Events_Count - 1)
eventTypes(0)\eventClass = #kEventClassControl
eventtypes(0)\eventKind = #kEventControlTrackingAreaEntered
eventTypes(1)\eventClass = #kEventClassControl
eventtypes(1)\eventKind = #kEventControlTrackingAreaExited
HIViewNewTrackingArea(GadgetID(0), #Null, 0, #Null)
InstallEventHandler_(GetControlEventTarget_(GadgetID(0)), EventHandlerUPP, Events_Count, @eventtypes(), @CallBackEventsHandler(), @handlerref)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
   EndSelect
ForEver

Re: Using an EventHandler on a Gadget

Posted: Tue Nov 30, 2010 10:08 am
by cajomi
I have a problem:

At all times I have an error,
   GetEventClass.i(inEvent.l) syntax error

When I delete the file (GetE....), and I have next error
HIViewNewTrackingArea(inView.l, inShape.l, inID.q, *outRef)

and so on

What can I do?

Re: Using an EventHandler on a Gadget

Posted: Tue Nov 30, 2010 9:20 pm
by Niffo
Do not copy/paste the code directly from Safari, it does not work. You have to paste in TextEdit before copy/paste in PB ... or better : install Firefox.

Re: Using an EventHandler on a Gadget

Posted: Wed Dec 01, 2010 8:37 am
by cajomi
I have tried, with no succes.

I am unsure, but somethings is wrong?

Johannes

Re: Using an EventHandler on a Gadget

Posted: Wed Dec 01, 2010 9:59 am
by jamirokwai
cajomi wrote:I have tried, with no succes.

I am unsure, but somethings is wrong?

Johannes
Hi Johannes,

I am not sure, if TextEdit will show the invisible part of the copied text, does ist?

Try TextWrangler (its for free). There you have to set the "Hide Invisibles" (in View -> Text Display).
If you copy and paste as suggested into TextWrangler, remove the then visible big, grey dots with
search and replace. Finally copy and paste the snippet over into PureBasic. Works for me for two
years without problems - although it's a bit annoying to have to do like this...

Re: Using an EventHandler on a Gadget

Posted: Wed Dec 01, 2010 10:22 am
by cajomi
A bit surprising, but it worked!
Johannes

Re: Using an EventHandler on a Gadget

Posted: Thu Mar 10, 2011 9:28 am
by cajomi
Hello again,

I need now a solutin to get more then one window opened and get the mouse events (the same tool).
What can I do?

Johannes

Re: Using an EventHandler on a Gadget

Posted: Thu Mar 10, 2011 10:00 am
by Niffo
What do you "need" exactly ?

Re: Using an EventHandler on a Gadget

Posted: Thu Mar 10, 2011 10:30 am
by cajomi
Window 1 is clear, but now window 8, window 11 needs also the mouse, for drawing.

Johannes

Re: Using an EventHandler on a Gadget

Posted: Thu Mar 10, 2011 10:33 am
by Niffo
???

Re: Using an EventHandler on a Gadget

Posted: Thu Mar 10, 2011 10:47 am
by cajomi
Window 8:
A roundtine to get the height and manipulate them, is smaller then the others windows.

When I fill in the second routine, container gadget

InstallEventHandler_(GetWindowEventTarget_(WindowID(8)), EventHandlerUPP, Events_Count, @eventTypes(), @CallBackEventsHandler(), @handlerref)


InstallEventHandler_(GetControlEventTarget_(GadgetID(#Container2)), EventHandlerUPP, Events_Count, @eventTypes(), @CallBackEventsHandler(), @handlerref)

it hangs up.

Johannes

Re: Using an EventHandler on a Gadget

Posted: Mon Mar 14, 2011 6:56 am
by cajomi
Was it not clear enough?
Johannes

Re: Using an EventHandler on a Gadget

Posted: Mon Mar 14, 2011 12:05 pm
by cajomi
Is solved
Johannes

Re:

Posted: Fri Apr 01, 2022 12:15 am
by mestnyi
Niffo wrote: Thu May 07, 2009 6:25 pm A solution :

Code: Select all

#kEventClassMouse = 'mous'
#kEventClassControl = 'cntl'
#kEventMouseDown = 1
#kEventMouseUp = 2
#kEventMouseMoved = 5
#kEventMouseDragged = 6
#kEventControlTrackingAreaEntered = 23
#kEventControlTrackingAreaExited = 24

ImportC "/System/Library/Frameworks/Carbon.framework/Carbon"
   GetEventClass.i(inEvent.l)
   HIViewNewTrackingArea(inView.l, inShape.l, inID.q, *outRef)
EndImport

Structure EventTypeSpec
   eventClass.l
   eventKind.l
EndStructure

OpenWindow(0, 100,100, 300, 200, "Test Window")
ContainerGadget(0, 100, 100, 50, 50, #PB_Container_Single)

ProcedureCDLL CallBackEventsHandler(*nextHandler, theEvent, *CallBackProc)
   Static OnTheControl.b

   Select GetEventClass(theEvent)
      Case #kEventClassMouse
         If OnTheControl
            Select GetEventKind_(theEvent)
               Case #kEventMouseDown
                  Debug "MouseDown"
               Case #kEventMouseMoved, #kEventMouseDragged
                  Debug "MouseMove"
               Case #kEventMouseUp
                  Debug "MouseUp"
            EndSelect
         EndIf

      Case #kEventClassControl ;{
         Select GetEventKind_(theEvent)
            Case #kEventControlTrackingAreaEntered
               OnTheControl = #True
            Case #kEventControlTrackingAreaExited
               OnTheControl = #False
         EndSelect         
   EndSelect

  If *nexthandler : CallNextEventHandler_(*nextHandler, theEvent) : EndIf
EndProcedure

; Window handler
EventHandlerUPP = NewEventHandlerUPP_(@CallBackEventsHandler())
Events_Count = 4
Dim eventTypes.EventTypeSpec(Events_Count - 1)
eventTypes(0)\eventClass = #kEventClassMouse
eventtypes(0)\eventKind = #kEventMouseDown
eventTypes(1)\eventClass = #kEventClassMouse
eventtypes(1)\eventKind = #kEventMouseMoved
eventTypes(2)\eventClass = #kEventClassMouse
eventtypes(2)\eventKind = #kEventMouseDragged
eventTypes(3)\eventClass = #kEventClassMouse
eventtypes(3)\eventKind = #kEventMouseUp
InstallEventHandler_(GetWindowEventTarget_(WindowID(0)), EventHandlerUPP, Events_Count, @eventtypes(), @CallBackEventsHandler(), @handlerref)

; Gadget hanlder
EventHandlerUPP = NewEventHandlerUPP_(@CallBackEventsHandler())
Events_Count = 2
Dim eventTypes.EventTypeSpec(Events_Count - 1)
eventTypes(0)\eventClass = #kEventClassControl
eventtypes(0)\eventKind = #kEventControlTrackingAreaEntered
eventTypes(1)\eventClass = #kEventClassControl
eventtypes(1)\eventKind = #kEventControlTrackingAreaExited
HIViewNewTrackingArea(GadgetID(0), #Null, 0, #Null)
InstallEventHandler_(GetControlEventTarget_(GadgetID(0)), EventHandlerUPP, Events_Count, @eventtypes(), @CallBackEventsHandler(), @handlerref)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
   EndSelect
ForEver
not work in cocoa