InputDlg.cpp

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

[目次 | 関数 | マクロ]

目次

関数一覧

マクロ一覧


   1|// InputDlg.cpp : インプリメンテーション ファイル 
   2|//
   3|
   4|/***********************************************************************
   5|*  1. <<< 汎用入力ウィンドウ >>>
   6|************************************************************************/
   7|
   8|#include "mixer_precomp.h"
   9|#ifdef  USES_MXP_AUTOINC
  10| #include  "SVGCat.ah"
  11|#endif
  12|
  13|#ifdef _DEBUG
  14|#define new DEBUG_NEW
  15|#undef THIS_FILE
  16|static char THIS_FILE[] = __FILE__;
  17|#endif
  18|
  19|/////////////////////////////////////////////////////////////////////////////
  20|// CInputDlg ダイアログ
  21|
  22|
  23|CInputDlg::CInputDlg(CWnd* pParent /*=NULL*/)
  24|	: CDialog(CInputDlg::IDD, pParent)
  25|{
  26|	//{{AFX_DATA_INIT(CInputDlg)
  27|	m_Text = _T("");
  28|	m_Msg = _T("");
  29|	//}}AFX_DATA_INIT
  30|  m_SelStart = 0;
  31|  m_SelEnd = -1;
  32|  m_bPath = false;
  33|  m_Filter = "All Files (*.*)|*.*||";
  34|  m_bSetAtCursor = true;
  35|  m_XY.x = 0;  m_XY.y = 0;
  36|  m_PenInputPanel = NULL;
  37|  m_bActive = true;
  38|}
  39|
  40|
  41|void CInputDlg::DoDataExchange(CDataExchange* pDX)
  42|{
  43|	CDialog::DoDataExchange(pDX);
  44|	//{{AFX_DATA_MAP(CInputDlg)
  45|	DDX_Control(pDX, IDC_Cut, m_CutBtn);
  46|	DDX_Control(pDX, IDC_Paste, m_PasteBtn);
  47|	DDX_Control(pDX, IDC_Copy, m_CopyBtn);
  48|	DDX_Control(pDX, IDC_Text, m_TextCtrl);
  49|	DDX_Control(pDX, IDC_Browse, m_Browse);
  50|	DDX_Text(pDX, IDC_Text, m_Text);
  51|	DDX_Text(pDX, IDC_Msg, m_Msg);
  52|	DDX_Control(pDX, IDC_Text2, m_Text2Ctrl);
  53|	//}}AFX_DATA_MAP
  54|}
  55|
  56|
  57|BEGIN_MESSAGE_MAP(CInputDlg, CDialog)
  58|	//{{AFX_MSG_MAP(CInputDlg)
  59|	ON_BN_CLICKED(IDC_Browse, OnBrowse)
  60|	ON_EN_CHANGE(IDC_Text, OnChangeText)
  61|	ON_WM_ACTIVATE()
  62|	ON_BN_CLICKED(IDC_Paste, OnPaste)
  63|	ON_BN_CLICKED(IDC_Copy, OnCopy)
  64|	ON_BN_CLICKED(IDC_Cut, OnCut)
  65|	//}}AFX_MSG_MAP
  66|END_MESSAGE_MAP()
  67|
  68|BEGIN_EVENTSINK_MAP(CInputDlg, CDialog)
  69|    //{{AFX_EVENTSINK_MAP(CInputDlg)
  70|	ON_EVENT(CInputDlg, IDC_Text2, 1 /* Change */, OnChangeText2, VTS_NONE)
  71|	//}}AFX_EVENTSINK_MAP
  72|END_EVENTSINK_MAP()
  73|
  74|
  75|/////////////////////////////////////////////////////////////////////////////
  76|// CInputDlg メッセージ ハンドラ
  77|
  78|
  79|BOOL CInputDlg::OnInitDialog()
  80|{
  81|  CDialog::OnInitDialog();
  82|  CString  s;
  83|  RECT   rect;
  84|  POINT  point;
  85|  int  w, h;
  86|  int  scr_w = GetSystemMetrics( SM_CXFULLSCREEN );
  87|  int  scr_h = GetSystemMetrics( SM_CYFULLSCREEN );
  88|  char  ss[256];
  89|
  90|
  91|  /* ペン入力パネルを設定する */
  92|  if ( m_PenInputPanel != NULL ) {
  93|    BSTR  s;
  94|    HRESULT  hr;
  95|
  96|    hr = m_PenInputPanel->put_AttachedEditWindow( (LONG_PTR)m_Text2Ctrl.GetHwnd() );
  97|    if ( hr != 0 )  error();
  98|
  99|    s = SysAllocString( OLESTR("ALL") );
 100|    hr = m_PenInputPanel->put_Factoid( s );
 101|    SysFreeString( s );
 102|    if ( hr != 0 )  error();
 103|
 104|    hr = m_PenInputPanel->EnableTsf( VARIANT_TRUE );
 105|    if ( hr != 0 )  error();
 106|
 107|    hr = m_PenInputPanel->put_AutoShow( VARIANT_FALSE );
 108|    if ( hr != 0 )  error();
 109|
 110|    hr = m_PenInputPanel->put_HorizontalOffset( -40 );
 111|    if ( hr != 0 )  error();
 112|    hr = m_PenInputPanel->put_VerticalOffset( 47 );
 113|    if ( hr != 0 )  error();
 114|  }
 115|
 116|
 117|  /* テキストボックスの初期化をする */
 118|  if ( m_PenInputPanel == NULL ) {
 119|    m_TextCtrl.SetFocus();
 120|    if ( m_SelStart == -1 && m_SelEnd == -1 ) {
 121|      m_TextCtrl.GetWindowText( s );
 122|      m_TextCtrl.SetSel( s.GetLength(), s.GetLength() );
 123|    }
 124|    else
 125|      m_TextCtrl.SetSel( m_SelStart, m_SelEnd );
 126|  }
 127|  else {
 128|    m_Text2Ctrl.SetFocus();
 129|    if ( m_SelStart == -1 && m_SelEnd == -1 ) {
 130|      m_Text2Ctrl.SetSelStart( m_Text.GetLength() );
 131|      m_Text2Ctrl.SetSelLength( 0 );
 132|    }
 133|    else {
 134|      m_Text2Ctrl.SetText( m_Text );
 135|      m_Text2Ctrl.SetSelStart( m_SelStart );
 136|      if ( m_SelEnd < 0 )
 137|        m_Text2Ctrl.SetSelLength( m_Text.GetLength() );
 138|      else
 139|        m_Text2Ctrl.SetSelLength( m_SelEnd - m_SelStart );
 140|    }
 141|  }
 142|
 143|  m_CutBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Cut) );
 144|  m_CopyBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Copy) );
 145|  m_PasteBtn.SetIcon( AfxGetApp()->LoadIcon(IDI_Paste) );
 146|
 147|  m_ToolTip.Create( this );
 148|  LoadString( AfxGetInstanceHandle(), ID_EDIT_COPY, ss, sizeof(ss) );
 149|  StrX_cpy1Line( ss, sizeof(ss), ss, 2 );
 150|  m_ToolTip.AddTool( GetDlgItem(IDC_Copy), ss );
 151|
 152|  LoadString( AfxGetInstanceHandle(), ID_EDIT_PASTE, ss, sizeof(ss) );
 153|  StrX_cpy1Line( ss, sizeof(ss), ss, 2 );
 154|  m_ToolTip.AddTool( GetDlgItem(IDC_Paste), ss );
 155|
 156|  GetWindowRect( &rect );
 157|  if ( m_bSetAtCursor ) {
 158|    GetCursorPos( &point );
 159|    point.x += 100;  point.y += 80;
 160|  }
 161|  else {
 162|    point.x = m_XY.x;  point.y = m_XY.y;
 163|  }
 164|  w = rect.right - rect.left;   h = rect.bottom - rect.top;
 165|  rect.left = point.x - w / 2;  rect.right = rect.left + w;
 166|  rect.top = point.y - h / 2;   rect.bottom = rect.top + h;
 167|  if ( rect.right >= scr_w )  { rect.left -= rect.right - scr_w;  rect.right = scr_w; }
 168|  if ( rect.bottom >= scr_h )  { rect.top -= rect.bottom - scr_h;  rect.bottom = scr_h; }
 169|  if ( rect.left < 0 )  { rect.right += -rect.left;  rect.left = 0; }
 170|  if ( rect.top < 0 )  { rect.bottom += -rect.top;  rect.top = 0; }
 171|  MoveWindow( &rect );
 172|
 173|  m_Browse.ShowWindow( m_bPath ? SW_SHOW : SW_HIDE );
 174|
 175|  WinX_setIme( m_hWnd, false );
 176|
 177|  m_TextCtrl.ShowWindow( m_PenInputPanel == NULL ? SW_SHOW : SW_HIDE );
 178|  m_Text2Ctrl.ShowWindow( m_PenInputPanel == NULL ? SW_HIDE : SW_SHOW );
 179|
 180|  return FALSE;  // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります
 181|                // 例外: OCX プロパティ ページの戻り値は FALSE となります
 182|}
 183|
 184|
 185| 
 186|void CInputDlg::OnBrowse() 
 187|{
 188|  CString  s;
 189|  m_bActive = false;
 190|
 191|  m_TextCtrl.GetWindowText( s );
 192|  {
 193|    CFileDialog  dlg( TRUE, NULL, s, OFN_HIDEREADONLY | OFN_EXPLORER, m_Filter );
 194|
 195|    if ( dlg.DoModal() == IDOK ) {
 196|      m_TextCtrl.SetWindowText( dlg.GetPathName() );
 197|      m_Text2Ctrl.SetText( dlg.GetPathName() );
 198|    }
 199|  }
 200|
 201|  m_bActive = true;
 202|  SetFocusToEdit();
 203|}
 204|
 205|
 206|
 207| 
 208|void CInputDlg::OnChangeText() 
 209|{
 210|  if ( m_PenInputPanel != NULL && ::GetFocus() == m_TextCtrl.m_hWnd ) {
 211|    if ( m_PenInputPanel != NULL ) {
 212|      CString s;
 213|
 214|      m_TextCtrl.GetWindowText( s );
 215|      m_Text2Ctrl.SetText( s );
 216|    }
 217|  }
 218|}
 219|
 220|void CInputDlg::OnChangeText2()
 221|{
 222|  if ( m_PenInputPanel != NULL && ::GetFocus() == (HWND)m_Text2Ctrl.GetHwnd()  ) {
 223|    if ( m_PenInputPanel != NULL ) {
 224|      CString s;
 225|
 226|      s = m_Text2Ctrl.GetText();
 227|      m_TextCtrl.SetWindowText( s );
 228|    }
 229|  }
 230|}
 231|
 232| 
 233|void CInputDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
 234|{
 235|  if ( ! m_bActive )  return;
 236|
 237|  if ( nState == WA_ACTIVE || nState == WA_CLICKACTIVE ) {
 238|    SetFocusToEdit();
 239|  }
 240|}
 241|
 242| 
 243|void CInputDlg::OnOK() 
 244|{
 245|  if ( m_PenInputPanel != NULL ) {
 246|    VARIANT_BOOL  busy;
 247|    CString  s;
 248|
 249|    m_PenInputPanel->CommitPendingInput();
 250|    for (;;) {
 251|      m_PenInputPanel->get_Visible( &busy );
 252|      if ( ! busy )  break;
 253|      Sleep(50);
 254|    }
 255|
 256|    s = m_Text2Ctrl.GetText();
 257|    m_TextCtrl.SetWindowText( s );
 258|  }
 259|
 260|	CDialog::OnOK();
 261|}
 262| 
 263|BOOL CInputDlg::PreTranslateMessage(MSG* pMsg) 
 264|{
 265|  if ( pMsg->message == WM_KEYDOWN ) {
 266|    if ( pMsg->wParam == '\r' ) {
 267|      m_TextCtrl.SetFocus();  /* これをしないと IPenInputPanel でしばらく固まる */
 268|      this->PostMessage( WM_COMMAND, IDOK );
 269|      return  TRUE;
 270|    }
 271|  }
 272|
 273|	return CDialog::PreTranslateMessage(pMsg);
 274|}
 275| 
 276|void CInputDlg::OnCut() 
 277|{
 278|  CWnd*  editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl;
 279|
 280|  GetKeyboardState( m_Keys );
 281|  m_Keys[VK_CONTROL] = 128;
 282|  SetKeyboardState( m_Keys );
 283|  editCtrl->PostMessage( WM_KEYDOWN, 'X', 0 );
 284|  this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 );
 285|  SetFocusToEdit();
 286|}
 287| 
 288|void CInputDlg::OnCopy() 
 289|{
 290|  CWnd*  editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl;
 291|
 292|  GetKeyboardState( m_Keys );
 293|  m_Keys[VK_CONTROL] = 128;
 294|  SetKeyboardState( m_Keys );
 295|  editCtrl->PostMessage( WM_KEYDOWN, 'C', 0 );
 296|  this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 );
 297|  SetFocusToEdit();
 298|}
 299|
 300|void CInputDlg::OnPaste()
 301|{
 302|  CWnd*  editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl;
 303|
 304|  GetKeyboardState( m_Keys );
 305|  m_Keys[VK_CONTROL] = 128;
 306|  SetKeyboardState( m_Keys );
 307|  editCtrl->PostMessage( WM_KEYDOWN, 'V', 0 );
 308|  this->PostMessage( WM_COMMAND, CInputML_KeyPosted, 0 );
 309|  SetFocusToEdit();
 310|}
 311| 
 312|void  CInputDlg::SetFocusToEdit() 
 313|{
 314|  HRESULT  hr;
 315|  CWnd*  editCtrl = ( m_PenInputPanel == NULL ) ? (CWnd*)&m_TextCtrl : (CWnd*)&m_Text2Ctrl;
 316|
 317|  editCtrl->SetFocus();
 318|
 319|  if ( m_PenInputPanel != NULL ) {
 320|    m_TextCtrl.ShowWindow( SW_HIDE );
 321|    m_Text2Ctrl.ShowWindow( SW_SHOW );
 322|
 323|    hr = m_PenInputPanel->put_Visible( TRUE );
 324|    if ( hr != 0 )  return;  /* コントロールが準備できていない */
 325|  }
 326|}
 327| 
 328|BOOL CInputDlg::OnCommand(WPARAM wParam, LPARAM lParam) 
 329|{
 330|  switch ( wParam ) {
 331|
 332|    case  CInputML_KeyPosted:
 333|
 334|      /* Ctrl キーを押さない状態にする */
 335|      GetKeyboardState( m_Keys );
 336|      m_Keys[VK_CONTROL] = 0;
 337|      SetKeyboardState( m_Keys );
 338|      break;
 339|  }
 340|
 341|	return CDialog::OnCommand(wParam, lParam);
 342|}
 343| 
 344|