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

#include <NumericTextCtrl.h>

Inheritance diagram for NumericTextCtrl:
NumericConverter

Classes

struct  Options
 

Public Member Functions

 NumericTextCtrl (wxWindow *parent, wxWindowID winid, NumericConverter::Type type, const wxString &formatName=wxEmptyString, double value=0.0, double sampleRate=44100, const Options &options={}, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~NumericTextCtrl ()
 
bool Layout () override
 
void Fit () override
 
void SetSampleRate (double sampleRate)
 
void SetValue (double newValue)
 
void SetFormatString (const wxString &formatString)
 
void SetFormatName (const wxString &formatName)
 
void SetFieldFocus (int)
 
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 wxString &formatName=wxEmptyString, double value=0.0f, double sampleRate=1.0f)
 
virtual ~NumericConverter ()
 
virtual void ValueToControls (double rawValue, bool nearest=true)
 
virtual void ParseFormatString (const wxString &format)
 
void PrintDebugInfo ()
 
void SetFormatName (const wxString &formatName)
 
void SetFormatString (const wxString &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 ()
 
wxString GetFormatString ()
 
int GetFormatIndex ()
 
int GetNumBuiltins ()
 
wxString GetBuiltinName (const int index)
 
wxString GetBuiltinFormat (const int index)
 
wxString GetBuiltinFormat (const wxString &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, FREQUENCY, BANDWIDTH }
 
- Protected Attributes inherited from NumericConverter
Type mType
 
double mValue
 
double mMinValue
 
double mMaxValue
 
double mInvalidValue
 
wxString mFormatString
 
std::vector< NumericFieldmFields
 
wxString mPrefix
 
wxString mValueTemplate
 
wxString mValueMask
 
wxString mValueString
 
double mScalingFactor
 
double mSampleRate
 
bool mNtscDrop
 
int mFocusedDigit
 
std::vector< DigitInfomDigits
 
const std::vector
< BuiltinFormatString > & 
mBuiltinFormatStrings
 
int mNBuiltins
 
int mDefaultNdx
 

Detailed Description

Definition at line 138 of file NumericTextCtrl.h.

Constructor & Destructor Documentation

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

Definition at line 1242 of file NumericTextCtrl.cpp.

1249  :
1250  wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
1251  NumericConverter(type, formatName, timeValue, sampleRate),
1253  mDigitFont{},
1254  mLabelFont{},
1255  mLastField(1),
1256  mAutoPos(options.autoPos)
1257  , mType(type)
1258 {
1259  mAllowInvalidValue = false;
1260 
1261  mDigitBoxW = 10;
1262  mDigitBoxH = 16;
1263 
1264  mReadOnly = options.readOnly;
1265  mMenuEnabled = options.menuEnabled;
1266  mButtonWidth = 9;
1267 
1268  Layout();
1269  Fit();
1270  ValueToControls();
1271  //PRL -- would this fix the following?
1272  //ValueToControls();
1273 
1274  //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
1275  //ControlsToValue();
1276 
1277  mScrollRemainder = 0.0;
1278 
1279 #if wxUSE_ACCESSIBILITY
1280  SetLabel(wxT(""));
1281  SetName(wxT(""));
1282  SetAccessible(safenew NumericTextCtrlAx(this));
1283 #endif
1284 
1285  if (options.hasInvalidValue)
1286  SetInvalidValue( options.invalidValue );
1287 
1288  if (!options.format.empty())
1289  SetFormatString( options.format );
1290 
1291  if (options.hasValue)
1292  SetValue( options.value );
1293 }
std::unique_ptr< wxFont > mDigitFont
std::unique_ptr< wxBitmap > mBackgroundBitmap
std::unique_ptr< wxFont > mLabelFont
NumericConverter(Type type, const wxString &formatName=wxEmptyString, double value=0.0f, double sampleRate=1.0f)
void SetFormatString(const wxString &formatString)
#define safenew
Definition: Audacity.h:223
void ValueToControls() override
void SetValue(double newValue)
void SetInvalidValue(double invalidValue)
void Fit() override
bool Layout() override
friend class NumericTextCtrlAx
NumericConverter::Type mType
NumericTextCtrl::~NumericTextCtrl ( )
virtual

Definition at line 1295 of file NumericTextCtrl.cpp.

1296 {
1297 }

Member Function Documentation

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1917 of file NumericTextCtrl.cpp.

References NumericConverter::ControlsToValue().

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

1918 {
1920 }
virtual void ControlsToValue()
void NumericTextCtrl::EnableMenu ( bool  enable = true)

Definition at line 1353 of file NumericTextCtrl.cpp.

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

1354 {
1355 #if wxUSE_TOOLTIPS
1356  wxString tip(_("(Use context menu to change format.)"));
1357  if (enable)
1358  SetToolTip(tip);
1359  else {
1360  wxToolTip *tt = GetToolTip();
1361  if (tt && tt->GetTip() == tip)
1362  SetToolTip(NULL);
1363  }
1364 #endif
1365  mMenuEnabled = enable;
1366  mButtonWidth = enable ? 9 : 0;
1367  Layout();
1368  Fit();
1369 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void Fit() override
bool Layout() override
void NumericTextCtrl::Fit ( )
override

Definition at line 1496 of file NumericTextCtrl.cpp.

References mButtonWidth, mHeight, and mWidth.

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

1497 {
1498  wxSize sz = GetSize();
1499  wxSize csz = GetClientSize();
1500 
1501  sz.x = mButtonWidth + mWidth + (sz.x - csz.x);
1502  sz.y = mHeight + (sz.y - csz.y);
1503 
1504  SetInitialSize(sz);
1505 }
int NumericTextCtrl::GetFocusedDigit ( )
inline

Definition at line 198 of file NumericTextCtrl.h.

References NumericConverter::mFocusedDigit.

198 { return mFocusedDigit; }
int NumericTextCtrl::GetFocusedField ( )
inline

Definition at line 197 of file NumericTextCtrl.h.

References mLastField.

197 { return mLastField; }
bool NumericTextCtrl::Layout ( )
override

Definition at line 1380 of file NumericTextCtrl.cpp.

References AColor::Arrow(), AColor::Bevel(), ThemeBase::Colour(), label, mBackgroundBitmap, mBorderBottom, mBorderLeft, mBorderRight, mBorderTop, mButtonWidth, mDigitBoxH, mDigitBoxW, mDigitFont, mDigitH, NumericConverter::mDigits, mDigitW, NumericConverter::mFields, mHeight, mLabelFont, mMenuEnabled, NumericConverter::mPrefix, mWidth, ThemeBase::SetBrushColour(), and theTheme.

Referenced by EnableMenu(), SpectralSelectionBar::Populate(), SetFormatString(), and SetSampleRate().

1381 {
1382  unsigned int i, j;
1383  int x, pos;
1384 
1385  wxMemoryDC memDC;
1386 
1387  // Placeholder bitmap so the memDC has something to reference
1388  mBackgroundBitmap = std::make_unique<wxBitmap>(1, 1);
1389  memDC.SelectObject(*mBackgroundBitmap);
1390 
1391  mDigits.clear();
1392 
1393  mBorderLeft = 1;
1394  mBorderTop = 1;
1395  mBorderRight = 1;
1396  mBorderBottom = 1;
1397 
1398  int fontSize = 4;
1399  wxCoord strW, strH;
1400  wxString exampleText = wxT("0");
1401 
1402  // Keep making the font bigger until it's too big, then subtract one.
1403  memDC.SetFont(wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
1404  memDC.GetTextExtent(exampleText, &strW, &strH);
1405  while (strW <= mDigitBoxW && strH <= mDigitBoxH) {
1406  fontSize++;
1407  memDC.SetFont(wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
1408  memDC.GetTextExtent(exampleText, &strW, &strH);
1409  }
1410  fontSize--;
1411 
1412  mDigitFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1413  memDC.SetFont(*mDigitFont);
1414  memDC.GetTextExtent(exampleText, &strW, &strH);
1415  mDigitW = strW;
1416  mDigitH = strH;
1417 
1418  // The label font should be a little smaller
1419  fontSize--;
1420  mLabelFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1421 
1422  // Figure out the x-position of each field and label in the box
1423  x = mBorderLeft;
1424  pos = 0;
1425 
1426  memDC.SetFont(*mLabelFont);
1427  memDC.GetTextExtent(mPrefix, &strW, &strH);
1428  x += strW;
1429  pos += mPrefix.Length();
1430 
1431  for(i = 0; i < mFields.size(); i++) {
1432  mFields[i].fieldX = x;
1433  for(j=0; j<(unsigned int)mFields[i].digits; j++) {
1434  mDigits.push_back(DigitInfo(i, j, pos, wxRect(x, mBorderTop,
1435  mDigitBoxW, mDigitBoxH)));
1436  x += mDigitBoxW;
1437  pos++;
1438  }
1439 
1440  mFields[i].labelX = x;
1441  memDC.GetTextExtent(mFields[i].label, &strW, &strH);
1442  pos += mFields[i].label.Length();
1443  x += strW;
1444  mFields[i].fieldW = x;
1445  }
1446 
1447  mWidth = x + mBorderRight;
1449 
1450  // Draw the background bitmap - it contains black boxes where
1451  // all of the digits go and all of the other text
1452 
1453  wxBrush Brush;
1454 
1455  mBackgroundBitmap = std::make_unique<wxBitmap>(mWidth + mButtonWidth, mHeight);
1456  memDC.SelectObject(*mBackgroundBitmap);
1457 
1458  theTheme.SetBrushColour( Brush, clrTimeHours );
1459  memDC.SetBrush(Brush);
1460  memDC.SetPen(*wxTRANSPARENT_PEN);
1461  memDC.DrawRectangle(0, 0, mWidth + mButtonWidth, mHeight);
1462 
1463  int numberBottom = mBorderTop + (mDigitBoxH - mDigitH)/2 + mDigitH;
1464 
1465  memDC.GetTextExtent(wxT("0"), &strW, &strH);
1466  int labelTop = numberBottom - strH;
1467 
1468  memDC.SetTextForeground(theTheme.Colour( clrTimeFont ));
1469  memDC.SetTextBackground(theTheme.Colour( clrTimeBack ));
1470  memDC.DrawText(mPrefix, mBorderLeft, labelTop);
1471 
1472  theTheme.SetBrushColour( Brush, clrTimeBack );
1473  memDC.SetBrush(Brush);
1474  //memDC.SetBrush(*wxLIGHT_GREY_BRUSH);
1475  for(i = 0; i < mDigits.size(); i++)
1476  memDC.DrawRectangle(mDigits[i].digitBox);
1477  memDC.SetBrush( wxNullBrush );
1478 
1479  for(i = 0; i < mFields.size(); i++)
1480  memDC.DrawText(mFields[i].label,
1481  mFields[i].labelX, labelTop);
1482 
1483  if (mMenuEnabled) {
1484  wxRect r(mWidth, 0, mButtonWidth - 1, mHeight - 1);
1485  AColor::Bevel(memDC, true, r);
1486  memDC.SetBrush(*wxBLACK_BRUSH);
1487  memDC.SetPen(*wxBLACK_PEN);
1488  AColor::Arrow(memDC,
1489  mWidth + 1,
1490  (mHeight / 2) - 2,
1491  mButtonWidth - 2);
1492  }
1493  return true;
1494 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
std::vector< NumericField > mFields
std::unique_ptr< wxFont > mDigitFont
std::unique_ptr< wxBitmap > mBackgroundBitmap
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:96
wxString label
Definition: Tags.cpp:727
std::unique_ptr< wxFont > mLabelFont
std::vector< DigitInfo > mDigits
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:202
void SetBrushColour(wxBrush &Brush, int iIndex)
Definition: Theme.cpp:1215
DigitInfo is a class used in NumericTextCtrl.
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1208
void NumericTextCtrl::OnCaptureKey ( wxCommandEvent &  event)
private

Definition at line 1668 of file NumericTextCtrl.cpp.

1669 {
1670  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
1671  int keyCode = kevent->GetKeyCode();
1672 
1673  // Convert numeric keypad entries.
1674  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1675  keyCode -= WXK_NUMPAD0 - '0';
1676 
1677  switch (keyCode)
1678  {
1679  case WXK_BACK:
1680  case WXK_LEFT:
1681  case WXK_RIGHT:
1682  case WXK_HOME:
1683  case WXK_END:
1684  case WXK_UP:
1685  case WXK_DOWN:
1686  case WXK_TAB:
1687  case WXK_RETURN:
1688  case WXK_NUMPAD_ENTER:
1689  case WXK_DELETE:
1690  return;
1691 
1692  default:
1693  if (keyCode >= '0' && keyCode <= '9')
1694  return;
1695  }
1696 
1697  event.Skip();
1698 
1699  return;
1700 }
void NumericTextCtrl::OnContext ( wxContextMenuEvent &  event)
private

Definition at line 1559 of file NumericTextCtrl.cpp.

References NumericConverter::BANDWIDTH, NumericConverter::FREQUENCY, NumericConverter::GetBuiltinFormat(), NumericConverter::GetBuiltinName(), NumericConverter::GetNumBuiltins(), ID_MENU, NumericConverter::mFormatString, mMenuEnabled, mType, SetFormatString(), and NumericConverter::TIME.

Referenced by OnMouse().

1560 {
1561  wxMenu menu;
1562  int i;
1563 
1564  if (!mMenuEnabled) {
1565  event.Skip();
1566  return;
1567  }
1568 
1569  SetFocus();
1570 
1571  int currentSelection = -1;
1572  for (i = 0; i < GetNumBuiltins(); i++) {
1573  menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i));
1574  if (mFormatString == GetBuiltinFormat(i)) {
1575  menu.Check(ID_MENU + i, true);
1576  currentSelection = i;
1577  }
1578  }
1579 
1580  PopupMenu(&menu, wxPoint(0, 0));
1581 
1582  // This used to be in an EVT_MENU() event handler, but GTK
1583  // is sensitive to what is done within the handler if the
1584  // user happens to check the first menuitem and then is
1585  // moving down the menu when the ...CTRL_UPDATED event
1586  // handler kicks in.
1587  for (i = 0; i < GetNumBuiltins(); i++) {
1588  if (menu.IsChecked(ID_MENU + i) && i != currentSelection) {
1590 
1591  int eventType = 0;
1592  switch (mType) {
1594  eventType = EVT_TIMETEXTCTRL_UPDATED;
1595  break;
1597  eventType = EVT_FREQUENCYTEXTCTRL_UPDATED;
1598  break;
1600  eventType = EVT_BANDWIDTHTEXTCTRL_UPDATED;
1601  break;
1602  default:
1603  wxASSERT(false);
1604  break;
1605  }
1606 
1607  wxCommandEvent e(eventType, GetId());
1608  e.SetInt(i);
1609  e.SetString(GetBuiltinName(i));
1610  GetParent()->GetEventHandler()->AddPendingEvent(e);
1611  }
1612  }
1613 
1614 }
void SetFormatString(const wxString &formatString)
#define ID_MENU
wxString GetBuiltinFormat(const int index)
wxString GetBuiltinName(const int index)
NumericConverter::Type mType
void NumericTextCtrl::OnErase ( wxEraseEvent &  event)
private

Definition at line 1507 of file NumericTextCtrl.cpp.

1508 {
1509  // Ignore it to prevent flashing
1510 }
void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 1656 of file NumericTextCtrl.cpp.

References AudacityProject::CaptureKeyboard(), and AudacityProject::ReleaseKeyboard().

1657 {
1658  if (event.GetEventType() == wxEVT_KILL_FOCUS) {
1660  }
1661  else {
1663  }
1664 
1665  Refresh(false);
1666 }
static void CaptureKeyboard(wxWindow *handler)
Definition: Project.cpp:5780
static void ReleaseKeyboard(wxWindow *handler)
Definition: Project.cpp:5791
void NumericTextCtrl::OnKeyDown ( wxKeyEvent &  event)
private

Definition at line 1720 of file NumericTextCtrl.cpp.

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

1721 {
1722  if (mDigits.size() == 0)
1723  {
1724  mFocusedDigit = 0;
1725  return;
1726  }
1727 
1728  event.Skip(false);
1729 
1730  int keyCode = event.GetKeyCode();
1731  int digit = mFocusedDigit;
1732 
1733  if (mFocusedDigit < 0)
1734  mFocusedDigit = 0;
1735  if (mFocusedDigit >= (int)mDigits.size())
1736  mFocusedDigit = mDigits.size() - 1;
1737 
1738  // Convert numeric keypad entries.
1739  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1740  keyCode -= WXK_NUMPAD0 - '0';
1741 
1742  if (!mReadOnly && (keyCode >= '0' && keyCode <= '9')) {
1743  int digitPosition = mDigits[mFocusedDigit].pos;
1744  if (mValueString[digitPosition] == wxChar('-')) {
1745  mValue = std::max(mMinValue, std::min(mMaxValue, 0.0));
1746  ValueToControls();
1747  // Beware relocation of the string
1748  digitPosition = mDigits[mFocusedDigit].pos;
1749  }
1750  mValueString[digitPosition] = wxChar(keyCode);
1751  ControlsToValue();
1752  Refresh();// Force an update of the control. [Bug 1497]
1753  ValueToControls();
1754  mFocusedDigit = (mFocusedDigit + 1) % (mDigits.size());
1755  Updated();
1756  }
1757 
1758  else if (!mReadOnly && keyCode == WXK_DELETE) {
1759  if (mAllowInvalidValue)
1761  }
1762 
1763  else if (!mReadOnly && keyCode == WXK_BACK) {
1764  // Moves left, replaces that char with '0', stays there...
1765  mFocusedDigit--;
1766  mFocusedDigit += mDigits.size();
1767  mFocusedDigit %= mDigits.size();
1768  wxString::reference theDigit = mValueString[mDigits[mFocusedDigit].pos];
1769  if (theDigit != wxChar('-'))
1770  theDigit = '0';
1771  ControlsToValue();
1772  Refresh();// Force an update of the control. [Bug 1497]
1773  ValueToControls();
1774  Updated();
1775  }
1776 
1777  else if (keyCode == WXK_LEFT) {
1778  mFocusedDigit--;
1779  mFocusedDigit += mDigits.size();
1780  mFocusedDigit %= mDigits.size();
1781  Refresh();
1782  }
1783 
1784  else if (keyCode == WXK_RIGHT) {
1785  mFocusedDigit++;
1786  mFocusedDigit %= mDigits.size();
1787  Refresh();
1788  }
1789 
1790  else if (keyCode == WXK_HOME) {
1791  mFocusedDigit = 0;
1792  Refresh();
1793  }
1794 
1795  else if (keyCode == WXK_END) {
1796  mFocusedDigit = mDigits.size() - 1;
1797  Refresh();
1798  }
1799 
1800  else if (!mReadOnly && keyCode == WXK_UP) {
1801  Adjust(1, 1);
1802  Updated();
1803  }
1804 
1805  else if (!mReadOnly && keyCode == WXK_DOWN) {
1806  Adjust(1, -1);
1807  Updated();
1808  }
1809 
1810  else if (keyCode == WXK_TAB) {
1811 #if defined(__WXMSW__)
1812  // Using Navigate() on Windows, rather than the following code causes
1813  // bug 1542
1814  wxWindow* parent = GetParent();
1815  wxNavigationKeyEvent nevent;
1816  nevent.SetWindowChange(event.ControlDown());
1817  nevent.SetDirection(!event.ShiftDown());
1818  nevent.SetEventObject(parent);
1819  nevent.SetCurrentFocus(parent);
1820  GetParent()->GetEventHandler()->ProcessEvent(nevent);
1821 #else
1822  Navigate(event.ShiftDown()
1823  ? wxNavigationKeyEvent::IsBackward
1824  : wxNavigationKeyEvent::IsForward);
1825 #endif
1826  }
1827 
1828  else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) {
1829  wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
1830  wxWindow *def = tlw->GetDefaultItem();
1831  if (def && def->IsEnabled()) {
1832  wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
1833  def->GetId());
1834  GetParent()->GetEventHandler()->ProcessEvent(cevent);
1835  }
1836  }
1837 
1838  else {
1839  event.Skip();
1840  return;
1841  }
1842 
1843  if (digit != mFocusedDigit) {
1845  }
1846 }
void Adjust(int steps, int dir)
std::vector< DigitInfo > mDigits
void ValueToControls() override
int min(int a, int b)
void Updated(bool keyup=false)
void ControlsToValue() override
void SetValue(double newValue)
void NumericTextCtrl::OnKeyUp ( wxKeyEvent &  event)
private

Definition at line 1702 of file NumericTextCtrl.cpp.

References Updated().

1703 {
1704  int keyCode = event.GetKeyCode();
1705 
1706  event.Skip(true);
1707 
1708  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1709  keyCode -= WXK_NUMPAD0 - '0';
1710 
1711  if ((keyCode >= '0' && keyCode <= '9') ||
1712  (keyCode == WXK_DELETE) ||
1713  (keyCode == WXK_BACK) ||
1714  (keyCode == WXK_UP) ||
1715  (keyCode == WXK_DOWN)) {
1716  Updated(true);
1717  }
1718 }
void Updated(bool keyup=false)
void NumericTextCtrl::OnMouse ( wxMouseEvent &  event)
private

Definition at line 1616 of file NumericTextCtrl.cpp.

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

1617 {
1618  if (event.LeftDown() && event.GetX() >= mWidth) {
1619  wxContextMenuEvent e;
1620  OnContext(e);
1621  }
1622  else if (event.LeftDown()) {
1623  SetFocus();
1624 
1625  int bestDist = 9999;
1626  unsigned int i;
1627 
1628  mFocusedDigit = 0;
1629  for(i = 0; i < mDigits.size(); i++) {
1630  int dist = abs(event.m_x - (mDigits[i].digitBox.x +
1631  mDigits[i].digitBox.width/2));
1632  if (dist < bestDist) {
1633  mFocusedDigit = i;
1634  bestDist = dist;
1635  }
1636  }
1637 
1638  Refresh(false);
1639  }
1640  else if (event.RightDown() && mMenuEnabled) {
1641  wxContextMenuEvent e;
1642  OnContext(e);
1643  }
1644  else if(!mReadOnly && event.m_wheelRotation != 0 ) {
1645  double steps = event.m_wheelRotation /
1646  (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0) +
1648  mScrollRemainder = steps - floor(steps);
1649  steps = floor(steps);
1650 
1651  Adjust((int)fabs(steps), steps < 0.0 ? -1 : 1);
1652  Updated();
1653  }
1654 }
void Adjust(int steps, int dir)
void OnContext(wxContextMenuEvent &event)
std::vector< DigitInfo > mDigits
void Updated(bool keyup=false)
void NumericTextCtrl::OnPaint ( wxPaintEvent &  event)
private

Definition at line 1512 of file NumericTextCtrl.cpp.

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

1513 {
1514  wxPaintDC dc(this);
1515  bool focused = (FindFocus() == this);
1516 
1517  dc.DrawBitmap(*mBackgroundBitmap, 0, 0);
1518 
1519  wxPen Pen;
1520  wxBrush Brush;
1521  if (focused) {
1522  theTheme.SetPenColour( Pen, clrTimeFontFocus );
1523  dc.SetPen(Pen);
1524  dc.SetBrush(*wxTRANSPARENT_BRUSH);
1525  dc.DrawRectangle(0, 0, mWidth, mHeight);
1526  dc.SetPen( wxNullPen );
1527  }
1528 
1529  dc.SetFont(*mDigitFont);
1530  dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1531  dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1532 
1533  dc.SetPen(*wxTRANSPARENT_PEN);
1534  theTheme.SetBrushColour( Brush , clrTimeBackFocus );
1535  dc.SetBrush( Brush );
1536 
1537  int i;
1538  for(i = 0; i < (int)mDigits.size(); i++) {
1539  wxRect box = mDigits[i].digitBox;
1540  if (focused && mFocusedDigit == i) {
1541  dc.DrawRectangle(box);
1542  dc.SetTextForeground(theTheme.Colour( clrTimeFontFocus ));
1543  dc.SetTextBackground(theTheme.Colour( clrTimeBackFocus ));
1544  }
1545  int pos = mDigits[i].pos;
1546  wxString digit = mValueString.Mid(pos, 1);
1547  int x = box.x + (mDigitBoxW - mDigitW)/2;
1548  int y = box.y + (mDigitBoxH - mDigitH)/2;
1549  dc.DrawText(digit, x, y);
1550  if (focused && mFocusedDigit == i) {
1551  dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1552  dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1553  }
1554  }
1555  dc.SetPen( wxNullPen );
1556  dc.SetBrush( wxNullBrush );
1557 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
std::unique_ptr< wxFont > mDigitFont
std::unique_ptr< wxBitmap > mBackgroundBitmap
std::vector< DigitInfo > mDigits
void SetBrushColour(wxBrush &Brush, int iIndex)
Definition: Theme.cpp:1215
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1208
void SetPenColour(wxPen &Pen, int iIndex)
Definition: Theme.cpp:1221
void NumericTextCtrl::SetFieldFocus ( int  digit)

Definition at line 1848 of file NumericTextCtrl.cpp.

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

Referenced by OnKeyDown(), and Updated().

1849 {
1850 #if wxUSE_ACCESSIBILITY
1851  if (mDigits.size() == 0)
1852  {
1853  mFocusedDigit = 0;
1854  return;
1855  }
1856  mFocusedDigit = digit;
1857  mLastField = mDigits[mFocusedDigit].field + 1;
1858 
1859  // This looks strange (and it is), but it was the only way I could come
1860  // up with that allowed Jaws, Window-Eyes, and NVDA to read the control
1861  // somewhat the same. See NumericTextCtrlAx below for even more odd looking
1862  // hackery.
1863  //
1864  // If you change SetFieldFocus(), Updated(), or NumericTextCtrlAx, make sure
1865  // you test with Jaws, Window-Eyes, and NVDA.
1866  GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
1867  this,
1868  wxOBJID_CLIENT,
1869  0);
1870  GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
1871  this,
1872  wxOBJID_CLIENT,
1873  mFocusedDigit + 1);
1874 #endif
1875 }
std::vector< DigitInfo > mDigits
void NumericTextCtrl::SetFormatName ( const wxString &  formatName)
void NumericTextCtrl::SetFormatString ( const wxString &  formatString)

