InputML.cpp

C:\home\SVGCats_src\src\InputML.cpp

[関数 | マクロ]

関数一覧

マクロ一覧


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