Skip to content

Commit

Permalink
[Mod] Implement custom context menu key handling through regular keyb…
Browse files Browse the repository at this point in the history
…oard handling instead of special-casing it everywhere.

[Mod] In addition to the Application key, custom context menu key handling now adds Shift+F10 as a default shortcut, which is what Windows uses by default as a substitute for keyboards without an Application key (https://bugs.openmpt.org/view.php?id=1815).
[Mod] Invert logic when to skip new default keyboard shortcuts: If the conflicting existing shortcut is in a more specific context, the new shortcut is added because it will be ignored anyway.
[Mod] OpenMPT: Version is now 1.32.00.25

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@21624 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
sagamusix committed Sep 19, 2024
1 parent 406d7b5 commit 6ecf80c
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 137 deletions.
2 changes: 1 addition & 1 deletion common/versionNumber.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
#define VER_MAJORMAJOR 1
#define VER_MAJOR 32
#define VER_MINOR 00
#define VER_MINORMINOR 24
#define VER_MINORMINOR 25
7 changes: 5 additions & 2 deletions mptrack/CommandSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ constexpr struct
{kcViewMIDImapping, VK_F3, ModCtrl, kKeyEventDown, kCtxAllContexts, MPT_V("1.31")},
{kcSwitchToInstrLibrary, 'I', ModAlt, kKeyEventDown | kKeyEventRepeat, kCtxAllContexts, MPT_V("1.31")},
{kcHelp, VK_F1, ModNone, kKeyEventDown, kCtxAllContexts, MPT_V("1.31")},
{kcContextMenu, VK_APPS, ModNone, kKeyEventDown, kCtxAllContexts, MPT_V("1.32.00.25")},
{kcContextMenu, VK_F10, ModShift, kKeyEventDown, kCtxAllContexts, MPT_V("1.32.00.25")},
{kcPrevInstrument, VK_DIVIDE, ModCtrl, kKeyEventDown | kKeyEventRepeat, kCtxAllContexts, MPT_V("1.31")},
{kcPrevInstrument, VK_UP, ModCtrl, kKeyEventDown | kKeyEventRepeat, kCtxAllContexts, MPT_V("1.31")},
{kcNextInstrument, VK_MULTIPLY, ModCtrl, kKeyEventDown | kKeyEventRepeat, kCtxAllContexts, MPT_V("1.31")},
Expand Down Expand Up @@ -1390,6 +1392,7 @@ static constexpr struct
{2098, kcGotoVolumeColumn, _T("Go to volume effect column")},
{2099, kcGotoCommandColumn, _T("Go to effect command column")},
{2100, kcGotoParamColumn, _T("Go to effect parameter column")},
{2101, kcContextMenu, _T("Open Context Menu")},
};
// clang-format on

