Skip to content

Commit

Permalink
Add WindowBase::setIMEPreeditPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
Edgaru089 committed Apr 5, 2023
1 parent f371a99 commit e04bcbb
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 1 deletion.
17 changes: 17 additions & 0 deletions include/SFML/Window/WindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ class SFML_WINDOW_API WindowBase
////////////////////////////////////////////////////////////
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
///
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@ bool WindowImplAndroid::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::setImePreeditPosition(const Vector2i& /* position */)
{
// Not applicable
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::forwardEvent(const Event& event)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ class WindowImplAndroid : public WindowImpl
////////////////////////////////////////////////////////////
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 WindowImplAndroid* singleInstance;

Expand Down
2 changes: 1 addition & 1 deletion src/SFML/Window/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ if(SFML_OS_LINUX)
sfml_find_package(UDev INCLUDE "UDEV_INCLUDE_DIR" LINK "UDEV_LIBRARIES")
target_link_libraries(sfml-window PRIVATE UDev dl)
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)
target_link_libraries(sfml-window PRIVATE usbhid)
elseif(SFML_OS_MACOSX)
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ bool WindowImplDRM::hasFocus() const
return true;
}


////////////////////////////////////////////////////////////
void WindowImplDRM::setImePreeditPosition(const Vector2i& /* position */)
{
// Not applicable
}

void WindowImplDRM::processEvents()
{
sf::Event ev;
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ class WindowImplDRM : public WindowImpl
////////////////////////////////////////////////////////////
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:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/OSX/WindowImplCocoa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ class WindowImplCocoa : public WindowImpl
////////////////////////////////////////////////////////////
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:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/OSX/WindowImplCocoa.mm
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,11 @@ void showMouseCursor()
}


////////////////////////////////////////////////////////////
void WindowImplCocoa::setImePreeditPosition(const Vector2i& /* position */)
{
// TODO: To implement
}


} // namespace sf::priv
10 changes: 10 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,16 @@ void WindowImplX11::grabFocus()
}


////////////////////////////////////////////////////////////
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::setVideoMode(const VideoMode& mode)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ class WindowImplX11 : public WindowImpl
////////////////////////////////////////////////////////////
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:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
15 changes: 15 additions & 0 deletions src/SFML/Window/Win32/WindowImplWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,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()
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Win32/WindowImplWin32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ class WindowImplWin32 : public WindowImpl
////////////////////////////////////////////////////////////
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:
////////////////////////////////////////////////////////////
/// \brief Process incoming events from the operating system
Expand Down
8 changes: 8 additions & 0 deletions src/SFML/Window/WindowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,14 @@ bool WindowBase::hasFocus() const
}


////////////////////////////////////////////////////////////
void WindowBase::setImePreeditPosition(const Vector2i& position)
{
if (m_impl)
m_impl->setImePreeditPosition(position);
}


////////////////////////////////////////////////////////////
WindowHandle WindowBase::getSystemHandle() const
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/WindowImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ class WindowImpl
////////////////////////////////////////////////////////////
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
///
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/iOS/WindowImplUIKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ class WindowImplUIKit : public WindowImpl
////////////////////////////////////////////////////////////
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;

public:
////////////////////////////////////////////////////////////
/// \brief Notify an event
Expand Down
7 changes: 7 additions & 0 deletions src/SFML/Window/iOS/WindowImplUIKit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@
}


////////////////////////////////////////////////////////////
void WindowImplUIKit::setImePreeditPosition(const Vector2i& /* position */)
{
// Not applicable
}


////////////////////////////////////////////////////////////
void WindowImplUIKit::forwardEvent(Event event)
{
Expand Down

0 comments on commit e04bcbb

Please sign in to comment.