Commit 5af59ada authored by Davis King's avatar Davis King

Applied another Unicode patch from Keita Mochizuki.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402362
parent c4629db6
...@@ -1950,6 +1950,24 @@ namespace dlib ...@@ -1950,6 +1950,24 @@ namespace dlib
} }
} }
// ----------------------------------------------------------------------------------------
void base_window::
set_im_pos (
long x,
long y
)
{
HIMC hImc = ImmGetContext(hwnd);
COMPOSITIONFORM cf;
cf.dwStyle = CFS_POINT;
cf.ptCurrentPos.x = x;
cf.ptCurrentPos.y = y;
ImmSetCompositionWindow(hImc, &cf);
ImmReleaseContext(hwnd, hImc);
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
void put_on_clipboard ( void put_on_clipboard (
......
...@@ -254,6 +254,11 @@ namespace dlib ...@@ -254,6 +254,11 @@ namespace dlib
void wait_until_closed ( void wait_until_closed (
) const; ) const;
void set_im_pos (
long x_,
long y_
);
enum on_close_return_code enum on_close_return_code
{ {
DO_NOT_CLOSE_WINDOW, DO_NOT_CLOSE_WINDOW,
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "../sync_extension.h" #include "../sync_extension.h"
#include "../logger.h" #include "../logger.h"
#include <vector> #include <vector>
#include <set>
namespace dlib namespace dlib
{ {
...@@ -47,7 +48,8 @@ namespace dlib ...@@ -47,7 +48,8 @@ namespace dlib
int depth; int depth;
Display* disp; Display* disp;
XIM xim; static XIM xim;
static XIMStyle xim_style;
static Screen* screen; static Screen* screen;
Atom delete_window; Atom delete_window;
...@@ -529,18 +531,24 @@ namespace dlib ...@@ -529,18 +531,24 @@ namespace dlib
KeySym key; KeySym key;
Status status; Status status;
std::wstring wstr; if (win->x11_stuff.xic) {
wstr.resize(2); std::wstring wstr;
int len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status); wstr.resize(2);
if (status == XBufferOverflow){ int len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status);
wstr.resize(len); if (status == XBufferOverflow){
len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status); wstr.resize(len);
} len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status);
if (status == XLookupChars){ }
win->on_string_put(wstr); if (status == XLookupChars){
win->on_string_put(wstr);
}
} else {
char buffer[2];
XLookupString(e, buffer, sizeof(buffer), &key, NULL);
status = XLookupKeySym;
} }
else if (status == XLookupKeySym || status == XLookupBoth){ if (status == XLookupKeySym || status == XLookupBoth){
bool is_printable; bool is_printable;
unsigned long result; unsigned long result;
...@@ -1098,10 +1106,36 @@ namespace dlib ...@@ -1098,10 +1106,36 @@ namespace dlib
xim = NULL; xim = NULL;
window_table.get_mutex().lock(); window_table.get_mutex().lock();
if (setlocale( LC_CTYPE, "" ) && XSupportsLocale() && XSetLocaleModifiers("")){ if (setlocale( LC_CTYPE, "" ) && XSupportsLocale() && XSetLocaleModifiers("")){
xim = XOpenIM(disp, NULL, NULL, NULL); xim = XOpenIM(disp, NULL, NULL, NULL);
} }
window_table.get_mutex().unlock(); window_table.get_mutex().unlock();
if (xim)
{
const static XIMStyle preedit_styles[] =
{XIMPreeditPosition, XIMPreeditNothing, XIMPreeditNone, 0};
const static XIMStyle status_styles[] =
{XIMStatusNothing, XIMStatusNone, 0};
xim_style = 0;
XIMStyles *xim_styles;
window_table.get_mutex().lock();
XGetIMValues (xim, XNQueryInputStyle, &xim_styles, NULL);
window_table.get_mutex().unlock();
std::set<XIMStyle> xims;
for (int i = 0; i < xim_styles->count_styles; ++i){
xims.insert(xim_styles->supported_styles[i]);
}
for (int j = 0; status_styles[j]; ++j){
for (int i = 0; preedit_styles[i]; ++i){
xim_style = (status_styles[j] | preedit_styles[i]);
if (xims.count(xim_style)) break;
}
if (xim_style) break;
}
}
// make this window just so we can send messages to it and trigger // make this window just so we can send messages to it and trigger
// events in the event thread // events in the event thread
XSetWindowAttributes attr; XSetWindowAttributes attr;
...@@ -1528,12 +1562,26 @@ namespace dlib ...@@ -1528,12 +1562,26 @@ namespace dlib
x11_stuff.xic = NULL; x11_stuff.xic = NULL;
if (gui_core_kernel_2_globals::xim) if (gui_core_kernel_2_globals::xim)
{ {
XVaNestedList xva_nlist;
XPoint xpoint;
char **mlist;
int mcount;
char *def_str;
char fontset[256];
sprintf(fontset, "-*-*-medium-r-normal--%lu-*-*-*-", get_native_font()->height());
XFontSet fs = XCreateFontSet(gui_core_kernel_2_globals::disp, fontset, &mlist, &mcount, &def_str);
xpoint.x = 0;
xpoint.y = 0;
xva_nlist = XVaCreateNestedList(0, XNSpotLocation, &xpoint, XNFontSet, fs, NULL);
x11_stuff.xic = XCreateIC( x11_stuff.xic = XCreateIC(
gui_core_kernel_2_globals::xim, gui_core_kernel_2_globals::xim,
XNInputStyle, XIMPreeditNothing | XIMStatusNothing, XNInputStyle, gui_core_kernel_2_globals::xim_style,
XNClientWindow, x11_stuff.hwnd, XNClientWindow, x11_stuff.hwnd,
XNPreeditAttributes, xva_nlist,
NULL NULL
); );
XFree(xva_nlist);
} }
Window temp = x11_stuff.hwnd; Window temp = x11_stuff.hwnd;
...@@ -1542,7 +1590,8 @@ namespace dlib ...@@ -1542,7 +1590,8 @@ namespace dlib
// query event mask required by input method // query event mask required by input method
unsigned long event_xim = 0; unsigned long event_xim = 0;
XGetICValues( x11_stuff.xic, XNFilterEvents, &event_xim, NULL ); if (x11_stuff.xic)
XGetICValues( x11_stuff.xic, XNFilterEvents, &event_xim, NULL );
XSelectInput( XSelectInput(
gui_core_kernel_2_globals::disp, gui_core_kernel_2_globals::disp,
...@@ -1601,9 +1650,11 @@ namespace dlib ...@@ -1601,9 +1650,11 @@ namespace dlib
has_been_destroyed = true; has_been_destroyed = true;
gui_core_kernel_2_globals::window_table.destroy(x11_stuff.hwnd); gui_core_kernel_2_globals::window_table.destroy(x11_stuff.hwnd);
if (x11_stuff.xic)
XDestroyIC(x11_stuff.xic); {
x11_stuff.xic = 0; XDestroyIC(x11_stuff.xic);
x11_stuff.xic = 0;
}
XDestroyWindow(gui_core_kernel_2_globals::disp,x11_stuff.hwnd); XDestroyWindow(gui_core_kernel_2_globals::disp,x11_stuff.hwnd);
x11_stuff.hwnd = 0; x11_stuff.hwnd = 0;
...@@ -1864,6 +1915,28 @@ namespace dlib ...@@ -1864,6 +1915,28 @@ namespace dlib
} }
} }
// ----------------------------------------------------------------------------------------
void base_window::
set_im_pos (
long x,
long y
)
{
auto_mutex a(wm);
if (!x11_stuff.xic || !(gui_core_kernel_2_globals::xim_style & XIMPreeditPosition)) return;
XVaNestedList xva_nlist;
XPoint xpoint;
xpoint.x = x;
xpoint.y = y;
xva_nlist = XVaCreateNestedList(0, XNSpotLocation, &xpoint, NULL);
XSetICValues(x11_stuff.xic, XNPreeditAttributes, xva_nlist, NULL);
XFree(xva_nlist);
}
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -262,6 +262,11 @@ namespace dlib ...@@ -262,6 +262,11 @@ namespace dlib
void wait_until_closed ( void wait_until_closed (
) const; ) const;
void set_im_pos (
long x_,
long y_
);
bool is_closed ( bool is_closed (
) const; ) const;
......
...@@ -498,6 +498,16 @@ namespace dlib ...@@ -498,6 +498,16 @@ namespace dlib
the given arguments. the given arguments.
!*/ !*/
void set_im_pos (
long x_,
long y_
);
/*!
ensures
- sets the left-top position of input method rectangle used
for wide character input methods.
!*/
protected: protected:
const rmutex& wm; const rmutex& wm;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// License: Boost Software License See LICENSE.txt for the full license. // License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_IGG_FONT_RENDERER_H_ #ifndef DLIB_IGG_FONT_RENDERER_H_
#define DLIB_IGG_FONT_RENDERER_H_ #define DLIB_IGG_FONT_RENDERER_H_
#include "../platform.h"
#include "../gui_widgets.h" #include "../gui_widgets.h"
#include "../unicode.h" #include "../unicode.h"
...@@ -13,10 +15,10 @@ ...@@ -13,10 +15,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <locale.h> #include <locale.h>
#ifdef WIN32 #if defined(WIN32)
#include <windows.h> #include <windows.h>
#include <mbstring.h> #include <mbstring.h>
#else #elif defined(POSIX)
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
...@@ -41,28 +43,28 @@ namespace nativefont ...@@ -41,28 +43,28 @@ namespace nativefont
#ifdef WIN32 #ifdef WIN32
template <typename T> struct input2native_trait{ template <typename T> struct input2native_trait{
}; };
template <> struct input2native_trait<char>{ template <> struct input2native_trait<char>{
typedef char type_t; typedef char type_t;
}; };
template <> struct input2native_trait<wchar_t>{ template <> struct input2native_trait<wchar_t>{
typedef wchar_t type_t; typedef wchar_t type_t;
}; };
template <> struct input2native_trait<dlib::unichar>{ template <> struct input2native_trait<dlib::unichar>{
typedef wchar_t type_t; typedef wchar_t type_t;
}; };
#endif #endif
// T : N : sizeof_source_type // T : N : sizeof_source_type
template <int N> struct size2inner_trait{ template <int N> struct size2inner_trait{
}; };
template <> struct size2inner_trait<1>{ template <> struct size2inner_trait<1>{
typedef char type_t; typedef char type_t;
}; };
template <> struct size2inner_trait<2>{ template <> struct size2inner_trait<2>{
typedef uint16_t type_t; typedef uint16_t type_t;
}; };
template <> struct size2inner_trait<4>{ template <> struct size2inner_trait<4>{
typedef dlib::unichar type_t; typedef dlib::unichar type_t;
}; };
...@@ -70,69 +72,67 @@ namespace nativefont ...@@ -70,69 +72,67 @@ namespace nativefont
template <int N> struct create_helper{ }; template <int N> struct create_helper{ };
template <> struct create_helper<1>{ template <> struct create_helper<1>{
typedef char type_t; typedef char type_t;
type_t *istr; type_t *istr;
int len; int len;
create_helper(char *str){ create_helper(char *str){
len = (int)strlen(str); len = (int)strlen(str);
istr = str; istr = str;
} }
~create_helper(){} ~create_helper(){}
}; };
template <> struct create_helper<2>{ template <> struct create_helper<2>{
typedef wchar_t type_t; typedef wchar_t type_t;
type_t *istr; type_t *istr;
bool allocated; bool allocated;
int len; int len;
create_helper(wchar_t *str){ create_helper(wchar_t *str){
allocated = false; allocated = false;
len = (int)wcslen(str); len = (int)wcslen(str);
istr = str; istr = str;
}
create_helper(dlib::unichar *str){
allocated = true;
len = 0;
int unicount = 0;
dlib::unichar *p = str;
while(*p){
if (*p > 0xffff){
len += 2;
}else{
len++;
} }
create_helper(dlib::unichar *str){ unicount++;
allocated = true; p++;
len = 0; }
int unicount = 0; istr = new wchar_t[len+1];
dlib::unichar *p = str; for (int i = 0, wi = 0; i < unicount; ++i){
while(*p){ dlib::unichar high, low;
if (*p > 0xffff){ if (str[i] > 0xffff){
len += 2; dlib::unichar_to_surrogate_pair(str[i], high, low);
}else{ istr[wi] = (wchar_t)high, istr[wi+1] = (wchar_t)low;
len++; wi += 2;
} }else{
unicount++; istr[wi] = (wchar_t)str[i];
p++; wi += 1;
}
istr = new wchar_t[len+1];
for (int i = 0, wi = 0; i < unicount; ++i){
dlib::unichar high, low;
if (str[i] > 0xffff){
dlib::unichar_to_surrogate_pair(str[i], high, low);
istr[wi] = (wchar_t)high, istr[wi+1] = (wchar_t)low;
wi += 2;
}else{
istr[wi] = (wchar_t)str[i];
wi += 1;
}
}
istr[len] = L'\0';
// printf("unicount:%d, len:%d wcslen:%d\n", unicount, len, wcslen(istr));
} }
}
istr[len] = L'\0';
}
~create_helper(){ ~create_helper(){
if (allocated) delete[] istr; if (allocated) delete[] istr;
} }
}; };
template <> struct create_helper<4>{ template <> struct create_helper<4>{
typedef wchar_t type_t; typedef wchar_t type_t;
type_t *istr; type_t *istr;
int len; int len;
create_helper(dlib::unichar *str){ create_helper(dlib::unichar *str){
len = (int)wcslen((wchar_t *)str); len = (int)wcslen((wchar_t *)str);
istr = (type_t *)str; istr = (type_t *)str;
// printf("len:%d\n", len); }
} ~create_helper(){}
~create_helper(){}
}; };
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
...@@ -298,7 +298,7 @@ namespace nativefont ...@@ -298,7 +298,7 @@ namespace nativefont
~vals_internal(){ ~vals_internal(){
destroy(); destroy();
} }
#else #elif defined(POSIX)
XImage *ximg; XImage *ximg;
Display *d; Display *d;
GC gc; GC gc;
...@@ -588,13 +588,6 @@ namespace nativefont ...@@ -588,13 +588,6 @@ namespace nativefont
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
} }
// history
// 2006/07/10 ver 1.10 Win32 と X11 で共通している部分の重複を無くした
// 2007/08/15 dlib用に修正
// 2007/12/16 unicode(UTF32)に対応した
// 2008/01/02 ver 2.00 dlib ver 16.1 で任意のフォントクラスをアプリケーション側で
// 指定できるようになり、dlibとこのクラスを分離して扱えるよう
// になった。この変更に合わせて、名前空間を変更した。
#endif // DLIB_IGG_FONT_RENDERER_H_ #endif // DLIB_IGG_FONT_RENDERER_H_
...@@ -1410,6 +1410,8 @@ namespace dlib ...@@ -1410,6 +1410,8 @@ namespace dlib
mfont->compute_size(text_,text_width,height,text_pos); mfont->compute_size(text_,text_width,height,text_pos);
} }
parent.set_im_pos(rect.left()+cursor_x, rect.top());
if (old_cursor_pos != cursor_pos) if (old_cursor_pos != cursor_pos)
{ {
if (shift_pos != -1) if (shift_pos != -1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment