📄 ctcommondoc.cpp
字号:
//####COPYRIGHTBEGIN####// // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//// ----------------------------------------------------------------------------// //####COPYRIGHTEND#####include "stdafx.h"#include "ConfigToolDoc.h"#ifdef PLUGIN #include "CTMain.h" #include "Project.h" #include "ProjectManager.h"#else #include "MainFrm.h"#endif#include "CTUtils.h"#include "CdlPackagesDialog.h"#include "ConfigItem.h"#include "ConfigTool.h"#include "ControlView.h"#include "FailingRulesDialog.h"#include "FolderDialog.h"#include "IdleMessage.h"#include "MLTView.h"#include "NotePage.h"#include "RegionGeneralPage.h"#include "RegKeyEx.h"#include "RulesView.h"#include "SectionGeneralPage.h"#include "SectionRelocationPage.h"#include <htmlhelp.h>#include <shlobj.h>#define INCLUDEFILE <string>#include "IncludeSTL.h"#define INCLUDEFILE "build.hxx"#include "IncludeSTL.h"#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__;#endifconst CFileName &CConfigToolDoc::DefaultExternalBrowser(){ static bool bFirstTime=true; if(bFirstTime){ const CFileName strFile(CFileName::GetTempPath()+_T("index.html")); CFile f; if(f.Open(strFile,CFile::modeCreate|CFile::modeWrite)){ f.Close(); bool rc=((int)FindExecutable(strFile,_T("."),m_strDefaultExternalBrowser.GetBuffer(MAX_PATH))>32); m_strDefaultExternalBrowser.ReleaseBuffer(); if(!rc){ m_strDefaultExternalBrowser=_T(""); } ::DeleteFile(strFile); } bFirstTime=false; } return m_strDefaultExternalBrowser;}CFileName CConfigToolDoc::m_strDefaultExternalBrowser;void CConfigToolDoc::CheckRadios(){ for(int nItem=0;nItem<ItemCount();nItem++){ CConfigItem *pItem=Item(nItem); if(pItem->HasRadio () && pItem==pItem->FirstRadio()){ CString strMsg; CConfigItem *pFirstSet=NULL; for(CConfigItem *pSibItem=pItem;pSibItem;pSibItem=pSibItem->NextRadio()){ if(pSibItem->IsEnabled ()){ if(pFirstSet){ strMsg+=_T(" "); strMsg+=pSibItem->Macro (); } else { pFirstSet=pSibItem; } } } if(!strMsg.IsEmpty()){ CConfigTool::Log(_T("%s, multiple radio buttons are set: %s%s"), pItem->Macro(),pFirstSet->Macro(),strMsg); } else if(!pFirstSet){ CConfigTool::Log(_T("%s, no radio buttons are set"),pItem->Macro()); } } }}// Find the ConfigItem referencing the given CdlValuableCConfigItem * CConfigToolDoc::Find (CdlValuable v){ for(int nItem=0;nItem<ItemCount();nItem++){ CConfigItem *pItem=Item(nItem); if(v==pItem->GetCdlValuable()){ return pItem; } } return NULL;}CConfigItem * CConfigToolDoc::Find(const CString & strWhat,WhereType where){ for(int nItem=0;nItem<ItemCount();nItem++){ CConfigItem *pItem=Item(nItem); if(0==pItem->StringValue(where).Compare(strWhat)){ return pItem; } } return NULL;}void CConfigToolDoc::OnMLTNewRegion() { // create the property sheet CPropertySheet prsRegionSheet (IDS_NEW_REGION_SHEET_TITLE, CConfigTool::GetMLTView()); // add the property pages CRegionGeneralPage prpGeneral; CNotePage prpNote; prsRegionSheet.AddPage (&prpGeneral); prsRegionSheet.AddPage (&prpNote); // setup initial values prpGeneral.m_strRegionName = _T(""); prpGeneral.m_dwRegionStartAddress = 0; prpGeneral.m_dwRegionSize = 0; // show property sheet if (prsRegionSheet.DoModal () == IDOK) { if (int nErrorCode = MemoryMap.create_memory_region (CUtils::UnicodeToStdStr(prpGeneral.m_strRegionName), prpGeneral.m_dwRegionStartAddress, prpGeneral.m_dwRegionSize, (prpGeneral.m_bRegionReadOnly ? read_only : read_write), CUtils::UnicodeToStdStr(prpNote.m_strNote))) ErrorBox (IDS_ERR_MEMMAP_REGION_CREATE, IDS_ERR_MEMMAP_BASE + nErrorCode); else // no errors { SetModifiedFlag (); UpdateAllViews (NULL, MemLayoutChanged); } } }void CConfigToolDoc::ErrorBox (UINT uIDSIntro, UINT uIDSError){ CString strIntro, strError; strIntro.LoadString (uIDSIntro); strError.LoadString (uIDSError); AfxMessageBox (strIntro + _T("\n\n") + strError);}void CConfigToolDoc::OnMLTNewSection() { // create the property sheet CPropertySheet prsSectionSheet (IDS_NEW_SECTION_SHEET_TITLE, CConfigTool::GetMLTView()); // add the property pages CSectionGeneralPage prpGeneral; CSectionRelocationPage prpRelocation; CNotePage prpNote; prsSectionSheet.AddPage (&prpGeneral); prsSectionSheet.AddPage (&prpRelocation); prsSectionSheet.AddPage (&prpNote); // initialise for a new section prpGeneral.m_bNameLinkerDefined = TRUE; prpGeneral.m_strNameLinker = _T(""); prpRelocation.m_bRelocates = FALSE; prpRelocation.m_bNewSection = TRUE; // show property sheet if (prsSectionSheet.DoModal () == IDOK) { mem_anchor initial_anchor, final_anchor; mem_address initial_address; CString strInitialRelativeName = _T(""); if (prpGeneral.m_bFinalAbsolute) // final location is an absolute location final_anchor = absolute; else // final location is a relative location final_anchor = relative; if (prpRelocation.m_bRelocates) // if the section relocates { if (prpRelocation.m_bInitialAbsolute) // initial location is an absolute location { initial_anchor = absolute; } else // initial location is a relative location { strInitialRelativeName = prpRelocation.m_strInitialRelativeName; initial_anchor = relative; } initial_address = prpRelocation.m_dwInitialAddress; } else { strInitialRelativeName = prpGeneral.m_strFinalRelativeName; initial_anchor = final_anchor; initial_address = prpGeneral.m_dwFinalAddress; } if (int nErrorCode = MemoryMap.create_memory_section (CUtils::UnicodeToStdStr(prpGeneral.m_bNameLinkerDefined ? prpGeneral.m_strNameLinker : prpGeneral.m_strNameUser), prpGeneral.m_dwSectionSize, prpGeneral.m_dwAlignment, initial_anchor, CUtils::UnicodeToStdStr(strInitialRelativeName), initial_address, final_anchor, CUtils::UnicodeToStdStr(prpGeneral.m_strFinalRelativeName), prpGeneral.m_dwFinalAddress, prpRelocation.m_bRelocates, false, prpGeneral.m_bNameLinkerDefined, CUtils::UnicodeToStdStr(prpNote.m_strNote))) ErrorBox (IDS_ERR_MEMMAP_SECTION_CREATE, IDS_ERR_MEMMAP_BASE + nErrorCode); else // no errors { SetModifiedFlag (); UpdateAllViews (NULL, MemLayoutChanged); } } }void CConfigToolDoc::OnMLTDelete() { if (strSelectedSection != _T("")) // a section is selected { if (MemoryMap.delete_memory_section (CUtils::UnicodeToStdStr(strSelectedSection))) { strSelectedSection = _T(""); SetModifiedFlag (); UpdateAllViews (NULL, MemLayoutChanged); } else AfxMessageBox (_T("Could not delete memory section.\n\nMake sure there are no other sections defined relative to this one.")); } else if (strSelectedRegion != _T("")) // a region is selected { if (MemoryMap.delete_memory_region (CUtils::UnicodeToStdStr(strSelectedRegion))) { strSelectedRegion = _T(""); SetModifiedFlag (); UpdateAllViews (NULL, MemLayoutChanged); } else AfxMessageBox (_T("Could not delete memory region.\n\nMake sure it is not in use.")); // FIXME }}void CConfigToolDoc::ShowRegionProperties(){ // create the property sheet CString strTitle; strTitle.LoadString (IDS_REGION_PROPERTIES_SHEET_TITLE); CPropertySheet prsRegionSheet (strSelectedRegion + _T(" - ") + strTitle, CConfigTool::GetMLTView()); // add the property pages CRegionGeneralPage prpGeneral; CNotePage prpNote; prsRegionSheet.AddPage (&prpGeneral); prsRegionSheet.AddPage (&prpNote); // set up property sheet values mem_type type; std::string note; MemoryMap.get_memory_region (CUtils::UnicodeToStdStr(strSelectedRegion), &prpGeneral.m_dwRegionStartAddress, &prpGeneral.m_dwRegionSize, &type, ¬e); prpGeneral.m_strRegionName = strSelectedRegion; prpGeneral.m_bRegionReadOnly = (type == read_only); prpNote.m_strNote = note.c_str (); // show property sheet if (prsRegionSheet.DoModal () == IDOK) { if (int nErrorCode = MemoryMap.edit_memory_region (CUtils::UnicodeToStdStr(strSelectedRegion), CUtils::UnicodeToStdStr(prpGeneral.m_strRegionName), prpGeneral.m_dwRegionStartAddress, prpGeneral.m_dwRegionSize, (prpGeneral.m_bRegionReadOnly ? read_only : read_write), CUtils::UnicodeToStdStr(prpNote.m_strNote))) ErrorBox (IDS_ERR_MEMMAP_REGION_MODIFY, IDS_ERR_MEMMAP_BASE + nErrorCode); else // no errors { SetModifiedFlag (); UpdateAllViews (NULL, MemLayoutChanged); } } }void CConfigToolDoc::ShowSectionProperties(){ // create the property sheet CString strTitle; strTitle.LoadString (IDS_SECTION_PROPERTIES_SHEET_TITLE); CPropertySheet prsSectionSheet (strSelectedSection + _T(" - ") + strTitle, CConfigTool::GetMLTView()); // add the property pages CSectionGeneralPage prpGeneral; CSectionRelocationPage prpRelocation; CNotePage prpNote; prsSectionSheet.AddPage (&prpGeneral); prsSectionSheet.AddPage (&prpRelocation); prsSectionSheet.AddPage (&prpNote); // setup initial values std::list <mem_section>::iterator section = MemoryMap.find_memory_section (CUtils::UnicodeToStdStr(strSelectedSection)); prpGeneral.m_bNameLinkerDefined = (section->linker_defined); if (prpGeneral.m_bNameLinkerDefined) prpGeneral.m_strNameLinker = section->name.c_str (); else { prpGeneral.m_strNameUser = section->name.c_str (); prpGeneral.m_dwSectionSize = section->size; } prpGeneral.m_bFinalAbsolute = (section->final_location->anchor == absolute); if (prpGeneral.m_bFinalAbsolute) prpGeneral.m_dwFinalAddress = section->final_location->address; else { prpGeneral.m_strFinalRelativeName = MemoryMap.find_preceding_section (section, false)->name.c_str (); prpGeneral.m_dwAlignment = section->alignment; } prpRelocation.m_bRelocates = section->relocates; if (prpRelocation.m_bRelocates) { prpRelocation.m_bInitialAbsolute = (section->initial_location->anchor == absolute); if (prpRelocation.m_bInitialAbsolute) prpRelocation.m_dwInitialAddress = section->initial_location->address; else prpRelocation.m_strInitialRelativeName = MemoryMap.find_preceding_section (section, true)->name.c_str (); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -