Audacity 3.2.0
Classes | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
NumericTextCtrl Class Referencefinal

#include <NumericTextCtrl.h>

Inheritance diagram for NumericTextCtrl:
[legend]
Collaboration diagram for NumericTextCtrl:
[legend]

Classes

struct  Options
 

Public Member Functions

 NumericTextCtrl (wxWindow *parent, wxWindowID winid, NumericConverter::Type type, const NumericFormatSymbol &formatName={}, double value=0.0, double sampleRate=44100, const Options &options={}, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~NumericTextCtrl ()
 
void SetName (const TranslatableString &name)
 
wxSize ComputeSizing (bool update=true, wxCoord digitW=0, wxCoord digitH=0)
 
bool Layout () override
 
void Fit () override
 
void SetSampleRate (double sampleRate)
 
void SetValue (double newValue)
 
bool SetFormatString (const FormatStrings &formatString)
 
bool SetFormatName (const NumericFormatSymbol &formatName)
 
void SetFieldFocus (int)
 
wxSize GetDimensions ()
 
wxSize GetDigitSize ()
 
void SetDigitSize (int width, int height)
 
void SetReadOnly (bool readOnly=true)
 
void EnableMenu (bool enable=true)
 
void SetInvalidValue (double invalidValue)
 
int GetFocusedField ()
 
int GetFocusedDigit ()
 
- Public Member Functions inherited from NumericConverter
 NumericConverter (Type type, const NumericFormatSymbol &formatName={}, double value=0.0f, double sampleRate=1.0f)
 
 NumericConverter (const NumericConverter &)
 
virtual ~NumericConverter ()
 
virtual void ValueToControls ()
 
virtual void ValueToControls (double rawValue, bool nearest=true)
 
virtual void ControlsToValue ()
 
void PrintDebugInfo ()
 
bool SetFormatName (const NumericFormatSymbol &formatName)
 
bool SetFormatString (const FormatStrings &formatString)
 
void SetSampleRate (double sampleRate)
 
void SetValue (double newValue)
 
void SetMinValue (double minValue)
 
void ResetMinValue ()
 
void SetMaxValue (double maxValue)
 
void ResetMaxValue ()
 
double GetValue ()
 
wxString GetString ()
 
int GetFormatIndex ()
 
int GetNumBuiltins ()
 
NumericFormatSymbol GetBuiltinName (const int index)
 
FormatStrings GetBuiltinFormat (const int index)
 
FormatStrings GetBuiltinFormat (const NumericFormatSymbol &name)
 
void Adjust (int steps, int dir)
 
void Increment ()
 
void Decrement ()
 

Private Member Functions

void OnCaptureKey (wxCommandEvent &event)
 
void OnKeyDown (wxKeyEvent &event)
 
void OnKeyUp (wxKeyEvent &event)
 
void OnMouse (wxMouseEvent &event)
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnFocus (wxFocusEvent &event)
 
void OnContext (wxContextMenuEvent &event)
 
void ValueToControls () override
 
void ControlsToValue () override
 
void UpdateAutoFocus ()
 
void Updated (bool keyup=false)
 

Private Attributes

bool mMenuEnabled
 
bool mReadOnly
 
std::unique_ptr< wxBitmap > mBackgroundBitmap
 
std::unique_ptr< wxFont > mDigitFont
 
std::unique_ptr< wxFont > mLabelFont
 
int mDigitBoxW
 
int mDigitBoxH
 
int mDigitW
 
int mDigitH
 
int mBorderLeft
 
int mBorderTop
 
int mBorderRight
 
int mBorderBottom
 
int mWidth
 
int mHeight
 
int mButtonWidth
 
int mLastField
 
bool mAutoPos
 
double mScrollRemainder
 
NumericConverter::Type mType
 
bool mAllowInvalidValue
 

Friends

class NumericTextCtrlAx
 

Additional Inherited Members

- Public Types inherited from NumericConverter
enum  Type { TIME , ATIME , FREQUENCY , BANDWIDTH }
 
- Static Public Member Functions inherited from NumericConverter
static NumericFormatSymbol DefaultSelectionFormat ()
 
static NumericFormatSymbol TimeAndSampleFormat ()
 
static NumericFormatSymbol SecondsFormat ()
 
static NumericFormatSymbol HoursMinsSecondsFormat ()
 
static NumericFormatSymbol HundredthsFormat ()
 
static NumericFormatSymbol HertzFormat ()
 
static NumericFormatSymbol LookupFormat (Type type, const wxString &id)
 
- Protected Attributes inherited from NumericConverter
Type mType
 
double mValue
 
double mMinValue
 
double mMaxValue
 
double mInvalidValue
 
FormatStrings mFormatString
 
std::vector< NumericFieldmFields
 
wxString mPrefix
 
wxString mValueTemplate
 
wxString mValueMask
 
wxString mValueString
 
double mScalingFactor
 
double mSampleRate
 
bool mNtscDrop
 
int mFocusedDigit
 
std::vector< DigitInfomDigits
 
const BuiltinFormatStringmBuiltinFormatStrings
 
const size_t mNBuiltins
 
int mDefaultNdx
 

Detailed Description

Definition at line 170 of file NumericTextCtrl.h.

Constructor & Destructor Documentation

◆ NumericTextCtrl()

NumericTextCtrl::NumericTextCtrl ( wxWindow *  parent,
wxWindowID  winid,
NumericConverter::Type  type,
const NumericFormatSymbol formatName = {},
double  value = 0.0,
double  sampleRate = 44100,
const Options options = {},
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 1355 of file NumericTextCtrl.cpp.

1362 :
1363 wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
1364 NumericConverter(type, formatName, timeValue, sampleRate),
1366 mDigitFont{},
1367 mLabelFont{},
1368 mLastField(1),
1369 mAutoPos(options.autoPos)
1370 , mType(type)
1371{
1372 mAllowInvalidValue = false;
1373
1374 mDigitBoxW = 11;
1375 mDigitBoxH = 19;
1376
1377 mBorderLeft = 1;
1378 mBorderTop = 1;
1379 mBorderRight = 1;
1380 mBorderBottom = 1;
1381
1382 mReadOnly = options.readOnly;
1383 mMenuEnabled = options.menuEnabled;
1384 mButtonWidth = mMenuEnabled ? 9 : 0;
1385
1386 SetLayoutDirection(wxLayout_LeftToRight);
1387 Layout();
1388 Fit();
1390
1391 //PRL -- would this fix the following?
1392 //ValueToControls();
1393
1394 //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
1395 //ControlsToValue();
1396
1397 mScrollRemainder = 0.0;
1398
1399#if wxUSE_ACCESSIBILITY
1400 SetLabel(wxT(""));
1401 SetName( {} );
1402 SetAccessible(safenew NumericTextCtrlAx(this));
1403#endif
1404
1405 if (options.hasInvalidValue)
1406 SetInvalidValue( options.invalidValue );
1407
1408 if (!options.format.formatStr.empty())
1409 SetFormatString( options.format );
1410
1411 if (options.hasValue)
1412 SetValue( options.value );
1413
1414}
wxT("CloseDown"))
#define safenew
Definition: MemoryX.h:10
NumericConverter(Type type, const NumericFormatSymbol &formatName={}, double value=0.0f, double sampleRate=1.0f)
void Fit() override
bool SetFormatString(const FormatStrings &formatString)
std::unique_ptr< wxFont > mDigitFont
void SetInvalidValue(double invalidValue)
bool Layout() override
friend class NumericTextCtrlAx
void ValueToControls() override
std::unique_ptr< wxBitmap > mBackgroundBitmap
void SetName(const TranslatableString &name)
NumericConverter::Type mType
void SetValue(double newValue)
std::unique_ptr< wxFont > mLabelFont

◆ ~NumericTextCtrl()

NumericTextCtrl::~NumericTextCtrl ( )
virtual

Definition at line 1416 of file NumericTextCtrl.cpp.

1417{
1418}

Member Function Documentation

◆ ComputeSizing()

wxSize NumericTextCtrl::ComputeSizing ( bool  update = true,
wxCoord  digitW = 0,
wxCoord  digitH = 0 
)

Definition at line 1519 of file NumericTextCtrl.cpp.

1520{
1521 // Get current box size
1522 if (boxW == 0) {
1523 boxW = mDigitBoxW;
1524 }
1525
1526 if (boxH == 0) {
1527 boxH = mDigitBoxH;
1528 }
1529 boxH -= (mBorderTop + mBorderBottom);
1530
1531 // We can use the screen device context since we're not drawing to it
1532 wxScreenDC dc;
1533
1534 // First calculate a rough point size
1535 wxFont pf(wxSize(boxW, boxH), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1536 int fontSize = pf.GetPointSize();
1537 wxCoord strW;
1538 wxCoord strH;
1539
1540 // Now decrease it until we fit within our digit box
1541 dc.SetFont(pf);
1542 dc.GetTextExtent(wxT("0"), &strW, &strH);
1543 while (strW > boxW || strH > boxH) {
1544 dc.SetFont(wxFont(--fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
1545 dc.GetTextExtent(wxT("0"), &strW, &strH);
1546 }
1547 fontSize--;
1548
1549 // Create the digit font with the new point size
1550 if (update) {
1551 mDigitFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1552 dc.SetFont(*mDigitFont);
1553
1554 // Remember the actual digit width and height using the new font
1555 dc.GetTextExtent(wxT("0"), &mDigitW, &mDigitH);
1556 }
1557
1558 // The label font should be a little smaller
1559 std::unique_ptr<wxFont> labelFont = std::make_unique<wxFont>(fontSize - 1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1560
1561 // Use the label font for all remaining measurements since only non-digit text is left
1562 dc.SetFont(*labelFont);
1563
1564 // Remember the pointer if updating
1565 if (update) {
1566 mLabelFont = std::move(labelFont);
1567 }
1568
1569 // Get the width of the prefix, if any
1570 dc.GetTextExtent(mPrefix, &strW, &strH);
1571
1572 // Bump x-position to the end of the prefix
1573 int x = mBorderLeft + strW;
1574
1575 if (update) {
1576 // Set the character position past the prefix
1577 int pos = mPrefix.length();
1578
1579 // Reset digits array
1580 mDigits.clear();
1581
1582 // Figure out the x-position of each field and label in the box
1583 for (int i = 0, fcnt = mFields.size(); i < fcnt; ++i) {
1584 // Get the size of the label
1585 dc.GetTextExtent(mFields[i].label, &strW, &strH);
1586
1587 // Remember this field's x-position
1588 mFields[i].fieldX = x;
1589
1590 // Remember metrics for each digit
1591 for (int j = 0, dcnt = mFields[i].digits; j < dcnt; ++j) {
1592 mDigits.push_back(DigitInfo(i, j, pos, wxRect(x, mBorderTop, boxW, boxH)));
1593 x += boxW;
1594 pos++;
1595 }
1596
1597 // Remember the label's x-position
1598 mFields[i].labelX = x;
1599
1600 // Bump to end of label
1601 x += strW;
1602
1603 // Remember the label's width
1604 mFields[i].fieldW = x;
1605
1606 // Bump character position to end of label
1607 pos += mFields[i].label.length();
1608 }
1609 }
1610 else {
1611 // Determine the maximum x-position (length) of the remaining fields
1612 for (int i = 0, fcnt = mFields.size(); i < fcnt; ++i) {
1613 // Get the size of the label
1614 dc.GetTextExtent(mFields[i].label, &strW, &strH);
1615
1616 // Just bump to next field
1617 x += (boxW * mFields[i].digits) + strW;
1618 }
1619 }
1620
1621 // Calculate the maximum dimensions
1622 wxSize dim(x + mBorderRight, boxH + mBorderTop + mBorderBottom);
1623
1624 // Save maximumFinally, calculate the minimum dimensions
1625 if (update) {
1626 mWidth = dim.x;
1627 mHeight = dim.y;
1628 }
1629
1630 return wxSize(dim.x + mButtonWidth, dim.y);
1631}
TranslatableString label
Definition: TagsEditor.cpp:164
DigitInfo is a class used in NumericTextCtrl.
std::vector< DigitInfo > mDigits
std::vector< NumericField > mFields

References label, mBorderBottom, mBorderLeft, mBorderRight, mBorderTop, mButtonWidth, mDigitBoxH, mDigitBoxW, mDigitFont, mDigitH, NumericConverter::mDigits, mDigitW, NumericConverter::mFields, mHeight, mLabelFont, NumericConverter::mPrefix, mWidth, and wxT().

Referenced by TimeToolBar::ComputeSizing(), and Layout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ControlsToValue()

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 2116 of file NumericTextCtrl.cpp.

2117{
2119}
virtual void ControlsToValue()

References NumericConverter::ControlsToValue().

Referenced by OnKeyDown(), SetFormatString(), SetSampleRate(), and SetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnableMenu()

void NumericTextCtrl::EnableMenu ( bool  enable = true)

Definition at line 1492 of file NumericTextCtrl.cpp.

1493{
1494#if wxUSE_TOOLTIPS
1495 wxString tip(_("(Use context menu to change format.)"));
1496 if (enable)
1497 SetToolTip(tip);
1498 else {
1499 wxToolTip *tt = GetToolTip();
1500 if (tt && tt->GetTip() == tip)
1501 SetToolTip(NULL);
1502 }
1503#endif
1504 mMenuEnabled = enable;
1505 mButtonWidth = enable ? 9 : 0;
1506 Layout();
1507 Fit();
1508}
#define _(s)
Definition: Internat.h:75

References _, Fit(), Layout(), mButtonWidth, and mMenuEnabled.

Here is the call graph for this function:

◆ Fit()

void NumericTextCtrl::Fit ( )
override

Definition at line 1690 of file NumericTextCtrl.cpp.

1691{
1692 wxSize sz = GetSize();
1693 wxSize csz = GetClientSize();
1694
1695 sz.x = mButtonWidth + mWidth + (sz.x - csz.x);
1696 sz.y = mHeight + (sz.y - csz.y);
1697
1698 SetInitialSize(sz);
1699}

References mButtonWidth, mHeight, and mWidth.

Referenced by EnableMenu(), SetDigitSize(), SetFormatString(), and SetSampleRate().

Here is the caller graph for this function:

◆ GetDigitSize()

wxSize NumericTextCtrl::GetDigitSize ( )
inline

Definition at line 232 of file NumericTextCtrl.h.

232{ return wxSize(mDigitBoxW, mDigitBoxH); }

Referenced by TimeToolBar::OnSize(), and TimeToolBar::Populate().

Here is the caller graph for this function:

◆ GetDimensions()

wxSize NumericTextCtrl::GetDimensions ( )
inline

Definition at line 231 of file NumericTextCtrl.h.

231{ return wxSize(mWidth + mButtonWidth, mHeight); }

Referenced by TimeToolBar::OnSize().

Here is the caller graph for this function:

◆ GetFocusedDigit()

int NumericTextCtrl::GetFocusedDigit ( )
inline

Definition at line 244 of file NumericTextCtrl.h.

244{ return mFocusedDigit; }

◆ GetFocusedField()

int NumericTextCtrl::GetFocusedField ( )
inline

Definition at line 243 of file NumericTextCtrl.h.

243{ return mLastField; }

◆ Layout()

bool NumericTextCtrl::Layout ( )
override

Definition at line 1633 of file NumericTextCtrl.cpp.

1634{
1635 ComputeSizing();
1636
1637 wxMemoryDC memDC;
1638 wxCoord strW, strH;
1639 memDC.SetFont(*mLabelFont);
1640 memDC.GetTextExtent(mPrefix, &strW, &strH);
1641
1642 int i;
1643
1644 // Draw the background bitmap - it contains black boxes where
1645 // all of the digits go and all of the other text
1646
1647 wxBrush Brush;
1648
1649 mBackgroundBitmap = std::make_unique<wxBitmap>(mWidth + mButtonWidth, mHeight,24);
1650 memDC.SelectObject(*mBackgroundBitmap);
1651
1652 theTheme.SetBrushColour( Brush, clrTimeHours );
1653 memDC.SetBrush(Brush);
1654 memDC.SetPen(*wxTRANSPARENT_PEN);
1655 memDC.DrawRectangle(0, 0, mWidth + mButtonWidth, mHeight);
1656
1657 int numberBottom = mBorderTop + (mDigitBoxH - mDigitH)/2 + mDigitH;
1658
1659 memDC.GetTextExtent(wxT("0"), &strW, &strH);
1660 int labelTop = numberBottom - strH;
1661
1662 memDC.SetTextForeground(theTheme.Colour( clrTimeFont ));
1663 memDC.SetTextBackground(theTheme.Colour( clrTimeBack ));
1664 memDC.DrawText(mPrefix, mBorderLeft, labelTop);
1665
1666 theTheme.SetBrushColour( Brush, clrTimeBack );
1667 memDC.SetBrush(Brush);
1668 //memDC.SetBrush(*wxLIGHT_GREY_BRUSH);
1669 for(i = 0; i < mDigits.size(); i++)
1670 memDC.DrawRectangle(mDigits[i].digitBox);
1671 memDC.SetBrush( wxNullBrush );
1672
1673 for(i = 0; i < mFields.size(); i++)
1674 memDC.DrawText(mFields[i].label,
1675 mFields[i].labelX, labelTop);
1676
1677 if (mMenuEnabled) {
1678 wxRect r(mWidth, 0, mButtonWidth - 1, mHeight - 1);
1679 AColor::Bevel(memDC, true, r);
1680 memDC.SetBrush(*wxBLACK_BRUSH);
1681 memDC.SetPen(*wxBLACK_PEN);
1682 AColor::Arrow(memDC,
1683 mWidth + 1,
1684 (mHeight / 2) - 2,
1685 mButtonWidth - 2);
1686 }
1687 return true;
1688}
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:160
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
wxSize ComputeSizing(bool update=true, wxCoord digitW=0, wxCoord digitH=0)
wxColour & Colour(int iIndex)
void SetBrushColour(wxBrush &Brush, int iIndex)

References AColor::Arrow(), AColor::Bevel(), ThemeBase::Colour(), ComputeSizing(), mBackgroundBitmap, mBorderLeft, mBorderTop, mButtonWidth, mDigitBoxH, mDigitH, NumericConverter::mDigits, NumericConverter::mFields, mHeight, mLabelFont, mMenuEnabled, NumericConverter::mPrefix, mWidth, ThemeBase::SetBrushColour(), theTheme, and wxT().

Referenced by EnableMenu(), SetDigitSize(), SetFormatString(), and SetSampleRate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCaptureKey()

void NumericTextCtrl::OnCaptureKey ( wxCommandEvent &  event)
private

Definition at line 1865 of file NumericTextCtrl.cpp.

1866{
1867 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
1868 int keyCode = kevent->GetKeyCode();
1869
1870 // Convert numeric keypad entries.
1871 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1872 keyCode -= WXK_NUMPAD0 - '0';
1873
1874 switch (keyCode)
1875 {
1876 case WXK_BACK:
1877 case WXK_LEFT:
1878 case WXK_RIGHT:
1879 case WXK_HOME:
1880 case WXK_END:
1881 case WXK_UP:
1882 case WXK_DOWN:
1883 case WXK_TAB:
1884 case WXK_RETURN:
1885 case WXK_NUMPAD_ENTER:
1886 case WXK_DELETE:
1887 return;
1888
1889 default:
1890 if (keyCode >= '0' && keyCode <= '9' && !kevent->HasAnyModifiers())
1891 return;
1892 }
1893
1894 event.Skip();
1895
1896 return;
1897}

◆ OnContext()

void NumericTextCtrl::OnContext ( wxContextMenuEvent &  event)
private

Definition at line 1753 of file NumericTextCtrl.cpp.

1754{
1755 wxMenu menu;
1756 int i;
1757
1758 if (!mMenuEnabled) {
1759 event.Skip();
1760 return;
1761 }
1762
1763 SetFocus();
1764
1765 int currentSelection = -1;
1766 for (i = 0; i < GetNumBuiltins(); i++) {
1767 menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i).Translation());
1768 if (mFormatString == GetBuiltinFormat(i)) {
1769 menu.Check(ID_MENU + i, true);
1770 currentSelection = i;
1771 }
1772 }
1773
1774 menu.Bind(wxEVT_MENU, [](auto&){});
1775 BasicMenu::Handle{ &menu }.Popup(
1777 { 0, 0 }
1778 );
1779
1780 // This used to be in an EVT_MENU() event handler, but GTK
1781 // is sensitive to what is done within the handler if the
1782 // user happens to check the first menuitem and then is
1783 // moving down the menu when the ...CTRL_UPDATED event
1784 // handler kicks in.
1785 for (i = 0; i < GetNumBuiltins(); i++) {
1786 if (menu.IsChecked(ID_MENU + i) && i != currentSelection) {
1788
1789 int eventType = 0;
1790 switch (mType) {
1792 eventType = EVT_TIMETEXTCTRL_UPDATED;
1793 break;
1795 eventType = EVT_FREQUENCYTEXTCTRL_UPDATED;
1796 break;
1798 eventType = EVT_BANDWIDTHTEXTCTRL_UPDATED;
1799 break;
1800 default:
1801 wxASSERT(false);
1802 break;
1803 }
1804
1805 wxCommandEvent e(eventType, GetId());
1806 e.SetInt(i);
1807 e.SetString(GetBuiltinName(i).Internal());
1808 GetParent()->GetEventHandler()->AddPendingEvent(e);
1809 }
1810 }
1811
1812}
@ Internal
Indicates internal failure from Audacity.
#define ID_MENU
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
Definition: BasicMenu.cpp:209
const wxString Translation() const
FormatStrings mFormatString
FormatStrings GetBuiltinFormat(const int index)
NumericFormatSymbol GetBuiltinName(const int index)
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.

References NumericConverter::BANDWIDTH, NumericConverter::FREQUENCY, NumericConverter::GetBuiltinFormat(), NumericConverter::GetBuiltinName(), NumericConverter::GetNumBuiltins(), ID_MENU, Internal, NumericConverter::mFormatString, mMenuEnabled, mType, BasicMenu::Handle::Popup(), SetFormatString(), NumericConverter::TIME, and ComponentInterfaceSymbol::Translation().

Referenced by OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnErase()

void NumericTextCtrl::OnErase ( wxEraseEvent &  event)
private

Definition at line 1701 of file NumericTextCtrl.cpp.

1702{
1703 // Ignore it to prevent flashing
1704}

◆ OnFocus()

void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 1854 of file NumericTextCtrl.cpp.

1855{
1856 KeyboardCapture::OnFocus( *this, event );
1857
1858 if (event.GetEventType() != wxEVT_KILL_FOCUS &&
1859 mFocusedDigit <= 0 )
1861
1862 event.Skip( false ); // PRL: not sure why, but preserving old behavior
1863}
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...

References NumericConverter::mFocusedDigit, KeyboardCapture::OnFocus(), and UpdateAutoFocus().

Here is the call graph for this function:

◆ OnKeyDown()

void NumericTextCtrl::OnKeyDown ( wxKeyEvent &  event)
private

Definition at line 1917 of file NumericTextCtrl.cpp.

1918{
1919 if (mDigits.size() == 0)
1920 {
1921 mFocusedDigit = 0;
1922 return;
1923 }
1924
1925 event.Skip(false);
1926
1927 int keyCode = event.GetKeyCode();
1928 int digit = mFocusedDigit;
1929
1930 if (mFocusedDigit < 0)
1931 mFocusedDigit = 0;
1932 if (mFocusedDigit >= (int)mDigits.size())
1933 mFocusedDigit = mDigits.size() - 1;
1934
1935 // Convert numeric keypad entries.
1936 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1937 keyCode -= WXK_NUMPAD0 - '0';
1938
1939 if (!mReadOnly && (keyCode >= '0' && keyCode <= '9' && !event.HasAnyModifiers())) {
1940 int digitPosition = mDigits[mFocusedDigit].pos;
1941 if (mValueString[digitPosition] == wxChar('-')) {
1942 mValue = std::max(mMinValue, std::min(mMaxValue, 0.0));
1944 // Beware relocation of the string
1945 digitPosition = mDigits[mFocusedDigit].pos;
1946 }
1947 mValueString[digitPosition] = wxChar(keyCode);
1949 Refresh();// Force an update of the control. [Bug 1497]
1951 mFocusedDigit = (mFocusedDigit + 1) % (mDigits.size());
1952 Updated();
1953 }
1954
1955 else if (!mReadOnly && keyCode == WXK_DELETE) {
1958 }
1959
1960 else if (!mReadOnly && keyCode == WXK_BACK) {
1961 // Moves left, replaces that char with '0', stays there...
1962 mFocusedDigit--;
1963 mFocusedDigit += mDigits.size();
1964 mFocusedDigit %= mDigits.size();
1965 wxString::reference theDigit = mValueString[mDigits[mFocusedDigit].pos];
1966 if (theDigit != wxChar('-'))
1967 theDigit = '0';
1969 Refresh();// Force an update of the control. [Bug 1497]
1971 Updated();
1972 }
1973
1974 else if (keyCode == WXK_LEFT) {
1975 mFocusedDigit--;
1976 mFocusedDigit += mDigits.size();
1977 mFocusedDigit %= mDigits.size();
1978 Refresh();
1979 }
1980
1981 else if (keyCode == WXK_RIGHT) {
1982 mFocusedDigit++;
1983 mFocusedDigit %= mDigits.size();
1984 Refresh();
1985 }
1986
1987 else if (keyCode == WXK_HOME) {
1988 mFocusedDigit = 0;
1989 Refresh();
1990 }
1991
1992 else if (keyCode == WXK_END) {
1993 mFocusedDigit = mDigits.size() - 1;
1994 Refresh();
1995 }
1996
1997 else if (!mReadOnly && keyCode == WXK_UP) {
1998 Adjust(1, 1);
1999 Updated();
2000 }
2001
2002 else if (!mReadOnly && keyCode == WXK_DOWN) {
2003 Adjust(1, -1);
2004 Updated();
2005 }
2006
2007 else if (keyCode == WXK_TAB) {
2008#if defined(__WXMSW__)
2009 // Using Navigate() on Windows, rather than the following code causes
2010 // bug 1542
2011 wxWindow* parent = GetParent();
2012 wxNavigationKeyEvent nevent;
2013 nevent.SetWindowChange(event.ControlDown());
2014 nevent.SetDirection(!event.ShiftDown());
2015 nevent.SetEventObject(parent);
2016 nevent.SetCurrentFocus(parent);
2017 GetParent()->GetEventHandler()->ProcessEvent(nevent);
2018#else
2019 Navigate(event.ShiftDown()
2020 ? wxNavigationKeyEvent::IsBackward
2021 : wxNavigationKeyEvent::IsForward);
2022#endif
2023 }
2024
2025 else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) {
2026 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
2027 wxWindow *def = tlw->GetDefaultItem();
2028 if (def && def->IsEnabled()) {
2029 wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
2030 def->GetId());
2031 cevent.SetEventObject( def );
2032 GetParent()->GetEventHandler()->ProcessEvent(cevent);
2033 }
2034 }
2035
2036 else {
2037 event.Skip();
2038 return;
2039 }
2040
2041 if (digit != mFocusedDigit) {
2043 }
2044}
wxEVT_COMMAND_BUTTON_CLICKED
int min(int a, int b)
void Adjust(int steps, int dir)
void Updated(bool keyup=false)
void ControlsToValue() override

References NumericConverter::Adjust(), ControlsToValue(), mAllowInvalidValue, NumericConverter::mDigits, NumericConverter::mFocusedDigit, min(), NumericConverter::mInvalidValue, NumericConverter::mMaxValue, NumericConverter::mMinValue, mReadOnly, NumericConverter::mValue, NumericConverter::mValueString, SetFieldFocus(), SetValue(), Updated(), ValueToControls(), and wxEVT_COMMAND_BUTTON_CLICKED.

Here is the call graph for this function:

◆ OnKeyUp()

void NumericTextCtrl::OnKeyUp ( wxKeyEvent &  event)
private

Definition at line 1899 of file NumericTextCtrl.cpp.

1900{
1901 int keyCode = event.GetKeyCode();
1902
1903 event.Skip(true);
1904
1905 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1906 keyCode -= WXK_NUMPAD0 - '0';
1907
1908 if ((keyCode >= '0' && keyCode <= '9' && !event.HasAnyModifiers()) ||
1909 (keyCode == WXK_DELETE) ||
1910 (keyCode == WXK_BACK) ||
1911 (keyCode == WXK_UP) ||
1912 (keyCode == WXK_DOWN)) {
1913 Updated(true);
1914 }
1915}

References Updated().

Here is the call graph for this function:

◆ OnMouse()

void NumericTextCtrl::OnMouse ( wxMouseEvent &  event)
private

Definition at line 1814 of file NumericTextCtrl.cpp.

1815{
1816 if (event.LeftDown() && event.GetX() >= mWidth) {
1817 wxContextMenuEvent e;
1818 OnContext(e);
1819 }
1820 else if (event.LeftDown()) {
1821 SetFocus();
1822
1823 int bestDist = 9999;
1824 unsigned int i;
1825
1826 mFocusedDigit = 0;
1827 for(i = 0; i < mDigits.size(); i++) {
1828 int dist = abs(event.m_x - (mDigits[i].digitBox.x +
1829 mDigits[i].digitBox.width/2));
1830 if (dist < bestDist) {
1831 mFocusedDigit = i;
1832 bestDist = dist;
1833 }
1834 }
1835
1836 Refresh(false);
1837 }
1838 else if (event.RightDown() && mMenuEnabled) {
1839 wxContextMenuEvent e;
1840 OnContext(e);
1841 }
1842 else if(!mReadOnly && event.m_wheelRotation != 0 ) {
1843 double steps = event.m_wheelRotation /
1844 (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0) +
1846 mScrollRemainder = steps - floor(steps);
1847 steps = floor(steps);
1848
1849 Adjust((int)fabs(steps), steps < 0.0 ? -1 : 1);
1850 Updated();
1851 }
1852}
void OnContext(wxContextMenuEvent &event)

References NumericConverter::Adjust(), NumericConverter::mDigits, NumericConverter::mFocusedDigit, mMenuEnabled, mReadOnly, mScrollRemainder, mWidth, OnContext(), and Updated().

Here is the call graph for this function:

◆ OnPaint()

void NumericTextCtrl::OnPaint ( wxPaintEvent &  event)
private

Definition at line 1706 of file NumericTextCtrl.cpp.

1707{
1708 wxBufferedPaintDC dc(this);
1709 bool focused = (FindFocus() == this);
1710
1711 dc.DrawBitmap(*mBackgroundBitmap, 0, 0);
1712
1713 wxPen Pen;
1714 wxBrush Brush;
1715 if (focused) {
1716 theTheme.SetPenColour( Pen, clrTimeFontFocus );
1717 dc.SetPen(Pen);
1718 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1719 dc.DrawRectangle(0, 0, mWidth, mHeight);
1720 dc.SetPen( wxNullPen );
1721 }
1722
1723 dc.SetFont(*mDigitFont);
1724 dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1725 dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1726
1727 dc.SetPen(*wxTRANSPARENT_PEN);
1728 theTheme.SetBrushColour( Brush , clrTimeBackFocus );
1729 dc.SetBrush( Brush );
1730
1731 int i;
1732 for(i = 0; i < (int)mDigits.size(); i++) {
1733 wxRect box = mDigits[i].digitBox;
1734 if (focused && mFocusedDigit == i) {
1735 dc.DrawRectangle(box);
1736 dc.SetTextForeground(theTheme.Colour( clrTimeFontFocus ));
1737 dc.SetTextBackground(theTheme.Colour( clrTimeBackFocus ));
1738 }
1739 int pos = mDigits[i].pos;
1740 wxString digit = mValueString.Mid(pos, 1);
1741 int x = box.x + (mDigitBoxW - mDigitW)/2;
1742 int y = box.y + (mDigitBoxH - mDigitH)/2;
1743 dc.DrawText(digit, x, y);
1744 if (focused && mFocusedDigit == i) {
1745 dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1746 dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1747 }
1748 }
1749 dc.SetPen( wxNullPen );
1750 dc.SetBrush( wxNullBrush );
1751}
void SetPenColour(wxPen &Pen, int iIndex)

References ThemeBase::Colour(), mBackgroundBitmap, mDigitBoxH, mDigitBoxW, mDigitFont, mDigitH, NumericConverter::mDigits, mDigitW, NumericConverter::mFocusedDigit, mHeight, NumericConverter::mValueString, mWidth, ThemeBase::SetBrushColour(), ThemeBase::SetPenColour(), and theTheme.

Here is the call graph for this function:

◆ SetDigitSize()

void NumericTextCtrl::SetDigitSize ( int  width,
int  height 
)

Definition at line 1479 of file NumericTextCtrl.cpp.

1480{
1481 mDigitBoxW = width;
1482 mDigitBoxH = height;
1483 Layout();
1484 Fit();
1485}

References Fit(), Layout(), mDigitBoxH, and mDigitBoxW.

Referenced by TimeToolBar::OnSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFieldFocus()

void NumericTextCtrl::SetFieldFocus ( int  digit)

Definition at line 2046 of file NumericTextCtrl.cpp.

2047{
2048#if wxUSE_ACCESSIBILITY
2049 if (mDigits.size() == 0)
2050 {
2051 mFocusedDigit = 0;
2052 return;
2053 }
2054 mFocusedDigit = digit;
2055 mLastField = mDigits[mFocusedDigit].field + 1;
2056
2057 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
2058 this,
2059 wxOBJID_CLIENT,
2060 mFocusedDigit + 1);
2061#endif
2062}

