Skip to content

Commit

Permalink
[#40] Track Map: General improvements and bugfixes (Part 26: Fixed re…
Browse files Browse the repository at this point in the history
…sponsiveness of context menu)
  • Loading branch information
tomas-nestorovic committed Feb 11, 2022
1 parent 929dd25 commit c6726d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions Main/src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,13 @@ namespace Medium{

BOOL CImage::CanCloseFrame(CFrameWnd* pFrame){
// True <=> the MainWindow can be closed (and thus the application), otherwise False
EXCLUSIVELY_LOCK_THIS_IMAGE();
PREVENT_FROM_DESTRUCTION(*this);
//EXCLUSIVELY_LOCK_THIS_IMAGE(); // commented out as it's being not worked with the Image
// - first asking the DOS that handles this Image
if (!dos->CanBeShutDown(pFrame))
return FALSE;
// - then attempting to close this Image
return __super::CanCloseFrame(pFrame);
return pFrame!=nullptr // Null if e.g. app closing
? __super::CanCloseFrame(pFrame)
: SaveModified();
}
3 changes: 3 additions & 0 deletions Main/src/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@

static Utils::CPtrList<PCProperties> Known; // list of known Images (registered in CRideApp::InitInstance)
static Utils::CPtrList<PCProperties> Devices; // list of known Devices (registered in CRideApp::InitInstance)
static CMutex destructionLocker;

static CImage *GetActive();
static PCProperties DetermineType(LPCTSTR fileName);
Expand Down Expand Up @@ -693,4 +694,6 @@
#define EXCLUSIVELY_LOCK_IMAGE(rImg) EXCLUSIVELY_LOCK(rImg)
#define EXCLUSIVELY_LOCK_THIS_IMAGE() EXCLUSIVELY_LOCK_IMAGE(*this)

#define PREVENT_FROM_DESTRUCTION(rObj) const Utils::CExclusivelyLocked locker( (rObj).destructionLocker )

#endif // IMAGE_H
3 changes: 3 additions & 0 deletions Main/src/TdiTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
return m_pOnlyDoc;
}

CMutex CImage::destructionLocker;

bool CMainWindow::CTdiTemplate::__closeDocument__(){
// closes the main Image (usually a disk)
if (m_pOnlyDoc){
Expand All @@ -45,6 +47,7 @@
( (CFrameWnd *)app.m_pMainWnd )->OnUpdateFrameTitle(FALSE); // updating the MainWindow's title (now without document)
}
const PImage image=(PImage)m_pOnlyDoc;
PREVENT_FROM_DESTRUCTION(*image); // have exlusive rights for destruction
image->locker.Lock(); // have exclusive right for manipulation
if (image->dos)
delete image->dos, image->dos=nullptr;
Expand Down
8 changes: 5 additions & 3 deletions Main/src/ViewTrackMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
break;
const div_t d=div(trackNumber,nHeads);
// . scanning the Track to draw its Sector Statuses
{ EXCLUSIVELY_LOCK_IMAGE(*image);
{ PREVENT_FROM_DESTRUCTION(*image);
if (!::IsWindow(pvtm->m_hWnd)) // TrackMap may not exist if, for instance, switched to another view while still scanning some Track(s)
continue;
ti.cylinder=d.quot, ti.head=d.rem;
Expand All @@ -241,7 +241,7 @@
// . scanning the Track to draw its Sector data
if (pvtm->displayType>=TDisplayType::DATA_OK_ONLY){
TFdcStatus statuses[(TSector)-1];
EXCLUSIVELY_LOCK_IMAGE(*image);
PREVENT_FROM_DESTRUCTION(*image);
if (!::IsWindow(pvtm->m_hWnd)) // TrackMap may not exist if, for instance, switched to another view while still scanning some Track(s)
continue;
image->GetTrackData( ti.cylinder, ti.head, Revolution::CURRENT, ti.bufferId, sectorIdAndPositionIdentity, ti.nSectors, ti.bufferSectorData, ti.bufferLength, statuses );
Expand Down Expand Up @@ -522,6 +522,8 @@
rOutNanoseconds= ns<=longestTrackNanoseconds ? ns : -1;
}
// . determining the Sector on which the cursor hovers
if (point.x<SECTOR1_X) // in "Cylinder" or "Head" columns?
return TCursorPos::TRACK;
const TTrack track=point.y/TRACK_HEIGHT;
const div_t d=div( track, scanner.params.nHeads );
TSectorId bufferId[(TSector)-1];
Expand Down Expand Up @@ -603,7 +605,7 @@
case TCursorPos::TRACK:
// clicked on a Track
mnu.EnableMenuItem( ID_TRACK, MF_BYCOMMAND|MF_ENABLED );
if (IMAGE->ReadTrack( chs.cylinder, chs.head ))
if (IMAGE->WriteTrack(0,0,CImage::CTrackReaderWriter::Invalid)!=ERROR_NOT_SUPPORTED) // determining existence of low-level information by an attempt of writing
mnu.EnableMenuItem( ID_HEAD, MF_BYCOMMAND|MF_ENABLED );
break;
default:
Expand Down

0 comments on commit c6726d6

Please sign in to comment.