Expand Down Expand Up @@ -2387,10 +2390,10 @@ void CCommandSet::ApplyDefaultKeybindings(const Version onlyCommandsAfterVersion

if(auto conflictCmd = IsConflicting(kc, kb.cmd, false); conflictCmd.first != kcNull)
{
// Allow cross-context conflicts in case the newly added shortcut is in a more specific context
// Allow cross-context conflicts in case the newly added shortcut is in a more generic context
// - unless the conflicting shortcut is the reserved dummy shortcut (which was used to prevent
// default shortcuts from being added back before default key binding versioning was added).
if(conflictCmd.first == kcDummyShortcut || !m_isParentContext[conflictCmd.second.Context()][kb.ctx])
if(conflictCmd.first == kcDummyShortcut || !m_isParentContext[kb.ctx][conflictCmd.second.Context()])
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion mptrack/CommandSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ enum CommandID
kcEndView = kcHelp,

kcStartMisc,
kcPrevInstrument = kcStartMisc,
kcContextMenu = kcStartMisc,
kcPrevInstrument,
kcNextInstrument,
kcPrevOctave,
kcNextOctave,
Expand Down
69 changes: 31 additions & 38 deletions mptrack/Ctrl_ins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,55 +71,42 @@ END_MESSAGE_MAP()

BOOL CNoteMapWnd::PreTranslateMessage(MSG *pMsg)
{
if(!pMsg)
return TRUE;
uint32 wParam = static_cast<uint32>(pMsg->wParam);

//We handle keypresses before Windows has a chance to handle them (for alt etc..)
if ((pMsg->message == WM_SYSKEYUP) || (pMsg->message == WM_KEYUP) ||
(pMsg->message == WM_SYSKEYDOWN) || (pMsg->message == WM_KEYDOWN))
{
//We handle keypresses before Windows has a chance to handle them (for alt etc..)
if ((pMsg->message == WM_SYSKEYUP) || (pMsg->message == WM_KEYUP) ||
(pMsg->message == WM_SYSKEYDOWN) || (pMsg->message == WM_KEYDOWN))
{
CInputHandler *ih = CMainFrame::GetInputHandler();
const auto event = ih->Translate(*pMsg);
CInputHandler *ih = CMainFrame::GetInputHandler();
const auto event = ih->Translate(*pMsg);

if (ih->KeyEvent(kCtxInsNoteMap, event) != kcNull)
return true; // Mapped to a command, no need to pass message on.
if (ih->KeyEvent(kCtxInsNoteMap, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.

// a bit of a hack...
if (ih->KeyEvent(kCtxCtrlInstruments, event) != kcNull)
return true; // Mapped to a command, no need to pass message on.
}
// a bit of a hack...
if (ih->KeyEvent(kCtxCtrlInstruments, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.

// For context menu shortcut
if(ih->KeyEvent(kCtxAllContexts, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.
}

//The key was not handled by a command, but it might still be useful
if (pMsg->message == WM_CHAR) //key is a character
uint32 wParam = static_cast<uint32>(pMsg->wParam);
if(pMsg->message == WM_CHAR && CInputHandler::GetKeyEventType(*pMsg) == kKeyEventDown) // Key is a character
{
if(CInputHandler::GetKeyEventType(*pMsg) == kKeyEventDown)
if(HandleChar(wParam))
return true;
}
else if (pMsg->message == WM_KEYDOWN) //key is not a character
if(HandleChar(wParam))
return TRUE;
} else if(pMsg->message == WM_KEYDOWN) // Key is not a character
{
if(HandleNav(wParam))
return true;

// Handle Application (menu) key
if(wParam == VK_APPS)
{
CRect clientRect;
GetClientRect(clientRect);
clientRect.bottom = clientRect.top + mpt::align_up(clientRect.Height(), m_cyFont);
OnRButtonDown(0, clientRect.CenterPoint());
}
}
else if (pMsg->message == WM_KEYUP) //stop notes on key release
return TRUE;
} else if(pMsg->message == WM_KEYUP) // Stop notes on key release
{
if (((pMsg->wParam >= '0') && (pMsg->wParam <= '9')) || (pMsg->wParam == ' ') ||
if(((pMsg->wParam >= '0') && (pMsg->wParam <= '9')) || (pMsg->wParam == ' ') ||
((pMsg->wParam >= VK_NUMPAD0) && (pMsg->wParam <= VK_NUMPAD9)))
{
StopNote();
return true;
return TRUE;
}
}

Expand Down Expand Up @@ -272,7 +259,6 @@ void CNoteMapWnd::OnSetFocus(CWnd *pOldWnd)
{
CStatic::OnSetFocus(pOldWnd);
Invalidate(FALSE);
CMainFrame::GetMainFrame()->m_pNoteMapHasFocus = this;
m_undo = true;
}

Expand All @@ -281,7 +267,6 @@ void CNoteMapWnd::OnKillFocus(CWnd *pNewWnd)
{
CStatic::OnKillFocus(pNewWnd);
Invalidate(FALSE);
CMainFrame::GetMainFrame()->m_pNoteMapHasFocus = nullptr;
}


Expand Down Expand Up @@ -615,6 +600,14 @@ LRESULT CNoteMapWnd::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)

switch(wParam)
{
case kcContextMenu:
{
CRect clientRect;
GetClientRect(clientRect);
clientRect.bottom = clientRect.top + mpt::align_up(clientRect.Height(), m_cyFont);
OnRButtonDown(0, clientRect.CenterPoint());
}
return wParam;
case kcInsNoteMapTransposeDown: MapTranspose(-1); return wParam;
case kcInsNoteMapTransposeUp: MapTranspose(1); return wParam;
case kcInsNoteMapTransposeOctDown: MapTranspose(-12); return wParam;
Expand Down
33 changes: 17 additions & 16 deletions mptrack/Ctrl_seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,26 +446,17 @@ BOOL COrderList::PreTranslateMessage(MSG *pMsg)
CInputHandler *ih = CMainFrame::GetInputHandler();
const auto event = ih->Translate(*pMsg);

if(ih->KeyEvent(kCtxCtrlOrderlist, event) != kcNull)
if(ih->KeyEvent(kCtxCtrlOrderlist, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.

//HACK: masquerade as kCtxViewPatternsNote context until we implement appropriate
// command propagation to kCtxCtrlOrderlist context.

if(ih->KeyEvent(kCtxViewPatternsNote, event) != kcNull)
if(ih->KeyEvent(kCtxViewPatternsNote, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.

// Handle Application (menu) key
if(pMsg->message == WM_KEYDOWN && event.key == VK_APPS)
{
const auto selection = GetCurSel();
auto pt = (GetRectFromOrder(selection.firstOrd) | GetRectFromOrder(selection.lastOrd)).CenterPoint();
CRect clientRect;
GetClientRect(clientRect);
if(!clientRect.PtInRect(pt))
pt = clientRect.CenterPoint();
OnRButtonDown(0, pt);
}
if(ih->KeyEvent(kCtxAllContexts, event, this) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.
}

return CWnd::PreTranslateMessage(pMsg);
Expand All @@ -474,9 +465,21 @@ BOOL COrderList::PreTranslateMessage(MSG *pMsg)

LRESULT COrderList::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
{
bool isPlaying = IsPlaying();
const bool isPlaying = IsPlaying();
switch(wParam)
{
case kcContextMenu:
{
const auto selection = GetCurSel();
auto pt = (GetRectFromOrder(selection.firstOrd) | GetRectFromOrder(selection.lastOrd)).CenterPoint();
CRect clientRect;
GetClientRect(clientRect);
if(!clientRect.PtInRect(pt))
pt = clientRect.CenterPoint();
OnRButtonDown(0, pt);
}
return wParam;

case kcEditCopy:
OnEditCopy(); return wParam;
case kcEditCut:
Expand Down Expand Up @@ -888,15 +891,13 @@ void COrderList::OnSetFocus(CWnd *pWnd)
CWnd::OnSetFocus(pWnd);
InvalidateSelection();
UpdateInfoText();
CMainFrame::GetMainFrame()->m_pOrderlistHasFocus = this;
}


void COrderList::OnKillFocus(CWnd *pWnd)
{
CWnd::OnKillFocus(pWnd);
InvalidateSelection();
CMainFrame::GetMainFrame()->m_pOrderlistHasFocus = nullptr;
}


Expand Down
7 changes: 2 additions & 5 deletions mptrack/Ctrl_smp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,11 +1900,8 @@ class DoPitchShiftTimeStretch : public CProgressDialog
: CProgressDialog{&parent}
, m_updateInterval{std::max(uint32(15), TrackerSettings::Instance().GUIUpdateInterval.Get())}
{
const auto updateFunc = std::bind(&DoPitchShiftTimeStretch::UpdateProgress, this, std::placeholders::_1, std::placeholders::_2);
const auto prepareUndo = [&parent]()
{
return parent.PrepareUndo("Pitch Shift / Time Stretch", sundo_replace);
};
const auto updateFunc = [this](SmpLength current, SmpLength maximum) { return UpdateProgress(current, maximum); };
const auto prepareUndo = [&parent]() { return parent.PrepareUndo("Pitch Shift / Time Stretch", sundo_replace); };

CSoundFile &sndFile = modDoc.GetSoundFile();
if(loFi)
Expand Down
12 changes: 1 addition & 11 deletions mptrack/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,6 @@ LRESULT CMainFrame::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
case kcPrevDocument: MDIPrev(); break;
case kcFileCloseAll: theApp.OnFileCloseAll(); break;


//D'oh!! moddoc isn't a CWnd so we have to handle its messages and pass them on.

case kcFileSaveAs:
Expand Down Expand Up @@ -2581,17 +2580,8 @@ LRESULT CMainFrame::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)
m_wndTree.SetFocus();
break;

//if handled neither by MainFrame nor by ModDoc...
default:
//If the treeview has focus, post command to the tree view
if (m_bModTreeHasFocus)
return m_wndTree.SendMessageToModTree(WM_MOD_KEYCOMMAND, wParam, lParam);
if (m_pNoteMapHasFocus)
return m_pNoteMapHasFocus->SendMessage(WM_MOD_KEYCOMMAND, wParam, lParam);
if (m_pOrderlistHasFocus)
return m_pOrderlistHasFocus->SendMessage(WM_MOD_KEYCOMMAND, wParam, lParam);

//Else send it to the active view
// If handled neither by MainFrame nor by ModDoc, send it to the active view
CMDIChildWnd *pMDIActive = MDIGetActive();
CWnd *wnd = nullptr;
if(pMDIActive)
Expand Down
16 changes: 0 additions & 16 deletions mptrack/Mainbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,22 +1291,6 @@ void CModTreeBar::OnLButtonUp(UINT, CPoint)
}


HWND CModTreeBar::GetModTreeHWND()
{
return m_pModTree->m_hWnd;
}


LRESULT CModTreeBar::SendMessageToModTree(UINT cmdID, WPARAM wParam, LPARAM lParam)
{
if(::GetFocus() == m_pModTree->m_hWnd)
return m_pModTree->SendMessage(cmdID, wParam, lParam);
if(::GetFocus() == m_pModTreeData->m_hWnd)
return m_pModTreeData->SendMessage(cmdID, wParam, lParam);
return 0;
}


bool CModTreeBar::SetTreeSoundfile(FileReader &file)
{
return m_pModTree->SetSoundFile(file);
Expand Down
2 changes: 0 additions & 2 deletions mptrack/Mainbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ class CModTreeBar: public CDialogBar
void OnDocumentClosed(CModDoc *pModDoc);
void OnUpdate(CModDoc *pModDoc, UpdateHint hint, CObject *pHint = nullptr);
void UpdatePlayPos(CModDoc *pModDoc, Notification *pNotify);
HWND GetModTreeHWND(); //rewbs.customKeys
LRESULT SendMessageToModTree(UINT cmdID, WPARAM wParam, LPARAM lParam);
bool SetTreeSoundfile(FileReader &file);

void StartTreeFilter(CModTree &source);
Expand Down
2 changes: 0 additions & 2 deletions mptrack/Mainfrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ class CMainFrame
CAutoSaver m_AutoSaver;

public:
CWnd *m_pNoteMapHasFocus = nullptr;
CWnd *m_pOrderlistHasFocus = nullptr;
bool m_bModTreeHasFocus = false;

public:
Expand Down
23 changes: 11 additions & 12 deletions mptrack/View_ins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2260,18 +2260,6 @@ BOOL CViewInstrument::PreTranslateMessage(MSG *pMsg)
const auto event = ih->Translate(*pMsg);
if(ih->KeyEvent(kCtxViewInstruments, event) != kcNull)
return TRUE; // Mapped to a command, no need to pass message on.

// Handle Application (menu) key
if(pMsg->message == WM_KEYDOWN && event.key == VK_APPS)
{
CPoint pt(0, 0);
if(m_nDragItem > 0)
{
uint32 point = DragItemToEnvPoint();
pt.SetPoint(PointToScreen(point), ValueToScreen(EnvGetValue(point)));
}
OnRButtonDown(0, pt);
}
}
}

Expand All @@ -2288,6 +2276,17 @@ LRESULT CViewInstrument::OnCustomKeyMsg(WPARAM wParam, LPARAM)

switch(wParam)
{
case kcContextMenu:
{
CPoint pt(0, 0);
if(m_nDragItem > 0)
{
uint32 point = DragItemToEnvPoint();
pt.SetPoint(PointToScreen(point), ValueToScreen(EnvGetValue(point)));
}
OnRButtonDown(0, pt);
}
return wParam;
case kcPrevInstrument: OnPrevInstrument(); return wParam;
case kcNextInstrument: OnNextInstrument(); return wParam;
case kcEditCopy: OnEditCopy(); return wParam;
Expand Down
8 changes: 2 additions & 6 deletions mptrack/View_pat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,6 @@ BOOL CViewPattern::PreTranslateMessage(MSG *pMsg)
}
}
//end HACK.

// Handle Application (menu) key
if(pMsg->message == WM_KEYDOWN && event.key == VK_APPS)
{
OnRButtonDown(0, GetPointFromPosition(m_Cursor));
}
} else if(pMsg->message == WM_MBUTTONDOWN)
{
// Open quick channel properties dialog if we're middle-clicking a channel header.
Expand Down Expand Up @@ -4334,6 +4328,8 @@ LRESULT CViewPattern::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)

switch(wParam)
{
case kcContextMenu: OnRButtonDown(0, GetPointFromPosition(m_Cursor)); return wParam;

case kcPrevInstrument: OnPrevInstrument(); return wParam;
case kcNextInstrument: OnNextInstrument(); return wParam;
case kcPrevOrder: GotoPreviousOrder(); return wParam;
Expand Down
9 changes: 2 additions & 7 deletions mptrack/View_smp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3656,13 +3656,6 @@ BOOL CViewSample::PreTranslateMessage(MSG *pMsg)
const auto event = ih->Translate(*pMsg);
if (ih->KeyEvent(kCtxViewSamples, event) != kcNull)
return true; // Mapped to a command, no need to pass message on.

// Handle Application (menu) key
if(pMsg->message == WM_KEYDOWN && event.key == VK_APPS)
{
int x = Util::ScalePixels(32, m_hWnd);
OnRButtonDown(0, CPoint(x, x));
}
}

}
Expand All @@ -3679,6 +3672,8 @@ LRESULT CViewSample::OnCustomKeyMsg(WPARAM wParam, LPARAM lParam)

switch(wParam)
{
case kcContextMenu: OnRButtonDown(0, CPoint(0, TimelineHeight(m_hWnd))); return wParam;

case kcSampleTrim: TrimSample(false); return wParam;
case kcSampleTrimToLoopEnd: TrimSample(true); return wParam;
case kcSampleZoomUp: OnZoomUp(); return wParam;
Expand Down
Loading

0 comments on commit 6ecf80c

Please sign in to comment.