References NumericConverter::mDigits, NumericConverter::mFocusedDigit, and mLastField.

Referenced by OnKeyDown().

Here is the caller graph for this function:

◆ SetFormatName()

bool NumericTextCtrl::SetFormatName ( const NumericFormatSymbol formatName)

Definition at line 1443 of file NumericTextCtrl.cpp.

1444{
1445 return
1446 SetFormatString(GetBuiltinFormat(formatName));
1447}

References NumericConverter::GetBuiltinFormat(), and SetFormatString().

Referenced by EffectChangeSpeed::OnTimeCtrlUpdate(), EffectChangeSpeed::TransferDataToWindow(), and EffectChangeSpeed::Update_TimeCtrl_ToLength().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFormatString()

bool NumericTextCtrl::SetFormatString ( const FormatStrings formatString)

Definition at line 1449 of file NumericTextCtrl.cpp.

1450{
1451 auto result =
1453 if (result) {
1454 Layout();
1455 Fit();
1459 }
1460 return result;
1461}
bool SetFormatString(const FormatStrings &formatString)

References ControlsToValue(), Fit(), Layout(), NumericConverter::SetFormatString(), UpdateAutoFocus(), and ValueToControls().

Referenced by OnContext(), TimeToolBar::SetAudioTimeFormat(), SetFormatName(), SelectionBar::SetSelectionFormat(), and TimeDialog::TransferDataToWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetInvalidValue()

void NumericTextCtrl::SetInvalidValue ( double  invalidValue)

Definition at line 1510 of file NumericTextCtrl.cpp.

1511{
1512 const bool wasInvalid = mAllowInvalidValue && (mValue == mInvalidValue);
1513 mAllowInvalidValue = true;
1514 mInvalidValue = invalidValue;
1515 if (wasInvalid)
1516 SetValue(invalidValue);
1517}

References mAllowInvalidValue, NumericConverter::mInvalidValue, NumericConverter::mValue, and SetValue().

Here is the call graph for this function:

◆ SetName()

void NumericTextCtrl::SetName ( const TranslatableString name)

Definition at line 1420 of file NumericTextCtrl.cpp.

1421{
1422 wxControl::SetName( name.Translation() );
1423}
const TranslatableString name
Definition: Distortion.cpp:74
wxString Translation() const

References name, and TranslatableString::Translation().

Referenced by LV2Validator::BuildPlain(), VSTEffectValidator::BuildPlain(), TimeToolBar::Populate(), and VST3UIValidator::VST3UIValidator().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetReadOnly()

void NumericTextCtrl::SetReadOnly ( bool  readOnly = true)

Definition at line 1487 of file NumericTextCtrl.cpp.

1488{
1489 mReadOnly = readOnly;
1490}

References mReadOnly.

Referenced by TimeToolBar::Populate().

Here is the caller graph for this function:

◆ SetSampleRate()

void NumericTextCtrl::SetSampleRate ( double  sampleRate)

Definition at line 1463 of file NumericTextCtrl.cpp.

1464{
1466 Layout();
1467 Fit();
1470}
void SetSampleRate(double sampleRate)

References ControlsToValue(), Fit(), Layout(), NumericConverter::SetSampleRate(), and ValueToControls().

Referenced by TimeToolBar::OnRateChanged(), and TimeDialog::TransferDataToWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetValue()

void NumericTextCtrl::SetValue ( double  newValue)

◆ UpdateAutoFocus()

void NumericTextCtrl::UpdateAutoFocus ( )
private

Definition at line 1428 of file NumericTextCtrl.cpp.

1429{
1430 if (!mAutoPos)
1431 return;
1432
1433 mFocusedDigit = 0;
1434 while (mFocusedDigit < ((int)mDigits.size() - 1)) {
1435 wxChar dgt = mValueString[mDigits[mFocusedDigit].pos];
1436 if (dgt != '0') {
1437 break;
1438 }
1439 mFocusedDigit++;
1440 }
1441}

References mAutoPos, NumericConverter::mDigits, NumericConverter::mFocusedDigit, and NumericConverter::mValueString.

