Input::IME完成
@@ -110,7 +110,10 @@ | ||
110 | 110 | extern char *ime_composition_attr; |
111 | 111 | extern int ime_composition_attr_size; |
112 | 112 | extern LPCANDIDATELIST ime_canlist; |
113 | +extern int ime_cursor_pos; | |
113 | 114 | |
115 | +static VALUE cCompositionInfo; /* 変換情報クラス */ | |
116 | + | |
114 | 117 | //LPDIRECTINPUTEFFECT g_lpDIEffect = NULL; |
115 | 118 | |
116 | 119 | /* Pad情報 */ |
@@ -1600,7 +1603,7 @@ | ||
1600 | 1603 | ---------------------------------------------------------------------*/ |
1601 | 1604 | static VALUE Input_IME_getstring( VALUE obj ) |
1602 | 1605 | { |
1603 | - return rb_enc_str_new( (char*)ime_buf_old, ime_str_length_old * 2, g_enc_utf16 ); | |
1606 | + return rb_str_export_to_enc( rb_enc_str_new( (char*)ime_buf_old, ime_str_length_old * 2, g_enc_utf16 ), g_enc_utf8 ); | |
1604 | 1607 | } |
1605 | 1608 | |
1606 | 1609 | UINT DI_KeyList[][2] = { {VK_UP,DIK_UP}, {VK_DOWN,DIK_DOWN}, {VK_LEFT,DIK_LEFT}, {VK_RIGHT,DIK_RIGHT}, |
@@ -1732,23 +1735,24 @@ | ||
1732 | 1735 | /*-------------------------------------------------------------------- |
1733 | 1736 | IMEの変換中文字列取得 |
1734 | 1737 | ---------------------------------------------------------------------*/ |
1735 | -static VALUE Input_IME_getcompositionstring( VALUE obj ) | |
1738 | +static VALUE Input_IME_getcompositioninfo( VALUE obj ) | |
1736 | 1739 | { |
1737 | 1740 | VALUE vary = rb_ary_new(); |
1738 | 1741 | VALUE vattr_ary = rb_ary_new(); |
1739 | 1742 | VALUE vcanlist = rb_ary_new(); |
1740 | 1743 | int i, j, topindex, pagesize; |
1744 | + VALUE ary[8]; | |
1741 | 1745 | |
1742 | 1746 | UpdateCompositionString(); |
1743 | - rb_ary_push( vary, rb_enc_associate( rb_str_new2( (char*)ime_composition_str ), g_enc_utf16 ) ); | |
1747 | + ary[0] = rb_str_export_to_enc( rb_enc_associate( rb_str_new( (char*)ime_composition_str, wcslen( ime_composition_str ) * 2 + 2 ), g_enc_utf16 ), g_enc_utf8 ); | |
1744 | 1748 | |
1745 | 1749 | for( i = 0; i < ime_composition_attr_size; i++ ) |
1746 | 1750 | { |
1747 | 1751 | rb_ary_push( vattr_ary, INT2FIX( ime_composition_attr[i] ) ); |
1748 | 1752 | } |
1749 | - rb_ary_push( vary, vattr_ary ); | |
1753 | + ary[1] = vattr_ary; | |
1754 | + ary[2] = INT2NUM( ime_cursor_pos ); | |
1750 | 1755 | |
1751 | - EnterCriticalSection( &ime_cs ); | |
1752 | 1756 | if( ime_canlist ) |
1753 | 1757 | { |
1754 | 1758 | pagesize = ime_canlist->dwPageSize; |
@@ -1755,17 +1759,22 @@ | ||
1755 | 1759 | topindex = (ime_canlist->dwSelection / pagesize) * pagesize; |
1756 | 1760 | for( i = topindex, j = 0; i < ime_canlist->dwCount && j < pagesize; i++, j++ ) |
1757 | 1761 | { |
1758 | - rb_ary_push( vcanlist, rb_enc_associate( rb_str_new2( (char *)ime_canlist + ime_canlist->dwOffset[i] ), g_enc_utf16 ) ); | |
1762 | + rb_ary_push( vcanlist, rb_str_export_to_enc( rb_enc_associate( rb_str_new( (char *)ime_canlist + ime_canlist->dwOffset[i], wcslen( (const wchar_t *)((char *)ime_canlist + ime_canlist->dwOffset[i] )) * 2 + 2 ), g_enc_utf16 ), g_enc_utf8 ) ); | |
1759 | 1763 | } |
1760 | - rb_ary_push( vary, vcanlist ); | |
1761 | - rb_ary_push( vary, INT2FIX( ime_canlist->dwSelection - topindex ) ); | |
1764 | + ary[3] = vcanlist; | |
1765 | + ary[4] = INT2FIX( ime_canlist->dwSelection - topindex ); | |
1766 | + ary[5] = INT2NUM( ime_canlist->dwSelection ); | |
1767 | + ary[6] = INT2NUM( pagesize ); | |
1768 | + ary[7] = INT2NUM( ime_canlist->dwCount ); | |
1762 | 1769 | } |
1763 | 1770 | else |
1764 | 1771 | { |
1765 | - rb_ary_push( vary, rb_ary_new() ); | |
1766 | - rb_ary_push( vary, rb_ary_new() ); | |
1772 | + ary[3] = rb_ary_new(); | |
1773 | + ary[4] = Qnil; | |
1774 | + ary[5] = Qnil; | |
1775 | + ary[6] = Qnil; | |
1776 | + ary[7] = Qnil; | |
1767 | 1777 | } |
1768 | - LeaveCriticalSection( &ime_cs ); | |
1769 | 1778 | |
1770 | 1779 | free( ime_composition_str ); |
1771 | 1780 | free( ime_composition_attr ); |
@@ -1773,7 +1782,7 @@ | ||
1773 | 1782 | ime_composition_attr = 0; |
1774 | 1783 | ime_composition_attr_size = 0; |
1775 | 1784 | |
1776 | - return vary; | |
1785 | + return rb_class_new_instance( 8, ary, cCompositionInfo ); | |
1777 | 1786 | } |
1778 | 1787 | #endif |
1779 | 1788 |
@@ -2413,7 +2422,7 @@ | ||
2413 | 2422 | rb_define_singleton_method( mIME, "pushKeys" , Input_IME_getpushkeys , 0 ); |
2414 | 2423 | rb_define_singleton_method( mIME, "release_keys", Input_IME_getreleasekeys , 0 ); |
2415 | 2424 | rb_define_singleton_method( mIME, "releaseKeys" , Input_IME_getreleasekeys , 0 ); |
2416 | - rb_define_singleton_method( mIME, "get_composition_string" , Input_IME_getcompositionstring , 0 ); | |
2425 | + rb_define_singleton_method( mIME, "get_comp_info" , Input_IME_getcompositioninfo , 0 ); | |
2417 | 2426 | |
2418 | 2427 | rb_define_const( mIME, "ATTR_INPUT" , INT2FIX(ATTR_INPUT) ); |
2419 | 2428 | rb_define_const( mIME, "ATTR_TARGET_CONVERTED" , INT2FIX(ATTR_TARGET_CONVERTED) ); |
@@ -2420,6 +2429,9 @@ | ||
2420 | 2429 | rb_define_const( mIME, "ATTR_CONVERTED" , INT2FIX(ATTR_CONVERTED) ); |
2421 | 2430 | rb_define_const( mIME, "ATTR_TARGET_NOTCONVERTED" , INT2FIX(ATTR_TARGET_NOTCONVERTED) ); |
2422 | 2431 | rb_define_const( mIME, "ATTR_INPUT_ERROR" , INT2FIX(ATTR_INPUT_ERROR) ); |
2432 | + | |
2433 | + cCompositionInfo = rb_struct_define( NULL, "comp_str", "comp_attr", "cursor_pos", "can_list", "selection", "selection_total", "page_size", "total", 0 ); | |
2434 | + rb_define_const( mIME, "CompositionInfo", cCompositionInfo ); | |
2423 | 2435 | #endif |
2424 | 2436 | |
2425 | 2437 | SetImeEnable( FALSE ); |
@@ -45,6 +45,7 @@ | ||
45 | 45 | char *ime_composition_attr; |
46 | 46 | int ime_composition_attr_size; |
47 | 47 | LPCANDIDATELIST ime_canlist; |
48 | +int ime_cursor_pos; | |
48 | 49 | |
49 | 50 | |
50 | 51 | char *ERR_MESSAGE[ERR_MAX] = |
@@ -594,7 +595,6 @@ | ||
594 | 595 | int len; |
595 | 596 | HIMC hIMC; |
596 | 597 | |
597 | - EnterCriticalSection( &ime_cs ); | |
598 | 598 | hIMC = ImmGetContext( g_hWnd ); |
599 | 599 | |
600 | 600 | len = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 ); |
@@ -606,8 +606,9 @@ | ||
606 | 606 | ime_composition_attr = (char *)malloc( len ); |
607 | 607 | ime_composition_attr_size = ImmGetCompositionStringW( hIMC, GCS_COMPATTR, ime_composition_attr, len ); |
608 | 608 | |
609 | + ime_cursor_pos = ImmGetCompositionStringW( hIMC, GCS_CURSORPOS, NULL, 0 ); | |
610 | + | |
609 | 611 | ImmReleaseContext( g_hWnd, hIMC ); |
610 | - LeaveCriticalSection( &ime_cs ); | |
611 | 612 | return 0; |
612 | 613 | } |
613 | 614 | case WM_IME_COMPOSITION: |
@@ -853,7 +853,7 @@ | ||
853 | 853 | static VALUE Window_getCaption( VALUE klass ) |
854 | 854 | { |
855 | 855 | char buf[256]; |
856 | - VALUE vstr; | |
856 | + VALUE vstr; | |
857 | 857 | VALUE venc = rb_enc_default_internal(); |
858 | 858 | |
859 | 859 | GetWindowText( g_hWnd, buf, 256 ); |
@@ -874,12 +874,16 @@ | ||
874 | 874 | ---------------------------------------------------------------------*/ |
875 | 875 | static VALUE Window_setCaption( VALUE klass, VALUE vcaption ) |
876 | 876 | { |
877 | - VALUE vsjisstr; | |
878 | 877 | Check_Type(vcaption, T_STRING); |
879 | 878 | |
880 | 879 | if( rb_enc_get_index( vcaption ) != 0 ) |
881 | 880 | { |
882 | - SetWindowTextW( g_hWnd, (LPWSTR)RSTRING_PTR( rb_str_export_to_enc( vcaption, g_enc_utf16 ) ) ); | |
881 | + VALUE vstr = rb_str_export_to_enc( vcaption, g_enc_utf16 ); | |
882 | + int len = RSTRING_LEN( vstr ); | |
883 | + char *buf = alloca( len + 2 ); | |
884 | + buf[len] = buf[len + 1] = 0; | |
885 | + memcpy( buf, RSTRING_PTR( vstr ), len ); | |
886 | + SetWindowTextW( g_hWnd, (LPWSTR)buf ); | |
883 | 887 | } |
884 | 888 | else |
885 | 889 | { |
@@ -3587,7 +3591,7 @@ | ||
3587 | 3591 | D3DXMATRIX matrix; |
3588 | 3592 | D3DXMATRIX matrix_t; |
3589 | 3593 | RECT rect; |
3590 | - struct DXRubyFont *font = DXRUBY_GET_STRUCT( Font, picture->value ); | |
3594 | + struct DXRubyFont *font = DXRUBY_GET_STRUCT( Font, RARRAY_AREF( picture->value, 0 ) ); | |
3591 | 3595 | float angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * picture->angle; |
3592 | 3596 | DXRUBY_CHECK_DISPOSE( font, pD3DXFont ); |
3593 | 3597 |
@@ -3609,8 +3613,23 @@ | ||
3609 | 3613 | rect.top = -picture->centery; |
3610 | 3614 | rect.right = picture->centerx; |
3611 | 3615 | rect.bottom = picture->centery; |
3612 | - font->pD3DXFont->lpVtbl->DrawText( font->pD3DXFont, g_pD3DXSprite, picture->str, -1, &rect, DT_LEFT | DT_NOCLIP, | |
3613 | - ((int)picture->alpha << 24) | picture->color & 0x00ffffff); | |
3616 | + { | |
3617 | + int len = RSTRING_LEN( RARRAY_AREF( picture->value, 1 ) ); | |
3618 | + char *buf = alloca( len + 2 ); | |
3619 | + buf[len] = buf[len + 1] = 0; | |
3620 | + memcpy( buf, RSTRING_PTR( RARRAY_AREF(picture->value, 1) ), len ); | |
3621 | + if( rb_enc_get_index( RARRAY_AREF(picture->value, 1) ) == 0 ) | |
3622 | + { | |
3623 | + font->pD3DXFont->lpVtbl->DrawText( font->pD3DXFont, g_pD3DXSprite, buf, -1, &rect, DT_LEFT | DT_NOCLIP, | |
3624 | + ((int)picture->alpha << 24) | picture->color & 0x00ffffff); | |
3625 | + } | |
3626 | + else | |
3627 | + { | |
3628 | + font->pD3DXFont->lpVtbl->DrawTextW( font->pD3DXFont, g_pD3DXSprite, (LPCWSTR)buf, -1, &rect, DT_LEFT | DT_NOCLIP, | |
3629 | + ((int)picture->alpha << 24) | picture->color & 0x00ffffff); | |
3630 | + } | |
3631 | + } | |
3632 | + | |
3614 | 3633 | g_pD3DXSprite->lpVtbl->Flush( g_pD3DXSprite ); |
3615 | 3634 | |
3616 | 3635 | /* ピクチャの描画終了 */ |
@@ -3629,7 +3648,8 @@ | ||
3629 | 3648 | VALUE vz, vangle, vscalex, vscaley, valpha, vcenterx, vcentery, vblend; |
3630 | 3649 | VALUE voption; |
3631 | 3650 | struct DXRubyRenderTarget *rt = DXRUBY_GET_STRUCT( RenderTarget, obj ); |
3632 | - VALUE vsjisstr; | |
3651 | + VALUE vstr; | |
3652 | + volatile VALUE temp; | |
3633 | 3653 | |
3634 | 3654 | DXRUBY_CHECK_DISPOSE( rt, surface ); |
3635 | 3655 | // DXRUBY_CHECK_IMAGE_LOCK( rt ); |
@@ -3665,7 +3685,7 @@ | ||
3665 | 3685 | font = DXRUBY_GET_STRUCT( Font, argv[3] ); |
3666 | 3686 | DXRUBY_CHECK_DISPOSE( font, pD3DXFont ); |
3667 | 3687 | |
3668 | - picture = (struct DXRubyPicture_drawFont *)RenderTarget_AllocPictureList( rt, sizeof( struct DXRubyPicture_drawFont ) + RSTRING_LEN(argv[2]) + 2 ); | |
3688 | + picture = (struct DXRubyPicture_drawFont *)RenderTarget_AllocPictureList( rt, sizeof( struct DXRubyPicture_drawFont ) ); | |
3669 | 3689 | if( picture == NULL ) |
3670 | 3690 | { |
3671 | 3691 | rb_raise( eDXRubyError, "フォント用メモリの確保に失敗しました" ); |
@@ -3687,20 +3707,17 @@ | ||
3687 | 3707 | (vblend == symbol_add2 ? 5 : |
3688 | 3708 | (vblend == symbol_sub ? 6 : |
3689 | 3709 | (vblend == symbol_sub2 ? 7 : 0)))))); |
3690 | - picture->value = argv[3]; | |
3691 | 3710 | |
3692 | 3711 | if( rb_enc_get_index( argv[2] ) != 0 ) |
3693 | 3712 | { |
3694 | - vsjisstr = rb_str_export_to_enc( argv[2], rb_default_internal_encoding() ); | |
3713 | + vstr = rb_str_export_to_enc( argv[2], g_enc_utf16 ); | |
3695 | 3714 | } |
3696 | 3715 | else |
3697 | 3716 | { |
3698 | - vsjisstr = argv[2]; | |
3717 | + vstr = rb_obj_dup( argv[2] ); | |
3699 | 3718 | } |
3700 | 3719 | |
3701 | - lstrcpy( picture->str, RSTRING_PTR( vsjisstr ) ); /* 文字列の保存 */ | |
3702 | - picture->str[RSTRING_LEN(vsjisstr)] = ' '; /* イタリック対策にスペース追加 */ | |
3703 | - picture->str[RSTRING_LEN(vsjisstr)+1] = 0; | |
3720 | + picture->value = temp = rb_ary_new3( 2, argv[3], vstr ); | |
3704 | 3721 | |
3705 | 3722 | if( vcolor != Qnil ) |
3706 | 3723 | { |
@@ -3726,7 +3743,6 @@ | ||
3726 | 3743 | cb = 255; |
3727 | 3744 | } |
3728 | 3745 | picture->color = D3DCOLOR_XRGB(cr, cg, cb); |
3729 | - picture->value = argv[3]; | |
3730 | 3746 | picture->z = 0; |
3731 | 3747 | |
3732 | 3748 | /* リストデータに追加 */ |
@@ -4867,9 +4883,9 @@ | ||
4867 | 4883 | rb_global_variable( &g_WindowInfo.before_call ); |
4868 | 4884 | rb_global_variable( &g_WindowInfo.after_call ); |
4869 | 4885 | |
4870 | - g_enc_sys = rb_enc_find( sys_encode ); | |
4871 | - g_enc_utf16 = rb_enc_find( "UTF-16LE" ); | |
4872 | - g_enc_utf8 = rb_enc_find( "UTF-8" ); | |
4886 | + g_enc_sys = rb_enc_find( sys_encode ); | |
4887 | + g_enc_utf16 = rb_enc_find( "UTF-16LE" ); | |
4888 | + g_enc_utf8 = rb_enc_find( "UTF-8" ); | |
4873 | 4889 | |
4874 | 4890 | /* BG色の初期化 */ |
4875 | 4891 | Window_set_bgcolor( mWindow, rb_ary_new3( 3, INT2FIX( 0 ), INT2FIX( 0 ), INT2FIX( 0 ) ) ); |
@@ -205,7 +205,6 @@ | ||
205 | 205 | float centery; |
206 | 206 | float angle; |
207 | 207 | int color; /* フォントの色 */ |
208 | - char str[0]; /* 文字列オブジェクト */ | |
209 | 208 | }; |
210 | 209 | |
211 | 210 | struct DXRubyPicture_drawMorph { |