Skip to content

Commit

Permalink
[New] Tree view can now also be placed on the right side of the window.
Browse files Browse the repository at this point in the history
[Fix] In the main menu, the checkboxes for main toolbar readout visibility were not updated.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22181 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Nov 13, 2024
1 parent 549c84f commit 47579ab
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 57 deletions.
45 changes: 30 additions & 15 deletions mptrack/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_COMMAND(ID_MAINBAR_SHOW_ROWSPERBEAT, &CMainFrame::OnToggleMainBarShowRowsPerBeat)
ON_COMMAND(ID_MAINBAR_SHOW_GLOBALVOLUME, &CMainFrame::OnToggleMainBarShowGlobalVolume)
ON_COMMAND(ID_MAINBAR_SHOW_VUMETER, &CMainFrame::OnToggleMainBarShowVUMeter)
ON_COMMAND(ID_TREEVIEW_ON_LEFT, &CMainFrame::OnToggleTreeViewOnLeft)

#ifdef MPT_ENABLE_PLAYBACK_TEST_MENU
ON_COMMAND(ID_CREATE_MIXERDUMP, &CMainFrame::OnCreateMixerDump)
Expand Down Expand Up @@ -300,7 +301,7 @@ int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
EnableDocking(CBRS_ALIGN_ANY);
if (!m_wndToolBar.Create(this)) return -1;
if (!m_wndStatusBar.Create(this)) return -1;
if (!m_wndTree.Create(this, IDD_TREEVIEW, CBRS_LEFT|CBRS_BORDER_RIGHT, IDD_TREEVIEW)) return -1;
if (!m_wndTree.Create(this, IDD_TREEVIEW, TrackerSettings::Instance().treeViewOnLeft ? CBRS_LEFT : CBRS_RIGHT, IDD_TREEVIEW)) return -1;
m_wndStatusBar.SetIndicators(StatusBarIndicators, static_cast<int>(std::size(StatusBarIndicators)));
SetupStatusBarSizes();
m_wndToolBar.Init(this);
Expand Down Expand Up @@ -2545,6 +2546,7 @@ void CMainFrame::AddToolBarMenuEntries(CMenu &menu)
{
menu.AppendMenu(MF_STRING, ID_VIEW_TOOLBAR, m_InputHandler->GetMenuText(ID_VIEW_TOOLBAR));
menu.AppendMenu(MF_STRING, IDD_TREEVIEW, m_InputHandler->GetMenuText(IDD_TREEVIEW));
menu.AppendMenu(MF_STRING | (TrackerSettings::Instance().treeViewOnLeft ? MF_CHECKED : 0), ID_TREEVIEW_ON_LEFT, _T("Tree View on &Left"));

const FlagSet<MainToolBarItem> visibleItems = TrackerSettings::Instance().mainToolBarVisibleItems.Get();

Expand All @@ -2560,12 +2562,28 @@ void CMainFrame::AddToolBarMenuEntries(CMenu &menu)
}


void CMainFrame::OnToggleMainBarShowOctave() { m_wndToolBar.ToggleVisibility(MainToolBarItem::Octave); }
void CMainFrame::OnToggleMainBarShowTempo() { m_wndToolBar.ToggleVisibility(MainToolBarItem::Tempo); }
void CMainFrame::OnToggleMainBarShowSpeed() { m_wndToolBar.ToggleVisibility(MainToolBarItem::Speed); }
void CMainFrame::OnToggleMainBarShowRowsPerBeat() { m_wndToolBar.ToggleVisibility(MainToolBarItem::RowsPerBeat); }
void CMainFrame::OnToggleMainBarShowGlobalVolume() { m_wndToolBar.ToggleVisibility(MainToolBarItem::GlobalVolume); }
void CMainFrame::OnToggleMainBarShowVUMeter() { m_wndToolBar.ToggleVisibility(MainToolBarItem::VUMeter); }
void CMainFrame::OnToggleMainBarShowOctave() { OnToggleMainBarItem(MainToolBarItem::Octave, ID_MAINBAR_SHOW_OCTAVE); }
void CMainFrame::OnToggleMainBarShowTempo() { OnToggleMainBarItem(MainToolBarItem::Tempo, ID_MAINBAR_SHOW_TEMPO); }
void CMainFrame::OnToggleMainBarShowSpeed() { OnToggleMainBarItem(MainToolBarItem::Speed, ID_MAINBAR_SHOW_SPEED); }
void CMainFrame::OnToggleMainBarShowRowsPerBeat() { OnToggleMainBarItem(MainToolBarItem::RowsPerBeat, ID_MAINBAR_SHOW_ROWSPERBEAT); }
void CMainFrame::OnToggleMainBarShowGlobalVolume() { OnToggleMainBarItem(MainToolBarItem::GlobalVolume, ID_MAINBAR_SHOW_GLOBALVOLUME); }
void CMainFrame::OnToggleMainBarShowVUMeter() { OnToggleMainBarItem(MainToolBarItem::VUMeter, ID_MAINBAR_SHOW_VUMETER); }

void CMainFrame::OnToggleMainBarItem(MainToolBarItem item, UINT menuID)
{
const bool visible = m_wndToolBar.ToggleVisibility(item);
GetMenu()->CheckMenuItem(menuID, MF_BYCOMMAND | (visible ? MF_CHECKED : 0));
}


void CMainFrame::OnToggleTreeViewOnLeft()
{
const bool left = !TrackerSettings::Instance().treeViewOnLeft;
TrackerSettings::Instance().treeViewOnLeft = left;
m_wndTree.SetBarOnLeft(left);
RecalcLayout();
GetMenu()->CheckMenuItem(ID_TREEVIEW_ON_LEFT, MF_BYCOMMAND | (left ? MF_CHECKED : 0));
}


LRESULT CMainFrame::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
Expand Down Expand Up @@ -2635,14 +2653,11 @@ LRESULT CMainFrame::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
case kcSpeedIncrease:
case kcSpeedDecrease:
case kcViewToggle:
{
CModDoc *modDoc = GetActiveDoc();
if(modDoc)
return GetActiveDoc()->OnCustomKeyMsg(wParam, lParam);
else if(wParam == kcPlayPauseSong || wParam == kcPlayStopSong || wParam == kcStopSong)
StopPreview();
break;
}
if(CModDoc *modDoc = GetActiveDoc())
return modDoc->OnCustomKeyMsg(wParam, lParam);
else if(wParam == kcPlayPauseSong || wParam == kcPlayStopSong || wParam == kcStopSong)
StopPreview();
break;

case kcSwitchToInstrLibrary:
if(!m_wndTree.IsVisible())
Expand Down
121 changes: 81 additions & 40 deletions mptrack/Mainbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,13 @@ void CMainToolBar::UpdateControls()
}


void CMainToolBar::ToggleVisibility(MainToolBarItem item)
bool CMainToolBar::ToggleVisibility(MainToolBarItem item)
{
FlagSet<MainToolBarItem> visibleItems = TrackerSettings::Instance().mainToolBarVisibleItems.Get();
visibleItems.flip(item);
TrackerSettings::Instance().mainToolBarVisibleItems = visibleItems.value().as_enum();
RefreshToolbar();
return visibleItems[item];
}


