/* InspectBase.h		by Paul Kunz	December 1991
 * Base class for Inspectors of Tuples and Plots.
 *
 * $Id: InspectBase.m,v 2.17.2.1 1993/10/25 18:13:40 pfkeb Exp $
 *
 * Copyright (C)  1991  The Board of Trustees of
 * The Leland Stanford Junior University.  All Rights Reserved.
 */

#import "Draw.subproj/draw.h"
#import "InspectBase.h"
#import "HDrawApp.h"
#import "HGraphicView.h"

@implementation InspectBase

- initInspFor:aDraw
{
    self = [super init];
    hDraw = aDraw;
    drawInstance = NXGetNamedObject("DrawInstance", NXApp);
    theInspector = [hDraw newInspector];
    return self;
}

- windowDidUpdate:sender
{
  if ( [sender isKindOf:[Panel class]] && [sender isKeyWindow] ) return self;
//    if ( [sender isMemberOf:[Panel class]] ) return self;
    [self load:[[drawInstance currentDocument] view]];
    comingForward = 0;
    return self;
}
- load:(GraphicView *)aView
{
     id		graphic;
     BOOL        test;
     
     graphicView = (HGraphicView *)aView;
     if ( !graphicView ) {
	  selectedPlot = nil;	/* reset so that updateView can test it */
	  firstPlot = nil;
	  [self updateEmptySelection];
	  return self;
     }
     test = [[graphicView window] isMainWindow];
     if (!test)
	  return self;	/* ignore events other than from key window */
     
     if ( [graphicView hasEmptySelection] ) {
	  selectedPlot = nil;
	  firstPlot = nil;
	  [self updateEmptySelection];
	  return self;
     }
     graphic = [graphicView firstPlot];
     if (!graphic) {
	  [ self updateMultiSelection];
	  return self;
     }
     
     selectedPlot = graphic;
     firstPlot = selectedPlot;
     if (comingForward)
	  [self fullUpdate];
     else
	  [self updateView];
     comingForward = 0;
     
     return self;
}

- firstPlot
{
    if ( [graphicView hasEmptySelection] ) {
        return nil;
    }
    return firstPlot;
}

- comingForward;
{
     comingForward = 1;
     return self;
}

/* Methods to be over-ridden by derived class */
- fullUpdate
{
     return [self updateView];	/* to be over-ridden if needed */
}

- updateView
{
    return self; /* to be over-ridden by derived class */
}
- updateEmptySelection
{
    return self; /* to be over-ridden by derived class */
}
- updateMultiSelection
{
    return self;
}
- setTuple:(ntuple) aTuple
{
    return self; /* to be over-ridden by derived class */
}
- mouseMoved:(const NXPoint *)offset in:sender
{
	return self;
}
@end

/* Methods implemented for Draw's Inspector to be compatible with
 * HippoDraw inspector
 */
 
@implementation Inspector(Hippo)

- updateView
{
    return self;
}
@end