Referenced by OnFocus(), and SetFormatString().

Here is the caller graph for this function:

◆ Updated()

void NumericTextCtrl::Updated ( bool  keyup = false)
private

Definition at line 2064 of file NumericTextCtrl.cpp.

2065{
2066 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
2067
2068 // This will give listeners the ability to do tasks when the
2069 // update has been completed, like when the UP ARROW has been
2070 // held down and is finally released.
2071 event.SetInt(keyup);
2072 event.SetEventObject(this);
2073 GetEventHandler()->ProcessEvent(event);
2074
2075#if wxUSE_ACCESSIBILITY
2076 if (!keyup) {
2077 if (mDigits.size() == 0)
2078 {
2079 mFocusedDigit = 0;
2080 return;
2081 }
2082
2083 // The object_focus event is only needed by Window-Eyes
2084 // and can be removed when we cease to support this screen reader.
2085 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
2086 this,
2087 wxOBJID_CLIENT,
2088 mFocusedDigit + 1);
2089
2090 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
2091 this,
2092 wxOBJID_CLIENT,
2093 mFocusedDigit + 1);
2094 }
2095#endif
2096}
wxEVT_COMMAND_TEXT_UPDATED
Definition: Nyquist.cpp:132

References NumericConverter::mDigits, NumericConverter::mFocusedDigit, and wxEVT_COMMAND_TEXT_UPDATED.

Referenced by OnKeyDown(), OnKeyUp(), and OnMouse().

Here is the caller graph for this function:

◆ ValueToControls()

void NumericTextCtrl::ValueToControls ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 2098 of file NumericTextCtrl.cpp.

2099{
2100 const wxString previousValueString = mValueString;
2102 if (mValueString != previousValueString) {
2103 // Doing this only when needed is an optimization.
2104 // NumerixTextCtrls are used in the selection bar at the bottom
2105 // of Audacity, and are updated at high frequency through
2106 // SetValue() when Audacity is playing. This consumes a
2107 // significant amount of CPU. Typically, when a track is
2108 // playing, only one of the NumericTextCtrl actually changes
2109 // (the audio position). We save CPU by updating the control
2110 // only when needed.
2111 Refresh(false);
2112 }
2113}
virtual void ValueToControls()

References NumericConverter::mValue, NumericConverter::mValueString, and NumericConverter::ValueToControls().

Referenced by OnKeyDown(), SetFormatString(), SetSampleRate(), and SetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ NumericTextCtrlAx

friend class NumericTextCtrlAx
friend

Definition at line 173 of file NumericTextCtrl.h.

Member Data Documentation

◆ mAllowInvalidValue

bool NumericTextCtrl::mAllowInvalidValue
private

Definition at line 298 of file NumericTextCtrl.h.

Referenced by OnKeyDown(), and SetInvalidValue().

◆ mAutoPos

bool NumericTextCtrl::mAutoPos
private

Definition at line 291 of file NumericTextCtrl.h.

Referenced by UpdateAutoFocus().

◆ mBackgroundBitmap

std::unique_ptr<wxBitmap> NumericTextCtrl::mBackgroundBitmap
private

Definition at line 273 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

◆ mBorderBottom

int NumericTextCtrl::mBorderBottom
private

Definition at line 283 of file NumericTextCtrl.h.

Referenced by ComputeSizing().

◆ mBorderLeft

int NumericTextCtrl::mBorderLeft
private

Definition at line 280 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mBorderRight

int NumericTextCtrl::mBorderRight
private

Definition at line 282 of file NumericTextCtrl.h.

Referenced by ComputeSizing().

◆ mBorderTop

int NumericTextCtrl::mBorderTop
private

Definition at line 281 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mButtonWidth

int NumericTextCtrl::mButtonWidth
private

Definition at line 286 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), EnableMenu(), Fit(), and Layout().

◆ mDigitBoxH

int NumericTextCtrl::mDigitBoxH
private

Definition at line 277 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), Layout(), OnPaint(), and SetDigitSize().

