// MutiRowTextDlg.cpp : implementation file // #include "stdafx.h" #include "MutiRowTextDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMutiRowTextDlg dialog static CString g_strLineSpace = _T("0.4"); static CString g_strPageWidth = _T("200"); static double g_nHeight_muti = 3.5; static int g_nAlignIndex_muti = 0; static CString g_strOldText = _T(""); // add by xly on 101222初始化多行文字中的转角的变量 CString CMutiRowTextDlg::m_strRotation = _T("0"); static XExplodeDraw::TextAlignment g_AlignList_muti[] = { XExplodeDraw::kLeft, XExplodeDraw::kRight , XExplodeDraw::kCenter, XExplodeDraw::kTextFit,}; IMPLEMENT_DYNAMIC(CMutiRowTextDlg, CCharToolbarDlg) CMutiRowTextDlg::CMutiRowTextDlg(BOOL bEdit, CWnd* pParent /*=NULL*/) : CCharToolbarDlg(CMutiRowTextDlg::IDD, pParent),m_bEditObj(bEdit) { //{{AFX_DATA_INIT(CMutiRowTextDlg) m_strInputText = _T(""); m_strHeight = _T(""); m_strPageWidth = _T(""); //m_strRotation = _T("");// delete by xly on 101222多行文字中的转角的变量变为静态变量 m_strLineSpace = _T(""); //}}AFX_DATA_INIT //m_uTimerID = 0; m_bInit = FALSE; m_nOldSizeX=495; m_nOldSizeY=224; m_bNeedSingleLineText = FALSE; // sg add 090324 } void CMutiRowTextDlg::DoDataExchange(CDataExchange* pDX) { CCharToolbarDlg::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMutiRowTextDlg) DDX_Control(pDX, IDOK, m_ctrlOk); DDX_Control(pDX, IDCANCEL, m_ctrlCancel); DDX_Control(pDX, IDC_INPUT_TEXT, m_editInputText); DDX_Control(pDX, IDC_COMBO_FONGSTYLE, m_comboFontStyle); DDX_Control(pDX, IDC_COMBO_ALIGNMENT, m_comboAlign); DDX_Text(pDX, IDC_INPUT_TEXT, m_strInputText); DDX_CBString(pDX, IDC_COMBO_HEIGHT, m_strHeight); DDX_Text(pDX, IDC_PAGE_WIDTH, m_strPageWidth); DDX_Text(pDX, IDC_ROTATION, m_strRotation); DDX_Text(pDX, IDC_ROWDIST, m_strLineSpace); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CMutiRowTextDlg, CCharToolbarDlg) //{{AFX_MSG_MAP(CMutiRowTextDlg) ON_BN_CLICKED(IDC_BUTTON_PAGEWIDTH, OnButtonPagewidth) ON_BN_CLICKED(IDC_BUTTON_TEXT_HEIGHT, OnButtonTextHeight) ON_WM_SIZE() ON_WM_CREATE() //}}AFX_MSG_MAP //ON_COMMAND_RANGE(ID_SPECIAL_CHAR, ID_ONE_STEEL, OnChar) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMutiRowTextDlg message handlers BOOL CMutiRowTextDlg::OnInitDialog() { CCharToolbarDlg::OnInitDialog(); m_bInit = TRUE; CRect rectDlg; GetClientRect(rectDlg); sizeDlg.cx = rectDlg.Width(); sizeDlg.cy = rectDlg.Height(); ResetSize(); LoadTextStyle(); if(m_strInputText == _T("")) m_strInputText = g_strOldText; m_comboAlign.SetCurSel(g_nAlignIndex_muti); if(fabs(g_nHeight_muti) < 1.0E-3) g_nHeight_muti = 3.5; if(!m_bEditObj)//add by whl m_strHeight.Format(_T("%.1f"), g_nHeight_muti); m_ctrlInputText = GetDlgItem(IDC_INPUT_TEXT); m_strLineSpace = g_strLineSpace; m_strPageWidth = g_strPageWidth; m_comboFontStyle.SetCurSel(m_comboFontStyle.FindStringExact(0, m_strStyle)); UpdateData(FALSE); //toolbar m_editInputText.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CMutiRowTextDlg::ResetSize() { CRect rectEdit, rectCancel, rectOk; m_editInputText.GetWindowRect(rectEdit); ScreenToClient(rectEdit); m_ctrlCancel.GetWindowRect(rectCancel); ScreenToClient(rectCancel); m_ctrlOk.GetWindowRect(rectOk); ScreenToClient(rectOk); long nIncY = sizeDlg.cy - m_nOldSizeY; // 对话框绝对尺寸 long nIncX = sizeDlg.cx - m_nOldSizeX; m_editInputText.MoveWindow(rectEdit.left, rectEdit.top, rectEdit.Width() + nIncX, rectEdit.Height() + nIncY); m_ctrlCancel.MoveWindow(rectCancel.left + nIncX, rectCancel.top, rectCancel.Width(), rectCancel.Height()); m_ctrlOk.MoveWindow(rectOk.left + nIncX, rectOk.top, rectOk.Width(), rectOk.Height()); } void CMutiRowTextDlg::LoadTextStyle() { AcDbDatabase *pCurDwg=acdbCurDwg(); AcDbTextStyleTable* pTT; VERIFY(pCurDwg->getSymbolTable(pTT, AcDb::kForRead)==Acad::eOk); AcDbTextStyleTableIterator* pIter = NULL; VERIFY(pTT->newIterator(pIter)==Acad::eOk); pTT->close(); for (pIter->start(); !pIter->done(); pIter->step()) { AcDbTextStyleTableRecord* pTTR; if (pIter->getRecord(pTTR, AcDb::kForRead) != Acad::eOk) continue; const TCHAR* pName = NULL; if (pTTR->getName(pName) == Acad::eOk && pName != NULL) { if(m_lstStyle.Index(pName) < 0 ) // 如果没有重复 m_lstStyle.Append(tstrnew(pName)); // 读字体风格 } pTTR->close(); } delete pIter; for (int m =0; m < m_lstStyle.Length(); m++) m_comboFontStyle.AddString(m_lstStyle[m]); UpdateData(false); return; } void CMutiRowTextDlg::Obj2Dlg(TDbMText *pText) { m_strHeight.Format(_T("%.1f"), pText->GetHeight()); m_strRotation = (const TCHAR *)Angle2Str(pText->GetRotation() * 180.0 / PI); AcDbObjectId idTextStyle = pText->GetStyleId(); OPENOBJ_BEGIN(idTextStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pStyle); ASSERT(pStyle); const TCHAR* pName = NULL; if (pStyle->getName(pName) == Acad::eOk && pName != NULL) m_strStyle = pName; else AfxMessageBox(_T("文字风格已删除!")); OPENOBJ_END(); m_strInputText = pText->GetText(); XExplodeDraw::TextAlignment Align = pText->GetAlignment(); for(int i = 0; i < 4; i++) { if(Align == g_AlignList_muti[i]) g_nAlignIndex_muti = i; } g_strLineSpace.Format(_T("%.2f"), (pText->GetLineSpace() / pText->GetHeight())); g_strPageWidth.Format(_T("%.1f"), pText->GetPageWidth()); } void CMutiRowTextDlg::Dlg2Obj(TDbMText *pText) { XString sTextStyle = m_strStyle; //xg_setvar(_T("TEXTSTYLE"), sTextStyle); g_strOldText = m_strInputText; AcDbObjectId idTextStyle = GetTextStyleId(sTextStyle); if(!idTextStyle) return; pText->SetStyleId(idTextStyle); g_nHeight_muti = _tstof(m_strHeight); g_strPageWidth = m_strPageWidth; g_strLineSpace = m_strLineSpace; pText->SetHeight(g_nHeight_muti); double nRotation = _tstof(m_strRotation); pText->SetRotation(nRotation * PI / 180.0); pText->SetText(m_strInputText); pText->SetAlignment(g_AlignList_muti[g_nAlignIndex_muti]); pText->SetLineSpace(_tstof(m_strLineSpace) * g_nHeight_muti); pText->SetPageWidth(_tstof(m_strPageWidth), TRUE); // 对话框指定 } void CMutiRowTextDlg::OnOK() { g_nAlignIndex_muti = m_comboAlign.GetCurSel(); if(g_nAlignIndex_muti < 0) g_nAlignIndex_muti = 0; if(m_comboFontStyle.GetCurSel()>=0) m_comboFontStyle.GetLBText(m_comboFontStyle.GetCurSel(), m_strStyle); CCharToolbarDlg::OnOK(); if(!m_bEditObj) // ZJQ modify on 2004/3/5 xg_setvar(_T("TEXTSTYLE"), m_strStyle); } void CMutiRowTextDlg::OnCancel() { CCharToolbarDlg::OnCancel(); } void CMutiRowTextDlg::OnButtonPagewidth() { UpdateData(TRUE); double nPageWidth = _tstof(m_strPageWidth)*DocGetPScale(); BeginEditorCommand(); LAB_REINPUT: if(GetDist(_T("\n定义上华多行文字行宽"), nPageWidth, RSG_NOZERO|RSG_NONEG) == RTCAN) { goto LAB_REINPUT; } else { CompleteEditorCommand(); nPageWidth /= DocGetPScale(); m_strPageWidth.Format(_T("%.1f"), nPageWidth); UpdateData(FALSE); } } void CMutiRowTextDlg::OnButtonTextHeight() { UpdateData(TRUE); double nHeight = _tstof(m_strHeight)*DocGetPScale(); BeginEditorCommand(); LAB_REINPUT: if(GetDist(_T("\n字高"), nHeight, RSG_NOZERO|RSG_NONEG) == RTCAN) { goto LAB_REINPUT; } else { CompleteEditorCommand(); nHeight /= DocGetPScale(); m_strHeight.Format(_T("%.1f"), nHeight); UpdateData(FALSE); } } void CMutiRowTextDlg::OnSize(UINT nType, int cx, int cy) { //CCharToolbarDlg::OnSize(nType, cx, cy); // 不调用 if(m_bInit == TRUE && !nType ) { CRect rectEdit; m_editInputText.GetWindowRect(rectEdit); ScreenToClient(rectEdit); CRect rectCancel, rectOk; m_ctrlCancel.GetWindowRect(rectCancel); ScreenToClient(rectCancel); m_ctrlOk.GetWindowRect(rectOk); ScreenToClient(rectOk); CSize sizeOld = sizeDlg; sizeDlg.cx = cx; sizeDlg.cy = cy; long nIncY = sizeDlg.cy - sizeOld.cy; long nIncX = sizeDlg.cx - sizeOld.cx; m_editInputText.MoveWindow(rectEdit.left, rectEdit.top, rectEdit.Width() + nIncX, rectEdit.Height() + nIncY); m_ctrlCancel.MoveWindow(rectCancel.left + nIncX, rectCancel.top, rectCancel.Width(), rectCancel.Height()); m_ctrlOk.MoveWindow(rectOk.left + nIncX, rectOk.top, rectOk.Width(), rectOk.Height()); } } int CMutiRowTextDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CCharToolbarDlg::OnCreate(lpCreateStruct) == -1) return -1; CRect rect; GetClientRect(rect); m_nOldSizeX=rect.Width(); m_nOldSizeY=rect.Height(); return 0; }