• R/O
  • SSH
  • HTTPS

dxruby: Commit


Commit MetaInfo

Revision445 (tree)
Time2014-04-27 19:37:50
Authormirichi

Log Message

Input::IME完成

Change Summary

Incremental Difference

--- branches/1.5dev/input.c (revision 444)
+++ branches/1.5dev/input.c (revision 445)
@@ -110,7 +110,10 @@
110110 extern char *ime_composition_attr;
111111 extern int ime_composition_attr_size;
112112 extern LPCANDIDATELIST ime_canlist;
113+extern int ime_cursor_pos;
113114
115+static VALUE cCompositionInfo; /* 変換情報クラス */
116+
114117 //LPDIRECTINPUTEFFECT g_lpDIEffect = NULL;
115118
116119 /* Pad情報 */
@@ -1600,7 +1603,7 @@
16001603 ---------------------------------------------------------------------*/
16011604 static VALUE Input_IME_getstring( VALUE obj )
16021605 {
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 );
16041607 }
16051608
16061609 UINT DI_KeyList[][2] = { {VK_UP,DIK_UP}, {VK_DOWN,DIK_DOWN}, {VK_LEFT,DIK_LEFT}, {VK_RIGHT,DIK_RIGHT},
@@ -1732,23 +1735,24 @@
17321735 /*--------------------------------------------------------------------
17331736 IMEの変換中文字列取得
17341737 ---------------------------------------------------------------------*/
1735-static VALUE Input_IME_getcompositionstring( VALUE obj )
1738+static VALUE Input_IME_getcompositioninfo( VALUE obj )
17361739 {
17371740 VALUE vary = rb_ary_new();
17381741 VALUE vattr_ary = rb_ary_new();
17391742 VALUE vcanlist = rb_ary_new();
17401743 int i, j, topindex, pagesize;
1744+ VALUE ary[8];
17411745
17421746 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 );
17441748
17451749 for( i = 0; i < ime_composition_attr_size; i++ )
17461750 {
17471751 rb_ary_push( vattr_ary, INT2FIX( ime_composition_attr[i] ) );
17481752 }
1749- rb_ary_push( vary, vattr_ary );
1753+ ary[1] = vattr_ary;
1754+ ary[2] = INT2NUM( ime_cursor_pos );
17501755
1751- EnterCriticalSection( &ime_cs );
17521756 if( ime_canlist )
17531757 {
17541758 pagesize = ime_canlist->dwPageSize;
@@ -1755,17 +1759,22 @@
17551759 topindex = (ime_canlist->dwSelection / pagesize) * pagesize;
17561760 for( i = topindex, j = 0; i < ime_canlist->dwCount && j < pagesize; i++, j++ )
17571761 {
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 ) );
17591763 }
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 );
17621769 }
17631770 else
17641771 {
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;
17671777 }
1768- LeaveCriticalSection( &ime_cs );
17691778
17701779 free( ime_composition_str );
17711780 free( ime_composition_attr );
@@ -1773,7 +1782,7 @@
17731782 ime_composition_attr = 0;
17741783 ime_composition_attr_size = 0;
17751784
1776- return vary;
1785+ return rb_class_new_instance( 8, ary, cCompositionInfo );
17771786 }
17781787 #endif
17791788
@@ -2413,7 +2422,7 @@
24132422 rb_define_singleton_method( mIME, "pushKeys" , Input_IME_getpushkeys , 0 );
24142423 rb_define_singleton_method( mIME, "release_keys", Input_IME_getreleasekeys , 0 );
24152424 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 );
24172426
24182427 rb_define_const( mIME, "ATTR_INPUT" , INT2FIX(ATTR_INPUT) );
24192428 rb_define_const( mIME, "ATTR_TARGET_CONVERTED" , INT2FIX(ATTR_TARGET_CONVERTED) );
@@ -2420,6 +2429,9 @@
24202429 rb_define_const( mIME, "ATTR_CONVERTED" , INT2FIX(ATTR_CONVERTED) );
24212430 rb_define_const( mIME, "ATTR_TARGET_NOTCONVERTED" , INT2FIX(ATTR_TARGET_NOTCONVERTED) );
24222431 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 );
24232435 #endif
24242436
24252437 SetImeEnable( FALSE );
--- branches/1.5dev/messagethread.c (revision 444)
+++ branches/1.5dev/messagethread.c (revision 445)
@@ -45,6 +45,7 @@
4545 char *ime_composition_attr;
4646 int ime_composition_attr_size;
4747 LPCANDIDATELIST ime_canlist;
48+int ime_cursor_pos;
4849
4950
5051 char *ERR_MESSAGE[ERR_MAX] =
@@ -594,7 +595,6 @@
594595 int len;
595596 HIMC hIMC;
596597
597- EnterCriticalSection( &ime_cs );
598598 hIMC = ImmGetContext( g_hWnd );
599599
600600 len = ImmGetCompositionStringW( hIMC, GCS_COMPSTR, 0, 0 );
@@ -606,8 +606,9 @@
606606 ime_composition_attr = (char *)malloc( len );
607607 ime_composition_attr_size = ImmGetCompositionStringW( hIMC, GCS_COMPATTR, ime_composition_attr, len );
608608
609+ ime_cursor_pos = ImmGetCompositionStringW( hIMC, GCS_CURSORPOS, NULL, 0 );
610+
609611 ImmReleaseContext( g_hWnd, hIMC );
610- LeaveCriticalSection( &ime_cs );
611612 return 0;
612613 }
613614 case WM_IME_COMPOSITION:
--- branches/1.5dev/dxruby.c (revision 444)
+++ branches/1.5dev/dxruby.c (revision 445)
@@ -853,7 +853,7 @@
853853 static VALUE Window_getCaption( VALUE klass )
854854 {
855855 char buf[256];
856- VALUE vstr;
856+ VALUE vstr;
857857 VALUE venc = rb_enc_default_internal();
858858
859859 GetWindowText( g_hWnd, buf, 256 );
@@ -874,12 +874,16 @@
874874 ---------------------------------------------------------------------*/
875875 static VALUE Window_setCaption( VALUE klass, VALUE vcaption )
876876 {
877- VALUE vsjisstr;
878877 Check_Type(vcaption, T_STRING);
879878
880879 if( rb_enc_get_index( vcaption ) != 0 )
881880 {
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 );
883887 }
884888 else
885889 {
@@ -3587,7 +3591,7 @@
35873591 D3DXMATRIX matrix;
35883592 D3DXMATRIX matrix_t;
35893593 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 ) );
35913595 float angle = 3.141592653589793115997963468544185161590576171875f / 180.0f * picture->angle;
35923596 DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
35933597
@@ -3609,8 +3613,23 @@
36093613 rect.top = -picture->centery;
36103614 rect.right = picture->centerx;
36113615 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+
36143633 g_pD3DXSprite->lpVtbl->Flush( g_pD3DXSprite );
36153634
36163635 /* ピクチャの描画終了 */
@@ -3629,7 +3648,8 @@
36293648 VALUE vz, vangle, vscalex, vscaley, valpha, vcenterx, vcentery, vblend;
36303649 VALUE voption;
36313650 struct DXRubyRenderTarget *rt = DXRUBY_GET_STRUCT( RenderTarget, obj );
3632- VALUE vsjisstr;
3651+ VALUE vstr;
3652+ volatile VALUE temp;
36333653
36343654 DXRUBY_CHECK_DISPOSE( rt, surface );
36353655 // DXRUBY_CHECK_IMAGE_LOCK( rt );
@@ -3665,7 +3685,7 @@
36653685 font = DXRUBY_GET_STRUCT( Font, argv[3] );
36663686 DXRUBY_CHECK_DISPOSE( font, pD3DXFont );
36673687
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 ) );
36693689 if( picture == NULL )
36703690 {
36713691 rb_raise( eDXRubyError, "フォント用メモリの確保に失敗しました" );
@@ -3687,20 +3707,17 @@
36873707 (vblend == symbol_add2 ? 5 :
36883708 (vblend == symbol_sub ? 6 :
36893709 (vblend == symbol_sub2 ? 7 : 0))))));
3690- picture->value = argv[3];
36913710
36923711 if( rb_enc_get_index( argv[2] ) != 0 )
36933712 {
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 );
36953714 }
36963715 else
36973716 {
3698- vsjisstr = argv[2];
3717+ vstr = rb_obj_dup( argv[2] );
36993718 }
37003719
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 );
37043721
37053722 if( vcolor != Qnil )
37063723 {
@@ -3726,7 +3743,6 @@
37263743 cb = 255;
37273744 }
37283745 picture->color = D3DCOLOR_XRGB(cr, cg, cb);
3729- picture->value = argv[3];
37303746 picture->z = 0;
37313747
37323748 /* リストデータに追加 */
@@ -4867,9 +4883,9 @@
48674883 rb_global_variable( &g_WindowInfo.before_call );
48684884 rb_global_variable( &g_WindowInfo.after_call );
48694885
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" );
48734889
48744890 /* BG色の初期化 */
48754891 Window_set_bgcolor( mWindow, rb_ary_new3( 3, INT2FIX( 0 ), INT2FIX( 0 ), INT2FIX( 0 ) ) );
--- branches/1.5dev/dxruby.h (revision 444)
+++ branches/1.5dev/dxruby.h (revision 445)
@@ -205,7 +205,6 @@
205205 float centery;
206206 float angle;
207207 int color; /* フォントの色 */
208- char str[0]; /* 文字列オブジェクト */
209208 };
210209
211210 struct DXRubyPicture_drawMorph {
Show on old repository browser