📄 mltview.cpp
字号:
CString strSection, strSectionLine; if ((section_view->section_location != initial_location) && (section_view->section->alignment > 1)) { strSectionLine.Format (_T("align %lX\n"), section_view->section->alignment); strSection += strSectionLine; } if (section_view->section->size > 0) { strSectionLine.Format (_T("size %lX\n"), section_view->section->size); strSection += strSectionLine; } if (section_view->section_location == final_location) { strSectionLine.Format (_T("relocated\n")); strSection += strSectionLine; } pDC->DrawText (strSection, -1, srSection.Rect - (LPCRECT) CRect (EXTERNAL_TEXT_BORDER, EXTERNAL_TEXT_BORDER + BAR_HEIGHT, EXTERNAL_TEXT_BORDER, EXTERNAL_TEXT_BORDER), DT_LEFT); // select caption bar colour according to type of section if (section_view->section_location == initial_location) { pDC->SetTextColor (GetSysColor (COLOR_INACTIVECAPTIONTEXT)); pDC->SelectObject (&brshInitialSectionBar); } else { pDC->SetTextColor (GetSysColor (COLOR_CAPTIONTEXT)); pDC->SelectObject (&brshFinalSectionBar); } // draw the caption bar rectBar.SetRect (HORIZ_BORDER + uSectionUnitCount * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion, HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION) * uPixelsPerUnit + 1, VERT_BORDER + REGION_SPACING * uRegion + BAR_HEIGHT + 1); pDC->Rectangle (rectBar); // draw the section name within the caption bar CString strName(section_view->section->name.c_str ()); CRect *pRect=NULL; m_arstrTooltipRects.Lookup(strName,(void *&)pRect); UINT format; if(pDC->GetTextExtent(strName).cx>rectBar.Width()-2*EXTERNAL_TEXT_BORDER){ format=DT_LEFT; if(pRect){ pRect->CopyRect(rectBar); } else { pRect=new CRect; m_arstrTooltipRects.SetAt(strName,pRect); } // Replace final three characters of name with an elipsis int nLength=1+max(1,strName.GetLength()-3); do { --nLength; strName=strName.Left(nLength)+_T("..."); } while(nLength>1 && pDC->GetTextExtent(strName).cx>rectBar.Width()-2*EXTERNAL_TEXT_BORDER); rectBar.left+=EXTERNAL_TEXT_BORDER; rectBar.right-=EXTERNAL_TEXT_BORDER; } else { format=DT_CENTER; if (pRect) { m_arstrTooltipRects.RemoveKey(strName); } } pDC->DrawText (strName, -1, rectBar, format | DT_VCENTER | DT_SINGLELINE); pDC->SetTextColor (GetSysColor (COLOR_WINDOWTEXT)); // find the mem_section item describing the current section_view item list <mem_section>::iterator MemorySection = section_view->section; // draw the section address if appropriate if ((section_view->section_location == initial_location)) { if (MemorySection->initial_location->anchor == absolute) { pDC->MoveTo (srSection.Rect.left, srSection.Rect.bottom - 1); // draw tick pDC->LineTo (srSection.Rect.left, srSection.Rect.bottom + TICK_HEIGHT); // draw tick rectAddress.SetRect (HORIZ_BORDER + uSectionUnitCount * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, (int) (HORIZ_BORDER + (uSectionUnitCount + ADDRESS_TEXT_SPACE * UNITS_PER_SECTION) * uPixelsPerUnit), VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30); strAddress.Format (ADDRESS_FORMAT, MemorySection->initial_location->address); pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE); /* if (MemorySection->size > 0) // the end address can be calculated { rectAddress.SetRect (HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION - ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION + ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30); strAddress.Format (ADDRESS_FORMAT, MemorySection->initial_location->address + MemorySection->size); pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE); } */ } } else if ((section_view->section_location == final_location) || (section_view->section_location == fixed_location)) { if (MemorySection->final_location->anchor == absolute) { pDC->MoveTo (srSection.Rect.left, srSection.Rect.bottom - 1); // draw tick pDC->LineTo (srSection.Rect.left, srSection.Rect.bottom + TICK_HEIGHT); // draw tick rectAddress.SetRect (HORIZ_BORDER + uSectionUnitCount * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, (int) (HORIZ_BORDER + (uSectionUnitCount + ADDRESS_TEXT_SPACE * UNITS_PER_SECTION) * uPixelsPerUnit), VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30); strAddress.Format (ADDRESS_FORMAT, MemorySection->final_location->address); pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE); /* if (MemorySection->size > 0) // the end address can be calculated { rectAddress.SetRect (HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION - ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER, HORIZ_BORDER + (uSectionUnitCount + UNITS_PER_SECTION + ADDRESS_TEXT_SPACE) * uPixelsPerUnit, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + EXTERNAL_TEXT_BORDER + 30); strAddress.Format (ADDRESS_FORMAT, MemorySection->final_location->address + MemorySection->size); pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE); } */ } } uSectionUnitCount += UNITS_PER_SECTION; } else { uSectionUnitCount++; // unused sections occupy a single unit } } // draw the focus rectangle around the selected object (if any) if (bDrawFocusRect) pDC->DrawFocusRect (m_rectSelectedItem + CRect (1, 1, 1, 1)); // restore previous drawing objects pDC->SelectObject (pOldBrush); pDC->SelectObject (pOldPen);}SECTIONRECT * CMLTView::SectionHitTest (CPoint pntTest){ for (POSITION posSection = listSectionRect.GetHeadPosition (); posSection != NULL; listSectionRect.GetNext (posSection)) { if (listSectionRect.GetAt (posSection).Rect.PtInRect (pntTest)) return & listSectionRect.GetAt (posSection); } return NULL;}REGIONRECT * CMLTView::RegionHitTest (CPoint pntTest){ for (POSITION posRegion = listRegionRect.GetHeadPosition (); posRegion != NULL; listRegionRect.GetNext (posRegion)) { CRect rectRegion = listRegionRect.GetAt (posRegion).Rect + CRect (EXTERNAL_TEXT_BORDER + 20, EXTERNAL_TEXT_BORDER + 20, EXTERNAL_TEXT_BORDER + 20, EXTERNAL_TEXT_BORDER + 20); // extended rectangle to allow clicking on region label if (rectRegion.PtInRect (pntTest)) return & listRegionRect.GetAt (posRegion); } return NULL;}/////////////////////////////////////////////////////////////////////////////// CMLTView printingBOOL CMLTView::OnPreparePrinting(CPrintInfo* pInfo){ // default preparation return DoPreparePrinting(pInfo);}void CMLTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){ // TODO: add extra initialization before printing}void CMLTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){ // TODO: add cleanup after printing}/////////////////////////////////////////////////////////////////////////////// CMLTView diagnostics#ifdef _DEBUGvoid CMLTView::AssertValid() const{ CView::AssertValid();}void CMLTView::Dump(CDumpContext& dc) const{ CView::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CMLTView message handlersvoid CMLTView::OnLButtonDown(UINT nFlags, CPoint point) { if (CConfigTool::GetConfigToolDoc() == NULL) // nothing to do return; list <mem_section_view>::iterator sviOldSelectedSectionView = m_sviSelectedSectionView; list <mem_region>::iterator riOldSelectedRegion = m_riSelectedRegion; CRect rectOldSelectedItem = m_rectSelectedItem; CConfigTool::GetConfigToolDoc()->strSelectedRegion = _T(""); CConfigTool::GetConfigToolDoc()->strSelectedSection = _T(""); SECTIONRECT * psrSection = SectionHitTest (point + GetScrollPosition ()); if (psrSection != NULL) // a section was clicked { m_sviSelectedSectionView = psrSection->SectionView; m_rectSelectedItem = psrSection->Rect; m_riSelectedRegion = NULL; CConfigTool::GetConfigToolDoc()->strSelectedSection = m_sviSelectedSectionView->section->name.c_str (); } else // no section was clicked, test for regions { REGIONRECT * prrRegion = RegionHitTest (point + GetScrollPosition ()); if (prrRegion != NULL) // a region was clicked, but not a section { m_riSelectedRegion = prrRegion->Region; m_rectSelectedItem = prrRegion->Rect; m_sviSelectedSectionView = NULL; CConfigTool::GetConfigToolDoc()->strSelectedRegion = m_riSelectedRegion->name.c_str (); } } // redraw the focus rectangle if the selection has changed if ((m_sviSelectedSectionView != sviOldSelectedSectionView) || (m_riSelectedRegion != riOldSelectedRegion)) { // CDC * pDC = GetDC (); if ((sviOldSelectedSectionView != NULL) || (riOldSelectedRegion != NULL)) // pDC->DrawFocusRect (rectOldSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); InvalidateRect (rectOldSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); // paint over the old focus rectangle if ((m_sviSelectedSectionView != NULL) || (m_riSelectedRegion != NULL)) // pDC->DrawFocusRect (m_rectSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); InvalidateRect (m_rectSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); // paint the new focus rectangle } // perform default processing CView::OnLButtonDown(nFlags, point);}void CMLTView::OnLButtonDblClk(UINT nFlags, CPoint point) { if (CConfigTool::GetConfigToolDoc() != NULL) CConfigTool::GetConfigToolDoc()->OnMLTProperties (); CView::OnLButtonDblClk(nFlags, point);}void CMLTView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { if ((lHint != 0) && (pHint != NULL) && (lHint != CConfigToolDoc::MemLayoutChanged)) return; // no need to invalidate the view m_arstrTooltipRects.RemoveAll(); CalcUnitCountMax (); // recalculate the total view width since the section count may have changed if (m_uUnitCountMax == 0 || (m_uClientWidth < HORIZ_BORDER * 2)) // there is nothing to draw m_uViewWidth = 0; else // allow horizontal scrolling when the unit width reduces to UNIT_WIDTH_MIN m_uViewWidth = __max ((m_uClientWidth - HORIZ_BORDER * 2) / m_uUnitCountMax, UNIT_WIDTH_MIN) * m_uUnitCountMax + HORIZ_BORDER * 2; SIZE sizeTotal; sizeTotal.cx = __max (m_uViewWidth, m_uClientWidth); sizeTotal.cy = CConfigTool::GetConfigToolDoc()->MemoryMap.region_list.size () * REGION_SPACING + EXTERNAL_TEXT_BORDER * 2; SetScrollSizes (MM_TEXT, sizeTotal); CScrollView::OnUpdate (pSender, lHint, pHint);}void CMLTView::OnSize(UINT nType, int cx, int cy)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -