wxRichTextCtrl is funky when inputting Japanese characters using input method

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

wxRichTextCtrl is funky when inputting Japanese characters using input method

Post by beneficii » Fri Feb 08, 2019 5:50 am

I'm using Windows 10 Home 64-bit, and normally when I enter Japanese characters in a textbox, it works like this:
スクリーンショット (5).png
As you type it and the suggestions pop up, the text you're typing (underlined with a wavy green line) is inside the textbox.

But with wxRichTextCtrl, when you're typing it in, it doesn't appear in the textbox; instead it appears way up on the upper left-hand corner of the screen. This happened as I typed in the wxRichTextCtrl which is in the small window in the middle of the screen:
スクリーンショット (7).png
What is causing this, and how can I fix it?

ueda
In need of some credit
In need of some credit
Posts: 1
Joined: Thu Aug 01, 2019 5:07 pm

Re: wxRichTextCtrl is funky when inputting Japanese characters using input method

Post by ueda » Thu Aug 01, 2019 5:21 pm

I realize this was asked a few months ago, but I found the solution here: https://osdn.net/projects/wxwindowsjp/f ... 489/30467/

Minimal sample:

Code: Select all

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/richtext/richtextctrl.h>
class richctrl:public wxRichTextCtrl{
public:
 richctrl(wxWindow* parent,wxWindowID id,const wxString& value=wxEmptyString,const wxPoint& pos=wxDefaultPosition,
          const wxSize& size=wxDefaultSize,long style=0x0020, const wxValidator& validator=wxDefaultValidator,const wxString& name=wxTextCtrlNameStr)
  :wxRichTextCtrl(parent,id,value,pos,size,style,validator,name){}
 HIMC hIME=ImmGetContext(m_hWnd);
 WXLRESULT MSWWindowProc(WXUINT nMsg,WXWPARAM wParam,WXLPARAM lParam) override{
  if(nMsg==WM_IME_STARTCOMPOSITION){
   COMPOSITIONFORM form;
   ImmGetCompositionWindow(hIME,&form);
   wxCaret* c=GetCaret();
   wxPoint p=c->GetPosition();
   form.dwStyle=CFS_POINT;
   form.ptCurrentPos.x=p.x;
   form.ptCurrentPos.y=p.y;
   ImmSetCompositionWindow(hIME,&form);
  }
  return wxWindow::MSWWindowProc(nMsg,wParam,lParam);
 }
};
class MyApp:public wxApp{
public:
 virtual bool OnInit(){
  wxFrame *frame=new wxFrame(NULL,wxID_ANY,"IME");
  new richctrl(frame,wxID_ANY);
  frame->Show();
  return true;
 }
};
wxIMPLEMENT_APP(MyApp);
You might have to link with imm32.lib, winmm.lib and/or Ws2_32.lib.

Post Reply