412 lines
10 KiB
C++
412 lines
10 KiB
C++
// CharToolbarDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "CharToolbarDlg.h"
|
|
#include "chardlg.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
//TARCH_IMPEXP bool FindRT_MANIFEST();
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCharToolbarDlg dialog
|
|
|
|
IMPLEMENT_DYNAMIC(CCharToolbarDlg, CModelessDialog)
|
|
CCharToolbarDlg::CCharToolbarDlg(UINT IDD, CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(IDD, pParent)
|
|
{
|
|
//{{AFX_DATA_INIT(CCharToolbarDlg)
|
|
// NOTE: the ClassWizard will add member initialization here
|
|
//}}AFX_DATA_INIT
|
|
m_nOperCode = -1;
|
|
m_bNeedSingleLineText = TRUE; // sg add 090324
|
|
}
|
|
|
|
|
|
void CCharToolbarDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CCharToolbarDlg)
|
|
// NOTE: the ClassWizard will add DDX and DDV calls here
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CCharToolbarDlg, CModelessDialog)
|
|
//{{AFX_MSG_MAP(CCharToolbarDlg)
|
|
//}}AFX_MSG_MAP
|
|
//ON_COMMAND_RANGE(ID_DOWN_MARK, ID_ONE_STEEL, OnChar)
|
|
ON_COMMAND_RANGE(ID_SPECIAL_CHAR, ID_PICKTEXT, OnChar)
|
|
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
|
|
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CCharToolbarDlg message handlers
|
|
BOOL CCharToolbarDlg::OnToolTipText(UINT, NMHDR* pNMHDR, LRESULT* pResult)
|
|
{
|
|
ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);
|
|
|
|
// if there is a top level routing frame then let it handle the message
|
|
if (GetRoutingFrame() != NULL) return FALSE;
|
|
|
|
// to be thorough we will need to handle UNICODE versions of the message also !!
|
|
TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
|
|
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
|
|
//TCHAR szFullText[512];
|
|
CString strTipText;
|
|
// Zyu modify on 100726,支持64位
|
|
//UINT nID = pNMHDR->idFrom;
|
|
UINT nID = (UINT)pNMHDR->idFrom;
|
|
|
|
if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
|
|
pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
|
|
{
|
|
// idFrom is actually the HWND of the tool
|
|
//nID = ::GetDlgCtrlID((HWND)nID);
|
|
return FALSE; // shen rui add 对话框控件不显示
|
|
}
|
|
|
|
if (nID != 0) // will be zero on a separator
|
|
{
|
|
//LoadString(AfxGetResourceHandle(), nID, szFullText, 8);
|
|
//strTipText=szFullText;
|
|
CTemporaryResourceOverride vTmp;
|
|
strTipText.LoadString(nID); //=szFullText;
|
|
|
|
#ifndef _UNICODE
|
|
if (pNMHDR->code == TTN_NEEDTEXTA)
|
|
{
|
|
lstrcpyn(pTTTA->szText, strTipText, sizeof(pTTTA->szText));
|
|
}
|
|
else
|
|
{
|
|
_mbstowcsz(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
|
|
}
|
|
#else
|
|
if (pNMHDR->code == TTN_NEEDTEXTA)
|
|
{
|
|
_wcstombsz(pTTTA->szText, strTipText,sizeof(pTTTA->szText));
|
|
}
|
|
else
|
|
{
|
|
lstrcpyn(pTTTW->szText, strTipText, sizeof(pTTTW->szText));
|
|
}
|
|
#endif
|
|
|
|
*pResult = 0;
|
|
|
|
// bring the tooltip window above other popup windows
|
|
::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,SWP_NOACTIVATE|
|
|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER); return TRUE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CCharToolbarDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
CTemporaryResourceOverride vTmp;
|
|
m_toolbar.Create(this);
|
|
m_toolbar.LoadToolBar(IDR_TOOLBAR_TEXT);
|
|
m_toolbar.ShowWindow(SW_SHOW);
|
|
m_toolbar.SetBarStyle(CBRS_ALIGN_TOP | CBRS_TOOLTIPS | CBRS_FLYBY );
|
|
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
|
|
|
|
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
void CCharToolbarDlg::OnChar(UINT nID)
|
|
{
|
|
UpdateData(TRUE);
|
|
int h, l;
|
|
if(!GetPosition(h, l))
|
|
return;
|
|
int i = 0;// Modify By Lcf On 2005-07-01
|
|
switch (nID)
|
|
{
|
|
case ID_DOWN_MARK:
|
|
if(h==l)
|
|
{
|
|
AfxMessageBox(_T("请先在文字框中选择字符!"));
|
|
return;
|
|
}
|
|
m_strInputText.Insert(l, _T("^L"));
|
|
m_strInputText.Insert(h + 2, _T("^L"));
|
|
i=h+4;
|
|
break;
|
|
case ID_UP_MARK:
|
|
if(h==l)
|
|
{
|
|
AfxMessageBox(_T("请先在文字框中选择字符!"));
|
|
return;
|
|
}
|
|
m_strInputText.Insert(l, _T("^U"));
|
|
m_strInputText.Insert(h + 2,_T("^U"));
|
|
i=h+4;
|
|
break;
|
|
case ID_CIRCLE:
|
|
if(h==l)
|
|
{
|
|
AfxMessageBox(_T("请先在文字框中选择字符!"));
|
|
return;
|
|
}
|
|
m_strInputText.Insert(l, _T("^C"));
|
|
m_strInputText.Insert(h + 2,_T("^C"));
|
|
i=h+4;
|
|
break;
|
|
case ID_ANGLE_CHAR:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l, _T("%%d"));
|
|
i=l+3;
|
|
break;
|
|
case ID_DIA_CHAR:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l, _T("%%c"));
|
|
i=l+3;
|
|
break;
|
|
case ID_TOLERANCE_CHAR:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l, _T("%%p"));
|
|
i=l+3;
|
|
break;
|
|
case ID_PERCENT_CHAR:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l, _T("%%%"));
|
|
i=l+3;
|
|
break;
|
|
case ID_ONE_STEEL:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l,_T("^1"));
|
|
i=l+2;
|
|
break;
|
|
case ID_TWO_STEEL:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l,_T("^2"));
|
|
i=l+2;
|
|
break;
|
|
case ID_THREE_STEEL:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l,_T("^3"));
|
|
i=l+2;
|
|
break;
|
|
case ID_FOUR_STEEL:
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l,_T("^4"));
|
|
i=l+2;
|
|
break;
|
|
case ID_SPECIAL_CHAR:// Add By Lcf On 2005-07-01
|
|
{
|
|
XPushAutoHide noAutoHide(this);
|
|
|
|
CCharDlg dlg(this);
|
|
CString str;
|
|
CTemporaryResourceOverride vTemp;
|
|
if(dlg.DoModal() != IDOK || dlg.m_character == _T(""))
|
|
return;
|
|
str = dlg.m_character;
|
|
m_strInputText.Delete(l, h - l);
|
|
m_strInputText.Insert(l,str);
|
|
i=l+str.GetLength();
|
|
}
|
|
break;
|
|
case ID_WORD://词库
|
|
{
|
|
XPushAutoHide noAutoHide(this);
|
|
|
|
CInsTextDlg dlg(this);
|
|
dlg.SetPreText(m_strInputText);
|
|
// sg add 090324,控制返回值是单行文字,还是多行文字
|
|
dlg.SetSingleText(m_bNeedSingleLineText);
|
|
if(dlg.DoModal()!=IDOK||dlg.GetEditText()==_T(""))
|
|
return;
|
|
m_strInputText.Delete(l,h-l);
|
|
m_strInputText.Insert(l,dlg.GetEditText());
|
|
i=l+dlg.GetEditText().GetLength();;
|
|
}
|
|
break;
|
|
case ID_PICKTEXT://拾取文字Add By Lcf On 2005-07-01
|
|
{
|
|
if(m_bModeless)
|
|
{
|
|
m_nOperCode = 1;
|
|
PostCommand(_T("` "), false);
|
|
}
|
|
else
|
|
{
|
|
GetPickText();
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
CComboBox *pComboBox = NULL;
|
|
CEdit *pEdit = NULL;
|
|
|
|
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CComboBox))) {
|
|
pComboBox = (CComboBox*)m_ctrlInputText;
|
|
int index = pComboBox->FindStringExact(0, m_strInputText);
|
|
if(index < 0)
|
|
pComboBox->InsertString(0, m_strInputText);
|
|
pComboBox->SelectString(0, m_strInputText);
|
|
pComboBox->SetEditSel(i, i);
|
|
}// 以上四行目的为了防止COMBOBOX在已有列表选择一个最匹配的,所加m_strInputText只是临时的。
|
|
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CEdit))) {
|
|
pEdit = (CEdit*)m_ctrlInputText;
|
|
pEdit->SetSel(i, i);
|
|
}
|
|
UpdateData(FALSE);
|
|
if(pEdit)
|
|
pEdit->SetSel(i, i);
|
|
else
|
|
pComboBox->SetEditSel(i, i);
|
|
|
|
}
|
|
|
|
// Add by lcf On 2005-07-01
|
|
BOOL CCharToolbarDlg::GetPickText()
|
|
{
|
|
|
|
BeginEditorCommand();
|
|
Entity ent;
|
|
RBList mask(RTDXF0,_T("TCH_*,TEXT,MTEXT"),NULL);
|
|
XPoint pt;
|
|
TPickEntSet pickents;
|
|
for (;;)
|
|
{
|
|
XPushAutoHide noAutoHide(this);
|
|
|
|
m_nOperCode = -1;
|
|
int h, l;
|
|
if(!GetPosition(h, l))
|
|
return FALSE;
|
|
int i = 0;// Modify By Lcf On 2005-07-01
|
|
if(SelectEntity(_T("\n屏幕拾取文字内容:"),ent,pt,mask) != RTNORM)
|
|
{
|
|
pickents.Redraw(4);
|
|
CompleteEditorCommand();
|
|
return TRUE;
|
|
}
|
|
ent.Redraw(3);
|
|
pickents += ent;
|
|
|
|
PickSet ss(SS_FREE);
|
|
ss+=ent;
|
|
TSubText* pSubText = HitTestOnText(ss,Ucs2Wcs(pt));
|
|
if(pSubText!=NULL)
|
|
{
|
|
CString sText=pSubText->GetText();
|
|
delete pSubText;
|
|
m_strInputText.Delete(l,h-l);
|
|
m_strInputText.Insert(l,sText);
|
|
i=l+sText.GetLength();
|
|
}
|
|
|
|
CComboBox *pComboBox = NULL;
|
|
CEdit *pEdit = NULL;
|
|
|
|
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CComboBox))) {
|
|
pComboBox = (CComboBox*)m_ctrlInputText;
|
|
int index = pComboBox->FindStringExact(0, m_strInputText);
|
|
if(index < 0)
|
|
pComboBox->InsertString(0, m_strInputText);
|
|
pComboBox->SelectString(0, m_strInputText);
|
|
pComboBox->SetEditSel(i, i);
|
|
}// 以上四行目的为了防止COMBOBOX在已有列表选择一个最匹配的,所加m_strInputText只是临时的。
|
|
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CEdit))) {
|
|
pEdit = (CEdit*)m_ctrlInputText;
|
|
pEdit->SetSel(i, i);
|
|
}
|
|
UpdateData(FALSE);
|
|
if(pEdit)
|
|
pEdit->SetSel(i, i);
|
|
else
|
|
pComboBox->SetEditSel(i, i);
|
|
}
|
|
pickents.Redraw(4);
|
|
|
|
CompleteEditorCommand();
|
|
|
|
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// Modify by lcf On 2005-07-05
|
|
BOOL CCharToolbarDlg::GetPosition(int& h, int& l)
|
|
{
|
|
DWORD n;
|
|
CComboBox *pComboBox = NULL;
|
|
CEdit *pEdit = NULL;
|
|
CWnd *pWnd1 = this->GetFocus();
|
|
if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CComboBox))) {
|
|
pComboBox = (CComboBox*)m_ctrlInputText;
|
|
if(pComboBox->m_hWnd != pWnd1->GetParent()->m_hWnd)
|
|
{
|
|
int nSel = pComboBox->GetWindowTextLength();
|
|
pComboBox->SetEditSel(nSel, nSel);
|
|
}
|
|
n = pComboBox->GetEditSel();
|
|
}
|
|
else if(m_ctrlInputText->IsKindOf(RUNTIME_CLASS(CEdit))) {
|
|
pEdit = (CEdit*)m_ctrlInputText;
|
|
if(pEdit->m_hWnd != pWnd1->m_hWnd)
|
|
{
|
|
int nBegin = pEdit->LineIndex( pEdit->GetLineCount()-1 );
|
|
int nEnd = nBegin + pEdit->LineLength(nBegin);
|
|
pEdit->SetSel(nEnd, nEnd);
|
|
}
|
|
n = pEdit->GetSel();
|
|
}
|
|
else
|
|
return FALSE;
|
|
|
|
l = (int)LOWORD(n);
|
|
h = (int)HIWORD(n);
|
|
|
|
#if (ADS>15)
|
|
if(!FindRT_MANIFEST())
|
|
return TRUE;
|
|
|
|
OSVERSIONINFO osVer;
|
|
osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
VERIFY(GetVersionEx(&osVer)==TRUE);
|
|
if(osVer.dwPlatformId==VER_PLATFORM_WIN32_NT && osVer.dwMajorVersion>=5 && osVer.dwMinorVersion>=1) {
|
|
CString csText;
|
|
m_ctrlInputText->GetWindowText(csText);
|
|
XString xsText;
|
|
xsText=csText;
|
|
// Zyu modify on 100726,去掉编译警告
|
|
//int nCount=_tcslen(xsText);
|
|
int nCount = (int)_tcslen(xsText);
|
|
int iLow=l, iUp=h;
|
|
for(int idx=0; idx<nCount; idx++) {
|
|
if(idx>=iUp)
|
|
break;
|
|
TCHAR c=xsText[idx];
|
|
if(c<0) { //汉字
|
|
if(idx<iLow)
|
|
iLow++;
|
|
if(idx<iUp)
|
|
iUp++;
|
|
idx++;
|
|
}
|
|
}
|
|
l=iLow;
|
|
h=iUp;
|
|
}
|
|
#endif
|
|
|
|
return TRUE;
|
|
}
|
|
|