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 1357 of file NumericTextCtrl.cpp.

1364 :
1365 wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
1366 NumericConverter(type, formatName, timeValue, sampleRate),
1368 mDigitFont{},
1369 mLabelFont{},
1370 mLastField(1),
1371 mAutoPos(options.autoPos)
1372 , mType(type)
1373{
1374 mAllowInvalidValue = false;
1375
1376 mDigitBoxW = 11;
1377 mDigitBoxH = 19;
1378
1379 mBorderLeft = 1;
1380 mBorderTop = 1;
1381 mBorderRight = 1;
1382 mBorderBottom = 1;
1383
1384 mReadOnly = options.readOnly;
1385 mMenuEnabled = options.menuEnabled;
1386 mButtonWidth = mMenuEnabled ? 9 : 0;
1387
1388 SetLayoutDirection(wxLayout_LeftToRight);
1389 Layout();
1390 Fit();
1392
1393 //PRL -- would this fix the following?
1394 //ValueToControls();
1395
1396 //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
1397 //ControlsToValue();
1398
1399 mScrollRemainder = 0.0;
1400
1401#if wxUSE_ACCESSIBILITY
1402 SetLabel(wxT(""));
1403 SetName( {} );
1404 SetAccessible(safenew NumericTextCtrlAx(this));
1405#endif
1406
1407 if (options.hasInvalidValue)
1408 SetInvalidValue( options.invalidValue );
1409
1410 if (!options.format.formatStr.empty())
1411 SetFormatString( options.format );
1412
1413 if (options.hasValue)
1414 SetValue( options.value );
1415
1416}
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 1418 of file NumericTextCtrl.cpp.

1419{
1420}

Member Function Documentation

◆ ComputeSizing()

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

Definition at line 1521 of file NumericTextCtrl.cpp.

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

2119{
2121}
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 1494 of file NumericTextCtrl.cpp.

1495{
1496#if wxUSE_TOOLTIPS
1497 wxString tip(_("(Use context menu to change format.)"));
1498 if (enable)
1499 SetToolTip(tip);
1500 else {
1501 wxToolTip *tt = GetToolTip();
1502 if (tt && tt->GetTip() == tip)
1503 SetToolTip(NULL);
1504 }
1505#endif
1506 mMenuEnabled = enable;
1507 mButtonWidth = enable ? 9 : 0;
1508 Layout();
1509 Fit();
1510}
#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 1692 of file NumericTextCtrl.cpp.

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

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 1635 of file NumericTextCtrl.cpp.

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

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

◆ OnContext()

void NumericTextCtrl::OnContext ( wxContextMenuEvent &  event)
private

Definition at line 1755 of file NumericTextCtrl.cpp.

1756{
1757 wxMenu menu;
1758 int i;
1759
1760 if (!mMenuEnabled) {
1761 event.Skip();
1762 return;
1763 }
1764
1765 SetFocus();
1766
1767 int currentSelection = -1;
1768 for (i = 0; i < GetNumBuiltins(); i++) {
1769 menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i).Translation());
1770 if (mFormatString == GetBuiltinFormat(i)) {
1771 menu.Check(ID_MENU + i, true);
1772 currentSelection = i;
1773 }
1774 }
1775
1776 menu.Bind(wxEVT_MENU, [](auto&){});
1777 BasicMenu::Handle{ &menu }.Popup(
1779 { 0, 0 }
1780 );
1781
1782 // This used to be in an EVT_MENU() event handler, but GTK
1783 // is sensitive to what is done within the handler if the
1784 // user happens to check the first menuitem and then is
1785 // moving down the menu when the ...CTRL_UPDATED event
1786 // handler kicks in.
1787 for (i = 0; i < GetNumBuiltins(); i++) {
1788 if (menu.IsChecked(ID_MENU + i) && i != currentSelection) {
1790
1791 int eventType = 0;
1792 switch (mType) {
1794 eventType = EVT_TIMETEXTCTRL_UPDATED;
1795 break;
1797 eventType = EVT_FREQUENCYTEXTCTRL_UPDATED;
1798 break;
1800 eventType = EVT_BANDWIDTHTEXTCTRL_UPDATED;
1801 break;
1802 default:
1803 wxASSERT(false);
1804 break;
1805 }
1806
1807 wxCommandEvent e(eventType, GetId());
1808 e.SetInt(i);
1809 e.SetString(GetBuiltinName(i).Internal());
1810 GetParent()->GetEventHandler()->AddPendingEvent(e);
1811 }
1812 }
1813
1814}
@ 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 1703 of file NumericTextCtrl.cpp.

1704{
1705 // Ignore it to prevent flashing
1706}

◆ OnFocus()

void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 1856 of file NumericTextCtrl.cpp.

1857{
1858 KeyboardCapture::OnFocus( *this, event );
1859
1860 if (event.GetEventType() != wxEVT_KILL_FOCUS &&
1861 mFocusedDigit <= 0 )
1863
1864 event.Skip( false ); // PRL: not sure why, but preserving old behavior
1865}
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 1919 of file NumericTextCtrl.cpp.

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

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

References Updated().

Here is the call graph for this function:

◆ OnMouse()

void NumericTextCtrl::OnMouse ( wxMouseEvent &  event)
private

Definition at line 1816 of file NumericTextCtrl.cpp.

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

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

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

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 2048 of file NumericTextCtrl.cpp.

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

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 1445 of file NumericTextCtrl.cpp.

1446{
1447 return
1448 SetFormatString(GetBuiltinFormat(formatName));
1449}

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 1451 of file NumericTextCtrl.cpp.

1452{
1453 auto result =
1455 if (result) {
1456 Layout();
1457 Fit();
1461 }
1462 return result;
1463}
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 1512 of file NumericTextCtrl.cpp.

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

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 1422 of file NumericTextCtrl.cpp.

1423{
1424 wxControl::SetName( name.Translation() );
1425}
const TranslatableString name
Definition: Distortion.cpp:82
wxString Translation() const

References name, and TranslatableString::Translation().

Referenced by LV2Validator::BuildPlain(), VSTEffect::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 1489 of file NumericTextCtrl.cpp.

1490{
1491 mReadOnly = readOnly;
1492}

References mReadOnly.

Referenced by TimeToolBar::Populate().

Here is the caller graph for this function:

◆ SetSampleRate()

void NumericTextCtrl::SetSampleRate ( double  sampleRate)

Definition at line 1465 of file NumericTextCtrl.cpp.

1466{
1468 Layout();
1469 Fit();
1472}
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 1430 of file NumericTextCtrl.cpp.

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

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 2066 of file NumericTextCtrl.cpp.

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

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 2100 of file NumericTextCtrl.cpp.

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