mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Applied another Unicode patch from Keita Mochizuki.
--HG-- extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402362
This commit is contained in:
parent
c4629db646
commit
5af59ada40
@ -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 (
|
||||
|
@ -254,6 +254,11 @@ namespace dlib
|
||||
void wait_until_closed (
|
||||
) const;
|
||||
|
||||
void set_im_pos (
|
||||
long x_,
|
||||
long y_
|
||||
);
|
||||
|
||||
enum on_close_return_code
|
||||
{
|
||||
DO_NOT_CLOSE_WINDOW,
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "../sync_extension.h"
|
||||
#include "../logger.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
namespace dlib
|
||||
{
|
||||
@ -47,7 +48,8 @@ namespace dlib
|
||||
|
||||
int depth;
|
||||
Display* disp;
|
||||
XIM xim;
|
||||
static XIM xim;
|
||||
static XIMStyle xim_style;
|
||||
static Screen* screen;
|
||||
|
||||
Atom delete_window;
|
||||
@ -529,18 +531,24 @@ namespace dlib
|
||||
KeySym key;
|
||||
Status status;
|
||||
|
||||
std::wstring wstr;
|
||||
wstr.resize(2);
|
||||
int len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status);
|
||||
if (status == XBufferOverflow){
|
||||
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 (win->x11_stuff.xic) {
|
||||
std::wstring wstr;
|
||||
wstr.resize(2);
|
||||
int len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status);
|
||||
if (status == XBufferOverflow){
|
||||
wstr.resize(len);
|
||||
len = XwcLookupString(win->x11_stuff.xic,e,&wstr[0],wstr.size(),&key,&status);
|
||||
}
|
||||
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;
|
||||
unsigned long result;
|
||||
@ -1098,10 +1106,36 @@ namespace dlib
|
||||
xim = NULL;
|
||||
window_table.get_mutex().lock();
|
||||
if (setlocale( LC_CTYPE, "" ) && XSupportsLocale() && XSetLocaleModifiers("")){
|
||||
xim = XOpenIM(disp, NULL, NULL, NULL);
|
||||
xim = XOpenIM(disp, NULL, NULL, NULL);
|
||||
}
|
||||
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
|
||||
// events in the event thread
|
||||
XSetWindowAttributes attr;
|
||||
@ -1528,12 +1562,26 @@ namespace dlib
|
||||
x11_stuff.xic = NULL;
|
||||
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(
|
||||
gui_core_kernel_2_globals::xim,
|
||||
XNInputStyle, XIMPreeditNothing | XIMStatusNothing,
|
||||
XNInputStyle, gui_core_kernel_2_globals::xim_style,
|
||||
XNClientWindow, x11_stuff.hwnd,
|
||||
XNPreeditAttributes, xva_nlist,
|
||||
NULL
|
||||
);
|
||||
XFree(xva_nlist);
|
||||
}
|
||||
|
||||
Window temp = x11_stuff.hwnd;
|
||||
@ -1542,7 +1590,8 @@ namespace dlib
|
||||
|
||||
// query event mask required by input method
|
||||
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(
|
||||
gui_core_kernel_2_globals::disp,
|
||||
@ -1601,9 +1650,11 @@ namespace dlib
|
||||
has_been_destroyed = true;
|
||||
|
||||
gui_core_kernel_2_globals::window_table.destroy(x11_stuff.hwnd);
|
||||
|
||||
XDestroyIC(x11_stuff.xic);
|
||||
x11_stuff.xic = 0;
|
||||
if (x11_stuff.xic)
|
||||
{
|
||||
XDestroyIC(x11_stuff.xic);
|
||||
x11_stuff.xic = 0;
|
||||
}
|
||||
|
||||
XDestroyWindow(gui_core_kernel_2_globals::disp,x11_stuff.hwnd);
|
||||
x11_stuff.hwnd = 0;
|
||||
@ -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
|
||||
void wait_until_closed (
|
||||
) const;
|
||||
|
||||
void set_im_pos (
|
||||
long x_,
|
||||
long y_
|
||||
);
|
||||
|
||||
bool is_closed (
|
||||
) const;
|
||||
|
||||
|
@ -498,6 +498,16 @@ namespace dlib
|
||||
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:
|
||||
const rmutex& wm;
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
#ifndef DLIB_IGG_FONT_RENDERER_H_
|
||||
#define DLIB_IGG_FONT_RENDERER_H_
|
||||
#include "../platform.h"
|
||||
|
||||
|
||||
#include "../gui_widgets.h"
|
||||
#include "../unicode.h"
|
||||
@ -13,10 +15,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32)
|
||||
#include <windows.h>
|
||||
#include <mbstring.h>
|
||||
#else
|
||||
#elif defined(POSIX)
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -41,28 +43,28 @@ namespace nativefont
|
||||
|
||||
#ifdef WIN32
|
||||
template <typename T> struct input2native_trait{
|
||||
};
|
||||
};
|
||||
template <> struct input2native_trait<char>{
|
||||
typedef char type_t;
|
||||
typedef char type_t;
|
||||
};
|
||||
template <> struct input2native_trait<wchar_t>{
|
||||
typedef wchar_t type_t;
|
||||
typedef wchar_t type_t;
|
||||
};
|
||||
template <> struct input2native_trait<dlib::unichar>{
|
||||
typedef wchar_t type_t;
|
||||
typedef wchar_t type_t;
|
||||
};
|
||||
#endif
|
||||
// T : N : sizeof_source_type
|
||||
template <int N> struct size2inner_trait{
|
||||
};
|
||||
};
|
||||
template <> struct size2inner_trait<1>{
|
||||
typedef char type_t;
|
||||
typedef char type_t;
|
||||
};
|
||||
template <> struct size2inner_trait<2>{
|
||||
typedef uint16_t type_t;
|
||||
typedef uint16_t type_t;
|
||||
};
|
||||
template <> struct size2inner_trait<4>{
|
||||
typedef dlib::unichar type_t;
|
||||
typedef dlib::unichar type_t;
|
||||
};
|
||||
|
||||
|
||||
@ -70,69 +72,67 @@ namespace nativefont
|
||||
|
||||
template <int N> struct create_helper{ };
|
||||
template <> struct create_helper<1>{
|
||||
typedef char type_t;
|
||||
type_t *istr;
|
||||
int len;
|
||||
create_helper(char *str){
|
||||
len = (int)strlen(str);
|
||||
istr = str;
|
||||
}
|
||||
~create_helper(){}
|
||||
typedef char type_t;
|
||||
type_t *istr;
|
||||
int len;
|
||||
create_helper(char *str){
|
||||
len = (int)strlen(str);
|
||||
istr = str;
|
||||
}
|
||||
~create_helper(){}
|
||||
};
|
||||
template <> struct create_helper<2>{
|
||||
typedef wchar_t type_t;
|
||||
type_t *istr;
|
||||
bool allocated;
|
||||
int len;
|
||||
create_helper(wchar_t *str){
|
||||
allocated = false;
|
||||
len = (int)wcslen(str);
|
||||
istr = str;
|
||||
typedef wchar_t type_t;
|
||||
type_t *istr;
|
||||
bool allocated;
|
||||
int len;
|
||||
create_helper(wchar_t *str){
|
||||
allocated = false;
|
||||
len = (int)wcslen(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){
|
||||
allocated = true;
|
||||
len = 0;
|
||||
int unicount = 0;
|
||||
dlib::unichar *p = str;
|
||||
while(*p){
|
||||
if (*p > 0xffff){
|
||||
len += 2;
|
||||
}else{
|
||||
len++;
|
||||
}
|
||||
unicount++;
|
||||
p++;
|
||||
}
|
||||
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));
|
||||
unicount++;
|
||||
p++;
|
||||
}
|
||||
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';
|
||||
}
|
||||
|
||||
~create_helper(){
|
||||
if (allocated) delete[] istr;
|
||||
}
|
||||
~create_helper(){
|
||||
if (allocated) delete[] istr;
|
||||
}
|
||||
};
|
||||
template <> struct create_helper<4>{
|
||||
typedef wchar_t type_t;
|
||||
type_t *istr;
|
||||
int len;
|
||||
create_helper(dlib::unichar *str){
|
||||
len = (int)wcslen((wchar_t *)str);
|
||||
istr = (type_t *)str;
|
||||
// printf("len:%d\n", len);
|
||||
}
|
||||
~create_helper(){}
|
||||
typedef wchar_t type_t;
|
||||
type_t *istr;
|
||||
int len;
|
||||
create_helper(dlib::unichar *str){
|
||||
len = (int)wcslen((wchar_t *)str);
|
||||
istr = (type_t *)str;
|
||||
}
|
||||
~create_helper(){}
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
@ -298,7 +298,7 @@ namespace nativefont
|
||||
~vals_internal(){
|
||||
destroy();
|
||||
}
|
||||
#else
|
||||
#elif defined(POSIX)
|
||||
XImage *ximg;
|
||||
Display *d;
|
||||
GC gc;
|
||||
@ -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_
|
||||
|
||||
|
@ -1410,6 +1410,8 @@ namespace dlib
|
||||
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 (shift_pos != -1)
|
||||
|
Loading…
Reference in New Issue
Block a user