OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [mltview.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// MLTView.cpp: implementation of the CMLTView class.
23
//
24
//////////////////////////////////////////////////////////////////////
25
 
26
#include "stdafx.h"
27
#ifndef PLUGIN
28
#include "BCMenu.h"
29
#endif
30
#include "ConfigtoolDoc.h"
31
#include "MLTView.h"
32
#include "ConfigTool.h"
33
#include "CTUtils.h"
34
#include "resource.h"
35
 
36
#ifdef _DEBUG
37
#define new DEBUG_NEW
38
#undef THIS_FILE
39
static char THIS_FILE[] = __FILE__;
40
#endif
41
 
42
using namespace std;
43
 
44
//////////////////////////////////////////////////////////////////////
45
// Construction/Destruction
46
//////////////////////////////////////////////////////////////////////
47
 
48
IMPLEMENT_DYNCREATE(CMLTView, CScrollView)
49
 
50
BEGIN_MESSAGE_MAP(CMLTView, CScrollView)
51
  //{{AFX_MSG_MAP(CMLTView)
52
    ON_WM_LBUTTONDOWN()
53
    ON_WM_LBUTTONDBLCLK()
54
    ON_WM_SIZE()
55
    ON_WM_ERASEBKGND()
56
    ON_WM_MOUSEMOVE()
57
    ON_COMMAND(ID_EDIT_NEW_REGION, OnMLTNewRegion)
58
    ON_COMMAND(ID_EDIT_NEW_SECTION, OnMLTNewSection)
59
    ON_COMMAND(ID_EDIT_DELETE_SECTION, OnMLTDelete)
60
    ON_COMMAND(ID_EDIT_PROPERTIES, OnMLTProperties)
61
    ON_UPDATE_COMMAND_UI(ID_EDIT_NEW_SECTION, OnUpdateMLTNewSection)
62
    ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE_SECTION, OnUpdateMLTDelete)
63
    ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateMLTProperties)
64
    ON_WM_CONTEXTMENU()
65
    ON_COMMAND(ID_POPUP_PROPERTIES, OnPopupProperties)
66
    ON_WM_RBUTTONDOWN()
67
        ON_WM_KEYDOWN()
68
        ON_WM_HELPINFO()
69
        ON_WM_MENUCHAR()
70
        //}}AFX_MSG_MAP
71
  ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
72
        ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
73
  // Standard printing commands
74
  ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
75
  ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
76
  ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
77
END_MESSAGE_MAP()
78
 
79
CMLTView::CMLTView()
80
{
81
  m_uViewWidth = 0;
82
  m_uUnitCountMax = 0;
83
  CConfigTool::SetMLTView(this);
84
}
85
 
86
CMLTView::~CMLTView()
87
{
88
  CConfigTool::SetMLTView(0);
89
  for(POSITION pos = m_arstrTooltipRects.GetStartPosition(); pos != NULL; ){
90
    CRect *pRect;
91
    CString strName;
92
    m_arstrTooltipRects.GetNextAssoc( pos, strName, (void *&)pRect );
93
    delete pRect;
94
  }
95
}
96
 
97
/////////////////////////////////////////////////////////////////////////////
98
// CMLTView drawing
99
 
100
#define VERT_BORDER 30 /* the vertical border at the top/bottom of the client area */
101
#define HORIZ_BORDER 30 /* the horizontal border at the left/right of the client area */
102
#define BAR_HEIGHT 18 /* the height of the memory section caption bar */
103
#define MAP_HEIGHT 66 /* the height of each memory section rectangle (including caption bar) */
104
#define REGION_SPACING 115 /* the vertical offset between successive memory regions */
105
#define ADDRESS_TEXT_SPACE 0.9 /* use 90% of the section width to draw the address */
106
#define EXTERNAL_TEXT_BORDER 5 /* spacing between external text and border of region */
107
#define ADDRESS_FORMAT _T("%08X") /* draw memory addresses in hex format */
108
#define UNITS_PER_SECTION 3 /* memory section width in units, unused sections are 1 unit wide */
109
#define UNIT_WIDTH_MIN 27 /* minimum width of memory section unit before horizontal scrolling enabled */
110
#define TICK_HEIGHT 4 /* the height of the tick marks on the memory sections and regions */
111
 
112
#define DISPLAY_MODE 1 /* 1 == const unit width for all regions */
113
/* 2 == const region width for all regions */
114
 
115
void CMLTView::OnDraw(CDC* pDC)
116
{
117
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
118
  if (pDoc == NULL) // no document so nothing to draw
119
    return;
120
 
121
  // clear the lists of region and section rectangles used for hit testing
122
 
123
  listRegionRect.RemoveAll ();
124
  listSectionRect.RemoveAll ();
125
 
126
  // setup background mode
127
 
128
  int nOldBkMode = pDC->SetBkMode (TRANSPARENT);
129
 
130
  // setup font
131
 
132
  CFont fntName;
133
  if (!fntName.CreatePointFont (80, _T("MS Sans Serif"), pDC))
134
    return;
135
  CFont * pOldFont = pDC->SelectObject (&fntName);
136
 
137
  // determine max unit count for any region
138
 
139
  mem_map * pMemoryMap = &CConfigTool::GetConfigToolDoc()->MemoryMap;
140
 
141
  // calculate the unit scaling for DISPLAY_MODE 1
142
 
143
  UINT uPixelsPerUnit = UNIT_WIDTH_MIN;
144
  RECT rectClientRect;
145
  if (m_uUnitCountMax != 0) // if there is something to draw
146
  {
147
 
148
    GetClientRect (&rectClientRect);
149
    uPixelsPerUnit = __max ((m_uClientWidth - HORIZ_BORDER * 2) / m_uUnitCountMax, UNIT_WIDTH_MIN);
150
    m_uViewWidth = uPixelsPerUnit * m_uUnitCountMax + HORIZ_BORDER * 2;
151
  }
152
 
153
  // draw the regions
154
 
155
  UINT uRegion = 0;
156
  UINT uUnitCount;
157
  list <mem_region>::iterator region;
158
  for (region = pMemoryMap->region_list.begin (); region != pMemoryMap->region_list.end (); ++region)
159
  {
160
    uUnitCount = 0;
161
    for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)
162
      uUnitCount += (section_view->section == NULL ? 1 : UNITS_PER_SECTION);
163
 
164
    if (DISPLAY_MODE == 1)
165
      DrawRegion (pDC, uRegion++, uUnitCount, uPixelsPerUnit, region);
166
    else // DISPLAY_MODE == 2
167
      DrawRegion (pDC, uRegion++, uUnitCount, (rectClientRect.right - HORIZ_BORDER * 2) / uUnitCount, region);
168
  }
169
 
170
  pDC->SelectObject (pOldFont);
171
  pDC->SetBkMode (nOldBkMode);
172
}
173
 
174
 
175
void CMLTView::DrawRegion (CDC* pDC, UINT uRegion, UINT uUnitCount, UINT uPixelsPerUnit, list <mem_region>::iterator region)
176
{
177
  BOOL bDrawFocusRect = FALSE;
178
  CRect rectAddress;
179
  CString strAddress;
180
 
181
  // setup the drawing objects
182
 
183
  CBrush brshUnusedSection;
184
  if (!brshUnusedSection.CreateHatchBrush (HS_BDIAGONAL, RGB (128, 128, 128)))
185
    return;
186
 
187
  CBrush brshUsedSection;
188
  if (!brshUsedSection.CreateSolidBrush (GetSysColor (COLOR_WINDOW)))
189
    return;
190
 
191
  CBrush brshInitialSectionBar;
192
  if (!brshInitialSectionBar.CreateSolidBrush (GetSysColor (COLOR_INACTIVECAPTION)))
193
    return;
194
 
195
  CBrush brshFixedSectionBar;
196
  if (!brshFixedSectionBar.CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION)))
197
    return;
198
 
199
  CBrush brshFinalSectionBar;
200
  if (!brshFinalSectionBar.CreateSolidBrush (GetSysColor (COLOR_ACTIVECAPTION)))
201
    return;
202
 
203
  CPen penBorder;
204
  if (!penBorder.CreatePen (PS_SOLID, 1, GetSysColor (COLOR_WINDOWTEXT)))
205
    return;
206
 
207
  CPen penSelected;
208
  if (!penSelected.CreatePen (PS_SOLID, 2, GetSysColor (COLOR_WINDOWTEXT)))
209
    return;
210
 
211
  // select the border pen object
212
 
213
  CPen * pOldPen = pDC->SelectObject (&penBorder);
214
 
215
  // calculate the region rectangle
216
 
217
  REGIONRECT srRegion;
218
  srRegion.Rect.SetRect (HORIZ_BORDER, VERT_BORDER + REGION_SPACING * uRegion, HORIZ_BORDER + uUnitCount * uPixelsPerUnit + 1, VERT_BORDER + REGION_SPACING * uRegion + MAP_HEIGHT + 1);
219
  srRegion.Region = region;
220
  listRegionRect.AddTail (srRegion);
221
 
222
  // draw the region
223
 
224
  CPoint pointOrigin (srRegion.Rect.left, srRegion.Rect.top);
225
  pDC->LPtoDP (&pointOrigin);
226
  pointOrigin.x %= 8;
227
  pointOrigin.y %= 8;
228
  pDC->SetBrushOrg (pointOrigin);
229
  CBrush * pOldBrush = pDC->SelectObject (&brshUnusedSection);
230
  pDC->Rectangle (srRegion.Rect);
231
  /*
232
  pDC->MoveTo (srRegion.Rect.left, srRegion.Rect.bottom - 1); // draw tick
233
  pDC->LineTo (srRegion.Rect.left, srRegion.Rect.bottom + TICK_HEIGHT); // draw tick
234
  */
235
  if (region == m_riSelectedRegion)
236
  {
237
    bDrawFocusRect = TRUE;
238
    m_rectSelectedItem = srRegion.Rect;
239
  }
240
 
241
  // draw the region label
242
 
243
  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);
244
  CString strRegionLabel;
245
  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("")));
246
  pDC->DrawText (strRegionLabel, -1, rectRegionLabel, DT_BOTTOM | DT_SINGLELINE);
247
 
248
  // draw the start address of the region
249
  /*
250
  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);
251
  strAddress.Format (ADDRESS_FORMAT, region->address);
252
  pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE);
253
  */
254
  // draw the end address of the region
255
  /*
256
  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);
257
  strAddress.Format (ADDRESS_FORMAT, region->address + region->size);
258
  pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE);
259
  */
260
  // draw the sections within the region
261
 
262
  UINT uSectionUnitCount = 0;
263
  CRect rectBar;
264
  SECTIONRECT srSection;
265
  for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)
266
  {
267
    if (section_view->section != NULL) // the section is used
268
    {
269
      // draw the section
270
 
271
      pDC->SelectObject (brshUsedSection);
272
      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);
273
      srSection.SectionView = section_view;
274
      listSectionRect.AddTail (srSection);
275
      pDC->Rectangle (srSection.Rect);
276
      if (section_view == m_sviSelectedSectionView)
277
      {
278
        bDrawFocusRect = TRUE;
279
        m_rectSelectedItem = srSection.Rect;
280
      }
281
 
282
      // draw text within the section
283
 
284
      CString strSection, strSectionLine;
285
 
286
      if ((section_view->section_location != initial_location) && (section_view->section->alignment > 1))
287
      {
288
        strSectionLine.Format (_T("align %lX\n"), section_view->section->alignment);
289
        strSection += strSectionLine;
290
      }
291
 
292
      if (section_view->section->size > 0)
293
      {
294
        strSectionLine.Format (_T("size %lX\n"), section_view->section->size);
295
        strSection += strSectionLine;
296
      }
297
 
298
      if (section_view->section_location == final_location)
299
      {
300
        strSectionLine.Format (_T("relocated\n"));
301
        strSection += strSectionLine;
302
      }
303
 
304
      pDC->DrawText (strSection, -1, srSection.Rect - (LPCRECT) CRect (EXTERNAL_TEXT_BORDER, EXTERNAL_TEXT_BORDER + BAR_HEIGHT, EXTERNAL_TEXT_BORDER, EXTERNAL_TEXT_BORDER), DT_LEFT);
305
 
306
      // select caption bar colour according to type of section
307
 
308
      if (section_view->section_location == initial_location)
309
      {
310
        pDC->SetTextColor (GetSysColor (COLOR_INACTIVECAPTIONTEXT));
311
        pDC->SelectObject (&brshInitialSectionBar);
312
      }
313
      else
314
      {
315
        pDC->SetTextColor (GetSysColor (COLOR_CAPTIONTEXT));
316
        pDC->SelectObject (&brshFinalSectionBar);
317
      }
318
 
319
      // draw the caption bar
320
 
321
      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);
322
      pDC->Rectangle (rectBar);
323
 
324
      // draw the section name within the caption bar
325
 
326
      CString strName(section_view->section->name.c_str ());
327
      CRect *pRect=NULL;
328
      m_arstrTooltipRects.Lookup(strName,(void *&)pRect);
329
      UINT format;
330
      if(pDC->GetTextExtent(strName).cx>rectBar.Width()-2*EXTERNAL_TEXT_BORDER){
331
        format=DT_LEFT;
332
        if(pRect){
333
          pRect->CopyRect(rectBar);
334
        } else {
335
          pRect=new CRect;
336
          m_arstrTooltipRects.SetAt(strName,pRect);
337
        }
338
        // Replace final three characters of name with an elipsis
339
        int nLength=1+max(1,strName.GetLength()-3);
340
        do {
341
          --nLength;
342
          strName=strName.Left(nLength)+_T("...");
343
        } while(nLength>1 && pDC->GetTextExtent(strName).cx>rectBar.Width()-2*EXTERNAL_TEXT_BORDER);
344
 
345
        rectBar.left+=EXTERNAL_TEXT_BORDER;
346
        rectBar.right-=EXTERNAL_TEXT_BORDER;
347
      } else {
348
        format=DT_CENTER;
349
        if (pRect) {
350
          m_arstrTooltipRects.RemoveKey(strName);
351
        }
352
      }
353
 
354
      pDC->DrawText (strName, -1, rectBar, format | DT_VCENTER | DT_SINGLELINE);
355
      pDC->SetTextColor (GetSysColor (COLOR_WINDOWTEXT));
356
 
357
      // find the mem_section item describing the current section_view item
358
 
359
      list <mem_section>::iterator MemorySection = section_view->section;
360
 
361
      // draw the section address if appropriate
362
 
363
      if ((section_view->section_location == initial_location))
364
      {
365
        if (MemorySection->initial_location->anchor == absolute)
366
        {
367
          pDC->MoveTo (srSection.Rect.left, srSection.Rect.bottom - 1); // draw tick
368
          pDC->LineTo (srSection.Rect.left, srSection.Rect.bottom + TICK_HEIGHT); // draw tick
369
          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);
370
          strAddress.Format (ADDRESS_FORMAT, MemorySection->initial_location->address);
371
          pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE);
372
 
373
          /*
374
          if (MemorySection->size > 0) // the end address can be calculated
375
          {
376
          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);
377
          strAddress.Format (ADDRESS_FORMAT, MemorySection->initial_location->address + MemorySection->size);
378
          pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE);
379
          }
380
          */
381
        }
382
      }
383
 
384
      else if ((section_view->section_location == final_location) || (section_view->section_location == fixed_location))
385
      {
386
        if (MemorySection->final_location->anchor == absolute)
387
        {
388
          pDC->MoveTo (srSection.Rect.left, srSection.Rect.bottom - 1); // draw tick
389
          pDC->LineTo (srSection.Rect.left, srSection.Rect.bottom + TICK_HEIGHT); // draw tick
390
          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);
391
          strAddress.Format (ADDRESS_FORMAT, MemorySection->final_location->address);
392
          pDC->DrawText (strAddress, -1, rectAddress, DT_LEFT | DT_SINGLELINE);
393
 
394
          /*
395
          if (MemorySection->size > 0) // the end address can be calculated
396
          {
397
          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);
398
          strAddress.Format (ADDRESS_FORMAT, MemorySection->final_location->address + MemorySection->size);
399
          pDC->DrawText (strAddress, -1, rectAddress, DT_CENTER | DT_SINGLELINE);
400
          }
401
          */
402
        }
403
      }
404
 
405
      uSectionUnitCount += UNITS_PER_SECTION;
406
    }
407
    else
408
    {
409
      uSectionUnitCount++; // unused sections occupy a single unit
410
    }
411
  }
412
 
413
  // draw the focus rectangle around the selected object (if any)
414
 
415
  if (bDrawFocusRect)
416
    pDC->DrawFocusRect (m_rectSelectedItem + CRect (1, 1, 1, 1));
417
 
418
  // restore previous drawing objects
419
 
420
  pDC->SelectObject (pOldBrush);
421
  pDC->SelectObject (pOldPen);
422
}
423
 
424
 
425
SECTIONRECT * CMLTView::SectionHitTest (CPoint pntTest)
426
{
427
  for (POSITION posSection = listSectionRect.GetHeadPosition (); posSection != NULL; listSectionRect.GetNext (posSection))
428
  {
429
    if (listSectionRect.GetAt (posSection).Rect.PtInRect (pntTest))
430
      return & listSectionRect.GetAt (posSection);
431
  }
432
 
433
  return NULL;
434
}
435
 
436
 
437
REGIONRECT * CMLTView::RegionHitTest (CPoint pntTest)
438
{
439
  for (POSITION posRegion = listRegionRect.GetHeadPosition (); posRegion != NULL; listRegionRect.GetNext (posRegion))
440
  {
441
    CRect rectRegion = listRegionRect.GetAt (posRegion).Rect +
442
      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
443
    if (rectRegion.PtInRect (pntTest))
444
      return & listRegionRect.GetAt (posRegion);
445
  }
446
 
447
  return NULL;
448
}
449
 
