// Copyright (C) 1995
// Use is governed by the MiscKit license


#import "MiscSwapViewPalette.h"

@implementation MiscSwapViewPalette

/*"
This class is the key to working with the regular swap view combo.
"*/

- (void)finishInstantiate
/*"
Does the final init which meants that all necessary associations need to be set up.
"*/
{	
    [super finishInstantiate];
    [self associateObject:realSwapObject ofType:IBObjectPboardType withView:swapImageView];
}

@end


@implementation MiscSwapView (IBDisplaying)

/*"
This category is necessary since the plain MiscSwapView doesn't draw anything, so you cannot see the object in the palette window or anywhere in IB. With the default drawSelf being pretty empty will will make it look more like those regular custom views to fix that.
"*/

- (void)drawRect:(NSRect)rect
/*"
Displays a bezel around the view and writes their class name in the center to identify subclasses, since otherwise you cannot even see where the view is (on the palette and after being dragged).
"*/
{
    // Only if we really are inside IB...
    
    if( [NSApp conformsToProtocol:@protocol(IB)] )
    {
        if( [NSApp isTestingInterface] == NO )
        {
            id		className = NSStringFromClass( [self class] );
            id		font = [NSFont boldSystemFontOfSize:12.0];			
            NSRect	ourFrame = [self bounds];
            float	xOffset;

            // We're going to look like the regular custom view..but with a different name

            if( [self drawsBackground] )
            {
                [backgroundColor set];
                NSRectFill( rect );
            }
            else
            {
                [[NSColor darkGrayColor] set];
                NSRectFill( ourFrame );  // rect

                // choose an offset gray for border and text

                [[NSColor whiteColor] set];
                ourFrame.origin.x = 1;
                ourFrame.size.width -= 1;
                ourFrame.size.height -= 1;
                NSFrameRect( ourFrame );
            }
            // Now put the white class name
            // This could be done with NSStrings drawing methods too..and might produce a nice text on screen
            // but those methods are not documented...so we kkep it that way.

            [[NSColor whiteColor] set];
            [font set];
            if( [font widthOfString:className] > ourFrame.size.width )
                xOffset = 10.0;
            else
                xOffset = (ourFrame.size.width - [font widthOfString:className]) / 2;
            PSmoveto( xOffset, (ourFrame.size.height - [font pointSize]) / 2 );
            PSshow( [className cString] );
        }
        // Otherwise we'll do what the regular swap view does

        else
        {
            // As long as you have a identifier connected to the identifier outlet, this
            // should select an initial view for you.

            if( [self drawsBackground] )
            {
                [backgroundColor set];
                NSRectFill( rect );
            }

            if( [self contentView] == nil ) [self swapContentView: identifier];
        }
    }
}

@end
