* NSApplication.m minor optimiztions.

* NSAttributedString.m sizeWithAttributes: implement tab support.
	* NSStringDrawing.m sizeWithAttributes: implement tab support.
	* NSScroller.m trackScrollButtons: add temporary hack in support of XRAW's
		heavily optimized scrolling machinery.
	* NSScroller.m remove sendAction:to:
	* NSScrolView.m _doScroll: implement scroller update when scrolling via
		buttons
	* NSScrolView.m reflectScrolledClipView comment out setNeedsDisplay as it
		causes display flicker.
	* NSText.m add changes from Daniel B�hringer, set initFrame to default
		values to prevent infinite loop in rebuildLineLayout, minor tweaks
	* NSView.m minor optimiztions.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3071 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
far 1998-10-15 12:04:53 +00:00
parent 2e3f81e829
commit 748f6b3661
14 changed files with 1042 additions and 535 deletions

View file

@ -1,3 +1,19 @@
Thu Oct 15 1998 Felipe A. Rodriguez <far@ix.netcom.com>
* NSApplication.m minor optimiztions.
* NSAttributedString.m sizeWithAttributes: implement tab support.
* NSStringDrawing.m sizeWithAttributes: implement tab support.
* NSScroller.m trackScrollButtons: add temporary hack in support of XRAW's
heavily optimized scrolling machinery.
* NSScroller.m remove sendAction:to:
* NSScrolView.m _doScroll: implement scroller update when scrolling via
buttons
* NSScrolView.m reflectScrolledClipView comment out setNeedsDisplay as it
causes display flicker.
* NSText.m add changes from Daniel Bðhringer, set initFrame to default
values to prevent infinite loop in rebuildLineLayout, minor tweaks
* NSView.m minor optimiztions.
Fri Sep 18 10:21:38 1998 Adam Fedor <fedor@ultra.doc.com> Fri Sep 18 10:21:38 1998 Adam Fedor <fedor@ultra.doc.com>
* Source/NSClipView.m (MIN, MAX): Remove. * Source/NSClipView.m (MIN, MAX): Remove.

View file

@ -55,7 +55,7 @@ extern NSString *NSKernAttributeName; // NSNumber float, 0
// defaultParagraphStyle // defaultParagraphStyle
// //
// NSKernAttributeName NSNumber float, offset from // NSKernAttributeName NSNumber float, offset from
// baseline, amount tomodify default // baseline, amount to modify default
// kerning, if 0 kerning is off // kerning, if 0 kerning is off
enum enum

View file

@ -107,21 +107,21 @@ typedef enum _NSSelectionAffinity
id lineLayoutInformation; id lineLayoutInformation;
NSMutableDictionary *typingAttributes; NSMutableDictionary *typingAttributes;
float currentCursorX; float currentCursorX; // column-stable cursor up/down
BOOL displayDisabled; BOOL displayDisabled;
int spellCheckerDocumentTag; int spellCheckerDocumentTag;
} }
// GNU utility methods // GNU utility methods
// return value is guaranteed to be a NSAttributedString even if data is only NSString // return value is guaranteed to be a NSAttributedString even if data contains only NSString
+(NSAttributedString*) attributedStringForData:(NSData*) aData; +(NSAttributedString*) attributedStringForData:(NSData*) aData;
+(NSData*) dataForAttributedString:(NSAttributedString*) aString; +(NSData*) dataForAttributedString:(NSAttributedString*) aString;
+(NSString*) newlineString; // GNU extension (override it if you want other characters treated as newline characters) +(NSString*) newlineString; // GNU extension (override it if you want other characters treated as newline characters)
// //
// Getting and Setting Contents // Getting and Setting Contents (low level: no selection handling, relayout or display)
// //
-(void) replaceRange:(NSRange)range withAttributedString:(NSAttributedString*)attrString; // GNU extension -(void) replaceRange:(NSRange)range withAttributedString:(NSAttributedString*)attrString; // GNU extension
-(void) replaceRange:(NSRange)range withString:(NSString*) aString; -(void) replaceRange:(NSRange)range withString:(NSString*) aString;
@ -241,8 +241,8 @@ typedef enum _NSSelectionAffinity
// //
// Managing the Delegate // Managing the Delegate
// //
- (id)delegate; - delegate;
- (void)setDelegate:(id)anObject; -(void) setDelegate:anObject;
// //
@ -262,13 +262,13 @@ typedef enum _NSSelectionAffinity
- (void)ignoreSpelling:(id)sender; - (void)ignoreSpelling:(id)sender;
// //
// these NSTextView methods are here only informally // these NSTextView methods are here only informally (GNU extensions)
// //
-(int) spellCheckerDocumentTag; -(int) spellCheckerDocumentTag;
-(void) insertText:(NSString *)insertString; -(void) insertText:insertString; // argument may be of class NSString or NSAttributedString (if isRichText)
-(NSMutableDictionary*) typingAttributes; -(NSMutableDictionary*) typingAttributes;
-(void) setTypingAttributes:(NSDictionary *)dict; -(void) setTypingAttributes:(NSDictionary *)attrs;
-(BOOL) shouldDrawInsertionPoint; -(BOOL) shouldDrawInsertionPoint;
@ -277,26 +277,29 @@ typedef enum _NSSelectionAffinity
-(NSArray*) acceptableDragTypes; -(NSArray*) acceptableDragTypes;
-(void) updateDragTypeRegistration; -(void) updateDragTypeRegistration;
-(NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity; -(NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity; // override if you want special cursor behaviour
// //
// these NSLayoutManager- like methods are here only informally // these NSLayoutManager- like methods are here only informally (GNU extensions)
// //
-(unsigned) characterIndexForPoint:(NSPoint)point; -(unsigned) characterIndexForPoint:(NSPoint)point;
-(NSRect) rectForCharacterIndex:(unsigned) index; -(NSRect) rectForCharacterIndex:(unsigned) index;
-(NSRect) boundingRectForLineRange:(NSRange)lineRange; -(NSRect) boundingRectForLineRange:(NSRange)lineRange;
-(NSRange) characterRangeForBoundingRect:(NSRect)bounds; -(NSRange) characterRangeForBoundingRect:(NSRect)bounds;
-(NSRange) lineRangeForRect:(NSRect) aRect;
// //
// these are implementation specific // these are implementation specific (GNU extensions)
// //
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine; // returns count of lines actually updated (e.g. drawing optimization) -(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine; // returns count of lines actually updated (e.g. drawing optimization)
-(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine; -(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // override for special layout of plain text
-(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex; // is identical to the real line number (not just counted return characters) -(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // ditto for rich text
-(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex; // return value is identical to the real line number (plus counted newline characters)
-(void) redisplayForLineRange:(NSRange) redrawLineRange; -(void) redisplayForLineRange:(NSRange) redrawLineRange;
-(void) drawRichLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:) -(void) drawRichLinesInLineRange:(NSRange) aRange; // low level, override but never invoke (use redisplayForLineRange:)
-(void) drawPlainLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:) -(void) drawPlainLinesInLineRange:(NSRange) aRange; // low level, override but never invoke (use redisplayForLineRange:)
// //
// various GNU extensions // various GNU extensions
@ -305,6 +308,14 @@ typedef enum _NSSelectionAffinity
-(void) setSelectionWordGranularitySet:(NSCharacterSet*) aSet; -(void) setSelectionWordGranularitySet:(NSCharacterSet*) aSet;
-(void) setSelectionParagraphGranularitySet:(NSCharacterSet*) aSet; -(void) setSelectionParagraphGranularitySet:(NSCharacterSet*) aSet;
//
// private (never invoke, never subclass)
//
-(void) drawRectNoSelection:(NSRect)rect;
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine; // low level never invoke (use rebuildLineLayoutInformationStartingAtLine:)
-(int) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine; // ditto
@end @end
/* Notifications */ /* Notifications */
@ -321,16 +332,3 @@ extern NSString *NSTextDidChangeNotification;
@end @end
#endif // _GNUstep_H_NSText #endif // _GNUstep_H_NSText
#if 0
NSFontAttributeName; /* NSFont, default Helvetica 12 */
-> NSParagraphStyleAttributeName; /* NSParagraphStyle, default defaultParagraphStyle */
NSForegroundColorAttributeName; /* NSColor, default blackColor */
NSUnderlineStyleAttributeName; /* int, default 0: no underline */
NSSuperscriptAttributeName; /* int, default 0 */
NSBackgroundColorAttributeName; /* NSColor, default nil: no background */
-> NSAttachmentAttributeName; /* NSTextAttachment, default nil */
NSLigatureAttributeName; /* int, default 1: default ligatures, 0: no ligatures, 2: all ligatures */
NSBaselineOffsetAttributeName; /* float, in points; offset from baseline, default 0 */
NSKernAttributeName; /* float, amount to modify default kerning, if 0, kerning off */
#endif

View file

@ -63,10 +63,9 @@ static BOOL gnustep_gui_app_is_in_dealloc;
static NSEvent *gnustep_gui_null_event; static NSEvent *gnustep_gui_null_event;
static id NSApp; static id NSApp;
#define ASSIGN(a, b) \ #define ASSIGN(a, b) [b retain]; \
[b retain]; \ [a release]; \
[a release]; \ a = b;
a = b;
@implementation NSApplication @implementation NSApplication
@ -336,75 +335,98 @@ NSAutoreleasePool* pool;
// Getting, removing, and posting events // Getting, removing, and posting events
// //
- (BOOL)event:(NSEvent *)theEvent matchMask:(unsigned int)mask - (BOOL)event:(NSEvent *)theEvent matchMask:(unsigned int)mask
{ {
NSEventType t; if (mask == NSAnyEventMask) // If mask is for any event
return YES; // then return success
// If mask is for any event then return success if (!theEvent)
if (mask == NSAnyEventMask) return NO;
return YES;
if (theEvent == gnustep_gui_null_event) // Don't check a null event
return NO;
if (!theEvent) return NO; switch([theEvent type])
{
case NSLeftMouseDown:
if (mask & NSLeftMouseDownMask)
return YES;
break;
// Don't check the null event case NSLeftMouseUp:
if (theEvent == gnustep_gui_null_event) return NO; if (mask & NSLeftMouseUpMask)
return YES;
break;
t = [theEvent type]; case NSRightMouseDown:
if (mask & NSRightMouseDownMask)
return YES;
break;
if ((t == NSLeftMouseDown) && (mask & NSLeftMouseDownMask)) case NSRightMouseUp:
return YES; if (mask & NSRightMouseUpMask)
return YES;
break;
if ((t == NSLeftMouseUp) && (mask & NSLeftMouseUpMask)) case NSMouseMoved:
return YES; if (mask & NSMouseMovedMask)
return YES;
break;
if ((t == NSRightMouseDown) && (mask & NSRightMouseDownMask)) case NSMouseEntered:
return YES; if (mask & NSMouseEnteredMask)
return YES;
break;
if ((t == NSRightMouseUp) && (mask & NSRightMouseUpMask)) case NSMouseExited:
return YES; if (mask & NSMouseExitedMask)
return YES;
break;
if ((t == NSMouseMoved) && (mask & NSMouseMovedMask)) case NSLeftMouseDragged:
return YES; if (mask & NSLeftMouseDraggedMask)
return YES;
break;
if ((t == NSMouseEntered) && (mask & NSMouseEnteredMask)) case NSRightMouseDragged:
return YES; if (mask & NSRightMouseDraggedMask)
return YES;
break;
if ((t == NSMouseExited) && (mask & NSMouseExitedMask)) case NSKeyDown:
return YES; if (mask & NSKeyDownMask)
return YES;
break;
if ((t == NSLeftMouseDragged) && (mask & NSLeftMouseDraggedMask)) case NSKeyUp:
return YES; if (mask & NSKeyUpMask)
return YES;
break;
if ((t == NSRightMouseDragged) && (mask & NSRightMouseDraggedMask)) case NSFlagsChanged:
return YES; if (mask & NSFlagsChangedMask)
return YES;
break;
if ((t == NSKeyDown) && (mask & NSKeyDownMask)) case NSPeriodic:
return YES; if (mask & NSPeriodicMask)
return YES;
break;
if ((t == NSKeyUp) && (mask & NSKeyUpMask)) case NSCursorUpdate:
return YES; if (mask & NSCursorUpdateMask)
return YES;
break;
if ((t == NSFlagsChanged) && (mask & NSFlagsChangedMask)) default:
return YES; break;
}
if ((t == NSPeriodic) && (mask & NSPeriodicMask))
return YES;
if ((t == NSCursorUpdate) && (mask & NSCursorUpdateMask))
return YES;
return NO; return NO;
} }
- (void)setCurrentEvent:(NSEvent *)theEvent
{
[theEvent retain];
[current_event release];
current_event = theEvent;
}
- (NSEvent *)currentEvent; - (NSEvent *)currentEvent;
{ {
return current_event; return current_event;
} }
- (void)discardEventsMatchingMask:(unsigned int)mask - (void)discardEventsMatchingMask:(unsigned int)mask
@ -415,12 +437,13 @@ NSAutoreleasePool* pool;
- (NSEvent*)_eventMatchingMask:(unsigned int)mask - (NSEvent*)_eventMatchingMask:(unsigned int)mask
{ {
NSEvent* event; NSEvent* event;
int i, count = [event_queue count]; int i, count;
[self getNextEvent]; [self getNextEvent];
if ((count = [event_queue count])) // Get an event from if ((count = [event_queue count])) // Get an event from
{ // the events queue { // the events queue
//fprintf(stderr,"NSAppliation _eventMatchingMask: count %d\n", count);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
event = [event_queue objectAtIndex:i]; event = [event_queue objectAtIndex:i];
@ -428,7 +451,7 @@ int i, count = [event_queue count];
{ {
[event retain]; [event retain];
[event_queue removeObjectAtIndex:i]; [event_queue removeObjectAtIndex:i];
[self setCurrentEvent:event]; ASSIGN(current_event, event);
return [event autorelease]; return [event autorelease];
} }
@ -458,7 +481,7 @@ BOOL done = NO;
{ // for next event { // for next event
NSDate *limitDate, *originalLimitDate; NSDate *limitDate, *originalLimitDate;
// Retain the limitDate so it doesn't get // Retain the limitDate so it doesn't get
// release accidentally by runMode:beforeDate: // released accidentally by runMode:beforeDate:
// if a timer which has this date as fire date // if a timer which has this date as fire date
// gets released. // gets released.
limitDate = [[currentLoop limitDateForMode:mode] retain]; limitDate = [[currentLoop limitDateForMode:mode] retain];
@ -483,13 +506,12 @@ BOOL done = NO;
if (event) if (event)
break; break;
} }
type = [event type];
// Unhide the cursor if necessary // Unhide the cursor if necessary
if (event != gnustep_gui_null_event) // and event is not a null event if (event != gnustep_gui_null_event) // and event is not a null event
{ // do so only if we should {
if ([NSCursor isHiddenUntilMouseMoves]) // unhide when mouse moves if ([NSCursor isHiddenUntilMouseMoves]) // do so only if we should
{ // and event is mouse event { // unhide when mouse moves
type = [event type]; // and event is mouse event
if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp) if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp)
|| (type == NSRightMouseDown) || (type == NSRightMouseUp) || (type == NSRightMouseDown) || (type == NSRightMouseUp)
|| (type == NSMouseMoved)) || (type == NSMouseMoved))

View file

@ -28,18 +28,44 @@
#include <AppKit/NSAttributedString.h> #include <AppKit/NSAttributedString.h>
#include <AppKit/AppKit.h> #include <AppKit/AppKit.h>
// by default tabs are measured as one
#define TABWIDTH 3 // char so this value is set to one
// minus the default tab width of 4
@implementation NSString(NSAttributedString) @implementation NSString(NSAttributedString)
- (NSSize)sizeWithAttributes:(NSDictionary *)attrs - (NSSize)sizeWithAttributes:(NSDictionary *)attrs
{ {
NSFont *font; NSFont *font;
const char *str = [self cString];
int i = 0, j = TABWIDTH;
float tabSize;
while(*str != '\0') // calc the additional size
{ // to be added for tabs.
if(*str++ == '\t')
{
i += j; // j is the max number of spaces needed per
j = TABWIDTH; // tab. the number of spaces needed per
} // tab varies in order to align each tab at
else // even multiples of TABWIDTH+1.
j = j-- > 0 ? j : TABWIDTH;
};
// fprintf(stderr,"NSAttributedString sizeWithAttributes tabs: %d\n", i);
// if font is not // if font is not
if(!(font = [attrs objectForKey:NSFontAttributeName])) // specified, use if(!(font = [attrs objectForKey:NSFontAttributeName])) // specified, use
font = [NSFont userFontOfSize:12]; // the default font = [NSFont userFontOfSize:12]; // the default
return NSMakeSize([font widthOfString:self], [font pointSize]); #ifdef FAR_DEBUG
fprintf(stderr,"NSAttributedString sizeWithAttributes \"%s\" width: %f\n", [self cString], [font widthOfString:self]);
fprintf(stderr,"NSAttributedString sizeWithAttributes width: %f\n", [font widthOfString:self]);
#endif
tabSize = (float)i * [font widthOfString:@" "];
return NSMakeSize(([font widthOfString:self] + tabSize), [font pointSize]);
} }
@end @end

View file

@ -57,7 +57,7 @@
if (_documentView) { if (_documentView) {
[self addSubview:_documentView]; [self addSubview:_documentView];
/* Register to notifications sent by the document view */ /* Register for notifications sent by the document view */
[_documentView setPostsFrameChangedNotifications:YES]; [_documentView setPostsFrameChangedNotifications:YES];
[_documentView setPostsBoundsChangedNotifications:YES]; [_documentView setPostsBoundsChangedNotifications:YES];
@ -120,7 +120,7 @@
- (NSRect)documentRect - (NSRect)documentRect
{ {
NSRect documentFrame = [_documentView frame]; NSRect documentFrame = [_documentView frame];
NSRect clipViewBounds = [self bounds]; NSRect clipViewBounds = bounds;
NSRect rect; NSRect rect;
rect.origin = documentFrame.origin; rect.origin = documentFrame.origin;
@ -133,7 +133,7 @@
- (NSRect)documentVisibleRect - (NSRect)documentVisibleRect
{ {
NSRect documentBounds = [_documentView bounds]; NSRect documentBounds = [_documentView bounds];
NSRect clipViewBounds = [self bounds]; NSRect clipViewBounds = bounds;
NSRect rect; NSRect rect;
rect.origin = clipViewBounds.origin; rect.origin = clipViewBounds.origin;
@ -202,14 +202,14 @@
[super_view reflectScrolledClipView:self]; [super_view reflectScrolledClipView:self];
} }
- (id)documentView { return _documentView; } - (id)documentView { return _documentView; }
- (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; } - (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; }
- (BOOL)copiesOnScroll { return _copiesOnScroll; } - (BOOL)copiesOnScroll { return _copiesOnScroll; }
- (void)setDocumentCursor:(NSCursor*)aCursor { ASSIGN(_cursor, aCursor); } - (void)setDocumentCursor:(NSCursor*)aCursor { ASSIGN(_cursor, aCursor); }
- (NSCursor*)documentCursor { return _cursor; } - (NSCursor*)documentCursor { return _cursor; }
- (NSColor*)backgroundColor { return _backgroundColor; } - (NSColor*)backgroundColor { return _backgroundColor; }
- (BOOL)isFlipped { return [_documentView isFlipped]; } - (BOOL)isFlipped { return [_documentView isFlipped]; }
- (BOOL)acceptsFirstResponder { return _documentView != nil; } - (BOOL)acceptsFirstResponder { return _documentView != nil; }
- (void)setBackgroundColor:(NSColor*)aColor - (void)setBackgroundColor:(NSColor*)aColor
{ {

View file

@ -52,6 +52,26 @@
[a release]; \ [a release]; \
a = b; a = b;
#ifdef MIN
# undef MIN
#endif
#define MIN(A,B) ({ typeof(A) __a = (A); \
typeof(B) __b = (B); \
__a < __b ? __a : __b; })
#ifdef MAX
# undef MAX
#endif
#define MAX(A,B) ({ typeof(A) __a = (A); \
typeof(B) __b = (B); \
__a < __b ? __b : __a; })
#ifdef ABS
# undef ABS
#endif
#define ABS(A) ({ typeof(A) __a = (A); __a < 0 ? -__a : __a; })
#define SIGN(x) \ #define SIGN(x) \
({typeof(x) _SIGN_x = (x); \ ({typeof(x) _SIGN_x = (x); \
_SIGN_x > 0 ? 1 : (_SIGN_x == 0 ? 0 : -1); }) _SIGN_x > 0 ? 1 : (_SIGN_x == 0 ? 0 : -1); })

View file

@ -81,7 +81,7 @@ static NSFont* menuFont = nil;
if (!menuFont) if (!menuFont)
menuFont = [[NSFont systemFontOfSize:0] retain]; menuFont = [[NSFont systemFontOfSize:0] retain];
cellSize = NSMakeSize (1, [menuFont pointSize] - [menuFont descender] + 4); cellSize = NSMakeSize (1, [menuFont pointSize] - [menuFont descender] + 6);
return self; return self;
} }

View file

@ -5,6 +5,8 @@
Author: Ovidiu Predescu <ovidiu@net-community.com> Author: Ovidiu Predescu <ovidiu@net-community.com>
Date: July 1997 Date: July 1997
Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: October 1998
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
@ -95,6 +97,7 @@ static Class rulerViewClass = nil;
_pageScroll = 10; _pageScroll = 10;
_borderType = NSBezelBorder; _borderType = NSBezelBorder;
_scrollsDynamically = YES; _scrollsDynamically = YES;
autoresizingMask = NSViewMaxYMargin;
[self tile]; [self tile];
return self; return self;
@ -193,119 +196,153 @@ static Class rulerViewClass = nil;
- (void)_doScroll:(NSScroller*)scroller - (void)_doScroll:(NSScroller*)scroller
{ {
float floatValue = [scroller floatValue]; float floatValue = [scroller floatValue];
NSRect clipViewBounds = [_contentView bounds]; NSRect clipViewBounds = [_contentView bounds];
NSScrollerPart hitPart = [scroller hitPart]; NSScrollerPart hitPart = [scroller hitPart];
NSRect documentRect = [_contentView documentRect]; NSRect documentRect = [_contentView documentRect];
float amount = 0; float amount = 0;
NSPoint point; NSPoint point;
NSDebugLog (@"_doScroll: float value = %f", floatValue); NSDebugLog (@"_doScroll: float value = %f", floatValue);
_knobMoved = NO; _knobMoved = NO;
if (hitPart == NSScrollerIncrementLine)
amount = _lineScroll;
else if (hitPart == NSScrollerIncrementPage)
amount = _pageScroll;
else if (hitPart == NSScrollerDecrementLine)
amount = -_lineScroll;
else if (hitPart == NSScrollerDecrementPage)
amount = -_pageScroll;
else
_knobMoved = YES;
if (!_knobMoved) { if(hitPart == NSScrollerKnob)
if (scroller == _horizScroller) { _knobMoved = YES;
point.x = clipViewBounds.origin.x + amount; else
point.y = clipViewBounds.origin.y; {
} if (hitPart == NSScrollerIncrementLine)
else if (scroller == _vertScroller) { amount = _lineScroll;
point.x = clipViewBounds.origin.x; else if (hitPart == NSScrollerIncrementPage)
/* For the vertical scroller the amount should actually be reversed */ amount = _pageScroll;
// amount = -amount; else if (hitPart == NSScrollerDecrementLine)
amount = -_lineScroll;
else if (hitPart == NSScrollerDecrementPage)
amount = -_pageScroll;
else
_knobMoved = YES;
}
/* If the view is flipped we also have to reverse the meanings of
increasing or decreasing of the y coordinate */
// if (![_contentView isFlipped])
// amount = -amount;
NSDebugLog (@"increment/decrement: amount = %f, flipped = %d", if (!_knobMoved) // button scrolling
amount, [_contentView isFlipped]); {
point.y = clipViewBounds.origin.y + amount; if (scroller == _horizScroller)
} {
else { point.x = clipViewBounds.origin.x + amount;
/* do nothing */ point.y = clipViewBounds.origin.y;
return; }
} else
} {
else { if (scroller == _vertScroller) // For the vertical
if (scroller == _horizScroller) { { // scroller the amount
point.x = floatValue * (documentRect.size.width point.x = clipViewBounds.origin.x; // should be reversed
- clipViewBounds.size.width); amount = -amount;
point.y = clipViewBounds.origin.y;
}
else if (scroller == _vertScroller) {
point.x = clipViewBounds.origin.x;
if (![_contentView isFlipped])
floatValue = 1 - floatValue;
point.y = floatValue * (documentRect.size.height
- clipViewBounds.size.height);
}
else {
/* do nothing */
return;
}
}
[_contentView scrollToPoint:point]; // If the view is flipped we also have to
_knobMoved = NO; // reverse the meanings of increasing or
// decreasing of the y coordinate
// if (![_contentView isFlipped])
// amount = -amount;
NSDebugLog (@"increment/decrement: amount = %f, flipped = %d",
amount, [_contentView isFlipped]);
point.y = clipViewBounds.origin.y + amount;
point.y = point.y < 0 ? 0 : point.y; // FIX ME s/b in
} // clipview
else
return; // do nothing
}
}
else
{ // knob scolling
if (scroller == _horizScroller)
{
point.x = floatValue * (documentRect.size.width
- clipViewBounds.size.width);
point.y = clipViewBounds.origin.y;
}
else
{
if (scroller == _vertScroller)
{
point.x = clipViewBounds.origin.x;
if (![_contentView isFlipped])
floatValue = 1 - floatValue;
point.y = floatValue * (documentRect.size.height
- clipViewBounds.size.height);
}
else
return; // do nothing
}
}
[_contentView scrollToPoint:point]; // scroll clipview
if (!_knobMoved)
{ // if scrolling via
[self reflectScrolledClipView:_contentView]; // buttons update
if (scroller == _vertScroller) // scroller pos to
[_vertScroller displayIfNeeded]; // reflect clipview
else
[_horizScroller displayIfNeeded];
[window flushWindow];
}
} }
- (void)reflectScrolledClipView:(NSClipView*)aClipView - (void)reflectScrolledClipView:(NSClipView*)aClipView
{ {
NSRect documentFrame = NSZeroRect; NSRect documentFrame = NSZeroRect;
NSRect clipViewBounds = NSZeroRect; NSRect clipViewBounds = NSZeroRect;
float floatValue; float floatValue;
float knobProportion; float knobProportion;
id documentView; id documentView;
// do nothing if
if(aClipView != _contentView) // aClipView is not
return; // our content view
if (_knobMoved) if (_knobMoved) // is this really needed?
return; return; // FAR FIX ME ?
NSDebugLog (@"reflectScrolledClipView:"); NSDebugLog (@"reflectScrolledClipView:");
if (_contentView) { clipViewBounds = [_contentView bounds];
clipViewBounds = [_contentView bounds]; if ((documentView = [_contentView documentView]))
if ((documentView = [_contentView documentView])) documentFrame = [documentView frame];
documentFrame = [documentView frame];
}
if (_hasVertScroller) { if (_hasVertScroller)
if (documentFrame.size.height <= clipViewBounds.size.height) {
[_vertScroller setEnabled:NO]; if (documentFrame.size.height <= clipViewBounds.size.height)
else { [_vertScroller setEnabled:NO];
[_vertScroller setEnabled:YES]; else
knobProportion = clipViewBounds.size.height / documentFrame.size.height; {
floatValue = clipViewBounds.origin.y [_vertScroller setEnabled:YES];
/ (documentFrame.size.height - clipViewBounds.size.height); knobProportion = clipViewBounds.size.height /
if (![_contentView isFlipped]) documentFrame.size.height;
floatValue = 1 - floatValue; floatValue = clipViewBounds.origin.y / (documentFrame.size.height -
[_vertScroller setFloatValue:floatValue knobProportion:knobProportion]; clipViewBounds.size.height);
} if (![_contentView isFlipped])
} floatValue = 1 - floatValue;
[_vertScroller setFloatValue:floatValue
knobProportion:knobProportion];
}
}
if (_hasHorizScroller) { if (_hasHorizScroller)
if (documentFrame.size.width <= clipViewBounds.size.width) {
[_horizScroller setEnabled:NO]; if (documentFrame.size.width <= clipViewBounds.size.width)
else { [_horizScroller setEnabled:NO];
[_horizScroller setEnabled:YES]; else
knobProportion = clipViewBounds.size.width / documentFrame.size.width; {
floatValue = clipViewBounds.origin.x [_horizScroller setEnabled:YES];
/ (documentFrame.size.width - clipViewBounds.size.width); knobProportion = clipViewBounds.size.width /
[_horizScroller setFloatValue:floatValue knobProportion:knobProportion]; documentFrame.size.width;
} floatValue = clipViewBounds.origin.x / (documentFrame.size.width -
} clipViewBounds.size.width);
[self setNeedsDisplay:YES]; [_horizScroller setFloatValue:floatValue
knobProportion:knobProportion];
}
}
// [self setNeedsDisplay:YES]; // not needed by XRAW causes flicker
} }
- (void)setHorizontalRulerView:(NSRulerView*)aRulerView - (void)setHorizontalRulerView:(NSRulerView*)aRulerView

View file

@ -31,6 +31,7 @@
#include <Foundation/NSRunLoop.h> #include <Foundation/NSRunLoop.h>
#include <AppKit/NSScroller.h> #include <AppKit/NSScroller.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSWindow.h> #include <AppKit/NSWindow.h>
#include <AppKit/NSButtonCell.h> #include <AppKit/NSButtonCell.h>
#include <AppKit/NSApplication.h> #include <AppKit/NSApplication.h>
@ -61,16 +62,16 @@ static NSButtonCell* knobCell = nil;
} }
} }
+ (float)scrollerWidth { return 18; } + (float)scrollerWidth { return 18; }
- (NSScrollArrowPosition)arrowsPosition { return _arrowsPosition; } - (NSScrollArrowPosition)arrowsPosition { return _arrowsPosition; }
- (NSUsableScrollerParts)usableParts { return _usableParts; } - (NSUsableScrollerParts)usableParts { return _usableParts; }
- (float)knobProportion { return _knobProportion; } - (float)knobProportion { return _knobProportion; }
- (NSScrollerPart)hitPart { return _hitPart; } - (NSScrollerPart)hitPart { return _hitPart; }
- (float)floatValue { return _floatValue; } - (float)floatValue { return _floatValue; }
- (void)setAction:(SEL)action { _action = action; } - (void)setAction:(SEL)action { _action = action; }
- (SEL)action { return _action; } - (SEL)action { return _action; }
- (void)setTarget:(id)target { ASSIGN(_target, target); } - (void)setTarget:(id)target { ASSIGN(_target, target); }
- (id)target { return _target; } - (id)target { return _target; }
- initWithFrame:(NSRect)frameRect - initWithFrame:(NSRect)frameRect
{ {
@ -477,17 +478,22 @@ static NSButtonCell* knobCell = nil;
if (theCell) { if (theCell) {
[theCell highlight:YES withFrame:rect inView:self]; [theCell highlight:YES withFrame:rect inView:self];
[self setNeedsDisplayInRect:rect]; // not needed by XRAW // [self setNeedsDisplayInRect:rect]; // not needed by XRAW
[window flushWindow]; [window flushWindow];
NSDebugLog (@"tracking cell %x", theCell); NSLog (@"tracking cell %x", theCell);
// Track the mouse until mouse goes up // Track the mouse until mouse goes up
shouldReturn = [theCell trackMouse:theEvent shouldReturn = [theCell trackMouse:theEvent
inRect:rect inRect:rect
ofView:self ofView:self
untilMouseUp:YES]; untilMouseUp:YES];
if([_target isKindOf:[NSScrollView class]]) // a hack for XRAW
{ // FIX ME
if([[_target contentView] respondsTo:@selector(_freeMatrix)])
[[_target contentView] _freeMatrix];
}
[theCell highlight:NO withFrame:rect inView:self]; [theCell highlight:NO withFrame:rect inView:self];
[self setNeedsDisplayInRect:rect]; // not needed by XRAW // [self setNeedsDisplayInRect:rect]; // not needed by XRAW
[window flushWindow]; [window flushWindow];
} }
@ -503,19 +509,6 @@ static NSButtonCell* knobCell = nil;
NSDebugLog (@"return from trackScrollButtons"); NSDebugLog (@"return from trackScrollButtons");
} }
- (BOOL)sendAction:(SEL)theAction to:(id)theTarget
{
BOOL ret;
// send action to the target on behalf of cell
ret = [super sendAction:theAction to:theTarget];
[self drawKnobSlot]; // lockFocus set in mouseDown method is
[self drawKnob]; // active so we simply redraw the knob and
[window flushWindow]; // slot to reflect the hit scroll button
return ret;
}
- (void)encodeWithCoder:aCoder - (void)encodeWithCoder:aCoder
{ {
} }

View file

@ -35,11 +35,30 @@
- (NSSize)sizeWithAttributes:(NSDictionary *)attrs - (NSSize)sizeWithAttributes:(NSDictionary *)attrs
{ {
NSFont *font; NSFont *font;
const char *str = [self cString];
int i = 0, j = 4;
float tabSize;
while(*str++ != '\0') // count the tabs
{
if(*str == '\t')
{
i += j;
j = 4;
}
else
j = j == 0 ? 4 : j--;
};
// if font is not // if font is not
if(!(font = [attrs objectForKey:NSFontAttributeName])) // specified, use if(!(font = [attrs objectForKey:NSFontAttributeName])) // specified, use
font = [NSFont userFontOfSize:12]; // the default font = [NSFont userFontOfSize:12]; // the default
return NSMakeSize([font widthOfString:self], [font pointSize]); fprintf(stderr,"string %s width: %f\n", [self cString], [font widthOfString:self]);
// tabSize = 4 * i * [font widthOfString:@" "];
tabSize = (float)i * [font widthOfString:@" "];
return NSMakeSize(([font widthOfString:self] + tabSize), [font pointSize]);
} }
@end @end

File diff suppressed because it is too large Load diff

View file

@ -116,9 +116,13 @@ if(container) [self setTextContainer: container];
/************************* Key binding entry-point *************************/ /************************* Key binding entry-point *************************/
// This method is the funnel point for text insertion after keys pass through the key binder. // This method is the funnel point for text insertion after keys pass through the key binder.
#ifdef DEBUGG
-(void) insertText:(NSString*) insertString -(void) insertText:(NSString*) insertString
{ {
[super insertText: insertString];
} }
#endif /* DEBUGG */
/*************************** Sizing methods ***************************/ /*************************** Sizing methods ***************************/
@ -204,12 +208,14 @@ if(container) [self setTextContainer: container];
{ {
} }
#ifdef DEBUGG
-(BOOL)shouldDrawInsertionPoint -(BOOL)shouldDrawInsertionPoint
{ {
} }
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag -(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
{ {
} }
#endif /* DEBUGG */
/*************************** Especially for subclassers ***************************/ /*************************** Especially for subclassers ***************************/
@ -228,12 +234,15 @@ if(container) [self setTextContainer: container];
return ret; return ret;
} }
#ifdef DEBUGG
- (void)updateDragTypeRegistration - (void)updateDragTypeRegistration
{ {
} }
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity - (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity
{} {
}
#endif /* DEBUGG */
@end @end
@ -327,12 +336,14 @@ if(container) [self setTextContainer: container];
/*************************** NSResponder methods ***************************/ /*************************** NSResponder methods ***************************/
#ifdef DEBUGG
-(BOOL) resignFirstResponder -(BOOL) resignFirstResponder
{ return YES; { return YES;
} }
-(BOOL) becomeFirstResponder -(BOOL) becomeFirstResponder
{ return YES; { return YES;
} }
#endif /* DEBUGG */
/*************************** Smart copy/paste/delete support ***************************/ /*************************** Smart copy/paste/delete support ***************************/

View file

@ -549,7 +549,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
PSMatrix* matrix; PSMatrix* matrix;
if (!aView) if (!aView)
aView = [[self window] contentView]; aView = [window contentView];
if ([self isDescendantOf:aView]) { if ([self isDescendantOf:aView]) {
NSArray* path = [self _pathBetweenSubview:self toSuperview:aView]; NSArray* path = [self _pathBetweenSubview:self toSuperview:aView];
@ -578,7 +578,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
toView:(NSView *)aView toView:(NSView *)aView
{ {
if (!aView) if (!aView)
aView = [[self window] contentView]; aView = [window contentView];
return [aView convertPoint:aPoint fromView:self]; return [aView convertPoint:aPoint fromView:self];
} }
@ -731,10 +731,20 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
frame.size.height = [super_view frame].size.height; frame.size.height = [super_view frame].size.height;
} }
else // height is not resizable so check else // height is not resizable so check
{ // if right margin can be stretched { // if bottom margin can be stretchd
if(autoresizingMask & NSViewMinYMargin) if(autoresizingMask & NSViewMinYMargin)
frame.origin.y += [super_view frame].size.height - oldSize.height; frame.origin.y += [super_view frame].size.height - oldSize.height;
// if(autoresizingMask & NSViewMaxYMargin)
// frame.origin.y = [super_view frame].origin.y;
} }
fprintf (stderr, "NSView resizeWithOldSuperviewSize: \n");
fprintf (stderr,
"NSView: frame origin (%1.2f, %1.2f), size (%1.2f, %1.2f)\n",
frame.origin.x, frame.origin.y,
frame.size.width, frame.size.height);
fprintf (stderr, "NSView: old size (%1.2f, %1.2f)\n",
oldSize.width, oldSize.height);
} }
- (void)allocateGState - (void)allocateGState
@ -791,8 +801,11 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
- (void)display - (void)display
{ {
invalidatedRectangle = NSZeroRect; if(!window) // do nothing if not in
[self displayRect:bounds]; return; // a window
invalidatedRectangle = NSZeroRect; // Reset invalid rect
[self displayRect:[self visibleRect]]; // display visible rect
} }
- (void)displayIfNeeded - (void)displayIfNeeded
@ -828,7 +841,6 @@ int i, count;
[self lockFocus]; [self lockFocus];
[self drawRect:rect]; [self drawRect:rect];
[window _setNeedsFlush]; [window _setNeedsFlush];
// [window _view:self needsFlushInRect:rect];
[self unlockFocus]; [self unlockFocus];
// Tell subviews to display // Tell subviews to display
for (i = 0, count = [sub_views count]; i < count; ++i) for (i = 0, count = [sub_views count]; i < count; ++i)
@ -864,25 +876,28 @@ int i, count;
{} {}
- (NSRect)visibleRect - (NSRect)visibleRect
{ { // if no super view
if (!super_view) if (!super_view) // bounds is visible
return bounds; return bounds;
else { else // return intersection
NSRect superviewsVisibleRect { // between bounds and
= [self convertRect:[super_view visibleRect] fromView:super_view]; NSRect superviewsVisibleRect; // super view's visible
// rect
superviewsVisibleRect = [self convertRect:[super_view visibleRect]
fromView:super_view];
return NSIntersectionRect (superviewsVisibleRect, bounds); return NSIntersectionRect(superviewsVisibleRect, bounds);
} }
} }
- (void)_addSubviewForNeedingDisplay:(NSView*)view - (void)_addSubviewForNeedingDisplay:(NSView*)view
{ // Add view to the list of { // Add view to the list
NSView* currentView; // sibling subviews that NSView* currentView; // of sibling subviews
// need display. // that need display.
currentView = _subviewsThatNeedDisplay; currentView = _subviewsThatNeedDisplay;
while (currentView) // do nothing if the view while (currentView) // do nothing if the
{ // is already in self's { // view is already in
if (currentView == view) // list. if (currentView == view) // self's list.
return; return;
currentView = currentView->_nextSiblingSubviewThatNeedsDisplay; currentView = currentView->_nextSiblingSubviewThatNeedsDisplay;
} }