Many changes, preparing to pull/merge main repo to get SDL_GetKeyboardFocus.
This commit is contained in:
parent
56aecc4828
commit
bfba97da7f
4 changed files with 117 additions and 12 deletions
|
@ -16,8 +16,18 @@ public:
|
||||||
|
|
||||||
LRESULT Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate);
|
LRESULT Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lParam, bool &Ate);
|
||||||
|
|
||||||
|
void Enable();
|
||||||
|
void Disable();
|
||||||
|
bool Is_Enabled();
|
||||||
|
void Toggle();
|
||||||
|
|
||||||
|
void Focus_Gained();
|
||||||
|
void Focus_Lost();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Update_Input_Locale();
|
void Update_Input_Locale();
|
||||||
|
void Cancel_Composition();
|
||||||
|
void Input_Language_Changed();
|
||||||
|
|
||||||
bool my_COM_Initialized;
|
bool my_COM_Initialized;
|
||||||
ITfThreadMgr *my_Thread_Manager;
|
ITfThreadMgr *my_Thread_Manager;
|
||||||
|
@ -25,6 +35,7 @@ private:
|
||||||
HIMC my_Context;
|
HIMC my_Context;
|
||||||
HKL my_HKL;
|
HKL my_HKL;
|
||||||
bool my_Vertical_Candidates;
|
bool my_Vertical_Candidates;
|
||||||
|
bool my_Enabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
#ifndef WINDOW_LISTENER_HPP
|
#ifndef WINDOW_LISTENER_HPP
|
||||||
#define WINDOW_LISTENER_HPP
|
#define WINDOW_LISTENER_HPP
|
||||||
|
|
||||||
|
enum Mouse_Button
|
||||||
|
{
|
||||||
|
Mouse_Button_Left,
|
||||||
|
Mouse_Button_Right
|
||||||
|
};
|
||||||
|
|
||||||
class Window_Listener
|
class Window_Listener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -9,6 +15,9 @@ public:
|
||||||
virtual void On_Key_Up(int Key){}
|
virtual void On_Key_Up(int Key){}
|
||||||
virtual void On_Char(unsigned int Char){}
|
virtual void On_Char(unsigned int Char){}
|
||||||
virtual void On_Resized(unsigned int Width, unsigned int Height){}
|
virtual void On_Resized(unsigned int Width, unsigned int Height){}
|
||||||
|
virtual void On_Mouse_Button_Down(Mouse_Button Button){}
|
||||||
|
virtual void On_Mouse_Button_Up(Mouse_Button Button){}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,8 @@ IMM::IMM() : my_COM_Initialized(false),
|
||||||
my_Window(0),
|
my_Window(0),
|
||||||
my_Context(0),
|
my_Context(0),
|
||||||
my_HKL(0),
|
my_HKL(0),
|
||||||
my_Vertical_Candidates(false)
|
my_Vertical_Candidates(false),
|
||||||
|
my_Enabled(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,11 +29,13 @@ void IMM::Initialize(HWND Window)
|
||||||
if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager))))
|
if (SUCCEEDED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<LPVOID *>(&my_Thread_Manager))))
|
||||||
{
|
{
|
||||||
ITfDocumentMgr *Document_Manager = 0;
|
ITfDocumentMgr *Document_Manager = 0;
|
||||||
if (FAILED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager)))
|
if (SUCCEEDED(my_Thread_Manager->AssociateFocus(Window, NULL, &Document_Manager)))
|
||||||
|
{
|
||||||
|
if (Document_Manager)
|
||||||
|
Document_Manager->Release();
|
||||||
|
}
|
||||||
|
else
|
||||||
printf("Warning: ITfThreadMgr->AssociateFocus failed\n");
|
printf("Warning: ITfThreadMgr->AssociateFocus failed\n");
|
||||||
|
|
||||||
if (Document_Manager)
|
|
||||||
Document_Manager->Release();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
printf("Warning: Failed to create ITfThreadMgr instance\n");
|
printf("Warning: Failed to create ITfThreadMgr instance\n");
|
||||||
|
@ -40,16 +43,16 @@ void IMM::Initialize(HWND Window)
|
||||||
else
|
else
|
||||||
printf("Warning: Failed to initialize COM\n");
|
printf("Warning: Failed to initialize COM\n");
|
||||||
|
|
||||||
ImmDisableTextFrameService(-1);
|
ImmDisableTextFrameService((DWORD)-1);
|
||||||
|
|
||||||
my_Context = ImmGetContext(my_Window);
|
my_Context = ImmGetContext(my_Window);
|
||||||
if (!ImmReleaseContext(my_Window, my_Context))
|
ImmReleaseContext(my_Window, my_Context);
|
||||||
throw std::runtime_error("Error releasing context");
|
|
||||||
|
|
||||||
if (!my_Context)
|
if (!my_Context)
|
||||||
throw std::runtime_error("No context");
|
throw std::runtime_error("No context (No IME installed?)");
|
||||||
|
|
||||||
Update_Input_Locale();
|
Update_Input_Locale();
|
||||||
|
Cancel_Composition();
|
||||||
|
Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMM::Finalize()
|
void IMM::Finalize()
|
||||||
|
@ -102,11 +105,10 @@ LRESULT IMM::Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lPa
|
||||||
switch (Message)
|
switch (Message)
|
||||||
{
|
{
|
||||||
case WM_INPUTLANGCHANGE:
|
case WM_INPUTLANGCHANGE:
|
||||||
Update_Input_Locale();
|
Input_Language_Changed();
|
||||||
break;
|
break;
|
||||||
case WM_IME_SETCONTEXT:
|
case WM_IME_SETCONTEXT:
|
||||||
lParam = 0;
|
lParam = 0;
|
||||||
return DefWindowProcW(my_Window, Message, wParam, lParam);
|
|
||||||
break;
|
break;
|
||||||
case WM_IME_STARTCOMPOSITION:
|
case WM_IME_STARTCOMPOSITION:
|
||||||
Ate = true;
|
Ate = true;
|
||||||
|
@ -158,8 +160,78 @@ LRESULT IMM::Handle_Message(HWND Window, UINT Message, WPARAM wParam, LPARAM lPa
|
||||||
case IMN_CHANGECANDIDATE:
|
case IMN_CHANGECANDIDATE:
|
||||||
Ate = true;
|
Ate = true;
|
||||||
break;
|
break;
|
||||||
|
case IMN_CLOSECANDIDATE:
|
||||||
|
Ate = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Ate = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IMM::Enable()
|
||||||
|
{
|
||||||
|
ImmAssociateContext(my_Window, my_Context);
|
||||||
|
Update_Input_Locale();
|
||||||
|
my_Enabled = true;
|
||||||
|
printf("* Enabled\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Disable()
|
||||||
|
{
|
||||||
|
ImmAssociateContext(my_Window, 0);
|
||||||
|
my_Enabled = false;
|
||||||
|
printf("* Disabled\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IMM::Is_Enabled()
|
||||||
|
{
|
||||||
|
return my_Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Toggle()
|
||||||
|
{
|
||||||
|
if (my_Enabled)
|
||||||
|
Disable();
|
||||||
|
else
|
||||||
|
Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Focus_Gained()
|
||||||
|
{
|
||||||
|
if (my_Enabled)
|
||||||
|
Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Focus_Lost()
|
||||||
|
{
|
||||||
|
bool Enabled = my_Enabled;
|
||||||
|
Cancel_Composition();
|
||||||
|
Disable();
|
||||||
|
my_Enabled = Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Cancel_Composition()
|
||||||
|
{
|
||||||
|
HIMC hIMC = ImmGetContext(my_Window);
|
||||||
|
if (!hIMC)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ImmNotifyIME(hIMC, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
|
||||||
|
ImmNotifyIME(hIMC, NI_CLOSECANDIDATE, 0, 0);
|
||||||
|
ImmReleaseContext(my_Window, hIMC);
|
||||||
|
}
|
||||||
|
|
||||||
|
void IMM::Input_Language_Changed()
|
||||||
|
{
|
||||||
|
Update_Input_Locale();
|
||||||
|
HWND hwndImeDef = ImmGetDefaultIMEWnd(my_Window);
|
||||||
|
if (hwndImeDef)
|
||||||
|
{
|
||||||
|
SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_OPENSTATUSWINDOW, 0);
|
||||||
|
SendMessageA(hwndImeDef, WM_IME_CONTROL, IMC_CLOSESTATUSWINDOW, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ void Window::Initialize(const std::wstring &Title, const Video_Mode &Mode, bool
|
||||||
my_Fullscreen = Fullscreen;
|
my_Fullscreen = Fullscreen;
|
||||||
Register_Class();
|
Register_Class();
|
||||||
Create_Window(Title, Mode, Fullscreen);
|
Create_Window(Title, Mode, Fullscreen);
|
||||||
|
Show();
|
||||||
my_IMM.Initialize(my_Handle);
|
my_IMM.Initialize(my_Handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,6 +297,18 @@ LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM
|
||||||
case WM_KILLFOCUS:
|
case WM_KILLFOCUS:
|
||||||
my_IMM.Focus_Lost();
|
my_IMM.Focus_Lost();
|
||||||
break;
|
break;
|
||||||
|
case WM_LBUTTONDOWN:
|
||||||
|
Call_Listener(On_Mouse_Button_Down(Mouse_Button_Left));
|
||||||
|
break;
|
||||||
|
case WM_LBUTTONUP:
|
||||||
|
Call_Listener(On_Mouse_Button_Up(Mouse_Button_Left));
|
||||||
|
break;
|
||||||
|
case WM_RBUTTONDOWN:
|
||||||
|
Call_Listener(On_Mouse_Button_Down(Mouse_Button_Right));
|
||||||
|
break;
|
||||||
|
case WM_RBUTTONUP:
|
||||||
|
Call_Listener(On_Mouse_Button_Up(Mouse_Button_Right));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return DefWindowProcW(Handle, Message, wParam, lParam);
|
return DefWindowProcW(Handle, Message, wParam, lParam);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue