NSScrollview / other suggestions ?

You can even override the scroller drawing and customize the scrollers:

[code]declare function object_getClass lib CocoaLib (id as Ptr ) as Ptr
declare function class_replaceMethod lib CocoaLib (cls as ptr, name as ptr, imp as ptr, types as CString) as ptr
dim scroller as ptr = object_getClass(verticalScroller(self.viewRef))
dim p as ptr = class_replaceMethod(scroller, NSSelectorFromString(“drawKnobSlotInRect:highlight:”), AddressOf dispatch_DrawSlot, “v@:@b”)

Private Shared Sub dispatch_DrawSlot(pid as ptr, sel as ptr, rect as NSRect, highlight as Boolean)
End Sub[/code]

From using the example project, delete the ClippingContainer from the window in the IDE, then adding it from in the constructor or open event.

dim cc as new ClippingContainerControl
cc.EmbedWithin(self, 0,0,self.width,self.height)

Scrolling works but scrollbars don’t show up.

[quote=236236:@Richard Berglund]From using the example project, delete the ClippingContainer from the window in the IDE, then adding it from in the constructor or open event.

dim cc as new ClippingContainerControl
cc.EmbedWithin(self, 0,0,self.width,self.height)

Scrolling works but scrollbars don’t show up.[/quote]

I have not issues: (open event mainwindow)

dim cc as new ClippingContainerControl cc.EmbedWithin(ScrollViewWIndow, 0,0) self.ccRef=cc

You need to make sure clipping container is smaller than content container (scrollerContainer) otherwise
Scroller doesn’t show because there no content to scroll.

With your code you expand the clip to the main window size which exceeds scrollerContainer size
and therefore no scrolling is needed.

cc.EmbedWithin(self, 0,0,self.width,self.height)

#Edit:
Updated the example: scrollToBottom works correctly.

Its the XScrollview thats a little sensitive :slight_smile: Got my way finally.

  dim cc as new ClippingContainerControl(new ScrolledContainerControl)
  cc.EmbedWithin(self,0,0,self.width,self.height)
  cc.myContainer.EmbedWithin(self, 0,0)
  cc.myScrollView=new XScrollView(self,cc.myContainer)
  AddHandler cc.myScrollView.Magnify,AddressOf cc.HandleMagnify
  
  cc.LockTop=true
  cc.LockLeft=true
  cc.LockRight=true
  cc.LockBottom=true

Voila!

There is a serious issue when using Jims declares. It disables mouse click throughs. So when the main window is not active and you click on the control that uses Jims declares, it does not receive the click. So the user will have first active the window and then click on the control. Which is not how OSX apps behave (and I do get a lot of users complaining about this).
I asked Jim to take a look at this. Hoping for the fix/improvement for this.

The myFlippedDocumentViewClass needs an acceptsFirstMouse method to return true, that yes it does accept click though. From the docs

To do that add this method (Shared) to XScrollView

Shared Function acceptsFirstMouse(obj as ptr, sel as ptr, e As Ptr) As boolean return true End Function

Then in the Constructors, in the “Create an NSView subclass” section, add this line after the other class_addMethod lines

res = class_addMethod(myFlippedDocumentViewClass, NSSelectorFromString("acceptsFirstMouse:"), AddressOf acceptsFirstMouse, "b@:@")

Thanks for your feedback Christoph and Will. I’veupdate the example project.

https://www.dropbox.com/s/ulsosfe77eqp6n1/NSScrollView_updated.xojo_binary_project?dl=0

Thanks Will ! that fixed the issue.

The standard in Cocoa is not to click through (even if most applications implement it nowadays). So the comment “serious issue” was a bit unfair towards Jim.

I was most certainly not dissing on Jim or being unfair towards him !
Anyhow, thank you for your valuable input.

I have a question for the obj-c programmers among us: I have added custom a paint event for the knob and slot by overriding
the scrollers methods but I am not sure if there’s a simpler way ? (although it works fine).

(2015R4 required! )

https://www.dropbox.com/s/71kbyyk8cmaapao/NSScrollView_updated_1.xojo_binary_project?dl=0

Download no longer works. Does anyone have the project and could send me a copy?

Still hoping that one day Xojo will offer us this solution, I guess they have to make something for Windows.

p.s. You do know that the TextArea is a NSTextView within a NSScrollView right?