Definition at line 1322 of file NumericTextCtrl.cpp.

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

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

1323 {
1324  NumericConverter::SetFormatString(formatString);
1325  Layout();
1326  Fit();
1327  ValueToControls();
1328  ControlsToValue();
1329  UpdateAutoFocus();
1330 }
void SetFormatString(const wxString &formatString)
void ValueToControls() override
void ControlsToValue() override
void Fit() override
bool Layout() override
void NumericTextCtrl::SetInvalidValue ( double  invalidValue)

Definition at line 1371 of file NumericTextCtrl.cpp.

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

1372 {
1373  const bool wasInvalid = mAllowInvalidValue && (mValue == mInvalidValue);
1374  mAllowInvalidValue = true;
1375  mInvalidValue = invalidValue;
1376  if (wasInvalid)
1377  SetValue(invalidValue);
1378 }
void SetValue(double newValue)
void NumericTextCtrl::SetReadOnly ( bool  readOnly = true)

Definition at line 1348 of file NumericTextCtrl.cpp.

References mReadOnly.

1349 {
1350  mReadOnly = readOnly;
1351 }
void NumericTextCtrl::SetSampleRate ( double  sampleRate)

Definition at line 1332 of file NumericTextCtrl.cpp.

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

Referenced by TimeDialog::TransferDataToWindow().

1333 {
1334  NumericConverter::SetSampleRate(sampleRate);
1335  Layout();
1336  Fit();
1337  ValueToControls();
1338  ControlsToValue();
1339 }
void ValueToControls() override
void ControlsToValue() override
void Fit() override
bool Layout() override
void SetSampleRate(double sampleRate)
void NumericTextCtrl::SetValue ( double  newValue)
void NumericTextCtrl::UpdateAutoFocus ( )
private

Definition at line 1302 of file NumericTextCtrl.cpp.

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

Referenced by SetFormatString().

1303 {
1304  if (!mAutoPos)
1305  return;
1306 
1307  mFocusedDigit = 0;
1308  while (mFocusedDigit < ((int)mDigits.size() - 1)) {
1309  wxChar dgt = mValueString[mDigits[mFocusedDigit].pos];
1310  if (dgt != '0') {
1311  break;
1312  }
1313  mFocusedDigit++;
1314  }
1315 }
std::vector< DigitInfo > mDigits
void NumericTextCtrl::Updated ( bool  keyup = false)
private

Definition at line 1877 of file NumericTextCtrl.cpp.

References NumericConverter::mFocusedDigit, SetFieldFocus(), and wxEVT_COMMAND_TEXT_UPDATED.

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

1878 {
1879  wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
1880 
1881  // This will give listeners the ability to do tasks when the
1882  // update has been completed, like when the UP ARROW has been
1883  // held down and is finally released.
1884  event.SetInt(keyup);
1885  event.SetEventObject(this);
1886  GetEventHandler()->ProcessEvent(event);
1887 
1888 #if wxUSE_ACCESSIBILITY
1889  if (!keyup) {
1890  GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
1891  this,
1892  wxOBJID_CLIENT,
1893  mFocusedDigit + 1);
1895  }
1896 #endif
1897 }
wxEVT_COMMAND_TEXT_UPDATED
Definition: Nyquist.cpp:109
void NumericTextCtrl::ValueToControls ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1899 of file NumericTextCtrl.cpp.

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

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

