mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +00:00
Some basic implementation of these class.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11096 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a113ea6e17
commit
ae558ee576
2 changed files with 541 additions and 0 deletions
252
Source/NSRulerMarker.m
Normal file
252
Source/NSRulerMarker.m
Normal file
|
@ -0,0 +1,252 @@
|
|||
/*
|
||||
NSRulerMarker.m
|
||||
|
||||
Displays a symbol in a NSRulerView.
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: Sept 2001
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSException.h>
|
||||
#include <AppKit/NSRulerMarker.h>
|
||||
#include <AppKit/NSRulerView.h>
|
||||
#include <AppKit/NSEvent.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
|
||||
@implementation NSRulerMarker
|
||||
|
||||
- (id)initWithRulerView:(NSRulerView *)aRulerView
|
||||
markerLocation:(float)location
|
||||
image:(NSImage *)anImage
|
||||
imageOrigin:(NSPoint)imageOrigin
|
||||
{
|
||||
if (aRulerView == nil || anImage == nil)
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"No view or image for ruler marker"];
|
||||
|
||||
_isMovable = YES;
|
||||
_isRemovable = NO;
|
||||
_location = location;
|
||||
_imageOrigin = imageOrigin;
|
||||
_rulerView = aRulerView;
|
||||
ASSIGN(_image, anImage);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(_image);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSRulerView *)ruler
|
||||
{
|
||||
return _rulerView;
|
||||
}
|
||||
|
||||
- (void)setImage:(NSImage *)anImage
|
||||
{
|
||||
ASSIGN(_image, anImage);
|
||||
}
|
||||
|
||||
- (NSImage *)image
|
||||
{
|
||||
return _image;
|
||||
}
|
||||
|
||||
- (void)setImageOrigin:(NSPoint)aPoint
|
||||
{
|
||||
_imageOrigin = aPoint;
|
||||
}
|
||||
|
||||
- (NSPoint)imageOrigin
|
||||
{
|
||||
return _imageOrigin;
|
||||
}
|
||||
|
||||
- (NSRect)imageRectInRuler
|
||||
{
|
||||
//BOOL flipped = [_rulerView isFlipped];
|
||||
NSSize size = [_image size];
|
||||
|
||||
// FIXME
|
||||
if ([_rulerView orientation] == NSHorizontalRuler)
|
||||
{
|
||||
return NSMakeRect(_location - _imageOrigin.x, -_imageOrigin.y,
|
||||
size.width, size.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
return NSZeroRect;
|
||||
}
|
||||
|
||||
- (float)thicknessRequiredInRuler
|
||||
{
|
||||
NSSize size = [_image size];
|
||||
|
||||
//FIXME
|
||||
if ([_rulerView orientation] == NSHorizontalRuler)
|
||||
{
|
||||
return size.height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return size.width;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setMovable:(BOOL)flag
|
||||
{
|
||||
_isMovable = flag;
|
||||
}
|
||||
|
||||
- (BOOL)isMovable
|
||||
{
|
||||
return _isMovable;
|
||||
}
|
||||
|
||||
- (void)setRemovable:(BOOL)flag
|
||||
{
|
||||
_isRemovable = flag;
|
||||
}
|
||||
|
||||
- (BOOL)isRemovable
|
||||
{
|
||||
return _isRemovable;
|
||||
}
|
||||
|
||||
- (void)setMarkerLocation:(float)location
|
||||
{
|
||||
_location = location;
|
||||
}
|
||||
|
||||
- (float)makerLocation
|
||||
{
|
||||
return _location;
|
||||
}
|
||||
|
||||
- (void)setRepresentedObject:(id <NSCopying>)anObject
|
||||
{
|
||||
_representedObject = anObject;
|
||||
}
|
||||
|
||||
- (id <NSCopying>)representedObject
|
||||
{
|
||||
return _representedObject;
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)aRect
|
||||
{
|
||||
// FIXME
|
||||
NSPoint aPoint;
|
||||
NSRect rect = [self imageRectInRuler];
|
||||
|
||||
rect = NSIntersectionRect(aRect, rect);
|
||||
if (NSIsEmptyRect(rect))
|
||||
return;
|
||||
|
||||
[_rulerView lockFocus];
|
||||
[_image compositeToPoint: aPoint
|
||||
operation: NSCompositeSourceOver];
|
||||
[_rulerView unlockFocus];
|
||||
}
|
||||
|
||||
- (BOOL)isDragging
|
||||
{
|
||||
return _isDragging;
|
||||
}
|
||||
|
||||
- (BOOL)trackMouse:(NSEvent *)theEvent adding:(BOOL)flag
|
||||
{
|
||||
NSView *client = [_rulerView clientView];
|
||||
|
||||
if (flag)
|
||||
{
|
||||
if ([client respondsToSelector: @selector(rulerView:shouldAddMarker:)] &&
|
||||
[client rulerView: _rulerView shouldAddMarker: self] == NO)
|
||||
return NO;
|
||||
}
|
||||
else if (!_isMovable && !_isRemovable)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else if ([client respondsToSelector: @selector(rulerView:shouldMoveMarker:)] &&
|
||||
[client rulerView: _rulerView shouldMoveMarker: self] == NO)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
_isDragging = YES;
|
||||
// FIXME
|
||||
|
||||
_isDragging = NO;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
// NSCopying protocol
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
NSRulerMarker *new = (NSRulerMarker*)NSCopyObject (self, 0, zone);
|
||||
|
||||
new->_image = [_image copyWithZone: zone];
|
||||
new->_isDragging = NO;
|
||||
return new;
|
||||
}
|
||||
|
||||
// NSCoding protocol
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: _rulerView];
|
||||
[aCoder encodeObject: _image];
|
||||
[aCoder encodeConditionalObject: _representedObject];
|
||||
[aCoder encodePoint: _imageOrigin];
|
||||
[aCoder encodeValueOfObjCType: @encode(float) at: &_location];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isMovable];
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isRemovable];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
_rulerView = [aDecoder decodeObject];
|
||||
_image = [aDecoder decodeObject];
|
||||
_representedObject = [aDecoder decodeObject];
|
||||
_imageOrigin = [aDecoder decodePoint];
|
||||
[aDecoder decodeValueOfObjCType: @encode(float) at: &_location];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isMovable];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isRemovable];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// NSObject protocol
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
|
||||
|
289
Source/NSRulerView.m
Normal file
289
Source/NSRulerView.m
Normal file
|
@ -0,0 +1,289 @@
|
|||
/*
|
||||
NSRulerView.m
|
||||
|
||||
The NSRulerView class.
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||
Date: Sept 2001
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <AppKit/NSRulerMarker.h>
|
||||
#include <AppKit/NSRulerView.h>
|
||||
#include <AppKit/NSScrollView.h>
|
||||
|
||||
|
||||
NSString *defaultUnits;
|
||||
|
||||
@implementation NSRulerView
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSRulerView class])
|
||||
{
|
||||
NSArray *two = [NSArray arrayWithObject: [NSNumber numberWithFloat: 2.0]];
|
||||
NSArray *half = [NSArray arrayWithObject: [NSNumber numberWithFloat: 0.5]];
|
||||
NSArray *ten = [NSArray arrayWithObject: [NSNumber numberWithFloat: 10.0]];
|
||||
NSArray *half_fifth = [NSArray arrayWithObjects:
|
||||
[NSNumber numberWithFloat: 0.5],
|
||||
[NSNumber numberWithFloat: 0.2],
|
||||
nil];
|
||||
|
||||
// Register the predefined units
|
||||
[self registerUnitWithName: @"Inches"
|
||||
abbreviation: @"in"
|
||||
unitToPointsConversionFactor: 72.0
|
||||
stepUpCycle: two
|
||||
stepDownCycle: half];
|
||||
[self registerUnitWithName: @"Centimeters"
|
||||
abbreviation: @"cm"
|
||||
unitToPointsConversionFactor: 28.35
|
||||
stepUpCycle: two
|
||||
stepDownCycle: half_fifth];
|
||||
[self registerUnitWithName: @"Points"
|
||||
abbreviation: @"pt"
|
||||
unitToPointsConversionFactor: 1.0
|
||||
stepUpCycle: ten
|
||||
stepDownCycle: half];
|
||||
[self registerUnitWithName: @"Picas"
|
||||
abbreviation: @"pc"
|
||||
unitToPointsConversionFactor: 12.0
|
||||
stepUpCycle: ten
|
||||
stepDownCycle: half];
|
||||
|
||||
defaultUnits = [[NSUserDefaults standardUserDefaults]
|
||||
objectForKey: @"NSMeasurementUnit"];
|
||||
if (defaultUnits == nil)
|
||||
defaultUnits = @"Centimeters";
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)registerUnitWithName:(NSString *)unitName
|
||||
abbreviation:(NSString *)abbreviation
|
||||
unitToPointsConversionFactor:(float)conversionFactor
|
||||
stepUpCycle:(NSArray *)stepUpCycle
|
||||
stepDownCycle:(NSArray *)stepDownCycle
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (id)initWithScrollView:(NSScrollView *)aScrollView
|
||||
orientation:(NSRulerOrientation)orientation
|
||||
{
|
||||
// FIXME
|
||||
[super init];
|
||||
_scrollView = aScrollView;
|
||||
_orientation = orientation;
|
||||
[self setMeasurementUnits: defaultUnits];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)setMeasurementUnits:(NSString *)unitName
|
||||
{
|
||||
// FIXME
|
||||
ASSIGN(_measurementUnits, unitName);
|
||||
}
|
||||
|
||||
- (NSString *)measurementUnits
|
||||
{
|
||||
return _measurementUnits;
|
||||
}
|
||||
|
||||
- (void)setClientView:(NSView *)aView
|
||||
{
|
||||
if (_clientView == aView)
|
||||
return;
|
||||
|
||||
if ([_clientView respondsToSelector: @selector(rulerView:willSetClientView:)])
|
||||
[_clientView rulerView: self willSetClientView: aView];
|
||||
|
||||
_clientView = aView;
|
||||
// FIXME Remove all markers
|
||||
}
|
||||
|
||||
- (NSView *)clientView
|
||||
{
|
||||
return _clientView;
|
||||
}
|
||||
|
||||
- (void)setAccessoryView:(NSView *)aView
|
||||
{
|
||||
// FIXME
|
||||
ASSIGN(_accessoryView, aView);
|
||||
}
|
||||
|
||||
- (NSView *)accessoryView
|
||||
{
|
||||
return _accessoryView;
|
||||
}
|
||||
|
||||
- (void)setOriginOffset:(float)offset
|
||||
{
|
||||
_originOffset = offset;
|
||||
}
|
||||
|
||||
- (float)originOffset
|
||||
{
|
||||
return _originOffset;
|
||||
}
|
||||
|
||||
- (void)setMarkers:(NSArray *)markers
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (NSArray *)markers
|
||||
{
|
||||
return _markers;
|
||||
}
|
||||
|
||||
- (void)addMarker:(NSRulerMarker *)aMarker
|
||||
{
|
||||
[_markers addObject: aMarker];
|
||||
}
|
||||
|
||||
- (void)removeMarker:(NSRulerMarker *)aMarker
|
||||
{
|
||||
[_markers removeObject: aMarker];
|
||||
}
|
||||
|
||||
- (BOOL)trackMarker:(NSRulerMarker *)aMarker
|
||||
withMouseEvent:(NSEvent *)theEvent
|
||||
{
|
||||
return [aMarker trackMouse: theEvent adding: YES];
|
||||
}
|
||||
|
||||
- (void)moveRulerlineFromLocation:(float)oldLoc toLocation:(float)newLoc
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void)drawHashMarksAndLabelsInRect:(NSRect)aRect
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void)drawMarkersInRect:(NSRect)aRect
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void) drawRect: (NSRect)rect
|
||||
{
|
||||
[self drawHashMarksAndLabelsInRect: rect];
|
||||
[self drawMarkersInRect: rect];
|
||||
}
|
||||
|
||||
- (void)invalidateHashMarks
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
||||
- (void)setScrollView:(NSScrollView *)scrollView
|
||||
{
|
||||
// FIXME
|
||||
_scrollView = scrollView;
|
||||
}
|
||||
|
||||
- (NSScrollView *)scrollView
|
||||
{
|
||||
return _scrollView;
|
||||
}
|
||||
|
||||
- (void)setOrientation:(NSRulerOrientation)orientation
|
||||
{
|
||||
_orientation = orientation;
|
||||
}
|
||||
|
||||
- (NSRulerOrientation)orientation
|
||||
{
|
||||
return _orientation;
|
||||
}
|
||||
|
||||
- (void)setReservedThicknessForAccessoryView:(float)thickness
|
||||
{
|
||||
_reservedThicknessForAccessoryView = thickness;
|
||||
}
|
||||
|
||||
- (float)reservedThicknessForAccessoryView
|
||||
{
|
||||
return _reservedThicknessForAccessoryView;
|
||||
}
|
||||
|
||||
- (void)setReservedThicknessForMarkers:(float)thickness
|
||||
{
|
||||
_reservedThicknessForMarkers = thickness;
|
||||
}
|
||||
|
||||
- (float)reservedThicknessForMarkers
|
||||
{
|
||||
return _reservedThicknessForMarkers;
|
||||
}
|
||||
|
||||
- (void)setRuleThickness:(float)thickness
|
||||
{
|
||||
_ruleThickness = thickness;
|
||||
}
|
||||
|
||||
- (float)ruleThickness
|
||||
{
|
||||
return _ruleThickness;
|
||||
}
|
||||
|
||||
- (float)requiredThickness
|
||||
{
|
||||
// FIXME
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
- (float)baselineLocation;
|
||||
{
|
||||
// FIXME
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
- (BOOL)isFlipped
|
||||
{
|
||||
return [_scrollView isFlipped];
|
||||
}
|
||||
|
||||
// NSCoding protocol
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
// FIXME
|
||||
[super encodeWithCoder: aCoder];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
// FIXME
|
||||
return [super initWithCoder: aDecoder];
|
||||
}
|
||||
|
||||
// NSObject protocol
|
||||
|
||||
@end
|
Loading…
Reference in a new issue