changeset 4734:0c7c67d4e6ee

Added On_Char method to Window_Listener for WM_CHAR messages. Removed a lot of TSF code because part of it was wrong and part was too complicated. Added Clear method to clear the window. IME input should work in both windowed mode and fullscreen mode with these changes. I have tested on Windows XP SP3 and Windows 7 Ultimate in VirtualBox. When you type a character (with an IME or not), the console will show the code point as U+XXXX. You use Left Alt+Shift (or whatever you have it set to) to switch input languages as usual. Hit ESC to exit (or close the window in windowed mode). The program will pause before exiting so you can review the console output (press a key to exit).
author dewyatt
date Wed, 09 Jun 2010 00:03:54 -0400
parents 983eb9d5ed31
children 8568ebdb5f1f
files EXCLUDE/GLTSF/include/App.hpp EXCLUDE/GLTSF/include/TSF.hpp EXCLUDE/GLTSF/include/Window.hpp EXCLUDE/GLTSF/include/Window_Listener.hpp EXCLUDE/GLTSF/src/App.cpp EXCLUDE/GLTSF/src/Main.cpp EXCLUDE/GLTSF/src/TSF.cpp EXCLUDE/GLTSF/src/Window.cpp
diffstat 8 files changed, 66 insertions(+), 168 deletions(-) [+]
line wrap: on
line diff
--- a/EXCLUDE/GLTSF/include/App.hpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/include/App.hpp	Wed Jun 09 00:03:54 2010 -0400
@@ -17,8 +17,14 @@
 	virtual void On_Close();
 	virtual void On_Key_Down(int Key);
 	virtual void On_Key_Up(int Key);
+	virtual void On_Char(unsigned int Char);
 
 private:
+	static const int Width = 800;
+	static const int Height = 600;
+	static const int Bits_Per_Pixel = 32;
+	static const bool Fullscreen = false;
+
 	Window my_Window;
 	bool my_Done;
 };
--- a/EXCLUDE/GLTSF/include/TSF.hpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/include/TSF.hpp	Wed Jun 09 00:03:54 2010 -0400
@@ -7,51 +7,15 @@
 class TSF
 {
 public:
-
-protected:
-	class UI_Sink : public ITfUIElementSink, public ITfInputProcessorProfileActivationSink
-	{
-	public:
-		UI_Sink();
-		~UI_Sink();
-
-		// IUnknown
-		STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
-		STDMETHODIMP_(ULONG) AddRef(void);
-		STDMETHODIMP_(ULONG) Release(void);
-
-		// ITfUIElementSink
-		STDMETHODIMP BeginUIElement(DWORD dwUIElementId, BOOL *pbShow);
-		STDMETHODIMP UpdateUIElement(DWORD dwUIElementId);
-		STDMETHODIMP EndUIElement(DWORD dwUIElementId);
-
-		// ITfInputProcessorProfileActivationSink
-		STDMETHODIMP OnActivated(DWORD dwProfileType, LANGID langid,
-								 REFCLSID clsid, REFGUID catid,
-								 REFGUID guidProfile, HKL hkl,
-								 DWORD dwFlags);
-
-		// ITfCompartmentEventSink
-		STDMETHODIMP OnChange(REFGUID rguid);
-
-	private:
-		LONG my_Reference_Count;
-	};
-
-	TSF();
-	~TSF();
-
-	void Initialize();
-	void Finalize();
+	static void Initialize();
+	static void Finalize();
 
 private:
-	bool my_COM_Initialized;
+	TSF();
 
-	CComPtr<ITfThreadMgrEx> my_Thread_Manager;
-	UI_Sink *my_UI_Sink;
+	static bool COM_Initialized;
 
-	DWORD my_UI_Element_Sink_Cookie;
-	DWORD my_IPPA_Sink_Cookie;
+	static CComPtr<ITfThreadMgr> Thread_Manager;
 };
 
 #endif
--- a/EXCLUDE/GLTSF/include/Window.hpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/include/Window.hpp	Wed Jun 09 00:03:54 2010 -0400
@@ -8,6 +8,7 @@
 
 #include "Video_Mode.hpp"
 #include "Window_Listener.hpp"
+#include "TSF.hpp"
 
 class Window
 {
@@ -26,6 +27,8 @@
 	void Update();
 	void Display();
 
+	void Clear();
+
 private:
 	static const wchar_t *Window_Class_Name;
 
--- a/EXCLUDE/GLTSF/include/Window_Listener.hpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/include/Window_Listener.hpp	Wed Jun 09 00:03:54 2010 -0400
@@ -8,6 +8,7 @@
 
 	virtual void On_Key_Down(int Key){}
 	virtual void On_Key_Up(int Key){}
+	virtual void On_Char(unsigned int Char){}
 };
 
 #endif
