Audacity  2.3.1
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 1212 of file NumericTextCtrl.cpp.

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

1267 {
1268 }

Member Function Documentation

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1886 of file NumericTextCtrl.cpp.

References NumericConverter::ControlsToValue().

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

1887 {
1889 }
virtual void ControlsToValue()
void NumericTextCtrl::EnableMenu ( bool  enable = true)

Definition at line 1324 of file NumericTextCtrl.cpp.

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

1325 {
1326 #if wxUSE_TOOLTIPS
1327  wxString tip(_("(Use context menu to change format.)"));
1328  if (enable)
1329  SetToolTip(tip);
1330  else {
1331  wxToolTip *tt = GetToolTip();
1332  if (tt && tt->GetTip() == tip)
1333  SetToolTip(NULL);
1334  }
1335 #endif
1336  mMenuEnabled = enable;
1337  mButtonWidth = enable ? 9 : 0;
1338  Layout();
1339  Fit();
1340 }
_("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 1467 of file NumericTextCtrl.cpp.

References mButtonWidth, mHeight, and mWidth.

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

1468 {
1469  wxSize sz = GetSize();
1470  wxSize csz = GetClientSize();
1471 
1472  sz.x = mButtonWidth + mWidth + (sz.x - csz.x);
1473  sz.y = mHeight + (sz.y - csz.y);
1474 
1475  SetInitialSize(sz);
1476 }
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 1351 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().

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

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

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

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

1479 {
1480  // Ignore it to prevent flashing
1481 }
void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 1627 of file NumericTextCtrl.cpp.

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

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

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

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

References Updated().

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

Definition at line 1587 of file NumericTextCtrl.cpp.

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

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

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

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

Referenced by OnKeyDown(), and Updated().

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

Definition at line 1293 of file NumericTextCtrl.cpp.

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

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

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

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

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

Definition at line 1319 of file NumericTextCtrl.cpp.

References mReadOnly.

1320 {
1321  mReadOnly = readOnly;
1322 }
void NumericTextCtrl::SetSampleRate ( double  sampleRate)

Definition at line 1303 of file NumericTextCtrl.cpp.

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

Referenced by TimeDialog::TransferDataToWindow().

1304 {
1305  NumericConverter::SetSampleRate(sampleRate);
1306  Layout();
1307  Fit();
1308  ValueToControls();
1309  ControlsToValue();
1310 }
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 1273 of file NumericTextCtrl.cpp.

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

Referenced by OnFocus(), and SetFormatString().

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

Definition at line 1850 of file NumericTextCtrl.cpp.

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

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

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

Reimplemented from NumericConverter.

Definition at line 1868 of file NumericTextCtrl.cpp.

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

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

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