From: <sv...@op...> - 2024-04-09 18:04:17
|
Author: sagamusix Date: Tue Apr 9 20:04:10 2024 New Revision: 20545 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20545 Log: [Imp] Comments tab: Sample / instrument names are now drawn using the Comments font, which is typically a fixed-width font (https://bugs.openmpt.org/view.php?id=1758). Modified: trunk/OpenMPT/mptrack/view_com.cpp trunk/OpenMPT/mptrack/view_com.h Modified: trunk/OpenMPT/mptrack/view_com.cpp ============================================================================== --- trunk/OpenMPT/mptrack/view_com.cpp Tue Apr 9 19:08:36 2024 (r20544) +++ trunk/OpenMPT/mptrack/view_com.cpp Tue Apr 9 20:04:10 2024 (r20545) @@ -58,24 +58,24 @@ static constexpr CListCtrlEx::Header SampleHeaders[SMPLIST_COLUMNS] = { - { _T("Sample Name"), 192, LVCFMT_LEFT }, - { _T("Num"), 45, LVCFMT_RIGHT }, - { _T("Size"), 72, LVCFMT_RIGHT }, - { _T("Type"), 80, LVCFMT_RIGHT }, - { _T("C-5 Freq"), 80, LVCFMT_RIGHT }, - { _T("Instr"), 64, LVCFMT_RIGHT }, - { _T("File Name"), 128, LVCFMT_RIGHT }, - { _T("Path"), 256, LVCFMT_LEFT }, + { _T("Sample Name"), 208, LVCFMT_LEFT }, + { _T("Num"), 45, LVCFMT_RIGHT }, + { _T("Size"), 72, LVCFMT_RIGHT }, + { _T("Type"), 80, LVCFMT_RIGHT }, + { _T("C-5 Freq"), 80, LVCFMT_RIGHT }, + { _T("Instr"), 64, LVCFMT_RIGHT }, + { _T("File Name"), 128, LVCFMT_RIGHT }, + { _T("Path"), 256, LVCFMT_LEFT }, }; static constexpr CListCtrlEx::Header InstrumentHeaders[INSLIST_COLUMNS] = { - { _T("Instrument Name"), 192, LVCFMT_LEFT }, - { _T("Num"), 45, LVCFMT_RIGHT }, - { _T("Samples"), 64, LVCFMT_RIGHT }, - { _T("Envelopes"), 128, LVCFMT_RIGHT }, - { _T("File Name"), 128, LVCFMT_RIGHT }, - { _T("Plugin"), 128, LVCFMT_RIGHT }, + { _T("Instrument Name"), 208, LVCFMT_LEFT }, + { _T("Num"), 45, LVCFMT_RIGHT }, + { _T("Samples"), 64, LVCFMT_RIGHT }, + { _T("Envelopes"), 128, LVCFMT_RIGHT }, + { _T("File Name"), 128, LVCFMT_RIGHT }, + { _T("Plugin"), 128, LVCFMT_RIGHT }, }; @@ -95,6 +95,7 @@ ON_NOTIFY(LVN_BEGINLABELEDIT, IDC_LIST_DETAILS, &CViewComments::OnBeginLabelEdit) ON_NOTIFY(NM_DBLCLK, IDC_LIST_DETAILS, &CViewComments::OnDblClickListItem) ON_NOTIFY(NM_RCLICK, IDC_LIST_DETAILS, &CViewComments::OnRClickListItem) + ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST_DETAILS, &CViewComments::OnCustomDrawList) //}}AFX_MSG_MAP END_MESSAGE_MAP() @@ -130,13 +131,14 @@ m_ToolBar.Init(CMainFrame::GetMainFrame()->m_MiscIcons, CMainFrame::GetMainFrame()->m_MiscIconsDisabled); m_ItemList.Create(WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL | LVS_EDITLABELS | LVS_NOSORTHEADER, rect, this, IDC_LIST_DETAILS); m_ItemList.ModifyStyleEx(0, WS_EX_STATICEDGE); + // Add ToolBar Buttons m_ToolBar.AddButton(IDC_LIST_SAMPLES, IMAGE_SAMPLES); m_ToolBar.AddButton(IDC_LIST_INSTRUMENTS, IMAGE_INSTRUMENTS); //m_ToolBar.AddButton(IDC_LIST_PATTERNS, TIMAGE_TAB_PATTERNS); m_ToolBar.SetIndent(4); UpdateButtonState(); - UpdateView(UpdateHint().ModType()); + UpdateView(UpdateHint().ModType().MPTOptions()); } @@ -153,6 +155,7 @@ commentState.initialized = true; commentState.nId = m_nListId; } + m_fixedFont.DeleteObject(); CModScrollView::OnDestroy(); } @@ -293,6 +296,16 @@ if (hintType[HINT_MPTOPTIONS]) { m_ToolBar.UpdateStyle(); + + // Font for sample / instrument names + CFont *font = m_ItemList.GetFont(); + LOGFONT lf; + font->GetLogFont(&lf); + mpt::WriteWinBuf(lf.lfFaceName) = mpt::ToWin(TrackerSettings::Instance().commentsFont.Get().name); + m_fixedFont.DeleteObject(); + m_fixedFont.CreateFontIndirect(&lf); + + m_ItemList.Invalidate(FALSE); } const SampleHint sampleHint = hint.ToType<SampleHint>(); const InstrumentHint instrHint = hint.ToType<InstrumentHint>(); @@ -555,8 +568,8 @@ void CViewComments::OnEndLabelEdit(LPNMHDR pnmhdr, LRESULT *) { CMainFrame::GetInputHandler()->Bypass(false); - LV_DISPINFO *plvDispInfo = (LV_DISPINFO *)pnmhdr; - LV_ITEM &lvItem = plvDispInfo->item; + LV_DISPINFO &lvDispInfo = *reinterpret_cast<LV_DISPINFO *>(pnmhdr); + LV_ITEM &lvItem = lvDispInfo.item; CModDoc *pModDoc = GetDocument(); if(lvItem.pszText != nullptr && !lvItem.iSubItem && pModDoc) @@ -672,6 +685,37 @@ } +void CViewComments::OnCustomDrawList(NMHDR *pNMHDR, LRESULT *pResult) +{ + const auto &lvcd = *reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR); + *pResult = CDRF_DODEFAULT; + + switch(lvcd.nmcd.dwDrawStage) + { + case CDDS_PREPAINT: + *pResult = CDRF_NOTIFYITEMDRAW; + break; + case CDDS_ITEMPREPAINT: + *pResult = CDRF_NOTIFYSUBITEMDRAW; + break; + case CDDS_ITEMPREPAINT | CDDS_SUBITEM: + if(lvcd.iSubItem == 0) + { + m_oldFont = SelectFont(lvcd.nmcd.hdc, m_fixedFont); + *pResult = CDRF_NEWFONT | CDRF_NOTIFYPOSTPAINT; + } + break; + case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM: + if(lvcd.iSubItem == 0) + { + SelectFont(lvcd.nmcd.hdc, m_oldFont); + *pResult = CDRF_NEWFONT; + } + break; + } +} + + void CViewComments::OnCopyNames() { std::wstring names; Modified: trunk/OpenMPT/mptrack/view_com.h ============================================================================== --- trunk/OpenMPT/mptrack/view_com.h Tue Apr 9 19:08:36 2024 (r20544) +++ trunk/OpenMPT/mptrack/view_com.h Tue Apr 9 20:04:10 2024 (r20545) @@ -28,6 +28,8 @@ protected: CModControlBar m_ToolBar; CListCtrlEx m_ItemList; + CFont m_fixedFont; + HFONT m_oldFont = nullptr; int m_nCurrentListId = 0, m_nListId = 0; ModCommand::NOTE m_lastNote = NOTE_NONE; CHANNELINDEX m_noteChannel = CHANNELINDEX_INVALID; @@ -59,6 +61,7 @@ afx_msg void OnBeginLabelEdit(LPNMHDR pnmhdr, LRESULT *pLResult); afx_msg void OnDblClickListItem(NMHDR *, LRESULT *); afx_msg void OnRClickListItem(NMHDR *, LRESULT *); + afx_msg void OnCustomDrawList(NMHDR *pNMHDR, LRESULT *pResult); afx_msg void OnCopyNames(); afx_msg LRESULT OnMidiMsg(WPARAM midiData, LPARAM); afx_msg LRESULT OnCustomKeyMsg(WPARAM, LPARAM); |