1900 {
1901  const wxString previousValueString = mValueString;
1903  if (mValueString != previousValueString) {
1904  // Doing this only when needed is an optimization.
1905  // NumerixTextCtrls are used in the selection bar at the bottom
1906  // of Audacity, and are updated at high frequency through
1907  // SetValue() when Audacity is playing. This consumes a
1908  // significant amount of CPU. Typically, when a track is
1909  // playing, only one of the NumericTextCtrl actually changes
1910  // (the audio position). We save CPU by updating the control
1911  // only when needed.
1912  Refresh(false);
1913  }
1914 }
virtual void ValueToControls()

Friends And Related Function Documentation

friend class NumericTextCtrlAx
friend

Definition at line 140 of file NumericTextCtrl.h.

Member Data Documentation

bool NumericTextCtrl::mAllowInvalidValue
private

Definition at line 252 of file NumericTextCtrl.h.

Referenced by OnKeyDown(), and SetInvalidValue().

bool NumericTextCtrl::mAutoPos
private

Definition at line 245 of file NumericTextCtrl.h.

Referenced by UpdateAutoFocus().

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

Definition at line 227 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mBorderBottom
private

Definition at line 237 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderLeft
private

Definition at line 234 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderRight
private

Definition at line 236 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderTop
private

Definition at line 235 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mButtonWidth
private

Definition at line 240 of file NumericTextCtrl.h.

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

int NumericTextCtrl::mDigitBoxH
private

Definition at line 231 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitBoxW
private

Definition at line 230 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

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

Definition at line 229 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitH
private

Definition at line 233 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitW
private

Definition at line 232 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mHeight
private

Definition at line 239 of file NumericTextCtrl.h.

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

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

Definition at line 229 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mLastField
private

Definition at line 242 of file NumericTextCtrl.h.

Referenced by GetFocusedField(), and SetFieldFocus().

bool NumericTextCtrl::mMenuEnabled
private

Definition at line 224 of file NumericTextCtrl.h.

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

bool NumericTextCtrl::mReadOnly
private

Definition at line 225 of file NumericTextCtrl.h.

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

double NumericTextCtrl::mScrollRemainder
private

Definition at line 248 of file NumericTextCtrl.h.

Referenced by OnMouse().

NumericConverter::Type NumericTextCtrl::mType
private

Definition at line 250 of file NumericTextCtrl.h.

Referenced by OnContext().

int NumericTextCtrl::mWidth
private

Definition at line 238 of file NumericTextCtrl.h.

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


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