Add IM control support

When the default system keyboard script is non-roman the input manager is
automatically switched to a roman keyboard script when going to normal mode.
See 'imd', 'imc', 'imi' for some relevant options.  MacVim uses an
over-the-spot style of IM support.
This commit is contained in:
Bjorn Winckler
2007-11-13 19:15:11 +01:00
parent eaaacf8af6
commit f7e4a83a92
10 changed files with 78 additions and 18 deletions
+1
View File
@@ -106,6 +106,7 @@
- (void)stopBlink;
- (void)adjustLinespace:(int)linespace;
- (void)activate;
- (void)setPreEditRow:(int)row column:(int)col;
- (int)lookupColorWithKey:(NSString *)key;
- (BOOL)hasSpecialKeyWithValue:(NSString *)value;
+8
View File
@@ -946,6 +946,14 @@ enum {
[self queueMessage:ActivateMsgID data:nil];
}
- (void)setPreEditRow:(int)row column:(int)col
{
NSMutableData *data = [NSMutableData data];
[data appendBytes:&row length:sizeof(int)];
[data appendBytes:&col length:sizeof(int)];
[self queueMessage:SetPreEditPositionMsgID data:data];
}
- (int)lookupColorWithKey:(NSString *)key
{
if (!(key && [key length] > 0))
+3
View File
@@ -26,10 +26,13 @@
int insertionPointShape;
int insertionPointFraction;
NSTextField *markedTextField;
int preEditRow;
int preEditColumn;
}
- (NSEvent *)lastMouseDownEvent;
- (void)setShouldDrawInsertionPoint:(BOOL)on;
- (void)setPreEditRow:(int)row column:(int)col;
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
fraction:(int)percent color:(NSColor *)color;
- (void)hideMarkedTextField;
+17 -16
View File
@@ -79,6 +79,12 @@ static NSString *MMKeypadEnterString = @"KA";
shouldDrawInsertionPoint = on;
}
- (void)setPreEditRow:(int)row column:(int)col
{
preEditRow = row;
preEditColumn = col;
}
- (void)drawInsertionPointAtRow:(int)row column:(int)col shape:(int)shape
fraction:(int)percent color:(NSColor *)color
{
@@ -396,7 +402,7 @@ static NSString *MMKeypadEnterString = @"KA";
// Convert coordinates (row,col) -> view -> window base -> screen
NSPoint origin;
if (![self convertRow:insertionPointRow+1 column:insertionPointColumn
if (![self convertRow:preEditRow+1 column:preEditColumn
toPoint:&origin])
return;
origin = [self convertPoint:origin toView:nil];
@@ -427,26 +433,21 @@ static NSString *MMKeypadEnterString = @"KA";
// HACK! Since we always return marked text to have location NSNotFound,
// this method will be called with 'range.location == NSNotFound' whenever
// the input manager tries to position a popup window near the insertion
// point. For this reason we compute where the insertion point is and
// return a rect which contains it.
// the input manager tries to position a popup window at the pre-edit
// point. The pre-edit point itself is set by the IM routines in Vim
// (MacVim is notified via the SetPreEditPositionMsgID).
if (!(ts && lm && tc) || NSNotFound != range.location)
return [super firstRectForCharacterRange:range];
unsigned charIdx = [ts characterIndexForRow:insertionPointRow
column:insertionPointColumn];
NSRange glyphRange =
[lm glyphRangeForCharacterRange:NSMakeRange(charIdx,1)
actualCharacterRange:NULL];
NSRect ipRect = [lm boundingRectForGlyphRange:glyphRange
inTextContainer:tc];
ipRect.origin.x += [self textContainerOrigin].x;
ipRect.origin.y += [self textContainerOrigin].y + [ts cellSize].height;
NSRect rect = [ts boundingRectForCharacterAtRow:preEditRow
column:preEditColumn];
rect.origin.x += [self textContainerOrigin].x;
rect.origin.y += [self textContainerOrigin].y + [ts cellSize].height;
ipRect.origin = [self convertPoint:ipRect.origin toView:nil];
ipRect.origin = [[self window] convertBaseToScreen:ipRect.origin];
rect.origin = [self convertPoint:rect.origin toView:nil];
rect.origin = [[self window] convertBaseToScreen:rect.origin];
return ipRect;
return rect;
}
- (void)scrollWheel:(NSEvent *)event
+3
View File
@@ -814,6 +814,9 @@ static NSTimeInterval MMResendInterval = 0.5;
[[windowController window] setDocumentEdited:NO];
} else if (BuffersModifiedMsgID == msgid) {
[[windowController window] setDocumentEdited:YES];
} else if (SetPreEditPositionMsgID == msgid) {
const int *dim = (const int*)[data bytes];
[[windowController textView] setPreEditRow:dim[0] column:dim[1]];
} else {
NSLog(@"WARNING: Unknown message received (msgid=%d)", msgid);
}
+1
View File
@@ -155,6 +155,7 @@ enum {
BuffersNotModifiedMsgID,
BuffersModifiedMsgID,
AddInputMsgID,
SetPreEditPositionMsgID,
};
+1
View File
@@ -68,6 +68,7 @@ char *MessageStrings[] =
"BuffersNotModifiedMsgID",
"BuffersModifiedMsgID",
"AddInputMsgID",
"SetPreEditPositionMsgID",
};
+41
View File
@@ -1104,6 +1104,47 @@ mch_set_mouse_shape(int shape)
// -- Input Method ----------------------------------------------------------
#if defined(USE_IM_CONTROL)
void
im_set_position(int row, int col)
{
// The pre-edit area is a popup window which is displayed by MMTextView.
[[MMBackend sharedInstance] setPreEditRow:row column:col];
}
void
im_set_active(int active)
{
// Set roman or the system script if 'active' is TRUE or FALSE,
// respectively.
SInt32 systemScript = GetScriptManagerVariable(smSysScript);
if (!p_imdisable && smRoman != systemScript)
KeyScript(active ? smKeySysScript : smKeyRoman);
}
int
im_get_status(void)
{
// IM is active whenever the current script is the system script and the
// system script isn't roman. (Hence IM can only be active when using
// non-roman scripts.)
SInt32 currentScript = GetScriptManagerVariable(smKeyScript);
SInt32 systemScript = GetScriptManagerVariable(smSysScript);
return currentScript != smRoman && currentScript == systemScript;
}
#endif // defined(USE_IM_CONTROL)
// -- Unsorted --------------------------------------------------------------
+1 -1
View File
@@ -1233,7 +1233,7 @@ MACVIMGUI_OBJ = objects/gui.o objects/pty.o objects/gui_macvim.o \
MACVIMGUI_DEFS = -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe
MACVIMGUI_IPATH = -I. -Iproto
MACVIMGUI_LIBS_DIR =
MACVIMGUI_LIBS1 = -framework Cocoa
MACVIMGUI_LIBS1 = -framework Cocoa -framework Carbon
MACVIMGUI_LIBS2 =
MACVIMGUI_INSTALL = install_normal
MACVIMGUI_TARGETS =
+2 -1
View File
@@ -463,7 +463,8 @@ typedef unsigned long u8char_T; /* long should be 32 bits or more */
* Check input method control.
*/
#if defined(FEAT_XIM) || \
(defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)))
(defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME))) \
|| defined(FEAT_GUI_MACVIM)
# define USE_IM_CONTROL
#endif