450
 
451
/////////////////////////////////////////////////////////////////////////////
452
// CMLTView printing
453
 
454
BOOL CMLTView::OnPreparePrinting(CPrintInfo* pInfo)
455
{
456
  // default preparation
457
  return DoPreparePrinting(pInfo);
458
}
459
 
460
void CMLTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
461
{
462
  // TODO: add extra initialization before printing
463
}
464
 
465
void CMLTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
466
{
467
  // TODO: add cleanup after printing
468
}
469
 
470
/////////////////////////////////////////////////////////////////////////////
471
// CMLTView diagnostics
472
 
473
#ifdef _DEBUG
474
void CMLTView::AssertValid() const
475
{
476
  CView::AssertValid();
477
}
478
 
479
void CMLTView::Dump(CDumpContext& dc) const
480
{
481
  CView::Dump(dc);
482
}
483
 
484
#endif //_DEBUG
485
 
486
/////////////////////////////////////////////////////////////////////////////
487
// CMLTView message handlers
488
 
489
 
490
void CMLTView::OnLButtonDown(UINT nFlags, CPoint point)
491
{
492
  if (CConfigTool::GetConfigToolDoc() == NULL) // nothing to do
493
    return;
494
 
495
  list <mem_section_view>::iterator sviOldSelectedSectionView = m_sviSelectedSectionView;
496
  list <mem_region>::iterator riOldSelectedRegion = m_riSelectedRegion;
497
  CRect rectOldSelectedItem = m_rectSelectedItem;
498
 
499
  CConfigTool::GetConfigToolDoc()->strSelectedRegion = _T("");
500
  CConfigTool::GetConfigToolDoc()->strSelectedSection = _T("");
501
 
502
  SECTIONRECT * psrSection = SectionHitTest (point + GetScrollPosition ());
503
  if (psrSection != NULL) // a section was clicked
504
  {
505
    m_sviSelectedSectionView = psrSection->SectionView;
506
    m_rectSelectedItem = psrSection->Rect;
507
    m_riSelectedRegion = NULL;
508
    CConfigTool::GetConfigToolDoc()->strSelectedSection = m_sviSelectedSectionView->section->name.c_str ();
509
  }
510
 
511
  else // no section was clicked, test for regions
512
  {
513
    REGIONRECT * prrRegion = RegionHitTest (point + GetScrollPosition ());
514
    if (prrRegion != NULL) // a region was clicked, but not a section
515
    {
516
      m_riSelectedRegion = prrRegion->Region;
517
      m_rectSelectedItem = prrRegion->Rect;
518
      m_sviSelectedSectionView = NULL;
519
      CConfigTool::GetConfigToolDoc()->strSelectedRegion = m_riSelectedRegion->name.c_str ();
520
    }
521
  }
522
 
523
  // redraw the focus rectangle if the selection has changed
524
 
525
  if ((m_sviSelectedSectionView != sviOldSelectedSectionView) || (m_riSelectedRegion != riOldSelectedRegion))
526
  {
527
    //          CDC * pDC = GetDC ();
528
    if ((sviOldSelectedSectionView != NULL) || (riOldSelectedRegion != NULL))
529
      //                        pDC->DrawFocusRect (rectOldSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ());
530
      InvalidateRect (rectOldSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); // paint over the old focus rectangle
531
    if ((m_sviSelectedSectionView != NULL) || (m_riSelectedRegion != NULL))
532
      //                        pDC->DrawFocusRect (m_rectSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ());
533
      InvalidateRect (m_rectSelectedItem + CRect (1, 1, 1, 1) - GetScrollPosition ()); // paint the new focus rectangle
534
  }
535
 
536
  // perform default processing
537
 
538
  CView::OnLButtonDown(nFlags, point);
539
}
540
 
541
void CMLTView::OnLButtonDblClk(UINT nFlags, CPoint point)
542
{
543
  if (CConfigTool::GetConfigToolDoc() != NULL)
544
    CConfigTool::GetConfigToolDoc()->OnMLTProperties ();
545
 
546
  CView::OnLButtonDblClk(nFlags, point);
547
}
548
 
