C:\home\SVGCats_src\src\InputML1.cpp
1|// InputML1.cpp : インプリメンテーション ファイル 2|// 3| 4|#include "mixer_precomp.h" 5|#ifdef USES_MXP_AUTOINC 6| #include "SVGCat.ah" 7|#endif 8| 9|#include "imm.h" 10| 11|#ifdef _DEBUG 12|#define new DEBUG_NEW 13|#undef THIS_FILE 14|static char THIS_FILE[] = __FILE__; 15|#endif 16| 17|///////////////////////////////////////////////////////////////////////////// 18|// CInputML1 ダイアログ 19| 20| 21| 22|CInputML1::CInputML1(CWnd* pParent /*=NULL*/) 23| : CDialog(CInputML1::IDD, pParent) 24|{ 25| //{{AFX_DATA_INIT(CInputML1) 26| //}}AFX_DATA_INIT 27| m_Creating = true; 28| m_mByteInLine = 1024; 29| m_PenInputPanel = NULL; 30| m_bDispPenPanel= false; 31| m_CursorPos.x = -1; 32| m_SaveFunc = NULL; 33| m_bCtrlRet = true; 34| m_bJapanese = true; 35| m_bNoSelect = false; 36| m_bHideMain = false; 37| m_HideTarget = NULL; 38|} 39| 40| 41|void CInputML1::DoDataExchange(CDataExchange* pDX) 42|{ 43| CDialog::DoDataExchange(pDX); 44| //{{AFX_DATA_MAP(CInputML1) 45| DDX_Control(pDX, ID_SearchPrev, m_SearchPrevBtn); 46| DDX_Control(pDX, ID_SearchNext, m_SearchNextBtn); 47| DDX_Control(pDX, ID_Search, m_SearchBtn); 48| DDX_Control(pDX, IDC_HideMain, m_HideMainBtn); 49| DDX_Control(pDX, IDC_ToggleCtrlEnter, m_ToggleCtrlEnter); 50| DDX_Control(pDX, IDC_Text, m_TextCtrl); 51| DDX_Control(pDX, IDOK, m_OKCtrl); 52| DDX_Control(pDX, IDCANCEL, m_CancelCtrl); 53| DDX_Control(pDX, IDC_Undo, m_UndoBtn); 54| DDX_Control(pDX, IDC_SaveBtn, m_SaveBtn); 55| DDX_Control(pDX, IDC_Ret, m_RetCtrl); 56| DDX_Control(pDX, IDC_Redo, m_RedoBtn); 57| DDX_Control(pDX, IDC_Pen, m_PenBtn); 58| DDX_Control(pDX, IDC_Paste, m_PasteBtn); 59| DDX_Control(pDX, IDC_Keyboard, m_KeyboardBtn); 60| DDX_Control(pDX, IDC_Guide, m_Guide); 61| DDX_Control(pDX, IDC_Del, m_DelBtn); 62| DDX_Control(pDX, IDC_Cut, m_CutBtn); 63| DDX_Control(pDX, IDC_Copy, m_CopyBtn); 64| //}}AFX_DATA_MAP 65|} 66| 67| 68|BEGIN_MESSAGE_MAP(CInputML1, CDialog) 69| //{{AFX_MSG_MAP(CInputML1) 70| ON_WM_ACTIVATE() 71| ON_WM_SIZE() 72| ON_BN_CLICKED(IDC_Ret, OnRet) 73| ON_WM_GETMINMAXINFO() 74| ON_BN_CLICKED(IDC_Cut, OnCut) 75| ON_BN_CLICKED(IDC_Copy, OnCopy) 76| ON_BN_CLICKED(IDC_Paste, OnPaste) 77| ON_BN_CLICKED(IDC_Del, OnDel) 78| ON_BN_CLICKED(IDC_Undo, OnUndo) 79| ON_BN_CLICKED(IDC_Redo, OnRedo) 80| ON_BN_CLICKED(IDC_SaveBtn, OnSaveBtn) 81| ON_BN_CLICKED(IDC_Keyboard, OnKeyboard) 82| ON_BN_CLICKED(IDC_Pen, OnPen) 83| ON_COMMAND(ID_EditSave, OnEditSave) 84| ON_BN_CLICKED(IDC_ToggleCtrlEnter, OnToggleCtrlEnter) 85| ON_WM_CREATE() 86| ON_BN_CLICKED(IDC_HideMain, OnHideMain) 87| ON_COMMAND(ID_SelectAll, OnSelectAll) 88| ON_COMMAND(ID_Search, OnSearch) 89| ON_COMMAND(ID_SearchNext, OnSearchNext) 90| ON_COMMAND(ID_SearchPrev, OnSearchPrev) 91| ON_COMMAND(ID_HideMain, OnHideMain) 92| ON_BN_CLICKED(ID_Search, OnSearch) 93| ON_BN_CLICKED(ID_SearchNext, OnSearchNext) 94| ON_BN_CLICKED(ID_SearchPrev, OnSearchPrev) 95| //}}AFX_MSG_MAP 96|END_MESSAGE_MAP() 97| 98| 99| 100|///////////////////////////////////////////////////////////////////////////// 101|// CInputML1 メッセージ ハンドラ 102| 103|void* CInputML1::m_ID_prev = NULL; 104|bool CInputML1::m_bImeOn = false; 105|int CInputML1::m_iStart = 0, CInputML1::m_iEnd = 0, CInputML1::m_iLine = 1; 106|RECT CInputML1::m_WinRect; 107|bool CInputML1::m_bMax; 108| 109|BOOL CInputML1::OnInitDialog() 110|{ 111| CDialog::OnInitDialog(); 112| char s[256]; 113| 114| m_Creating = false; 115| m_OldText = m_Text; 116| 117| m_PenInputPanel = NULL; 118| if ( m_PenInputPanel == NULL ) m_bDispPenPanel = false; 119| 120|// m_Text2Ctrl.SetText( m_Text ); 121| 122| m_SaveBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Save) ); 123| m_CutBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Cut) ); 124| m_CopyBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Copy) ); 125| m_PasteBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Paste) ); 126| m_DelBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Del) ); 127| m_UndoBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Undo) ); 128| m_RedoBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Redo) ); 129| m_SearchBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Search) ); 130| m_SearchNextBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_SearchNext) ); 131| m_SearchPrevBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_SearchPrev) ); 132| m_KeyboardBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Keyboard) ); 133| m_PenBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Pen) ); 134| m_HideMainBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_HideMain) ); 135| SetIcon( AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE ); 136| 137| m_ToolTip.Create( this ); 138| LoadString( AfxGetInstanceHandle(), ID_SaveOv, s, sizeof(s) ); 139| StrX_cpy1Line( s, sizeof(s), s, 2 ); 140| m_ToolTip.AddTool( GetDlgItem(IDC_SaveBtn), s ); 141| 142| LoadString( AfxGetInstanceHandle(), ID_EDIT_CUT, s, sizeof(s) ); 143| StrX_cpy1Line( s, sizeof(s), s, 2 ); 144| m_ToolTip.AddTool( GetDlgItem(IDC_Cut), s ); 145| 146| LoadString( AfxGetInstanceHandle(), ID_EDIT_COPY, s, sizeof(s) ); 147| StrX_cpy1Line( s, sizeof(s), s, 2 ); 148| m_ToolTip.AddTool( GetDlgItem(IDC_Copy), s ); 149| 150| LoadString( AfxGetInstanceHandle(), ID_EDIT_PASTE, s, sizeof(s) ); 151| StrX_cpy1Line( s, sizeof(s), s, 2 ); 152| m_ToolTip.AddTool( GetDlgItem(IDC_Paste), s ); 153| 154| LoadString( AfxGetInstanceHandle(), ID_EDIT_CLEAR, s, sizeof(s) ); 155| StrX_cpy1Line( s, sizeof(s), s, 2 ); 156| m_ToolTip.AddTool( GetDlgItem(IDC_Del), s ); 157| 158| LoadString( AfxGetInstanceHandle(), ID_EDIT_UNDO, s, sizeof(s) ); 159| StrX_cpy1Line( s, sizeof(s), s, 2 ); 160| m_ToolTip.AddTool( GetDlgItem(IDC_Undo), s ); 161| 162| LoadString( AfxGetInstanceHandle(), ID_EDIT_REDO, s, sizeof(s) ); 163| StrX_cpy1Line( s, sizeof(s), s, 2 ); 164| m_ToolTip.AddTool( GetDlgItem(IDC_Redo), s ); 165| 166| LoadString( AfxGetInstanceHandle(), IDS_Keyboard, s, sizeof(s) ); 167| StrX_cpy1Line( s, sizeof(s), s, 2 ); 168| m_ToolTip.AddTool( GetDlgItem(IDC_Keyboard), s ); 169| 170| LoadString( AfxGetInstanceHandle(), IDS_Pen, s, sizeof(s) ); 171| StrX_cpy1Line( s, sizeof(s), s, 2 ); 172| m_ToolTip.AddTool( GetDlgItem(IDC_Pen), s ); 173| 174| LoadString( AfxGetInstanceHandle(), IDS_HideMain, s, sizeof(s) ); 175| StrX_cpy1Line( s, sizeof(s), s, 2 ); 176| m_ToolTip.AddTool( GetDlgItem(IDC_HideMain), s ); 177| 178| 179| /* ペン入力パネルを設定する */ 180|#if 0 181| if ( m_PenInputPanel != NULL ) { 182| BSTR s; 183| HRESULT hr; 184| 185| hr = m_PenInputPanel->put_AttachedEditWindow( (LONG_PTR)m_Text2Ctrl.GetHwnd() ); 186| if ( hr != 0 ) error(); 187| 188| s = SysAllocString( OLESTR("ALL") ); 189| hr = m_PenInputPanel->put_Factoid( s ); 190| SysFreeString( s ); 191| if ( hr != 0 ) error(); 192| 193| hr = m_PenInputPanel->EnableTsf( VARIANT_TRUE ); 194| if ( hr != 0 ) error(); 195| 196| hr = m_PenInputPanel->put_AutoShow( VARIANT_FALSE ); 197| if ( hr != 0 ) error(); 198| 199| hr = m_PenInputPanel->put_HorizontalOffset( -14 ); 200| if ( hr != 0 ) error(); 201| 202| hr = m_PenInputPanel->put_VerticalOffset( 51 ); 203| if ( hr != 0 ) error(); 204| } 205|#endif 206| 207| 208| /* テキストボックスの初期化をする */ 209| m_TextCtrl.SetWindowText( m_Text ); 210| if ( m_ID == m_ID_prev || m_bNoSelect ) { 211| if ( !m_bDispPenPanel ) { 212| m_TextCtrl.SetSel( m_iStart, m_iEnd ); 213| m_TextCtrl.SetFocus(); /* コレをしないと全選択になってしまう */ 214| // m_TextCtrl.LineScroll( m_iLine ); // 後にしないと、PosFromChar でウィンドウサイズがおかしくなる。 215| } 216| else { 217|#if 0 218| m_Text2Ctrl.SetFocus(); 219| m_Text2Ctrl.SetSelStart( m_iStart ); 220| m_Text2Ctrl.SetSelLength( m_iEnd - m_iStart ); 221|#endif 222| } 223| } 224| 225| if ( m_ID == m_ID_prev ) { 226| MoveWindow( &m_WinRect ); /* 内部で OnSize が呼ばれる */ 227| if ( m_bMax ) { 228| ShowWindow( SW_SHOWMAXIMIZED ); 229| } 230| } 231| 232| if ( m_ID != m_ID_prev ) { 233| RECT rect, desktopRect; 234| POINT point; 235| int w,h, i1, nLine, max; 236| POINT pt; 237| int scr_w = GetSystemMetrics( SM_CXFULLSCREEN ); 238| int scr_h = GetSystemMetrics( SM_CYFULLSCREEN ); 239| 240| GetWindowRect( &rect ); 241| if ( m_CursorPos.x < 0 || m_CursorPos.y < 0 ) GetCursorPos( &point ); 242| else point = m_CursorPos; 243| point.x += 100; point.y += 108; 244| 245| nLine = m_TextCtrl.GetLineCount(); 246| if ( nLine > 3 ) { 247| i1 = m_TextCtrl.LineIndex( 2 ); 248| pt = m_TextCtrl.PosFromChar( i1 ); 249| rect.bottom += (nLine - 3) * ( pt.y + ( m_PenInputPanel == 0 ? 0 : 4 ) ); 250| } 251| 252| w = rect.right - rect.left; h = rect.bottom - rect.top; 253| rect.left = point.x - w / 2; rect.right = rect.left + w; 254| rect.top = point.y - h / 2; rect.bottom = rect.top + h; 255| if ( rect.right >= scr_w ) { rect.left -= rect.right - scr_w; rect.right = scr_w; } 256| if ( rect.bottom >= scr_h ) { rect.top -= rect.bottom - scr_h; rect.bottom = scr_h; } 257| if ( rect.left < 0 ) { rect.right += -rect.left; rect.left = 0; } 258| if ( rect.top < 0 ) { rect.bottom += -rect.top; rect.top = 0; } 259| 260| SystemParametersInfo( SPI_GETWORKAREA, 0, &desktopRect, 0 ); 261| max = desktopRect.bottom - desktopRect.top; 262| if ( m_PenInputPanel != NULL ) { 263| long height; 264| 265| m_PenInputPanel->get_Height( &height ); 266| max -= height; 267| } 268| if ( rect.bottom - rect.top > max ) { 269| rect.bottom = rect.top + max; 270| } 271| if ( rect.bottom > max ) { 272| rect.top -= rect.bottom - max; 273| rect.bottom = max; 274| } 275| 276| MoveWindow( &rect ); 277| } 278| 279| if ( m_ID == m_ID_prev || m_bNoSelect ) { 280| if ( !m_bDispPenPanel ) { 281| m_TextCtrl.LineScroll( m_iLine ); 282| } 283| } 284| else { 285| if ( m_PenInputPanel == NULL ) { 286| if ( StrX_strchrs( m_Text, "\r\n" ) != NULL ) { 287| m_TextCtrl.SetSel( 0, 0 ); 288| m_TextCtrl.SetFocus(); /* コレをしないと全選択になってしまう */ 289| } 290| else { 291| m_TextCtrl.SetSel( 0, -1 ); 292| } 293| } 294| else { 295| if ( StrX_strchrs( m_Text, "\r\n" ) == NULL ) { 296|#if 0 297| m_Text2Ctrl.SetFocus(); 298| m_Text2Ctrl.SetSelStart( 0 ); 299| m_Text2Ctrl.SetSelLength( strlen(m_Text) ); 300|#endif 301| } 302| } 303| } 304| 305| m_ToggleCtrlEnter.SetCheck( ! m_bCtrlRet ); 306| SetCtrlRet( m_bCtrlRet ); 307| m_bShift = false; 308| m_bCtrl = false; 309| 310| /* 編集中の状態をリセットする */ 311| m_ID_prev = m_ID; 312| 313| 314|// m_TextCtrl.ShowWindow( m_PenInputPanel == NULL || !m_bDispPenPanel ? SW_SHOW : SW_HIDE ); 315| m_TextCtrl.ShowWindow( SW_SHOW ); 316|// m_Text2Ctrl.ShowWindow( m_PenInputPanel == NULL || !m_bDispPenPanel ? SW_HIDE : SW_SHOW ); 317| WinX_setIme( m_hWnd, m_bImeOn ); 318| 319| AdjustUI(); 320| m_TextCtrl2_bModify = false; 321| if ( m_bHideMain ) m_ShowWindowFunc( m_HideTarget, false ); 322| 323| return FALSE; // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります 324| // 例外: OCX プロパティ ページの戻り値は FALSE となります 325|} 326| 327| 328|int CInputML1::OnCreate(LPCREATESTRUCT lpCreateStruct) 329|{ 330| if (CDialog::OnCreate(lpCreateStruct) == -1) 331| return -1; 332| 333| ModifyStyleEx( 0, WS_EX_APPWINDOW ); 334| 335| return 0; 336|} 337| 338| 339| 340|void CInputML1::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 341|{ 342| CDialog::OnActivate(nState, pWndOther, bMinimized); 343| 344| if ( nState == WA_ACTIVE || nState == WA_CLICKACTIVE ) { 345| if ( m_bDispPenPanel != NULL ) { 346| SetFocusToEdit(); 347| } 348| } 349|} 350| 351| 352|void CInputML1::SetFocusToEdit() 353|{ 354| HRESULT hr; 355| 356|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 357| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 358| 359| editCtrl->SetFocus(); 360| m_HideMainBtn.SetState( m_bHideMain ? 1 : 0 ); 361| 362| if ( m_PenInputPanel != NULL ) { 363|// m_TextCtrl.ShowWindow( m_bDispPenPanel ? SW_HIDE : SW_SHOW ); 364| m_TextCtrl.ShowWindow( SW_SHOW ); 365|// m_Text2Ctrl.ShowWindow( m_bDispPenPanel ? SW_SHOW : SW_HIDE ); 366| 367| if ( m_bDispPenPanel ) { 368| hr = m_PenInputPanel->put_Visible( m_bDispPenPanel ); 369| if ( hr != 0 ) return; /* コントロールが準備できていない */ 370| } 371| } 372|} 373| 374| 375| 376| 377|void CInputML1::save() 378|{ 379| if ( m_bDispPenPanel ) { 380| #if 0 /* 自動保存時にハングアップするためカット */ 381| VARIANT_BOOL busy; 382| 383| m_PenInputPanel->CommitPendingInput(); 384| for (;;) { 385| m_PenInputPanel->get_Visible( &busy ); 386| if ( ! busy ) break; 387| Sleep(50); 388| } 389| #endif 390| 391|#if 0 392| m_Text = m_Text2Ctrl.GetText(); 393| m_iStart = m_Text2Ctrl.GetSelStart(); 394| m_iEnd = m_Text2Ctrl.GetSelLength() + m_iStart; 395| m_iLine = 0; // InkEdit にこのインターフェイスがない 396|#endif 397| } 398| else { 399| m_TextCtrl.GetWindowText( m_Text ); 400| m_TextCtrl.GetSel( m_iStart, m_iEnd ); 401| m_iLine = m_TextCtrl.GetFirstVisibleLine(); 402| } 403| m_bMax = IsZoomed() != 0; 404| if ( ! m_bMax ) 405| GetWindowRect( &m_WinRect ); 406| 407| /* 1行を m_mByteInLine に制限する */ 408| { 409| char* s = (char*)malloc( CInputML_MTextByte ); 410| 411| strcpy( s, m_Text.Left( CInputML_MTextByte - 1 ) ); 412| StrX_separateByByteInLine( s, CInputML_MTextByte, m_mByteInLine, "\r\n" ); 413| m_Text = s; 414| 415| free( s ); 416| } 417|} 418| 419|void CInputML1::saveAlways() 420|{ 421| m_bImeOn = WinX_getIme( m_hWnd ); 422|} 423| 424| 425| 426|void CInputML1::AdjustUI() 427|{ 428| CMenu* menu = GetMenu(); 429| 430| menu->EnableMenuItem( ID_Redo, MF_BYCOMMAND | 431| ( m_bDispPenPanel ? MF_ENABLED : MF_GRAYED ) ); 432| m_RedoBtn.ShowWindow( m_bDispPenPanel ); 433| 434| m_KeyboardBtn.SetState( m_bDispPenPanel ? 0 : 1 ); 435| m_KeyboardBtn.EnableWindow( m_PenInputPanel != NULL ); 436| menu->EnableMenuItem( ID_Keyboard, MF_BYCOMMAND | 437| ( m_PenInputPanel == NULL ? MF_GRAYED : MF_ENABLED ) ); 438| menu->CheckMenuItem( ID_Keyboard, MF_BYCOMMAND | 439| ( m_bDispPenPanel ? MF_UNCHECKED : MF_CHECKED ) ); 440| 441| m_PenBtn.SetState( m_bDispPenPanel ? 1 : 0 ); 442| m_PenBtn.EnableWindow( m_PenInputPanel != NULL ); 443| menu->EnableMenuItem( ID_Pen, MF_BYCOMMAND | 444| ( m_PenInputPanel == NULL ? MF_GRAYED : MF_ENABLED ) ); 445| menu->CheckMenuItem( ID_Pen, MF_BYCOMMAND | 446| ( m_bDispPenPanel ? MF_CHECKED : MF_UNCHECKED ) ); 447| 448| menu->CheckMenuItem( ID_HideMain, MF_BYCOMMAND | 449| ( m_bHideMain ? MF_CHECKED : MF_UNCHECKED ) ); 450| 451| SetFocusToEdit(); 452|} 453| 454| 455| 456|void CInputML1::OnOK() 457|{ 458| m_ShowWindowFunc( m_HideTarget, true ); 459| save(); 460| saveAlways(); 461| CDialog::OnOK(); 462|} 463| 464| 465|void CInputML1::OnCancel() 466|{ 467| m_ShowWindowFunc( m_HideTarget, true ); 468| 469| if ( m_TextCtrl.GetModify() || m_TextCtrl2_bModify ) { 470| switch ( MessageBox( "編集した内容を使いますか?", "", MB_YESNOCANCEL ) ) { 471| case IDYES: OnOK(); return; 472| case IDCANCEL: return; 473| } 474| } 475| 476| saveAlways(); 477| m_Text = m_OldText; 478| m_TextCtrl.GetSel( m_iStart, m_iEnd ); 479| m_iLine = m_TextCtrl.GetFirstVisibleLine(); 480| 481| m_ID_prev = NULL; 482| 483| CDialog::OnCancel(); 484|} 485| 486|void CInputML1::OnSaveBtn() 487|{ 488| save(); 489| if ( m_SaveFunc != NULL ) 490| m_SaveFunc( m_SaveObj, this ); 491| 492| SetFocusToEdit(); 493|} 494| 495| 496|void CInputML1::OnEditSave() 497|{ 498| OnSaveBtn(); 499|} 500| 501| 502|BOOL CInputML1::PreTranslateMessage(MSG* msg) 503|{ 504| switch( msg->message ) { 505| case WM_LBUTTONDOWN: 506| case WM_LBUTTONUP: 507| case WM_MOUSEMOVE: 508| m_ToolTip.RelayEvent( msg ); 509| break; 510| } 511| 512| if ( msg->message == WM_KEYDOWN ) { 513| if ( msg->wParam == VK_CONTROL ) m_bCtrl = true; 514| if ( msg->wParam == VK_SHIFT ) m_bShift = true; 515| if ( msg->wParam == VK_F3 ) { 516| if ( m_bShift ) OnSearchPrev(); 517| else OnSearchNext(); 518| } 519| if ( msg->wParam == 'S' && m_bCtrl ) { /* アクセラレータが使えないため */ 520| OnSaveBtn(); 521| m_bCtrl = false; 522| return TRUE; 523| } 524| if ( msg->wParam == 'A' && m_bCtrl ) { /* アクセラレータが使えないため */ 525| OnSelectAll(); 526| m_bCtrl = false; 527| return TRUE; 528| } 529| if ( msg->wParam == 'F' && m_bCtrl ) { /* アクセラレータが使えないため */ 530| OnSearch(); 531| m_bCtrl = false; 532| return TRUE; 533| } 534| if ( msg->wParam == '\r' ) { 535| if ( m_bCtrl == m_bCtrlRet ) 536| OnRet(); 537| else { 538| m_TextCtrl.SetFocus(); /* これをしないと IPenInputPanel でしばらく固まる */ 539| this->PostMessage( WM_COMMAND, IDOK ); 540| } 541| return TRUE; 542| } 543| } 544| if ( msg->message == WM_KEYUP ) { 545| if ( msg->wParam == VK_CONTROL ) m_bCtrl = false; 546| if ( msg->wParam == VK_SHIFT ) m_bShift = false; 547| } 548| 549| return CDialog::PreTranslateMessage( msg ); 550|} 551| 552|void CInputML1::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) 553|{ 554| RECT desktopRect; 555| int max; 556| 557| SystemParametersInfo( SPI_GETWORKAREA, 0, &desktopRect, 0 ); 558| max = desktopRect.bottom - desktopRect.top; 559| if ( m_PenInputPanel != NULL ) { 560| short bVisible; 561| 562| m_PenInputPanel->get_Visible( &bVisible ); 563| if ( bVisible ) { 564| long height; 565| 566| m_PenInputPanel->get_Height( &height ); 567| max -= height; 568| } 569| } 570| 571| lpMMI->ptMinTrackSize.x = 456; 572| lpMMI->ptMinTrackSize.y = 155; 573| lpMMI->ptMaxTrackSize.x = desktopRect.right - desktopRect.left; 574| lpMMI->ptMaxTrackSize.y = max; 575| 576| CDialog::OnGetMinMaxInfo(lpMMI); 577|} 578| 579|void CInputML1::OnRet() 580|{ 581| CString s; 582|// int iStart, iEnd, iStart2, iEnd2; 583| 584| if ( m_bDispPenPanel == NULL ) { 585| m_TextCtrl.ReplaceSel( "\r\n" ); 586| m_TextCtrl.SetFocus(); 587| } 588| else { 589|#if 0 590| HRESULT hr; 591| unsigned short* work; 592| int work_size; 593| 594| s = m_Text2Ctrl.GetText(); 595| work_size = ( strlen( s ) + 1 ) * 4; 596| work = (unsigned short*)malloc( work_size ); 597| iStart = m_Text2Ctrl.GetSelStart(); 598| iEnd = iStart + m_Text2Ctrl.GetSelLength(); 599| iStart2 = StrX_convIdxEdit2SJis( s, iStart, work, work_size ); 600| iEnd2 = StrX_convIdxEdit2SJis( s, iEnd, work, work_size ); 601| if ( iEnd2 != iStart2 ) 602| s.Delete( iStart2, iEnd2 - iStart2 ); 603| s.Insert( iStart2, "\r\n" ); 604| m_Text2Ctrl.SetText( s ); 605| m_TextCtrl.SetWindowText( s ); 606| m_Text2Ctrl.SetSelStart( iStart + 1 ); 607| free( work ); 608| m_Text2Ctrl.SetFocus(); 609| 610| if ( m_bDispPenPanel ) { 611| hr = m_PenInputPanel->put_Visible( VARIANT_TRUE ); 612| if ( hr != 0 ) error(); 613| } 614|#endif 615| } 616|} 617| 618|void CInputML1::OnToggleCtrlEnter() 619|{ 620| SetCtrlRet( m_ToggleCtrlEnter.GetCheck() == 0 ); 621| SetFocusToEdit(); 622|} 623| 624| 625|void CInputML1::SetCtrlRet( bool bCtrlRet ) 626|{ 627| m_bCtrlRet = bCtrlRet; 628| 629| if ( bCtrlRet ) { 630| m_Guide.SetWindowText( m_bJapanese ? "の入力は Ctrl+Enterです。(R)" : 631| "will be inserted by Ctrl+Enter." ); 632| } 633| else { 634| m_Guide.SetWindowText( m_bJapanese ? "の入力は Enterです。(R)" : 635| "will be inserted by Enter." ); 636| } 637|} 638| 639| 640|void CInputML1::OnSize(UINT nType, int cx, int cy) 641|{ 642| RECT prev = m_Rect; 643| RECT rc; 644| int dx, dy; 645| 646| CDialog::OnSize(nType, cx, cy); 647| 648| if ( IsIconic() ) return; 649| 650| GetWindowRect( &m_Rect ); 651| if ( IsZoomed() ) 652| WinX_getWndRectN( m_hWnd, &m_WinRect ); 653| else if ( ! m_Creating || m_ID != m_ID_prev ) 654| m_WinRect = m_Rect; 655| 656| if ( ! m_Creating ) { 657| 658| dx = ( m_Rect.right - m_Rect.left ) - ( prev.right - prev.left ); 659| dy = ( m_Rect.bottom - m_Rect.top ) - ( prev.bottom - prev.top ); 660| 661| m_TextCtrl.GetWindowRect( &rc ); 662| rc.right += dx; rc.bottom += dy; 663| ScreenToClient( &rc ); 664| m_TextCtrl.MoveWindow( &rc ); 665| 666|#if 0 667| m_Text2Ctrl.GetWindowRect( &rc ); 668| rc.right += dx; rc.bottom += dy; 669| ScreenToClient( &rc ); 670| m_Text2Ctrl.MoveWindow( &rc ); 671|#endif 672| 673| m_ToggleCtrlEnter.GetWindowRect( &rc ); 674| rc.top += dy; rc.bottom += dy; 675| ScreenToClient( &rc ); 676| m_ToggleCtrlEnter.MoveWindow( &rc ); 677| 678| m_RetCtrl.GetWindowRect( &rc ); 679| rc.top += dy; rc.bottom += dy; 680| ScreenToClient( &rc ); 681| m_RetCtrl.MoveWindow( &rc ); 682| 683| m_Guide.GetWindowRect( &rc ); 684| rc.top += dy; rc.bottom += dy; 685| ScreenToClient( &rc ); 686| m_Guide.MoveWindow( &rc ); 687| 688| m_OKCtrl.GetWindowRect( &rc ); 689| rc.left += dx; rc.right += dx; 690| rc.top += dy; rc.bottom += dy; 691| ScreenToClient( &rc ); 692| m_OKCtrl.MoveWindow( &rc ); 693| 694| m_CancelCtrl.GetWindowRect( &rc ); 695| rc.left += dx; rc.right += dx; 696| rc.top += dy; rc.bottom += dy; 697| ScreenToClient( &rc ); 698| m_CancelCtrl.MoveWindow( &rc ); 699| } 700|} 701| 702|void CInputML1::OnCut() 703|{ 704|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 705| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 706| 707| /* Ctrl キーを押した状態にする */ 708| GetKeyboardState( m_Keys ); 709| m_Keys[VK_CONTROL] = 128; 710| SetKeyboardState( m_Keys ); 711| 712| /* キーボード・メッセージを送る */ 713| editCtrl->PostMessage( WM_KEYDOWN, 'X', 0 ); /* SendMessage では動きません */ 714| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); /* Ctrl キーの状態を戻すため */ 715| 716| /* Del ボタンに移ってしまったフォーカスを、Edit コントロールに戻す */ 717| SetFocusToEdit(); 718|} 719| 720|void CInputML1::OnCopy() 721|{ 722|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 723| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 724| 725| GetKeyboardState( m_Keys ); 726| m_Keys[VK_CONTROL] = 128; 727| SetKeyboardState( m_Keys ); 728| editCtrl->PostMessage( WM_KEYDOWN, 'C', 0 ); 729| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 730| SetFocusToEdit(); 731|} 732| 733|void CInputML1::OnPaste() 734|{ 735|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 736| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 737| 738| GetKeyboardState( m_Keys ); 739| m_Keys[VK_CONTROL] = 128; 740| SetKeyboardState( m_Keys ); 741| editCtrl->PostMessage( WM_KEYDOWN, 'V', 0 ); 742| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 743| SetFocusToEdit(); 744|} 745| 746|void CInputML1::OnDel() 747|{ 748|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 749| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 750| 751| editCtrl->PostMessage( WM_KEYDOWN, VK_DELETE, 0 ); 752| SetFocusToEdit(); 753|} 754| 755|void CInputML1::OnUndo() 756|{ 757|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 758| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 759| 760| GetKeyboardState( m_Keys ); 761| m_Keys[VK_CONTROL] = 128; 762| SetKeyboardState( m_Keys ); 763| editCtrl->PostMessage( WM_KEYDOWN, 'Z', 0 ); 764| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 765| SetFocusToEdit(); 766|} 767| 768|void CInputML1::OnRedo() 769|{ 770|// CWnd* editCtrl = ( !m_bDispPenPanel ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl; 771| CWnd* editCtrl = (CWnd*)&m_TextCtrl; 772| 773| GetKeyboardState( m_Keys ); 774| m_Keys[VK_CONTROL] = 128; 775| SetKeyboardState( m_Keys ); 776| editCtrl->PostMessage( WM_KEYDOWN, 'Y', 0 ); 777| this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 ); 778| SetFocusToEdit(); 779|} 780| 781|BOOL CInputML1::OnCommand(WPARAM wParam, LPARAM lParam) 782|{ 783| switch ( wParam ) { 784| 785| case CInputML_KeyPosted: 786| 787| /* Ctrl キーを押さない状態にする */ 788| GetKeyboardState( m_Keys ); 789| m_Keys[VK_CONTROL] = 0; 790| SetKeyboardState( m_Keys ); 791| break; 792| } 793| 794| return CDialog::OnCommand(wParam, lParam); 795|} 796| 797|void CInputML1::OnKeyboard() 798|{ 799| m_bDispPenPanel = false; 800| AdjustUI(); 801|} 802| 803|void CInputML1::OnPen() 804|{ 805| m_bDispPenPanel = true; 806| AdjustUI(); 807|} 808| 809|void CInputML1::OnHideMain() 810|{ 811| static int bIn = false; 812| 813| if ( bIn ) return; 814| 815| bIn = true; 816| m_bHideMain = !m_bHideMain; 817| m_ShowWindowFunc( m_HideTarget, ! m_bHideMain ); 818| AdjustUI(); 819| bIn = false; 820|} 821| 822| 823|BOOL CInputML1::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 824|{ 825|#if 0 826| HRESULT hr; 827| 828| hr = m_PenInputPanel->put_Visible( m_bDispPenPanel ); 829| if ( hr != 0 ) error(); 830|#endif 831| 832| return CDialog::Create(IDD, pParentWnd); 833|} 834| 835| 836|void CInputML1::OnSelectAll() 837|{ 838| m_TextCtrl.SetSel( 0, -1 ); 839|} 840| 841|void CInputML1::OnSearch() 842|{ 843| CInputDlg1 dlg; 844| 845| dlg.m_Msg = "キーワード:"; 846| dlg.m_Text = m_kword; 847| dlg.m_bPath = false; 848| dlg.m_bSetAtCursor = true; 849| 850| if ( dlg.DoModal() == IDOK ) { 851| m_kword = dlg.m_Text; 852| OnSearch_imp( m_kword, false ); 853| } 854|} 855| 856|void CInputML1::OnSearchNext() 857|{ 858| OnSearch_imp( m_kword, false ); 859|} 860| 861|void CInputML1::OnSearchPrev() 862|{ 863| OnSearch_imp( m_kword, true ); 864|} 865| 866|void CInputML1::OnSearch_imp( const char* kword, bool bRev ) 867|{ 868| CString s; 869| int iStart, iEnd; 870| char* f; 871| 872| m_TextCtrl.GetSel( iStart, iEnd ); 873| m_TextCtrl.GetWindowText( s ); 874| 875| if ( iStart < iEnd ) { 876| m_kword = s.Mid( iStart, iEnd - iStart ); 877| kword = m_kword; 878| } 879| 880| if ( m_kword[0] == '\0' ) return; 881| 882| if ( bRev ) 883| f = StrX_stristr3r( (const char*)s, iStart - 1, kword, false, NULL ); 884| else 885| f = StrX_stristr3( (const char*)s + iStart + 1, kword, false, NULL ); 886| 887| if ( f != NULL ) { 888| m_TextCtrl.SetSel( f - (const char*)s, f - (const char*)s + strlen(kword) ); 889| } 890|} 891|