summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:48 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:48 +0000
commite2ec0ddb030afd4e7bdf08d1a8f3cb9361388eae (patch)
tree1c90e05fa6e94d2b0f1ebf2fff6ff444e2d515ed /src/video
parentf5e41314922604c160efc4ac18c77056a1b66400 (diff)
downloadopenttd-e2ec0ddb030afd4e7bdf08d1a8f3cb9361388eae.tar.xz
(svn r25690) -Change: [OSX] Position the candidate window at the caret position.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/cocoa/cocoa_v.mm29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 16069bb24..e4897ac50 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -896,7 +896,14 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
/** Get a string corresponding to the given range. */
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)theRange
{
- return nil;
+ if (!EditBoxInGlobalFocus()) return nil;
+
+ NSString *s = [ NSString stringWithUTF8String:_focused_window->GetFocusedText() ];
+ NSRange valid_range = NSIntersectionRange(NSMakeRange(0, [ s length ]), theRange);
+
+ if (valid_range.length == 0) return nil;
+
+ return [ [ [ NSAttributedString alloc ] initWithString:[ s substringWithRange:valid_range ] ] autorelease ];
}
/** Get the character that is rendered at the given point. */
@@ -908,7 +915,25 @@ static const char *Utf8AdvanceByUtf16Units(const char *str, NSUInteger count)
/** Get the bounding rect for the given range. */
- (NSRect)firstRectForCharacterRange:(NSRange)aRange
{
- return NSMakeRect(0, 0, 0, 0);
+ if (!EditBoxInGlobalFocus()) return NSMakeRect(0, 0, 0, 0);
+
+ /* Convert range to UTF-8 string pointers. */
+ const char *start = Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), aRange.location);
+ const char *end = aRange.length != 0 ? Utf8AdvanceByUtf16Units(_focused_window->GetFocusedText(), aRange.location + aRange.length) : start;
+
+ /* Get the bounding rect for the text range.*/
+ Rect r = _focused_window->GetTextBoundingRect(start, end);
+ NSRect view_rect = NSMakeRect(_focused_window->left + r.left, [ self frame ].size.height - _focused_window->top - r.bottom, r.right - r.left, r.bottom - r.top);
+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
+ if ([ [ self window ] respondsToSelector:@selector(convertRectToScreen:) ]) {
+ return [ [ self window ] convertRectToScreen:[ self convertRect:view_rect toView:nil ] ];
+ }
+#endif
+
+ NSRect window_rect = [ self convertRect:view_rect toView:nil ];
+ NSPoint origin = [ [ self window ] convertBaseToScreen:window_rect.origin ];
+ return NSMakeRect(origin.x, origin.y, window_rect.size.width, window_rect.size.height);
}
/** Get all string attributes that we can process for marked text. */