/* Implemenation of SliderCell class
 *
 * Copyright (C)  1993, 1994  The Board of Trustees of
 * The Leland Stanford Junior University.  All Rights Reserved.
 *
 * Authors: Scott Francis, Paul Kunz, and Libing Wang
 *
 * This file is part of an Objective-C class library for a window system
 *
 * SliderCell.m,v 1.23 1995/12/13 22:33:20 fedor Exp
 */

#include "SliderCell.h"

#include <stdlib.h>
#include <string.h>
#include <objc/typedstream2.h>

extern char * SliderCellInstanceName(void);

@class View;
@interface SliderCell(WidgetSet)
- _init;
- _setFrame:(const NXRect *)frame inView:(View *)aView;
- _setMinValue;
- _setMaxValue;
- _setValue;
- (double)_value;
- _setVertical:(BOOL)flag;
- (int)_isVertical;
- _addCallback;
- _managedBy:parent wid:(void *)widget;
@end

@implementation SliderCell : ActionCell

// + (BOOL)prefersTrackingUntilMouseUp

- init
{
	[super init];
	[self _init];
	instancename = SliderCellInstanceName();
	return self;
}

- awake
{
  return self;
}

- (double)minValue
{
    return minValue;
}

- setMinValue:(double)aDouble
{
    minValue = aDouble;
    [self _setMinValue];
    return self;
}

- (double)maxValue
{
    return maxValue;
}

- setMaxValue:(double)aDouble
{
    maxValue = aDouble;
    [self _setMaxValue];
    return self;
}

- setAltIncrementValue:(double)incValue
{
  [self notImplemented:_cmd];
  return 0;
}

- (double)altIncrementValue
{
  [self notImplemented:_cmd];
  return 0;
}

- (int)isVertical
{
    return [self _isVertical];;
}

- (const char *)stringValue
{
    float f;
    char *temp;
    
    f = [self floatValue];
    temp = (char *)malloc(sizeof(float)*2);
    sprintf(temp, "%f", f);
    return temp;
}

- setStringValue:(const char *)str
{
    double f;
    
    f = atof(str);
    if (f) [self setDoubleValue:f];
    return self;
}

- (int)intValue
{
    int intValue;
    
    intValue = [self _value];;
    return intValue;
}

- setIntValue:(int)anInt
{
    value = anInt;
    [self _setValue];
    return self;
}

- (float)floatValue
{
    float	f;
    
    f = [self _value];
    return f;
}

- setFloatValue:(float)aFloat
{
    value = (double)aFloat;
    [self _setValue];
    return self;
}

- (double)doubleValue
{
    value = [self _value];
    return value;
}

- setDoubleValue:(double)aDouble
{
    value = aDouble;
    [self _setValue];
    return self;
}

- setContinuous:(BOOL)flag
{
  return [super setContinuous: flag];
}

- (BOOL)isContinuous
{
  return [super isContinuous];
}

- (BOOL)isOpaque
{
  return [super isOpaque];
}

- calcCellSize:(NXSize *)theSize inRect:(const NXRect *)aRect
{
  [self notImplemented:_cmd];
  return 0;
}

- setTitleGray:(float)grayVal
{
  [self notImplemented:_cmd];
  return 0;
}

- (float)titleGray
{
  [self notImplemented:_cmd];
  return 0;
}

- setTitleColor:(NXColor)newColor
{
  [self notImplemented:_cmd];
  return 0;
}

- (NXColor)titleColor
{
  NXColor color;
  [self notImplemented:_cmd];
  return color;
}

- setTitleFont:fontObj
{
  [self notImplemented:_cmd];
  return 0;
}

- titleFont
{
  [self notImplemented:_cmd];
  return 0;
}

- (const char *)title
{
  [self notImplemented:_cmd];
  return 0;
}

- setTitle:(const char *)aString
{
  [self notImplemented:_cmd];
  return 0;
}

- setTitleNoCopy:(const char *)aString
{
  [self notImplemented:_cmd];
  return 0;
}

- setTitleCell:aCell
{
  [self notImplemented:_cmd];
  return 0;
}

- titleCell
{
  [self notImplemented:_cmd];
  return 0;
}

- setEnabled:(BOOL)flag
{
  return [super setEnabled: flag];
}

- setKnobThickness:(NXCoord)aFloat
{
  [self notImplemented:_cmd];
  return 0;
}

- (NXCoord)knobThickness
{
  [self notImplemented:_cmd];
  return 0;
}

- setImage:backgroundImage
{
  [self notImplemented:_cmd];
  return 0;
}

- image
{
  [self notImplemented:_cmd];
  return 0;
}

- getKnobRect:(NXRect*)knobRect flipped:(BOOL)flipped
{
  [self notImplemented:_cmd];
  return 0;
}

- drawKnob:(const NXRect*)knobRect
{
  [self notImplemented:_cmd];
  return 0;
}

- drawKnob
{
  [self notImplemented:_cmd];
  return 0;
}

- drawBarInside:(const NXRect *)aRect flipped:(BOOL)flipped
{
  [self notImplemented:_cmd];
  return 0;
}

- drawSelf:(const NXRect *)cellFrame inView:controlView
{
  return self;
}

- drawInside:(const NXRect *)cellFrame inView:controlView
{
  return self;
}

- (BOOL)startTrackingAt:(const NXPoint *)startPoint inView:controlView
{
  [self notImplemented:_cmd];
  return 0;
}

- (BOOL)continueTracking:(const NXPoint *)lastPoint 
                      at:(const NXPoint *)currentPoint inView:controlView
{
  [self notImplemented:_cmd];
  return 0;
}

- stopTracking:(const NXPoint *)lastPoint 
            at:(const NXPoint *)stopPoint inView:controlView
     mouseIsUp:(BOOL)flag
{
  [self notImplemented:_cmd];
  return 0;
}

- (BOOL)trackMouse:(NXEvent *)theEvent 
            inRect:(const NXRect *)cellFrame ofView:controlView
{
  [self notImplemented:_cmd];
  return 0;
}

- write:(TypedStream *)ts
{
  return self;
}

- read:(TypedStream *)ts
{
    int a, b, c;
    [super read:ts];
    objc_read_float(ts, &a);
    objc_read_float(ts, &b);
    objc_read_float(ts, &c);
    objc_read_type(ts, "i", &vert);
    value = (double)a;
    maxValue = (double)b;
    minValue = (double)c;
    if (minValue >= maxValue) maxValue = minValue + 1.0;
    if (value > maxValue) value = maxValue;
    if (value < minValue) value = minValue;
    
    [self init];

    [self setMaxValue:maxValue];
    [self setMinValue:minValue];
    [self setDoubleValue:value];
    [self _setVertical:vert];
    return self;
}


/* The following method is obsolete. */
// + new;

/* The following methods are not in NeXTSTEP/OpenStep */

- copyFromZone:(NSZone *)zone
{
    SliderCell	*newCell;
    
    newCell = [super copy];
    [newCell setMaxValue:maxValue];
    [newCell setMinValue:minValue];
    [newCell setDoubleValue:value];
    return newCell;
}

- setVertical:(BOOL)flag
{
    [self _setVertical:flag];
    return self;
}

@end
