⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mltview.cpp

📁 eCos1.31版
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//####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####// MLTView.cpp: implementation of the CMLTView class.////////////////////////////////////////////////////////////////////////#include "stdafx.h"#ifndef PLUGIN#include "BCMenu.h"#endif#include "ConfigtoolDoc.h"#include "MLTView.h"#include "ConfigTool.h"#include "CTUtils.h"#include "resource.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endifusing namespace std;//////////////////////////////////////////////////////////////////////// Construction/Destruction//////////////////////////////////////////////////////////////////////IMPLEMENT_DYNCREATE(CMLTView, CScrollView)BEGIN_MESSAGE_MAP(CMLTView, CScrollView)  //{{AFX_MSG_MAP(CMLTView)    ON_WM_LBUTTONDOWN()    ON_WM_LBUTTONDBLCLK()    ON_WM_SIZE()    ON_WM_ERASEBKGND()    ON_WM_MOUSEMOVE()    ON_COMMAND(ID_EDIT_NEW_REGION, OnMLTNewRegion)    ON_COMMAND(ID_EDIT_NEW_SECTION, OnMLTNewSection)    ON_COMMAND(ID_EDIT_DELETE_SECTION, OnMLTDelete)    ON_COMMAND(ID_EDIT_PROPERTIES, OnMLTProperties)    ON_UPDATE_COMMAND_UI(ID_EDIT_NEW_SECTION, OnUpdateMLTNewSection)    ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE_SECTION, OnUpdateMLTDelete)    ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateMLTProperties)    ON_WM_CONTEXTMENU()    ON_COMMAND(ID_POPUP_PROPERTIES, OnPopupProperties)    ON_WM_RBUTTONDOWN()	ON_WM_KEYDOWN()	ON_WM_HELPINFO()	ON_WM_MENUCHAR()	//}}AFX_MSG_MAP  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)	ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)  // Standard printing commands  ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)  ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)  ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()CMLTView::CMLTView(){  m_uViewWidth = 0;  m_uUnitCountMax = 0;  CConfigTool::SetMLTView(this);}CMLTView::~CMLTView(){  CConfigTool::SetMLTView(0);  for(POSITION pos = m_arstrTooltipRects.GetStartPosition(); pos != NULL; ){    CRect *pRect;    CString strName;    m_arstrTooltipRects.GetNextAssoc( pos, strName, (void *&)pRect );    delete pRect;  }}/////////////////////////////////////////////////////////////////////////////// CMLTView drawing#define VERT_BORDER 30 /* the vertical border at the top/bottom of the client area */#define HORIZ_BORDER 30 /* the horizontal border at the left/right of the client area */#define BAR_HEIGHT 18 /* the height of the memory section caption bar */#define MAP_HEIGHT 66 /* the height of each memory section rectangle (including caption bar) */#define REGION_SPACING 115 /* the vertical offset between successive memory regions */#define ADDRESS_TEXT_SPACE 0.9 /* use 90% of the section width to draw the address */#define EXTERNAL_TEXT_BORDER 5 /* spacing between external text and border of region */#define ADDRESS_FORMAT _T("%08X") /* draw memory addresses in hex format */#define UNITS_PER_SECTION 3 /* memory section width in units, unused sections are 1 unit wide */#define UNIT_WIDTH_MIN 27 /* minimum width of memory section unit before horizontal scrolling enabled */#define TICK_HEIGHT 4 /* the height of the tick marks on the memory sections and regions */#define DISPLAY_MODE 1 /* 1 == const unit width for all regions *//* 2 == const region width for all regions */void CMLTView::OnDraw(CDC* pDC){  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  if (pDoc == NULL) // no document so nothing to draw    return;    // clear the lists of region and section rectangles used for hit testing    listRegionRect.RemoveAll ();  listSectionRect.RemoveAll ();    // setup background mode    int nOldBkMode = pDC->SetBkMode (TRANSPARENT);    // setup font    CFont fntName;  if (!fntName.CreatePointFont (80, _T("MS Sans Serif"), pDC))    return;  CFont * pOldFont = pDC->SelectObject (&fntName);    // determine max unit count for any region    mem_map * pMemoryMap = &CConfigTool::GetConfigToolDoc()->MemoryMap;    // calculate the unit scaling for DISPLAY_MODE 1    UINT uPixelsPerUnit = UNIT_WIDTH_MIN;  RECT rectClientRect;  if (m_uUnitCountMax != 0) // if there is something to draw  {        GetClientRect (&rectClientRect);    uPixelsPerUnit = __max ((m_uClientWidth - HORIZ_BORDER * 2) / m_uUnitCountMax, UNIT_WIDTH_MIN);    m_uViewWidth = uPixelsPerUnit * m_uUnitCountMax + HORIZ_BORDER * 2;  }    // draw the regions    UINT uRegion = 0;  UINT uUnitCount;  list <mem_region>::iterator region;  for (region = pMemoryMap->region_list.begin (); region != pMemoryMap->region_list.end (); ++region)  {    uUnitCount = 0;    for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)      uUnitCount += (section_view->section == NULL ? 1 : UNITS_PER_SECTION);        if (DISPLAY_MODE == 1)      DrawRegion (pDC, uRegion++, uUnitCount, uPixelsPerUnit, region);    else // DISPLAY_MODE == 2      DrawRegion (pDC, uRegion++, uUnitCount, (rectClientRect.right - HORIZ_BORDER * 2) / uUnitCount, region);  }        pDC->SelectObject (pOldFont);  pDC->SetBkMode (nOldBkMode);}void CMLTView::DrawRegion (CDC* pDC, UINT uRegion, UINT uUnitCount, UINT uPixelsPerUnit, list <mem_region>::iterator region){  BOOL bDrawFocusRect = FALSE;  CRect rectAddress;  CString strAddress;    // setup the drawing objects    CBrush brshUnusedSection;  if (!brshUnusedSection.CreateHatchBrush (HS_BDIAGONAL, RGB (128, 128, 128)))    return;    CBrush brshUsedSection;  if (!brshUsedSection.CreateSolidBrush (GetSysColor (COLOR_WINDOW)))    return;    CBrush brshInitialSectionBar;  if (!brshInitialSectionBar.CreateSolidBrush (GetSysColor (COLOR_INACTIVECAPTION)))    return;    CBrush brshFixedSectionBar;  if (!brshFixedSectionBar.CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION)))    return;    CBrush brshFinalSectionBar;  if (!brshFinalSectionBar.CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION)))    return;    CPen penBorder;  if (!penBorder.CreatePen (PS_SOLID, 1, GetSysColor (COLOR_WINDOWTEXT)))    return;    CPen penSelected;  if (!penSelected.CreatePen (PS_SOLID, 2, GetSysColor (COLOR_WINDOWTEXT)))    return;    // select the border pen object    CPen * pOldPen = pDC->SelectObject (&penBorder);    // calculate the region rectangle    REGIONRECT srRegion;  srRegion.Rect.SetRect (HORIZ_BORDER, VERT_BORDER + REGION_SPACING * uRegion, HORIZ_BORDER + uUnitCount * uPixelsPerUnit + 1, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + 1);  srRegion.Region = region;  listRegionRect.AddTail (srRegion);    // draw the region    CPoint pointOrigin (srRegion.Rect.left, srRegion.Rect.top);  pDC->LPtoDP (&pointOrigin);  pointOrigin.x %= 8;  pointOrigin.y %= 8;  pDC->SetBrushOrg (pointOrigin);  CBrush * pOldBrush = pDC->SelectObject (&brshUnusedSection);  pDC->Rectangle (srRegion.Rect);  /*  pDC->MoveTo (srRegion.Rect.left, srRegion.Rect.bottom - 1); // draw tick  pDC->LineTo (srRegion.Rect.left, srRegion.Rect.bottom + TICK_HEIGHT); // draw tick  */  if (region == m_riSelectedRegion)  {    bDrawFocusRect = TRUE;    m_rectSelectedItem = srRegion.Rect;  }    // draw the region label    CRect rectRegionLabel (HORIZ_BORDER, VERT_BORDER + REGION_SPACING * uRegion - EXTERNAL_TEXT_BORDER - 20, m_uViewWidth - HORIZ_BORDER /*HORIZ_BORDER + uUnitCount * uPixelsPerUnit + 1*/, VERT_BORDER + REGION_SPACING * uRegion - EXTERNAL_TEXT_BORDER);  CString strRegionLabel;  strRegionLabel.Format (_T("%s (%08X-%08X)%s"), CString(region->name.c_str ()), region->address, region->address + region->size - 1, ((region->type == read_only) ? _T(" read only") : _T("")));  pDC->DrawText (strRegionLabel, -1, rectRegionLabel, DT_BOTTOM | DT_SINGLELINE);    // draw the start address of the region  /*  rectAddress.SetRect (HORIZ_BORDER, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, HORIZ_BORDER + ADDRESS_TEXT_SPACE * UNITS_PER_SECTION * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30);  strAddress.Format (ADDRESS_FORMAT, region->address);  pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE);  */  // draw the end address of the region  /*  rectAddress.SetRect (HORIZ_BORDER + (uUnitCount - ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, HORIZ_BORDER + (uUnitCount + ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30);  strAddress.Format (ADDRESS_FORMAT, region->address + region->size);  pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE);  */  // draw the sections within the region    UINT uSectionUnitCount = 0;  CRect rectBar;  SECTIONRECT srSection;  for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)  {    if (section_view->section != NULL) // the section is used    {      // draw the section            pDC->SelectObject (brshUsedSection);      srSection.Rect.SetRect (HORIZ_BORDER + uSectionUnitCount * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion, HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION) * uPixelsPerUnit + 1, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + 1);      srSection.SectionView = section_view;      listSectionRect.AddTail (srSection);      pDC->Rectangle (srSection.Rect);      if (section_view == m_sviSelectedSectionView)      {        bDrawFocusRect = TRUE;        m_rectSelectedItem = srSection.Rect;      }            // draw text within the section      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -