From: Bjorn Winckler Date: Sat, 3 Apr 2010 11:44:27 +0000 (+0200) Subject: Fix placement of auxiliary IM window for Core Text X-Git-Url: https://repo.or.cz/w/MacVim.git/commitdiff_plain/0c0a07ccf35fd95f2f7d747f03e4951709387b34 Fix placement of auxiliary IM window for Core Text --- diff --git a/src/MacVim/MMCoreTextView.h b/src/MacVim/MMCoreTextView.h index 338bfcd9..2423c3ef 100644 --- a/src/MacVim/MMCoreTextView.h +++ b/src/MacVim/MMCoreTextView.h @@ -73,6 +73,8 @@ - (void)setImControl:(BOOL)enable; - (void)activateIm:(BOOL)enable; - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column; +- (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr + numColumns:(int)nc; // // NSTextView methods diff --git a/src/MacVim/MMCoreTextView.m b/src/MacVim/MMCoreTextView.m index fd50b585..069e4c4e 100644 --- a/src/MacVim/MMCoreTextView.m +++ b/src/MacVim/MMCoreTextView.m @@ -63,8 +63,6 @@ @interface MMCoreTextView (Drawing) - (NSPoint)pointForRow:(int)row column:(int)column; -- (NSRect)rectForRow:(int)row column:(int)column numRows:(int)nr - numColumns:(int)nc; - (NSRect)rectFromRow:(int)row1 column:(int)col1 toRow:(int)row2 column:(int)col2; - (NSSize)textAreaSize; @@ -385,6 +383,7 @@ defaultAdvanceForFont(CTFontRef fontRef) - (void)setPreEditRow:(int)row column:(int)col { + [helper setPreEditRow:row column:col]; } - (void)setMouseShape:(int)shape @@ -743,9 +742,6 @@ defaultAdvanceForFont(CTFontRef fontRef) - (BOOL)convertPoint:(NSPoint)point toRow:(int *)row column:(int *)column { - // View is not flipped, instead the atsui code draws to a flipped image; - // thus we need to 'flip' the coordinate here since the column number - // increases in an up-to-down order. point.y = [self bounds].size.height - point.y; NSPoint origin = { insetSize.width, insetSize.height }; @@ -762,6 +758,24 @@ defaultAdvanceForFont(CTFontRef fontRef) return YES; } +- (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr + numColumns:(int)nc +{ + // Return the rect for the block which covers the specified rows and + // columns. The lower-left corner is the origin of this rect. + // NOTE: The coordinate system is _NOT_ flipped! + NSRect rect; + NSRect frame = [self bounds]; + + rect.origin.x = col*cellSize.width + insetSize.width; + rect.origin.y = frame.size.height - (row+nr)*cellSize.height - + insetSize.height; + rect.size.width = nc*cellSize.width; + rect.size.height = nr*cellSize.height; + + return rect; +} + - (NSArray *)validAttributesForMarkedText { return nil; @@ -827,21 +841,6 @@ defaultAdvanceForFont(CTFontRef fontRef) frame.size.height - (row+1)*cellSize.height - insetSize.height); } -- (NSRect)rectForRow:(int)row column:(int)col numRows:(int)nr - numColumns:(int)nc -{ - NSRect rect; - NSRect frame = [self bounds]; - - rect.origin.x = col*cellSize.width + insetSize.width; - rect.origin.y = frame.size.height - (row+nr)*cellSize.height - - insetSize.height; - rect.size.width = nc*cellSize.width; - rect.size.height = nr*cellSize.height; - - return rect; -} - - (NSRect)rectFromRow:(int)row1 column:(int)col1 toRow:(int)row2 column:(int)col2 { diff --git a/src/MacVim/MMTextViewHelper.m b/src/MacVim/MMTextViewHelper.m index fcd11066..ce7e2984 100644 --- a/src/MacVim/MMTextViewHelper.m +++ b/src/MacVim/MMTextViewHelper.m @@ -747,7 +747,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) // Vim by sending SetPreEditPositionMsgID so compute a position based on // the pre-edit (row,column) pair. int col = preEditColumn; - int row = preEditRow + 1; + int row = preEditRow; NSFont *theFont = [[textView markedTextAttributes] valueForKey:NSFontAttributeName]; @@ -771,6 +771,14 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b) numRows:1 numColumns:range.length]; + // NOTE: If the text view is flipped then 'rect' has its origin in the top + // left corner of the rect, but the methods below expect it to be in the + // lower left corner. Compensate for this here. + // TODO: Maybe the above method should always return rects where the origin + // is in the lower left corner? + if ([textView isFlipped]) + rect.origin.y += rect.size.height; + rect.origin = [textView convertPoint:rect.origin toView:nil]; rect.origin = [[textView window] convertBaseToScreen:rect.origin];