/* NSScrollView subclass to insert a "placard" within the scrollbar area. Original Source: (See copyright notice at ) */ /*" A placard is a little display in the scroll bar area; for instance what you see in TextEdit when you're in "Wrap to Page" view. PlacardScrollView is used to place a small view to the left or right of a horizontal scrollbar in a scrollview. Replace #NSScrollView with #PlacardScrollView and then hook up a view to the "placard" outlet. (The view should be 16 pixels high.) "*/ enum { PlacardLeft = 0, // default PlacardRight = 1 }; @interface PlacardScrollView : NSScrollView { IBOutlet NSView *placard; int _side; } - (void) setPlacard:(NSView *)inView; - (NSView *) placard; - (void) setSide:(int) inSide; @end @implementation PlacardScrollView /*" Release all the objects held by self, then call superclass. "*/ - (void) dealloc { [placard release]; [super dealloc]; } /*" Set the side (!{PlacardLeft} or !{PlacardRight}) that the placard will appear on. "*/ - (void) setSide:(int) inSide { _side = inSide; } /*" This setter puts it into the superview. Therefore, if you hook it up from Interface Builder, the view will be installed automagically. "*/ - (void) setPlacard:(NSView *)inView { [inView retain]; if (nil != placard) { [placard removeFromSuperview]; [placard release]; } placard = inView; [self addSubview:placard]; } /*" Return the placard view "*/ - (NSView *) placard { return placard; } /*" Tile the view. This invokes super to do most of its work, but then fits the placard into place. "*/ - (void)tile { [super tile]; if (placard && [self hasHorizontalScroller]) { NSScroller *horizScroller; NSRect horizScrollerFrame, placardFrame; horizScroller = [self horizontalScroller]; horizScrollerFrame = [horizScroller frame]; placardFrame = [placard frame]; // Now we'll just adjust the horizontal scroller size and set the placard size and location. horizScrollerFrame.size.width -= placardFrame.size.width; [horizScroller setFrameSize:horizScrollerFrame.size]; if (PlacardLeft == _side) { // Put placard where the horizontal scroller is placardFrame.origin.x = NSMinX(horizScrollerFrame); // Move horizontal scroller over to the right of the placard horizScrollerFrame.origin.x = NSMaxX(placardFrame); [horizScroller setFrameOrigin:horizScrollerFrame.origin]; } else // on right { // Put placard to the right of the new scroller frame placardFrame.origin.x = NSMaxX(horizScrollerFrame); } // Adjust height of placard placardFrame.size.height = horizScrollerFrame.size.height + 1.0; placardFrame.origin.y = [self bounds].size.height - placardFrame.size.height + 1.0; // Move the placard into place [placard setFrame:placardFrame]; } } @end