Skip to content

Commit

Permalink
[#13] Minor source code improvements (Part 112: Replacement of CMainW…
Browse files Browse the repository at this point in the history
…indow::TDynMenu with CMainWindow::CDynMenu)
  • Loading branch information
tomas-nestorovic committed Nov 9, 2020
1 parent 35ceee2 commit 4252bda
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Main/src/BSDOS_FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
if (const LRESULT err=__super::WindowProc(msg,wParam,lParam))
return err;
// . showing the Tape ToolBar "after" the FileManager's ToolBar
toolbar.__show__( tab.toolbar );
toolbar.Show( tab.toolbar );
return 0;
case WM_DESTROY:
// FileManager destroyed - hiding the Tape ToolBar
toolbar.__hide__();
toolbar.Hide();
break;
}
return __super::WindowProc(msg,wParam,lParam);
Expand Down
2 changes: 1 addition & 1 deletion Main/src/Dos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
if (CHexaPreview::pSingleInstance && &CHexaPreview::pSingleInstance->rFileManager==pFileManager)
CHexaPreview::pSingleInstance->DestroyWindow();
// - hiding DOS Menu
menu.__hide__();
menu.Hide();
// - removing Tabs from TDI
//nop (see CTdiTemplate)
}
Expand Down
2 changes: 1 addition & 1 deletion Main/src/Dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@

CFileManagerView *const pFileManager;
const PCSide sideMap; // how Heads map to Side numbers (Head->Side)
const CMainWindow::TDynMenu menu;
const CMainWindow::CDynMenu menu;
TFormat formatBoot; // information on Medium Format retrieved from Boot; this information has ALWAYS priority if handling the disk; changes in this structure must be projected back to Boot Sector using FlushToBootSector (e.g. called automatically by BootView)

virtual ~CDos();
Expand Down
28 changes: 14 additions & 14 deletions Main/src/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#include "stdafx.h"

