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 NumericFormatId &formatName={}, 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 NumericFormatId &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 NumericFormatId &formatName={}, double value=0.0f, double sampleRate=1.0f)
 
virtual ~NumericConverter ()
 
virtual void ValueToControls (double rawValue, bool nearest=true)
 
void PrintDebugInfo ()
 
void SetFormatName (const NumericFormatId &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 ()
 
int GetFormatIndex ()
 
int GetNumBuiltins ()
 
NumericFormatId GetBuiltinName (const int index)
 
wxString GetBuiltinFormat (const int index)
 
wxString GetBuiltinFormat (const NumericFormatId &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 }
 
- Static Public Member Functions inherited from NumericConverter
static NumericFormatId DefaultSelectionFormat ()
 
static NumericFormatId TimeAndSampleFormat ()
 
static NumericFormatId SecondsFormat ()
 
static NumericFormatId HundredthsFormat ()
 
static NumericFormatId HertzFormat ()
 
static NumericFormatId LookupFormat (Type type, const wxString &id)
 
- 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 BuiltinFormatStringmBuiltinFormatStrings
 
const size_t mNBuiltins
 
int mDefaultNdx
 

Detailed Description

Definition at line 152 of file NumericTextCtrl.h.

Constructor & Destructor Documentation

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

Definition at line 1210 of file NumericTextCtrl.cpp.

1217  :
1218  wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
1219  NumericConverter(type, formatName, timeValue, sampleRate),
1221  mDigitFont{},
1222  mLabelFont{},
1223  mLastField(1),
1224  mAutoPos(options.autoPos)
1225  , mType(type)
1226 {
1227  mAllowInvalidValue = false;
1228 
1229  mDigitBoxW = 10;
1230  mDigitBoxH = 16;
1231 
1232  mReadOnly = options.readOnly;
1233  mMenuEnabled = options.menuEnabled;
1234  mButtonWidth = 9;
1235 
1236  Layout();
1237  Fit();
1238  ValueToControls();
1239  //PRL -- would this fix the following?
1240  //ValueToControls();
1241 
1242  //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
1243  //ControlsToValue();
1244 
1245  mScrollRemainder = 0.0;
1246 
1247 #if wxUSE_ACCESSIBILITY
1248  SetLabel(wxT(""));
1249  SetName(wxT(""));
1250  SetAccessible(safenew NumericTextCtrlAx(this));
1251 #endif
1252 
1253  if (options.hasInvalidValue)
1254  SetInvalidValue( options.invalidValue );
1255 
1256  if (!options.format.empty())
1257  SetFormatString( options.format );
1258 
1259  if (options.hasValue)
1260  SetValue( options.value );
1261 }
std::unique_ptr< wxFont > mDigitFont
std::unique_ptr< wxBitmap > mBackgroundBitmap
std::unique_ptr< wxFont > mLabelFont
NumericConverter(Type type, const NumericFormatId &formatName={}, double value=0.0f, double sampleRate=1.0f)
void SetFormatString(const wxString &formatString)
#define safenew
Definition: Audacity.h:230
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 1263 of file NumericTextCtrl.cpp.

1264 {
1265 }

Member Function Documentation

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1883 of file NumericTextCtrl.cpp.

References NumericConverter::ControlsToValue().

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

1884 {
1886 }
virtual void ControlsToValue()
void NumericTextCtrl::EnableMenu ( bool  enable = true)

Definition at line 1321 of file NumericTextCtrl.cpp.

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

1322 {
1323 #if wxUSE_TOOLTIPS
1324  wxString tip(_("(Use context menu to change format.)"));
1325  if (enable)
1326  SetToolTip(tip);
1327  else {
1328  wxToolTip *tt = GetToolTip();
1329  if (tt && tt->GetTip() == tip)
1330  SetToolTip(NULL);
1331  }
1332 #endif
1333  mMenuEnabled = enable;
1334  mButtonWidth = enable ? 9 : 0;
1335  Layout();
1336  Fit();
1337 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void Fit() override
bool Layout() override
void NumericTextCtrl::Fit ( )
override

Definition at line 1464 of file NumericTextCtrl.cpp.

References mButtonWidth, mHeight, and mWidth.

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

1465 {
1466  wxSize sz = GetSize();
1467  wxSize csz = GetClientSize();
1468 
1469  sz.x = mButtonWidth + mWidth + (sz.x - csz.x);
1470  sz.y = mHeight + (sz.y - csz.y);
1471 
1472  SetInitialSize(sz);
1473 }
int NumericTextCtrl::GetFocusedDigit ( )
inline

Definition at line 214 of file NumericTextCtrl.h.

References NumericConverter::mFocusedDigit.

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

Definition at line 213 of file NumericTextCtrl.h.

References mLastField.

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

Definition at line 1348 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().

1349 {
1350  unsigned int i, j;
1351  int x, pos;
1352 
1353  wxMemoryDC memDC;
1354 
1355  // Placeholder bitmap so the memDC has something to reference
1356  mBackgroundBitmap = std::make_unique<wxBitmap>(1, 1);
1357  memDC.SelectObject(*mBackgroundBitmap);
1358 
1359  mDigits.clear();
1360 
1361  mBorderLeft = 1;
1362  mBorderTop = 1;
1363  mBorderRight = 1;
1364  mBorderBottom = 1;
1365 
1366  int fontSize = 4;
1367  wxCoord strW, strH;
1368  wxString exampleText = wxT("0");
1369 
1370  // Keep making the font bigger until it's too big, then subtract one.
1371  memDC.SetFont(wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
1372  memDC.GetTextExtent(exampleText, &strW, &strH);
1373  while (strW <= mDigitBoxW && strH <= mDigitBoxH) {
1374  fontSize++;
1375  memDC.SetFont(wxFont(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
1376  memDC.GetTextExtent(exampleText, &strW, &strH);
1377  }
1378  fontSize--;
1379 
1380  mDigitFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1381  memDC.SetFont(*mDigitFont);
1382  memDC.GetTextExtent(exampleText, &strW, &strH);
1383  mDigitW = strW;
1384  mDigitH = strH;
1385 
1386  // The label font should be a little smaller
1387  fontSize--;
1388  mLabelFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
1389 
1390  // Figure out the x-position of each field and label in the box
1391  x = mBorderLeft;
1392  pos = 0;
1393 
1394  memDC.SetFont(*mLabelFont);
1395  memDC.GetTextExtent(mPrefix, &strW, &strH);
1396  x += strW;
1397  pos += mPrefix.Length();
1398 
1399  for(i = 0; i < mFields.size(); i++) {
1400  mFields[i].fieldX = x;
1401  for(j=0; j<(unsigned int)mFields[i].digits; j++) {
1402  mDigits.push_back(DigitInfo(i, j, pos, wxRect(x, mBorderTop,
1403  mDigitBoxW, mDigitBoxH)));
1404  x += mDigitBoxW;
1405  pos++;
1406  }
1407 
1408  mFields[i].labelX = x;
1409  memDC.GetTextExtent(mFields[i].label, &strW, &strH);
1410  pos += mFields[i].label.Length();
1411  x += strW;
1412  mFields[i].fieldW = x;
1413  }
1414 
1415  mWidth = x + mBorderRight;
1417 
1418  // Draw the background bitmap - it contains black boxes where
1419  // all of the digits go and all of the other text
1420 
1421  wxBrush Brush;
1422 
1423  mBackgroundBitmap = std::make_unique<wxBitmap>(mWidth + mButtonWidth, mHeight);
1424  memDC.SelectObject(*mBackgroundBitmap);
1425 
1426  theTheme.SetBrushColour( Brush, clrTimeHours );
1427  memDC.SetBrush(Brush);
1428  memDC.SetPen(*wxTRANSPARENT_PEN);
1429  memDC.DrawRectangle(0, 0, mWidth + mButtonWidth, mHeight);
1430 
1431  int numberBottom = mBorderTop + (mDigitBoxH - mDigitH)/2 + mDigitH;
1432 
1433  memDC.GetTextExtent(wxT("0"), &strW, &strH);
1434  int labelTop = numberBottom - strH;
1435 
1436  memDC.SetTextForeground(theTheme.Colour( clrTimeFont ));
1437  memDC.SetTextBackground(theTheme.Colour( clrTimeBack ));
1438  memDC.DrawText(mPrefix, mBorderLeft, labelTop);
1439 
1440  theTheme.SetBrushColour( Brush, clrTimeBack );
1441  memDC.SetBrush(Brush);
1442  //memDC.SetBrush(*wxLIGHT_GREY_BRUSH);
1443  for(i = 0; i < mDigits.size(); i++)
1444  memDC.DrawRectangle(mDigits[i].digitBox);
1445  memDC.SetBrush( wxNullBrush );
1446 
1447  for(i = 0; i < mFields.size(); i++)
1448  memDC.DrawText(mFields[i].label,
1449  mFields[i].labelX, labelTop);
1450 
1451  if (mMenuEnabled) {
1452  wxRect r(mWidth, 0, mButtonWidth - 1, mHeight - 1);
1453  AColor::Bevel(memDC, true, r);
1454  memDC.SetBrush(*wxBLACK_BRUSH);
1455  memDC.SetPen(*wxBLACK_PEN);
1456  AColor::Arrow(memDC,
1457  mWidth + 1,
1458  (mHeight / 2) - 2,
1459  mButtonWidth - 2);
1460  }
1461  return true;
1462 }
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:1232
DigitInfo is a class used in NumericTextCtrl.
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void NumericTextCtrl::OnCaptureKey ( wxCommandEvent &  event)
private

Definition at line 1638 of file NumericTextCtrl.cpp.

1639 {
1640  wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
1641  int keyCode = kevent->GetKeyCode();
1642 
1643  // Convert numeric keypad entries.
1644  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1645  keyCode -= WXK_NUMPAD0 - '0';
1646 
1647  switch (keyCode)
1648  {
1649  case WXK_BACK:
1650  case WXK_LEFT:
1651  case WXK_RIGHT:
1652  case WXK_HOME:
1653  case WXK_END:
1654  case WXK_UP:
1655  case WXK_DOWN:
1656  case WXK_TAB:
1657  case WXK_RETURN:
1658  case WXK_NUMPAD_ENTER:
1659  case WXK_DELETE:
1660  return;
1661 
1662  default:
1663  if (keyCode >= '0' && keyCode <= '9')
1664  return;
1665  }
1666 
1667  event.Skip();
1668 
1669  return;
1670 }
void NumericTextCtrl::OnContext ( wxContextMenuEvent &  event)
private

Definition at line 1527 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().

1528 {
1529  wxMenu menu;
1530  int i;
1531 
1532  if (!mMenuEnabled) {
1533  event.Skip();
1534  return;
1535  }
1536 
1537  SetFocus();
1538 
1539  int currentSelection = -1;
1540  for (i = 0; i < GetNumBuiltins(); i++) {
1541  menu.AppendRadioItem(ID_MENU + i, GetBuiltinName(i).Translation());
1542  if (mFormatString == GetBuiltinFormat(i)) {
1543  menu.Check(ID_MENU + i, true);
1544  currentSelection = i;
1545  }
1546  }
1547 
1548  PopupMenu(&menu, wxPoint(0, 0));
1549 
1550  // This used to be in an EVT_MENU() event handler, but GTK
1551  // is sensitive to what is done within the handler if the
1552  // user happens to check the first menuitem and then is
1553  // moving down the menu when the ...CTRL_UPDATED event
1554  // handler kicks in.
1555  for (i = 0; i < GetNumBuiltins(); i++) {
1556  if (menu.IsChecked(ID_MENU + i) && i != currentSelection) {
1558 
1559  int eventType = 0;
1560  switch (mType) {
1562  eventType = EVT_TIMETEXTCTRL_UPDATED;
1563  break;
1565  eventType = EVT_FREQUENCYTEXTCTRL_UPDATED;
1566  break;
1568  eventType = EVT_BANDWIDTHTEXTCTRL_UPDATED;
1569  break;
1570  default:
1571  wxASSERT(false);
1572  break;
1573  }
1574 
1575  wxCommandEvent e(eventType, GetId());
1576  e.SetInt(i);
1577  e.SetString(GetBuiltinName(i).Internal());
1578  GetParent()->GetEventHandler()->AddPendingEvent(e);
1579  }
1580  }
1581 
1582 }
void SetFormatString(const wxString &formatString)
#define ID_MENU
wxString GetBuiltinFormat(const int index)
NumericFormatId GetBuiltinName(const int index)
NumericConverter::Type mType
void NumericTextCtrl::OnErase ( wxEraseEvent &  event)
private

Definition at line 1475 of file NumericTextCtrl.cpp.

1476 {
1477  // Ignore it to prevent flashing
1478 }
void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 1624 of file NumericTextCtrl.cpp.

References AudacityProject::CaptureKeyboard(), NumericConverter::mFocusedDigit, AudacityProject::ReleaseKeyboard(), and UpdateAutoFocus().

1625 {
1626  if (event.GetEventType() == wxEVT_KILL_FOCUS) {
1628  }
1629  else {
1631  if( mFocusedDigit <=0 )
1632  UpdateAutoFocus();
1633  }
1634 
1635  Refresh(false);
1636 }
static void CaptureKeyboard(wxWindow *handler)
Definition: Project.cpp:5954
static void ReleaseKeyboard(wxWindow *handler)
Definition: Project.cpp:5965
void NumericTextCtrl::OnKeyDown ( wxKeyEvent &  event)
private

Definition at line 1690 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().

1691 {
1692  if (mDigits.size() == 0)
1693  {
1694  mFocusedDigit = 0;
1695  return;
1696  }
1697 
1698  event.Skip(false);
1699 
1700  int keyCode = event.GetKeyCode();
1701  int digit = mFocusedDigit;
1702 
1703  if (mFocusedDigit < 0)
1704  mFocusedDigit = 0;
1705  if (mFocusedDigit >= (int)mDigits.size())
1706  mFocusedDigit = mDigits.size() - 1;
1707 
1708  // Convert numeric keypad entries.
1709  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1710  keyCode -= WXK_NUMPAD0 - '0';
1711 
1712  if (!mReadOnly && (keyCode >= '0' && keyCode <= '9')) {
1713  int digitPosition = mDigits[mFocusedDigit].pos;
1714  if (mValueString[digitPosition] == wxChar('-')) {
1715  mValue = std::max(mMinValue, std::min(mMaxValue, 0.0));
1716  ValueToControls();
1717  // Beware relocation of the string
1718  digitPosition = mDigits[mFocusedDigit].pos;
1719  }
1720  mValueString[digitPosition] = wxChar(keyCode);
1721  ControlsToValue();
1722  Refresh();// Force an update of the control. [Bug 1497]
1723  ValueToControls();
1724  mFocusedDigit = (mFocusedDigit + 1) % (mDigits.size());
1725  Updated();
1726  }
1727 
1728  else if (!mReadOnly && keyCode == WXK_DELETE) {
1729  if (mAllowInvalidValue)
1731  }
1732 
1733  else if (!mReadOnly && keyCode == WXK_BACK) {
1734  // Moves left, replaces that char with '0', stays there...
1735  mFocusedDigit--;
1736  mFocusedDigit += mDigits.size();
1737  mFocusedDigit %= mDigits.size();
1738  wxString::reference theDigit = mValueString[mDigits[mFocusedDigit].pos];
1739  if (theDigit != wxChar('-'))
1740  theDigit = '0';
1741  ControlsToValue();
1742  Refresh();// Force an update of the control. [Bug 1497]
1743  ValueToControls();
1744  Updated();
1745  }
1746 
1747  else if (keyCode == WXK_LEFT) {
1748  mFocusedDigit--;
1749  mFocusedDigit += mDigits.size();
1750  mFocusedDigit %= mDigits.size();
1751  Refresh();
1752  }
1753 
1754  else if (keyCode == WXK_RIGHT) {
1755  mFocusedDigit++;
1756  mFocusedDigit %= mDigits.size();
1757  Refresh();
1758  }
1759 
1760  else if (keyCode == WXK_HOME) {
1761  mFocusedDigit = 0;
1762  Refresh();
1763  }
1764 
1765  else if (keyCode == WXK_END) {
1766  mFocusedDigit = mDigits.size() - 1;
1767  Refresh();
1768  }
1769 
1770  else if (!mReadOnly && keyCode == WXK_UP) {
1771  Adjust(1, 1);
1772  Updated();
1773  }
1774 
1775  else if (!mReadOnly && keyCode == WXK_DOWN) {
1776  Adjust(1, -1);
1777  Updated();
1778  }
1779 
1780  else if (keyCode == WXK_TAB) {
1781 #if defined(__WXMSW__)
1782  // Using Navigate() on Windows, rather than the following code causes
1783  // bug 1542
1784  wxWindow* parent = GetParent();
1785  wxNavigationKeyEvent nevent;
1786  nevent.SetWindowChange(event.ControlDown());
1787  nevent.SetDirection(!event.ShiftDown());
1788  nevent.SetEventObject(parent);
1789  nevent.SetCurrentFocus(parent);
1790  GetParent()->GetEventHandler()->ProcessEvent(nevent);
1791 #else
1792  Navigate(event.ShiftDown()
1793  ? wxNavigationKeyEvent::IsBackward
1794  : wxNavigationKeyEvent::IsForward);
1795 #endif
1796  }
1797 
1798  else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) {
1799  wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
1800  wxWindow *def = tlw->GetDefaultItem();
1801  if (def && def->IsEnabled()) {
1802  wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
1803  def->GetId());
1804  GetParent()->GetEventHandler()->ProcessEvent(cevent);
1805  }
1806  }
1807 
1808  else {
1809  event.Skip();
1810  return;
1811  }
1812 
1813  if (digit != mFocusedDigit) {
1815  }
1816 }
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 1672 of file NumericTextCtrl.cpp.

References Updated().

1673 {
1674  int keyCode = event.GetKeyCode();
1675 
1676  event.Skip(true);
1677 
1678  if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
1679  keyCode -= WXK_NUMPAD0 - '0';
1680 
1681  if ((keyCode >= '0' && keyCode <= '9') ||
1682  (keyCode == WXK_DELETE) ||
1683  (keyCode == WXK_BACK) ||
1684  (keyCode == WXK_UP) ||
1685  (keyCode == WXK_DOWN)) {
1686  Updated(true);
1687  }
1688 }
void Updated(bool keyup=false)
void NumericTextCtrl::OnMouse ( wxMouseEvent &  event)
private

Definition at line 1584 of file NumericTextCtrl.cpp.

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

1585 {
1586  if (event.LeftDown() && event.GetX() >= mWidth) {
1587  wxContextMenuEvent e;
1588  OnContext(e);
1589  }
1590  else if (event.LeftDown()) {
1591  SetFocus();
1592 
1593  int bestDist = 9999;
1594  unsigned int i;
1595 
1596  mFocusedDigit = 0;
1597  for(i = 0; i < mDigits.size(); i++) {
1598  int dist = abs(event.m_x - (mDigits[i].digitBox.x +
1599  mDigits[i].digitBox.width/2));
1600  if (dist < bestDist) {
1601  mFocusedDigit = i;
1602  bestDist = dist;
1603  }
1604  }
1605 
1606  Refresh(false);
1607  }
1608  else if (event.RightDown() && mMenuEnabled) {
1609  wxContextMenuEvent e;
1610  OnContext(e);
1611  }
1612  else if(!mReadOnly && event.m_wheelRotation != 0 ) {
1613  double steps = event.m_wheelRotation /
1614  (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0) +
1616  mScrollRemainder = steps - floor(steps);
1617  steps = floor(steps);
1618 
1619  Adjust((int)fabs(steps), steps < 0.0 ? -1 : 1);
1620  Updated();
1621  }
1622 }
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 1480 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.

1481 {
1482  wxPaintDC dc(this);
1483  bool focused = (FindFocus() == this);
1484 
1485  dc.DrawBitmap(*mBackgroundBitmap, 0, 0);
1486 
1487  wxPen Pen;
1488  wxBrush Brush;
1489  if (focused) {
1490  theTheme.SetPenColour( Pen, clrTimeFontFocus );
1491  dc.SetPen(Pen);
1492  dc.SetBrush(*wxTRANSPARENT_BRUSH);
1493  dc.DrawRectangle(0, 0, mWidth, mHeight);
1494  dc.SetPen( wxNullPen );
1495  }
1496 
1497  dc.SetFont(*mDigitFont);
1498  dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1499  dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1500 
1501  dc.SetPen(*wxTRANSPARENT_PEN);
1502  theTheme.SetBrushColour( Brush , clrTimeBackFocus );
1503  dc.SetBrush( Brush );
1504 
1505  int i;
1506  for(i = 0; i < (int)mDigits.size(); i++) {
1507  wxRect box = mDigits[i].digitBox;
1508  if (focused && mFocusedDigit == i) {
1509  dc.DrawRectangle(box);
1510  dc.SetTextForeground(theTheme.Colour( clrTimeFontFocus ));
1511  dc.SetTextBackground(theTheme.Colour( clrTimeBackFocus ));
1512  }
1513  int pos = mDigits[i].pos;
1514  wxString digit = mValueString.Mid(pos, 1);
1515  int x = box.x + (mDigitBoxW - mDigitW)/2;
1516  int y = box.y + (mDigitBoxH - mDigitH)/2;
1517  dc.DrawText(digit, x, y);
1518  if (focused && mFocusedDigit == i) {
1519  dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
1520  dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
1521  }
1522  }
1523  dc.SetPen( wxNullPen );
1524  dc.SetBrush( wxNullBrush );
1525 }
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:1232
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void SetPenColour(wxPen &Pen, int iIndex)
Definition: Theme.cpp:1238
void NumericTextCtrl::SetFieldFocus ( int  digit)

Definition at line 1818 of file NumericTextCtrl.cpp.

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

Referenced by OnKeyDown(), and Updated().

1819 {
1820 #if wxUSE_ACCESSIBILITY
1821  if (mDigits.size() == 0)
1822  {
1823  mFocusedDigit = 0;
1824  return;
1825  }
1826  mFocusedDigit = digit;
1827  mLastField = mDigits[mFocusedDigit].field + 1;
1828 
1829  // This looks strange (and it is), but it was the only way I could come
1830  // up with that allowed Jaws, Window-Eyes, and NVDA to read the control
1831  // somewhat the same. See NumericTextCtrlAx below for even more odd looking
1832  // hackery.
1833  //
1834  // If you change SetFieldFocus(), Updated(), or NumericTextCtrlAx, make sure
1835  // you test with Jaws, Window-Eyes, and NVDA.
1836  GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
1837  this,
1838  wxOBJID_CLIENT,
1839  0);
1840  GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
1841  this,
1842  wxOBJID_CLIENT,
1843  mFocusedDigit + 1);
1844 #endif
1845 }
std::vector< DigitInfo > mDigits
void NumericTextCtrl::SetFormatName ( const NumericFormatId formatName)
void NumericTextCtrl::SetFormatString ( const wxString &  formatString)

Definition at line 1290 of file NumericTextCtrl.cpp.

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

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

1291 {
1292  NumericConverter::SetFormatString(formatString);
1293  Layout();
1294  Fit();
1295  ValueToControls();
1296  ControlsToValue();
1297  UpdateAutoFocus();
1298 }
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 1339 of file NumericTextCtrl.cpp.

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

1340 {
1341  const bool wasInvalid = mAllowInvalidValue && (mValue == mInvalidValue);
1342  mAllowInvalidValue = true;
1343  mInvalidValue = invalidValue;
1344  if (wasInvalid)
1345  SetValue(invalidValue);
1346 }
void SetValue(double newValue)
void NumericTextCtrl::SetReadOnly ( bool  readOnly = true)

Definition at line 1316 of file NumericTextCtrl.cpp.

References mReadOnly.

1317 {
1318  mReadOnly = readOnly;
1319 }
void NumericTextCtrl::SetSampleRate ( double  sampleRate)

Definition at line 1300 of file NumericTextCtrl.cpp.

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

Referenced by TimeDialog::TransferDataToWindow().

1301 {
1302  NumericConverter::SetSampleRate(sampleRate);
1303  Layout();
1304  Fit();
1305  ValueToControls();
1306  ControlsToValue();
1307 }
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 1270 of file NumericTextCtrl.cpp.

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

Referenced by OnFocus(), and SetFormatString().

1271 {
1272  if (!mAutoPos)
1273  return;
1274 
1275  mFocusedDigit = 0;
1276  while (mFocusedDigit < ((int)mDigits.size() - 1)) {
1277  wxChar dgt = mValueString[mDigits[mFocusedDigit].pos];
1278  if (dgt != '0') {
1279  break;
1280  }
1281  mFocusedDigit++;
1282  }
1283 }
std::vector< DigitInfo > mDigits
void NumericTextCtrl::Updated ( bool  keyup = false)
private

Definition at line 1847 of file NumericTextCtrl.cpp.

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

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

1848 {
1849  wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
1850 
1851  // This will give listeners the ability to do tasks when the
1852  // update has been completed, like when the UP ARROW has been
1853  // held down and is finally released.
1854  event.SetInt(keyup);
1855  event.SetEventObject(this);
1856  GetEventHandler()->ProcessEvent(event);
1857 
1858 #if wxUSE_ACCESSIBILITY
1859  if (!keyup) {
1861  }
1862 #endif
1863 }
wxEVT_COMMAND_TEXT_UPDATED
Definition: Nyquist.cpp:111
void NumericTextCtrl::ValueToControls ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1865 of file NumericTextCtrl.cpp.

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

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

1866 {
1867  const wxString previousValueString = mValueString;
1869  if (mValueString != previousValueString) {
1870  // Doing this only when needed is an optimization.
1871  // NumerixTextCtrls are used in the selection bar at the bottom
1872  // of Audacity, and are updated at high frequency through
1873  // SetValue() when Audacity is playing. This consumes a
1874  // significant amount of CPU. Typically, when a track is
1875  // playing, only one of the NumericTextCtrl actually changes
1876  // (the audio position). We save CPU by updating the control
1877  // only when needed.
1878  Refresh(false);
1879  }
1880 }
virtual void ValueToControls()

Friends And Related Function Documentation

friend class NumericTextCtrlAx
friend

Definition at line 154 of file NumericTextCtrl.h.

Member Data Documentation

bool NumericTextCtrl::mAllowInvalidValue
private

Definition at line 268 of file NumericTextCtrl.h.

Referenced by OnKeyDown(), and SetInvalidValue().

bool NumericTextCtrl::mAutoPos
private

Definition at line 261 of file NumericTextCtrl.h.

Referenced by UpdateAutoFocus().

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

Definition at line 243 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mBorderBottom
private

Definition at line 253 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderLeft
private

Definition at line 250 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderRight
private

Definition at line 252 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mBorderTop
private

Definition at line 251 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mButtonWidth
private

Definition at line 256 of file NumericTextCtrl.h.

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

int NumericTextCtrl::mDigitBoxH
private

Definition at line 247 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitBoxW
private

Definition at line 246 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

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

Definition at line 245 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitH
private

Definition at line 249 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mDigitW
private

Definition at line 248 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

int NumericTextCtrl::mHeight
private

Definition at line 255 of file NumericTextCtrl.h.

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

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

Definition at line 245 of file NumericTextCtrl.h.

Referenced by Layout().

int NumericTextCtrl::mLastField
private

Definition at line 258 of file NumericTextCtrl.h.

Referenced by GetFocusedField(), and SetFieldFocus().

bool NumericTextCtrl::mMenuEnabled
private

Definition at line 240 of file NumericTextCtrl.h.

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

bool NumericTextCtrl::mReadOnly
private

Definition at line 241 of file NumericTextCtrl.h.

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

double NumericTextCtrl::mScrollRemainder
private

Definition at line 264 of file NumericTextCtrl.h.

Referenced by OnMouse().

NumericConverter::Type NumericTextCtrl::mType
private

Definition at line 266 of file NumericTextCtrl.h.

Referenced by OnContext().

int NumericTextCtrl::mWidth
private

Definition at line 254 of file NumericTextCtrl.h.

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


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