Add WindowBase::setImePreEditPosition

This commit is contained in:
Edgaru089 2023-09-19 16:01:01 +08:00
parent 910514871e
commit b4410ff015
16 changed files with 144 additions and 2 deletions

View File

@ -412,6 +412,23 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const; bool hasFocus() const;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit popup
/// should show up
///
/// The position specified is relative to the left-top
/// corner of the window area.
///
/// It is implementation-specific what happens when negative
/// values are used. X11 handles them as you would expect,
/// but Windows sometimes resets the position to the top-left
/// of the screen.
///
/// \param position Left-top corner of the preedit popup
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Get the OS-specific handle of the window /// \brief Get the OS-specific handle of the window
/// ///

View File

@ -226,6 +226,13 @@ bool WindowImplAndroid::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowImplAndroid::setImePreEditPosition(const Vector2i& /* position */)
{
// Not applicable
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplAndroid::forwardEvent(const Event& event) void WindowImplAndroid::forwardEvent(const Event& event)
{ {

View File

@ -202,6 +202,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreeditPosition(const Vector2i& position) override;
static void forwardEvent(const Event& event); static void forwardEvent(const Event& event);
static WindowImplAndroid* singleInstance; static WindowImplAndroid* singleInstance;

View File

@ -330,7 +330,7 @@ if(SFML_OS_LINUX)
find_package(UDev REQUIRED) find_package(UDev REQUIRED)
target_link_libraries(sfml-window PRIVATE UDev::UDev dl) target_link_libraries(sfml-window PRIVATE UDev::UDev dl)
elseif(SFML_OS_WINDOWS) elseif(SFML_OS_WINDOWS)
target_link_libraries(sfml-window PRIVATE winmm gdi32) target_link_libraries(sfml-window PRIVATE winmm gdi32 imm32)
elseif(SFML_OS_FREEBSD) elseif(SFML_OS_FREEBSD)
target_link_libraries(sfml-window PRIVATE usbhid) target_link_libraries(sfml-window PRIVATE usbhid)
elseif(SFML_OS_MACOS) elseif(SFML_OS_MACOS)

View File

@ -158,6 +158,14 @@ bool WindowImplDRM::hasFocus() const
return true; return true;
} }
////////////////////////////////////////////////////////////
void WindowImplDRM::setImePreEditPosition(const Vector2i& /* position */)
{
// Not applicable
}
void WindowImplDRM::processEvents() void WindowImplDRM::processEvents()
{ {
sf::Event ev; sf::Event ev;

View File

@ -196,6 +196,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreeditPosition(const Vector2i& position) override;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system /// \brief Process incoming events from the operating system

View File

@ -1232,6 +1232,16 @@ bool WindowImplX11::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowImplX11::setImePreEditPosition(const Vector2i& position)
{
const XPoint xpos{static_cast<short>(position.x), static_cast<short>(position.y)};
const XVaNestedList preeditAttr = XVaCreateNestedList(0, XNSpotLocation, &xpos, NULL);
XSetICValues(m_inputContext, XNPreeditAttributes, preeditAttr, NULL);
XFree(preeditAttr);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplX11::grabFocus() void WindowImplX11::grabFocus()
{ {

View File

@ -203,6 +203,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system /// \brief Process incoming events from the operating system

View File

@ -454,6 +454,21 @@ bool WindowImplWin32::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowImplWin32::setImePreEditPosition(const Vector2i& position)
{
if (HIMC himc = ImmGetContext(m_handle); himc != nullptr)
{
COMPOSITIONFORM cf;
cf.ptCurrentPos.x = static_cast<LONG>(position.x);
cf.ptCurrentPos.y = static_cast<LONG>(position.y);
cf.dwStyle = CFS_FORCE_POSITION; // Don't let the IME adjust the position
ImmSetCompositionWindow(himc, &cf);
ImmReleaseContext(m_handle, himc);
}
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplWin32::registerWindowClass() void WindowImplWin32::registerWindowClass()
{ {
@ -671,7 +686,7 @@ Keyboard::Scancode WindowImplWin32::toScancode(WPARAM wParam, LPARAM lParam)
case 86: return Keyboard::Scan::NonUsBackslash; case 86: return Keyboard::Scan::NonUsBackslash;
case 87: return Keyboard::Scan::F11; case 87: return Keyboard::Scan::F11;
case 88: return Keyboard::Scan::F12; case 88: return Keyboard::Scan::F12;
case 91: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::LSystem : Keyboard::Scan::Unknown; case 91: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::LSystem : Keyboard::Scan::Unknown;
case 92: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::RSystem : Keyboard::Scan::Unknown; case 92: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::RSystem : Keyboard::Scan::Unknown;
case 93: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::Menu : Keyboard::Scan::Unknown; case 93: return (HIWORD(lParam) & KF_EXTENDED) ? Keyboard::Scan::Menu : Keyboard::Scan::Unknown;

View File

@ -183,6 +183,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system /// \brief Process incoming events from the operating system

View File

@ -351,6 +351,14 @@ bool WindowBase::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowBase::setImePreEditPosition(const Vector2i& position)
{
if (m_impl)
m_impl->setImePreEditPosition(position);
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
WindowHandle WindowBase::getNativeHandle() const WindowHandle WindowBase::getNativeHandle() const
{ {

View File

@ -275,6 +275,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
virtual bool hasFocus() const = 0; virtual bool hasFocus() const = 0;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
virtual void setImePreEditPosition(const Vector2i& position) = 0;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Create a Vulkan rendering surface /// \brief Create a Vulkan rendering surface
/// ///

View File

@ -197,6 +197,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Notify an event /// \brief Notify an event
/// ///

View File

@ -223,6 +223,13 @@ bool WindowImplUIKit::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowImplUIKit::setImePreeditPosition(const Vector2i& /* position */)
{
// Not applicable
}
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void WindowImplUIKit::forwardEvent(Event event) void WindowImplUIKit::forwardEvent(Event event)
{ {

View File

@ -371,6 +371,15 @@ public:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool hasFocus() const override; bool hasFocus() const override;
////////////////////////////////////////////////////////////
/// \brief Set the position where the IME preedit window
/// should show up
///
/// \param position Left-top corner of the preedit window
///
////////////////////////////////////////////////////////////
void setImePreEditPosition(const Vector2i& position) override;
protected: protected:
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system /// \brief Process incoming events from the operating system

View File

@ -546,4 +546,11 @@ bool WindowImplCocoa::hasFocus() const
} }
////////////////////////////////////////////////////////////
void WindowImplCocoa::setImePreEditPosition(const Vector2i& /* position */)
{
// TODO: To implement
}
} // namespace sf::priv } // namespace sf::priv