From 701853d4079727924c362ccd2e2ecc8ae466cb8d Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 27 Feb 2007 06:07:01 +0000 Subject: [PATCH] bugfix for #13564 git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24697 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 31 +++++++---- Source/NSLayoutManager.m | 115 +++++++++++++++++++++++++++++++++------ 2 files changed, 116 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index dc74817f0..2cc405d29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,16 @@ +2007-02-26 Richard Frith-Macdonald + + * Source/NSLayoutManager.m: ([drawGlyphsForGlyphRange:atPoint:]) + Implement selected text color ... use the value set in the textview + or if that is not supplied, fall back to selectedTextColor. + Fix ([drawBackgroundForGlyphRange:atPoint:]) to use + ([textViewForBeginningOfSelection]) to determine selected text color. + 2007-02-22 Matt Rice * Source/NSAlert.m (-_initWithoutGModel): Add missing nil at end of call to -dictionaryWithObjectsAndKeys: - 2007-02-22 Sergii Stoian * Source/NSWindow.m: (_lossOfKeyOrMainWindow): Add sanity checks. @@ -56,7 +63,7 @@ * Source/NSDocument.m (runModalSavePanel:withAccessoryView:): Only set accessory view when not nil. Workaround for bug #19031. -2007-02-16 Richard Frith-Macdoanld +2007-02-16 Richard Frith-Macdonald * Source/NSMenuItSemCell.m: fixup glitch with drawing of horizontal menu items overwriting menu border. @@ -177,7 +184,7 @@ * Source/NSTableView (-mouseDown:): Compute the selection immediately instead of at the end of the loop. -2007-02-04 Richard Frith-Macdoanld +2007-02-04 Richard Frith-Macdonald * Source/NSImageView.m: fix minor error in dragging offset. @@ -191,7 +198,7 @@ depending on whether the mouse went up inside the menu or not. Fixes bug #18946 -2007-01-31 Richard Frith-Macdoanld +2007-01-31 Richard Frith-Macdonald * Source/GSFontInfo.m: * Source/NSFont.m: @@ -251,7 +258,7 @@ * Source/GSTheme.m (-buttonBorderForStyle:state:, -drawButton:view:style:state:): Handle some of the bezel styles. -2007-01-24 Richard Frith-Macdoanld +2007-01-24 Richard Frith-Macdonald * Headers/AppKit/NSButtonCell.h: Fix documentation error. * Headers/AppKit/NSMenu.h: Tidy a litte, fix errors in documentation @@ -317,7 +324,7 @@ * Source/NSPopUpButton.m (-keyDown:): Handle selection of first entry correctly. Patch by Phillipe Roussel -2007-01-19 Richard Frith-Macdoanld +2007-01-19 Richard Frith-Macdonald * Source/NSDocument.m: fix include path (bug #18829) @@ -422,7 +429,7 @@ * Source/NSTableView.m (rectOfColumn:): Use the height of the rows, not the bounds. -2006-12-27 Richard Frith-Macdoanld +2006-12-27 Richard Frith-Macdonald * Headers/Additions/GNUstepGUI/GSTheme.h: Store images in dictionary. * Source/GSTheme.m: Improve handling of named images. @@ -470,7 +477,7 @@ * Source/NSBitmapImageRep.m: Autogsdoc comments -2006-12-08 Richard Frith-Macdoanld +2006-12-08 Richard Frith-Macdonald * Source/NSInputManager.m: Use help function key to enter context help mode rather than @@ -580,7 +587,7 @@ to moveForward: and moveBackward: -2006-11-19 Richard Frith-Macdoanld +2006-11-19 Richard Frith-Macdonald * Source/NSAffineTransform.m: * Headers/AppKit/NSAffineTransform.h: @@ -592,11 +599,11 @@ Update to use transformStruct accessor method rather than trying to work with the affine transform ivars directly. -2006-11-18 Richard Frith-Macdoanld +2006-11-18 Richard Frith-Macdonald * Source/NSScrollView.m: Adjust corner view when scroller is on right. -2006-11-17 Richard Frith-Macdoanld +2006-11-17 Richard Frith-Macdonald * Source/GSTheme.m: * Source/NSButtonCell.m: @@ -3857,7 +3864,7 @@ (-trackMouse:inRect:ofView:untilMouseUp:): ... to here. This fixes bug #9824. -2005-02-14 Richard Frith-Macdoanld +2005-02-14 Richard Frith-Macdonald * Source/GSTitleView.m (-mouseDown:): Post an NSWindowDidMoveNotification at end of method if window was dragged. diff --git a/Source/NSLayoutManager.m b/Source/NSLayoutManager.m index f1144f069..f1f7e7b9e 100644 --- a/Source/NSLayoutManager.m +++ b/Source/NSLayoutManager.m @@ -1214,8 +1214,8 @@ container if (!_selected_range.length || _selected_range.location == NSNotFound) return; - if (_selected_range.location >= char_pos || - _selected_range.location + _selected_range.length <= first_char_pos) + if (_selected_range.location >= char_pos + || _selected_range.location + _selected_range.length <= first_char_pos) { return; } @@ -1242,9 +1242,9 @@ container } /* Use the text view's selected text attributes */ - if ((ftv = [self firstTextView])) + if ((ftv = [self textViewForBeginningOfSelection])) color = [[ftv selectedTextAttributes] - objectForKey:NSBackgroundColorAttributeName]; + objectForKey: NSBackgroundColorAttributeName]; if (!color) color = [NSColor selectedTextBackgroundColor]; @@ -1288,7 +1288,9 @@ container NSDictionary *attributes; NSFont *f; - NSColor *color, *new_color; + NSColor *color, *run_color; + NSRange selectedGlyphRange; + BOOL currentGlyphIsSelected; glyph_run_t *glyph_run; unsigned int glyph_pos, char_pos; @@ -1303,6 +1305,7 @@ container cache in sync with the actual color. */ NSColor *defaultTextColor = [NSColor textColor]; + NSColor *selectedTextColor = defaultTextColor; #define GBUF_SIZE 16 /* TODO: tweak */ NSGlyph gbuf[GBUF_SIZE]; @@ -1315,6 +1318,21 @@ container return; [self _doLayoutToGlyph: range.location + range.length - 1]; + /* Find the selected range of glyphs as it overlaps with the range we + * are about to display. + */ + if (_selected_range.length == 0) + { + selectedGlyphRange.location = 0; + selectedGlyphRange.length = 0; + } + else + { + selectedGlyphRange = [self glyphRangeForCharacterRange: _selected_range + actualCharacterRange: 0]; + } + selectedGlyphRange = NSIntersectionRange(selectedGlyphRange, range); + if ([ctxt isDrawingToScreen]) gbuf_size = GBUF_SIZE; else @@ -1343,12 +1361,32 @@ container lp++, j++; glyph_run = run_for_glyph_index(lp->pos, glyphs, &glyph_pos, &char_pos); + currentGlyphIsSelected = NSLocationInRange(lp->pos, selectedGlyphRange); glyph = glyph_run->glyphs + lp->pos - glyph_pos; attributes = [_textStorage attributesAtIndex: char_pos - effectiveRange: NULL]; - color = [attributes valueForKey: NSForegroundColorAttributeName]; - if (!color) - color = defaultTextColor; + effectiveRange: NULL]; + run_color = [attributes valueForKey: NSForegroundColorAttributeName]; + if (run_color == nil) + run_color = defaultTextColor; + + if (selectedGlyphRange.length > 0) + { + /* Get the text view's color setting for selected text as we will + * be needing to draw some selected glyphs. + */ + selectedTextColor = [[[self textViewForBeginningOfSelection] + selectedTextAttributes] objectForKey: NSForegroundColorAttributeName]; + + /* FIXME ... should we fall back to using selectedTextColor or + * defaultTextColor? + */ + if (selectedTextColor == nil) + { + selectedTextColor = [NSColor selectedTextColor]; + } + } + + color = (currentGlyphIsSelected ? selectedTextColor : run_color); [color set]; f = glyph_run->font; [f set]; @@ -1359,6 +1397,39 @@ container gbuf_len = 0; for (g = lp->pos; g < range.location + range.length; g++, glyph++) { + if (currentGlyphIsSelected != NSLocationInRange(g, selectedGlyphRange)) + { + /* When we change between drawing selected and unselected glyphs + * we must flush any glyphs from the buffer and change trhe color + * we use for the text. + */ + if (gbuf_len) + { + DPSmoveto(ctxt, gbuf_point.x, gbuf_point.y); + GSShowGlyphs(ctxt, gbuf, gbuf_len); + DPSnewpath(ctxt); + gbuf_len = 0; + } + if (currentGlyphIsSelected == YES) + { + currentGlyphIsSelected = NO; + if (color != run_color) + { + color = run_color; + [color set]; + } + } + else + { + currentGlyphIsSelected = YES; + if (color != selectedTextColor) + { + color = selectedTextColor; + [color set]; + } + } + } + if (g == lp->pos + lp->length) { if (gbuf_len) @@ -1390,11 +1461,19 @@ container glyph_run = (glyph_run_t *)glyph_run->head.next; attributes = [_textStorage attributesAtIndex: char_pos effectiveRange: NULL]; - new_color = [attributes valueForKey: NSForegroundColorAttributeName]; - if (!new_color) - new_color = defaultTextColor; + run_color = [attributes valueForKey: NSForegroundColorAttributeName]; + if (run_color == nil) + { + run_color = defaultTextColor; + } glyph = glyph_run->glyphs; - if (glyph_run->font != f || new_color != color) + + /* If the font has changed or the color has changed (and we are + * not drawing using the selected text color) then we must flush + * any buffered glyphs and set the new font and color. + */ + if (glyph_run->font != f + || (currentGlyphIsSelected == NO && run_color != color)) { if (gbuf_len) { @@ -1403,16 +1482,16 @@ container DPSnewpath(ctxt); gbuf_len = 0; } - if (color != new_color) - { - color = new_color; - [color set]; - } if (f != glyph_run->font) { f = glyph_run->font; [f set]; } + if (currentGlyphIsSelected == NO && run_color != color) + { + color = run_color; + [color set]; + } } } if (!glyph->isNotShown && glyph->g && glyph->g != NSControlGlyph)