--- a/EXCLUDE/GLTSF/src/App.cpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/src/App.cpp	Wed Jun 09 00:03:54 2010 -0400
@@ -1,20 +1,22 @@
 #include "App.hpp"
+#include "TSF.hpp"
 
 App::App() : my_Done(false)
 {
-
+	TSF::Initialize();
 }
 
 App::~App()
 {
 	Finalize();
+	TSF::Finalize();
 }
 
 void App::Initialize()
 {
 	Finalize();
 
-	my_Window.Initialize(L"GLTSF", Video_Mode(800, 600, 32), false);
+	my_Window.Initialize(L"GLTSF", Video_Mode(Width, Height, Bits_Per_Pixel), Fullscreen);
 	my_Window.Set_Listener(this);
 	my_Window.Show();
 }
@@ -30,6 +32,7 @@
 	while (!my_Done)
 	{
 		my_Window.Update();
+		my_Window.Clear();
 		my_Window.Display();
 	}
 }
@@ -54,3 +57,8 @@
 {
 
 }
+
+void App::On_Char(unsigned int Char)
+{
+	printf("Char: U+%04X\n", Char);
+}
--- a/EXCLUDE/GLTSF/src/Main.cpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/src/Main.cpp	Wed Jun 09 00:03:54 2010 -0400
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+	int Result = EXIT_SUCCESS;
 	try
 	{
 		App theApp;
@@ -11,7 +12,13 @@
 	catch (const std::exception& e)
 	{
 		printf("Error: %s\n", e.what());
-		return 1;
+		Result = EXIT_FAILURE;
 	}
-	return 0;
+	catch (...)
+	{
+		printf("Unhandled exception\n");
+		Result = EXIT_FAILURE;
+	}
+	system("PAUSE");
+	return Result;
 }
--- a/EXCLUDE/GLTSF/src/TSF.cpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/src/TSF.cpp	Wed Jun 09 00:03:54 2010 -0400
@@ -1,140 +1,40 @@
 #include "TSF.hpp"
 #include <stdexcept>
 
-TSF::TSF() : my_COM_Initialized(false),
-			 my_UI_Sink(0),
-			 my_UI_Element_Sink_Cookie(TF_INVALID_COOKIE),
-			 my_IPPA_Sink_Cookie(TF_INVALID_COOKIE)
-{
-
-}
-
-TSF::~TSF()
-{
-	Finalize();
-}
+bool TSF::COM_Initialized = false;
+CComPtr<ITfThreadMgr> TSF::Thread_Manager;
 
 void TSF::Initialize()
 {
-	Finalize();
-
-	if (S_OK != CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))
-		throw std::runtime_error("Failed to initialize COM");
-
-	my_COM_Initialized = true;
-	if (S_OK != CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, __uuidof(ITfThreadMgrEx), (void **)&my_Thread_Manager))
-		throw std::runtime_error("Failed to create ITfThreadMgrEx instance");
+	if (!COM_Initialized)
+	{
+		HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+		if (S_OK != hr && S_FALSE != hr)
+			throw std::runtime_error("Failed to initialize COM");
 
-	TfClientId Client_Id = 0;
-	if (FAILED(my_Thread_Manager->ActivateEx(&Client_Id, TF_TMAE_UIELEMENTENABLEDONLY)))
-		throw std::runtime_error("ITfThreadMgrEx::ActivateEx failed");
+		COM_Initialized = true;
+	}
+	if (!Thread_Manager)
+	{
+		if (FAILED(CoCreateInstance(CLSID_TF_ThreadMgr, NULL, CLSCTX_INPROC_SERVER, IID_ITfThreadMgr, reinterpret_cast<void **>(&Thread_Manager))))
+			throw std::runtime_error("Failed to create ITfThreadMgr instance");
 
-	my_UI_Sink = new UI_Sink();
-	ITfSource *Source = NULL;
-	if (FAILED(my_Thread_Manager->QueryInterface(__uuidof(ITfSource), (void **)&Source)))
-		throw std::runtime_error("QueryInterface failed");
-
-	if (FAILED(Source->AdviseSink(__uuidof(ITfUIElementSink), (ITfUIElementSink *)my_UI_Sink, &my_UI_Element_Sink_Cookie)))
-		throw std::runtime_error("AdviseSink failed");
-
-	if (FAILED(Source->AdviseSink(__uuidof(ITfInputProcessorProfileActivationSink), (ITfInputProcessorProfileActivationSink *)my_UI_Sink, &my_IPPA_Sink_Cookie)))
-		throw std::runtime_error("AdviseSink failed");
+		TfClientId ClientId;
+		if (FAILED(Thread_Manager->Activate(&ClientId)))
+			throw std::runtime_error("ITfThreadMgr::Activate failed");
+	}
 }
 
 void TSF::Finalize()
 {
-	if (my_UI_Sink)
+	if (Thread_Manager)
 	{
-		ITfSource *Source = NULL;
-		if (SUCCEEDED(my_Thread_Manager->QueryInterface(__uuidof(ITfSource), (void **)&Source)))
-		{
-			Source->UnadviseSink(my_IPPA_Sink_Cookie);
-			Source->UnadviseSink(my_UI_Element_Sink_Cookie);
-			Source->Release();
-		}
-		if (my_Thread_Manager)
-			my_Thread_Manager->Deactivate();
-
-		my_UI_Sink->Release();
-		delete my_UI_Sink;
-		my_UI_Sink = NULL;
+		Thread_Manager->Deactivate();
+		Thread_Manager = NULL;
 	}
-	my_Thread_Manager = NULL;
-	if (my_COM_Initialized)
+	if (COM_Initialized)
 	{
 		CoUninitialize();
-		my_COM_Initialized = false;
+		COM_Initialized = false;
 	}
 }
-
-TSF::UI_Sink::UI_Sink()
-{
-	my_Reference_Count = 1;
-}
-
-TSF::UI_Sink::~UI_Sink()
-{
-
-}
-
-STDMETHODIMP TSF::UI_Sink::QueryInterface(REFIID riid, void **ppvObj)
-{
-	if (NULL == ppvObj)
-		return E_INVALIDARG;
-
-	*ppvObj = NULL;
-	if (IsEqualIID(riid, IID_IUnknown))
-		*ppvObj = reinterpret_cast<IUnknown *>(this);
-	else if (IsEqualIID(riid, __uuidof(ITfUIElementSink)))
-		*ppvObj = reinterpret_cast<ITfUIElementSink *>(this);
-	else if (IsEqualIID(riid, __uuidof(ITfInputProcessorProfileActivationSink)))
-		*ppvObj = reinterpret_cast<ITfInputProcessorProfileActivationSink *>(this);
-	else if (IsEqualIID(riid, __uuidof(ITfCompartmentEventSink)))
-		*ppvObj = reinterpret_cast<ITfCompartmentEventSink *>(this);
-
-	if (*ppvObj)
-	{
-		AddRef();
-		return S_OK;
-	}
-	return E_NOINTERFACE;
-}
-
-ULONG TSF::UI_Sink::AddRef(void)
-{
-	return ++my_Reference_Count;
-}
-
-ULONG TSF::UI_Sink::Release(void)
-{
-	LONG Count = --my_Reference_Count;
-	if (0 == Count)
-		delete this;
-
-	return Count;
-}
-
-STDMETHODIMP TSF::UI_Sink::BeginUIElement(DWORD dwUIElementId, BOOL *pbShow)
-{
-	return S_OK;
-}
-
-STDMETHODIMP TSF::UI_Sink::UpdateUIElement(DWORD dwUIElementId)
-{
-	return S_OK;
-}
-
-STDMETHODIMP TSF::UI_Sink::EndUIElement(DWORD dwUIElementId)
-{
-	return S_OK;
-}
-
-STDMETHODIMP TSF::UI_Sink::OnActivated(DWORD dwProfileType, LANGID langid, REFCLSID clsid, REFGUID catid, REFGUID guidProfile, HKL hkl, DWORD dwFlags)
-{
-	return S_OK;
-}
-
-STDMETHODIMP TSF::UI_Sink::OnChange(REFGUID rguid)
-{
-	return S_OK;
-}
--- a/EXCLUDE/GLTSF/src/Window.cpp	Tue Jun 08 05:22:49 2010 -0400
+++ b/EXCLUDE/GLTSF/src/Window.cpp	Wed Jun 09 00:03:54 2010 -0400
@@ -1,4 +1,5 @@
 #include "Window.hpp"
+#include <gl/GL.h>
 
 #pragma comment(lib, "opengl32.lib")
 
@@ -83,7 +84,7 @@
 	int Height = my_Video_Mode.Height;
 	ReleaseDC(NULL, Screen_DC);
 
-	DWORD Style = WS_OVERLAPPEDWINDOW;
+	DWORD Style = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
 	if (!my_Fullscreen)
 	{
 		RECT Rect = {0, 0, Width, Height};
@@ -227,6 +228,9 @@
 	case WM_KEYUP:
 		Call_Listener(On_Key_Up(wParam));
 		break;
+	case WM_CHAR:
+		Call_Listener(On_Char(wParam));
+		break;
 	default:
 		return DefWindowProcW(Handle, Message, wParam, lParam);
 		break;
@@ -261,3 +265,8 @@
 	if (my_Device_Context && my_GL_Context)
 		SwapBuffers(my_Device_Context);
 }
+
+void Window::Clear()
+{
+	glClear(GL_COLOR_BUFFER_BIT);
+}