mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-07 07:12:34 +02:00
Steps to reproduce: 1. Open preferences 2. Select the keyboard category 3. Scroll down the list by any amount 4. Select an item using the mouse. The list scrolls to the top and the wrong item is selected. The problem occurs because if the list of shortcuts is currently not the focus, then after a left mouse click, KeyView::OnSetFocus() is called, and setting the selection in that function interferes with the mouse selection. Fix: In KeyView::OnSetFocus(), if there has been a left down event, don't select anything.
178 lines
4.2 KiB
C++
178 lines
4.2 KiB
C++
/**********************************************************************
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
KeyView.h
|
|
|
|
**********************************************************************/
|
|
|
|
#ifndef __AUDACITY_WIDGETS_KEYVIEW__
|
|
#define __AUDACITY_WIDGETS_KEYVIEW__
|
|
|
|
#include "../Audacity.h"
|
|
#include "audacity/Types.h"
|
|
|
|
#include <vector>
|
|
#include <wx/setup.h> // for wxUSE_* macros
|
|
#include <wx/defs.h>
|
|
#include <wx/vlbox.h> // to inherit wxVListBox
|
|
|
|
#include "../commands/Keyboard.h"
|
|
|
|
class wxArrayString;
|
|
|
|
// Class holding all information about a node. Rather than a real tree
|
|
// we store these in an array and simulate a tree.
|
|
class KeyNode
|
|
{
|
|
public:
|
|
KeyNode()
|
|
{
|
|
index = -1;
|
|
line = -1;
|
|
depth = -1;
|
|
iscat = false;
|
|
ispfx = false;
|
|
isparent = false;
|
|
isopen = false;
|
|
}
|
|
KeyNode( const KeyNode & ) = default;
|
|
KeyNode &operator = ( const KeyNode & ) = default;
|
|
//KeyNode( KeyNode && ) = default;
|
|
//KeyNode &operator = ( KeyNode && ) = default;
|
|
|
|
public:
|
|
CommandID name;
|
|
wxString category;
|
|
wxString prefix;
|
|
wxString label;
|
|
NormalizedKeyString key;
|
|
int index;
|
|
int line;
|
|
int depth;
|
|
bool iscat;
|
|
bool ispfx;
|
|
bool isparent;
|
|
bool isopen;
|
|
};
|
|
|
|
// Declare the KeyNode arrays
|
|
|
|
// Types of view currently supported
|
|
enum ViewByType : int
|
|
{
|
|
ViewByTree,
|
|
ViewByName,
|
|
ViewByKey
|
|
};
|
|
|
|
#if wxUSE_ACCESSIBILITY
|
|
class KeyViewAx;
|
|
#endif
|
|
|
|
// The KeyView class
|
|
class KeyView final : public wxVListBox
|
|
{
|
|
public:
|
|
KeyView(wxWindow *parent,
|
|
wxWindowID id = wxID_ANY,
|
|
const wxPoint & pos = wxDefaultPosition,
|
|
const wxSize & size = wxDefaultSize);
|
|
virtual ~KeyView();
|
|
wxString GetName() const override; // Gets the control name from the base class
|
|
|
|
void RefreshBindings(const CommandIDs & names,
|
|
const wxArrayString & categories,
|
|
const wxArrayString & prefixes,
|
|
const wxArrayString & labels,
|
|
const std::vector<NormalizedKeyString> & keys,
|
|
bool bSort);
|
|
|
|
int GetSelected() const;
|
|
|
|
wxString GetLabel(int index) const;
|
|
wxString GetFullLabel(int index) const;
|
|
|
|
int GetIndexByName(const CommandID & name) const;
|
|
CommandID GetName(int index) const;
|
|
CommandID GetNameByKey(const NormalizedKeyString & key) const;
|
|
|
|
int GetIndexByKey(const NormalizedKeyString & key) const;
|
|
NormalizedKeyString GetKey(int index) const;
|
|
bool CanSetKey(int index) const;
|
|
bool SetKey(int index, const NormalizedKeyString & key);
|
|
bool SetKeyByName(const CommandID & name, const NormalizedKeyString & key);
|
|
|
|
void SetView(ViewByType type);
|
|
|
|
void SetFilter(const wxString & filter);
|
|
|
|
void ExpandAll();
|
|
void CollapseAll();
|
|
|
|
void SelectNode(int index);
|
|
|
|
private:
|
|
void RecalcExtents();
|
|
void UpdateHScroll();
|
|
void RefreshLines(bool bSort = true);
|
|
|
|
int LineToIndex(int line) const;
|
|
int IndexToLine(int index) const;
|
|
|
|
void OnDrawBackground(wxDC & dc, const wxRect & rect, size_t line) const override;
|
|
void OnDrawItem(wxDC & dc, const wxRect & rect, size_t line) const override;
|
|
wxCoord OnMeasureItem(size_t line) const override;
|
|
|
|
void OnSelected(wxCommandEvent & event);
|
|
void OnSetFocus(wxFocusEvent & event);
|
|
void OnKillFocus(wxFocusEvent & event);
|
|
void OnSize(wxSizeEvent & event);
|
|
void OnScroll(wxScrollWinEvent & event);
|
|
void OnKeyDown(wxKeyEvent & event);
|
|
void OnLeftDown(wxMouseEvent & event);
|
|
|
|
|
|
static wxString CommandTranslated;
|
|
static bool CmpKeyNodeByTree(KeyNode *n1, KeyNode *n2);
|
|
static bool CmpKeyNodeByName(KeyNode *n1, KeyNode *n2);
|
|
static bool CmpKeyNodeByKey(KeyNode *n1, KeyNode *n2);
|
|
|
|
#if wxUSE_ACCESSIBILITY
|
|
friend class KeyViewAx;
|
|
|
|
bool HasChildren(int line);
|
|
bool IsExpanded(int line);
|
|
wxCoord GetLineHeight(int line);
|
|
wxString GetValue(int line);
|
|
ViewByType GetViewType();
|
|
#endif
|
|
|
|
private:
|
|
std::vector<KeyNode> mNodes;
|
|
std::vector<KeyNode*> mLines;
|
|
|
|
ViewByType mViewType;
|
|
wxString mFilter;
|
|
|
|
wxCoord mScrollX;
|
|
wxCoord mWidth;
|
|
|
|
size_t mLineCount;
|
|
wxCoord mLineHeight;
|
|
wxCoord mKeyX;
|
|
int mCommandWidth;
|
|
wxCoord mKeyWidth;
|
|
|
|
bool mThereHasBeenALeftDown{};
|
|
|
|
#if wxUSE_ACCESSIBILITY
|
|
KeyViewAx *mAx;
|
|
#endif
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
};
|
|
|
|
#endif
|
|
|