void SetAtllDDX(VSClass* pClass, InsDelPoints* pModifications, bool bUseFloat /* = false */) { if (pClass->m_bDDX && !bUseFloat) return; InsertPointDDXSupport* pInsPt = FindInsertPoint(pModifications); EnvDTE::CodeElementPtr pIncludeElem = FindInclude(pClass, L"<atlddx.h>", true); if (pIncludeElem == NULL) { if (!pInsPt) { pInsPt = new InsertPointDDXSupport; pInsPt->bUseFloat = false; pInsPt->pBase = NULL; pInsPt->pElement = NULL; pModifications->InsertPoints.Add(pInsPt); } if (!pInsPt->pElement) { VSInclude* pInclude = new VSInclude; pInclude->Name = _T("<atlddx.h>"); pInsPt->pElement = pInclude; } } if (bUseFloat) { EnvDTE::CodeElementPtr pMacro = FindDefine(pClass, L"_ATL_USE_DDX_FLOAT", true); if (pMacro == NULL) { if (!pInsPt) { pInsPt = new InsertPointDDXSupport; pInsPt->pElement = NULL; pInsPt->pBase = NULL; pInsPt->bUseFloat = true; pModifications->InsertPoints.Add(pInsPt); } else { pInsPt->bUseFloat = true; } } } bool bBase = false; for (size_t i = 0; i < pClass->Parents.GetCount(); i++) { if ((pClass->Parents[i])->Name == _T("CWinDataExchange")) { bBase = true; break; } } if (!bBase) { //нужно добавить в качестве предка класс CWinDataExchange VSBase* pNewBase = new VSBase; pNewBase->Name = _T("CWinDataExchange<") + pClass->Name + _T(">"); pNewBase->pElement = NULL; pNewBase->pParent = (VSElement*)pClass; pClass->Parents.Add(pNewBase); if (!pInsPt) { pInsPt = new InsertPointDDXSupport; pInsPt->bUseFloat = false; pInsPt->pBase = NULL; pInsPt->pElement = NULL; pModifications->InsertPoints.Add(pInsPt); } if (!pInsPt->pBase) { pInsPt->pBase = pNewBase; } } pClass->m_bDDX = true; }
bool CDDXManager::CheckCString(VSClass* pClass) { EnvDTE::ProjectPtr pProject; EnvDTE::ProjectItemPtr pProjectItem; EnvDTE::GlobalsPtr pProjGlobals; pClass->pElement->get_ProjectItem(&pProjectItem); pProjectItem->get_ContainingProject(&pProject); pProject->get_Globals(&pProjGlobals); if (pProjGlobals != NULL) { VARIANT_BOOL bExist; pProjGlobals->get_VariableExists(_bstr_t(L"CTypeCString.Ask"), &bExist); if (bExist == VARIANT_TRUE) return true; } if (FindInclude(pClass, L"<atlstr.h>", true) != NULL || FindInclude(pClass, L"<atlmisc.h>", true) != NULL) { return true; } CSmartAtlArray<InsertionPoint*>& CurInsPoints = m_pModifications->InsertPoints; for (size_t i = 0; i < CurInsPoints.GetCount(); i++) { if (CurInsPoints[i]->Type == INSERT_POINT_INCLUDE) { InsertInclude* pInsInclude = (InsertInclude*)CurInsPoints[i]; if (pInsInclude->pElement->Name == _T("<atlstr.h>") || pInsInclude->pElement->Name == _T("<atlmisc.h>")) { return true; } } } ATLASSERT(m_pGlobalModifications); for (size_t i = 0; i < m_pGlobalModifications->GetCount(); i++) { CSmartAtlArray<InsertionPoint*>& InsPoints = (*m_pGlobalModifications)[i].InsertPoints; for (size_t j = 0; j < InsPoints.GetCount(); j++) { if (InsPoints[j]->Type == INSERT_POINT_INCLUDE) { InsertInclude* pInsInclude = (InsertInclude*)InsPoints[j]; if (pInsInclude->pProjectFile != NULL) { if (pInsInclude->pElement->Name == _T("<atlstr.h>") || pInsInclude->pElement->Name == _T("<atlmisc.h>")) { return true; } } } } } //показать диалог в котором можно будет выбрать CString используемый CTypeCStringDlg dlg; EnvDTE::ProjectItemPtr pStdAfxFile = FindItem(pProject, _bstr_t(L"stdafx.h"), EnvDTE::ProjectItemPtr(NULL)); if (pStdAfxFile != NULL) { dlg.m_bStdAfx = true; } else { dlg.m_bStdAfx = false; } if (dlg.DoModal() == IDOK) { if (dlg.m_Type == STYPE_ANOTHER) return true; if (dlg.m_Type == STYPE_WTL) { InsertWtlCString(pProject, CurInsPoints, dlg.m_Place); return true; } if (dlg.m_Type == STYPE_ATL) { InsertAtlCString(pProject, CurInsPoints); } if (dlg.m_bAskAgain) { pProjGlobals->put_VariablePersists(_bstr_t(L"CTypeCString.Ask"), VARIANT_TRUE); } } return true; }
int NewInputFile (const char* Name) /* Open a new input file. Returns true if the file could be successfully opened * and false otherwise. */ { int RetCode = 0; /* Return code. Assume an error. */ char* PathName = 0; /* First try to open the file */ FILE* F = fopen (Name, "r"); if (F == 0) { /* Error (fatal error if this is the main file) */ if (FCount == 0) { Fatal ("Cannot open input file `%s': %s", Name, strerror (errno)); } /* We are on include level. Search for the file in the include * directories. */ PathName = FindInclude (Name); if (PathName == 0 || (F = fopen (PathName, "r")) == 0) { /* Not found or cannot open, print an error and bail out */ Error ("Cannot open include file `%s': %s", Name, strerror (errno)); goto ExitPoint; } /* Use the path name from now on */ Name = PathName; } /* check again if we do now have an open file */ if (F != 0) { StrBuf NameBuf; unsigned FileIdx; CharSource* S; /* Stat the file and remember the values. There a race condition here, * since we cannot use fileno() (non standard identifier in standard * header file), and therefore not fstat. When using stat with the * file name, there's a risk that the file was deleted and recreated * while it was open. Since mtime and size are only used to check * if a file has changed in the debugger, we will ignore this problem * here. */ struct stat Buf; if (stat (Name, &Buf) != 0) { Fatal ("Cannot stat input file `%s': %s", Name, strerror (errno)); } /* Add the file to the input file table and remember the index */ FileIdx = AddFile (SB_InitFromString (&NameBuf, Name), Buf.st_size, Buf.st_mtime); /* Create a new input source variable and initialize it */ S = xmalloc (sizeof (*S)); S->Func = &IFFunc; S->V.File.F = F; S->V.File.Pos.Line = 0; S->V.File.Pos.Col = 0; S->V.File.Pos.Name = FileIdx; S->V.File.Line[0] = '\0'; /* Count active input files */ ++FCount; /* Use this input source */ UseCharSource (S); } /* File successfully opened */ RetCode = 1; ExitPoint: /* Free an allocated name buffer */ xfree (PathName); /* Return the success code */ return RetCode; }