Skip to content

Commit

Permalink
First step to support CJK input under Mac OS: implementation of the f…
Browse files Browse the repository at this point in the history
…unction

firstRectForCharacterRange of the NSTextInput protocol.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8228 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
  • Loading branch information
Manolo Gouy authored and Manolo Gouy committed Jan 9, 2011
1 parent 5f940c4 commit 2dadc8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 2 additions & 3 deletions FL/Fl_Text_Display.H
Expand Up @@ -142,7 +142,8 @@ public:
\return insert position index into text buffer
*/
int insert_position() const { return mCursorPos; }

int position_to_xy(int pos, int* x, int* y) const;

int in_selection(int x, int y) const;
void show_insert_position();

Expand Down Expand Up @@ -364,8 +365,6 @@ protected:

void xy_to_rowcol(int x, int y, int* row, int* column,
int PosType = CHARACTER_POS) const;

int position_to_xy(int pos, int* x, int* y) const;
void maintain_absolute_top_line_number(int state);
int get_absolute_top_line_number() const;
void absolute_top_line_number(int oldFirstChar);
Expand Down
23 changes: 18 additions & 5 deletions src/Fl_cocoa.mm
Expand Up @@ -1818,13 +1818,26 @@ - (NSArray *)validAttributesForMarkedText {
}

- (NSRect)firstRectForCharacterRange:(NSRange)aRange {
NSRect glyphRect, frame;
NSRect glyphRect;
Fl_Widget *focus = Fl::focus();
Fl_Window *wfocus = focus->window();
while (wfocus->window()) wfocus = wfocus->window();
glyphRect.size.width = 0;

frame = [self frame];
glyphRect.origin.x = frame.size.width;
glyphRect.origin.y = 0;
glyphRect.size.width = glyphRect.size.height = 0;
if (dynamic_cast<Fl_Text_Display*>(focus) != NULL) {
int x, y;
Fl_Text_Display *current = (Fl_Text_Display*)focus;
current->position_to_xy( current->insert_position(), &x, &y );
glyphRect.origin.x = (CGFloat)x;
glyphRect.origin.y = (CGFloat)y + current->textsize();
glyphRect.size.height = current->textsize();
} else {
glyphRect.origin.x = (CGFloat)Fl::event_x();
glyphRect.origin.y = (CGFloat)Fl::event_y() + 12;
glyphRect.size.height = 12;
}
// Convert the rect to screen coordinates
glyphRect.origin.y = wfocus->h() - glyphRect.origin.y;
glyphRect.origin = [[self window] convertBaseToScreen:glyphRect.origin];
return glyphRect;
}
Expand Down

0 comments on commit 2dadc8c

Please sign in to comment.