Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added On_Char method to Window_Listener for WM_CHAR messages.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
dewyatt committed Jun 9, 2010
1 parent 683b09d commit 64169f7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 168 deletions.
6 changes: 6 additions & 0 deletions EXCLUDE/GLTSF/include/App.hpp
Expand Up @@ -17,8 +17,14 @@ class App : public Window_Listener
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;
};
Expand Down
46 changes: 5 additions & 41 deletions EXCLUDE/GLTSF/include/TSF.hpp
Expand Up @@ -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
3 changes: 3 additions & 0 deletions EXCLUDE/GLTSF/include/Window.hpp
Expand Up @@ -8,6 +8,7 @@

#include "Video_Mode.hpp"
#include "Window_Listener.hpp"
#include "TSF.hpp"

class Window
{
Expand All @@ -26,6 +27,8 @@ class Window
void Update();
void Display();

void Clear();

private:
static const wchar_t *Window_Class_Name;

Expand Down
1 change: 1 addition & 0 deletions EXCLUDE/GLTSF/include/Window_Listener.hpp
Expand Up @@ -8,6 +8,7 @@ class Window_Listener

virtual void On_Key_Down(int Key){}
virtual void On_Key_Up(int Key){}
virtual void On_Char(unsigned int Char){}
};

#endif
12 changes: 10 additions & 2 deletions EXCLUDE/GLTSF/src/App.cpp
@@ -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();
}
Expand All @@ -30,6 +32,7 @@ void App::Run()
while (!my_Done)
{
my_Window.Update();
my_Window.Clear();
my_Window.Display();
}
}
Expand All @@ -54,3 +57,8 @@ void App::On_Key_Up(int Key)
{

}

void App::On_Char(unsigned int Char)
{
printf("Char: U+%04X\n", Char);
}
11 changes: 9 additions & 2 deletions EXCLUDE/GLTSF/src/Main.cpp
Expand Up @@ -3,6 +3,7 @@

int main(int argc, char *argv[])
{
int Result = EXIT_SUCCESS;
try
{
App theApp;
Expand All @@ -11,7 +12,13 @@ int main(int argc, char *argv[])
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;
}
144 changes: 22 additions & 122 deletions EXCLUDE/GLTSF/src/TSF.cpp
@@ -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");

TfClientId Client_Id = 0;
if (FAILED(my_Thread_Manager->ActivateEx(&Client_Id, TF_TMAE_UIELEMENTENABLEDONLY)))
throw std::runtime_error("ITfThreadMgrEx::ActivateEx failed");

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 (!COM_Initialized)
{
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (S_OK != hr && S_FALSE != hr)
throw std::runtime_error("Failed to initialize COM");

if (FAILED(Source->AdviseSink(__uuidof(ITfUIElementSink), (ITfUIElementSink *)my_UI_Sink, &my_UI_Element_Sink_Cookie)))
throw std::runtime_error("AdviseSink 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");

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;
}
11 changes: 10 additions & 1 deletion EXCLUDE/GLTSF/src/Window.cpp
@@ -1,4 +1,5 @@
#include "Window.hpp"
#include <gl/GL.h>

#pragma comment(lib, "opengl32.lib")

Expand Down Expand Up @@ -83,7 +84,7 @@ void Window::Create_Window(const std::wstring &Title, const Video_Mode &Mode, bo
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};
Expand Down Expand Up @@ -227,6 +228,9 @@ LRESULT Window::Handle_Message(HWND Handle, UINT Message, WPARAM wParam, LPARAM
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;
Expand Down Expand Up @@ -261,3 +265,8 @@ void Window::Display()
if (my_Device_Context && my_GL_Context)
SwapBuffers(my_Device_Context);
}

void Window::Clear()
{
glClear(GL_COLOR_BUFFER_BIT);
}

0 comments on commit 64169f7

Please sign in to comment.