CMainWindow::TDynMenu::TDynMenu(UINT nResId)
CMainWindow::CDynMenu::CDynMenu(UINT nResId)
// ctor
: hMenu( ::LoadMenu(AfxGetInstanceHandle(),(LPCTSTR)nResId) )
, hAccel( ::LoadAccelerators(AfxGetInstanceHandle(),(LPCTSTR)nResId) ) {
: hAccel( ::LoadAccelerators(AfxGetInstanceHandle(),(LPCTSTR)nResId) ) {
if (nResId!=0)
LoadMenu(nResId);
}
CMainWindow::TDynMenu::~TDynMenu(){
CMainWindow::CDynMenu::~CDynMenu(){
// dtor
::DestroyAcceleratorTable(hAccel);
::DestroyMenu(hMenu);
}

void CMainWindow::TDynMenu::__show__(UINT position) const{
void CMainWindow::CDynMenu::Show(UINT position) const{
// shows this Menu in MainWindow's menu
if (hMenu){ // may not if the MainWindow is being closed
if (m_hMenu){ // may not if the MainWindow is being closed
TCHAR buf[30];
::GetMenuString(hMenu,0,buf,sizeof(buf)/sizeof(TCHAR),MF_BYPOSITION);
::GetMenuString(m_hMenu,0,buf,sizeof(buf)/sizeof(TCHAR),MF_BYPOSITION);
app.m_pMainWnd->GetMenu()->InsertMenu( position,
MF_BYPOSITION | MF_POPUP,
(UINT)::GetSubMenu(hMenu,0),
(UINT)::GetSubMenu(m_hMenu,0),
buf
);
app.m_pMainWnd->DrawMenuBar();
}
}
void CMainWindow::TDynMenu::__hide__() const{
void CMainWindow::CDynMenu::Hide() const{
// removes this Menu from MainWindow's menu
if (hMenu && app.m_pMainWnd){ // may not if the MainWindow is being closed
app.m_pMainWnd->GetMenu()->RemoveMenu( (UINT)::GetSubMenu(hMenu,0), MF_BYCOMMAND|MF_POPUP );
if (m_hMenu && app.m_pMainWnd){ // may not if the MainWindow is being closed
app.m_pMainWnd->GetMenu()->RemoveMenu( (UINT)::GetSubMenu(m_hMenu,0), MF_BYCOMMAND|MF_POPUP );
app.m_pMainWnd->DrawMenuBar();
}
}
Expand All @@ -48,7 +48,7 @@
}
}

void CMainWindow::CDockableToolBar::__show__(const CToolBar &rDockNextTo){
void CMainWindow::CDockableToolBar::Show(const CToolBar &rDockNextTo){
// shows this ToolBar docked immediately next to the specified existing one
if (m_hWnd && rDockNextTo.m_hWnd){ // only if both ToolBars exist (may not if the MainWindow is being closed)
RECT r;
Expand All @@ -60,7 +60,7 @@
}
}

void CMainWindow::CDockableToolBar::__hide__(){
void CMainWindow::CDockableToolBar::Hide(){
// hides this Toolbar
if (m_hWnd) // this ToolBar is destroyed automatically when the MainWindow is being closed
( (CMainWindow *)app.m_pMainWnd )->ShowControlBar(this,FALSE,FALSE);
Expand Down
17 changes: 8 additions & 9 deletions Main/src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
afx_msg void __openUrl_tutorials__();
afx_msg void __openUrl_credits__();
public:
struct TDynMenu sealed{
const HMENU hMenu;
struct CDynMenu:public CMenu{
const HACCEL hAccel;

TDynMenu(UINT nResId);
~TDynMenu();
CDynMenu(UINT nResId);
~CDynMenu();
public:
void __show__(UINT position) const;
void __hide__() const;
void Show(UINT position) const;
void Hide() const;
};

class CDockableToolBar sealed:public CToolBar{
void OnUpdateCmdUI(CFrameWnd* pTarget,BOOL bDisableIfNoHndler) override;
public:
CDockableToolBar(UINT nResId,UINT id);

void __show__(const CToolBar &rDockNextTo);
void __hide__();
void Show(const CToolBar &rDockNextTo);
void Hide();
};

class CTdiTemplate sealed:public CSingleDocTemplate{
Expand All @@ -70,7 +69,7 @@

typedef struct TTab sealed{
const PDos dos; // DOS that gets into focus when switched to this Tab (e.g. CSpectrumDos::CTape)
const TDynMenu menu;
const CDynMenu menu;
const PView view;
CDockableToolBar toolbar;
TTab(UINT nMenuResId,UINT nToolbarResId,UINT nToolBarId,PDos _dos,PView _view); // ctor
Expand Down
2 changes: 1 addition & 1 deletion Main/src/SpectrumDos.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
};

class CBasicPreview sealed:public CAssemblerPreview{
const CMainWindow::TDynMenu machineCodeMenu;
const CMainWindow::CDynMenu machineCodeMenu;
union{
BYTE info;
struct{
Expand Down
4 changes: 2 additions & 2 deletions Main/src/SpectrumDos_BasicPreview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ errorInBasic:listing << _T("<p style=\"color:red\">Error in BASIC file structure
}else
SetWindowText(PREVIEW_LABEL);
// - hiding/displaying additional menus
GetMenu()->RemoveMenu( (UINT)::GetSubMenu(machineCodeMenu.hMenu,0), MF_BYCOMMAND|MF_POPUP );
GetMenu()->RemoveMenu( (UINT)::GetSubMenu(machineCodeMenu.m_hMenu,0), MF_BYCOMMAND|MF_POPUP );
if (dataAfterBasic==TDataAfterBasic::SHOW_AS_MACHINE_CODE || features.showRemAsMachineCode)
GetMenu()->InsertMenu( 1,
MF_BYPOSITION | MF_POPUP,
(UINT)::GetSubMenu(machineCodeMenu.hMenu,0),
(UINT)::GetSubMenu(machineCodeMenu.m_hMenu,0),
_T("Machine code")
);
// - refreshing the non-client area (TODO: why?)
Expand Down
4 changes: 2 additions & 2 deletions Main/src/SpectrumDos_Tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,11 @@ error: Utils::Information(_T("The tape is corrupted."));
if (const LRESULT err=__super::WindowProc(msg,wParam,lParam))
return err;
// . showing the Tape's ToolBar "after" the TapeFileManager's ToolBar
toolbar.__show__( tab.toolbar );
toolbar.Show( tab.toolbar );
return 0;
case WM_DESTROY:
// TapeFileManager destroyed - hiding the Tape's ToolBar
toolbar.__hide__();
toolbar.Hide();
break;
}
return __super::WindowProc(msg,wParam,lParam);
Expand Down
20 changes: 10 additions & 10 deletions Main/src/TdiView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,20 @@
const PView view=tab->view;
// - showing the Menus associated with the DOS and View
if (IS_TAB_PART_OF_DOS(tab)){ // the Tab is part of a DOS (e.g. a WebPage is usually not part of any DOS)
CImage::GetActive()->dos->menu.__show__(MENU_POSITION_DOS);
tab->menu.__show__(MENU_POSITION_VIEW);
CImage::GetActive()->dos->menu.Show(MENU_POSITION_DOS);
tab->menu.Show(MENU_POSITION_VIEW);
}else
tab->menu.__show__(MENU_POSITION_DOS); // showing the View's Menu at the DOS's position
tab->menu.Show(MENU_POSITION_DOS); // showing the View's Menu at the DOS's position
// - showing Image's ToolBar (guaranteed that the Toolbar always exists)
CMainWindow *const pMainWindow=(CMainWindow *)app.m_pMainWnd;
if (IS_TAB_PART_OF_DOS(tab)){ // the Tab is part of a DOS (e.g. a WebPage is usually not part of any DOS)
tab->dos->image->toolbar.__show__(pMainWindow->toolbar);
tab->dos->image->toolbar.Show(pMainWindow->toolbar);
}
// - showing the Tab's ToolBar (e.g. the FileManager's ToolBar)
if (IS_TAB_PART_OF_DOS(tab)) // the Tab is part of a DOS (e.g. a WebPage is usually not part of any DOS)
tab->toolbar.__show__( tab->dos->image->toolbar );
tab->toolbar.Show( tab->dos->image->toolbar );
else
tab->toolbar.__show__( pMainWindow->toolbar );
tab->toolbar.Show( pMainWindow->toolbar );
// - showing the associated View
__setStatusBarText__(nullptr); // StatusBar without text
RECT r;
Expand Down Expand Up @@ -374,14 +374,14 @@
image->RemoveView(view); // View added into the list when shown, see CCreateContext
::DestroyWindow( view->m_hWnd );
// - hiding the Tab's ToolBar (e.g. the FileManager's ToolBar)
tab->toolbar.__hide__();
tab->toolbar.Hide();
// - hiding the Image's ToolBar (guaranteed that the Toolbar always exists)
if (IS_TAB_PART_OF_DOS(tab))
tab->dos->image->toolbar.__hide__();
tab->dos->image->toolbar.Hide();
// - hiding the Menus associated with the DOS and View
tab->menu.__hide__();
tab->menu.Hide();
if (IS_TAB_PART_OF_DOS(tab))
CImage::GetActive()->dos->menu.__hide__();
CImage::GetActive()->dos->menu.Hide();
// - resetting the StatusBar
__resetStatusBar__();
// - displaying the introductory GuidePost if this was the last Tab in the TDI
Expand Down

0 comments on commit 4252bda

Please sign in to comment.