◆ mDigitBoxW

int NumericTextCtrl::mDigitBoxW
private

Definition at line 276 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), OnPaint(), and SetDigitSize().

◆ mDigitFont

std::unique_ptr<wxFont> NumericTextCtrl::mDigitFont
private

Definition at line 275 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and OnPaint().

◆ mDigitH

int NumericTextCtrl::mDigitH
private

Definition at line 279 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), Layout(), and OnPaint().

◆ mDigitW

int NumericTextCtrl::mDigitW
private

Definition at line 278 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and OnPaint().

◆ mHeight

int NumericTextCtrl::mHeight
private

Definition at line 285 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), Fit(), Layout(), and OnPaint().

◆ mLabelFont

std::unique_ptr<wxFont> NumericTextCtrl::mLabelFont
private

Definition at line 275 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mLastField

int NumericTextCtrl::mLastField
private

Definition at line 288 of file NumericTextCtrl.h.

Referenced by SetFieldFocus().

◆ mMenuEnabled

bool NumericTextCtrl::mMenuEnabled
private

Definition at line 270 of file NumericTextCtrl.h.

Referenced by EnableMenu(), Layout(), OnContext(), and OnMouse().

◆ mReadOnly

bool NumericTextCtrl::mReadOnly
private

Definition at line 271 of file NumericTextCtrl.h.

Referenced by OnKeyDown(), OnMouse(), and SetReadOnly().

◆ mScrollRemainder

double NumericTextCtrl::mScrollRemainder
private

Definition at line 294 of file NumericTextCtrl.h.

Referenced by OnMouse().

◆ mType

NumericConverter::Type NumericTextCtrl::mType
private

Definition at line 296 of file NumericTextCtrl.h.

Referenced by OnContext().

◆ mWidth

int NumericTextCtrl::mWidth
private

Definition at line 284 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), Fit(), Layout(), OnMouse(), and OnPaint().


The documentation for this class was generated from the following files: