mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 00:00:43 +00:00
* 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:
parent
a5ddb67158
commit
388f29cf3c
14 changed files with 1042 additions and 535 deletions
16
ChangeLog
16
ChangeLog
|
@ -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>
|
||||
|
||||
* Source/NSClipView.m (MIN, MAX): Remove.
|
||||
|
|
|
@ -55,7 +55,7 @@ extern NSString *NSKernAttributeName; // NSNumber float, 0
|
|||
// defaultParagraphStyle
|
||||
//
|
||||
// NSKernAttributeName NSNumber float, offset from
|
||||
// baseline, amount tomodify default
|
||||
// baseline, amount to modify default
|
||||
// kerning, if 0 kerning is off
|
||||
|
||||
enum
|
||||
|
|
|
@ -107,21 +107,21 @@ typedef enum _NSSelectionAffinity
|
|||
|
||||
id lineLayoutInformation;
|
||||
NSMutableDictionary *typingAttributes;
|
||||
float currentCursorX;
|
||||
float currentCursorX; // column-stable cursor up/down
|
||||
BOOL displayDisabled;
|
||||
int spellCheckerDocumentTag;
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
+(NSData*) dataForAttributedString:(NSAttributedString*) aString;
|
||||
|
||||
+(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 withString:(NSString*) aString;
|
||||
|
@ -241,8 +241,8 @@ typedef enum _NSSelectionAffinity
|
|||
//
|
||||
// Managing the Delegate
|
||||
//
|
||||
- (id)delegate;
|
||||
- (void)setDelegate:(id)anObject;
|
||||
- delegate;
|
||||
-(void) setDelegate:anObject;
|
||||
|
||||
|
||||
//
|
||||
|
@ -262,13 +262,13 @@ typedef enum _NSSelectionAffinity
|
|||
- (void)ignoreSpelling:(id)sender;
|
||||
|
||||
//
|
||||
// these NSTextView methods are here only informally
|
||||
// these NSTextView methods are here only informally (GNU extensions)
|
||||
//
|
||||
-(int) spellCheckerDocumentTag;
|
||||
|
||||
-(void) insertText:(NSString *)insertString;
|
||||
-(void) insertText:insertString; // argument may be of class NSString or NSAttributedString (if isRichText)
|
||||
-(NSMutableDictionary*) typingAttributes;
|
||||
-(void) setTypingAttributes:(NSDictionary *)dict;
|
||||
-(void) setTypingAttributes:(NSDictionary *)attrs;
|
||||
|
||||
|
||||
-(BOOL) shouldDrawInsertionPoint;
|
||||
|
@ -277,26 +277,29 @@ typedef enum _NSSelectionAffinity
|
|||
-(NSArray*) acceptableDragTypes;
|
||||
-(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;
|
||||
-(NSRect) rectForCharacterIndex:(unsigned) index;
|
||||
-(NSRect) boundingRectForLineRange:(NSRange)lineRange;
|
||||
-(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) rebuildRichLineLayoutInformationStartingAtLine:(int) aLine;
|
||||
-(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex; // is identical to the real line number (not just counted return characters)
|
||||
-(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine; // returns count of lines actually updated (e.g. drawing optimization)
|
||||
-(int) rebuildPlainLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLine; // override for special layout of plain text
|
||||
-(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) drawRichLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:)
|
||||
-(void) drawPlainLinesInLineRange:(NSRange) aRange; // private (use redisplayForLineRange:)
|
||||
-(void) drawRichLinesInLineRange:(NSRange) aRange; // low level, override but never invoke (use redisplayForLineRange:)
|
||||
-(void) drawPlainLinesInLineRange:(NSRange) aRange; // low level, override but never invoke (use redisplayForLineRange:)
|
||||
|
||||
//
|
||||
// various GNU extensions
|
||||
|
@ -305,6 +308,14 @@ typedef enum _NSSelectionAffinity
|
|||
-(void) setSelectionWordGranularitySet:(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
|
||||
|
||||
/* Notifications */
|
||||
|
@ -321,16 +332,3 @@ extern NSString *NSTextDidChangeNotification;
|
|||
@end
|
||||
|
||||
#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
|
||||
|
|
|
@ -63,10 +63,9 @@ static BOOL gnustep_gui_app_is_in_dealloc;
|
|||
static NSEvent *gnustep_gui_null_event;
|
||||
static id NSApp;
|
||||
|
||||
#define ASSIGN(a, b) \
|
||||
[b retain]; \
|
||||
[a release]; \
|
||||
a = b;
|
||||
#define ASSIGN(a, b) [b retain]; \
|
||||
[a release]; \
|
||||
a = b;
|
||||
|
||||
@implementation NSApplication
|
||||
|
||||
|
@ -336,75 +335,98 @@ NSAutoreleasePool* pool;
|
|||
// Getting, removing, and posting events
|
||||
//
|
||||
- (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 (mask == NSAnyEventMask)
|
||||
return YES;
|
||||
if (!theEvent)
|
||||
return NO;
|
||||
|
||||
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
|
||||
if (theEvent == gnustep_gui_null_event) return NO;
|
||||
case NSLeftMouseUp:
|
||||
if (mask & NSLeftMouseUpMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
t = [theEvent type];
|
||||
case NSRightMouseDown:
|
||||
if (mask & NSRightMouseDownMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSLeftMouseDown) && (mask & NSLeftMouseDownMask))
|
||||
return YES;
|
||||
case NSRightMouseUp:
|
||||
if (mask & NSRightMouseUpMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSLeftMouseUp) && (mask & NSLeftMouseUpMask))
|
||||
return YES;
|
||||
case NSMouseMoved:
|
||||
if (mask & NSMouseMovedMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSRightMouseDown) && (mask & NSRightMouseDownMask))
|
||||
return YES;
|
||||
case NSMouseEntered:
|
||||
if (mask & NSMouseEnteredMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSRightMouseUp) && (mask & NSRightMouseUpMask))
|
||||
return YES;
|
||||
case NSMouseExited:
|
||||
if (mask & NSMouseExitedMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSMouseMoved) && (mask & NSMouseMovedMask))
|
||||
return YES;
|
||||
case NSLeftMouseDragged:
|
||||
if (mask & NSLeftMouseDraggedMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSMouseEntered) && (mask & NSMouseEnteredMask))
|
||||
return YES;
|
||||
case NSRightMouseDragged:
|
||||
if (mask & NSRightMouseDraggedMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSMouseExited) && (mask & NSMouseExitedMask))
|
||||
return YES;
|
||||
case NSKeyDown:
|
||||
if (mask & NSKeyDownMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSLeftMouseDragged) && (mask & NSLeftMouseDraggedMask))
|
||||
return YES;
|
||||
case NSKeyUp:
|
||||
if (mask & NSKeyUpMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSRightMouseDragged) && (mask & NSRightMouseDraggedMask))
|
||||
return YES;
|
||||
case NSFlagsChanged:
|
||||
if (mask & NSFlagsChangedMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSKeyDown) && (mask & NSKeyDownMask))
|
||||
return YES;
|
||||
case NSPeriodic:
|
||||
if (mask & NSPeriodicMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSKeyUp) && (mask & NSKeyUpMask))
|
||||
return YES;
|
||||
case NSCursorUpdate:
|
||||
if (mask & NSCursorUpdateMask)
|
||||
return YES;
|
||||
break;
|
||||
|
||||
if ((t == NSFlagsChanged) && (mask & NSFlagsChangedMask))
|
||||
return YES;
|
||||
|
||||
if ((t == NSPeriodic) && (mask & NSPeriodicMask))
|
||||
return YES;
|
||||
|
||||
if ((t == NSCursorUpdate) && (mask & NSCursorUpdateMask))
|
||||
return YES;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)setCurrentEvent:(NSEvent *)theEvent
|
||||
{
|
||||
[theEvent retain];
|
||||
[current_event release];
|
||||
current_event = theEvent;
|
||||
}
|
||||
|
||||
- (NSEvent *)currentEvent;
|
||||
{
|
||||
return current_event;
|
||||
return current_event;
|
||||
}
|
||||
|
||||
- (void)discardEventsMatchingMask:(unsigned int)mask
|
||||
|
@ -415,12 +437,13 @@ NSAutoreleasePool* pool;
|
|||
- (NSEvent*)_eventMatchingMask:(unsigned int)mask
|
||||
{
|
||||
NSEvent* event;
|
||||
int i, count = [event_queue count];
|
||||
int i, count;
|
||||
|
||||
[self getNextEvent];
|
||||
|
||||
if ((count = [event_queue count])) // Get an event from
|
||||
{ // the events queue
|
||||
//fprintf(stderr,"NSAppliation _eventMatchingMask: count %d\n", count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
event = [event_queue objectAtIndex:i];
|
||||
|
@ -428,7 +451,7 @@ int i, count = [event_queue count];
|
|||
{
|
||||
[event retain];
|
||||
[event_queue removeObjectAtIndex:i];
|
||||
[self setCurrentEvent:event];
|
||||
ASSIGN(current_event, event);
|
||||
|
||||
return [event autorelease];
|
||||
}
|
||||
|
@ -458,7 +481,7 @@ BOOL done = NO;
|
|||
{ // for next event
|
||||
NSDate *limitDate, *originalLimitDate;
|
||||
// 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
|
||||
// gets released.
|
||||
limitDate = [[currentLoop limitDateForMode:mode] retain];
|
||||
|
@ -483,13 +506,12 @@ BOOL done = NO;
|
|||
if (event)
|
||||
break;
|
||||
}
|
||||
|
||||
type = [event type];
|
||||
// Unhide the cursor if necessary
|
||||
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
|
||||
{ // and event is mouse event
|
||||
{
|
||||
if ([NSCursor isHiddenUntilMouseMoves]) // do so only if we should
|
||||
{ // unhide when mouse moves
|
||||
type = [event type]; // and event is mouse event
|
||||
if ((type == NSLeftMouseDown) || (type == NSLeftMouseUp)
|
||||
|| (type == NSRightMouseDown) || (type == NSRightMouseUp)
|
||||
|| (type == NSMouseMoved))
|
||||
|
|
|
@ -28,18 +28,44 @@
|
|||
|
||||
#include <AppKit/NSAttributedString.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)
|
||||
|
||||
- (NSSize)sizeWithAttributes:(NSDictionary *)attrs
|
||||
{
|
||||
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 = [attrs objectForKey:NSFontAttributeName])) // specified, use
|
||||
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
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
if (_documentView) {
|
||||
[self addSubview:_documentView];
|
||||
|
||||
/* Register to notifications sent by the document view */
|
||||
/* Register for notifications sent by the document view */
|
||||
[_documentView setPostsFrameChangedNotifications:YES];
|
||||
[_documentView setPostsBoundsChangedNotifications:YES];
|
||||
|
||||
|
@ -120,7 +120,7 @@
|
|||
- (NSRect)documentRect
|
||||
{
|
||||
NSRect documentFrame = [_documentView frame];
|
||||
NSRect clipViewBounds = [self bounds];
|
||||
NSRect clipViewBounds = bounds;
|
||||
NSRect rect;
|
||||
|
||||
rect.origin = documentFrame.origin;
|
||||
|
@ -133,7 +133,7 @@
|
|||
- (NSRect)documentVisibleRect
|
||||
{
|
||||
NSRect documentBounds = [_documentView bounds];
|
||||
NSRect clipViewBounds = [self bounds];
|
||||
NSRect clipViewBounds = bounds;
|
||||
NSRect rect;
|
||||
|
||||
rect.origin = clipViewBounds.origin;
|
||||
|
@ -202,14 +202,14 @@
|
|||
[super_view reflectScrolledClipView:self];
|
||||
}
|
||||
|
||||
- (id)documentView { return _documentView; }
|
||||
- (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; }
|
||||
- (BOOL)copiesOnScroll { return _copiesOnScroll; }
|
||||
- (id)documentView { return _documentView; }
|
||||
- (void)setCopiesOnScroll:(BOOL)flag { _copiesOnScroll = flag; }
|
||||
- (BOOL)copiesOnScroll { return _copiesOnScroll; }
|
||||
- (void)setDocumentCursor:(NSCursor*)aCursor { ASSIGN(_cursor, aCursor); }
|
||||
- (NSCursor*)documentCursor { return _cursor; }
|
||||
- (NSColor*)backgroundColor { return _backgroundColor; }
|
||||
- (BOOL)isFlipped { return [_documentView isFlipped]; }
|
||||
- (BOOL)acceptsFirstResponder { return _documentView != nil; }
|
||||
- (NSCursor*)documentCursor { return _cursor; }
|
||||
- (NSColor*)backgroundColor { return _backgroundColor; }
|
||||
- (BOOL)isFlipped { return [_documentView isFlipped]; }
|
||||
- (BOOL)acceptsFirstResponder { return _documentView != nil; }
|
||||
|
||||
- (void)setBackgroundColor:(NSColor*)aColor
|
||||
{
|
||||
|
|
|
@ -52,6 +52,26 @@
|
|||
[a release]; \
|
||||
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) \
|
||||
({typeof(x) _SIGN_x = (x); \
|
||||
_SIGN_x > 0 ? 1 : (_SIGN_x == 0 ? 0 : -1); })
|
||||
|
|
|
@ -81,7 +81,7 @@ static NSFont* menuFont = nil;
|
|||
if (!menuFont)
|
||||
menuFont = [[NSFont systemFontOfSize:0] retain];
|
||||
|
||||
cellSize = NSMakeSize (1, [menuFont pointSize] - [menuFont descender] + 4);
|
||||
cellSize = NSMakeSize (1, [menuFont pointSize] - [menuFont descender] + 6);
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
||||
Date: July 1997
|
||||
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
||||
Date: October 1998
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
|
@ -95,6 +97,7 @@ static Class rulerViewClass = nil;
|
|||
_pageScroll = 10;
|
||||
_borderType = NSBezelBorder;
|
||||
_scrollsDynamically = YES;
|
||||
autoresizingMask = NSViewMaxYMargin;
|
||||
[self tile];
|
||||
|
||||
return self;
|
||||
|
@ -193,119 +196,153 @@ static Class rulerViewClass = nil;
|
|||
|
||||
- (void)_doScroll:(NSScroller*)scroller
|
||||
{
|
||||
float floatValue = [scroller floatValue];
|
||||
NSRect clipViewBounds = [_contentView bounds];
|
||||
NSScrollerPart hitPart = [scroller hitPart];
|
||||
NSRect documentRect = [_contentView documentRect];
|
||||
float amount = 0;
|
||||
NSPoint point;
|
||||
float floatValue = [scroller floatValue];
|
||||
NSRect clipViewBounds = [_contentView bounds];
|
||||
NSScrollerPart hitPart = [scroller hitPart];
|
||||
NSRect documentRect = [_contentView documentRect];
|
||||
float amount = 0;
|
||||
NSPoint point;
|
||||
|
||||
NSDebugLog (@"_doScroll: float value = %f", floatValue);
|
||||
NSDebugLog (@"_doScroll: float value = %f", floatValue);
|
||||
|
||||
_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;
|
||||
_knobMoved = NO;
|
||||
|
||||
if (!_knobMoved) {
|
||||
if (scroller == _horizScroller) {
|
||||
point.x = clipViewBounds.origin.x + amount;
|
||||
point.y = clipViewBounds.origin.y;
|
||||
}
|
||||
else if (scroller == _vertScroller) {
|
||||
point.x = clipViewBounds.origin.x;
|
||||
/* For the vertical scroller the amount should actually be reversed */
|
||||
// amount = -amount;
|
||||
if(hitPart == NSScrollerKnob)
|
||||
_knobMoved = YES;
|
||||
else
|
||||
{
|
||||
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 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",
|
||||
amount, [_contentView isFlipped]);
|
||||
point.y = clipViewBounds.origin.y + amount;
|
||||
}
|
||||
else {
|
||||
/* do nothing */
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
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 {
|
||||
/* do nothing */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!_knobMoved) // button scrolling
|
||||
{
|
||||
if (scroller == _horizScroller)
|
||||
{
|
||||
point.x = clipViewBounds.origin.x + amount;
|
||||
point.y = clipViewBounds.origin.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scroller == _vertScroller) // For the vertical
|
||||
{ // scroller the amount
|
||||
point.x = clipViewBounds.origin.x; // should be reversed
|
||||
amount = -amount;
|
||||
|
||||
[_contentView scrollToPoint:point];
|
||||
_knobMoved = NO;
|
||||
// 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",
|
||||
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
|
||||
{
|
||||
NSRect documentFrame = NSZeroRect;
|
||||
NSRect clipViewBounds = NSZeroRect;
|
||||
float floatValue;
|
||||
float knobProportion;
|
||||
id documentView;
|
||||
NSRect documentFrame = NSZeroRect;
|
||||
NSRect clipViewBounds = NSZeroRect;
|
||||
float floatValue;
|
||||
float knobProportion;
|
||||
id documentView;
|
||||
// do nothing if
|
||||
if(aClipView != _contentView) // aClipView is not
|
||||
return; // our content view
|
||||
|
||||
if (_knobMoved)
|
||||
return;
|
||||
if (_knobMoved) // is this really needed?
|
||||
return; // FAR FIX ME ?
|
||||
|
||||
NSDebugLog (@"reflectScrolledClipView:");
|
||||
NSDebugLog (@"reflectScrolledClipView:");
|
||||
|
||||
if (_contentView) {
|
||||
clipViewBounds = [_contentView bounds];
|
||||
if ((documentView = [_contentView documentView]))
|
||||
documentFrame = [documentView frame];
|
||||
}
|
||||
clipViewBounds = [_contentView bounds];
|
||||
if ((documentView = [_contentView documentView]))
|
||||
documentFrame = [documentView frame];
|
||||
|
||||
if (_hasVertScroller) {
|
||||
if (documentFrame.size.height <= clipViewBounds.size.height)
|
||||
[_vertScroller setEnabled:NO];
|
||||
else {
|
||||
[_vertScroller setEnabled:YES];
|
||||
knobProportion = clipViewBounds.size.height / documentFrame.size.height;
|
||||
floatValue = clipViewBounds.origin.y
|
||||
/ (documentFrame.size.height - clipViewBounds.size.height);
|
||||
if (![_contentView isFlipped])
|
||||
floatValue = 1 - floatValue;
|
||||
[_vertScroller setFloatValue:floatValue knobProportion:knobProportion];
|
||||
}
|
||||
}
|
||||
if (_hasVertScroller)
|
||||
{
|
||||
if (documentFrame.size.height <= clipViewBounds.size.height)
|
||||
[_vertScroller setEnabled:NO];
|
||||
else
|
||||
{
|
||||
[_vertScroller setEnabled:YES];
|
||||
knobProportion = clipViewBounds.size.height /
|
||||
documentFrame.size.height;
|
||||
floatValue = clipViewBounds.origin.y / (documentFrame.size.height -
|
||||
clipViewBounds.size.height);
|
||||
if (![_contentView isFlipped])
|
||||
floatValue = 1 - floatValue;
|
||||
[_vertScroller setFloatValue:floatValue
|
||||
knobProportion:knobProportion];
|
||||
}
|
||||
}
|
||||
|
||||
if (_hasHorizScroller) {
|
||||
if (documentFrame.size.width <= clipViewBounds.size.width)
|
||||
[_horizScroller setEnabled:NO];
|
||||
else {
|
||||
[_horizScroller setEnabled:YES];
|
||||
knobProportion = clipViewBounds.size.width / documentFrame.size.width;
|
||||
floatValue = clipViewBounds.origin.x
|
||||
/ (documentFrame.size.width - clipViewBounds.size.width);
|
||||
[_horizScroller setFloatValue:floatValue knobProportion:knobProportion];
|
||||
}
|
||||
}
|
||||
[self setNeedsDisplay:YES];
|
||||
if (_hasHorizScroller)
|
||||
{
|
||||
if (documentFrame.size.width <= clipViewBounds.size.width)
|
||||
[_horizScroller setEnabled:NO];
|
||||
else
|
||||
{
|
||||
[_horizScroller setEnabled:YES];
|
||||
knobProportion = clipViewBounds.size.width /
|
||||
documentFrame.size.width;
|
||||
floatValue = clipViewBounds.origin.x / (documentFrame.size.width -
|
||||
clipViewBounds.size.width);
|
||||
[_horizScroller setFloatValue:floatValue
|
||||
knobProportion:knobProportion];
|
||||
}
|
||||
}
|
||||
|
||||
// [self setNeedsDisplay:YES]; // not needed by XRAW causes flicker
|
||||
}
|
||||
|
||||
- (void)setHorizontalRulerView:(NSRulerView*)aRulerView
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <Foundation/NSRunLoop.h>
|
||||
|
||||
#include <AppKit/NSScroller.h>
|
||||
#include <AppKit/NSScrollView.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSButtonCell.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; }
|
||||
- (NSUsableScrollerParts)usableParts { return _usableParts; }
|
||||
- (float)knobProportion { return _knobProportion; }
|
||||
- (NSScrollerPart)hitPart { return _hitPart; }
|
||||
- (float)floatValue { return _floatValue; }
|
||||
- (void)setAction:(SEL)action { _action = action; }
|
||||
- (SEL)action { return _action; }
|
||||
- (void)setTarget:(id)target { ASSIGN(_target, target); }
|
||||
- (id)target { return _target; }
|
||||
- (float)knobProportion { return _knobProportion; }
|
||||
- (NSScrollerPart)hitPart { return _hitPart; }
|
||||
- (float)floatValue { return _floatValue; }
|
||||
- (void)setAction:(SEL)action { _action = action; }
|
||||
- (SEL)action { return _action; }
|
||||
- (void)setTarget:(id)target { ASSIGN(_target, target); }
|
||||
- (id)target { return _target; }
|
||||
|
||||
- initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
|
@ -477,17 +478,22 @@ static NSButtonCell* knobCell = nil;
|
|||
|
||||
if (theCell) {
|
||||
[theCell highlight:YES withFrame:rect inView:self];
|
||||
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||
// [self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||
[window flushWindow];
|
||||
NSDebugLog (@"tracking cell %x", theCell);
|
||||
NSLog (@"tracking cell %x", theCell);
|
||||
// Track the mouse until mouse goes up
|
||||
shouldReturn = [theCell trackMouse:theEvent
|
||||
inRect:rect
|
||||
ofView:self
|
||||
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];
|
||||
[self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||
// [self setNeedsDisplayInRect:rect]; // not needed by XRAW
|
||||
[window flushWindow];
|
||||
}
|
||||
|
||||
|
@ -503,19 +509,6 @@ static NSButtonCell* knobCell = nil;
|
|||
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
|
||||
{
|
||||
}
|
||||
|
|
|
@ -35,11 +35,30 @@
|
|||
- (NSSize)sizeWithAttributes:(NSDictionary *)attrs
|
||||
{
|
||||
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 = [attrs objectForKey:NSFontAttributeName])) // specified, use
|
||||
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
|
||||
|
|
926
Source/NSText.m
926
Source/NSText.m
File diff suppressed because it is too large
Load diff
|
@ -116,9 +116,13 @@ if(container) [self setTextContainer: container];
|
|||
/************************* Key binding entry-point *************************/
|
||||
|
||||
// This method is the funnel point for text insertion after keys pass through the key binder.
|
||||
|
||||
#ifdef DEBUGG
|
||||
-(void) insertText:(NSString*) insertString
|
||||
{
|
||||
[super insertText: insertString];
|
||||
}
|
||||
#endif /* DEBUGG */
|
||||
|
||||
/*************************** Sizing methods ***************************/
|
||||
|
||||
|
@ -204,12 +208,14 @@ if(container) [self setTextContainer: container];
|
|||
{
|
||||
}
|
||||
|
||||
#ifdef DEBUGG
|
||||
-(BOOL)shouldDrawInsertionPoint
|
||||
{
|
||||
}
|
||||
-(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag
|
||||
{
|
||||
}
|
||||
#endif /* DEBUGG */
|
||||
|
||||
/*************************** Especially for subclassers ***************************/
|
||||
|
||||
|
@ -228,12 +234,15 @@ if(container) [self setTextContainer: container];
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef DEBUGG
|
||||
- (void)updateDragTypeRegistration
|
||||
{
|
||||
}
|
||||
|
||||
- (NSRange)selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity
|
||||
{}
|
||||
{
|
||||
}
|
||||
#endif /* DEBUGG */
|
||||
|
||||
@end
|
||||
|
||||
|
@ -327,12 +336,14 @@ if(container) [self setTextContainer: container];
|
|||
|
||||
/*************************** NSResponder methods ***************************/
|
||||
|
||||
#ifdef DEBUGG
|
||||
-(BOOL) resignFirstResponder
|
||||
{ return YES;
|
||||
}
|
||||
-(BOOL) becomeFirstResponder
|
||||
{ return YES;
|
||||
}
|
||||
#endif /* DEBUGG */
|
||||
|
||||
/*************************** Smart copy/paste/delete support ***************************/
|
||||
|
||||
|
|
|
@ -549,7 +549,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
|
|||
PSMatrix* matrix;
|
||||
|
||||
if (!aView)
|
||||
aView = [[self window] contentView];
|
||||
aView = [window contentView];
|
||||
|
||||
if ([self isDescendantOf:aView]) {
|
||||
NSArray* path = [self _pathBetweenSubview:self toSuperview:aView];
|
||||
|
@ -578,7 +578,7 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
|
|||
toView:(NSView *)aView
|
||||
{
|
||||
if (!aView)
|
||||
aView = [[self window] contentView];
|
||||
aView = [window contentView];
|
||||
|
||||
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;
|
||||
}
|
||||
else // height is not resizable so check
|
||||
{ // if right margin can be stretched
|
||||
{ // if bottom margin can be stretchd
|
||||
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
|
||||
|
@ -791,8 +801,11 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
|
|||
|
||||
- (void)display
|
||||
{
|
||||
invalidatedRectangle = NSZeroRect;
|
||||
[self displayRect:bounds];
|
||||
if(!window) // do nothing if not in
|
||||
return; // a window
|
||||
|
||||
invalidatedRectangle = NSZeroRect; // Reset invalid rect
|
||||
[self displayRect:[self visibleRect]]; // display visible rect
|
||||
}
|
||||
|
||||
- (void)displayIfNeeded
|
||||
|
@ -828,7 +841,6 @@ int i, count;
|
|||
[self lockFocus];
|
||||
[self drawRect:rect];
|
||||
[window _setNeedsFlush];
|
||||
// [window _view:self needsFlushInRect:rect];
|
||||
[self unlockFocus];
|
||||
// Tell subviews to display
|
||||
for (i = 0, count = [sub_views count]; i < count; ++i)
|
||||
|
@ -864,25 +876,28 @@ int i, count;
|
|||
{}
|
||||
|
||||
- (NSRect)visibleRect
|
||||
{
|
||||
if (!super_view)
|
||||
return bounds;
|
||||
else {
|
||||
NSRect superviewsVisibleRect
|
||||
= [self convertRect:[super_view visibleRect] fromView:super_view];
|
||||
{ // if no super view
|
||||
if (!super_view) // bounds is visible
|
||||
return bounds;
|
||||
else // return intersection
|
||||
{ // between bounds and
|
||||
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
|
||||
{ // Add view to the list of
|
||||
NSView* currentView; // sibling subviews that
|
||||
// need display.
|
||||
{ // Add view to the list
|
||||
NSView* currentView; // of sibling subviews
|
||||
// that need display.
|
||||
currentView = _subviewsThatNeedDisplay;
|
||||
while (currentView) // do nothing if the view
|
||||
{ // is already in self's
|
||||
if (currentView == view) // list.
|
||||
while (currentView) // do nothing if the
|
||||
{ // view is already in
|
||||
if (currentView == view) // self's list.
|
||||
return;
|
||||
currentView = currentView->_nextSiblingSubviewThatNeedsDisplay;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue