Add user default MMUseInlineIm

Use inline IM (Vim draws marked text) when on, use old IM drawing code
otherwise.
This commit is contained in:
Bjorn Winckler
2009-08-09 21:27:30 +02:00
parent 507a68ef81
commit ae400c2dbb
8 changed files with 51 additions and 29 deletions
+3
View File
@@ -209,6 +209,9 @@ fsEventCallback(ConstFSEventStreamRef streamRef,
[NSNumber numberWithInt:0], MMPreloadCacheSizeKey,
[NSNumber numberWithInt:0], MMLastWindowClosedBehaviorKey,
[NSNumber numberWithBool:YES], MMLoadDefaultFontKey,
#ifdef INCLUDE_OLD_IM_CODE
[NSNumber numberWithBool:YES], MMUseInlineImKey,
#endif // INCLUDE_OLD_IM_CODE
nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dict];
+3 -3
View File
@@ -518,8 +518,8 @@ defaultLineHeightForFont(NSFont *font)
NSPoint pt = { insetSize.width, insetSize.height };
[contentImage compositeToPoint:pt operation:NSCompositeCopy];
#ifdef USE_OLD_IM
if ([self hasMarkedText]) {
#ifdef INCLUDE_OLD_IM_CODE
if ([self hasMarkedText] && ![helper useInlineIm]) {
int len = [[helper markedText] length];
int rows = 0;
int cols = maxColumns - [helper preEditColumn];
@@ -575,7 +575,7 @@ defaultLineHeightForFont(NSFont *font)
shape:MMInsertionPointVertical
fraction:25];
}
#endif // USE_OLD_IM
#endif // INCLUDE_OLD_IM_CODE
}
- (BOOL) wantsDefaultClipping
-6
View File
@@ -56,11 +56,9 @@ vimmenu_T *menu_for_descriptor(NSArray *desc);
static id evalExprCocoa(NSString * expr, NSString ** errstr);
#ifndef USE_OLD_IM
extern void im_preedit_start_macvim();
extern void im_preedit_end_macvim();
extern void im_preedit_changed_macvim(char *preedit_string, int cursor_index);
#endif
enum {
MMBlinkStateNone = 0,
@@ -2771,8 +2769,6 @@ static void netbeansReadCallback(CFSocketRef s,
}
#ifndef USE_OLD_IM
- (void)handleMarkedText:(NSData *)data
{
const void *bytes = [data bytes];
@@ -2792,8 +2788,6 @@ static void netbeansReadCallback(CFSocketRef s,
}
}
#endif // USE_OLD_IM
@end // MMBackend (Private)
+6 -6
View File
@@ -522,8 +522,8 @@
numInvertRects = 0;
}
#ifdef USE_OLD_IM
if ([self hasMarkedText]) {
#ifdef INCLUDE_OLD_IM_CODE
if ([self hasMarkedText] && ![helper useInlineIm]) {
shouldDrawInsertionPoint = YES;
MMTextStorage *ts = (MMTextStorage*)[self textStorage];
NSSize inset = [self textContainerInset];
@@ -581,7 +581,7 @@
}
}
}
#endif
#endif // INCLUDE_OLD_IM_CODE
if (shouldDrawInsertionPoint) {
MMTextStorage *ts = (MMTextStorage*)[self textStorage];
@@ -591,9 +591,9 @@
ipRect.origin.x += [self textContainerOrigin].x;
ipRect.origin.y += [self textContainerOrigin].y;
#ifdef USE_OLD_IM
#ifdef INCLUDE_OLD_IM_CODE
// Draw insertion point inside marked text.
if ([self hasMarkedText]) {
if ([self hasMarkedText] && ![helper useInlineIm]) {
NSFont *theFont = [[self markedTextAttributes]
valueForKey:NSFontAttributeName];
if (theFont == [ts font])
@@ -605,7 +605,7 @@
([helper imRange].location +
[helper imRange].length);
}
#endif
#endif // INCLUDE_OLD_IM_CODE
if (MMInsertionPointHorizontal == insertionPointShape) {
int frac = ([ts cellSize].height * insertionPointFraction + 99)/100;
+1
View File
@@ -95,5 +95,6 @@ enum {
- (NSRect)firstRectForCharacterRange:(NSRange)range;
- (void)setImControl:(BOOL)enable;
- (void)activateIm:(BOOL)enable;
- (BOOL)useInlineIm;
@end
+29 -14
View File
@@ -185,9 +185,8 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
- (void)insertText:(id)string
{
if ([self hasMarkedText]) {
// Clear marked text
[self sendMarkedText:nil position:0];
// NOTE: If this call is left out then the marked text isn't properly
// erased when Return is used to accept the text.
// The input manager only ever sets new marked text, it never actually
@@ -627,7 +626,20 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
ASLogDebug(@"text='%@' range=%@", text, NSStringFromRange(range));
[self unmarkText];
#ifdef USE_OLD_IM
if ([self useInlineIm]) {
if ([text isKindOfClass:[NSAttributedString class]])
text = [text string];
if ([text length] > 0) {
markedRange = NSMakeRange(0, [text length]);
imRange = range;
}
[self sendMarkedText:text position:range.location];
return;
}
#ifdef INCLUDE_OLD_IM_CODE
if (!(text && [text length] > 0))
return;
@@ -667,17 +679,7 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
}
[textView setNeedsDisplay:YES];
#else // USE_OLD_IM
if ([text isKindOfClass:[NSAttributedString class]])
text = [text string];
if ([text length] > 0) {
markedRange = NSMakeRange(0, [text length]);
imRange = range;
}
[self sendMarkedText:text position:range.location];
#endif
#endif // INCLUDE_OLD_IM_CODE
}
- (void)unmarkText
@@ -851,6 +853,16 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
#endif
}
- (BOOL)useInlineIm
{
#ifdef INCLUDE_OLD_IM_CODE
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
return [ud boolForKey:MMUseInlineImKey];
#else
return YES;
#endif // INCLUDE_OLD_IM_CODE
}
@end // MMTextViewHelper
@@ -1107,6 +1119,9 @@ KeyboardInputSourcesEqual(TISInputSourceRef a, TISInputSourceRef b)
- (void)sendMarkedText:(NSString *)text position:(unsigned)pos
{
if (![self useInlineIm])
return;
NSMutableData *data = [NSMutableData data];
unsigned len = text == nil ? 0
: [text lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
+6
View File
@@ -13,6 +13,9 @@
#import "MacVim.h"
// TODO: Remove this when the inline IM code has been tested
#define INCLUDE_OLD_IM_CODE
// NSUserDefaults keys
extern NSString *MMTabMinWidthKey;
@@ -47,6 +50,9 @@ extern NSString *MMVerticalSplitKey;
extern NSString *MMPreloadCacheSizeKey;
extern NSString *MMLastWindowClosedBehaviorKey;
extern NSString *MMLoadDefaultFontKey;
#ifdef INCLUDE_OLD_IM_CODE
extern NSString *MMUseInlineImKey;
#endif // INCLUDE_OLD_IM_CODE
// Enum for MMUntitledWindowKey
+3
View File
@@ -46,6 +46,9 @@ NSString *MMVerticalSplitKey = @"MMVerticalSplit";
NSString *MMPreloadCacheSizeKey = @"MMPreloadCacheSize";
NSString *MMLastWindowClosedBehaviorKey = @"MMLastWindowClosedBehavior";
NSString *MMLoadDefaultFontKey = @"MMLoadDefaultFont";
#ifdef INCLUDE_OLD_IM_CODE
NSString *MMUseInlineImKey = @"MMUseInlineIm";
#endif // INCLUDE_OLD_IM_CODE