549
void CMLTView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
550
{
551
  if ((lHint != 0) && (pHint != NULL) && (lHint != CConfigToolDoc::MemLayoutChanged))
552
    return; // no need to invalidate the view
553
  m_arstrTooltipRects.RemoveAll();
554
 
555
  CalcUnitCountMax (); // recalculate the total view width since the section count may have changed
556
  if (m_uUnitCountMax == 0 || (m_uClientWidth < HORIZ_BORDER * 2)) // there is nothing to draw
557
    m_uViewWidth = 0;
558
  else // allow horizontal scrolling when the unit width reduces to UNIT_WIDTH_MIN
559
    m_uViewWidth = __max ((m_uClientWidth - HORIZ_BORDER * 2) / m_uUnitCountMax, UNIT_WIDTH_MIN) * m_uUnitCountMax + HORIZ_BORDER * 2;
560
 
561
  SIZE sizeTotal;
562
  sizeTotal.cx = __max (m_uViewWidth, m_uClientWidth);
563
  sizeTotal.cy = CConfigTool::GetConfigToolDoc()->MemoryMap.region_list.size () * REGION_SPACING + EXTERNAL_TEXT_BORDER * 2;
564
  SetScrollSizes (MM_TEXT, sizeTotal);
565
 
566
  CScrollView::OnUpdate (pSender, lHint, pHint);
567
}
568
 
569
void CMLTView::OnSize(UINT nType, int cx, int cy)
570
{
571
  CScrollView::OnSize(nType, cx, cy);
572
 
573
  m_uClientWidth = cx;
574
  if (m_uUnitCountMax == 0) // there is nothing to draw
575
    m_uViewWidth = 0;
576
  else // allow horizontal scrolling when the unit width reduces to UNIT_WIDTH_MIN
577
    m_uViewWidth = __max ((cx - HORIZ_BORDER * 2) / m_uUnitCountMax, UNIT_WIDTH_MIN) * m_uUnitCountMax + HORIZ_BORDER * 2;
578
 
579
  SIZE sizeTotal;
580
  sizeTotal.cx = __max (m_uViewWidth, m_uClientWidth);
581
  if (CConfigTool::GetConfigToolDoc() == NULL)
582
    sizeTotal.cy = 0;
583
  else
584
    sizeTotal.cy = CConfigTool::GetConfigToolDoc()->MemoryMap.region_list.size () * REGION_SPACING + EXTERNAL_TEXT_BORDER * 2;
585
  SetScrollSizes (MM_TEXT, sizeTotal);
586
}
587
 
588
void CMLTView::CalcUnitCountMax ()
589
{
590
  UINT uUnitCountMax = 0;
591
  UINT uUnitCount;
592
  list <mem_region>::iterator region;
593
  mem_map * pMemoryMap = & (CConfigTool::GetConfigToolDoc()->MemoryMap);
594
  for (region = pMemoryMap->region_list.begin (); region != pMemoryMap->region_list.end (); ++region)
595
  {
596
    uUnitCount = 0;
597
    for (list <mem_section_view>::iterator section_view = region->section_view_list.begin (); section_view != region->section_view_list.end (); ++section_view)
598
      uUnitCount += (section_view->section == NULL ? 1 : UNITS_PER_SECTION);
599
 
600
    if (uUnitCount > uUnitCountMax)
601
      uUnitCountMax = uUnitCount;
602
  }
603
  m_uUnitCountMax = uUnitCountMax;
604
}
605
 
606
BOOL CMLTView::OnEraseBkgnd(CDC* pDC)
607
{
608
  // Work around bug apparently caused by SlickEdit
609
  CRect rcClient;
610
  pDC->GetClipBox(rcClient);
611
  pDC->FillSolidRect(rcClient,GetSysColor(COLOR_WINDOW));
612
 
613
  return TRUE;//return CScrollView::OnEraseBkgnd(pDC);
614
}
615
 
616
BOOL CMLTView::OnToolTipText(UINT id, NMHDR* pNMHDR, LRESULT*pResult)
617
{
618
        // need to handle both ANSI and UNICODE versions of the message
619
        TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
620
        TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
621
        id=pNMHDR->idFrom;
622
 
623
  if(id){
624
    for(POSITION pos = m_arstrTooltipRects.GetStartPosition(); pos != NULL; ){
625
      CRect *pRect;
626
      CString strTipText;
627
      m_arstrTooltipRects.GetNextAssoc( pos, strTipText, (void *&)pRect );
628
      if((UINT)pRect==id){
629
    #ifndef _UNICODE
630
              if (pNMHDR->code == TTN_NEEDTEXTA)
631
                      lstrcpyn(pTTTA->szText, strTipText, sizeof pTTTA->szText/sizeof TCHAR - 1);
632
              else
633
                      _mbstowcsz(pTTTW->szText, strTipText, sizeof pTTTW->szText/sizeof TCHAR - 1);
634
    #else
635
              if (pNMHDR->code == TTN_NEEDTEXTA)
636
                      _wcstombsz(pTTTA->szText, strTipText, sizeof pTTTA->szText/sizeof TCHAR - 1);
637
              else
638
                      lstrcpyn(pTTTW->szText, strTipText, sizeof pTTTW->szText/sizeof TCHAR - 1);
639
    #endif
640
        *pResult = 0;
641
        return TRUE;    // message was handled
642
      }
643
    }
644
  }
645
  return FALSE;
646
}
647
 
