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  SetLayoutDirection(wxLayout_LeftToRight);
1237  Layout();
1238  Fit();
1239  ValueToControls();
1240  //PRL -- would this fix the following?
1241  //ValueToControls();
1242 
1243  //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
1244  //ControlsToValue();
1245 
1246  mScrollRemainder = 0.0;
1247 
1248 #if wxUSE_ACCESSIBILITY
1249  SetLabel(wxT(""));
1250  SetName(wxT(""));
1251  SetAccessible(safenew NumericTextCtrlAx(this));
1252 #endif
1253 
1254  if (options.hasInvalidValue)
1255  SetInvalidValue( options.invalidValue );
1256 
1257  if (!options.format.empty())
1258  SetFormatString( options.format );
1259 
1260  if (options.hasValue)
1261  SetValue( options.value );
1262 }
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 1264 of file NumericTextCtrl.cpp.

1265 {
1266 }

Member Function Documentation

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 1884 of file NumericTextCtrl.cpp.

References NumericConverter::ControlsToValue().

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

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

Definition at line 1322 of file NumericTextCtrl.cpp.

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

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

References mButtonWidth, mHeight, and mWidth.

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

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

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

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

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

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

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

Definition at line 1625 of file NumericTextCtrl.cpp.

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

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

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

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

References Updated().

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

Definition at line 1585 of file NumericTextCtrl.cpp.

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

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

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

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

Referenced by OnKeyDown(), and Updated().

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

Definition at line 1291 of file NumericTextCtrl.cpp.

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

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

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

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

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

Definition at line 1317 of file NumericTextCtrl.cpp.

References mReadOnly.

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

Definition at line 1301 of file NumericTextCtrl.cpp.

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

Referenced by TimeDialog::TransferDataToWindow().

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

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

Referenced by OnFocus(), and SetFormatString().

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

Definition at line 1848 of file NumericTextCtrl.cpp.

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

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

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

Reimplemented from NumericConverter.

Definition at line 1866 of file NumericTextCtrl.cpp.

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

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

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