Re: Weird bug with selection in Textview with custom textcontainer [solved]
Re: Weird bug with selection in Textview with custom textcontainer [solved]
- Subject: Re: Weird bug with selection in Textview with custom textcontainer [solved]
- From: Alexander Griekspoor <email@hidden>
- Date: Sun, 23 Apr 2006 17:15:40 +0200
Dear listmembers,
For the archives I post here the workaround for the selection problem
with my custom textview. It turns out that under fairly specific
circumstances the layoutmanager returns wrong indices for an NSPoint.
Many thanks to Doug Davidson for helping to find a solution.
Cheers,
Alex
#import "KDLayoutManager.h"
#define COLUMN_WIDTH 10
@implementation KDLayoutManager
- (unsigned)glyphIndexForPoint:(NSPoint)aPoint inTextContainer:
(NSTextContainer *)aTextContainer fractionOfDistanceThroughGlyph:
(float *)partialFraction{
unsigned idx = [super glyphIndexForPoint: aPoint
inTextContainer: aTextContainer
fractionOfDistanceThroughGlyph: partialFraction];
// because of a bug in this method we check by hand if wrong value
is given
if(idx == COLUMN_WIDTH && !NSPointInRect(aPoint, [self
boundingRectForGlyphRange: NSMakeRange(COLUMN_WIDTH,1)
inTextContainer: aTextContainer])){
int i;
for (i=0; i<COLUMN_WIDTH; i++){
NSRect glyphRect = [self boundingRectForGlyphRange: NSMakeRange(i,
1) inTextContainer: aTextContainer];
if(NSPointInRect(aPoint, glyphRect)){
//calculate fraction
if (partialFraction) *partialFraction = (aPoint.x - NSMinX
(glyphRect)) / NSWidth(glyphRect);
return i;
}
}
// if not found, check whether before or after
if(aPoint.x < NSMinX([self boundingRectForGlyphRange: NSMakeRange
(0,1) inTextContainer: aTextContainer])) {
if (partialFraction) *partialFraction = 0.0;
return 0;
}
else {
if (partialFraction) *partialFraction = 1.0;
return COLUMN_WIDTH;
}
}
return idx;
}
@end
***********************************
Mek (Alexander Griekspoor)
MekenTosj.com
Web: http://www.mekentosj.com
Mail: email@hidden
***********************************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden