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

#include <NumericTextCtrl.h>

Inheritance diagram for NumericTextCtrl:
[legend]
Collaboration diagram for NumericTextCtrl:
[legend]

Classes

struct  FieldPosition
 
struct  Options
 

Public Member Functions

 NumericTextCtrl (const FormatterContext &context, wxWindow *parent, wxWindowID winid, NumericConverterType type, const NumericFormatSymbol &formatName={}, double value=0.0, const Options &options={}, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
 
virtual ~NumericTextCtrl ()
 
void SetName (const TranslatableString &name)
 
wxSize ComputeSizing (bool update=true, wxCoord digitW=0, wxCoord digitH=0)
 
bool Layout () override
 
void Fit () override
 
void SetValue (double newValue)
 
bool SetTypeAndFormatName (const NumericConverterType &type, const NumericFormatSymbol &formatName)
 
bool SetFormatName (const NumericFormatSymbol &formatName)
 
bool SetCustomFormat (const TranslatableString &customFormat)
 
void SetFieldFocus (int)
 
wxSize GetDimensions ()
 
wxSize GetDigitSize ()
 
void SetDigitSize (int width, int height)
 
void SetReadOnly (bool readOnly=true)
 
void EnableMenu (bool enable=true)
 
void SetInvalidValue (double invalidValue)
 
int GetFocusedField ()
 
int GetFocusedDigit ()
 
- Public Member Functions inherited from NumericConverter
 NumericConverter (const FormatterContext &context, NumericConverterType type, const NumericFormatSymbol &formatName={}, double value=0.0f)
 
virtual ~NumericConverter ()
 
virtual void ValueToControls ()
 
virtual void ValueToControls (double rawValue, bool nearest=true)
 
virtual void ControlsToValue ()
 
bool SetTypeAndFormatName (const NumericConverterType &type, const NumericFormatSymbol &formatName)
 
bool SetFormatName (const NumericFormatSymbol &formatName)
 
NumericFormatSymbol GetFormatName () const
 
bool SetCustomFormat (const TranslatableString &customFormat)
 
void SetValue (double newValue)
 
void SetMinValue (double minValue)
 
void ResetMinValue ()
 
void SetMaxValue (double maxValue)
 
void ResetMaxValue ()
 
double GetValue ()
 
wxString GetString ()
 
void Adjust (int steps, int dir, int focusedDigit)
 
void Increment (int focusedDigit=-1)
 
void Decrement (int focusedDigit=-1)
 

Private Member Functions

void OnFormatUpdated () override
 
void HandleFormatterChanged ()
 
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)
 
wxRect GetBox (size_t ii) const
 

Private Attributes

std::vector< wxRect > mBoxes
 
std::vector< FieldPositionmFieldPositions
 
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
 
int mFocusedDigit { 0 }
 
bool mAutoPos
 
double mScrollRemainder
 
NumericConverterType mType
 
bool mAllowInvalidValue
 

Friends

class NumericTextCtrlAx
 

Additional Inherited Members

- Protected Member Functions inherited from NumericConverter
bool UpdateFormatter ()
 
virtual void OnFormatUpdated ()
 
- Protected Attributes inherited from NumericConverter
FormatterContext mContext
 
NumericConverterType mType
 
double mValue
 
double mMinValue
 
double mMaxValue
 
double mInvalidValue { -1 }
 
std::unique_ptr< NumericConverterFormattermFormatter
 
NumericFormatSymbol mFormatSymbol
 
TranslatableString mCustomFormat
 
wxString mValueString
 
std::vector< wxString > mFieldValueStrings
 
Observer::Subscription mFormatUpdatedSubscription
 

Detailed Description

Definition at line 34 of file NumericTextCtrl.h.

Constructor & Destructor Documentation

◆ NumericTextCtrl()

NumericTextCtrl::NumericTextCtrl ( const FormatterContext context,
wxWindow *  parent,
wxWindowID  winid,
NumericConverterType  type,
const NumericFormatSymbol formatName = {},
double  value = 0.0,
const Options options = {},
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize 
)

Definition at line 145 of file NumericTextCtrl.cpp.

153 :
154 wxControl(parent, id, pos, size, wxSUNKEN_BORDER | wxWANTS_CHARS),
155 NumericConverter(context, type, formatName, timeValue),
157 mDigitFont{},
158 mLabelFont{},
159 mLastField(1),
160 mAutoPos(options.autoPos)
161 , mType(type)
162{
163 mAllowInvalidValue = false;
164
165 mDigitBoxW = 11;
166 mDigitBoxH = 19;
167
168 mBorderLeft = 1;
169 mBorderTop = 1;
170 mBorderRight = 1;
171 mBorderBottom = 1;
172
173 mReadOnly = options.readOnly;
174 mMenuEnabled = options.menuEnabled;
175 mButtonWidth = mMenuEnabled ? 9 : 0;
176
177 SetLayoutDirection(wxLayout_LeftToRight);
178 Layout();
179 Fit();
181
182 //PRL -- would this fix the following?
183 //ValueToControls();
184
185 //mchinen - aug 15 09 - this seems to put the mValue back to zero, and do nothing else.
186 //ControlsToValue();
187
188 mScrollRemainder = 0.0;
189
190#if wxUSE_ACCESSIBILITY
191 SetLabel(wxT(""));
192 SetName( {} );
193 SetAccessible(safenew NumericTextCtrlAx(this));
194#endif
195
196 if (options.hasInvalidValue)
197 SetInvalidValue( options.invalidValue );
198
199 if (!options.formatSymbol.empty())
200 SetFormatName( options.formatSymbol );
201
202 if (!options.customFormat.empty())
203 SetCustomFormat( options.customFormat );
204
205 if (options.hasValue)
206 SetValue( options.value );
207}
wxT("CloseDown"))
#define safenew
Definition: MemoryX.h:10
NumericConverter(const FormatterContext &context, NumericConverterType type, const NumericFormatSymbol &formatName={}, double value=0.0f)
void Fit() override
std::unique_ptr< wxFont > mDigitFont
void SetInvalidValue(double invalidValue)
bool Layout() override
bool SetCustomFormat(const TranslatableString &customFormat)
friend class NumericTextCtrlAx
void ValueToControls() override
std::unique_ptr< wxBitmap > mBackgroundBitmap
void SetName(const TranslatableString &name)
bool SetFormatName(const NumericFormatSymbol &formatName)
NumericConverterType mType
void SetValue(double newValue)
std::unique_ptr< wxFont > mLabelFont

◆ ~NumericTextCtrl()

NumericTextCtrl::~NumericTextCtrl ( )
virtual

Definition at line 209 of file NumericTextCtrl.cpp.

210{
211}

Member Function Documentation

◆ ComputeSizing()

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

Definition at line 315 of file NumericTextCtrl.cpp.

316{
317 if (!mFormatter)
318 return {};
319
320 // Get current box size
321 if (boxW == 0) {
322 boxW = mDigitBoxW;
323 }
324
325 if (boxH == 0) {
326 boxH = mDigitBoxH;
327 }
328 boxH -= (mBorderTop + mBorderBottom);
329
330 // We can use the screen device context since we're not drawing to it
331 wxScreenDC dc;
332
333 // First calculate a rough point size
334 wxFont pf(wxSize(boxW, boxH), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
335 int fontSize = pf.GetPointSize();
336 wxCoord strW;
337 wxCoord strH;
338
339 // Now decrease it until we fit within our digit box
340 dc.SetFont(pf);
341 dc.GetTextExtent(wxT("0"), &strW, &strH);
342 while (strW > boxW || strH > boxH) {
343 dc.SetFont(wxFont(--fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
344 dc.GetTextExtent(wxT("0"), &strW, &strH);
345 }
346 fontSize--;
347
348 // Create the digit font with the new point size
349 if (update) {
350 mDigitFont = std::make_unique<wxFont>(fontSize, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
351 dc.SetFont(*mDigitFont);
352
353 // Remember the actual digit width and height using the new font
354 dc.GetTextExtent(wxT("0"), &mDigitW, &mDigitH);
355 }
356
357 // The label font should be a little smaller
358 std::unique_ptr<wxFont> labelFont = std::make_unique<wxFont>(fontSize - 1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
359
360 // Use the label font for all remaining measurements since only non-digit text is left
361 dc.SetFont(*labelFont);
362
363 // Remember the pointer if updating
364 if (update) {
365 mLabelFont = std::move(labelFont);
366 }
367
368 auto& prefix = mFormatter->GetPrefix();
369 auto& fields = mFormatter->GetFields();
370
371 // Get the width of the prefix, if any
372 dc.GetTextExtent(prefix, &strW, &strH);
373
374 // Bump x-position to the end of the prefix
375 int x = mBorderLeft + strW;
376
377 if (update) {
378 // Set the character position past the prefix
379 int pos = prefix.length();
380
381 mBoxes.clear();
382 // No need to clear - all the data will be reinitialized anyway
383 mFieldPositions.resize(fields.size());
384
385 // Figure out the x-position of each field and label in the box
386 for (int i = 0, fcnt = fields.size(); i < fcnt; ++i) {
387 // Get the size of the label
388 dc.GetTextExtent(fields[i].label, &strW, &strH);
389
390 // Remember this field's x-position
391 mFieldPositions[i].fieldX = x;
392
393 // Remember metrics for each digit
394 for (int j = 0, dcnt = fields[i].digits; j < dcnt; ++j) {
395 mBoxes.push_back(wxRect { x, mBorderTop, boxW, boxH });
396 x += boxW;
397 pos++;
398 }
399
400 // Remember the label's x-position
401 mFieldPositions[i].labelX = x;
402
403 // Bump to end of label
404 x += strW;
405
406 // Remember the label's width
407 mFieldPositions[i].fieldW = x;
408
409 // Bump character position to end of label
410 pos += fields[i].label.length();
411 }
412 }
413 else {
414 // Determine the maximum x-position (length) of the remaining fields
415 for (int i = 0, fcnt = fields.size(); i < fcnt; ++i) {
416 // Get the size of the label
417 dc.GetTextExtent(fields[i].label, &strW, &strH);
418
419 // Just bump to next field
420 x += (boxW * fields[i].digits) + strW;
421 }
422 }
423
424 // Calculate the maximum dimensions
425 wxSize dim(x + mBorderRight, boxH + mBorderTop + mBorderBottom);
426
427 // Save maximumFinally, calculate the minimum dimensions
428 if (update) {
429 mWidth = dim.x;
430 mHeight = dim.y;
431 }
432
433 return wxSize(dim.x + mButtonWidth, dim.y);
434}
TranslatableString label
Definition: TagsEditor.cpp:164
std::unique_ptr< NumericConverterFormatter > mFormatter
std::vector< wxRect > mBoxes
std::vector< FieldPosition > mFieldPositions

References label, mBorderBottom, mBorderLeft, mBorderRight, mBorderTop, mBoxes, mButtonWidth, mDigitBoxH, mDigitBoxW, mDigitFont, mDigitH, mDigitW, mFieldPositions, NumericConverter::mFormatter, mHeight, mLabelFont, mWidth, and wxT().

Referenced by TimeToolBar::ComputeSizing(), and Layout().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ControlsToValue()

void NumericTextCtrl::ControlsToValue ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 959 of file NumericTextCtrl.cpp.

960{
962}
virtual void ControlsToValue()

References NumericConverter::ControlsToValue().

Referenced by HandleFormatterChanged(), OnKeyDown(), and SetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnableMenu()

void NumericTextCtrl::EnableMenu ( bool  enable = true)

Definition at line 288 of file NumericTextCtrl.cpp.

289{
290#if wxUSE_TOOLTIPS
291 wxString tip(_("(Use context menu to change format.)"));
292 if (enable)
293 SetToolTip(tip);
294 else {
295 wxToolTip *tt = GetToolTip();
296 if (tt && tt->GetTip() == tip)
297 SetToolTip(NULL);
298 }
299#endif
300 mMenuEnabled = enable;
301 mButtonWidth = enable ? 9 : 0;
302 Layout();
303 Fit();
304}
#define _(s)
Definition: Internat.h:73

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

Here is the call graph for this function:

◆ Fit()

void NumericTextCtrl::Fit ( )
override

Definition at line 499 of file NumericTextCtrl.cpp.

500{
501 wxSize sz = GetSize();
502 wxSize csz = GetClientSize();
503
504 sz.x = mButtonWidth + mWidth + (sz.x - csz.x);
505 sz.y = mHeight + (sz.y - csz.y);
506
507 SetInitialSize(sz);
508}

References mButtonWidth, mHeight, and mWidth.

Referenced by EnableMenu(), HandleFormatterChanged(), and SetDigitSize().

Here is the caller graph for this function:

◆ GetBox()

wxRect NumericTextCtrl::GetBox ( size_t  ii) const
private

Definition at line 964 of file NumericTextCtrl.cpp.

965{
966 if (ii < mBoxes.size())
967 return mBoxes[ii];
968 return {};
969}

References mBoxes.

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

Here is the caller graph for this function:

◆ GetDigitSize()

wxSize NumericTextCtrl::GetDigitSize ( )
inline

Definition at line 100 of file NumericTextCtrl.h.

100{ return wxSize(mDigitBoxW, mDigitBoxH); }

Referenced by TimeToolBar::OnSize(), and TimeToolBar::Populate().

Here is the caller graph for this function:

◆ GetDimensions()

wxSize NumericTextCtrl::GetDimensions ( )
inline

Definition at line 99 of file NumericTextCtrl.h.

99{ return wxSize(mWidth + mButtonWidth, mHeight); }

Referenced by TimeToolBar::OnSize().

Here is the caller graph for this function:

◆ GetFocusedDigit()

int NumericTextCtrl::GetFocusedDigit ( )
inline

Definition at line 112 of file NumericTextCtrl.h.

112{ return mFocusedDigit; }

◆ GetFocusedField()

int NumericTextCtrl::GetFocusedField ( )
inline

Definition at line 111 of file NumericTextCtrl.h.

111{ return mLastField; }

◆ HandleFormatterChanged()

void NumericTextCtrl::HandleFormatterChanged ( )
private

Definition at line 696 of file NumericTextCtrl.cpp.

697{
698 mBoxes.clear();
699 Layout();
700 Fit();
704}
void ControlsToValue() override

References ControlsToValue(), Fit(), Layout(), mBoxes, UpdateAutoFocus(), and ValueToControls().

Referenced by OnFormatUpdated(), SetCustomFormat(), SetFormatName(), and SetTypeAndFormatName().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Layout()

bool NumericTextCtrl::Layout ( )
override

Definition at line 436 of file NumericTextCtrl.cpp.

437{
438 if (!mFormatter)
439 return {};
440
442
443 auto& prefix = mFormatter->GetPrefix();
444 auto& fields = mFormatter->GetFields();
445 auto& digits = mFormatter->GetDigitInfos();
446
447 wxMemoryDC memDC;
448 wxCoord strW, strH;
449 memDC.SetFont(*mLabelFont);
450 memDC.GetTextExtent(prefix, &strW, &strH);
451
452 int i;
453
454 // Draw the background bitmap - it contains black boxes where
455 // all of the digits go and all of the other text
456
457 wxBrush Brush;
458
459 mBackgroundBitmap = std::make_unique<wxBitmap>(mWidth + mButtonWidth, mHeight,24);
460 memDC.SelectObject(*mBackgroundBitmap);
461
462 theTheme.SetBrushColour( Brush, clrTimeHours );
463 memDC.SetBrush(Brush);
464 memDC.SetPen(*wxTRANSPARENT_PEN);
465 memDC.DrawRectangle(0, 0, mWidth + mButtonWidth, mHeight);
466
467 int numberBottom = mBorderTop + (mDigitBoxH - mDigitH)/2 + mDigitH;
468
469 memDC.GetTextExtent(wxT("0"), &strW, &strH);
470 int labelTop = numberBottom - strH;
471
472 memDC.SetTextForeground(theTheme.Colour( clrTimeFont ));
473 memDC.SetTextBackground(theTheme.Colour( clrTimeBack ));
474 memDC.DrawText(prefix, mBorderLeft, labelTop);
475
476 theTheme.SetBrushColour( Brush, clrTimeBack );
477 memDC.SetBrush(Brush);
478 //memDC.SetBrush(*wxLIGHT_GREY_BRUSH);
479 for(i = 0; i < digits.size(); i++)
480 memDC.DrawRectangle(GetBox(i));
481 memDC.SetBrush( wxNullBrush );
482
483 for(i = 0; i < fields.size(); i++)
484 memDC.DrawText(fields[i].label, mFieldPositions[i].labelX, labelTop);
485
486 if (mMenuEnabled) {
487 wxRect r(mWidth, 0, mButtonWidth - 1, mHeight - 1);
488 AColor::Bevel(memDC, true, r);
489 memDC.SetBrush(*wxBLACK_BRUSH);
490 memDC.SetPen(*wxBLACK_PEN);
491 AColor::Arrow(memDC,
492 mWidth + 1,
493 (mHeight / 2) - 2,
494 mButtonWidth - 2);
495 }
496 return true;
497}
THEME_API Theme theTheme
Definition: Theme.cpp:82
static void Arrow(wxDC &dc, wxCoord x, wxCoord y, int width, bool down=true)
Definition: AColor.cpp:160
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
wxRect GetBox(size_t ii) const
wxSize ComputeSizing(bool update=true, wxCoord digitW=0, wxCoord digitH=0)
wxColour & Colour(int iIndex)
void SetBrushColour(wxBrush &Brush, int iIndex)

References AColor::Arrow(), AColor::Bevel(), ThemeBase::Colour(), ComputeSizing(), GetBox(), mBackgroundBitmap, mBorderLeft, mBorderTop, mButtonWidth, mDigitBoxH, mDigitH, mFieldPositions, NumericConverter::mFormatter, mHeight, mLabelFont, mMenuEnabled, mWidth, ThemeBase::SetBrushColour(), theTheme, and wxT().

Referenced by EnableMenu(), HandleFormatterChanged(), and SetDigitSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCaptureKey()

void NumericTextCtrl::OnCaptureKey ( wxCommandEvent &  event)
private

Definition at line 706 of file NumericTextCtrl.cpp.

707{
708 wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
709 int keyCode = kevent->GetKeyCode();
710
711 // Convert numeric keypad entries.
712 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
713 keyCode -= WXK_NUMPAD0 - '0';
714
715 switch (keyCode)
716 {
717 case WXK_BACK:
718 case WXK_LEFT:
719 case WXK_RIGHT:
720 case WXK_HOME:
721 case WXK_END:
722 case WXK_UP:
723 case WXK_DOWN:
724 case WXK_TAB:
725 case WXK_RETURN:
726 case WXK_NUMPAD_ENTER:
727 case WXK_DELETE:
728 return;
729
730 default:
731 if (keyCode >= '0' && keyCode <= '9' && !kevent->HasAnyModifiers())
732 return;
733 }
734
735 event.Skip();
736
737 return;
738}

◆ OnContext()

void NumericTextCtrl::OnContext ( wxContextMenuEvent &  event)
private

Definition at line 567 of file NumericTextCtrl.cpp.

568{
569
570 if (!mMenuEnabled) {
571 event.Skip();
572 return;
573 }
574
575 wxMenu menu;
576
577 SetFocus();
578
579 std::vector<NumericFormatSymbol> symbols;
580
582 mContext,
583 mType,
584 [&menu, &symbols, this, i = ID_MENU](auto& item) mutable
585 {
586 symbols.push_back(item.symbol);
587 menu.AppendRadioItem(i, item.symbol.Translation());
588
589 if (mFormatSymbol == item.symbol)
590 menu.Check(i, true);
591
592 ++i;
593 });
594
595 menu.Bind(wxEVT_MENU, [](auto&){});
596 BasicMenu::Handle{ &menu }.Popup(
598 { 0, 0 }
599 );
600
601 // This used to be in an EVT_MENU() event handler, but GTK
602 // is sensitive to what is done within the handler if the
603 // user happens to check the first menuitem and then is
604 // moving down the menu when the ...CTRL_UPDATED event
605 // handler kicks in.
606 auto menuIndex = ID_MENU;
607
608 int eventType = 0;
609
611 eventType = EVT_TIMETEXTCTRL_UPDATED;
613 eventType = EVT_FREQUENCYTEXTCTRL_UPDATED;
615 eventType = EVT_BANDWIDTHTEXTCTRL_UPDATED;
616 else
617 {
618 assert(false); // unsupported control type, skip it
619 return;
620 }
621
622 for (const auto& symbol : symbols)
623 {
624 if (!menu.IsChecked(menuIndex++) || mFormatSymbol == symbol)
625 continue;
626
627 SetFormatName(symbol);
628
629 wxCommandEvent e(eventType, GetId());
630 e.SetString(symbol.Internal());
631 GetParent()->GetEventHandler()->AddPendingEvent(e);
632
633 break;
634 }
635}
const NumericConverterType & NumericConverterType_BANDWIDTH()
const NumericConverterType & NumericConverterType_FREQUENCY()
const NumericConverterType & NumericConverterType_TIME()
#define ID_MENU
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
Definition: BasicMenu.cpp:209
NumericFormatSymbol mFormatSymbol
FormatterContext mContext
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
Definition: BasicUI.h:352
static void Visit(const FormatterContext &context, const NumericConverterType &type, Visitor visitor)
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.

References ID_MENU, NumericConverter::mContext, NumericConverter::mFormatSymbol, mMenuEnabled, mType, NumericConverterType_BANDWIDTH(), NumericConverterType_FREQUENCY(), NumericConverterType_TIME(), BasicMenu::Handle::Popup(), BasicUI::SetFocus(), SetFormatName(), and NumericConverterRegistry::Visit().

Referenced by OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnErase()

void NumericTextCtrl::OnErase ( wxEraseEvent &  event)
private

Definition at line 510 of file NumericTextCtrl.cpp.

511{
512 // Ignore it to prevent flashing
513}

◆ OnFocus()

void NumericTextCtrl::OnFocus ( wxFocusEvent &  event)
private

Definition at line 679 of file NumericTextCtrl.cpp.

680{
681 KeyboardCapture::OnFocus( *this, event );
682
683 if (event.GetEventType() != wxEVT_KILL_FOCUS &&
684 mFocusedDigit <= 0 )
686
687 event.Skip( false ); // PRL: not sure why, but preserving old behavior
688}
void OnFocus(wxWindow &window, wxFocusEvent &event)
a function useful to implement a focus event handler The window releases the keyboard if the event is...

References mFocusedDigit, KeyboardCapture::OnFocus(), and UpdateAutoFocus().

Here is the call graph for this function:

◆ OnFormatUpdated()

void NumericTextCtrl::OnFormatUpdated ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 690 of file NumericTextCtrl.cpp.

References HandleFormatterChanged(), and NumericConverter::OnFormatUpdated().

Here is the call graph for this function:

◆ OnKeyDown()

void NumericTextCtrl::OnKeyDown ( wxKeyEvent &  event)
private

Definition at line 758 of file NumericTextCtrl.cpp.

759{
760 if (!mFormatter || mBoxes.size() == 0)
761 {
762 mFocusedDigit = 0;
763 return;
764 }
765
766 event.Skip(false);
767
768 int keyCode = event.GetKeyCode();
769 int digit = mFocusedDigit;
770
771 if (mFocusedDigit < 0)
772 mFocusedDigit = 0;
773 if (mFocusedDigit >= (int)mBoxes.size())
774 mFocusedDigit = mBoxes.size() - 1;
775
776 // Convert numeric keypad entries.
777 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
778 keyCode -= WXK_NUMPAD0 - '0';
779
780 auto& digits = mFormatter->GetDigitInfos();
781
782 if (!mReadOnly && (keyCode >= '0' && keyCode <= '9' && !event.HasAnyModifiers())) {
783 int digitPosition = digits[mFocusedDigit].pos;
784 if (mValueString[digitPosition] == wxChar('-')) {
785 mValue = std::max(mMinValue, std::min(mMaxValue, 0.0));
787 // Beware relocation of the string
788 digitPosition = digits[mFocusedDigit].pos;
789 }
790 mValueString[digitPosition] = wxChar(keyCode);
792 Refresh();// Force an update of the control. [Bug 1497]
794 mFocusedDigit = (mFocusedDigit + 1) % (digits.size());
795 Updated();
796 }
797
798 else if (!mReadOnly && keyCode == WXK_DELETE) {
801 }
802
803 else if (!mReadOnly && keyCode == WXK_BACK) {
804 // Moves left, replaces that char with '0', stays there...
806 mFocusedDigit += digits.size();
807 mFocusedDigit %= digits.size();
808 wxString::reference theDigit = mValueString[digits[mFocusedDigit].pos];
809 if (theDigit != wxChar('-'))
810 theDigit = '0';
812 Refresh();// Force an update of the control. [Bug 1497]
814 Updated();
815 }
816
817 else if (keyCode == WXK_LEFT) {
819 mFocusedDigit += digits.size();
820 mFocusedDigit %= digits.size();
821 Refresh();
822 }
823
824 else if (keyCode == WXK_RIGHT) {
826 mFocusedDigit %= digits.size();
827 Refresh();
828 }
829
830 else if (keyCode == WXK_HOME) {
831 mFocusedDigit = 0;
832 Refresh();
833 }
834
835 else if (keyCode == WXK_END) {
836 mFocusedDigit = digits.size() - 1;
837 Refresh();
838 }
839
840 else if (!mReadOnly && keyCode == WXK_UP) {
841 Adjust(1, 1, mFocusedDigit);
842 Updated();
843 }
844
845 else if (!mReadOnly && keyCode == WXK_DOWN) {
846 Adjust(1, -1, mFocusedDigit);
847 Updated();
848 }
849
850 else if (keyCode == WXK_TAB) {
851#if defined(__WXMSW__)
852 // Using Navigate() on Windows, rather than the following code causes
853 // bug 1542
854 wxWindow* parent = GetParent();
855 wxNavigationKeyEvent nevent;
856 nevent.SetWindowChange(event.ControlDown());
857 nevent.SetDirection(!event.ShiftDown());
858 nevent.SetEventObject(parent);
859 nevent.SetCurrentFocus(parent);
860 GetParent()->GetEventHandler()->ProcessEvent(nevent);
861#else
862 Navigate(event.ShiftDown()
863 ? wxNavigationKeyEvent::IsBackward
864 : wxNavigationKeyEvent::IsForward);
865#endif
866 }
867
868 else if (keyCode == WXK_RETURN || keyCode == WXK_NUMPAD_ENTER) {
869 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
870 wxWindow *def = tlw->GetDefaultItem();
871 if (def && def->IsEnabled()) {
872 wxCommandEvent cevent(wxEVT_COMMAND_BUTTON_CLICKED,
873 def->GetId());
874 cevent.SetEventObject( def );
875 GetParent()->GetEventHandler()->ProcessEvent(cevent);
876 }
877 }
878
879 else {
880 event.Skip();
881 return;
882 }
883
884 if (digit != mFocusedDigit) {
886 }
887}
wxEVT_COMMAND_BUTTON_CLICKED
int min(int a, int b)
void Adjust(int steps, int dir, int focusedDigit)
void Updated(bool keyup=false)

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

Here is the call graph for this function:

◆ OnKeyUp()

void NumericTextCtrl::OnKeyUp ( wxKeyEvent &  event)
private

Definition at line 740 of file NumericTextCtrl.cpp.

741{
742 int keyCode = event.GetKeyCode();
743
744 event.Skip(true);
745
746 if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9))
747 keyCode -= WXK_NUMPAD0 - '0';
748
749 if ((keyCode >= '0' && keyCode <= '9' && !event.HasAnyModifiers()) ||
750 (keyCode == WXK_DELETE) ||
751 (keyCode == WXK_BACK) ||
752 (keyCode == WXK_UP) ||
753 (keyCode == WXK_DOWN)) {
754 Updated(true);
755 }
756}

References Updated().

Here is the call graph for this function:

◆ OnMouse()

void NumericTextCtrl::OnMouse ( wxMouseEvent &  event)
private

Definition at line 637 of file NumericTextCtrl.cpp.

638{
639 if (event.LeftDown() && event.GetX() >= mWidth) {
640 wxContextMenuEvent e;
641 OnContext(e);
642 }
643 else if (event.LeftDown()) {
644 SetFocus();
645
646 int bestDist = 9999;
647 unsigned int i;
648
649 mFocusedDigit = 0;
650 for(i = 0; i < mBoxes.size(); i++) {
651 int dist = abs(event.m_x - (GetBox(i).x +
652 GetBox(i).width/2));
653 if (dist < bestDist) {
654 mFocusedDigit = i;
655 bestDist = dist;
656 }
657 }
658
659 Refresh(false);
660 }
661 else if (event.RightDown() && mMenuEnabled) {
662 wxContextMenuEvent e;
663 OnContext(e);
664 }
665 else if(!mReadOnly && event.m_wheelRotation != 0 ) {
666 double steps = event.m_wheelRotation /
667 (event.m_wheelDelta > 0 ? (double)event.m_wheelDelta : 120.0) +
669 mScrollRemainder = steps - floor(steps);
670 steps = floor(steps);
671
672 Adjust((int)fabs(steps), steps < 0.0 ? -1 : 1, mFocusedDigit);
673 Updated();
674
675 Refresh();
676 }
677}
void OnContext(wxContextMenuEvent &event)

References NumericConverter::Adjust(), GetBox(), mBoxes, mFocusedDigit, mMenuEnabled, mReadOnly, mScrollRemainder, mWidth, OnContext(), BasicUI::SetFocus(), and Updated().

Here is the call graph for this function:

◆ OnPaint()

void NumericTextCtrl::OnPaint ( wxPaintEvent &  event)
private

Definition at line 515 of file NumericTextCtrl.cpp.

516{
517 if (!mFormatter)
518 return;
519
520 wxBufferedPaintDC dc(this);
521 bool focused = (FindFocus() == this);
522
523 dc.DrawBitmap(*mBackgroundBitmap, 0, 0);
524
525 wxPen Pen;
526 wxBrush Brush;
527 if (focused) {
528 theTheme.SetPenColour( Pen, clrTimeFontFocus );
529 dc.SetPen(Pen);
530 dc.SetBrush(*wxTRANSPARENT_BRUSH);
531 dc.DrawRectangle(0, 0, mWidth, mHeight);
532 dc.SetPen( wxNullPen );
533 }
534
535 dc.SetFont(*mDigitFont);
536 dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
537 dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
538
539 dc.SetPen(*wxTRANSPARENT_PEN);
540 theTheme.SetBrushColour( Brush , clrTimeBackFocus );
541 dc.SetBrush( Brush );
542
543 auto& digits = mFormatter->GetDigitInfos();
544 auto digitsCount = int(digits.size());
545 int i;
546 for(i = 0; i < digits.size(); i++) {
547 wxRect box = GetBox(i);
548 if (focused && mFocusedDigit == i) {
549 dc.DrawRectangle(box);
550 dc.SetTextForeground(theTheme.Colour( clrTimeFontFocus ));
551 dc.SetTextBackground(theTheme.Colour( clrTimeBackFocus ));
552 }
553 int pos = digits[i].pos;
554 wxString digit = mValueString.Mid(pos, 1);
555 int x = box.x + (mDigitBoxW - mDigitW)/2;
556 int y = box.y + (mDigitBoxH - mDigitH)/2;
557 dc.DrawText(digit, x, y);
558 if (focused && mFocusedDigit == i) {
559 dc.SetTextForeground(theTheme.Colour( clrTimeFont ));
560 dc.SetTextBackground(theTheme.Colour( clrTimeBack ));
561 }
562 }
563 dc.SetPen( wxNullPen );
564 dc.SetBrush( wxNullBrush );
565}
void SetPenColour(wxPen &Pen, int iIndex)
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:343

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

Here is the call graph for this function:

◆ SetCustomFormat()

bool NumericTextCtrl::SetCustomFormat ( const TranslatableString customFormat)

Definition at line 258 of file NumericTextCtrl.cpp.

259{
260 if (!NumericConverter::SetCustomFormat(customFormat))
261 return false;
262
264
265 return true;
266}
bool SetCustomFormat(const TranslatableString &customFormat)

References HandleFormatterChanged(), and NumericConverter::SetCustomFormat().

Here is the call graph for this function:

◆ SetDigitSize()

void NumericTextCtrl::SetDigitSize ( int  width,
int  height 
)

Definition at line 275 of file NumericTextCtrl.cpp.

276{
277 mDigitBoxW = width;
278 mDigitBoxH = height;
279 Layout();
280 Fit();
281}

References Fit(), Layout(), mDigitBoxH, and mDigitBoxW.

Referenced by TimeToolBar::OnSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetFieldFocus()

void NumericTextCtrl::SetFieldFocus ( int  digit)

Definition at line 889 of file NumericTextCtrl.cpp.

890{
891#if wxUSE_ACCESSIBILITY
892 if (!mFormatter || mBoxes.size() == 0)
893 {
894 mFocusedDigit = 0;
895 return;
896 }
897 mFocusedDigit = digit;
898 mLastField = mFormatter->GetDigitInfos()[mFocusedDigit].field + 1;
899
900 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
901 this,
902 wxOBJID_CLIENT,
903 mFocusedDigit + 1);
904#endif
905}

References mBoxes, mFocusedDigit, NumericConverter::mFormatter, and mLastField.

Referenced by OnKeyDown().

Here is the caller graph for this function:

◆ SetFormatName()

bool NumericTextCtrl::SetFormatName ( const NumericFormatSymbol formatName)

Definition at line 248 of file NumericTextCtrl.cpp.

249{
250 if (!NumericConverter::SetFormatName(formatName))
251 return false;
252
254
255 return true;
256}
bool SetFormatName(const NumericFormatSymbol &formatName)

References HandleFormatterChanged(), and NumericConverter::SetFormatName().

Referenced by OnContext(), EffectChangeSpeed::OnTimeCtrlUpdate(), TimeToolBar::SetAudioTimeFormat(), TimeDialog::TransferDataToWindow(), EffectChangeSpeed::TransferDataToWindow(), and EffectChangeSpeed::Update_TimeCtrl_ToLength().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetInvalidValue()

void NumericTextCtrl::SetInvalidValue ( double  invalidValue)

Definition at line 306 of file NumericTextCtrl.cpp.

307{
308 const bool wasInvalid = mAllowInvalidValue && (mValue == mInvalidValue);
309 mAllowInvalidValue = true;
310 mInvalidValue = invalidValue;
311 if (wasInvalid)
312 SetValue(invalidValue);
313}

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

Here is the call graph for this function:

◆ SetName()

void NumericTextCtrl::SetName ( const TranslatableString name)

Definition at line 213 of file NumericTextCtrl.cpp.

214{
215 wxControl::SetName( name.Translation() );
216}
const TranslatableString name
Definition: Distortion.cpp:76
wxString Translation() const

References name, and TranslatableString::Translation().

Referenced by LV2Editor::BuildPlain(), VSTEditor::BuildPlain(), TimeToolBar::Populate(), LadspaEditor::PopulateUI(), and VST3Editor::VST3Editor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetReadOnly()

void NumericTextCtrl::SetReadOnly ( bool  readOnly = true)

Definition at line 283 of file NumericTextCtrl.cpp.

284{
285 mReadOnly = readOnly;
286}

References mReadOnly.

Referenced by TimeToolBar::Populate().

Here is the caller graph for this function:

◆ SetTypeAndFormatName()

bool NumericTextCtrl::SetTypeAndFormatName ( const NumericConverterType type,
const NumericFormatSymbol formatName 
)

Definition at line 238 of file NumericTextCtrl.cpp.

239{
240 if (!NumericConverter::SetTypeAndFormatName(type, formatName))
241 return false;
242
244
245 return true;
246}
bool SetTypeAndFormatName(const NumericConverterType &type, const NumericFormatSymbol &formatName)

References HandleFormatterChanged(), and NumericConverter::SetTypeAndFormatName().

Here is the call graph for this function:

◆ SetValue()

void NumericTextCtrl::SetValue ( double  newValue)

◆ UpdateAutoFocus()

void NumericTextCtrl::UpdateAutoFocus ( )
private

Definition at line 221 of file NumericTextCtrl.cpp.

222{
223 if (!mAutoPos || !mFormatter)
224 return;
225
226 auto& digits = mFormatter->GetDigitInfos();
227
228 mFocusedDigit = 0;
229 while (mFocusedDigit < ((int)digits.size() - 1)) {
230 wxChar dgt = mValueString[digits[mFocusedDigit].pos];
231 if (dgt != '0') {
232 break;
233 }
235 }
236}

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

Referenced by HandleFormatterChanged(), and OnFocus().

Here is the caller graph for this function:

◆ Updated()

void NumericTextCtrl::Updated ( bool  keyup = false)
private

Definition at line 907 of file NumericTextCtrl.cpp.

908{
909 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
910
911 // This will give listeners the ability to do tasks when the
912 // update has been completed, like when the UP ARROW has been
913 // held down and is finally released.
914 event.SetInt(keyup);
915 event.SetEventObject(this);
916 GetEventHandler()->ProcessEvent(event);
917
918#if wxUSE_ACCESSIBILITY
919 if (!keyup) {
920 if (!mFormatter || mBoxes.size() == 0)
921 {
922 mFocusedDigit = 0;
923 return;
924 }
925
926 // The object_focus event is only needed by Window-Eyes
927 // and can be removed when we cease to support this screen reader.
928 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_FOCUS,
929 this,
930 wxOBJID_CLIENT,
931 mFocusedDigit + 1);
932
933 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
934 this,
935 wxOBJID_CLIENT,
936 mFocusedDigit + 1);
937 }
938#endif
939}
wxEVT_COMMAND_TEXT_UPDATED
Definition: Nyquist.cpp:133

References mBoxes, mFocusedDigit, NumericConverter::mFormatter, and wxEVT_COMMAND_TEXT_UPDATED.

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

Here is the caller graph for this function:

◆ ValueToControls()

void NumericTextCtrl::ValueToControls ( )
overrideprivatevirtual

Reimplemented from NumericConverter.

Definition at line 941 of file NumericTextCtrl.cpp.

942{
943 const wxString previousValueString = mValueString;
945 if (mValueString != previousValueString) {
946 // Doing this only when needed is an optimization.
947 // NumerixTextCtrls are used in the selection bar at the bottom
948 // of Audacity, and are updated at high frequency through
949 // SetValue() when Audacity is playing. This consumes a
950 // significant amount of CPU. Typically, when a track is
951 // playing, only one of the NumericTextCtrl actually changes
952 // (the audio position). We save CPU by updating the control
953 // only when needed.
954 Refresh(false);
955 }
956}
virtual void ValueToControls()

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

Referenced by HandleFormatterChanged(), OnKeyDown(), and SetValue().

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ NumericTextCtrlAx

friend class NumericTextCtrlAx
friend

Definition at line 37 of file NumericTextCtrl.h.

Member Data Documentation

◆ mAllowInvalidValue

bool NumericTextCtrl::mAllowInvalidValue
private

Definition at line 181 of file NumericTextCtrl.h.

Referenced by OnKeyDown(), and SetInvalidValue().

◆ mAutoPos

bool NumericTextCtrl::mAutoPos
private

Definition at line 174 of file NumericTextCtrl.h.

Referenced by UpdateAutoFocus().

◆ mBackgroundBitmap

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

Definition at line 154 of file NumericTextCtrl.h.

Referenced by Layout(), and OnPaint().

◆ mBorderBottom

int NumericTextCtrl::mBorderBottom
private

Definition at line 164 of file NumericTextCtrl.h.

Referenced by ComputeSizing().

◆ mBorderLeft

int NumericTextCtrl::mBorderLeft
private

Definition at line 161 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mBorderRight

int NumericTextCtrl::mBorderRight
private

Definition at line 163 of file NumericTextCtrl.h.

Referenced by ComputeSizing().

◆ mBorderTop

int NumericTextCtrl::mBorderTop
private

Definition at line 162 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mBoxes

std::vector<wxRect> NumericTextCtrl::mBoxes
private

◆ mButtonWidth

int NumericTextCtrl::mButtonWidth
private

Definition at line 167 of file NumericTextCtrl.h.

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

◆ mDigitBoxH

int NumericTextCtrl::mDigitBoxH
private

Definition at line 158 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), Layout(), OnPaint(), and SetDigitSize().

◆ mDigitBoxW

int NumericTextCtrl::mDigitBoxW
private

Definition at line 157 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), OnPaint(), and SetDigitSize().

◆ mDigitFont

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

Definition at line 156 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and OnPaint().

◆ mDigitH

int NumericTextCtrl::mDigitH
private

Definition at line 160 of file NumericTextCtrl.h.

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

◆ mDigitW

int NumericTextCtrl::mDigitW
private

Definition at line 159 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and OnPaint().

◆ mFieldPositions

std::vector<FieldPosition> NumericTextCtrl::mFieldPositions
private

Definition at line 147 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mFocusedDigit

int NumericTextCtrl::mFocusedDigit { 0 }
private

◆ mHeight

int NumericTextCtrl::mHeight
private

Definition at line 166 of file NumericTextCtrl.h.

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

◆ mLabelFont

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

Definition at line 156 of file NumericTextCtrl.h.

Referenced by ComputeSizing(), and Layout().

◆ mLastField

int NumericTextCtrl::mLastField
private

Definition at line 169 of file NumericTextCtrl.h.

Referenced by SetFieldFocus().

◆ mMenuEnabled

bool NumericTextCtrl::mMenuEnabled
private

Definition at line 151 of file NumericTextCtrl.h.

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

◆ mReadOnly

bool NumericTextCtrl::mReadOnly
private

Definition at line 152 of file NumericTextCtrl.h.

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

◆ mScrollRemainder

double NumericTextCtrl::mScrollRemainder
private

Definition at line 177 of file NumericTextCtrl.h.

Referenced by OnMouse().

◆ mType

NumericConverterType NumericTextCtrl::mType
private

Definition at line 179 of file NumericTextCtrl.h.

Referenced by OnContext().

◆ mWidth

int NumericTextCtrl::mWidth
private

Definition at line 165 of file NumericTextCtrl.h.

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


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