NSScrollView : documentView stuck in the bottom-left corner !

  • Hi list !

    I want to programatically create a scroll view and here what I'm
    using right now :

        NSScrollView * scrollView = [[[NSScrollView alloc] init]
    autorelease];

        [scrollView setDrawsBackground:NO];
        [scrollView setHasVerticalScroller:YES];
        [scrollView setDocumentView:lateralView];
        [scrollView setAutoresizingMask:NSViewWidthSizable +
    NSViewHeightSizable];

    lateralView is just a custom NSView that does nothing special
    (currently, it only fills itself in black for test purpose) but it is
    stuck in the bottom-left corner of the scroll view ! Very problematic
    and making my scroll view unusable.

    What is the correct way to add a document view to an NSScrollView ?
    By the way, I don't want to subclass anything else that my custom
    class. Because standard NSScrollView is used in a lot of standard
    objects (NSTableView for instance) without subclassing and that it
    works perfectly. So there IS a solution to have it handle its
    document view correctly.

    Thanks for your help,

    Eric.
  • OK,

    Forget about it, I just forgot to subclass isFlipped on my custom
    class so that it returns YES.

    Eric.

    Le 10 août 05 à 19:45, Eric Morand a écrit :

    > Hi list !
    >
    >
    >
    > I want to programatically create a scroll view and here what I'm
    > using right now :
    >
    > NSScrollView * scrollView = [[[NSScrollView alloc] init]
    > autorelease];
    >
    > [scrollView setDrawsBackground:NO];
    > [scrollView setHasVerticalScroller:YES];
    > [scrollView setDocumentView:lateralView];
    > [scrollView setAutoresizingMask:NSViewWidthSizable +
    > NSViewHeightSizable];
    >
    >
    >
    > lateralView is just a custom NSView that does nothing special
    > (currently, it only fills itself in black for test purpose) but it
    > is stuck in the bottom-left corner of the scroll view ! Very
    > problematic and making my scroll view unusable.
    >
    >
    >
    > What is the correct way to add a document view to an NSScrollView ?
    > By the way, I don't want to subclass anything else that my custom
    > class. Because standard NSScrollView is used in a lot of standard
    > objects (NSTableView for instance) without subclassing and that it
    > works perfectly. So there IS a solution to have it handle its
    > document view correctly.
    >
    >
    >
    > Thanks for your help,
    >
    >
    >
    > Eric.
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<eric.morand...>
    >
    > This email sent to <eric.morand...>
    >
  • Hi again !

    i'm back with my question about NSScrollView.

    Let me summarize the problem : I want to add a custom view (created
    and populated with controls in IB) to an NSScrollView, programatically
    ( as there is no way to doing this correctly in IB) but when I add my
    custom view to the scroll view (using setDocumentView: ), it remains
    stuck in the bottom-left corner !

    So, I thought that subclassing isFlipped: in my custom viex so that
    it returns YES would solve the problem. In a way, it did : now my
    custom view is at the right place...but all my controls are drawn
    inverted (controls at the top in IB are at the bottom) !!!

    I can understand why (the coordinate system is flipped in my custom
    view), what I don't get is : how can I have a custom view created in
    IB positioned correctly in a scroll view while keeping the controls
    at the place where they are in IB ???

    Thanks by advance for your help,

    Eric.

    Le 10 août 05 à 20:06, Eric Morand a écrit :

    > OK,
    >
    > Forget about it, I just forgot to subclass isFlipped on my custom
    > class so that it returns YES.
    >
    >
    >
    > Eric.
    >
    >
    > Le 10 août 05 à 19:45, Eric Morand a écrit :
    >
    >
    >> Hi list !
    >>
    >>
    >>
    >> I want to programatically create a scroll view and here what I'm
    >> using right now :
    >>
    >> NSScrollView * scrollView = [[[NSScrollView alloc] init]
    >> autorelease];
    >>
    >> [scrollView setDrawsBackground:NO];
    >> [scrollView setHasVerticalScroller:YES];
    >> [scrollView setDocumentView:lateralView];
    >> [scrollView setAutoresizingMask:NSViewWidthSizable +
    >> NSViewHeightSizable];
    >>
    >>
    >>
    >> lateralView is just a custom NSView that does nothing special
    >> (currently, it only fills itself in black for test purpose) but it
    >> is stuck in the bottom-left corner of the scroll view ! Very
    >> problematic and making my scroll view unusable.
    >>
    >>
    >>
    >> What is the correct way to add a document view to an
    >> NSScrollView ? By the way, I don't want to subclass anything else
    >> that my custom class. Because standard NSScrollView is used in a
    >> lot of standard objects (NSTableView for instance) without
    >> subclassing and that it works perfectly. So there IS a solution to
    >> have it handle its document view correctly.
    >>
    >>
    >>
    >> Thanks for your help,
    >>
    >>
    >>
    >> Eric.
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/eric.morand%
    >> 40mac.com
    >>
    >> This email sent to <eric.morand...>
    >>
    >>
    >
    >
  • This subject is really a FAQ.

    The Quartz coordinate system used in Mac OS X has the origin in the
    lower left corner just like Postscript, PDF, and every math textbook
    that contains a graph.

    Western languages and historical CRT electron beams start in the
    upper left corner of the display and scan left to right down the
    display.

    I regret that "Cocoa Programming" does not contain more information
    on this particular subject.

    Placing an arbitrary view so that its top left corner corresponds to
    the top left cornet of a clip view [content view of a scroll view]
    that contains it is similar to the problem of centering an arbitrary
    view in a clip view.

    I usually set the document view to be a flipped NSView instance and
    then add my custom (not flipped) view as a sub-view of the document
    view.  The document view can also be used to center the custom view,
    provide margins, etc.

    Here is another solution that actually replaces the clip view:
    http://www.bergdesign.com/missing_cocoa_docs/nsclipview.html

    Here is a random sampling of the previous times this question was asked:
    http://www.cocoabuilder.com/archive/message/2003/8/1/92472
    http://www.cocoabuilder.com/archive/message/2003/10/30/1527
    http://www.cocoabuilder.com/archive/message/2005/6/27/140185
  • I just whipped up a little example of exactly what the OP wants:
    Custom view full of controls created in IB and programatically added
    to a scroll view so that the custom view stays in the top left corner
    of the scroll view.  Just for fun, I also include a mode to center
    the custom view in the scroll view.

    Send email to me and I will provide a 52K sample project to anyone
    who asks.
  • Thanks Erik !

    I've sent you a private email.

    Another member of the list (Cameron) also hinted that I could
    subclass NSClipView so that my subclass returns YES to isFlipped. In
    fact, it works very well too.

    Again, thanks to both of you,

    Eric.

    Le 13 août 05 à 04:22, Erik Buck a écrit :

    > I just whipped up a little example of exactly what the OP wants:
    > Custom view full of controls created in IB and programatically
    > added to a scroll view so that the custom view stays in the top
    > left corner of the scroll view.  Just for fun, I also include a
    > mode to center the custom view in the scroll view.
    >
    > Send email to me and I will provide a 52K sample project to anyone
    > who asks.
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<eric.morand...>
    >
    > This email sent to <eric.morand...>
    >