648
int CMLTView::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
649
{
650
  for(POSITION pos = m_arstrTooltipRects.GetStartPosition(); pos != NULL; ){
651
    CRect *pRect;
652
    CString strName;
653
    m_arstrTooltipRects.GetNextAssoc( pos, strName, (void *&)pRect );
654
 
655
    if(pRect->PtInRect(point)){
656
      pTI->hwnd = m_hWnd;
657
      pTI->uId = (UINT)pRect;
658
      pTI->uFlags = 0 ;
659
      GetClientRect(&pTI->rect);
660
      pTI->lpszText=LPSTR_TEXTCALLBACK;
661
            return pTI->uId;
662
    }
663
  }
664
  return -1;
665
}
666
 
667
void CMLTView::OnInitialUpdate()
668
{
669
        CScrollView::OnInitialUpdate();
670
        EnableToolTips(true);
671
}
672
 
673
void CMLTView::OnMouseMove(UINT nFlags, CPoint point)
674
{
675
/*
676
  CString strToolTipText;
677
  for(POSITION pos = m_arstrTooltipRects.GetStartPosition(); pos != NULL; ){
678
    CRect *pRect;
679
    CString strName;
680
    m_arstrTooltipRects.GetNextAssoc( pos, strName, (void *&)pRect );
681
 
682
    if(pRect->PtInRect(point)){
683
      strToolTipText=strName;
684
      break;
685
    }
686
  }
687
  if(strToolTipText!=m_strTipText){
688
          _AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
689
          CToolTipCtrl* pToolTip = pThreadState->m_pToolTip;
690
    if(!m_strTipText.IsEmpty()){
691
      pToolTip->Activate(false);
692
    }
693
    pToolTip->Activate(!strToolTipText.IsEmpty());
694
    m_strTipText=strToolTipText;
695
  }
696
*/
697
        CScrollView::OnMouseMove(nFlags, point);
698
}
699
 
700
void CMLTView::OnMLTNewRegion ()
701
{
702
  CConfigTool::GetConfigToolDoc ()->OnMLTNewRegion ();
703
}
704
 
705
void CMLTView::OnMLTNewSection ()
706
{
707
  CConfigTool::GetConfigToolDoc ()->OnMLTNewSection ();
708
}
709
 
710
void CMLTView::OnMLTDelete ()
711
{
712
  CConfigTool::GetConfigToolDoc ()->OnMLTDelete ();
713
}
714
 
715
void CMLTView::OnMLTProperties ()
716
{
717
  CConfigTool::GetConfigToolDoc ()->OnMLTProperties ();
718
}
719
 
720
void CMLTView::OnUpdateMLTNewRegion (CCmdUI* pCmdUI)
721
{
722
  pCmdUI->Enable (true);
723
}
724
 
725
void CMLTView::OnUpdateMLTNewSection (CCmdUI* pCmdUI)
726
{
727
  pCmdUI->Enable (CConfigTool::GetConfigToolDoc()->MemoryMap.region_list.size() > 0);
728
}
729
 
730
void CMLTView::OnUpdateMLTDelete (CCmdUI* pCmdUI)
731
{
732
  pCmdUI->Enable(
733
    (!CConfigTool::GetConfigToolDoc ()->strSelectedRegion.IsEmpty() || !CConfigTool::GetConfigToolDoc ()->strSelectedSection.IsEmpty()));
734
}
735
 
736
void CMLTView::OnUpdateMLTProperties (CCmdUI* pCmdUI)
737
{
738
  pCmdUI->Enable(
739
    (!CConfigTool::GetConfigToolDoc ()->strSelectedRegion.IsEmpty() || !CConfigTool::GetConfigToolDoc ()->strSelectedSection.IsEmpty()));
740
}
741
 
742
 
