Skip to content

Commit

Permalink
fix(ime): composition window position problem (#36, #175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticLampyrid authored and lc-soft committed Oct 3, 2019
1 parent 9be4b7e commit 1107f91
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
3 changes: 3 additions & 0 deletions include/LCUI/ime.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct LCUI_IMEHandlerRec_ {
void (*totext)(int);
LCUI_BOOL (*open)(void);
LCUI_BOOL (*close)(void);
void (*setcaret)(int, int);
} LCUI_IMEHandlerRec, *LCUI_IMEHandler;

/** 注册一个输入法 */
Expand Down Expand Up @@ -72,6 +73,8 @@ int LCUI_RegisterWin32IME(void);
int LCUI_RegisterLinuxIME(void);
#endif

LCUI_API void LCUIIME_SetCaret(int x, int y);

LCUI_END_HEADER

#endif
8 changes: 7 additions & 1 deletion src/gui/widget/textcaret.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <LCUI/gui/widget.h>
#include <LCUI/gui/widget/textcaret.h>
#include <LCUI/gui/css_parser.h>
#include <LCUI/ime.h>

/** 文本插入符相关数据 */
typedef struct LCUI_TextCaretRec_ {
Expand All @@ -59,11 +60,16 @@ textcaret {

void TextCaret_Refresh(LCUI_Widget widget)
{
float x, y;

LCUI_TextCaret caret = Widget_GetData(widget, prototype);

if (!caret->visible) {
return;
}
LCUITimer_Reset(caret->timer_id, caret->blink_interval);
Widget_GetOffset(widget, LCUIWidget_GetRoot(), &x, &y);
LCUIIME_SetCaret((int)x, (int)y);
Widget_Show(widget);
}

Expand Down Expand Up @@ -101,7 +107,7 @@ static void TextCaret_OnInit(LCUI_Widget widget)
caret->blink_interval = 500;
caret->visible = FALSE;
caret->timer_id = LCUI_SetInterval(caret->blink_interval,
TextCaret_OnBlink, widget);
TextCaret_OnBlink, widget);
}

void TextCaret_SetBlinkTime(LCUI_Widget widget, unsigned int n_ms)
Expand Down
7 changes: 7 additions & 0 deletions src/ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,13 @@ void LCUI_InitIME(void)
#endif
}

void LCUIIME_SetCaret(int x, int y)
{
if (self.ime->handler.setcaret) {
self.ime->handler.setcaret(x, y);
}
}

void LCUI_FreeIME(void)
{
self.active = FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/platform/linux/linux_ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ int LCUI_RegisterLinuxIME(void)
handler.totext = X11IME_ToText;
handler.close = X11IME_Close;
handler.open = X11IME_Open;
handler.setcaret = NULL;
return LCUIIME_Register("LCUI X11 Input Method", &handler);
}
#endif
Expand Down
18 changes: 17 additions & 1 deletion src/platform/windows/windows_ime.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
#include <string.h>
#include <stdlib.h>
#include <LCUI_Build.h>

#ifdef LCUI_BUILD_IN_WIN32
#include <LCUI/LCUI.h>
#include <LCUI/input.h>
#include <LCUI/ime.h>
#include <LCUI/platform.h>
#include LCUI_EVENTS_H

#pragma comment(lib, "Imm32.lib")

static LCUI_BOOL IME_ProcessKey(int key, int key_state)
{
return FALSE;
Expand All @@ -60,6 +61,20 @@ static void WinIME_OnChar(LCUI_Event e, void *arg)
LCUIIME_Commit(text, 2);
}

static void IME_SetCaret(int x, int y)
{
HWND hwnd = GetActiveWindow();
HIMC himc = ImmGetContext(hwnd);
if (himc) {
COMPOSITIONFORM composition;
composition.dwStyle = CFS_POINT;
composition.ptCurrentPos.x = x;
composition.ptCurrentPos.y = y;
ImmSetCompositionWindow(himc, &composition);
ImmReleaseContext(hwnd, himc);
}
}

static LCUI_BOOL IME_Open(void)
{
LCUI_BindSysEvent(WM_CHAR, WinIME_OnChar, NULL, NULL);
Expand All @@ -79,6 +94,7 @@ int LCUI_RegisterWin32IME(void)
handler.totext = IME_ToText;
handler.close = IME_Close;
handler.open = IME_Open;
handler.setcaret = IME_SetCaret;
return LCUIIME_Register("LCUI Input Method", &handler);
}

Expand Down

0 comments on commit 1107f91

Please sign in to comment.