It is currently Tue Jul 14, 2020 5:52 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Scrollareagadget No events
PostPosted: Sat Sep 07, 2019 1:20 pm 
Offline
Addict
Addict

Joined: Fri Aug 28, 2015 6:10 pm
Posts: 1099
Location: Portugal
Using the example in the help:-

Code:
Procedure BindScrollDatas()
    SetWindowTitle(0, "ScrollAreaGadget " +
                      "(" +
                      GetGadgetAttribute(0, #PB_ScrollArea_X) +
                      "," +                     
                      GetGadgetAttribute(0, #PB_ScrollArea_Y) +
                      ")" )
  EndProcedure
 
  If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ScrollAreaGadget(0, 10, 10, 390,220, 575, 555, 30)
      ButtonGadget  (1, 10, 10, 230, 30,"Button 1")
      ButtonGadget  (2, 50, 50, 230, 30,"Button 2")
      ButtonGadget  (3, 90, 90, 230, 30,"Button 3")
      TextGadget    (4,130,130, 230, 20,"This is the content of a ScrollAreaGadget!",#PB_Text_Right)
      CloseGadgetList()
 
    BindGadgetEvent(0, @ BindScrollDatas())
 
    Repeat
      Select WaitWindowEvent()
        Case  #PB_Event_CloseWindow
          End
        Case  #PB_Event_Gadget
          Select EventGadget()
            Case 0
              MessageRequester("Info","A Scroll has been used ! (" +
                                      GetGadgetAttribute(0, #PB_ScrollArea_X) +
                                      "," +                     
                                      GetGadgetAttribute(0, #PB_ScrollArea_Y) +
                                      ")" ,#PB_MessageRequester_Ok)
            Case 1
              MessageRequester("Info","Button 1 was pressed!",#PB_MessageRequester_Ok)
            Case 2
              MessageRequester("Info","Button 2 was pressed!",#PB_MessageRequester_Ok)
            Case 3
              MessageRequester("Info","Button 3 was pressed!",#PB_MessageRequester_Ok)
          EndSelect
      EndSelect
    ForEver
  EndIf


There appears to be no events fired for the scrollareagadget the window title is never set and no message requester shows even if the scrollbars are used when they appear.

CD

_________________
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.


Top
 Profile  
Reply with quote  
 Post subject: Re: Scrollareagadget No events
PostPosted: Sun Sep 08, 2019 10:17 am 
Offline
Enthusiast
Enthusiast

Joined: Thu May 30, 2013 4:39 pm
Posts: 507
I have no problem here.
OSX 10.13.6, PB 5.62x64


Top
 Profile  
Reply with quote  
 Post subject: Re: Scrollareagadget No events
PostPosted: Sun Sep 08, 2019 12:28 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2550
Location: Germany
Not work on macOS 10.14.6

X64: PB v5.46, v5.62, v5.71

P.S. Workaround
Update v1.02
Code:
;-TOP

; *****************************************************************************

; Workaround ScrollArreaGadget and macOS 10.14.6
; by mk-soft, v1.02, 08.09.2019

Structure udtScrollAreaGadgetData
  Window.i
  Gadget.i
  x.i
  y.i
EndStructure

Global NewMap ScrollAreaGadgetData.udtScrollAreaGadgetData()

Procedure BugFixScrollAreaGadget()
  Protected x, y
  ForEach ScrollAreaGadgetData()
    With ScrollAreaGadgetData()
      x = GetGadgetAttribute(\Gadget, #PB_ScrollArea_X)
      y = GetGadgetAttribute(\Gadget, #PB_ScrollArea_Y)
      If x <> \x Or y <> \y
        \x = x
        \y = y
        PostEvent(#PB_Event_Gadget, \Window, \Gadget, #PB_EventType_Change)
      EndIf
    EndWith
  Next
EndProcedure

Procedure AddScrollAreaGadget(Window, Gadget)
  AddMapElement(ScrollAreaGadgetData(), Hex(Gadget))
  With ScrollAreaGadgetData()
    \Window = Window
    \Gadget = Gadget
    \x = GetGadgetAttribute(\Gadget, #PB_ScrollArea_X)
    \y = GetGadgetAttribute(\Gadget, #PB_ScrollArea_Y)
  EndWith
EndProcedure

Procedure RemoveScrollAreaGadget(Gadget)
  If FindMapElement(ScrollAreaGadgetData(), Hex(Gadget))
    DeleteMapElement(ScrollAreaGadgetData())
  EndIf
EndProcedure

; *****************************************************************************

Procedure BindScrollDatas()
  SetWindowTitle(0, "ScrollAreaGadget " +
                    "(" +
                    GetGadgetAttribute(0, #PB_ScrollArea_X) +
                    "," +                     
                    GetGadgetAttribute(0, #PB_ScrollArea_Y) +
                    ")" )
EndProcedure


If OpenWindow(0, 0, 0, 405, 240, "ScrollAreaGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ScrollAreaGadget(0, 10, 10, 390,220, 575, 555, 30)
  ButtonGadget  (1, 10, 10, 230, 30,"Button 1")
  ButtonGadget  (2, 50, 50, 230, 30,"Button 2")
  ButtonGadget  (3, 90, 90, 230, 30,"Button 3")
  TextGadget    (4,130,130, 230, 20,"This is the content of a ScrollAreaGadget!",#PB_Text_Right)
  CloseGadgetList()
 
  BindGadgetEvent(0, @BindScrollDatas())
 
  AddScrollAreaGadget(0,0)
 
  AddWindowTimer(0, 999, 100)
  BindEvent(#PB_Event_Timer, @BugFixScrollAreaGadget(), 0, 999)
 
 
  Repeat
    Select WaitWindowEvent()
      Case  #PB_Event_CloseWindow
        End
      Case  #PB_Event_Gadget
        Select EventGadget()
          Case 0
;             MessageRequester("Info","A Scroll has been used ! (" +
;                                     GetGadgetAttribute(0, #PB_ScrollArea_X) +
;                                     "," +                     
;                                     GetGadgetAttribute(0, #PB_ScrollArea_Y) +
;                                     ")" ,#PB_MessageRequester_Ok)
          Case 1
            MessageRequester("Info","Button 1 was pressed!",#PB_MessageRequester_Ok)
          Case 2
            MessageRequester("Info","Button 2 was pressed!",#PB_MessageRequester_Ok)
          Case 3
            MessageRequester("Info","Button 3 was pressed!",#PB_MessageRequester_Ok)
        EndSelect
    EndSelect
  ForEver
EndIf

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Scrollareagadget No events
PostPosted: Sun Sep 08, 2019 8:25 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1738
Location: Germany
While mk-soft's workaround utilizing a window timer is running quite fine, it's not the ideal solution because of its continous polling every 100 milliseconds. A more direct way is to use API and utilize a notification callback which is only called after the scroll bar inside a ScrollAreaGadget is released. And it should be easier for Fred or freak to implement a similar solution natively in PureBasic. A drawback of this example is that it needs at least Mavericks and currently doesn't detect scrolling by a scroll wheel!

I have tested my first example successfully on these MacOS versions:
- MacOS 10.9.5 'Mavericks' with PB 5.71 x86 and x64
- MacOS 10.10.5 'Yosemite' with PB 5.71 x86 and x64
- MacOS 10.11.6 'El Capitan' with PB 5.71 x86 and x64
- MacOS 10.13.6 'High Sierra' with PB 5.71 x64
- MacOS 10.14.6 'Mojave' with PB 5.71 x64
Code:
EnableExplicit

Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
  "NSApplication sharedApplication"), "delegate")
Define NotificationCenter.I = CocoaMessage(0, 0,
  "NSNotificationCenter defaultCenter")

Structure ScrollAreaEntry
  GadgetID.I
  Object.I
  EventWasPosted.I
EndStructure

NewList ScrollArea.ScrollAreaEntry()

ProcedureC NotificationCallback(Object.I, Selector.I, Notification.I)
  Shared ScrollArea.ScrollAreaEntry()
  Protected ScrollAreaObject.I = CocoaMessage(0, Notification, "object")

  ForEach ScrollArea()
    If ScrollArea()\Object = ScrollAreaObject
      If OSVersion() > #PB_OS_MacOSX_10_10
        If ScrollArea()\EventWasPosted = #False
          PostEvent(#PB_Event_Gadget, 0, ScrollArea()\GadgetID)
          ScrollArea()\EventWasPosted = #True
        Else
          ScrollArea()\EventWasPosted = #False
        EndIf
      Else
        PostEvent(#PB_Event_Gadget, 0, ScrollArea()\GadgetID)
      EndIf

      Break
    EndIf
  Next
EndProcedure

Procedure AddScrollEventDetection(ScrollAreaID.I)
  Shared AppDelegate.I
  Shared NotificationCenter.I
  Shared ScrollArea.ScrollAreaEntry()

  Protected DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
  Protected Selector.I = sel_registerName_("" +
    "NSScrollViewDidEndLiveScrollNotification")

  If GadgetType(ScrollAreaID) = #PB_GadgetType_ScrollArea
    AddElement(ScrollArea())
    ScrollArea()\GadgetID = ScrollAreaID
    ScrollArea()\Object = GadgetID(ScrollAreaID)
    class_addMethod_(DelegateClass, Selector, @NotificationCallback(), "v@:@")
    CocoaMessage(0, NotificationCenter,
      "addObserver:", AppDelegate,
      "selector:", Selector,
      "name:$", @"NSScrollViewDidEndLiveScrollNotification",
      "object:", ScrollArea()\Object)
  EndIf
EndProcedure

If OSVersion() < #PB_OS_MacOSX_10_9
  MessageRequester("Error",
    "You need at least MacOS 10.9 'Mavericks' to run this program!",
    #PB_MessageRequester_Error)
  End
EndIf

OpenWindow(0, 270, 100, 405, 485, "ScrollAreaGadget")
ScrollAreaGadget(0, 10, 10, 390, 220, 575, 555, 30)
ButtonGadget(1, 10, 10, 230, 30,"Button 1")
ButtonGadget(2, 50, 50, 230, 30,"Button 2")
ButtonGadget(3, 90, 90, 230, 30,"Button 3")
TextGadget(4, 130, 130, 330, 20,
  "This is the content of a ScrollAreaGadget!", #PB_Text_Right)
CloseGadgetList()

ScrollAreaGadget(5, 10, 250, 390, 220, 575, 555, 30)
ButtonGadget(6, 10, 10, 230, 30,"Button 1")
CloseGadgetList()

AddScrollEventDetection(0)
AddScrollEventDetection(5)

Repeat
  Select WaitWindowEvent()
    Case  #PB_Event_CloseWindow
      Break
    Case  #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "The ScrollAreaGadget 0 has been scrolled! (" +
            GetGadgetAttribute(0, #PB_ScrollArea_X) + "," +                     
            GetGadgetAttribute(0, #PB_ScrollArea_Y) + ")"
        Case 1
          Debug "Button 1 in ScrollAreaGadget 0 was pressed!"
        Case 2
          Debug "Button 2 in ScrollAreaGadget 0 was pressed!"
        Case 3
          Debug "Button 3 in ScrollAreaGadget 0 was pressed!"
        Case 5
          Debug "The ScrollAreaGadget 5 has been scrolled! (" +
            GetGadgetAttribute(5, #PB_ScrollArea_X) + "," +                     
            GetGadgetAttribute(5, #PB_ScrollArea_Y) + ")"
        Case 6
          Debug "Button 1 in ScrollAreaGadget 5 was pressed!"
      EndSelect
  EndSelect
ForEver

CocoaMessage(0, NotificationCenter, "removeObserver:", AppDelegate)

The following second example is even compatible with older MacOS versions (successfully tested on MacOS 10.6.8 'Snow Leopard' with PB 5.62 x86 and on MacOS 10.13.6 'High Sierra' with PB 5.71 x64) and detects the dragging of the scroll bar and scrolling by a scroll wheel. As a current drawback the dragging of the scroll bar is reported multiple times while a scroll wheel movement is always only reported once. For the sake of simplicity and as a proof of concept the example demonstrates only how to modify a single ScrollAreaGadget:
Code:
EnableExplicit

Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
  "NSApplication sharedApplication"), "delegate")
Define ContentView.I
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
Define NotificationCenter.I = CocoaMessage(0, 0,
  "NSNotificationCenter defaultCenter")
Define Selector.I = sel_registerName_("boundsDidChange:")

ProcedureC NotificationCallback(Object.I, Selector.I, Notification.I)
  PostEvent(#PB_Event_Gadget, 0, 0)
EndProcedure

OpenWindow(0, 270, 100, 405, 240, "ScrollAreaGadget")
ScrollAreaGadget(0, 10, 10, 390, 220, 575, 555, 30)
ButtonGadget(1, 10, 10, 230, 30,"Button 1")
ButtonGadget(2, 50, 50, 230, 30,"Button 2")
ButtonGadget(3, 90, 90, 230, 30,"Button 3")
TextGadget(4, 130, 130, 330, 20,
  "This is the content of a ScrollAreaGadget!", #PB_Text_Right)
CloseGadgetList()

; ----- Set ContentView of ScrollAreaGadget to post its scrolling changes
ContentView = CocoaMessage(0, GadgetID(0), "contentView")
CocoaMessage(0, ContentView, "setPostsBoundsChangedNotifications:", #YES)

; ----- Register as an observer of those scrolling changes
class_addMethod_(DelegateClass, Selector, @NotificationCallback(), "v@:@")
CocoaMessage(0, NotificationCenter,
  "addObserver:", AppDelegate,
  "selector:", Selector,
  "name:$", @"NSViewBoundsDidChangeNotification",
  "object:", ContentView)

Repeat
  Select WaitWindowEvent()
    Case  #PB_Event_CloseWindow
      Break
    Case  #PB_Event_Gadget
      Select EventGadget()
        Case 0
          Debug "The ScrollAreaGadget 0 has been scrolled! (" +
            GetGadgetAttribute(0, #PB_ScrollArea_X) + "," +                     
            GetGadgetAttribute(0, #PB_ScrollArea_Y) + ")"
        Case 1
          Debug "Button 1 in ScrollAreaGadget 0 was pressed!"
        Case 2
          Debug "Button 2 in ScrollAreaGadget 0 was pressed!"
        Case 3
          Debug "Button 3 in ScrollAreaGadget 0 was pressed!"
      EndSelect
  EndSelect
ForEver

CocoaMessage(0, NotificationCenter, "removeObserver:", AppDelegate)


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 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