Expand Down Expand Up @@ -1091,8 +1092,10 @@ CSize CModTreeBar::CalcFixedLayout(BOOL, BOOL)
CSize sz;
m_sizeDefault.cx = width;
m_sizeDefault.cy = 32767;
sz.cx = width + TREEVIEW_PADDING;
if(sz.cx < 4) sz.cx = 4;
const int padding = TREEVIEW_PADDING;
sz.cx = width + padding;
if(sz.cx < padding + 1)
sz.cx = padding + 1;
sz.cy = 32767;
return sz;
}
Expand All @@ -1101,6 +1104,7 @@ CSize CModTreeBar::CalcFixedLayout(BOOL, BOOL)
void CModTreeBar::DoMouseMove(CPoint pt)
{
CRect rect;
GetClientRect(&rect);

if((m_dwStatus & (MTB_CAPTURE|MTB_DRAGGING)) && (::GetCapture() != m_hWnd))
{
Expand All @@ -1112,27 +1116,32 @@ void CModTreeBar::DoMouseMove(CPoint pt)
{
if(m_pModTree)
{
m_pModTree->GetWindowRect(&rect);
pt.y += rect.Height();
CRect windowRect;
m_pModTree->GetWindowRect(&windowRect);
pt.y += windowRect.Height();
}
GetClientRect(&rect);
pt.y -= ptDragging.y;
if(pt.y < 0) pt.y = 0;
if(pt.y > rect.Height()) pt.y = rect.Height();
if((!(m_dwStatus & MTB_TRACKER)) || (pt.y != (int)m_nTrackPos))
pt.y = std::clamp(static_cast<int>(pt.y), 0, rect.Height());
if((!(m_dwStatus & MTB_TRACKER)) || (pt.y != static_cast<int>(m_nTrackPos)))
{
if(m_dwStatus & MTB_TRACKER) OnInvertTracker(m_nTrackPos);
if(m_dwStatus & MTB_TRACKER)
OnInvertTracker(m_nTrackPos);
m_nTrackPos = pt.y;
OnInvertTracker(m_nTrackPos);
m_dwStatus |= MTB_TRACKER;
}
} else
{
pt.x -= ptDragging.x - m_cxOriginal + TREEVIEW_PADDING;
if(pt.x < 0) pt.x = 0;
if((!(m_dwStatus & MTB_TRACKER)) || (pt.x != (int)m_nTrackPos))
pt.x -= ptDragging.x;
if(BarOnLeft())
pt.x += (m_cxOriginal - TREEVIEW_PADDING);
else
pt.x = m_cxOriginal - pt.x;
pt.x = std::max(pt.x, LONG(0));
if((!(m_dwStatus & MTB_TRACKER)) || (pt.x != static_cast<int>(m_nTrackPos)))
{
if(m_dwStatus & MTB_TRACKER) OnInvertTracker(m_nTrackPos);
if(m_dwStatus & MTB_TRACKER)
OnInvertTracker(m_nTrackPos);
m_nTrackPos = pt.x;
OnInvertTracker(m_nTrackPos);
m_dwStatus |= MTB_TRACKER;
Expand All @@ -1142,9 +1151,17 @@ void CModTreeBar::DoMouseMove(CPoint pt)
{
UINT nCursor = 0;

GetClientRect(&rect);
rect.left = rect.right - 2;
rect.right = rect.left + 5;
const int padding = TREEVIEW_PADDING;
const int extraPadding = HighDPISupport::ScalePixels(2, m_hWnd);
if(BarOnLeft())
{
rect.left = rect.right - extraPadding;
rect.right = rect.left + padding + extraPadding;
} else
{
rect.left -= extraPadding;
rect.right = rect.left + padding + extraPadding;
}
if(rect.PtInRect(pt))
{
nCursor = AFX_IDC_HSPLITBAR;
Expand All @@ -1154,8 +1171,8 @@ void CModTreeBar::DoMouseMove(CPoint pt)
m_pModTree->GetWindowRect(&rect);
rect.right = rect.Width();
rect.left = 0;
rect.top = rect.Height()-1;
rect.bottom = rect.top + 5;
rect.top = rect.Height() - extraPadding;
rect.bottom = rect.top + padding + extraPadding;
if(rect.PtInRect(pt))
{
nCursor = AFX_IDC_VSPLITBAR;
Expand All @@ -1164,19 +1181,21 @@ void CModTreeBar::DoMouseMove(CPoint pt)
if(nCursor)
{
UINT nDir = (nCursor == AFX_IDC_VSPLITBAR) ? MTB_VERTICAL : 0;
BOOL bLoad = FALSE;
bool load = false;
if(!(m_dwStatus & MTB_CAPTURE))
{
m_dwStatus |= MTB_CAPTURE;
SetCapture();
bLoad = TRUE;
load = true;
} else
{
if(nDir != (m_dwStatus & MTB_VERTICAL)) bLoad = TRUE;
if(nDir != (m_dwStatus & MTB_VERTICAL))
load = true;
}
m_dwStatus &= ~MTB_VERTICAL;
m_dwStatus |= nDir;
if(bLoad) SetCursor(theApp.LoadCursor(nCursor));
if(load)
SetCursor(theApp.LoadCursor(nCursor));
} else
{
if(m_dwStatus & MTB_CAPTURE)
Expand Down Expand Up @@ -1222,18 +1241,18 @@ void CModTreeBar::DoLButtonUp()
{
GetClientRect(&rect);
int cyavail = rect.Height() - padding;
if(cyavail < 4) cyavail = 4;
int ratio = (m_nTrackPos << 8) / cyavail;
if(ratio < 0) ratio = 0;
if(ratio > 256) ratio = 256;
if(cyavail < padding + 1)
cyavail = padding + 1;
int ratio = std::clamp(static_cast<int>(m_nTrackPos * 256) / cyavail, 0, 256);
m_nTreeSplitRatio = ratio;
TrackerSettings::Instance().glTreeSplitRatio = ratio;
RecalcLayout();
} else
{
GetWindowRect(&rect);
m_nTrackPos += padding;
if(m_nTrackPos < 4) m_nTrackPos = 4;
if(m_nTrackPos < static_cast<UINT>(padding + 1))
m_nTrackPos = padding + 1;
CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
if((m_nTrackPos != (UINT)rect.Width()) && (pMainFrm))
{
Expand Down Expand Up @@ -1272,14 +1291,18 @@ void CModTreeBar::OnInvertTracker(UINT x)
CRect rect;

GetClientRect(&rect);
const int padding = TREEVIEW_PADDING + 1;
if(m_dwStatus & MTB_VERTICAL)
{
rect.top = x;
rect.bottom = rect.top + 4;
rect.bottom = rect.top + padding;
} else
{
rect.left = x;
rect.right = rect.left + 4;
if(BarOnLeft())
rect.left = x;
else
rect.left = rect.right - x;
rect.right = rect.left + padding;
}
ClientToScreen(&rect);
pMainFrm->ScreenToClient(&rect);
Expand All @@ -1288,11 +1311,11 @@ void CModTreeBar::OnInvertTracker(UINT x)
CDC* pDC = pMainFrm->GetDC();
// invert the brush pattern (looks just like frame window sizing)
CBrush* pBrush = CDC::GetHalftoneBrush();
HBRUSH hOldBrush = NULL;
if(pBrush != NULL)
HBRUSH hOldBrush = nullptr;
if(pBrush != nullptr)
hOldBrush = (HBRUSH)SelectObject(pDC->m_hDC, pBrush->m_hObject);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
if(hOldBrush != NULL)
if(hOldBrush != nullptr)
SelectObject(pDC->m_hDC, hOldBrush);
ReleaseDC(pDC);
}
Expand Down Expand Up @@ -1323,6 +1346,13 @@ void CModTreeBar::UpdatePlayPos(CModDoc *pModDoc, Notification *pNotify)
}


void CModTreeBar::SetBarOnLeft(const bool left)
{
SetBarStyle(left ? CBRS_LEFT : CBRS_RIGHT);
SetWindowPos(nullptr, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_DRAWFRAME);
}


////////////////////////////////////////////////////////////////////////////////////////////////////
// CModTreeBar message handlers

Expand All @@ -1331,8 +1361,11 @@ void CModTreeBar::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
CDialogBar::OnNcCalcSize(bCalcValidRects, lpncsp);
if(lpncsp)
{
lpncsp->rgrc[0].right -= TREEVIEW_PADDING;
if(lpncsp->rgrc[0].right < lpncsp->rgrc[0].left) lpncsp->rgrc[0].right = lpncsp->rgrc[0].left;
if(BarOnLeft())
lpncsp->rgrc[0].right -= TREEVIEW_PADDING;
else
lpncsp->rgrc[0].left += TREEVIEW_PADDING;
lpncsp->rgrc[0].right = std::max(lpncsp->rgrc[0].left, lpncsp->rgrc[0].right);
}
}

Expand All @@ -1342,9 +1375,13 @@ LRESULT CModTreeBar::OnNcHitTest(CPoint point)
CRect rect;

GetWindowRect(&rect);
rect.DeflateRect(1,1);
rect.right -= TREEVIEW_PADDING;
if(!rect.PtInRect(point)) return HTBORDER;
rect.DeflateRect(1, 1);
if(BarOnLeft())
rect.right -= TREEVIEW_PADDING;
else
rect.left += TREEVIEW_PADDING;
if(!rect.PtInRect(point))
return HTBORDER;
return CDialogBar::OnNcHitTest(point);
}

Expand All @@ -1358,8 +1395,12 @@ void CModTreeBar::OnNcPaint()
// Assumes there is no other non-client items
rect.right -= rect.left;
rect.bottom -= rect.top;
rect.left = 0;
rect.top = 0;
rect.left = rect.right - TREEVIEW_PADDING;
if(BarOnLeft())
rect.left = rect.right - TREEVIEW_PADDING;
else
rect.right = rect.left + TREEVIEW_PADDING;
if((rect.left < rect.right) && (rect.top < rect.bottom))
{
CDC *pDC = GetWindowDC();
Expand Down
5 changes: 4 additions & 1 deletion mptrack/Mainbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class CMainToolBar: public CToolBarEx
bool ShowUpdateInfo(const CString &newVersion, const CString &infoURL, bool showHighLight);
void RemoveUpdateInfo();

void ToggleVisibility(MainToolBarItem item);
bool ToggleVisibility(MainToolBarItem item);

protected:
void RefreshToolbar();
Expand Down Expand Up @@ -196,6 +196,9 @@ class CModTreeBar: public CDialogBar

void StartTreeFilter(CModTree &source);

void SetBarOnLeft(const bool left);
bool BarOnLeft() { return (GetBarStyle() & CBRS_ALIGN_LEFT); }

protected:
//{{AFX_VIRTUAL(CModTreeBar)
CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz) override;
Expand Down
5 changes: 4 additions & 1 deletion mptrack/Mainfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CModDoc;
struct UpdateCheckResult;
struct UpdateHint;
struct MODPLUGDIB;
enum class MainToolBarItem : uint8;
enum SoundDeviceStopMode : int;
namespace SoundDevice {
class Base;
Expand Down Expand Up @@ -253,7 +254,7 @@ class CMainFrame
void SetMidiRecordWnd(HWND hwnd) { m_hWndMidi = hwnd; }
HWND GetMidiRecordWnd() const { return m_hWndMidi; }

static int ApplyVolumeRelatedSettings(const DWORD &dwParam1, const BYTE midivolume);
static int ApplyVolumeRelatedSettings(const DWORD &dwParam1, const uint8 midivolume);

// static functions
public:
Expand Down Expand Up @@ -453,6 +454,8 @@ class CMainFrame
afx_msg void OnToggleMainBarShowRowsPerBeat();
afx_msg void OnToggleMainBarShowGlobalVolume();
afx_msg void OnToggleMainBarShowVUMeter();
afx_msg void OnToggleMainBarItem(MainToolBarItem item, UINT menuID);
afx_msg void OnToggleTreeViewOnLeft();

afx_msg void OnCreateMixerDump();
afx_msg void OnVerifyMixerDump();
Expand Down
1 change: 1 addition & 0 deletions mptrack/TrackerSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ TrackerSettings::TrackerSettings(SettingsContainer &conf)
, defaultRainbowChannelColors(conf, UL_("Display"), UL_("DefaultChannelColors"), DefaultChannelColors::Random)
, commentsFont(conf, UL_("Display"), UL_("Comments Font"), FontSetting(UL_("Courier New"), 120))
, mainToolBarVisibleItems(conf, UL_("Display"), UL_("MainToolBarVisibleItems"), MainToolBarItem::Default)
, treeViewOnLeft(conf, UL_("Display"), UL_("TreeViewOnLeft"), true)
// Misc
, defaultModType(conf, UL_("Misc"), UL_("DefaultModType"), MOD_TYPE_IT)
, defaultNewFileAction(conf, UL_("Misc"), UL_("DefaultNewFileAction"), nfDefaultFormat)
Expand Down
1 change: 1 addition & 0 deletions mptrack/TrackerSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,7 @@ class TrackerSettings
Setting<FontSetting> commentsFont;

Setting<MainToolBarItem> mainToolBarVisibleItems;
Setting<bool> treeViewOnLeft;

// Misc

Expand Down
Loading

0 comments on commit 47579ab

Please sign in to comment.