Files
envi-code/SourceCode/Code2026/tg_shs/shs_public/CharToolbarDlg.cpp
T
2026-09-28 15:28:50 +08:00

515 lines
13 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_UNDERLINE, 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_MTEXT);
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
}
extern bool IsGreeceChar(const CString &sWord);
void CCharToolbarDlg::OnChar(UINT nID)
{
UpdateData(TRUE);
// zxl 2013.03.13 modify
// int h, l;
// if(!GetPosition(h, l))
// return;
long h, l;
m_ctrlInputText->GetSel(l, h);
int i = 0;
switch (nID)
{
case ID_DOWN_MARK2:
if(h==l)
{
AfxMessageBox(_T("请先在文字框中选择字符!"));
return;
}
// m_strInputText.Insert(l, _T("^L"));
// m_strInputText.Insert(h + 2, _T("^L"));
m_ctrlInputText->SetSel(l, l);
m_ctrlInputText->ReplaceSel(_T("^L"));
m_ctrlInputText->SetSel(h+2, h+2);
m_ctrlInputText->ReplaceSel(_T("^L"));
i=h+4;
break;
case ID_UP_MARK2:
if(h==l)
{
AfxMessageBox(_T("请先在文字框中选择字符!"));
return;
}
// m_strInputText.Insert(l, _T("^U"));
// m_strInputText.Insert(h + 2,_T("^U"));
m_ctrlInputText->SetSel(l, l);
m_ctrlInputText->ReplaceSel( _T("^U"));
m_ctrlInputText->SetSel(h+2, h+2);
m_ctrlInputText->ReplaceSel(_T("^U"));
i=h+4;
break;
case ID_CIRCLE2:
if(h==l)
{
AfxMessageBox(_T("请先在文字框中选择字符!"));
return;
}
// m_strInputText.Insert(l, _T("^C"));
// m_strInputText.Insert(h + 2,_T("^C"));
m_ctrlInputText->SetSel(l, l);
m_ctrlInputText->ReplaceSel( _T("^C"));
m_ctrlInputText->SetSel(h+2, h+2);
m_ctrlInputText->ReplaceSel(_T("^C"));
i=h+4;
break;
case ID_ANGLE_CHAR2:
//m_strInputText.Delete(l, h - l);
//m_strInputText.Insert(l, _T("%%d"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("%%d"));
i=l+3;
break;
case ID_DIA_CHAR2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l, _T("%%c"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("%%c"));
i=l+3;
break;
case ID_TOLERANCE_CHAR2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l, _T("%%p"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("%%p"));
i=l+3;
break;
case ID_PERCENT_CHAR2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l, _T("%%%"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("%%%"));
i=l+3;
break;
case ID_ONE_STEEL2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l,_T("^1"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("^1"));
i=l+2;
break;
case ID_TWO_STEEL2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l,_T("^2"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("^2"));
i=l+2;
break;
case ID_THREE_STEEL2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l,_T("^3"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_T("^3"));
i=l+2;
break;
case ID_FOUR_STEEL2:
// m_strInputText.Delete(l, h - l);
// m_strInputText.Insert(l,_T("^4"));
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(_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);
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(str);
i=l+str.GetLength();
if (IsGreeceChar(str))// 希腊字符特殊处理
{
i -= 1;
}
}
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_PICKTEXT2://拾取文字Add By Lcf On 2005-07-01
{
if(m_bModeless)
{
m_nOperCode = 1;
PostCommand(_T("` "), false);
}
else
{
GetPickText();
acedGetAcadDwgView()->SetFocus();
}
}
break;
case ID_UNDERLINE:// zxl 2013.02.22 add 设定文字下划线
{
SetTextUnderLine();
return;
}
break;
}
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);
}
// zxl 2013.02.22 add 设定文字下划线
void CCharToolbarDlg::SetTextUnderLine()
{
long hPos = 0l, lPos = 0l;
m_ctrlInputText->GetSel(hPos, lPos);
if (hPos == lPos)
{
return;
}
UpdateData(TRUE);
CHARFORMAT cf;
ZeroMemory(&cf, sizeof(CHARFORMAT));
m_ctrlInputText->GetSelectionCharFormat(cf);
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_UNDERLINE;
if (cf.dwEffects & CFE_UNDERLINE)
{
cf.dwEffects &= ~CFE_UNDERLINE;
}
else
{
cf.dwEffects |= CFE_UNDERLINE;
}
m_ctrlInputText->SetSel(hPos, lPos);
BOOL bRet = m_ctrlInputText->SetSelectionCharFormat(cf);
m_ctrlInputText->SetFocus();
m_ctrlInputText->SetSel(hPos, lPos);
m_ctrlInputText->Invalidate();
}
// Add by lcf On 2005-07-01
BOOL CCharToolbarDlg::GetPickText()
{
XPushAutoHide noAutoHide(this);
m_nOperCode = -1;
// zxl 2013.03.13 modify
// int h, l;
// if(!GetPosition(h, l))
// return;
long h, l;
m_ctrlInputText->GetSel(l, h);
int i = 0;// Modify By Lcf On 2005-07-01
BeginEditorCommand();
Entity ent;
RBList mask(RTDXF0,_T("TCH_*,TEXT"),NULL);
XPoint pt;
if(SelectEntity(_T("\n屏幕拾取文字内容:"),ent,pt,mask) != RTNORM)
{
CompleteEditorCommand();
return FALSE;
}
PickSet ss(SS_FREE);
ss+=ent;
TSubText* pSubText = HitTestOnText(ss,Ucs2Wcs(pt));
if(pSubText!=NULL)
{
CString sText=pSubText->GetText();
delete pSubText;
// modified by zxl 2013.03.13
// m_strInputText.Delete(l,h-l);
// m_strInputText.Insert(l,sText);
m_ctrlInputText->SetSel(l, h);
m_ctrlInputText->ReplaceSel(sText);
i=l+sText.GetLength();
}
CompleteEditorCommand();
// Del by zxl 2013.03.13
// 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);
return TRUE;
}
// zxl 2013.03.13 del
// 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;
// }