Provide a way to set cursor area for IME cursor

Rename `Window::set_ime_position` to `Window::set_ime_cursor_area`
adding a way to create cursor exclusive zone.

Fixes #2886.
This commit is contained in:
Kirill Chibisov 2023-06-22 19:12:14 +00:00 committed by GitHub
parent 66ff52b012
commit 05444628e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 72 additions and 43 deletions

View file

@ -1,12 +1,11 @@
use std::{
ffi::{c_void, OsString},
mem::zeroed,
os::windows::prelude::OsStringExt,
ptr::null_mut,
};
use windows_sys::Win32::{
Foundation::POINT,
Foundation::{POINT, RECT},
Globalization::HIMC,
UI::{
Input::Ime::{
@ -19,7 +18,10 @@ use windows_sys::Win32::{
},
};
use crate::{dpi::Position, platform::windows::HWND};
use crate::{
dpi::{Position, Size},
platform::windows::HWND,
};
pub struct ImeContext {
hwnd: HWND,
@ -109,17 +111,24 @@ impl ImeContext {
}
}
pub unsafe fn set_ime_position(&self, spot: Position, scale_factor: f64) {
pub unsafe fn set_ime_cursor_area(&self, spot: Position, size: Size, scale_factor: f64) {
if !ImeContext::system_has_ime() {
return;
}
let (x, y) = spot.to_physical::<i32>(scale_factor).into();
let (width, height): (i32, i32) = size.to_physical::<i32>(scale_factor).into();
let rc_area = RECT {
left: x,
top: y,
right: x + width,
bottom: y - height,
};
let candidate_form = CANDIDATEFORM {
dwIndex: 0,
dwStyle: CFS_EXCLUDE,
ptCurrentPos: POINT { x, y },
rcArea: zeroed(),
rcArea: rc_area,
};
ImmSetCandidateWindow(self.himc, &candidate_form);

View file

@ -722,9 +722,9 @@ impl Window {
}
#[inline]
pub fn set_ime_position(&self, spot: Position) {
pub fn set_ime_cursor_area(&self, spot: Position, size: Size) {
unsafe {
ImeContext::current(self.hwnd()).set_ime_position(spot, self.scale_factor());
ImeContext::current(self.hwnd()).set_ime_cursor_area(spot, size, self.scale_factor());
}
}