743
void CMLTView::OnContextMenu(CWnd*, CPoint point)
744
{
745
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
746
  if (!pDoc->strSelectedRegion.IsEmpty() || !pDoc->strSelectedSection.IsEmpty()){
747
    if(point.x<0){
748
      // Keyboard
749
      point=!pDoc->strSelectedRegion.IsEmpty()?m_rectSelectedItem.TopLeft():m_rectSelectedItem.CenterPoint();
750
      ClientToScreen(&point);
751
    }
752
    Menu menu;
753
    menu.LoadMenu(IDR_MLTVIEW_POPUP);
754
 
755
    #ifndef PLUGIN
756
    menu.LoadToolbar(IDR_MISCBAR);
757
    #endif
758
 
759
    Menu *pPopup=(Menu *)menu.GetSubMenu(0);
760
    pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, point.x,point.y,this);
761
  }
762
}
763
 
764
void CMLTView::OnPopupProperties()
765
{
766
  CConfigTool::GetConfigToolDoc()->OnMLTProperties ();
767
}
768
 
769
void CMLTView::OnRButtonDown(UINT nFlags, CPoint point)
770
{
771
  OnLButtonDown(nFlags, point);
772
  ClientToScreen(&point);
773
  OnContextMenu(this, point) ;
774
}
775
 
776
void CMLTView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
777
{
778
  POSITION pos;
779
  switch(nChar){
780
    case VK_RIGHT:
781
      pos = listSectionRect.GetHeadPosition ();
782
      if(!CConfigTool::GetConfigToolDoc()->strSelectedSection.IsEmpty()){
783
        while(NULL!=pos){
784
          if (listSectionRect.GetNext (pos).SectionView==m_sviSelectedSectionView){
785
            if(NULL==pos){
786
              pos=listSectionRect.GetHeadPosition();
787
            }
788
            break;
789
          }
790
        }
791
      }
792
      OnLButtonDown(0, listSectionRect.GetNext(pos).Rect.CenterPoint()-GetScrollPosition());
793
      break;
794
    case VK_LEFT:
795
      pos = listSectionRect.GetTailPosition ();
796
      if(!CConfigTool::GetConfigToolDoc()->strSelectedSection.IsEmpty()){
797
        while(NULL!=pos){
798
          if (listSectionRect.GetPrev (pos).SectionView==m_sviSelectedSectionView){
799
            if(NULL==pos){
800
              pos=listSectionRect.GetTailPosition();
801
            }
802
            break;
803
          }
804
        }
805
      }
806
      OnLButtonDown(0, listSectionRect.GetPrev(pos).Rect.CenterPoint()-GetScrollPosition());
807
      break;
808
    case VK_DOWN:
809
      pos = listRegionRect.GetHeadPosition ();
810
      if(!CConfigTool::GetConfigToolDoc()->strSelectedRegion.IsEmpty()){
811
        while(NULL!=pos){
812
          if (listRegionRect.GetNext (pos).Region==m_riSelectedRegion){
813
            if(NULL==pos){
814
              pos=listRegionRect.GetHeadPosition();
815
            }
816
            break;
817
          }
818
        }
819
      }
820
      OnLButtonDown(0, listRegionRect.GetNext(pos).Rect.TopLeft()-CPoint(1,1)-GetScrollPosition());
821
      break;
822
    case VK_UP:
823
      pos = listRegionRect.GetTailPosition ();
824
      if(!CConfigTool::GetConfigToolDoc()->strSelectedRegion.IsEmpty()){
825
        while(NULL!=pos){
826
          if (listRegionRect.GetPrev (pos).Region==m_riSelectedRegion){
827
            if(NULL==pos){
828
              pos=listRegionRect.GetTailPosition();
829
            }
830
            break;
831
          }
832
        }
833
      }
834
      OnLButtonDown(0, listRegionRect.GetPrev(pos).Rect.TopLeft()-CPoint(1,1)-GetScrollPosition());
835
      break;
836
    default:
837
      break;
838
  }
839
 
840
        CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
841
}
842
 
843
 
844
BOOL CMLTView::OnHelpInfo(HELPINFO*)
845
{
846
  return CConfigTool::GetConfigToolDoc()->ShowURL(CUtils::LoadString(IDS_MLT_VIEW_HELP));
847
}
848
 
849
LRESULT CMLTView::OnMenuChar(UINT, UINT, CMenu*)
850
{
851
  const MSG *pMsg=GetCurrentMessage();
852
  // punt to the mainframe to deal with shortcuts in popups
853
  return AfxGetMainWnd()->SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
854
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.