Only show the input window when we attempt to add marked text, *and* we can't submit marked text directly to the viewer.
parent
5683fe2fa3
commit
cda10266ae
|
|
@ -20,6 +20,7 @@
|
|||
bool mHasMarkedText;
|
||||
unsigned int mMarkedTextLength;
|
||||
NSAttributedString *mMarkedText;
|
||||
bool mMarkedTextAllowed;
|
||||
}
|
||||
- (id) initWithSamples:(NSUInteger)samples;
|
||||
- (id) initWithSamples:(NSUInteger)samples andVsync:(BOOL)vsync;
|
||||
|
|
@ -42,6 +43,8 @@
|
|||
|
||||
- (unsigned long) getVramSize;
|
||||
|
||||
- (void) allowMarkedTextInput:(bool)allowed;
|
||||
|
||||
@end
|
||||
|
||||
@interface LLNonInlineTextView : NSTextView
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
segment_standouts seg_standouts;
|
||||
NSRange effectiveRange;
|
||||
NSRange limitRange = NSMakeRange(0, [str length]);
|
||||
|
||||
while (limitRange.length > 0) {
|
||||
NSNumber *attr = [str attribute:NSUnderlineStyleAttributeName atIndex:limitRange.location longestEffectiveRange:&effectiveRange inRange:limitRange];
|
||||
limitRange = NSMakeRange(NSMaxRange(effectiveRange), NSMaxRange(limitRange) - NSMaxRange(effectiveRange));
|
||||
|
|
@ -402,32 +403,40 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
|
||||
- (void)setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString"))
|
||||
{
|
||||
unsigned int selected[2] = {
|
||||
selectedRange.location,
|
||||
selectedRange.length
|
||||
};
|
||||
|
||||
unsigned int replacement[2] = {
|
||||
replacementRange.location,
|
||||
replacementRange.length
|
||||
};
|
||||
|
||||
unichar text[[aString length]];
|
||||
[[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])];
|
||||
attributedStringInfo segments = getSegments((NSAttributedString *)aString);
|
||||
setMarkedText(text, selected, replacement, [aString length], segments);
|
||||
mHasMarkedText = TRUE;
|
||||
mMarkedTextLength = [aString length];
|
||||
mMarkedText = (NSAttributedString*)[aString mutableString];
|
||||
}
|
||||
if (mMarkedTextAllowed)
|
||||
{
|
||||
if ([aString class] == NSClassFromString(@"NSConcreteMutableAttributedString"))
|
||||
{
|
||||
unsigned int selected[2] = {
|
||||
selectedRange.location,
|
||||
selectedRange.length
|
||||
};
|
||||
|
||||
unsigned int replacement[2] = {
|
||||
replacementRange.location,
|
||||
replacementRange.length
|
||||
};
|
||||
|
||||
unichar text[[aString length]];
|
||||
[[aString mutableString] getCharacters:text range:NSMakeRange(0, [aString length])];
|
||||
attributedStringInfo segments = getSegments((NSAttributedString *)aString);
|
||||
setMarkedText(text, selected, replacement, [aString length], segments);
|
||||
mHasMarkedText = TRUE;
|
||||
mMarkedTextLength = [aString length];
|
||||
mMarkedText = (NSAttributedString*)[aString mutableString];
|
||||
}
|
||||
} else {
|
||||
showInputWindow(true);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)commitCurrentPreedit
|
||||
{
|
||||
[self insertText:mMarkedText replacementRange:NSMakeRange(0, [mMarkedText length])];
|
||||
[[self inputContext] discardMarkedText];
|
||||
if (mMarkedText)
|
||||
{
|
||||
[self insertText:mMarkedText];
|
||||
[[self inputContext] discardMarkedText];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)unmarkText
|
||||
|
|
@ -452,11 +461,12 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
|
||||
- (void)insertText:(id)aString replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
bool success = false;
|
||||
if (!mHasMarkedText)
|
||||
{
|
||||
for (NSInteger i = 0; i < [aString length]; i++)
|
||||
{
|
||||
callUnicodeCallback([aString characterAtIndex:i], mModifiers);
|
||||
success = callUnicodeCallback([aString characterAtIndex:i], mModifiers);
|
||||
}
|
||||
} else {
|
||||
// We may never get this point since unmarkText may be called before insertText ever gets called once we submit our text.
|
||||
|
|
@ -465,10 +475,12 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
|
||||
for (NSInteger i = 0; i < [aString length]; i++)
|
||||
{
|
||||
handleUnicodeCharacter([aString characterAtIndex:i]);
|
||||
success = handleUnicodeCharacter([aString characterAtIndex:i]);
|
||||
}
|
||||
mHasMarkedText = FALSE;
|
||||
}
|
||||
|
||||
NSLog(@"Successful text input: %d", success);
|
||||
}
|
||||
|
||||
- (void) insertNewline:(id)sender
|
||||
|
|
@ -508,6 +520,11 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (void) allowMarkedTextInput:(bool)allowed
|
||||
{
|
||||
mMarkedTextAllowed = allowed;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation LLNonInlineTextView
|
||||
|
|
@ -525,9 +542,10 @@ attributedStringInfo getSegments(NSAttributedString *str)
|
|||
- (void) insertText:(id)aString replacementRange:(NSRange)replacementRange
|
||||
{
|
||||
[glview insertText:aString replacementRange:replacementRange];
|
||||
[_window orderOut:_window];
|
||||
[[self textStorage] setValue:@""];
|
||||
[[self inputContext] discardMarkedText];
|
||||
[self setString:@""];
|
||||
[_window orderOut:_window];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -95,10 +95,10 @@ void showInputWindow(bool show);
|
|||
|
||||
// These are all implemented in llwindowmacosx.cpp.
|
||||
// This is largely for easier interop between Obj-C and C++ (at least in the viewer's case due to the BOOL vs. BOOL conflict)
|
||||
void callKeyUp(unsigned short key, unsigned int mask);
|
||||
void callKeyDown(unsigned short key, unsigned int mask);
|
||||
bool callKeyUp(unsigned short key, unsigned int mask);
|
||||
bool callKeyDown(unsigned short key, unsigned int mask);
|
||||
void callResetKeys();
|
||||
void callUnicodeCallback(wchar_t character, unsigned int mask);
|
||||
bool callUnicodeCallback(wchar_t character, unsigned int mask);
|
||||
void callRightMouseDown(float *pos, unsigned int mask);
|
||||
void callRightMouseUp(float *pos, unsigned int mask);
|
||||
void callLeftMouseDown(float *pos, unsigned int mask);
|
||||
|
|
@ -129,13 +129,14 @@ void callHandleDragDropped(std::string url);
|
|||
std::basic_string<wchar_t> getPreeditString();
|
||||
void getPreeditSelectionRange(int *position, int *length);
|
||||
void getPreeditMarkedRange(int *position, int *length);
|
||||
void handleUnicodeCharacter(wchar_t c);
|
||||
bool handleUnicodeCharacter(wchar_t c);
|
||||
void updatePreeditor(unsigned short *str);
|
||||
void setPreeditMarkedRange(int position, int length);
|
||||
void resetPreedit();
|
||||
int wstring_length(const std::basic_string<wchar_t> & wstr, const int woffset, const int utf16_length, int *unaligned);
|
||||
void setMarkedText(unsigned short *text, unsigned int *selectedRange, unsigned int *replacementRange, long text_len, attributedStringInfo segments);
|
||||
void getPreeditLocation(float *location, unsigned int length);
|
||||
void allowDirectMarkedTextInput(bool allow);
|
||||
|
||||
NSWindowRef getMainAppWindow();
|
||||
GLViewRef getGLView();
|
||||
|
|
|
|||
|
|
@ -377,6 +377,11 @@ void commitCurrentPreedit(GLViewRef glView)
|
|||
[(LLOpenGLView*)glView commitCurrentPreedit];
|
||||
}
|
||||
|
||||
void allowDirectMarkedTextInput(bool allow)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NSWindowRef getMainAppWindow()
|
||||
{
|
||||
LLNSWindow *winRef = [(LLAppDelegate*)[[NSApplication sharedApplication] delegate] window];
|
||||
|
|
|
|||
|
|
@ -204,14 +204,14 @@ LLWindowMacOSX::LLWindowMacOSX(LLWindowCallbacks* callbacks,
|
|||
// These functions are used as wrappers for our internal event handling callbacks.
|
||||
// It's a good idea to wrap these to avoid reworking more code than we need to within LLWindow.
|
||||
|
||||
void callKeyUp(unsigned short key, unsigned int mask)
|
||||
bool callKeyUp(unsigned short key, unsigned int mask)
|
||||
{
|
||||
gKeyboard->handleKeyUp(key, mask);
|
||||
return gKeyboard->handleKeyUp(key, mask);
|
||||
}
|
||||
|
||||
void callKeyDown(unsigned short key, unsigned int mask)
|
||||
bool callKeyDown(unsigned short key, unsigned int mask)
|
||||
{
|
||||
gKeyboard->handleKeyDown(key, mask);
|
||||
return gKeyboard->handleKeyDown(key, mask);
|
||||
}
|
||||
|
||||
void callResetKeys()
|
||||
|
|
@ -219,9 +219,9 @@ void callResetKeys()
|
|||
gKeyboard->resetKeys();
|
||||
}
|
||||
|
||||
void callUnicodeCallback(wchar_t character, unsigned int mask)
|
||||
bool callUnicodeCallback(wchar_t character, unsigned int mask)
|
||||
{
|
||||
gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask);
|
||||
return gWindowImplementation->getCallbacks()->handleUnicodeChar(character, mask);
|
||||
}
|
||||
|
||||
void callFocus()
|
||||
|
|
@ -408,12 +408,15 @@ void setPreeditMarkedRange(int position, int length)
|
|||
}
|
||||
}
|
||||
|
||||
void handleUnicodeCharacter(wchar_t c)
|
||||
bool handleUnicodeCharacter(wchar_t c)
|
||||
{
|
||||
bool success = false;
|
||||
if (gWindowImplementation->getPreeditor())
|
||||
{
|
||||
gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c);
|
||||
success = gWindowImplementation->getPreeditor()->handleUnicodeCharHere(c);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void resetPreedit()
|
||||
|
|
@ -1033,21 +1036,7 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position)
|
|||
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
static void fixOrigin(void)
|
||||
{
|
||||
GrafPtr port;
|
||||
Rect portrect;
|
||||
|
||||
::GetPort(&port);
|
||||
::GetPortBounds(port, &portrect);
|
||||
if((portrect.left != 0) || (portrect.top != 0))
|
||||
{
|
||||
// Mozilla sometimes changes our port origin.
|
||||
::SetOrigin(0,0);
|
||||
}
|
||||
}
|
||||
*/
|
||||
BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position)
|
||||
{
|
||||
float cursor_point[2];
|
||||
|
|
@ -1840,7 +1829,14 @@ void LLWindowMacOSX::allowLanguageTextInput(LLPreeditor *preeditor, BOOL b)
|
|||
return;
|
||||
}
|
||||
|
||||
showInputWindow(!b);
|
||||
if (preeditor == NULL) {
|
||||
// If we don't have a pre editor, then we can't accept direct marked text input.
|
||||
// We needs an input window (which is handled internally by LLOpenGLView)
|
||||
allowDirectMarkedTextInput(false);
|
||||
} else {
|
||||
// If we have a preeditor, then accept direct marked text input.
|
||||
allowDirectMarkedTextInput(true);
|
||||
}
|
||||
|
||||
// Take care of old and new preeditors.
|
||||
if (preeditor != mPreeditor || !b)
|
||||
|
|
|
|||
Loading…
Reference in New Issue