diff --git a/ChangeLog b/ChangeLog index 91fa2d7bd..6cf752872 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,32 @@ +Tue Aug 31 9:45:00 1999 Richard Frith-Macdonald + + Fixes to remove hard-coded colors from gui. I'm not sure this is + entirely correct - in places where we expect to display white text on + a dark-gray background, I've used windowFrameTextColor and + controlShadowColor, since the MacOS-X documentation doesn't seem to + specify anything exactly for this. + * NSBrowser.m: use windowFrameTextColor for title text and + controlShadowColor for background. + * NSClipView.m: (-init) use controlColor for default background. + * NSColorWell.m: (-drawRect:) use controlColor for background. + * NSFontPanel.m: use windowFrameTextColor for title text and + controlShadowColor for background. + * NSMatrix.m: Use controlBackgroundColor for backgrounds. + * NSMenu.m: ([NSMenuWindowTitleView drawRect:]) use windowFrameColor + and windowFrameTextColor. + * NSMenuItemCell.m: use selectedMenuItemColor or controlColor for + background, and use selectedMenuItemTextColor, controlTextColor, or + disabledControlTextColor for text. + * NSPopUpButtonCell.m: use selectedMenuItemColor or controlColor for + background, and use selectedMenuItemTextColor, controlTextColor for + text. + * NSSplitView.m: ([-initWithFrame:]) use controlShadowColor for the + divider, and controlBackgroundColor for background. + * NSTabViewItem.m: use controlBackgroundColor. + * NSTableHeaderCell.m: use controlShadowColor for header. + * NSTableView.m: use gridColor for the grid. + * NSText.m: Tidied most chunks of code using color. + Fri Aug 27 8:02:00 1999 Richard Frith-Macdonald Patch from Nicola Pero diff --git a/Source/NSBrowser.m b/Source/NSBrowser.m index 5c262db10..214f69b27 100644 --- a/Source/NSBrowser.m +++ b/Source/NSBrowser.m @@ -188,10 +188,10 @@ return [NSBrowserCell class]; } -// -// Instance methods -// -- initWithFrame: (NSRect)rect +/* + * Instance methods + */ +- (id) initWithFrame: (NSRect)rect { NSSize bs; NSRect scroller_rect; @@ -219,7 +219,7 @@ scroller_rect.size.height = [NSScroller scrollerWidth]; _horizontalScroller = [[NSScroller alloc] initWithFrame: scroller_rect]; [_horizontalScroller setTarget: self]; - [_horizontalScroller setAction: @selector(scrollViaScroller: )]; + [_horizontalScroller setAction: @selector(scrollViaScroller:)]; [self addSubview: _horizontalScroller]; _acceptsArrowKeys = YES; _sendsActionOnArrowKeys = YES; @@ -229,8 +229,8 @@ _browserColumns = [[NSMutableArray alloc] init]; _titleCell = [NSTextFieldCell new]; [_titleCell setEditable: NO]; - [_titleCell setTextColor: [NSColor whiteColor]]; - [_titleCell setBackgroundColor: [NSColor darkGrayColor]]; + [_titleCell setTextColor: [NSColor windowFrameTextColor]]; + [_titleCell setBackgroundColor: [NSColor controlShadowColor]]; //[_titleCell setBordered: YES]; //[_titleCell setBezeled: YES]; [_titleCell setAlignment: NSCenterTextAlignment]; @@ -295,20 +295,20 @@ BOOL both = NO; if (![anObject respondsToSelector: - @selector(browser: willDisplayCell: atRow: column: )]) + @selector(browser:willDisplayCell:atRow:column:)]) [NSException raise: NSBrowserIllegalDelegateException format: @"Delegate does not respond to %s\n", "browser: willDisplayCell: atRow: column: "]; if ([anObject respondsToSelector: - @selector(browser: numberOfRowsInColumn: )]) + @selector(browser:numberOfRowsInColumn:)]) { _passiveDelegate = YES; flag = YES; } if ([anObject respondsToSelector: - @selector(browser: createRowsForColumn: inMatrix: )]) + @selector(browser:createRowsForColumn:inMatrix:)]) { _passiveDelegate = NO; @@ -611,7 +611,7 @@ // Ask the delegate for the column title if ([_browserDelegate respondsToSelector: - @selector(browser: titleOfColumn: )]) + @selector(browser:titleOfColumn:)]) [self setTitle: [_browserDelegate browser: self titleOfColumn: column] ofColumn: column]; @@ -786,7 +786,7 @@ // xxx Should we trigger an exception? if (![_browserDelegate respondsToSelector: - @selector(browser: isColumnValid: )]) + @selector(browser:isColumnValid:)]) return; // Loop through the visible columns @@ -893,7 +893,7 @@ return; // Notify the delegate - if ([_browserDelegate respondsToSelector: @selector(browserWillScroll: )]) + if ([_browserDelegate respondsToSelector: @selector(browserWillScroll:)]) [_browserDelegate browserWillScroll: self]; // Shift @@ -907,7 +907,7 @@ [self updateScroller]; // Notify the delegate - if ([_browserDelegate respondsToSelector: @selector(browserDidScroll: )]) + if ([_browserDelegate respondsToSelector: @selector(browserDidScroll:)]) [_browserDelegate browserDidScroll: self]; } @@ -922,7 +922,7 @@ return; // Notify the delegate - if ([_browserDelegate respondsToSelector: @selector(browserWillScroll: )]) + if ([_browserDelegate respondsToSelector: @selector(browserWillScroll:)]) [_browserDelegate browserWillScroll: self]; // Shift @@ -936,7 +936,7 @@ [self updateScroller]; // Notify the delegate - if ([_browserDelegate respondsToSelector: @selector(browserDidScroll: )]) + if ([_browserDelegate respondsToSelector: @selector(browserDidScroll:)]) [_browserDelegate browserDidScroll: self]; } @@ -1039,7 +1039,7 @@ // Ask delegate if selection is ok if ([_browserDelegate respondsToSelector: - @selector(browser: selectRow: inColumn: )]) + @selector(browser:selectRow:inColumn:)]) { int row = [sender selectedRow]; shouldSelect = [_browserDelegate browser: self selectRow: row @@ -1049,7 +1049,7 @@ { // Try the other method if ([_browserDelegate respondsToSelector: - @selector(browser: selectCellWithString: inColumn: )]) + @selector(browser:selectCellWithString:inColumn:)]) { id c = [sender selectedCell]; shouldSelect = [_browserDelegate browser: self @@ -1595,8 +1595,8 @@ if (!_allowsMultipleSelection) [matrix setMode: NSRadioModeMatrix]; [matrix setTarget: self]; - [matrix setAction: @selector(doClick: )]; - [matrix setDoubleAction: @selector(doDoubleClick: )]; + [matrix setAction: @selector(doClick:)]; + [matrix setDoubleAction: @selector(doDoubleClick:)]; // set new col matrix and release old [bc setColumnMatrix: matrix]; @@ -1630,8 +1630,8 @@ if (!_allowsMultipleSelection) [matrix setMode: NSRadioModeMatrix]; [matrix setTarget: self]; - [matrix setAction: @selector(doClick: )]; - [matrix setDoubleAction: @selector(doDoubleClick: )]; + [matrix setAction: @selector(doClick:)]; + [matrix setDoubleAction: @selector(doDoubleClick:)]; // set new col matrix and release old [bc setColumnMatrix: matrix]; diff --git a/Source/NSClipView.m b/Source/NSClipView.m index 687b4a208..355ac1503 100644 --- a/Source/NSClipView.m +++ b/Source/NSClipView.m @@ -36,11 +36,11 @@ @implementation NSClipView -- init +- (id) init { [super init]; [self setAutoresizesSubviews: YES]; - [self setBackgroundColor: [NSColor lightGrayColor]]; + [self setBackgroundColor: [NSColor controlColor]]; _copiesOnScroll = YES; return self; } diff --git a/Source/NSColorWell.m b/Source/NSColorWell.m index 73bfc58b5..b537d0b3c 100644 --- a/Source/NSColorWell.m +++ b/Source/NSColorWell.m @@ -48,7 +48,7 @@ // // Instance methods // -- initWithFrame: (NSRect)frameRect +- (id) initWithFrame: (NSRect)frameRect { [super initWithFrame: frameRect]; @@ -65,9 +65,9 @@ [super dealloc]; } -// -// Drawing -// +/* + * Drawing + */ - (void) drawRect: (NSRect)rect { NSRect aRect = bounds; @@ -83,10 +83,10 @@ NSDrawButton(aRect, rect); /* - * Fill in grey. + * Fill in control color. */ aRect = NSInsetRect(aRect, 2.0, 2.0); - [[NSColor lightGrayColor] set]; + [[NSColor controlColor] set]; NSRectFill(NSIntersectionRect(aRect, rect)); /* diff --git a/Source/NSFontPanel.m b/Source/NSFontPanel.m index d48d81ad7..0e67f8423 100644 --- a/Source/NSFontPanel.m +++ b/Source/NSFontPanel.m @@ -51,7 +51,7 @@ NSDebugLog(@"Initialize NSFontPanel class\n"); // Initial version - [self setVersion:1]; + [self setVersion: 1]; } } @@ -62,7 +62,7 @@ { NSFontManager *fm = [NSFontManager sharedFontManager]; - return [fm fontPanel:YES]; + return [fm fontPanel: YES]; } // @@ -100,82 +100,82 @@ unsigned int style = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask; - self = [super initWithContentRect:pf - styleMask:style - backing:NSBackingStoreRetained - defer:NO - screen:nil]; - [self setTitle:@"Font Panel"]; + self = [super initWithContentRect: pf + styleMask: style + backing: NSBackingStoreRetained + defer: NO + screen: nil]; + [self setTitle: @"Font Panel"]; v = [self contentView]; - topArea = [[NSView alloc] initWithFrame:NSMakeRect(0,50,300,250)]; + topArea = [[NSView alloc] initWithFrame: NSMakeRect(0,50,300,250)]; - splitView = [[NSSplitView alloc] initWithFrame:NSMakeRect(0,0,300,240)]; - [splitView setVertical:NO]; - [topArea addSubview:splitView]; + splitView = [[NSSplitView alloc] initWithFrame: NSMakeRect(0,0,300,240)]; + [splitView setVertical: NO]; + [topArea addSubview: splitView]; - topSplit = [[NSView alloc] initWithFrame:ts]; + topSplit = [[NSView alloc] initWithFrame: ts]; - previewArea = [[NSTextField alloc] initWithFrame:pa]; - [previewArea setBackgroundColor:[NSColor whiteColor]]; - [previewArea setDrawsBackground:YES]; - [topSplit addSubview:previewArea]; + previewArea = [[NSTextField alloc] initWithFrame: pa]; + [previewArea setBackgroundColor: [NSColor textBackgroundColor]]; + [previewArea setDrawsBackground: YES]; + [topSplit addSubview: previewArea]; - bottomSplit = [[NSView alloc] initWithFrame:bs]; + bottomSplit = [[NSView alloc] initWithFrame: bs]; l.size.width = 110; - label = [[NSTextField alloc] initWithFrame:l]; + label = [[NSTextField alloc] initWithFrame: l]; [label setAlignment: NSCenterTextAlignment]; - [label setFont:[NSFont boldSystemFontOfSize:12]]; - [label setStringValue:@"Family"]; - [label setEditable:NO]; - [label setDrawsBackground:YES]; - [label setTextColor:[NSColor whiteColor]]; - [label setBackgroundColor:[NSColor colorWithCalibratedWhite:NSDarkGray alpha: 1.0]]; - [bottomSplit addSubview:label]; + [label setFont: [NSFont boldSystemFontOfSize: 12]]; + [label setStringValue: @"Family"]; + [label setEditable: NO]; + [label setDrawsBackground: YES]; + [label setTextColor: [NSColor windowFrameTextColor]]; + [label setBackgroundColor: [NSColor controlShadowColor]]; + [bottomSplit addSubview: label]; [label release]; ss.size.width = 110; - familyScroll = [[NSScrollView alloc] initWithFrame:ss]; - [familyScroll setHasVerticalScroller:YES]; - [bottomSplit addSubview:familyScroll]; + familyScroll = [[NSScrollView alloc] initWithFrame: ss]; + [familyScroll setHasVerticalScroller: YES]; + [bottomSplit addSubview: familyScroll]; l.size.width = 109; l.origin.x = 120; - label = [[NSTextField alloc] initWithFrame:l]; - [label setFont:[NSFont boldSystemFontOfSize:12]]; - [label setEditable:NO]; + label = [[NSTextField alloc] initWithFrame: l]; + [label setFont: [NSFont boldSystemFontOfSize: 12]]; + [label setEditable: NO]; [label setAlignment: NSCenterTextAlignment]; - [label setDrawsBackground:YES]; - [label setTextColor:[NSColor whiteColor]]; - [label setBackgroundColor:[NSColor darkGrayColor]]; - [label setStringValue:@"Typeface"]; - [bottomSplit addSubview:label]; + [label setDrawsBackground: YES]; + [label setTextColor: [NSColor windowFrameTextColor]]; + [label setBackgroundColor: [NSColor controlShadowColor]]; + [label setStringValue: @"Typeface"]; + [bottomSplit addSubview: label]; [label release]; ss.size.width = 109; ss.origin.x = 120; - typeScroll = [[NSScrollView alloc] initWithFrame:ss]; - [typeScroll setHasVerticalScroller:YES]; - [bottomSplit addSubview:typeScroll]; + typeScroll = [[NSScrollView alloc] initWithFrame: ss]; + [typeScroll setHasVerticalScroller: YES]; + [bottomSplit addSubview: typeScroll]; l.origin.x = 231; l.size.width = 58; - label = [[NSTextField alloc] initWithFrame:l]; - [label setFont:[NSFont boldSystemFontOfSize:12]]; + label = [[NSTextField alloc] initWithFrame: l]; + [label setFont: [NSFont boldSystemFontOfSize: 12]]; [label setAlignment: NSCenterTextAlignment]; - [label setDrawsBackground:YES]; - [label setEditable:NO]; - [label setTextColor:[NSColor whiteColor]]; - [label setBackgroundColor:[NSColor darkGrayColor]]; - [label setStringValue:@"Size"]; - [bottomSplit addSubview:label]; + [label setDrawsBackground: YES]; + [label setEditable: NO]; + [label setTextColor: [NSColor windowFrameTextColor]]; + [label setBackgroundColor: [NSColor controlShadowColor]]; + [label setStringValue: @"Size"]; + [bottomSplit addSubview: label]; [label release]; // last label, this is the size input. We don't release this one. @@ -183,54 +183,54 @@ l.origin.x = 231; l.origin.y = 140; - label = [[NSTextField alloc] initWithFrame:l]; - [label setDrawsBackground:YES]; - [label setBackgroundColor:[NSColor whiteColor]]; - [bottomSplit addSubview:label]; + label = [[NSTextField alloc] initWithFrame: l]; + [label setDrawsBackground: YES]; + [label setBackgroundColor: [NSColor windowFrameTextColor]]; + [bottomSplit addSubview: label]; ss.origin.x = 231; ss.size.height = 138; ss.size.width = 58; - sizeScroll = [[NSScrollView alloc] initWithFrame:ss]; - [sizeScroll setHasVerticalScroller:YES]; - [bottomSplit addSubview:sizeScroll]; + sizeScroll = [[NSScrollView alloc] initWithFrame: ss]; + [sizeScroll setHasVerticalScroller: YES]; + [bottomSplit addSubview: sizeScroll]; - bottomArea = [[NSView alloc] initWithFrame:NSMakeRect(0,0,300,50)]; + bottomArea = [[NSView alloc] initWithFrame: NSMakeRect(0,0,300,50)]; - slash = [[NSBox alloc] initWithFrame:NSMakeRect(0,40,300,2)]; - [slash setBorderType:NSGrooveBorder]; - [slash setTitlePosition:NSNoTitle]; - [bottomArea addSubview:slash]; + slash = [[NSBox alloc] initWithFrame: NSMakeRect(0,40,300,2)]; + [slash setBorderType: NSGrooveBorder]; + [slash setTitlePosition: NSNoTitle]; + [bottomArea addSubview: slash]; [slash release]; - revertButton = [[NSButton alloc] initWithFrame:b]; - [revertButton setStringValue:@"Revert"]; - [bottomArea addSubview:revertButton]; + revertButton = [[NSButton alloc] initWithFrame: b]; + [revertButton setStringValue: @"Revert"]; + [bottomArea addSubview: revertButton]; b.origin.x = 137; - previewButton = [[NSButton alloc] initWithFrame:b]; - [previewButton setStringValue:@"Preview"]; - [previewButton setButtonType:NSOnOffButton]; - [bottomArea addSubview:previewButton]; + previewButton = [[NSButton alloc] initWithFrame: b]; + [previewButton setStringValue: @"Preview"]; + [previewButton setButtonType: NSOnOffButton]; + [bottomArea addSubview: previewButton]; b.origin.x = 217; - setButton = [[NSButton alloc] initWithFrame:b]; - [setButton setStringValue:@"Set"]; - [bottomArea addSubview:setButton]; + setButton = [[NSButton alloc] initWithFrame: b]; + [setButton setStringValue: @"Set"]; + [bottomArea addSubview: setButton]; - [splitView addSubview:bottomSplit]; - [splitView addSubview:topSplit]; + [splitView addSubview: bottomSplit]; + [splitView addSubview: topSplit]; - [v addSubview:topArea]; - [v addSubview:bottomArea]; + [v addSubview: topArea]; + [v addSubview: bottomArea]; return self; } -- (NSFont *)panelConvertFont:(NSFont *)fontObject +- (NSFont *)panelConvertFont: (NSFont *)fontObject { return panel_font; } @@ -238,8 +238,8 @@ // // Setting the Font // -- (void)setPanelFont:(NSFont *)fontObject - isMultiple:(BOOL)flag +- (void)setPanelFont: (NSFont *)fontObject + isMultiple: (BOOL)flag { panel_font = fontObject; } @@ -257,10 +257,10 @@ return NO; } -- (void)setAccessoryView:(NSView *)aView +- (void)setAccessoryView: (NSView *)aView {} -- (void)setEnabled:(BOOL)flag +- (void)setEnabled: (BOOL)flag {} - (BOOL)worksWhenModal @@ -271,8 +271,8 @@ // // Displaying the NSFontPanel // -- (void)orderWindow:(NSWindowOrderingMode)place - relativeTo:(int)otherWindows +- (void)orderWindow: (NSWindowOrderingMode)place + relativeTo: (int)otherWindows {} - (void)display diff --git a/Source/NSMatrix.m b/Source/NSMatrix.m index 88f19d134..fa326b403 100644 --- a/Source/NSMatrix.m +++ b/Source/NSMatrix.m @@ -360,9 +360,9 @@ static int mouseDownFlags = 0; cellSize = NSMakeSize(DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT); intercell = NSMakeSize(1, 1); - [self setBackgroundColor: [NSColor lightGrayColor]]; + [self setBackgroundColor: [NSColor controlBackgroundColor]]; [self setDrawsBackground: YES]; - [self setCellBackgroundColor: [NSColor lightGrayColor]]; + [self setCellBackgroundColor: [NSColor controlBackgroundColor]]; [self setSelectionByRect: YES]; [self setAutosizesCells: YES]; if (mode == NSRadioModeMatrix && numRows && numCols) diff --git a/Source/NSMenu.m b/Source/NSMenu.m index 05ec4853e..8098334ac 100644 --- a/Source/NSMenu.m +++ b/Source/NSMenu.m @@ -961,7 +961,7 @@ NSArray* array; - (void)setMenu: (NSMenu*)aMenu { menu = aMenu; } - (NSMenu*)menu { return menu; } -- (void)drawRect: (NSRect)rect +- (void) drawRect: (NSRect)rect { NSRect floodRect = rect; @@ -971,10 +971,10 @@ NSArray* array; floodRect.origin.y += 2; floodRect.size.height -= 3; floodRect.size.width -= 3; - [[NSColor blackColor] set]; + [[NSColor windowFrameColor] set]; NSRectFill(floodRect); - [[NSColor whiteColor] set]; + [[NSColor windowFrameTextColor] set]; [[NSFont boldSystemFontOfSize:12] set]; PSmoveto(rect.origin.x + 5, rect.origin.y + 6); PSshow([[menu title] cString]); diff --git a/Source/NSMenuItemCell.m b/Source/NSMenuItemCell.m index 607094070..8bceea72a 100644 --- a/Source/NSMenuItemCell.m +++ b/Source/NSMenuItemCell.m @@ -249,12 +249,12 @@ static BOOL usesUserKeyEquivalents = YES; { } -- (void)drawWithFrame:(NSRect)cellFrame - inView:(NSView *)controlView +- (void) drawWithFrame: (NSRect)cellFrame + inView: (NSView *)controlView { - NSGraphicsContext *ctxt = GSCurrentContext(); - NSRect floodRect = cellFrame; - NSString *keyQ = nil; + NSGraphicsContext *ctxt = GSCurrentContext(); + NSRect floodRect = cellFrame; + NSString *keyQ = nil; NSDrawButton(cellFrame, cellFrame); @@ -263,18 +263,31 @@ static BOOL usesUserKeyEquivalents = YES; floodRect.size.height -= 3; floodRect.size.width -= 2; - if (cell_highlighted) { - [[NSColor whiteColor] set]; - NSRectFill(floodRect); - } else { - [[NSColor lightGrayColor] set]; - NSRectFill(floodRect); - } + if (cell_highlighted) + { + [[NSColor selectedMenuItemColor] set]; + } + else + { + [[NSColor controlColor] set]; + } + NSRectFill(floodRect); if ([self isEnabled]) - [[NSColor blackColor] set]; + { + if (cell_highlighted) + { + [[NSColor selectedMenuItemTextColor] set]; + } + else + { + [[NSColor controlTextColor] set]; + } + } else - [[NSColor grayColor] set]; + { + [[NSColor disabledControlTextColor] set]; + } [[NSFont systemFontOfSize:12] set]; DPSmoveto(ctxt, cellFrame.origin.x + 5, cellFrame.origin.y + 6); diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 5200d3cd2..c3fe4db03 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -56,8 +56,8 @@ return contents; } -- (void)drawWithFrame:(NSRect)cellFrame - inView:(NSView*)view +- (void) drawWithFrame: (NSRect)cellFrame + inView: (NSView*)view { NSGraphicsContext *ctxt = GSCurrentContext(); NSRect rect = cellFrame; @@ -71,13 +71,15 @@ arect.origin.x += 1; arect.origin.y += 2; - if (cell_highlighted) { - [[NSColor whiteColor] set]; - NSRectFill(arect); - } else { - [[NSColor lightGrayColor] set]; - NSRectFill(arect); - } + if (cell_highlighted) + { + [[NSColor selectedMenuItemColor] set]; + } + else + { + [[NSColor controlColor] set]; + } + NSRectFill(arect); if (cell_image) { @@ -96,7 +98,14 @@ point.x = rect.origin.x + xDist; rect.origin = point; - [[NSColor blackColor] set]; + if (cell_highlighted) + { + [[NSColor selectedMenuItemTextColor] set]; + } + else + { + [[NSColor controlTextColor] set]; + } // Draw the title. diff --git a/Source/NSSplitView.m b/Source/NSSplitView.m index a59cbbcc5..8080f8839 100644 --- a/Source/NSSplitView.m +++ b/Source/NSSplitView.m @@ -482,7 +482,7 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect) if ([self isOpaque]) { [[self backgroundColor] set]; - NSRectFill(r); + NSRectFill(r); } /* draw the dimples */ @@ -529,8 +529,8 @@ static inline NSPoint centerSizeInRect(NSSize innerSize, NSRect outerRect) dividerWidth = 8; draggedBarWidth = 8; isVertical = NO; - [self setDividerColor: [NSColor darkGrayColor]]; - [self setBackgroundColor: [NSColor lightGrayColor]]; + [self setDividerColor: [NSColor controlShadowColor]]; + [self setBackgroundColor: [NSColor controlBackgroundColor]]; [self setDimpleImage: [NSImage imageNamed: @"common_Dimple.tiff"] resetDividerThickness: YES]; } diff --git a/Source/NSTabViewItem.m b/Source/NSTabViewItem.m index 1061c695d..653024ef9 100644 --- a/Source/NSTabViewItem.m +++ b/Source/NSTabViewItem.m @@ -130,18 +130,22 @@ fRect = tabRect; - if (item_state == NSSelectedTab) { - fRect.origin.y -= 1; - fRect.size.height += 1; - [[NSColor lightGrayColor] set]; - NSRectFill(fRect); - } else if (item_state == NSBackgroundTab) { - [[NSColor lightGrayColor] set]; - NSRectFill(fRect); - } else { - [[NSColor lightGrayColor] set]; - NSRectFill(fRect); - } + if (item_state == NSSelectedTab) + { + fRect.origin.y -= 1; + fRect.size.height += 1; + [[NSColor controlBackgroundColor] set]; + NSRectFill(fRect); + } + else if (item_state == NSBackgroundTab) + { + [[NSColor controlBackgroundColor] set]; + NSRectFill(fRect); + } + else + { + [[NSColor controlBackgroundColor] set]; + } lRect = tabRect; lRect.origin.y += 3; diff --git a/Source/NSTableHeaderCell.m b/Source/NSTableHeaderCell.m index 99bc37cc4..946b0505a 100644 --- a/Source/NSTableHeaderCell.m +++ b/Source/NSTableHeaderCell.m @@ -2,11 +2,11 @@ #include @implementation NSTableHeaderCell -- (void)drawInteriorWithFrame:(NSRect)cellFrame - inView:(NSView *)controlView +- (void) drawInteriorWithFrame: (NSRect)cellFrame + inView: (NSView *)controlView { - [[NSColor darkGrayColor] set]; - NSRectFill(cellFrame); - [super drawInteriorWithFrame: cellFrame inView: controlView]; + [[NSColor controlShadowColor] set]; + NSRectFill(cellFrame); + [super drawInteriorWithFrame: cellFrame inView: controlView]; } @end diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 801c64721..a2aadcb3b 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -21,7 +21,7 @@ tbv_interCellSpacing = NSMakeSize (3,2); tbv_rowHeight = 16.0; tbv_columns = [NSMutableArray new]; - tbv_gridColor = [NSColor grayColor]; + tbv_gridColor = [NSColor gridColor]; tbv_headerView = nil; } diff --git a/Source/NSText.m b/Source/NSText.m index e801d3424..795486977 100644 --- a/Source/NSText.m +++ b/Source/NSText.m @@ -30,7 +30,7 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -// doDo: -caret blinking +// doDo: -caret blinking // -formatting routine: broader than 1.5x width cause display problems // -optimization: 1.deletion of single char in paragraph [opti hook 1] // -optimization: 2.newline in first line @@ -73,7 +73,7 @@ enum { NSBacktabKey = 25 }; -@interface _GNULineLayoutInfo:NSObject +@interface _GNULineLayoutInfo: NSObject { NSRange lineRange; NSRect lineRect; float drawingOffset; @@ -88,7 +88,7 @@ typedef enum LineLayoutInfoType_Paragraph=2 } _GNULineLayoutInfo_t; -+ lineLayoutWithRange:(NSRange) aRange rect:(NSRect) aRect drawingOffset:(float) anOffset type:(unsigned) aType; ++ lineLayoutWithRange: (NSRange) aRange rect: (NSRect) aRect drawingOffset: (float) anOffset type: (unsigned) aType; -(NSRange) lineRange; -(NSRect) lineRect; @@ -96,13 +96,13 @@ typedef enum -(BOOL) isDontDisplay; -(unsigned) type; --(void) setLineRange:(NSRange) aRange; --(void) setLineRect:(NSRect) aRect; --(void) setDrawingOffset:(float) anOffset; --(void) setDontDisplay:(BOOL) flag; --(void) setType:(unsigned) aType; +-(void) setLineRange: (NSRange) aRange; +-(void) setLineRect: (NSRect) aRect; +-(void) setDrawingOffset: (float) anOffset; +-(void) setDontDisplay: (BOOL) flag; +-(void) setType: (unsigned) aType; -(NSString*) fingerprintString; --(void) setFingerprintString:(NSString*) aString; +-(void) setFingerprintString: (NSString*) aString; -(BOOL) isLineTerminatingParagraph; -(NSString*) description; @@ -110,9 +110,9 @@ typedef enum @implementation _GNULineLayoutInfo -+ lineLayoutWithRange:(NSRange) aRange rect:(NSRect) aRect drawingOffset:(float) anOffset type:(unsigned) aType ++ lineLayoutWithRange: (NSRange) aRange rect: (NSRect) aRect drawingOffset: (float) anOffset type: (unsigned) aType { id ret=[[[_GNULineLayoutInfo alloc] init] autorelease]; - [ret setLineRange:aRange]; [ret setLineRect:aRect]; [ret setDrawingOffset:anOffset]; [ret setType:aType]; + [ret setLineRange: aRange]; [ret setLineRect: aRect]; [ret setDrawingOffset: anOffset]; [ret setType: aType]; return ret; } @@ -123,9 +123,9 @@ typedef enum -(float) drawingOffset {return drawingOffset;} -(NSString*) fingerprintString {return fingerprintString;} --(void) setLineRange:(NSRange) aRange {lineRange= aRange;} +-(void) setLineRange: (NSRange) aRange {lineRange= aRange;} --(void) setLineRect:(NSRect) aRect +-(void) setLineRect: (NSRect) aRect { //FIXME, line up textEditor with how text in text cell will be placed. // aRect.origin.y += 2; @@ -133,16 +133,16 @@ typedef enum lineRect= aRect; } --(void) setDrawingOffset:(float) anOffset {drawingOffset= anOffset;} --(void) setDontDisplay:(BOOL) flag {dontDisplay=flag;} --(void) setType:(unsigned) aType {type=aType;} +-(void) setDrawingOffset: (float) anOffset {drawingOffset= anOffset;} +-(void) setDontDisplay: (BOOL) flag {dontDisplay=flag;} +-(void) setType: (unsigned) aType {type=aType;} --(void) setFingerprintString:(NSString*) aString +-(void) setFingerprintString: (NSString*) aString { ASSIGN(fingerprintString,aString); } -(NSString*) description -{ return [[NSDictionary dictionaryWithObjectsAndKeys: NSStringFromRange(lineRange),@"LineRange", +{ return [[NSDictionary dictionaryWithObjectsAndKeys: NSStringFromRange(lineRange),@"LineRange", NSStringFromRect(lineRect),@"LineRect", fingerprintString,@"fingerprint", nil] description]; @@ -151,7 +151,7 @@ typedef enum -(BOOL) isLineTerminatingParagraph {return type == LineLayoutInfoType_Paragraph && lineRect.origin.x> 0;} // sort of hackish -(void) dealloc -{ if(fingerprintString) [fingerprintString release]; +{ if (fingerprintString) [fingerprintString release]; [super dealloc]; } @end @@ -170,59 +170,59 @@ static NSRange MakeRangeFromAbs(int a1,int a2) // not the same as NSMakeRange! /* static NSRange MakeRangeFromAbs(int a1,int a2) -{ if(a1< a2) return NSMakeRange(a1,a2-a1); +{ if (a1< a2) return NSMakeRange(a1,a2-a1); else return NSMakeRange(a2,a1-a2); } */ // end: _GNULineLayoutInfo ------------------------------------------------------------------------------------------ // NeXT's NSScanner's scanCharactersFromSet and friends seem to be a bit sluggish on whitespaces and newlines -//(have not tried GNUstep-base implementation though). so here is a more pedantic (and faster) implementation: +//(have not tried GNUstep-base implementation though). so here is a more pedantic (and faster) implementation: // this class should be considered private since it is not polished at all! -@interface _GNUTextScanner:NSObject +@interface _GNUTextScanner: NSObject { NSString *string; NSCharacterSet *set,*iSet; unsigned stringLength; NSRange activeRange; } -+(_GNUTextScanner*) scannerWithString:(NSString*) aStr set:(NSCharacterSet*) aSet invertedSet:(NSCharacterSet*) anInvSet; --(void) setString:(NSString*) aString set:(NSCharacterSet*) aSet invertedSet:(NSCharacterSet*) anInvSet; --(NSRange) _scanCharactersInverted:(BOOL) inverted; ++(_GNUTextScanner*) scannerWithString: (NSString*) aStr set: (NSCharacterSet*) aSet invertedSet: (NSCharacterSet*) anInvSet; +-(void) setString: (NSString*) aString set: (NSCharacterSet*) aSet invertedSet: (NSCharacterSet*) anInvSet; +-(NSRange) _scanCharactersInverted: (BOOL) inverted; -(NSRange) scanSetCharacters; -(NSRange) scanNonSetCharacters; -(BOOL) isAtEnd; -(unsigned) scanLocation; --(void) setScanLocation:(unsigned) aLoc; +-(void) setScanLocation: (unsigned) aLoc; @end @implementation _GNUTextScanner -+(_GNUTextScanner*) scannerWithString:(NSString*) aStr set:(NSCharacterSet*) aSet invertedSet:(NSCharacterSet*) anInvSet ++(_GNUTextScanner*) scannerWithString: (NSString*) aStr set: (NSCharacterSet*) aSet invertedSet: (NSCharacterSet*) anInvSet { _GNUTextScanner *ret=[[self alloc] init]; - [ret setString:aStr set:aSet invertedSet:anInvSet]; + [ret setString: aStr set: aSet invertedSet: anInvSet]; return [ret autorelease]; } --(void) setString:(NSString*) aString set:(NSCharacterSet*) aSet invertedSet:(NSCharacterSet*) anInvSet +-(void) setString: (NSString*) aString set: (NSCharacterSet*) aSet invertedSet: (NSCharacterSet*) anInvSet { ASSIGN(string,aString); stringLength=[string length]; activeRange=NSMakeRange(0,stringLength); ASSIGN(set,aSet); ASSIGN(iSet,anInvSet); } --(NSRange) _scanCharactersInverted:(BOOL) inverted +-(NSRange) _scanCharactersInverted: (BOOL) inverted { NSRange range=NSMakeRange(activeRange.location,0); - NSCharacterSet *currentSet= inverted? iSet:set; - NSCharacterSet *currentISet= inverted? set:iSet; + NSCharacterSet *currentSet= inverted? iSet: set; + NSCharacterSet *currentISet= inverted? set: iSet; - if(activeRange.location>= stringLength) return range; - if([currentSet characterIsMember:[string characterAtIndex:activeRange.location]]) - { range=[string rangeOfCharacterFromSet:currentSet options:0 range:activeRange]; + if (activeRange.location>= stringLength) return range; + if ([currentSet characterIsMember: [string characterAtIndex: activeRange.location]]) + { range=[string rangeOfCharacterFromSet: currentSet options: 0 range: activeRange]; } if (range.length) { NSRange iRange=range; - iRange=[string rangeOfCharacterFromSet:currentISet options:0 range:MakeRangeFromAbs(NSMaxRange(range),stringLength)]; - if(iRange.length) range=MakeRangeFromAbs(range.location,iRange.location); + iRange=[string rangeOfCharacterFromSet: currentISet options: 0 range: MakeRangeFromAbs(NSMaxRange(range),stringLength)]; + if (iRange.length) range=MakeRangeFromAbs(range.location,iRange.location); else range=MakeRangeFromAbs(range.location,stringLength); activeRange=MakeRangeFromAbs(NSMaxRange(range),stringLength); } @@ -230,17 +230,17 @@ static NSRange MakeRangeFromAbs(int a1,int a2) } -(NSRange) scanSetCharacters -{ return [self _scanCharactersInverted:NO]; +{ return [self _scanCharactersInverted: NO]; } -(NSRange) scanNonSetCharacters -{ return [self _scanCharactersInverted:YES]; +{ return [self _scanCharactersInverted: YES]; } -(BOOL) isAtEnd { return activeRange.location>= stringLength; } -(unsigned) scanLocation {return activeRange.location;} --(void) setScanLocation:(unsigned) aLoc { activeRange=MakeRangeFromAbs(aLoc,stringLength);} +-(void) setScanLocation: (unsigned) aLoc { activeRange=MakeRangeFromAbs(aLoc,stringLength);} -(void) dealloc { [string release]; @@ -254,69 +254,70 @@ static NSRange MakeRangeFromAbs(int a1,int a2) /* @interface NSAttributedString(DrawingAddition) --(NSSize) sizeRange:(NSRange) aRange; --(void) drawRange:(NSRange) aRange atPoint:(NSPoint) aPoint; --(void) drawRange:(NSRange) aRange inRect:(NSRect) aRect; --(BOOL) areMultipleFontsInRange:(NSRange) aRange; +-(NSSize) sizeRange: (NSRange) aRange; +-(void) drawRange: (NSRange) aRange atPoint: (NSPoint) aPoint; +-(void) drawRange: (NSRange) aRange inRect: (NSRect) aRect; +-(BOOL) areMultipleFontsInRange: (NSRange) aRange; @end */ @implementation NSAttributedString(DrawingAddition) --(NSSize) sizeRange:(NSRange) lineRange +-(NSSize) sizeRange: (NSRange) lineRange { NSRect retRect=NSZeroRect; NSRange currRange=NSMakeRange(lineRange.location,0); NSPoint currPoint=NSMakePoint(0,0); NSString *string=[self string]; for(; NSMaxRange(currRange)< NSMaxRange(lineRange);) // draw all "runs" - { NSDictionary *attributes=[self attributesAtIndex:NSMaxRange(currRange) longestEffectiveRange:&currRange inRange:lineRange]; - NSString *substring=[string substringWithRange:currRange]; + { NSDictionary *attributes=[self attributesAtIndex: NSMaxRange(currRange) longestEffectiveRange: &currRange inRange: lineRange]; + NSString *substring=[string substringWithRange: currRange]; NSRect sizeRect=NSMakeRect(currPoint.x,0,0,0); - sizeRect.size=[substring sizeWithAttributes:attributes]; + sizeRect.size=[substring sizeWithAttributes: attributes]; retRect=NSUnionRect(retRect,sizeRect); currPoint.x+=sizeRect.size.width; // size attachments } return retRect.size; } --(void) drawRange:(NSRange) lineRange atPoint:(NSPoint) aPoint +-(void) drawRange: (NSRange) lineRange atPoint: (NSPoint) aPoint { NSRange currRange=NSMakeRange(lineRange.location,0); NSPoint currPoint; NSString *string=[self string]; for(currPoint=aPoint; NSMaxRange(currRange)< NSMaxRange(lineRange);) // draw all "runs" - { NSDictionary *attributes=[self attributesAtIndex:NSMaxRange(currRange) longestEffectiveRange:&currRange inRange:lineRange]; - NSString *substring=[string substringWithRange:currRange]; - [substring drawAtPoint:currPoint withAttributes:attributes]; - currPoint.x+=[substring sizeWithAttributes:attributes].width; + { NSDictionary *attributes=[self attributesAtIndex: NSMaxRange(currRange) longestEffectiveRange: &currRange inRange: lineRange]; + NSString *substring=[string substringWithRange: currRange]; + [substring drawAtPoint: currPoint withAttributes: attributes]; + currPoint.x+=[substring sizeWithAttributes: attributes].width; // draw attachments } } --(void) drawRange:(NSRange) aRange inRect:(NSRect) aRect; +- (void) drawRange: (NSRange)aRange inRect: (NSRect)aRect { - NSString *substring=[[self string] substringWithRange:aRange]; + NSString *substring = [[self string] substringWithRange: aRange]; - [substring drawInRect:aRect withAttributes:[NSDictionary dictionaryWithObjectsAndKeys: -[NSFont systemFontOfSize:12.0],NSFontAttributeName, -[NSColor blueColor],NSForegroundColorAttributeName, -nil]]; + [substring drawInRect: aRect + withAttributes: [NSDictionary dictionaryWithObjectsAndKeys: + [NSFont systemFontOfSize: 12.0], NSFontAttributeName, + [NSColor blueColor], NSForegroundColorAttributeName, + nil]]; } --(BOOL) areMultipleFontsInRange:(NSRange) aRange +-(BOOL) areMultipleFontsInRange: (NSRange) aRange { NSRange longestRange; - [self attribute:NSFontAttributeName atIndex:aRange.location longestEffectiveRange:&longestRange inRange:aRange]; - if(NSEqualRanges(NSIntersectionRange(longestRange,aRange),aRange)) return NO; + [self attribute: NSFontAttributeName atIndex: aRange.location longestEffectiveRange: &longestRange inRange: aRange]; + if (NSEqualRanges(NSIntersectionRange(longestRange,aRange),aRange)) return NO; else return YES; } @end -@interface _GNUSeekableArrayEnumerator:NSObject +@interface _GNUSeekableArrayEnumerator: NSObject { unsigned currentIndex; NSArray *array; } -- initWithArray:(NSArray*) anArray; +- initWithArray: (NSArray*) anArray; - nextObject; - previousObject; - currentObject; @@ -324,21 +325,21 @@ nil]]; @implementation _GNUSeekableArrayEnumerator -- initWithArray:(NSArray*) anArray +- initWithArray: (NSArray*) anArray { [super init]; array=[anArray retain]; return self; } - nextObject -{ if(currentIndex >= [array count]) return nil; - return [array objectAtIndex:currentIndex++]; +{ if (currentIndex >= [array count]) return nil; + return [array objectAtIndex: currentIndex++]; } - previousObject -{ if(!currentIndex) return nil; - return [array objectAtIndex:--currentIndex]; +{ if (!currentIndex) return nil; + return [array objectAtIndex: --currentIndex]; } - currentObject -{ return [array objectAtIndex:currentIndex]; +{ return [array objectAtIndex: currentIndex]; } -(void) dealloc @@ -351,7 +352,7 @@ nil]]; @end @implementation NSArray(SeekableEnumerator) -(_GNUSeekableArrayEnumerator*) seekableEnumerator -{ return [[[_GNUSeekableArrayEnumerator alloc] initWithArray:self] autorelease]; +{ return [[[_GNUSeekableArrayEnumerator alloc] initWithArray: self] autorelease]; } @end @@ -371,7 +372,7 @@ nil]]; NSArray *r; NSArray *s; - [self setVersion:1]; // Initial version + [self setVersion: 1]; // Initial version r = [NSArray arrayWithObjects: NSStringPboardType, nil]; s = [NSArray arrayWithObjects: NSStringPboardType, nil]; @@ -383,21 +384,21 @@ nil]]; // //this is sort of a botch up: rtf should be spilled out here in order to be OPENSTEP-compatible -// the way to go is surely implementing -(NSData *)RTFDFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict; and friends. +// the way to go is surely implementing -(NSData *)RTFDFromRange: (NSRange)range documentAttributes: (NSDictionary *)dict; and friends. // (NeXT OPENSTEP additions to NSAttributedString) // // but on the other hand: since rtf is MS-technology, simply let us declare the NSArchiver generated data stream output being the GNU rich text format ;-) -+(NSData*) dataForAttributedString:(NSAttributedString*) aString -{ return [NSArchiver archivedDataWithRootObject:aString]; ++(NSData*) dataForAttributedString: (NSAttributedString*) aString +{ return [NSArchiver archivedDataWithRootObject: aString]; } //this is sort of a botch up: a rtf parser should come in here in order to be OPENSTEP-compatible // but on the other hand: since rtf is MS-technology, simply let us declare the NSArchiver generated data stream output being the GNU rich text format ;-) // return value is guaranteed to be a NSAttributedString even if data is only NSString -+(NSAttributedString*) attributedStringForData:(NSData*) aData -{ id erg=[NSUnarchiver unarchiveObjectWithData:aData]; - if(![erg isKindOfClass:[NSAttributedString class]]) - return [[[NSAttributedString alloc] initWithString:erg] autorelease]; ++(NSAttributedString*) attributedStringForData: (NSData*) aData +{ id erg=[NSUnarchiver unarchiveObjectWithData: aData]; + if (![erg isKindOfClass: [NSAttributedString class]]) + return [[[NSAttributedString alloc] initWithString: erg] autorelease]; else return erg; } @@ -410,48 +411,49 @@ nil]]; // Initialization // -- init +- (id) init { - return [self initWithFrame:NSMakeRect(0,0,100,100)]; + return [self initWithFrame: NSMakeRect(0,0,100,100)]; } -- initWithFrame:(NSRect)frameRect -{ [super initWithFrame:frameRect]; - - alignment = NSLeftTextAlignment; - is_editable = YES; - [self setRichText:NO]; // sets up the contents object - is_selectable = YES; - imports_graphics = NO; - uses_font_panel = NO; - is_horizontally_resizable =NO; - is_vertically_resizable = YES; - is_ruler_visible = NO; - is_field_editor = NO; - draws_background = YES; - [self setBackgroundColor:[NSColor whiteColor]]; - [self setTextColor:[NSColor blackColor]]; - default_font = [NSFont userFontOfSize:12]; +- (id) initWithFrame: (NSRect)frameRect +{ + [super initWithFrame: frameRect]; + + alignment = NSLeftTextAlignment; + is_editable = YES; + [self setRichText: NO]; // sets up the contents object + is_selectable = YES; + imports_graphics = NO; + uses_font_panel = NO; + is_horizontally_resizable =NO; + is_vertically_resizable = YES; + is_ruler_visible = NO; + is_field_editor = NO; + draws_background = YES; + [self setBackgroundColor: [NSColor textBackgroundColor]]; + [self setTextColor: [NSColor textColor]]; + default_font = [NSFont userFontOfSize: 12]; - [self setSelectionWordGranularitySet:[NSCharacterSet characterSetWithCharactersInString:@" "]]; //[NSCharacterSet whitespaceCharacterSet] - [self setSelectionParagraphGranularitySet:[NSCharacterSet characterSetWithCharactersInString:[[self class] newlineString]]]; + [self setSelectionWordGranularitySet: + [NSCharacterSet characterSetWithCharactersInString: @" "]]; //[NSCharacterSet whitespaceCharacterSet] + [self setSelectionParagraphGranularitySet: + [NSCharacterSet characterSetWithCharactersInString: [[self class] newlineString]]]; - [self setMinSize:frameRect.size]; - [self setMaxSize:NSMakeSize(HUGE,HUGE)]; + [self setMinSize: frameRect.size]; + [self setMaxSize: NSMakeSize(HUGE,HUGE)]; - [self setString:@"Text"]; - [self setSelectedRange:NSMakeRange(0,0)]; - return self; + [self setString: @"Text"]; + [self setSelectedRange: NSMakeRange(0,0)]; + return self; } --(NSDictionary*) defaultTypingAttributes +- (NSDictionary*) defaultTypingAttributes { - -return [NSDictionary dictionaryWithObjectsAndKeys: -default_font,NSFontAttributeName, -text_color,NSForegroundColorAttributeName, -nil]; - + return [NSDictionary dictionaryWithObjectsAndKeys: + default_font, NSFontAttributeName, + text_color, NSForegroundColorAttributeName, + nil]; } /* @@ -496,66 +498,75 @@ nil]; // // handle font pasteboard as well! // handle ruler pasteboard as well! --(BOOL) performPasteOperation:(NSPasteboard *)pboard +- (BOOL) performPasteOperation: (NSPasteboard*)pboard { // color accepting - if([pboard availableTypeFromArray:[NSArray arrayWithObject:NSColorPboardType]]) - { NSColor *color=[NSColor colorFromPasteboard:pboard]; - if([self isRichText]) - { [self setTextColor:color range:[self selectedRange]]; - } else [self setTextColor:color]; - return YES; - } + if ([pboard availableTypeFromArray: + [NSArray arrayWithObject: NSColorPboardType]]) + { + NSColor *color = [NSColor colorFromPasteboard: pboard]; - if([self importsGraphics]) - { NSArray *types=[NSArray arrayWithObjects:NSFileContentsPboardType, NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, NSTIFFPboardType, nil]; - if([[pboard availableTypeFromArray:types] isEqualToString:NSRTFDPboardType]) - { [self insertText:[[self class] attributedStringForData:[pboard dataForType:NSRTFDPboardType]]]; - } else if([[pboard availableTypeFromArray:types] isEqualToString:NSRTFPboardType]) - { [self insertText:[[self class] attributedStringForData:[pboard dataForType:NSRTFPboardType]]]; - } else if([[pboard availableTypeFromArray:types] isEqualToString:NSStringPboardType]) - { [self insertText:[pboard stringForType:NSStringPboardType]]; - return YES; - } - } else if([self isRichText]) - { NSArray *types=[NSArray arrayWithObjects:NSRTFPboardType, NSStringPboardType,nil]; - if([[pboard availableTypeFromArray:types] isEqualToString:NSRTFPboardType]) - { [self insertText:[[self class] attributedStringForData:[pboard dataForType:NSRTFPboardType]]]; - } else if([[pboard availableTypeFromArray:types] isEqualToString:NSStringPboardType]) - { [self insertText:[pboard stringForType:NSStringPboardType]]; - return YES; - } - } else // plain text - { NSArray *types=[NSArray arrayWithObjects:NSStringPboardType, nil]; - if([[pboard availableTypeFromArray:types] isEqualToString:NSStringPboardType]) - { [self insertText:[pboard stringForType:NSStringPboardType]]; - return YES; - } - } return NO; + if ([self isRichText]) + { + [self setTextColor: color range: [self selectedRange]]; + } + else + [self setTextColor: color]; + return YES; + } + + if ([self importsGraphics]) + { + NSArray *types=[NSArray arrayWithObjects: NSFileContentsPboardType, NSRTFDPboardType, NSRTFPboardType, NSStringPboardType, NSTIFFPboardType, nil]; + if ([[pboard availableTypeFromArray: types] isEqualToString: NSRTFDPboardType]) + { [self insertText: [[self class] attributedStringForData: [pboard dataForType: NSRTFDPboardType]]]; + } else if ([[pboard availableTypeFromArray: types] isEqualToString: NSRTFPboardType]) + { [self insertText: [[self class] attributedStringForData: [pboard dataForType: NSRTFPboardType]]]; + } else if ([[pboard availableTypeFromArray: types] isEqualToString: NSStringPboardType]) + { [self insertText: [pboard stringForType: NSStringPboardType]]; + return YES; + } + } else if ([self isRichText]) + { NSArray *types=[NSArray arrayWithObjects: NSRTFPboardType, NSStringPboardType,nil]; + if ([[pboard availableTypeFromArray: types] isEqualToString: NSRTFPboardType]) + { [self insertText: [[self class] attributedStringForData: [pboard dataForType: NSRTFPboardType]]]; + } else if ([[pboard availableTypeFromArray: types] isEqualToString: NSStringPboardType]) + { [self insertText: [pboard stringForType: NSStringPboardType]]; + return YES; + } + } else // plain text + { NSArray *types=[NSArray arrayWithObjects: NSStringPboardType, nil]; + if ([[pboard availableTypeFromArray: types] isEqualToString: NSStringPboardType]) + { [self insertText: [pboard stringForType: NSStringPboardType]]; + return YES; + } + } return NO; } - (BOOL) readSelectionFromPasteboard: (NSPasteboard*)pb -{ return [self performPasteOperation:pb]; +{ return [self performPasteOperation: pb]; } // begin: dragging of colors and files --------------- --(unsigned int) draggingEntered:(id )sender +-(unsigned int) draggingEntered: (id )sender { return NSDragOperationGeneric; } --(unsigned int) draggingUpdated:(id )sender +-(unsigned int) draggingUpdated: (id )sender { return NSDragOperationGeneric; } --(void) draggingExited:(id )sender +-(void) draggingExited: (id )sender { } --(BOOL) prepareForDragOperation:(id )sender +-(BOOL) prepareForDragOperation: (id )sender { return YES; } --(BOOL) performDragOperation:(id )sender -{ return [self performPasteOperation:[sender draggingPasteboard]]; +- (BOOL) performDragOperation: (id )sender +{ + return [self performPasteOperation: [sender draggingPasteboard]]; } --(void) concludeDragOperation:(id )sender + +-(void) concludeDragOperation: (id )sender { } // end: drag accepting --------------------------------- @@ -573,45 +584,48 @@ nil]; } -(NSArray*) acceptableDragTypes -{ NSMutableArray *ret=[NSMutableArray arrayWithObjects:NSStringPboardType, NSColorPboardType, nil]; +{ + NSMutableArray *ret=[NSMutableArray arrayWithObjects: NSStringPboardType, NSColorPboardType, nil]; - if([self isRichText]) [ret addObject:NSRTFPboardType]; - if([self importsGraphics]) [ret addObject:NSRTFDPboardType]; - return ret; + if ([self isRichText]) + [ret addObject: NSRTFPboardType]; + if ([self importsGraphics]) + [ret addObject: NSRTFDPboardType]; + return ret; } -(void) updateDragTypeRegistration -{ [self registerForDraggedTypes:[self acceptableDragTypes]]; +{ [self registerForDraggedTypes: [self acceptableDragTypes]]; } --(NSRange) selectionRangeForProposedRange:(NSRange)proposedCharRange granularity:(NSSelectionGranularity)granularity +-(NSRange) selectionRangeForProposedRange: (NSRange)proposedCharRange granularity: (NSSelectionGranularity)granularity { NSCharacterSet *set=nil; unsigned lastIndex=[self textLength]-1,lpos=MIN(lastIndex,proposedCharRange.location), rpos=NSMaxRange(proposedCharRange); // better: rpos=MAX(0,(int)NSMaxRange(proposedCharRange)-1); NSString *string=[self string]; BOOL rmemberstate,lmemberstate; - if(![string length]) { + if (![string length]) { NSLog(@"We have no length, our range is 0,0\n"); return NSMakeRange(0,0); } switch(granularity) { case NSSelectByCharacter: return NSIntersectionRange(proposedCharRange,NSMakeRange(0,[self textLength]+1)); - case NSSelectByWord: + case NSSelectByWord: set=selectionWordGranularitySet; break; - case NSSelectByParagraph: + case NSSelectByParagraph: set=selectionParagraphGranularitySet; break; } // now work on set... - lmemberstate=[set characterIsMember:[string characterAtIndex:lpos]]; - rmemberstate=[set characterIsMember:[string characterAtIndex:MIN(rpos,lastIndex)]]; - while (rpos<= lastIndex && [set characterIsMember:[string characterAtIndex:rpos]]== rmemberstate) rpos++; + lmemberstate=[set characterIsMember: [string characterAtIndex: lpos]]; + rmemberstate=[set characterIsMember: [string characterAtIndex: MIN(rpos,lastIndex)]]; + while (rpos<= lastIndex && [set characterIsMember: [string characterAtIndex: rpos]]== rmemberstate) rpos++; - while(lpos && [set characterIsMember:[string characterAtIndex:lpos]]== lmemberstate) lpos--; - if([set characterIsMember:[string characterAtIndex:lpos]] != lmemberstate && lpos < proposedCharRange.location) lpos++; + while(lpos && [set characterIsMember: [string characterAtIndex: lpos]]== lmemberstate) lpos--; + if ([set characterIsMember: [string characterAtIndex: lpos]] != lmemberstate && lpos < proposedCharRange.location) lpos++; NSLog(@"lpos = %d, rpos = %d\n", lpos, rpos); @@ -624,53 +638,53 @@ nil]; // // low level (no selection handling, relayout or display) --(void) replaceRange:(NSRange)range withAttributedString:(NSAttributedString*)attrString -{ if([self isRichText]) - { return [rtfContent replaceCharactersInRange:range withAttributedString:attrString]; - } else return [plainContent replaceCharactersInRange:range withString:[attrString string]]; +-(void) replaceRange: (NSRange)range withAttributedString: (NSAttributedString*)attrString +{ if ([self isRichText]) + { return [rtfContent replaceCharactersInRange: range withAttributedString: attrString]; + } else return [plainContent replaceCharactersInRange: range withString: [attrString string]]; } --(void) replaceRange:(NSRange)range withRTFD:(NSData *)rtfdData -{ return [self replaceRange:range withAttributedString:[[self class] attributedStringForData:rtfdData]]; +-(void) replaceRange: (NSRange)range withRTFD: (NSData *)rtfdData +{ return [self replaceRange: range withAttributedString: [[self class] attributedStringForData: rtfdData]]; } --(void) replaceRange:(NSRange)range withRTF:(NSData*) rtfData -{ [self replaceRange:range withRTFD:rtfData]; +-(void) replaceRange: (NSRange)range withRTF: (NSData*) rtfData +{ [self replaceRange: range withRTFD: rtfData]; } --(void) replaceRange:(NSRange)range withString:(NSString*) aString -{ if([self isRichText]) - { return [rtfContent replaceCharactersInRange:range withString:aString]; - } else return [plainContent replaceCharactersInRange:range withString:aString]; +-(void) replaceRange: (NSRange)range withString: (NSString*) aString +{ if ([self isRichText]) + { return [rtfContent replaceCharactersInRange: range withString: aString]; + } else return [plainContent replaceCharactersInRange: range withString: aString]; } --(void) setText:(NSString*) aString range:(NSRange) aRange -{ [self replaceRange:(NSRange)aRange withString:aString]; +-(void) setText: (NSString*) aString range: (NSRange) aRange +{ [self replaceRange: (NSRange)aRange withString: aString]; } --(NSData*) RTFDFromRange:(NSRange)range -{ if([self isRichText]) - { return [[self class] dataForAttributedString:[rtfContent attributedSubstringFromRange:range]]; +-(NSData*) RTFDFromRange: (NSRange)range +{ if ([self isRichText]) + { return [[self class] dataForAttributedString: [rtfContent attributedSubstringFromRange: range]]; } else return nil; } --(NSData*) RTFFromRange:(NSRange)range -{ return [self RTFDFromRange:range]; +-(NSData*) RTFFromRange: (NSRange)range +{ return [self RTFDFromRange: range]; } --(void) setString:(NSString *)string +-(void) setString: (NSString *)string { [plainContent release]; - plainContent=[[NSMutableString stringWithString:string] retain]; + plainContent=[[NSMutableString stringWithString: string] retain]; [lineLayoutInformation autorelease]; lineLayoutInformation=nil; // force complete re-layout - [self setRichText:NO]; - [self setSelectedRangeNoDrawing:NSMakeRange(0,0)]; -// [self rebuildLineLayoutInformationStartingAtLine:0]; -// [self setNeedsDisplay:YES]; + [self setRichText: NO]; + [self setSelectedRangeNoDrawing: NSMakeRange(0,0)]; +// [self rebuildLineLayoutInformationStartingAtLine: 0]; +// [self setNeedsDisplay: YES]; } --(void) setText:(NSString *)string {[self setString:string];} +-(void) setText: (NSString *)string {[self setString: string];} -(NSString*) string -{ if([self isRichText]) return [rtfContent string]; +{ if ([self isRichText]) return [rtfContent string]; else return plainContent; } -(NSString*) text {return [self string];} @@ -685,129 +699,154 @@ nil]; -(BOOL) isRichText { return is_rich_text; } -(BOOL) isSelectable { return is_selectable; } -- (void)setAlignment:(NSTextAlignment)mode +- (void)setAlignment: (NSTextAlignment)mode { alignment = mode; } -- (void)setDrawsBackground:(BOOL)flag +- (void)setDrawsBackground: (BOOL)flag { draws_background = flag; } -- (void)setEditable:(BOOL)flag +- (void)setEditable: (BOOL)flag { is_editable = flag; if (flag) is_selectable = YES; // If we are editable then we are selectable } -- (void)setImportsGraphics:(BOOL)flag +- (void)setImportsGraphics: (BOOL)flag { imports_graphics = flag; [self updateDragTypeRegistration]; } --(void) setRichText:(BOOL)flag +-(void) setRichText: (BOOL)flag { is_rich_text = flag; - if(flag) - { if(!rtfContent) rtfContent=[[NSMutableAttributedString alloc] initWithString:plainContent? (NSString*)plainContent:@"" attributes:[self defaultTypingAttributes]]; + if (flag) + { if (!rtfContent) rtfContent=[[NSMutableAttributedString alloc] initWithString: plainContent? (NSString*)plainContent: @"" attributes: [self defaultTypingAttributes]]; [lineLayoutInformation autorelease]; lineLayoutInformation=nil; - [self rebuildLineLayoutInformationStartingAtLine:0]; + [self rebuildLineLayoutInformationStartingAtLine: 0]; } else - { if(!plainContent) plainContent=[[NSMutableString alloc] initWithString:rtfContent? [rtfContent string]:@""]; - [self rebuildLineLayoutInformationStartingAtLine:0]; + { if (!plainContent) plainContent=[[NSMutableString alloc] initWithString: rtfContent? [rtfContent string]: @""]; + [self rebuildLineLayoutInformationStartingAtLine: 0]; } [self updateDragTypeRegistration]; [self sizeToFit]; - [self setNeedsDisplay:YES]; + [self setNeedsDisplay: YES]; } -- (void)setSelectable:(BOOL)flag +- (void)setSelectable: (BOOL)flag { is_selectable = flag; if (!flag) is_editable = NO; // If we are not selectable then we must not be editable } -// -// Managing Font and Color -// --(NSColor*) backgroundColor { return background_color; } --(NSFont*) font { return default_font; } --(NSColor*) textColor { return text_color; } --(BOOL) usesFontPanel { return uses_font_panel; } +/* + * Managing Font and Color + */ +- (NSColor*) backgroundColor +{ + return background_color; +} + +- (NSFont*) font +{ + return default_font; +} + +- (NSColor*) textColor +{ + return text_color; +} + +- (BOOL) usesFontPanel +{ + return uses_font_panel; +} // This action method changes the font of the selection for a rich text object, or of all text for a plain text object. If the receiver doesn't use the Font Panel, however, this method does nothing. --(void) changeFont:sender -{ if([self usesFontPanel]) - { if([self isRichText]) +-(void) changeFont: sender +{ if ([self usesFontPanel]) + { if ([self isRichText]) { NSRange selectedRange=[self selectedRange], searchRange=selectedRange,foundRange; int maxSelRange; for(maxSelRange=NSMaxRange(selectedRange); searchRange.location< maxSelRange; searchRange=NSMakeRange(NSMaxRange(foundRange),maxSelRange-NSMaxRange(foundRange))) - { NSFont *font=[rtfContent attribute:NSFontAttributeName atIndex:searchRange.location longestEffectiveRange:&foundRange inRange:searchRange]; - if(font) - { [self setFont:[sender convertFont:font] ofRange:foundRange]; + { NSFont *font=[rtfContent attribute: NSFontAttributeName atIndex: searchRange.location longestEffectiveRange: &foundRange inRange: searchRange]; + if (font) + { [self setFont: [sender convertFont: font] ofRange: foundRange]; } } } else - { [self setFont:[sender convertFont:[[self defaultTypingAttributes] objectForKey:NSFontAttributeName]]]; + { [self setFont: [sender convertFont: [[self defaultTypingAttributes] objectForKey: NSFontAttributeName]]]; } } } --(void) setSelectionWordGranularitySet:(NSCharacterSet*) aSet +-(void) setSelectionWordGranularitySet: (NSCharacterSet*) aSet { ASSIGN(selectionWordGranularitySet, aSet); } --(void) setSelectionParagraphGranularitySet:(NSCharacterSet*) aSet +-(void) setSelectionParagraphGranularitySet: (NSCharacterSet*) aSet { ASSIGN(selectionParagraphGranularitySet, aSet); } -- (void)setBackgroundColor:(NSColor *)color -{ ASSIGN(background_color, color); +- (void) setBackgroundColor: (NSColor *)color +{ + ASSIGN(background_color, color); } --(void) setTypingAttributes:(NSDictionary*) dict -{ if(![dict isKindOfClass:[NSMutableDictionary class]]) + +-(void) setTypingAttributes: (NSDictionary*) dict +{ if (![dict isKindOfClass: [NSMutableDictionary class]]) { [typingAttributes autorelease]; - typingAttributes=[[NSMutableDictionary alloc] initWithDictionary:dict]; // do not autorelease! + typingAttributes=[[NSMutableDictionary alloc] initWithDictionary: dict]; // do not autorelease! } else ASSIGN(typingAttributes, (NSMutableDictionary*)dict); } -(NSMutableDictionary*) typingAttributes -{ if(typingAttributes) return typingAttributes; - else return [NSMutableDictionary dictionaryWithDictionary:[self defaultTypingAttributes]]; +{ if (typingAttributes) return typingAttributes; + else return [NSMutableDictionary dictionaryWithDictionary: [self defaultTypingAttributes]]; } -- (void)setTextColor:(NSColor *)color range:(NSRange)range -{ if([self isRichText]) - { if(color) [rtfContent addAttribute:NSForegroundColorAttributeName value:color range:range]; - } else {} - -} --(void) setColor:(NSColor *)color ofRange:(NSRange)range -{ [self setTextColor:color range:range]; +- (void) setTextColor: (NSColor*)color range: (NSRange)range +{ + if ([self isRichText]) + { + if (color) + [rtfContent addAttribute: NSForegroundColorAttributeName + value: color + range: range]; + } } -- (void)setFont:(NSFont *)obj -{ ASSIGN(default_font, obj); +- (void) setColor: (NSColor*)color ofRange: (NSRange)range +{ + [self setTextColor: color range: range]; } -- (void)setFont:(NSFont *)font ofRange:(NSRange)range -{ if([self isRichText]) - { if(font) - { [rtfContent addAttribute:NSFontAttributeName value:font range:range]; - [self rebuildFromCharacterIndex:range.location]; +- (void)setFont: (NSFont*)obj +{ + ASSIGN(default_font, obj); +} + +- (void)setFont: (NSFont *)font ofRange: (NSRange)range +{ if ([self isRichText]) + { if (font) + { [rtfContent addAttribute: NSFontAttributeName value: font range: range]; + [self rebuildFromCharacterIndex: range.location]; NSLog(@"did set font"); } } else {} } -- (void)setTextColor:(NSColor *)color -{ ASSIGN(text_color,color); - - if(![self isRichText]) [self setNeedsDisplay:YES]; +- (void) setTextColor: (NSColor *)color +{ + ASSIGN(text_color,color); + if (![self isRichText]) + [self setNeedsDisplay: YES]; } -- (void)setUsesFontPanel:(BOOL)flag +- (void)setUsesFontPanel: (BOOL)flag { uses_font_panel = flag; } @@ -821,44 +860,62 @@ NSLog(@"did set font"); -(BOOL) shouldDrawInsertionPoint { return ([self selectedRange].length==0) && [self isEditable]; } --(void) drawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)flag -{ BOOL didLock=NO; - if (![self window]) - return; +- (void) drawInsertionPointInRect: (NSRect)rect + color: (NSColor *)color + turnedOn: (BOOL)flag +{ + BOOL didLock = NO; - if([self window] && [[self class] focusView] != self) - { [self lockFocus]; - didLock=YES; - } + if (![self window]) + return; - if(flag) { - [color set]; - NSRectFill(rect); - } else { - [[self backgroundColor] set]; NSRectFill(rect); - } + if ([self window] && [[self class] focusView] != self) + { + [self lockFocus]; + didLock = YES; + } - if(didLock) - { [self unlockFocus]; - [[self window] flushWindow]; - } + if (flag) + { + [color set]; + NSRectFill(rect); + } + else + { + [[self backgroundColor] set]; + NSRectFill(rect); + } + + if (didLock) + { + [self unlockFocus]; + [[self window] flushWindow]; + } } --(void) drawInsertionPointAtIndex:(unsigned)index color:(NSColor *)color turnedOn:(BOOL)flag -{ NSRect startRect=[self rectForCharacterIndex:index]; -// [self drawInsertionPointInRect:NSMakeRect(startRect.origin.x, startRect.origin.y,0.5,startRect.size.height) - [self drawInsertionPointInRect:NSMakeRect(startRect.origin.x, startRect.origin.y,1,startRect.size.height) - color:[NSColor blackColor] turnedOn:flag]; + +- (void) drawInsertionPointAtIndex: (unsigned)index + color: (NSColor*)color + turnedOn: (BOOL)flag +{ + NSRect startRect = [self rectForCharacterIndex: index]; + NSRect drawRect; + + drawRect = NSMakeRect(startRect.origin.x, startRect.origin.y, + 1, startRect.size.height); + [self drawInsertionPointInRect: drawRect + color: [NSColor blackColor] + turnedOn: flag]; } --(void) drawSelectionAsRangeNoCaret:(NSRange) aRange -{ if(aRange.length) - { NSRect startRect=[self rectForCharacterIndex:aRange.location], - endRect=[self rectForCharacterIndex:NSMaxRange(aRange)]; - if(startRect.origin.y == endRect.origin.y) // single line selection +-(void) drawSelectionAsRangeNoCaret: (NSRange) aRange +{ if (aRange.length) + { NSRect startRect=[self rectForCharacterIndex: aRange.location], + endRect=[self rectForCharacterIndex: NSMaxRange(aRange)]; + if (startRect.origin.y == endRect.origin.y) // single line selection { NSHighlightRect(NSMakeRect(startRect.origin.x,startRect.origin.y,endRect.origin.x-startRect.origin.x, startRect.size.height)); - } else if(startRect.origin.y == endRect.origin.y-endRect.size.height) // two line selection + } else if (startRect.origin.y == endRect.origin.y-endRect.size.height) // two line selection { NSHighlightRect((NSMakeRect(startRect.origin.x,startRect.origin.y,[self frame].size.width-startRect.origin.x,startRect.size.height))); // first line NSHighlightRect(NSMakeRect(0,endRect.origin.y,endRect.origin.x,endRect.size.height)); // second line } else // 3 Rects: multiline selection @@ -868,70 +925,79 @@ NSLog(@"did set font"); } } } --(void) drawSelectionAsRange:(NSRange) aRange -{ if(aRange.length) - { [self drawSelectionAsRangeNoCaret:aRange]; - } else [self drawInsertionPointAtIndex:aRange.location color:[NSColor blackColor] turnedOn:YES]; + +- (void) drawSelectionAsRange: (NSRange) aRange +{ + if (aRange.length) + { + [self drawSelectionAsRangeNoCaret: aRange]; + } + else + { + [self drawInsertionPointAtIndex: aRange.location + color: [NSColor blackColor] + turnedOn: YES]; + } } // low level selection setting including delegation --(void) setSelectedRangeNoDrawing:(NSRange)range +-(void) setSelectedRangeNoDrawing: (NSRange)range { #if 0 // ask delegate for selection validation #endif selected_range = range; #if 0 - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextViewDidChangeSelectionNotification object:self - userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSStringFromRange(selected_range),NSOldSelectedCharacterRange, + [[NSNotificationCenter defaultCenter] postNotificationName: NSTextViewDidChangeSelectionNotification object: self + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: NSStringFromRange(selected_range),NSOldSelectedCharacterRange, nil]]; #endif } --(void) setSelectedRange:(NSRange)range +-(void) setSelectedRange: (NSRange)range { BOOL didLock=NO; - if(![self window]) + if (![self window]) return; - if([self window] && [[self class] focusView] != self) + if ([self window] && [[self class] focusView] != self) { [self lockFocus]; didLock=YES; } - if(selected_range.length== 0) // remove old cursor - { [self drawInsertionPointAtIndex:selected_range.location color:nil turnedOn:NO]; + if (selected_range.length== 0) // remove old cursor + { [self drawInsertionPointAtIndex: selected_range.location color: nil turnedOn: NO]; } else - { [self drawSelectionAsRange:selected_range]; + { [self drawSelectionAsRange: selected_range]; } - [self setSelectedRangeNoDrawing:range]; + [self setSelectedRangeNoDrawing: range]; - if([self usesFontPanel]) // update fontPanel + if ([self usesFontPanel]) // update fontPanel { BOOL isMultiple=NO; NSFont *currentFont=nil; - if([self isRichText]) - { if([rtfContent areMultipleFontsInRange:selected_range]) isMultiple=YES; - else currentFont=[[rtfContent attribute:NSFontAttributeName atIndex:range.location longestEffectiveRange:NULL inRange:range] - objectForKey:NSFontAttributeName]; - } else currentFont=[[self defaultTypingAttributes] objectForKey:NSFontAttributeName]; - [[NSFontPanel sharedFontPanel] setPanelFont:currentFont isMultiple:isMultiple]; + if ([self isRichText]) + { if ([rtfContent areMultipleFontsInRange: selected_range]) isMultiple=YES; + else currentFont=[[rtfContent attribute: NSFontAttributeName atIndex: range.location longestEffectiveRange: NULL inRange: range] + objectForKey: NSFontAttributeName]; + } else currentFont=[[self defaultTypingAttributes] objectForKey: NSFontAttributeName]; + [[NSFontPanel sharedFontPanel] setPanelFont: currentFont isMultiple: isMultiple]; } // display - if(range.length) + if (range.length) { // disable caret timed entry } else // no selection - { if([self isRichText]) - { [self setTypingAttributes:[NSMutableDictionary dictionaryWithDictionary:[rtfContent attributesAtIndex:range.location effectiveRange:NULL]]]; + { if ([self isRichText]) + { [self setTypingAttributes: [NSMutableDictionary dictionaryWithDictionary: [rtfContent attributesAtIndex: range.location effectiveRange: NULL]]]; } // enable caret timed entry } - [self drawSelectionAsRange:range]; - [self scrollRangeToVisible:range]; + [self drawSelectionAsRange: range]; + [self scrollRangeToVisible: range]; - if(didLock) + if (didLock) { [self unlockFocus]; [[self window] flushWindow]; } @@ -940,9 +1006,9 @@ NSLog(@"did set font"); // // Sizing the Frame Rectangle // --(void) setFrame:(NSRect)frameRect +-(void) setFrame: (NSRect)frameRect { - [super setFrame:frameRect]; + [super setFrame: frameRect]; } -(BOOL) isHorizontallyResizable { return is_horizontally_resizable; } @@ -950,29 +1016,29 @@ NSLog(@"did set font"); -(NSSize) maxSize { return maxSize; } -(NSSize) minSize { return minSize; } -- (void)setHorizontallyResizable:(BOOL)flag +- (void)setHorizontallyResizable: (BOOL)flag { is_horizontally_resizable = flag; } -- (void)setMaxSize:(NSSize)newMaxSize +- (void)setMaxSize: (NSSize)newMaxSize { maxSize=newMaxSize; } -- (void)setMinSize:(NSSize)newMinSize +- (void)setMinSize: (NSSize)newMinSize { minSize=newMinSize; } --(void) setVerticallyResizable:(BOOL)flag +-(void) setVerticallyResizable: (BOOL)flag { is_vertically_resizable = flag; } -(unsigned) textLength -{ if([self isRichText]) return [rtfContent length]; +{ if ([self isRichText]) return [rtfContent length]; else return [plainContent length]; } --(NSRect) boundingRectForLineRange:(NSRange)lineRange -{ NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange:lineRange]; +-(NSRect) boundingRectForLineRange: (NSRange)lineRange +{ NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange: lineRange]; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; NSRect retRect=NSMakeRect(0,0,0,0); @@ -992,23 +1058,23 @@ NSLog(@"did set font"); if ([self isFieldEditor]) // if we are a field editor we don't have to handle the size. return; - if([self isHorizontallyResizable]) { - if([lineLayoutInformation count]) { - sizeToRect=[self boundingRectForLineRange:NSMakeRange(0,[lineLayoutInformation count])]; + if ([self isHorizontallyResizable]) { + if ([lineLayoutInformation count]) { + sizeToRect=[self boundingRectForLineRange: NSMakeRange(0,[lineLayoutInformation count])]; } else sizeToRect.size=minSize; } - else if([self isVerticallyResizable]) { - if([lineLayoutInformation count]) { - NSRect rect=NSUnionRect([[lineLayoutInformation objectAtIndex:0] + else if ([self isVerticallyResizable]) { + if ([lineLayoutInformation count]) { + NSRect rect=NSUnionRect([[lineLayoutInformation objectAtIndex: 0] lineRect], [[lineLayoutInformation lastObject] lineRect]); float newHeight=rect.size.height; float newY; NSRect tRect; - if([[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph && NSMaxY(rect)<= newHeight) + if ([[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph && NSMaxY(rect)<= newHeight) newHeight+=[[lineLayoutInformation lastObject] lineRect].size.height; if ( [[self superview] isKindOfClass: [NSClipView class]] ) @@ -1023,7 +1089,7 @@ NSLog(@"did set font"); [[lineLayoutInformation lastObject] lineRect].size.height) { newY = currentCursorY - tRect.size.height + ([[lineLayoutInformation lastObject] lineRect].size.height * 2); - [(NSClipView *)[self superview] scrollToPoint:NSMakePoint(sizeToRect.origin.x,newY)]; + [(NSClipView *)[self superview] scrollToPoint: NSMakePoint(sizeToRect.origin.x,newY)]; } else NSLog(@"=========> Oops!\n"); @@ -1036,58 +1102,58 @@ NSLog(@"did set font"); sizeToRect=NSMakeRect(0,0,minSize.width,minSize.height); } - if(!NSEqualSizes([self frame].size,sizeToRect.size)) { - [self setFrame:sizeToRect]; //[self setFrameSize:sizeToRect.size]; + if (!NSEqualSizes([self frame].size,sizeToRect.size)) { + [self setFrame: sizeToRect]; //[self setFrameSize: sizeToRect.size]; } } --(void) sizeToFit:sender {[self sizeToFit];} +-(void) sizeToFit: sender {[self sizeToFit];} // // Responding to Editing Commands // --(void) alignCenter:sender +-(void) alignCenter: sender { } --(void) alignLeft:sender +-(void) alignLeft: sender { } --(void) alignRight:sender +-(void) alignRight: sender { } --(void) selectAll:sender -{ [self setSelectedRange:NSMakeRange(0,[self textLength])]; +-(void) selectAll: sender +{ [self setSelectedRange: NSMakeRange(0,[self textLength])]; } --(void) subscript:sender +-(void) subscript: sender { } --(void) superscript:sender +-(void) superscript: sender { } --(void) underline:sender -{ if([self isRichText]) +-(void) underline: sender +{ if ([self isRichText]) { BOOL doUnderline=YES; - if([[rtfContent attribute:NSUnderlineStyleAttributeName atIndex:[self selectedRange].location effectiveRange:NULL] intValue]) doUnderline=NO; + if ([[rtfContent attribute: NSUnderlineStyleAttributeName atIndex: [self selectedRange].location effectiveRange: NULL] intValue]) doUnderline=NO; - if([self selectedRange].length) - { [rtfContent addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:doUnderline] range:[self selectedRange]]; - [self rebuildFromCharacterIndex:[self selectedRange].location]; - } else [[self typingAttributes] setObject:[NSNumber numberWithInt:doUnderline] forKey: NSUnderlineStyleAttributeName]; // no redraw necess. + if ([self selectedRange].length) + { [rtfContent addAttribute: NSUnderlineStyleAttributeName value: [NSNumber numberWithInt: doUnderline] range: [self selectedRange]]; + [self rebuildFromCharacterIndex: [self selectedRange].location]; + } else [[self typingAttributes] setObject: [NSNumber numberWithInt: doUnderline] forKey: NSUnderlineStyleAttributeName]; // no redraw necess. } } --(void) unscript:sender -{ if([self isRichText]) - { if([self selectedRange].length) - { [rtfContent removeAttribute:NSUnderlineStyleAttributeName range:[self selectedRange]]; - [self rebuildFromCharacterIndex:[self selectedRange].location]; - } else [[self typingAttributes] removeObjectForKey:NSUnderlineStyleAttributeName]; // no redraw necess. +-(void) unscript: sender +{ if ([self isRichText]) + { if ([self selectedRange].length) + { [rtfContent removeAttribute: NSUnderlineStyleAttributeName range: [self selectedRange]]; + [self rebuildFromCharacterIndex: [self selectedRange].location]; + } else [[self typingAttributes] removeObjectForKey: NSUnderlineStyleAttributeName]; // no redraw necess. } } @@ -1096,7 +1162,7 @@ NSLog(@"did set font"); // -(BOOL) isRulerVisible { return NO; } --(void) toggleRuler:sender +-(void) toggleRuler: sender { } @@ -1105,34 +1171,34 @@ NSLog(@"did set font"); // Scrolling // --(void) scrollRangeToVisible:(NSRange)range +-(void) scrollRangeToVisible: (NSRange)range { - [self scrollRectToVisible:NSUnionRect([self -rectForCharacterIndex:[self selectedRange].location], - [self rectForCharacterIndex:NSMaxRange([self selectedRange])])]; + [self scrollRectToVisible: NSUnionRect([self +rectForCharacterIndex: [self selectedRange].location], + [self rectForCharacterIndex: NSMaxRange([self selectedRange])])]; } // // Reading and Writing RTFD Files // --(BOOL) readRTFDFromFile:(NSString *)path -{ NSData *data=[NSData dataWithContentsOfFile:path]; +-(BOOL) readRTFDFromFile: (NSString *)path +{ NSData *data=[NSData dataWithContentsOfFile: path]; id peek; - if(data && (peek=[[self class] attributedStringForData:data])) - { is_rich_text=YES; // not [self setRichText:YES] for efficiancy reasons + if (data && (peek=[[self class] attributedStringForData: data])) + { is_rich_text=YES; // not [self setRichText: YES] for efficiancy reasons [self updateDragTypeRegistration]; - [self replaceRange:NSMakeRange(0,[self textLength]) withAttributedString:peek]; - [self rebuildLineLayoutInformationStartingAtLine:0]; - [self setNeedsDisplay:YES]; + [self replaceRange: NSMakeRange(0,[self textLength]) withAttributedString: peek]; + [self rebuildLineLayoutInformationStartingAtLine: 0]; + [self setNeedsDisplay: YES]; return YES; } return NO; } --(BOOL) writeRTFDToFile:(NSString *)path atomically:(BOOL)flag -{ if([self isRichText]) - { NSFileWrapper *wrapper=[[[NSFileWrapper alloc] initRegularFileWithContents:[[self class] dataForAttributedString:rtfContent]] autorelease]; - return [wrapper writeToFile:path atomically:flag updateFilenames:YES]; +-(BOOL) writeRTFDToFile: (NSString *)path atomically: (BOOL)flag +{ if ([self isRichText]) + { NSFileWrapper *wrapper=[[[NSFileWrapper alloc] initRegularFileWithContents: [[self class] dataForAttributedString: rtfContent]] autorelease]; + return [wrapper writeToFile: path atomically: flag updateFilenames: YES]; } return NO; } @@ -1141,72 +1207,72 @@ rectForCharacterIndex:[self selectedRange].location], // -(BOOL) isFieldEditor { return is_field_editor; } --(void) setFieldEditor:(BOOL)flag +-(void) setFieldEditor: (BOOL)flag { is_field_editor = flag; } --(int) lineLayoutIndexForCharacterIndex:(unsigned) anIndex +-(int) lineLayoutIndexForCharacterIndex: (unsigned) anIndex { NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; - if([lineLayoutInformation count] && anIndex>= NSMaxRange([[lineLayoutInformation lastObject] lineRange])) + if ([lineLayoutInformation count] && anIndex>= NSMaxRange([[lineLayoutInformation lastObject] lineRange])) return [lineLayoutInformation count]-1; for((lineEnum=[lineLayoutInformation objectEnumerator]); (currentInfo=[lineEnum nextObject]);) { NSRange lineRange=[currentInfo lineRange]; - if(lineRange.location<= anIndex && anIndex<= NSMaxRange(lineRange)-([currentInfo type] == LineLayoutInfoType_Paragraph? 1:0)) - return [lineLayoutInformation indexOfObject:currentInfo]; + if (lineRange.location<= anIndex && anIndex<= NSMaxRange(lineRange)-([currentInfo type] == LineLayoutInfoType_Paragraph? 1: 0)) + return [lineLayoutInformation indexOfObject: currentInfo]; } - if([lineLayoutInformation count]) NSLog(@"NSText's lineLayoutIndexForCharacterIndex: index out of bounds!"); + if ([lineLayoutInformation count]) NSLog(@"NSText's lineLayoutIndexForCharacterIndex: index out of bounds!"); return 0; } // choose granularity according to keyboard modifier flags --(void) moveCursorUp:sender +-(void) moveCursorUp: sender { unsigned cursorIndex; NSPoint cursorPoint; - if([self selectedRange].length) { - currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; - currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y; + if ([self selectedRange].length) { + currentCursorX=[self rectForCharacterIndex: [self selectedRange].location].origin.x; + currentCursorY=[self rectForCharacterIndex: [self selectedRange].location].origin.y; } cursorIndex=[self selectedRange].location; - cursorPoint=[self rectForCharacterIndex:cursorIndex].origin; - cursorIndex=[self characterIndexForPoint:NSMakePoint(currentCursorX+0.001,MAX(0,cursorPoint.y-0.001))]; - [self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange(cursorIndex,0) granularity:NSSelectByCharacter]]; + cursorPoint=[self rectForCharacterIndex: cursorIndex].origin; + cursorIndex=[self characterIndexForPoint: NSMakePoint(currentCursorX+0.001,MAX(0,cursorPoint.y-0.001))]; + [self setSelectedRange: [self selectionRangeForProposedRange: NSMakeRange(cursorIndex,0) granularity: NSSelectByCharacter]]; // FIXME: Terrible hack. - [self insertText:@""]; + [self insertText: @""]; } --(void) moveCursorDown:sender +-(void) moveCursorDown: sender { unsigned cursorIndex; NSRect cursorRect; - if([self selectedRange].length) { -currentCursorX=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].origin.x; -currentCursorY=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].origin.y; + if ([self selectedRange].length) { +currentCursorX=[self rectForCharacterIndex: NSMaxRange([self selectedRange])].origin.x; +currentCursorY=[self rectForCharacterIndex: NSMaxRange([self selectedRange])].origin.y; } cursorIndex=[self selectedRange].location; - cursorRect=[self rectForCharacterIndex:cursorIndex]; - cursorIndex=[self characterIndexForPoint:NSMakePoint(currentCursorX+0.001,NSMaxY(cursorRect)+0.001)]; - [self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange(cursorIndex,0) granularity:NSSelectByCharacter]]; + cursorRect=[self rectForCharacterIndex: cursorIndex]; + cursorIndex=[self characterIndexForPoint: NSMakePoint(currentCursorX+0.001,NSMaxY(cursorRect)+0.001)]; + [self setSelectedRange: [self selectionRangeForProposedRange: NSMakeRange(cursorIndex,0) granularity: NSSelectByCharacter]]; // FIXME: Terrible hack. - [self insertText:@""]; + [self insertText: @""]; } --(void) moveCursorLeft:sender -{ [self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange([self selectedRange].location-1,0) granularity:NSSelectByCharacter]]; - currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; +-(void) moveCursorLeft: sender +{ [self setSelectedRange: [self selectionRangeForProposedRange: NSMakeRange([self selectedRange].location-1,0) granularity: NSSelectByCharacter]]; + currentCursorX=[self rectForCharacterIndex: [self selectedRange].location].origin.x; } --(void) moveCursorRight:sender -{ [self setSelectedRange:[self selectionRangeForProposedRange:NSMakeRange(MIN(NSMaxRange([self selectedRange])+1,[self textLength]),0) - granularity:NSSelectByCharacter]]; - currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; +-(void) moveCursorRight: sender +{ [self setSelectedRange: [self selectionRangeForProposedRange: NSMakeRange(MIN(NSMaxRange([self selectedRange])+1,[self textLength]),0) + granularity: NSSelectByCharacter]]; + currentCursorX=[self rectForCharacterIndex: [self selectedRange].location].origin.x; } // // Handling Events // --(void) mouseDown:(NSEvent *)theEvent +-(void) mouseDown: (NSEvent *)theEvent { NSSelectionGranularity granularity= NSSelectByCharacter; NSRange chosenRange,prevChosenRange,proposedRange; @@ -1217,7 +1283,7 @@ currentCursorY=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].ori if (!is_selectable) return; // If not selectable then don't recognize the mouse down - [[self window] makeFirstResponder:self]; + [[self window] makeFirstResponder: self]; switch([theEvent clickCount]) { case 1: granularity=NSSelectByCharacter; @@ -1228,45 +1294,45 @@ currentCursorY=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].ori break; } - startPoint=[self convertPoint:[theEvent locationInWindow] fromView:nil]; - startIndex=[self characterIndexForPoint:startPoint]; + startPoint=[self convertPoint: [theEvent locationInWindow] fromView: nil]; + startIndex=[self characterIndexForPoint: startPoint]; proposedRange=NSMakeRange(startIndex,0); - chosenRange=prevChosenRange=[self selectionRangeForProposedRange:proposedRange granularity:granularity]; + chosenRange=prevChosenRange=[self selectionRangeForProposedRange: proposedRange granularity: granularity]; [self lockFocus]; // clean up before doing the dragging - if([self selectedRange].length== 0) // remove old cursor - { [self drawInsertionPointAtIndex:[self selectedRange].location color:nil turnedOn:NO]; - } else [self drawSelectionAsRangeNoCaret:[self selectedRange]]; + if ([self selectedRange].length== 0) // remove old cursor + { [self drawInsertionPointAtIndex: [self selectedRange].location color: nil turnedOn: NO]; + } else [self drawSelectionAsRangeNoCaret: [self selectedRange]]; // make this non-blocking (or make use of timed entries) - for(currentEvent= [[self window] nextEventMatchingMask:NSLeftMouseDraggedMask|NSLeftMouseUpMask];[currentEvent type] != NSLeftMouseUp; - (currentEvent= [[self window] nextEventMatchingMask:NSLeftMouseDraggedMask|NSLeftMouseUpMask]), prevChosenRange=chosenRange) // run modal loop + for(currentEvent= [[self window] nextEventMatchingMask: NSLeftMouseDraggedMask|NSLeftMouseUpMask];[currentEvent type] != NSLeftMouseUp; + (currentEvent= [[self window] nextEventMatchingMask: NSLeftMouseDraggedMask|NSLeftMouseUpMask]), prevChosenRange=chosenRange) // run modal loop { - BOOL didScroll= [self autoscroll:currentEvent]; - point = [self convertPoint:[currentEvent locationInWindow] fromView:nil]; - proposedRange=MakeRangeFromAbs([self characterIndexForPoint:point],startIndex); - chosenRange=[self selectionRangeForProposedRange:proposedRange granularity:granularity]; + BOOL didScroll= [self autoscroll: currentEvent]; + point = [self convertPoint: [currentEvent locationInWindow] fromView: nil]; + proposedRange=MakeRangeFromAbs([self characterIndexForPoint: point],startIndex); + chosenRange=[self selectionRangeForProposedRange: proposedRange granularity: granularity]; - if(NSEqualRanges(prevChosenRange,chosenRange)) - { if(!didDragging) - { [self drawSelectionAsRangeNoCaret:chosenRange]; + if (NSEqualRanges(prevChosenRange,chosenRange)) + { if (!didDragging) + { [self drawSelectionAsRangeNoCaret: chosenRange]; [[self window] flushWindow]; } else continue; } // this changes the selection without needing instance drawing (carefully thought out ;-) - if(!didScroll) - { [self drawSelectionAsRangeNoCaret:MakeRangeFromAbs(MIN(chosenRange.location, prevChosenRange.location), + if (!didScroll) + { [self drawSelectionAsRangeNoCaret: MakeRangeFromAbs(MIN(chosenRange.location, prevChosenRange.location), MAX(chosenRange.location, prevChosenRange.location))]; - [self drawSelectionAsRangeNoCaret:MakeRangeFromAbs(MIN(NSMaxRange(chosenRange),NSMaxRange(prevChosenRange)), + [self drawSelectionAsRangeNoCaret: MakeRangeFromAbs(MIN(NSMaxRange(chosenRange),NSMaxRange(prevChosenRange)), MAX(NSMaxRange(chosenRange),NSMaxRange(prevChosenRange)))]; [[self window] flushWindow]; } else - { [self drawRectNoSelection:[self visibleRect]]; - [self drawSelectionAsRangeNoCaret:chosenRange]; + { [self drawRectNoSelection: [self visibleRect]]; + [self drawSelectionAsRangeNoCaret: chosenRange]; [[self window] flushWindow]; } @@ -1276,238 +1342,238 @@ currentCursorY=[self rectForCharacterIndex:NSMaxRange([self selectedRange])].ori NSLog(@"chosenRange. location = % d, length = %d\n", (int)chosenRange.location, (int)chosenRange.length); - [self setSelectedRangeNoDrawing:chosenRange]; - if(!didDragging) [self drawSelectionAsRange:chosenRange]; - else if(chosenRange.length == 0) [self drawInsertionPointAtIndex:chosenRange.location color:[NSColor blackColor] turnedOn:YES]; + [self setSelectedRangeNoDrawing: chosenRange]; + if (!didDragging) [self drawSelectionAsRange: chosenRange]; + else if (chosenRange.length == 0) [self drawInsertionPointAtIndex: chosenRange.location color: [NSColor blackColor] turnedOn: YES]; - currentCursorX=[self rectForCharacterIndex:chosenRange.location].origin.x; // remember for column stable cursor up/down - currentCursorY=[self rectForCharacterIndex:chosenRange.location].origin.y; // remember for column stable cursor up/down + currentCursorX=[self rectForCharacterIndex: chosenRange.location].origin.x; // remember for column stable cursor up/down + currentCursorY=[self rectForCharacterIndex: chosenRange.location].origin.y; // remember for column stable cursor up/down [self unlockFocus]; [[self window] flushWindow]; } --(void) redisplayForLineRange:(NSRange) redrawLineRange +-(void) redisplayForLineRange: (NSRange) redrawLineRange { BOOL didLock=NO; - if([self window] && [[self class] focusView] != self) + if ([self window] && [[self class] focusView] != self) { [self lockFocus]; didLock=YES; } - if([lineLayoutInformation count] && redrawLineRange.location < [lineLayoutInformation count] && redrawLineRange.length) - { _GNULineLayoutInfo *firstInfo=[lineLayoutInformation objectAtIndex:redrawLineRange.location]; + if ([lineLayoutInformation count] && redrawLineRange.location < [lineLayoutInformation count] && redrawLineRange.length) + { _GNULineLayoutInfo *firstInfo=[lineLayoutInformation objectAtIndex: redrawLineRange.location]; NSRect displayRect,firstRect=[firstInfo lineRect]; - if([firstInfo type] == LineLayoutInfoType_Paragraph && firstRect.origin.x >0 && redrawLineRange.location) + if ([firstInfo type] == LineLayoutInfoType_Paragraph && firstRect.origin.x >0 && redrawLineRange.location) { redrawLineRange.location--;redrawLineRange.length++; } - displayRect=NSUnionRect([[lineLayoutInformation objectAtIndex:redrawLineRange.location] lineRect], - [[lineLayoutInformation objectAtIndex:MAX(0,(int)NSMaxRange(redrawLineRange)-1)] lineRect]); + displayRect=NSUnionRect([[lineLayoutInformation objectAtIndex: redrawLineRange.location] lineRect], + [[lineLayoutInformation objectAtIndex: MAX(0,(int)NSMaxRange(redrawLineRange)-1)] lineRect]); displayRect.size.width=[self frame].size.width-displayRect.origin.x; [[self backgroundColor] set]; NSRectFill(displayRect); - if([self isRichText]) - { [self drawRichLinesInLineRange:redrawLineRange]; + if ([self isRichText]) + { [self drawRichLinesInLineRange: redrawLineRange]; } else - { [self drawPlainLinesInLineRange:redrawLineRange]; + { [self drawPlainLinesInLineRange: redrawLineRange]; } - [self drawSelectionAsRange:[self selectedRange]]; + [self drawSelectionAsRange: [self selectedRange]]; } - if([self drawsBackground]) // clean up the remaining area under text of us + if ([self drawsBackground]) // clean up the remaining area under text of us { float lowestY=0; NSRect myFrame=[self frame]; - if([lineLayoutInformation count]) lowestY=NSMaxY([[lineLayoutInformation lastObject] lineRect]); + if ([lineLayoutInformation count]) lowestY=NSMaxY([[lineLayoutInformation lastObject] lineRect]); - if(![lineLayoutInformation count] || (lowestY < NSMaxY(myFrame) && myFrame.size.height<= [self minSize].height)) + if (![lineLayoutInformation count] || (lowestY < NSMaxY(myFrame) && myFrame.size.height<= [self minSize].height)) { [[self backgroundColor] set]; NSRectFill(NSMakeRect(0,lowestY,myFrame.size.width,NSMaxY(myFrame)-lowestY)); - if(![lineLayoutInformation count] || [[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph) - [self drawSelectionAsRange:[self selectedRange]]; + if (![lineLayoutInformation count] || [[lineLayoutInformation lastObject] type] == LineLayoutInfoType_Paragraph) + [self drawSelectionAsRange: [self selectedRange]]; } - } if(didLock) + } if (didLock) { [self unlockFocus]; [[self window] flushWindow]; } } --(void) rebuildFromCharacterIndex:(int) anIndex +-(void) rebuildFromCharacterIndex: (int) anIndex { NSRange redrawLineRange; - int start,count=[self rebuildLineLayoutInformationStartingAtLine:start=[self lineLayoutIndexForCharacterIndex:anIndex]]; + int start,count=[self rebuildLineLayoutInformationStartingAtLine: start=[self lineLayoutIndexForCharacterIndex: anIndex]]; redrawLineRange=NSMakeRange(MAX(0,start-1),count+1); - redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect:[self visibleRect]]); - [self redisplayForLineRange:redrawLineRange]; + redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect: [self visibleRect]]); + [self redisplayForLineRange: redrawLineRange]; NSLog(NSStringFromRange(redrawLineRange)); } // central text inserting method (takes care of optimized redraw/ cursor positioning) --(void) insertText:insertObjc +-(void) insertText: insertObjc { NSRange selectedRange=[self selectedRange]; - int lineIndex=[self lineLayoutIndexForCharacterIndex:selectedRange.location],origLineIndex=lineIndex,caretLineIndex=lineIndex; + int lineIndex=[self lineLayoutIndexForCharacterIndex: selectedRange.location],origLineIndex=lineIndex,caretLineIndex=lineIndex; NSRange redrawLineRange; NSString *insertString=nil; - if([insertObjc isKindOfClass:[NSString class]]) insertString=insertObjc; + if ([insertObjc isKindOfClass: [NSString class]]) insertString=insertObjc; else insertString=[insertObjc string]; // in case e.g a space is inserted and a word actually shortened: redraw previous line to give it the chance to move up - if([lineLayoutInformation count] && [[lineLayoutInformation objectAtIndex:origLineIndex] type] != LineLayoutInfoType_Paragraph && - origLineIndex && [[lineLayoutInformation objectAtIndex:origLineIndex-1] type] != LineLayoutInfoType_Paragraph) + if ([lineLayoutInformation count] && [[lineLayoutInformation objectAtIndex: origLineIndex] type] != LineLayoutInfoType_Paragraph && + origLineIndex && [[lineLayoutInformation objectAtIndex: origLineIndex-1] type] != LineLayoutInfoType_Paragraph) origLineIndex--; redrawLineRange=MakeRangeFromAbs(origLineIndex,[lineLayoutInformation count]); - if([self isRichText]) - { [self replaceRange:[self selectedRange] - withAttributedString:[insertObjc isKindOfClass:[NSAttributedString class]]? insertObjc: - [[[NSAttributedString alloc] initWithString:insertString attributes:[self typingAttributes]] + if ([self isRichText]) + { [self replaceRange: [self selectedRange] + withAttributedString: [insertObjc isKindOfClass: [NSAttributedString class]]? insertObjc: + [[[NSAttributedString alloc] initWithString: insertString attributes: [self typingAttributes]] autorelease]]; } else - { [self replaceRange:[self selectedRange] withString:insertString]; + { [self replaceRange: [self selectedRange] withString: insertString]; } - redrawLineRange.length=[self rebuildLineLayoutInformationStartingAtLine:redrawLineRange.location - delta:[insertString length]-selectedRange.length - actualLine:caretLineIndex]; + redrawLineRange.length=[self rebuildLineLayoutInformationStartingAtLine: redrawLineRange.location + delta: [insertString length]-selectedRange.length + actualLine: caretLineIndex]; [self sizeToFit]; // ScrollView interaction - [self setSelectedRange:NSMakeRange([self selectedRange].location+[insertString length],0)]; // move cursor [self selectionRangeForProposedRange:] - currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; // remember x for row-stable cursor movements - currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y; // remember x for row-stable cursor movements + [self setSelectedRange: NSMakeRange([self selectedRange].location+[insertString length],0)]; // move cursor [self selectionRangeForProposedRange: ] + currentCursorX=[self rectForCharacterIndex: [self selectedRange].location].origin.x; // remember x for row-stable cursor movements + currentCursorY=[self rectForCharacterIndex: [self selectedRange].location].origin.y; // remember x for row-stable cursor movements - redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect:[self visibleRect]]); - [self redisplayForLineRange:redrawLineRange]; - [self textDidChange:nil]; // broadcast notification + redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect: [self visibleRect]]); + [self redisplayForLineRange: redrawLineRange]; + [self textDidChange: nil]; // broadcast notification } // central text deletion/backspace method (takes care of optimized redraw/ cursor positioning) --(void) deleteRange:(NSRange) aRange backspace:(BOOL) flag +-(void) deleteRange: (NSRange) aRange backspace: (BOOL) flag { int redrawLineIndex,caretLineIndex,firstLineIndex,lastLineIndex,linePosition; NSRange redrawLineRange; NSRange deleteRange; - if(!aRange.length && !flag) return; - if(!aRange.location && ! aRange.length) return; + if (!aRange.length && !flag) return; + if (!aRange.location && ! aRange.length) return; - if(aRange.length) { deleteRange=aRange;linePosition=deleteRange.location;} + if (aRange.length) { deleteRange=aRange;linePosition=deleteRange.location;} else { deleteRange=NSMakeRange(MAX(0,aRange.location-1),1);linePosition=NSMaxRange(deleteRange); } - firstLineIndex=caretLineIndex=[self lineLayoutIndexForCharacterIndex:linePosition]; - lastLineIndex=[self lineLayoutIndexForCharacterIndex:NSMaxRange(deleteRange)]; + firstLineIndex=caretLineIndex=[self lineLayoutIndexForCharacterIndex: linePosition]; + lastLineIndex=[self lineLayoutIndexForCharacterIndex: NSMaxRange(deleteRange)]; redrawLineIndex=MAX(0,firstLineIndex-1); // since first word may move upward - if(firstLineIndex && [[lineLayoutInformation objectAtIndex:firstLineIndex-1] type] == LineLayoutInfoType_Paragraph) - { _GNULineLayoutInfo *upperInfo=[lineLayoutInformation objectAtIndex:firstLineIndex], - *prevInfo=[lineLayoutInformation objectAtIndex:firstLineIndex-1]; + if (firstLineIndex && [[lineLayoutInformation objectAtIndex: firstLineIndex-1] type] == LineLayoutInfoType_Paragraph) + { _GNULineLayoutInfo *upperInfo=[lineLayoutInformation objectAtIndex: firstLineIndex], + *prevInfo=[lineLayoutInformation objectAtIndex: firstLineIndex-1]; - if(linePosition> [upperInfo lineRange].location) redrawLineIndex++; // no danger of word moving up - else if([prevInfo lineRect].origin.x > 0) redrawLineIndex--; // remove newline: skip paragraph-terminating infoObject + if (linePosition> [upperInfo lineRange].location) redrawLineIndex++; // no danger of word moving up + else if ([prevInfo lineRect].origin.x > 0) redrawLineIndex--; // remove newline: skip paragraph-terminating infoObject redrawLineIndex=MAX(0,redrawLineIndex); } redrawLineIndex=MIN(redrawLineIndex,[lineLayoutInformation count]-1); redrawLineRange=MakeRangeFromAbs(redrawLineIndex,[lineLayoutInformation count]); - if([self isRichText]) [rtfContent deleteCharactersInRange:deleteRange]; - else [plainContent deleteCharactersInRange:deleteRange]; + if ([self isRichText]) [rtfContent deleteCharactersInRange: deleteRange]; + else [plainContent deleteCharactersInRange: deleteRange]; - redrawLineRange.length=[self rebuildLineLayoutInformationStartingAtLine:redrawLineRange.location - delta:-deleteRange.length - actualLine:caretLineIndex]; + redrawLineRange.length=[self rebuildLineLayoutInformationStartingAtLine: redrawLineRange.location + delta: -deleteRange.length + actualLine: caretLineIndex]; [self sizeToFit]; // ScrollView interaction - [self setSelectedRange:NSMakeRange(deleteRange.location,0)]; // move cursor [self selectionRangeForProposedRange:] - currentCursorX=[self rectForCharacterIndex:[self selectedRange].location].origin.x; // remember x for row-stable cursor movements - currentCursorY=[self rectForCharacterIndex:[self selectedRange].location].origin.y; // remember x for row-stable cursor movements - redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect:[self visibleRect]]); - [self redisplayForLineRange:redrawLineRange]; + [self setSelectedRange: NSMakeRange(deleteRange.location,0)]; // move cursor [self selectionRangeForProposedRange: ] + currentCursorX=[self rectForCharacterIndex: [self selectedRange].location].origin.x; // remember x for row-stable cursor movements + currentCursorY=[self rectForCharacterIndex: [self selectedRange].location].origin.y; // remember x for row-stable cursor movements + redrawLineRange=NSIntersectionRange(redrawLineRange,[self lineRangeForRect: [self visibleRect]]); + [self redisplayForLineRange: redrawLineRange]; - [self textDidChange:nil]; // broadcast notification + [self textDidChange: nil]; // broadcast notification } --(void) keyDown:(NSEvent *)theEvent +-(void) keyDown: (NSEvent *)theEvent { unsigned short keyCode; - if(!is_editable) return; // If not editable then don't recognize the key down + if (!is_editable) return; // If not editable then don't recognize the key down - if((keyCode=[theEvent keyCode])) + if ((keyCode=[theEvent keyCode])) switch(keyCode) - { case NSUpArrowFunctionKey: //NSUpArrowFunctionKey: - [self moveCursorUp:self]; + { case NSUpArrowFunctionKey: //NSUpArrowFunctionKey: + [self moveCursorUp: self]; return; - case NSDownArrowFunctionKey: //NSDownArrowFunctionKey: - [self moveCursorDown:self]; + case NSDownArrowFunctionKey: //NSDownArrowFunctionKey: + [self moveCursorDown: self]; return; - case NSLeftArrowFunctionKey: //NSLeftArrowFunctionKey: - [self moveCursorLeft:self]; + case NSLeftArrowFunctionKey: //NSLeftArrowFunctionKey: + [self moveCursorLeft: self]; return; - case NSRightArrowFunctionKey: //NSRightArrowFunctionKey: - [self moveCursorRight:self]; + case NSRightArrowFunctionKey: //NSRightArrowFunctionKey: + [self moveCursorRight: self]; return; - case NSBackspaceKey: // backspace - [self deleteRange:[self selectedRange] backspace:YES]; + case NSBackspaceKey: // backspace + [self deleteRange: [self selectedRange] backspace: YES]; return; #if 1 - case 0x6d: // end-key: debugging: enforce complete re-layout + case 0x6d: // end-key: debugging: enforce complete re-layout [lineLayoutInformation autorelease]; lineLayoutInformation=nil; - [self rebuildLineLayoutInformationStartingAtLine:0]; - [self setNeedsDisplay:YES]; + [self rebuildLineLayoutInformationStartingAtLine: 0]; + [self setNeedsDisplay: YES]; return; #endif #if 1 - case 0x45: // num-lock: debugging + case 0x45: // num-lock: debugging NSLog([lineLayoutInformation description]); return; #endif - case NSCarriageReturnKey: // return - if([self isFieldEditor]) //textShouldEndEditing delegation is handled in resignFirstResponder + case NSCarriageReturnKey: // return + if ([self isFieldEditor]) //textShouldEndEditing delegation is handled in resignFirstResponder { NSLog(@"isFieldEditor return\n"); #if 0 // Movement codes for movement between fields; these codes are the intValue of the NSTextMovement key in NSTextDidEndEditing notifications - [NSNumber numberWithInt:NSIllegalTextMovement] - [NSNumber numberWithInt:NSReturnTextMovement] - [NSNumber numberWithInt:NSTabTextMovement] - [NSNumber numberWithInt:NSBacktabTextMovement] - [NSNumber numberWithInt:NSLeftTextMovement] - [NSNumber numberWithInt:NSRightTextMovement] - [NSNumber numberWithInt:NSUpTextMovement] - [NSNumber numberWithInt:NSDownTextMovement] + [NSNumber numberWithInt: NSIllegalTextMovement] + [NSNumber numberWithInt: NSReturnTextMovement] + [NSNumber numberWithInt: NSTabTextMovement] + [NSNumber numberWithInt: NSBacktabTextMovement] + [NSNumber numberWithInt: NSLeftTextMovement] + [NSNumber numberWithInt: NSRightTextMovement] + [NSNumber numberWithInt: NSUpTextMovement] + [NSNumber numberWithInt: NSDownTextMovement] #endif - [[self window] makeFirstResponder:[self nextResponder]]; - [self textDidEndEditing:[NSNotification notificationWithName:NSTextDidEndEditingNotification object:self - userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSReturnTextMovement],@"NSTextMovement",nil]]]; + [[self window] makeFirstResponder: [self nextResponder]]; + [self textDidEndEditing: [NSNotification notificationWithName: NSTextDidEndEditingNotification object: self + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: NSReturnTextMovement],@"NSTextMovement",nil]]]; } else { NSLog(@"\bCarriage return.\b\n"); - [self insertText:[[self class] newlineString]]; + [self insertText: [[self class] newlineString]]; return; } break; /* fixme */ - case 0x09: + case 0x09: if ([self isFieldEditor]) { - [[self window] makeFirstResponder:[self nextResponder]]; - [self textDidEndEditing:[NSNotification -notificationWithName:NSTextDidEndEditingNotification object:self - userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSTabTextMovement],@"NSTextMovement",nil]]]; + [[self window] makeFirstResponder: [self nextResponder]]; + [self textDidEndEditing: [NSNotification +notificationWithName: NSTextDidEndEditingNotification object: self + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt: NSTabTextMovement],@"NSTextMovement",nil]]]; break; } /* fixme */ } #if 0 -NSLog(@"keycode:%x",keyCode); +NSLog(@"keycode: %x",keyCode); #endif { // else - [self insertText:[theEvent characters]]; + [self insertText: [theEvent characters]]; } } @@ -1517,44 +1583,46 @@ NSLog(@"keycode:%x",keyCode); } -(BOOL) resignFirstResponder -{ if([self shouldDrawInsertionPoint]) +{ if ([self shouldDrawInsertionPoint]) { // [self lockFocus]; - [self drawInsertionPointAtIndex:[self selectedRange].location color:nil turnedOn:NO]; + [self drawInsertionPointAtIndex: [self selectedRange].location color: nil turnedOn: NO]; // [self unlockFocus]; // stop timed entry } - if([self isEditable]) return [self textShouldEndEditing:(NSText*)self]; + if ([self isEditable]) return [self textShouldEndEditing: (NSText*)self]; return YES; } -(BOOL) becomeFirstResponder { -// if([self shouldDrawInsertionPoint]) +// if ([self shouldDrawInsertionPoint]) // { // [self lockFocus]; -// [self drawInsertionPointAtIndex:[self selectedRange].location color:[NSColor blackColor] turnedOn:YES]; +// [self drawInsertionPointAtIndex: [self selectedRange].location color: [NSColor blackColor] turnedOn: YES]; // [self unlockFocus]; // // restart timed entry // } - if([self isEditable] && [self textShouldBeginEditing:(NSText*)self]) return YES; + if ([self isEditable] && [self textShouldBeginEditing: (NSText*)self]) return YES; else return NO; } -// -// Managing the Delegate -// -- delegate { return delegate; } +/* + * Managing the Delegate + */ +- (id) delegate +{ + return delegate; +} --(void) setDelegate:anObject +- (void) setDelegate: (id)anObject { NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; if (delegate) [nc removeObserver: delegate name: nil object: self]; ASSIGN(delegate, anObject); -// delegate = anObject; #define SET_DELEGATE_NOTIFICATION(notif_name) \ if ([delegate respondsToSelector: @selector(text##notif_name:)]) \ @@ -1568,76 +1636,76 @@ NSLog(@"keycode:%x",keyCode); SET_DELEGATE_NOTIFICATION(DidEndEditing); } -// -// Implemented by the Delegate -// +/* + * Implemented by the Delegate + */ --(void) textDidBeginEditing:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidBeginEditing:)]) - [delegate textDidBeginEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidBeginEditingNotification object:self]]; +- (void) textDidBeginEditing: (NSNotification *)aNotification +{ if ([delegate respondsToSelector: @selector(textDidBeginEditing: )]) + [delegate textDidBeginEditing: aNotification? aNotification: [NSNotification notificationWithName: NSTextDidBeginEditingNotification object: self]]; - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidBeginEditingNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidBeginEditingNotification object: self]; } -- (void)textDidChange:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidChange:)]) - [delegate textDidChange:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidChangeNotification object:self]]; +- (void)textDidChange: (NSNotification *)aNotification +{ if ([delegate respondsToSelector: @selector(textDidChange: )]) + [delegate textDidChange: aNotification? aNotification: [NSNotification notificationWithName: NSTextDidChangeNotification object: self]]; - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidChangeNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidChangeNotification object: self]; } --(void)textDidEndEditing:(NSNotification *)aNotification -{ if ([delegate respondsToSelector:@selector(textDidEndEditing:)]) - [delegate textDidEndEditing:aNotification? aNotification:[NSNotification notificationWithName:NSTextDidEndEditingNotification object:self]]; +-(void)textDidEndEditing: (NSNotification *)aNotification +{ if ([delegate respondsToSelector: @selector(textDidEndEditing: )]) + [delegate textDidEndEditing: aNotification? aNotification: [NSNotification notificationWithName: NSTextDidEndEditingNotification object: self]]; - [[NSNotificationCenter defaultCenter] postNotificationName:NSTextDidEndEditingNotification object:self]; + [[NSNotificationCenter defaultCenter] postNotificationName: NSTextDidEndEditingNotification object: self]; } --(BOOL) textShouldBeginEditing:(NSText *)textObject -{ if ([delegate respondsToSelector:@selector(textShouldBeginEditing:)]) - return [delegate textShouldBeginEditing:(NSText*)self]; +-(BOOL) textShouldBeginEditing: (NSText *)textObject +{ if ([delegate respondsToSelector: @selector(textShouldBeginEditing: )]) + return [delegate textShouldBeginEditing: (NSText*)self]; else return YES; } --(BOOL) textShouldEndEditing:(NSText *)textObject -{ if ([delegate respondsToSelector:@selector(textShouldEndEditing:)]) - return [delegate textShouldEndEditing:(NSText*)self]; +-(BOOL) textShouldEndEditing: (NSText *)textObject +{ if ([delegate respondsToSelector: @selector(textShouldEndEditing: )]) + return [delegate textShouldEndEditing: (NSText*)self]; else return YES; } --(NSRange) characterRangeForBoundingRect:(NSRect)boundsRect -{ NSRange lineRange=[self lineRangeForRect:boundsRect]; - if(lineRange.length) return MakeRangeFromAbs([[lineLayoutInformation objectAtIndex:lineRange.location] lineRange].location, - NSMaxRange([[lineLayoutInformation objectAtIndex:NSMaxRange(lineRange)] lineRange])); +-(NSRange) characterRangeForBoundingRect: (NSRect)boundsRect +{ NSRange lineRange=[self lineRangeForRect: boundsRect]; + if (lineRange.length) return MakeRangeFromAbs([[lineLayoutInformation objectAtIndex: lineRange.location] lineRange].location, + NSMaxRange([[lineLayoutInformation objectAtIndex: NSMaxRange(lineRange)] lineRange])); else return NSMakeRange(0,0); } --(unsigned) characterIndexForPoint:(NSPoint)point +-(unsigned) characterIndexForPoint: (NSPoint)point { int i; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; NSDictionary *attributes=[self defaultTypingAttributes]; - if(point.y >= NSMaxY([[lineLayoutInformation lastObject] lineRect])) return [self textLength]; + if (point.y >= NSMaxY([[lineLayoutInformation lastObject] lineRect])) return [self textLength]; point.x=MAX(0,point.x); point.y=MAX(0,point.y); for(i=0,(lineEnum=[lineLayoutInformation objectEnumerator]);(currentInfo=[lineEnum nextObject]);i++) { NSRect rect=[currentInfo lineRect]; - if(NSMaxY(rect)>=point.y && rect.origin.y= NSMaxX(rect) ) return NSMaxRange([currentInfo lineRange]); - if(NSPointInRect(point,rect)) // this loop holds some optimization potential (linear search) + if (NSMaxY(rect)>=point.y && rect.origin.y= NSMaxX(rect) ) return NSMaxRange([currentInfo lineRange]); + if (NSPointInRect(point,rect)) // this loop holds some optimization potential (linear search) { int retPos=0; NSRange range=[currentInfo lineRange]; for(retPos=range.location; retPos<=NSMaxRange(range); retPos++) // this loop holds some optimization potential (linear search) { NSString *evalString=nil; - if([self isRichText]) - { if([rtfContent sizeRange:NSMakeRange(range.location,retPos-range.location)].width >= point.x) return MAX(0,retPos-1); + if ([self isRichText]) + { if ([rtfContent sizeRange: NSMakeRange(range.location,retPos-range.location)].width >= point.x) return MAX(0,retPos-1); } else - { evalString=[plainContent substringWithRange:NSMakeRange(range.location,retPos-range.location)]; - if([evalString sizeWithAttributes:attributes].width >= point.x) return MAX(0,retPos-1); + { evalString=[plainContent substringWithRange: NSMakeRange(range.location,retPos-range.location)]; + if ([evalString sizeWithAttributes: attributes].width >= point.x) return MAX(0,retPos-1); } } return range.location; } @@ -1646,17 +1714,17 @@ NSLog(@"keycode:%x",keyCode); } // rect to the end of line --(NSRect) rectForCharacterIndex:(unsigned) index +-(NSRect) rectForCharacterIndex: (unsigned) index { int i; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; NSDictionary *attributes=[self defaultTypingAttributes]; - if(![lineLayoutInformation count]) return NSMakeRect(0,0,[self frame].size.width,[[[self class] newlineString] sizeWithAttributes:attributes].height); + if (![lineLayoutInformation count]) return NSMakeRect(0,0,[self frame].size.width,[[[self class] newlineString] sizeWithAttributes: attributes].height); - if(index >= NSMaxRange([[lineLayoutInformation lastObject] lineRange])) + if (index >= NSMaxRange([[lineLayoutInformation lastObject] lineRange])) { NSRect rect=[[lineLayoutInformation lastObject] lineRect]; - if(NSMaxX(rect)>= [self frame].size.width) + if (NSMaxX(rect)>= [self frame].size.width) { return NSMakeRect(0, NSMaxY(rect),[self frame].size.width,rect.size.height); } return NSMakeRect(NSMaxX(rect), rect.origin.y,[self frame].size.width-NSMaxX(rect),rect.size.height); @@ -1664,15 +1732,15 @@ NSLog(@"keycode:%x",keyCode); for(i=0,(lineEnum=[lineLayoutInformation objectEnumerator]);(currentInfo=[lineEnum nextObject]);i++) { NSRange range=[currentInfo lineRange]; - if(NSLocationInRange(index,range)) + if (NSLocationInRange(index,range)) { NSRect rect=[currentInfo lineRect]; - if([self isRichText]) - { NSSize stringSize=[rtfContent sizeRange:MakeRangeFromAbs(range.location,index)]; + if ([self isRichText]) + { NSSize stringSize=[rtfContent sizeRange: MakeRangeFromAbs(range.location,index)]; float x=rect.origin.x+stringSize.width; return NSMakeRect(x,rect.origin.y,NSMaxX(rect)-x,rect.size.height); } else - { NSString *evalString=[plainContent substringWithRange:MakeRangeFromAbs(range.location,index)]; - NSSize stringSize=[evalString sizeWithAttributes:attributes]; + { NSString *evalString=[plainContent substringWithRange: MakeRangeFromAbs(range.location,index)]; + NSSize stringSize=[evalString sizeWithAttributes: attributes]; float x=rect.origin.x+stringSize.width; return NSMakeRect(x,rect.origin.y,NSMaxX(rect)-x,rect.size.height); } @@ -1681,44 +1749,44 @@ NSLog(@"keycode:%x",keyCode); return NSZeroRect; } --(unsigned) lineLayoutIndexForPoint:(NSPoint)point +-(unsigned) lineLayoutIndexForPoint: (NSPoint)point { int i; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; NSDictionary *attributes=[self defaultTypingAttributes]; - if(point.y >= NSMaxY([[lineLayoutInformation lastObject] lineRect])) return [lineLayoutInformation count]-1; + if (point.y >= NSMaxY([[lineLayoutInformation lastObject] lineRect])) return [lineLayoutInformation count]-1; point.x=MAX(0,point.x); point.y=MAX(0,point.y); for(i=0,(lineEnum=[lineLayoutInformation objectEnumerator]); (currentInfo=[lineEnum nextObject]);i++) { NSRect rect=[currentInfo lineRect]; - if(NSMaxY(rect)> point.y && rect.origin.y<= point.y && rect.origin.x< point.x && point.x >= NSMaxX(rect) ) - return [lineLayoutInformation indexOfObject:currentInfo]; - if(NSPointInRect(point,rect)) // this loop holds some optimization potential (linear search) + if (NSMaxY(rect)> point.y && rect.origin.y<= point.y && rect.origin.x< point.x && point.x >= NSMaxX(rect) ) + return [lineLayoutInformation indexOfObject: currentInfo]; + if (NSPointInRect(point,rect)) // this loop holds some optimization potential (linear search) { int retPos=0; NSRange range=[currentInfo lineRange]; for(retPos=range.location; retPos<=NSMaxRange(range); retPos++) // this loop holds some optimization potential (linear search) { NSString *evalString=nil; - if([self isRichText]) - { if([rtfContent sizeRange:NSMakeRange(range.location,retPos-range.location)].width >= point.x) - return [lineLayoutInformation indexOfObject:currentInfo]; + if ([self isRichText]) + { if ([rtfContent sizeRange: NSMakeRange(range.location,retPos-range.location)].width >= point.x) + return [lineLayoutInformation indexOfObject: currentInfo]; } else - { evalString=[plainContent substringWithRange:NSMakeRange(range.location,retPos-range.location)]; - if([evalString sizeWithAttributes:attributes].width >= point.x) return [lineLayoutInformation indexOfObject:currentInfo]; + { evalString=[plainContent substringWithRange: NSMakeRange(range.location,retPos-range.location)]; + if ([evalString sizeWithAttributes: attributes].width >= point.x) return [lineLayoutInformation indexOfObject: currentInfo]; } - } return [lineLayoutInformation indexOfObject:currentInfo]; + } return [lineLayoutInformation indexOfObject: currentInfo]; } } return 0; } // internal method range is currently not passed as absolute --(void) addNewlines:(NSRange) aRange intoLayoutArray:(NSMutableArray*) anArray attributes:(NSDictionary*) attributes atPoint:(NSPoint*) aPointP - width:(float) width characterIndex:(unsigned) startingLineCharIndex ghostEnumerator:(_GNUSeekableArrayEnumerator*) prevArrayEnum - didShift:(BOOL*) didShift verticalDisplacement:(float*) verticalDisplacement -{ NSSize advanceSize=[[[self class] newlineString] sizeWithAttributes:attributes]; +-(void) addNewlines: (NSRange) aRange intoLayoutArray: (NSMutableArray*) anArray attributes: (NSDictionary*) attributes atPoint: (NSPoint*) aPointP + width: (float) width characterIndex: (unsigned) startingLineCharIndex ghostEnumerator: (_GNUSeekableArrayEnumerator*) prevArrayEnum + didShift: (BOOL*) didShift verticalDisplacement: (float*) verticalDisplacement +{ NSSize advanceSize=[[[self class] newlineString] sizeWithAttributes: attributes]; int count=aRange.length,charIndex; _GNULineLayoutInfo *thisInfo,*ghostInfo=nil; BOOL isRich=[self isRichText]; @@ -1728,18 +1796,18 @@ NSLog(@"keycode:%x",keyCode); for(charIndex=aRange.location;--count>=0;charIndex++) { NSRect currentLineRect; - if(0&& isRich) - { advanceSize=[rtfContent sizeRange:NSMakeRange(startingLineCharIndex,1)]; + if (0&& isRich) + { advanceSize=[rtfContent sizeRange: NSMakeRange(startingLineCharIndex,1)]; } currentLineRect=NSMakeRect(aPointP->x,aPointP->y,width-aPointP->x,advanceSize.height); - [anArray addObject:thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: - NSMakeRange(startingLineCharIndex,1) rect:currentLineRect drawingOffset:0 type:LineLayoutInfoType_Paragraph]]; + [anArray addObject: thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: + NSMakeRange(startingLineCharIndex,1) rect: currentLineRect drawingOffset: 0 type: LineLayoutInfoType_Paragraph]]; startingLineCharIndex++; aPointP->x=0; aPointP->y+= advanceSize.height; - if(prevArrayEnum && !(ghostInfo=[prevArrayEnum nextObject])) prevArrayEnum=nil; + if (prevArrayEnum && !(ghostInfo=[prevArrayEnum nextObject])) prevArrayEnum=nil; - if(ghostInfo && ([thisInfo type] != [ghostInfo type])) + if (ghostInfo && ([thisInfo type] != [ghostInfo type])) { _GNULineLayoutInfo *prevInfo=[prevArrayEnum previousObject]; prevArrayEnum=nil; (*didShift)=YES; @@ -1751,30 +1819,30 @@ NSLog(@"keycode:%x",keyCode); // private helper function static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray *ghostArray,int aLine,int relocOffset,int rebuildLineDrift,float yReloc) { unsigned ret=[lineLayoutInformation count]-aLine; // lines actually updated (optimized drawing) - NSArray *relocArray=[ghostArray subarrayWithRange:MakeRangeFromAbs(MAX(0,ret+rebuildLineDrift),[ghostArray count])]; + NSArray *relocArray=[ghostArray subarrayWithRange: MakeRangeFromAbs(MAX(0,ret+rebuildLineDrift),[ghostArray count])]; NSEnumerator *relocEnum; _GNULineLayoutInfo *currReloc; - if(![relocArray count]) return ret; + if (![relocArray count]) return ret; for((relocEnum=[relocArray objectEnumerator]); (currReloc=[relocEnum nextObject]);) { NSRange range=[currReloc lineRange]; - [currReloc setLineRange:NSMakeRange(range.location+relocOffset,range.length)]; - if(yReloc) + [currReloc setLineRange: NSMakeRange(range.location+relocOffset,range.length)]; + if (yReloc) { NSRect rect=[currReloc lineRect]; - [currReloc setLineRect:NSMakeRect(rect.origin.x,rect.origin.y+yReloc,rect.size.width,rect.size.height)]; + [currReloc setLineRect: NSMakeRect(rect.origin.x,rect.origin.y+yReloc,rect.size.width,rect.size.height)]; } } - [lineLayoutInformation addObjectsFromArray:relocArray]; + [lineLayoutInformation addObjectsFromArray: relocArray]; return ret; } // begin: central line formatting method --------------------------------------- // returns count of lines actually updated -// detachNewThreadSelector:selector toTarget:target withObject:argument; +// detachNewThreadSelector: selector toTarget: target withObject: argument; --(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine delta:(int) insertionDelta actualLine:(int) insertionLineIndex +-(int) rebuildLineLayoutInformationStartingAtLine: (int) aLine delta: (int) insertionDelta actualLine: (int) insertionLineIndex { NSDictionary *attributes=[self defaultTypingAttributes]; NSPoint drawingPoint=NSZeroPoint; _GNUTextScanner *parscanner; @@ -1792,34 +1860,34 @@ static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray float yDisplacement=0; BOOL isRich=[self isRichText]; - if(!lineLayoutInformation) lineLayoutInformation=[[NSMutableArray alloc] init]; + if (!lineLayoutInformation) lineLayoutInformation=[[NSMutableArray alloc] init]; else - { ghostArray=[lineLayoutInformation subarrayWithRange:NSMakeRange(aLine,[lineLayoutInformation count]-aLine)]; // remember old array for optimization purposes + { ghostArray=[lineLayoutInformation subarrayWithRange: NSMakeRange(aLine,[lineLayoutInformation count]-aLine)]; // remember old array for optimization purposes prevArrayEnum=[ghostArray seekableEnumerator]; // every time an object is added to lineLayoutInformation a nextObject has to be performed on prevArrayEnum! } - if(aLine) + if (aLine) { lastValidLineInfo=[lineLayoutInformation objectAtIndex: aLine-1]; drawingPoint=[lastValidLineInfo lineRect].origin; drawingPoint.y+=[lastValidLineInfo lineRect].size.height; startingIndex=NSMaxRange([lastValidLineInfo lineRange]); } - if([lastValidLineInfo type]== LineLayoutInfoType_Paragraph) + if ([lastValidLineInfo type]== LineLayoutInfoType_Paragraph) { drawingPoint.x=0; - } if((((int)[lineLayoutInformation count])-1) >= aLine) // keep paragraph-terminating space on same line as paragraph - { _GNULineLayoutInfo *anchorLine=[lineLayoutInformation objectAtIndex:aLine]; + } if ((((int)[lineLayoutInformation count])-1) >= aLine) // keep paragraph-terminating space on same line as paragraph + { _GNULineLayoutInfo *anchorLine=[lineLayoutInformation objectAtIndex: aLine]; NSRect anchorRect=[anchorLine lineRect]; - if(anchorRect.origin.x> drawingPoint.x && [lastValidLineInfo lineRect].origin.y == anchorRect.origin.y) + if (anchorRect.origin.x> drawingPoint.x && [lastValidLineInfo lineRect].origin.y == anchorRect.origin.y) { drawingPoint= anchorRect.origin; } } - [lineLayoutInformation removeObjectsInRange:NSMakeRange(aLine,[lineLayoutInformation count]-aLine)]; + [lineLayoutInformation removeObjectsInRange: NSMakeRange(aLine,[lineLayoutInformation count]-aLine)]; currentLineIndex=aLine; // each paragraph - for(parscanner=[_GNUTextScanner scannerWithString:parsedString=[[self string] substringFromIndex:startingIndex] - set:selectionParagraphGranularitySet invertedSet:invSelectionParagraphGranularitySet]; + for(parscanner=[_GNUTextScanner scannerWithString: parsedString=[[self string] substringFromIndex: startingIndex] + set: selectionParagraphGranularitySet invertedSet: invSelectionParagraphGranularitySet]; ![parscanner isAtEnd];) { _GNUTextScanner *linescanner; NSString *paragraph; @@ -1828,15 +1896,15 @@ static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray BOOL isBuckled=NO,inBuckling=NO; leadingNlRange=[parscanner scanSetCharacters]; - if(leadingNlRange.length) // add the leading newlines of current paragraph if any (only the first time) - { [self addNewlines:leadingNlRange intoLayoutArray:lineLayoutInformation attributes:attributes atPoint:&drawingPoint width:width - characterIndex:startingLineCharIndex ghostEnumerator:prevArrayEnum - didShift:&nlDidShift verticalDisplacement:&yDisplacement]; - if(nlDidShift) - { if(insertionDelta == 1) + if (leadingNlRange.length) // add the leading newlines of current paragraph if any (only the first time) + { [self addNewlines: leadingNlRange intoLayoutArray: lineLayoutInformation attributes: attributes atPoint: &drawingPoint width: width + characterIndex: startingLineCharIndex ghostEnumerator: prevArrayEnum + didShift: &nlDidShift verticalDisplacement: &yDisplacement]; + if (nlDidShift) + { if (insertionDelta == 1) { frameshiftCorrection=YES; rebuildLineDrift--; - } else if(insertionDelta == -1) + } else if (insertionDelta == -1) { frameshiftCorrection=YES; rebuildLineDrift++; } else nlDidShift=NO; @@ -1849,8 +1917,8 @@ static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray trailingNlRange=[parscanner scanSetCharacters]; // each line - for(linescanner=[_GNUTextScanner scannerWithString:paragraph=[parsedString substringWithRange:paragraphRange] - set:selectionWordGranularitySet invertedSet:invSelectionWordGranularitySet]; + for(linescanner=[_GNUTextScanner scannerWithString: paragraph=[parsedString substringWithRange: paragraphRange] + set: selectionWordGranularitySet invertedSet: invSelectionWordGranularitySet]; ![linescanner isAtEnd];) { NSRect currentLineRect=NSMakeRect(0,drawingPoint.y,0,0); unsigned localLineStartIndex=[linescanner scanLocation]; // starts with zero, do not confuse with startingLineCharIndex @@ -1866,27 +1934,27 @@ static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray currentStringRange= [linescanner scanNonSetCharacters]; trailingSpacesRange=[linescanner scanSetCharacters]; if (leadingSpacesRange.length) currentStringRange=NSUnionRange (leadingSpacesRange,currentStringRange); - if(trailingSpacesRange.length) currentStringRange=NSUnionRange(trailingSpacesRange,currentStringRange); + if (trailingSpacesRange.length) currentStringRange=NSUnionRange(trailingSpacesRange,currentStringRange); // evaluate size of current word and line so far - if(isRich) advanceSize=[rtfContent sizeRange:NSMakeRange(currentStringRange.location+paragraphRange.location+startingIndex,currentStringRange.length)]; - else advanceSize=[[paragraph substringWithRange:currentStringRange] sizeWithAttributes:attributes]; + if (isRich) advanceSize=[rtfContent sizeRange: NSMakeRange(currentStringRange.location+paragraphRange.location+startingIndex,currentStringRange.length)]; + else advanceSize=[[paragraph substringWithRange: currentStringRange] sizeWithAttributes: attributes]; currentLineRect=NSUnionRect(currentLineRect,NSMakeRect(drawingPoint.x,drawingPoint.y, advanceSize.width, advanceSize.height)); // handle case where single word is broader than width (buckle word) unfinished and untested for richText (absolute position see above) - if(!isHorizontallyResizable && advanceSize.width >= width) - { if(isBuckled) + if (!isHorizontallyResizable && advanceSize.width >= width) + { if (isBuckled) { NSSize currentSize=NSMakeSize(HUGE,0); unsigned lastVisibleCharIndex; for(lastVisibleCharIndex=startingLineCharIndex+currentStringRange.length; currentSize.width>= width && lastVisibleCharIndex> startingLineCharIndex; lastVisibleCharIndex--) - { if(isRich) - { currentSize=[rtfContent sizeRange:MakeRangeFromAbs(startingLineCharIndex,lastVisibleCharIndex)]; + { if (isRich) + { currentSize=[rtfContent sizeRange: MakeRangeFromAbs(startingLineCharIndex,lastVisibleCharIndex)]; } else - { NSString *evalString=[plainContent substringWithRange:MakeRangeFromAbs(startingLineCharIndex,lastVisibleCharIndex)]; - currentSize=[evalString sizeWithAttributes:attributes]; + { NSString *evalString=[plainContent substringWithRange: MakeRangeFromAbs(startingLineCharIndex,lastVisibleCharIndex)]; + currentSize=[evalString sizeWithAttributes: attributes]; } } isBuckled=NO; inBuckling=YES; @@ -1899,31 +1967,31 @@ static unsigned _relocLayoutArray(NSMutableArray *lineLayoutInformation,NSArray } // end of line-> word wrap - if(!isHorizontallyResizable && (currentLineRect.size.width >= width || isBuckled)) // >= :wichtig för abknicken (isBuckled) + if (!isHorizontallyResizable && (currentLineRect.size.width >= width || isBuckled)) // >= : wichtig för abknicken (isBuckled) { _GNULineLayoutInfo *ghostInfo=nil,*thisInfo; - [linescanner setScanLocation:scannerPosition]; // undo layout of last word + [linescanner setScanLocation: scannerPosition]; // undo layout of last word currentLineRect.origin.x=0; currentLineRect.origin.y=drawingPoint.y; drawingPoint.y+= currentLineRect.size.height; drawingPoint.x=0; - [lineLayoutInformation addObject:thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: + [lineLayoutInformation addObject: thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: NSMakeRange(startingLineCharIndex,scannerPosition-localLineStartIndex) - rect:currentLineRect drawingOffset:0 type:LineLayoutInfoType_Text]]; + rect: currentLineRect drawingOffset: 0 type: LineLayoutInfoType_Text]]; currentLineIndex++; startingLineCharIndex=NSMaxRange([thisInfo lineRange]); - if(prevArrayEnum && !(ghostInfo=[prevArrayEnum nextObject])) prevArrayEnum=nil; + if (prevArrayEnum && !(ghostInfo=[prevArrayEnum nextObject])) prevArrayEnum=nil; // optimization stuff (do relayout only as much lines as necessary and patch the rest) --------- - if(ghostInfo) - { if([ghostInfo type] != [thisInfo type]) // frameshift correction + if (ghostInfo) + { if ([ghostInfo type] != [thisInfo type]) // frameshift correction { frameshiftCorrection=YES; - if(insertionDelta == -1) // deletition of newline + if (insertionDelta == -1) // deletition of newline { _GNULineLayoutInfo *nextObject; - if(!(nextObject=[prevArrayEnum nextObject])) prevArrayEnum=nil; + if (!(nextObject=[prevArrayEnum nextObject])) prevArrayEnum=nil; else - { if(nlDidShift && frameshiftCorrection) + { if (nlDidShift && frameshiftCorrection) {// frameshiftCorrection=NO; #if 0 NSLog(@"opti hook 1 (preferred)"); @@ -1938,17 +2006,17 @@ NSLog(@"opti hook 1 (preferred)"); } else lineDriftOffset+=([thisInfo lineRange].length-[ghostInfo lineRange].length); // is it possible to simply patch layout changes into layout array instead of doing a time consuming re-layout of the whole doc? - if((currentLineIndex-1 > insertionLineIndex && !inBuckling && !isBuckled) && + if ((currentLineIndex-1 > insertionLineIndex && !inBuckling && !isBuckled) && (!(lineDriftOffset-insertionDelta) || (nlDidShift && !lineDriftOffset) || enforceOpti)) { unsigned erg=_relocLayoutArray(lineLayoutInformation,ghostArray,aLine,insertionDelta, rebuildLineDrift, yDisplacement); - if(frameshiftCorrection) erg=[lineLayoutInformation count]-aLine; // y displacement: redisplay all remaining lines - else if(currentLineIndex-1 == insertionLineIndex && ABS(insertionDelta)== 1) + if (frameshiftCorrection) erg=[lineLayoutInformation count]-aLine; // y displacement: redisplay all remaining lines + else if (currentLineIndex-1 == insertionLineIndex && ABS(insertionDelta)== 1) { erg=2; // return 2: redisplay only this and previous line } #if 0 -NSLog(@"opti for:%d",erg); +NSLog(@"opti for: %d",erg); #endif return erg; } @@ -1957,33 +2025,33 @@ NSLog(@"opti for:%d",erg); break; // newline-induced premature lineending: flush - } else if([linescanner isAtEnd]) + } else if ([linescanner isAtEnd]) { _GNULineLayoutInfo *thisInfo; scannerPosition=[linescanner scanLocation]; - [lineLayoutInformation addObject:thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: + [lineLayoutInformation addObject: thisInfo=[_GNULineLayoutInfo lineLayoutWithRange: NSMakeRange(startingLineCharIndex,scannerPosition-localLineStartIndex) - rect:currentLineRect drawingOffset:0 type:LineLayoutInfoType_Text]]; + rect: currentLineRect drawingOffset: 0 type: LineLayoutInfoType_Text]]; currentLineIndex++; startingLineCharIndex=NSMaxRange([thisInfo lineRange]); // check for optimization (lines after paragraph are unchanged and do not need redisplay/relayout)------ - if(prevArrayEnum) + if (prevArrayEnum) { _GNULineLayoutInfo *ghostInfo=nil; ghostInfo=[prevArrayEnum nextObject]; - if(ghostInfo) - { if([ghostInfo type] != [thisInfo type]) // frameshift correction for inserted newline + if (ghostInfo) + { if ([ghostInfo type] != [thisInfo type]) // frameshift correction for inserted newline { frameshiftCorrection=YES; - if(insertionDelta == 1) + if (insertionDelta == 1) { [prevArrayEnum previousObject]; lineDriftOffset+=([thisInfo lineRange].length-[ghostInfo lineRange].length)+insertionDelta; rebuildLineDrift--; yDisplacement+= [thisInfo lineRect].origin.y-[ghostInfo lineRect].origin.y; - } else if(insertionDelta == -1) - { if(nlDidShift && frameshiftCorrection) + } else if (insertionDelta == -1) + { if (nlDidShift && frameshiftCorrection) {// frameshiftCorrection=NO; #if 0 NSLog(@"opti hook 2"); @@ -1997,15 +2065,15 @@ NSLog(@"opti hook 2"); } } } - if(trailingNlRange.length) // add the trailing newlines of current paragraph if any - { [self addNewlines:trailingNlRange intoLayoutArray:lineLayoutInformation attributes:attributes atPoint:&drawingPoint width:width - characterIndex:startingLineCharIndex ghostEnumerator:prevArrayEnum - didShift:&nlDidShift verticalDisplacement:&yDisplacement]; - if(nlDidShift) - { if(insertionDelta == 1) + if (trailingNlRange.length) // add the trailing newlines of current paragraph if any + { [self addNewlines: trailingNlRange intoLayoutArray: lineLayoutInformation attributes: attributes atPoint: &drawingPoint width: width + characterIndex: startingLineCharIndex ghostEnumerator: prevArrayEnum + didShift: &nlDidShift verticalDisplacement: &yDisplacement]; + if (nlDidShift) + { if (insertionDelta == 1) { frameshiftCorrection=YES; rebuildLineDrift--; - } else if(insertionDelta == -1) + } else if (insertionDelta == -1) { frameshiftCorrection=YES; rebuildLineDrift++; } else nlDidShift=NO; @@ -2018,50 +2086,50 @@ NSLog(@"opti hook 2"); } // end: central line formatting method ------------------------------------ --(int) rebuildLineLayoutInformationStartingAtLine:(int) aLine -{ return [self rebuildLineLayoutInformationStartingAtLine:aLine delta:0 actualLine:0]; +-(int) rebuildLineLayoutInformationStartingAtLine: (int) aLine +{ return [self rebuildLineLayoutInformationStartingAtLine: aLine delta: 0 actualLine: 0]; } // relies on lineLayoutInformation --(void) drawPlainLinesInLineRange:(NSRange) aRange -{ if(NSMaxRange(aRange) > MAX(0,[lineLayoutInformation count]-1)) // lay out lines before drawing them - { [self rebuildLineLayoutInformationStartingAtLine:MAX(0,[lineLayoutInformation count]-1)]; +-(void) drawPlainLinesInLineRange: (NSRange) aRange +{ if (NSMaxRange(aRange) > MAX(0,[lineLayoutInformation count]-1)) // lay out lines before drawing them + { [self rebuildLineLayoutInformationStartingAtLine: MAX(0,[lineLayoutInformation count]-1)]; } - { NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange:aRange]; + { NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange: aRange]; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; NSDictionary *attributes=[self defaultTypingAttributes]; for((lineEnum=[linesToDraw objectEnumerator]);(currentInfo=[lineEnum nextObject]);) - { if([currentInfo isDontDisplay] || [currentInfo type]== LineLayoutInfoType_Paragraph) continue; // e.g. for nl - [[plainContent substringWithRange:[currentInfo lineRange]] drawAtPoint:[currentInfo lineRect].origin withAttributes:attributes]; - // make this use drawInRect:withAttributes: in the future (for proper adoption of layout information [e.g. centering]) + { if ([currentInfo isDontDisplay] || [currentInfo type]== LineLayoutInfoType_Paragraph) continue; // e.g. for nl + [[plainContent substringWithRange: [currentInfo lineRange]] drawAtPoint: [currentInfo lineRect].origin withAttributes: attributes]; + // make this use drawInRect: withAttributes: in the future (for proper adoption of layout information [e.g. centering]) } } } --(void) drawRichLinesInLineRange:(NSRange) aRange -{ if(NSMaxRange(aRange) > [lineLayoutInformation count]-1) // lay out lines before drawing them - { [self rebuildLineLayoutInformationStartingAtLine:[lineLayoutInformation count]-1]; +-(void) drawRichLinesInLineRange: (NSRange) aRange +{ if (NSMaxRange(aRange) > [lineLayoutInformation count]-1) // lay out lines before drawing them + { [self rebuildLineLayoutInformationStartingAtLine: [lineLayoutInformation count]-1]; } - { NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange:aRange]; + { NSArray *linesToDraw=[lineLayoutInformation subarrayWithRange: aRange]; NSEnumerator *lineEnum; _GNULineLayoutInfo *currentInfo; for((lineEnum=[linesToDraw objectEnumerator]);(currentInfo=[lineEnum nextObject]);) - { if([currentInfo isDontDisplay] || [currentInfo type] == LineLayoutInfoType_Paragraph) continue; // e.g. for nl - [rtfContent drawRange:[currentInfo lineRange] atPoint:[currentInfo lineRect].origin]; + { if ([currentInfo isDontDisplay] || [currentInfo type] == LineLayoutInfoType_Paragraph) continue; // e.g. for nl + [rtfContent drawRange: [currentInfo lineRange] atPoint: [currentInfo lineRect].origin]; // make this use drawRange: inRect: in the future (for proper adoption of layout information [e.g. centering]) } } } --(NSRange) lineRangeForRect:(NSRect) rect +-(NSRange) lineRangeForRect: (NSRect) rect { NSPoint upperLeftPoint=rect.origin, lowerRightPoint=NSMakePoint(NSMaxX(rect),NSMaxY(rect)); NSRange myTest; unsigned startLine,endLine; - startLine=[self lineLayoutIndexForPoint:upperLeftPoint], - endLine=[self lineLayoutIndexForPoint:lowerRightPoint]; + startLine=[self lineLayoutIndexForPoint: upperLeftPoint], + endLine=[self lineLayoutIndexForPoint: lowerRightPoint]; //FIXME return MakeRangeFromAbs(startLine,endLine+1); if ([plainContent length] != 0) { myTest = MakeRangeFromAbs(startLine,endLine+1); @@ -2078,31 +2146,31 @@ NSLog(@"opti hook 2"); } } --(void) drawRectNoSelection:(NSRect)rect +-(void) drawRectNoSelection: (NSRect)rect { NSRange redrawLineRange; - if(![lineLayoutInformation count]) // bootstrap layout information for [self lineLayoutIndexForCharacterIndex:anIndex] to work initially - { [self rebuildLineLayoutInformationStartingAtLine:0]; + if (![lineLayoutInformation count]) // bootstrap layout information for [self lineLayoutIndexForCharacterIndex: anIndex] to work initially + { [self rebuildLineLayoutInformationStartingAtLine: 0]; } - redrawLineRange=[self lineRangeForRect:rect]; + redrawLineRange=[self lineRangeForRect: rect]; - if([self drawsBackground]) // clear area under text + if ([self drawsBackground]) // clear area under text { [[self backgroundColor] set]; NSRectFill(rect); } - if([self isRichText]) - { [self drawRichLinesInLineRange:redrawLineRange]; + if ([self isRichText]) + { [self drawRichLinesInLineRange: redrawLineRange]; } else - { [self drawPlainLinesInLineRange:redrawLineRange]; + { [self drawPlainLinesInLineRange: redrawLineRange]; } } --(void) drawRect:(NSRect)rect -{ if(displayDisabled) return; +-(void) drawRect: (NSRect)rect +{ if (displayDisabled) return; - [self drawRectNoSelection:rect]; - [self drawSelectionAsRange:[self selectedRange]]; + [self drawRectNoSelection: rect]; + [self drawSelectionAsRange: [self selectedRange]]; } // text lays out from top to bottom @@ -2111,48 +2179,52 @@ NSLog(@"opti hook 2"); // // Copy and paste // --(void) copy:sender -{ NSMutableArray *types=[NSMutableArray arrayWithObjects:NSStringPboardType, nil]; +-(void) copy: sender +{ NSMutableArray *types=[NSMutableArray arrayWithObjects: NSStringPboardType, nil]; NSPasteboard *pboard=[NSPasteboard generalPasteboard]; - if([self isRichText]) [types addObject:NSRTFPboardType]; - if([self importsGraphics]) [types addObject:NSRTFDPboardType]; - [pboard declareTypes:types owner:self]; - [pboard setString:[[self string] substringWithRange:[self selectedRange]] forType:NSStringPboardType]; - if([self isRichText]) [pboard setData:[self RTFFromRange:[self selectedRange]] forType:NSRTFPboardType]; - if([self importsGraphics]) [pboard setData:[self RTFDFromRange:[self selectedRange]] forType:NSRTFDPboardType]; + if ([self isRichText]) [types addObject: NSRTFPboardType]; + if ([self importsGraphics]) [types addObject: NSRTFDPboardType]; + [pboard declareTypes: types owner: self]; + [pboard setString: [[self string] substringWithRange: [self selectedRange]] forType: NSStringPboardType]; + if ([self isRichText]) [pboard setData: [self RTFFromRange: [self selectedRange]] forType: NSRTFPboardType]; + if ([self importsGraphics]) [pboard setData: [self RTFDFromRange: [self selectedRange]] forType: NSRTFDPboardType]; } // --(void) copyFont:sender +-(void) copyFont: sender { } // --(void) copyRuler:sender +-(void) copyRuler: sender { } --(void) delete:sender -{ [self deleteRange:[self selectedRange] backspace:NO]; +-(void) delete: sender +{ [self deleteRange: [self selectedRange] backspace: NO]; } --(void) cut:sender -{ if([self selectedRange].length) - { [self copy:self]; - [self delete:self]; +-(void) cut: sender +{ if ([self selectedRange].length) + { [self copy: self]; + [self delete: self]; } } --(void) paste:sender -{ [self performPasteOperation:[NSPasteboard generalPasteboard]]; +- (void) paste: sender +{ + [self performPasteOperation: [NSPasteboard generalPasteboard]]; } --(void) pasteFont:sender -{ [self performPasteOperation:[NSPasteboard pasteboardWithName:NSFontPboard]]; +- (void) pasteFont: sender +{ + [self performPasteOperation: [NSPasteboard pasteboardWithName: NSFontPboard]]; } --(void) pasteRuler:sender -{ [self performPasteOperation:[NSPasteboard pasteboardWithName:NSRulerPboard]]; +- (void) pasteRuler: sender +{ + [self performPasteOperation: + [NSPasteboard pasteboardWithName: NSRulerPboard]]; } @@ -2161,10 +2233,10 @@ NSLog(@"opti hook 2"); // // NSCoding protocol // -- (void)encodeWithCoder:aCoder -{ [super encodeWithCoder:aCoder]; +- (void)encodeWithCoder: aCoder +{ [super encodeWithCoder: aCoder]; - [aCoder encodeConditionalObject:delegate]; + [aCoder encodeConditionalObject: delegate]; [aCoder encodeObject: plainContent]; [aCoder encodeObject: rtfContent]; @@ -2185,8 +2257,8 @@ NSLog(@"opti hook 2"); [aCoder encodeValueOfObjCType: @encode(NSRange) at: &selected_range]; } -- initWithCoder:aDecoder -{ [super initWithCoder:aDecoder]; +- initWithCoder: aDecoder +{ [super initWithCoder: aDecoder]; delegate = [aDecoder decodeObject]; @@ -2215,34 +2287,34 @@ NSLog(@"opti hook 2"); // Spelling // --(void) checkSpelling:sender -{ NSRange errorRange=[[NSSpellChecker sharedSpellChecker] checkSpellingOfString:[self string] startingAt:NSMaxRange([self selectedRange])]; - if(errorRange.length) [self setSelectedRange:errorRange]; +-(void) checkSpelling: sender +{ NSRange errorRange=[[NSSpellChecker sharedSpellChecker] checkSpellingOfString: [self string] startingAt: NSMaxRange([self selectedRange])]; + if (errorRange.length) [self setSelectedRange: errorRange]; else NSBeep(); } --(void) showGuessPanel:sender -{ [[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront:self]; +-(void) showGuessPanel: sender +{ [[[NSSpellChecker sharedSpellChecker] spellingPanel] orderFront: self]; } // // NSChangeSpelling protocol // --(void) changeSpelling:sender -{ [self insertText:[[(NSControl*)sender selectedCell] stringValue]]; +-(void) changeSpelling: sender +{ [self insertText: [[(NSControl*)sender selectedCell] stringValue]]; } -(int) spellCheckerDocumentTag -{ if(!spellCheckerDocumentTag) spellCheckerDocumentTag=[NSSpellChecker uniqueSpellDocumentTag]; +{ if (!spellCheckerDocumentTag) spellCheckerDocumentTag=[NSSpellChecker uniqueSpellDocumentTag]; return spellCheckerDocumentTag; } // // NSIgnoreMisspelledWords protocol // --(void) ignoreSpelling:sender -{ [[NSSpellChecker sharedSpellChecker] ignoreWord:[[(NSControl*)sender selectedCell] stringValue] inSpellDocumentWithTag:[self spellCheckerDocumentTag]]; +-(void) ignoreSpelling: sender +{ [[NSSpellChecker sharedSpellChecker] ignoreWord: [[(NSControl*)sender selectedCell] stringValue] inSpellDocumentWithTag: [self spellCheckerDocumentTag]]; } @end