mirror of
https://github.com/cookiengineer/audacity
synced 2025-04-30 23:59:41 +02:00
From: martin@steghoefer.eu [patches 0017 and 0018] Fix compilation problem with wxWidgets 3.0:
0017: Encapsulation of reference type returned by wxString::operator[] 0018: Interface change for classes deriving from wxGridTableBase 0017 ---- The NumericTextCtrl relies on the fact that the value returned by wxString::operator[] is a "wxChar&". However, in wxWidgets 3.0 it is a wxUniCharRef (encapsulation of a reference to characters, to improve unicode handling). wxString::reference provides the correct type in both wx2.8 and wx3.0 and can be used as writable reference in both cases. However, for the case of an update of the reference itself (instead of the value), there is no common syntax. In this case the character position within the string has to be used as reference. 0018 ---- With wx3.0, different methods have to be implemented (EndEdit with new signature and ApplyEdit) than with wx2.8 (only EndEdit with old signature). Now both versions are implemented in parallel in the classes TimeEditor and ChoiceEditor (one version essentially being a wrapper of the other one). Note: Superseding the previous solution of the issue (committed in r13403) by one that avoids code duplication. This should avoid problems with missed changes in code that isn't used with the wxWidgets version that the developer tests with (like just happened in r13557).
This commit is contained in:
parent
83e8983165
commit
649315c644
@ -71,7 +71,8 @@ void TimeEditor::BeginEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
wxGridTableBase *table = grid->GetTable();
|
||||
|
||||
table->GetValue(row, col).ToDouble(&mOld);
|
||||
mOldString = table->GetValue(row, col);
|
||||
mOldString.ToDouble(&mOld);
|
||||
|
||||
GetTimeCtrl()->SetValue(mOld);
|
||||
GetTimeCtrl()->EnableMenu();
|
||||
@ -79,16 +80,24 @@ void TimeEditor::BeginEdit(int row, int col, wxGrid *grid)
|
||||
GetTimeCtrl()->SetFocus();
|
||||
}
|
||||
|
||||
#if wxCHECK_VERSION(3,0,0)
|
||||
|
||||
bool TimeEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid *WXUNUSED(grid), const wxString & WXUNUSED(oldval), wxString *newval)
|
||||
bool TimeEditor::EndEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
double newtime = GetTimeCtrl()->GetTimeValue();
|
||||
wxString newvalue;
|
||||
bool changed = EndEdit(row, col, grid, mOldString, &newvalue);
|
||||
if (changed) {
|
||||
ApplyEdit(row, col, grid);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool TimeEditor::EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval)
|
||||
{
|
||||
double newtime = GetTimeCtrl()->GetValue();
|
||||
bool changed = newtime != mOld;
|
||||
|
||||
if (changed) {
|
||||
mNew = newtime;
|
||||
*newval = wxString::Format(wxT("%g"), newtime);
|
||||
mValueAsString = wxString::Format(wxT("%g"), newtime);
|
||||
*newval = mValueAsString;
|
||||
}
|
||||
|
||||
return changed;
|
||||
@ -96,25 +105,9 @@ bool TimeEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid *WXU
|
||||
|
||||
void TimeEditor::ApplyEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%g"), mNew));
|
||||
grid->GetTable()->SetValue(row, col, mValueAsString);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool TimeEditor::EndEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
double newtime = GetTimeCtrl()->GetValue();
|
||||
bool changed = newtime != mOld;
|
||||
|
||||
if (changed) {
|
||||
grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%g"), newtime));
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void TimeEditor::Reset()
|
||||
{
|
||||
GetTimeCtrl()->SetValue(mOld);
|
||||
@ -319,9 +312,19 @@ void ChoiceEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||
Choice()->SetFocus();
|
||||
}
|
||||
|
||||
#if wxCHECK_VERSION(3,0,0)
|
||||
bool ChoiceEditor::EndEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
wxString newvalue;
|
||||
bool changed = EndEdit(row, col, grid, mOld, &newvalue);
|
||||
if (changed) {
|
||||
ApplyEdit(row, col, grid);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
bool ChoiceEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid* WXUNUSED(grid), const wxString & WXUNUSED(oldval), wxString *newval)
|
||||
bool ChoiceEditor::EndEdit(int row, int col,
|
||||
const wxGrid* grid,
|
||||
const wxString &oldval, wxString *newval)
|
||||
{
|
||||
int sel = Choice()->GetSelection();
|
||||
|
||||
@ -332,47 +335,22 @@ bool ChoiceEditor::EndEdit(int WXUNUSED(row), int WXUNUSED(col), const wxGrid* W
|
||||
}
|
||||
|
||||
wxString val = mChoices[sel];
|
||||
if (val == mOld)
|
||||
bool changed = val != mOld;
|
||||
|
||||
if (changed)
|
||||
{
|
||||
return false;
|
||||
mValueAsString = val;
|
||||
*newval = val;
|
||||
}
|
||||
|
||||
*newval = val;
|
||||
|
||||
mNew = val;
|
||||
|
||||
return true;
|
||||
return changed;
|
||||
}
|
||||
|
||||
void ChoiceEditor::ApplyEdit(int row, int col, wxGrid *grid)
|
||||
{
|
||||
grid->GetTable()->SetValue(row, col, mNew);
|
||||
grid->GetTable()->SetValue(row, col, mValueAsString);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
bool ChoiceEditor::EndEdit(int row, int col,
|
||||
wxGrid* grid)
|
||||
{
|
||||
int sel = Choice()->GetSelection();
|
||||
|
||||
// This can happen if the wxChoice control is displayed and the list of choices get changed
|
||||
if ((sel < 0) || (sel >= (int)(mChoices.GetCount())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString val = mChoices[sel];
|
||||
if (val == mOld)
|
||||
return false;
|
||||
|
||||
grid->GetTable()->SetValue(row, col, val);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void ChoiceEditor::Reset()
|
||||
{
|
||||
Choice()->SetSelection(mChoices.Index(mOld));
|
||||
|
@ -53,13 +53,11 @@ class TimeEditor:public wxGridCellEditor
|
||||
|
||||
void BeginEdit(int row, int col, wxGrid *grid);
|
||||
|
||||
#if wxCHECK_VERSION(3,0,0)
|
||||
bool EndEdit(int row, int col, const wxGrid *grid,
|
||||
const wxString & oldval, wxString *newval);
|
||||
void ApplyEdit(int, int, wxGrid *);
|
||||
#else
|
||||
bool EndEdit(int row, int col, wxGrid *grid);
|
||||
#endif
|
||||
|
||||
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval);
|
||||
|
||||
void ApplyEdit(int row, int col, wxGrid *grid);
|
||||
|
||||
void Reset();
|
||||
|
||||
@ -78,7 +76,8 @@ class TimeEditor:public wxGridCellEditor
|
||||
wxString mFormat;
|
||||
double mRate;
|
||||
double mOld;
|
||||
double mNew;
|
||||
wxString mOldString;
|
||||
wxString mValueAsString;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -133,13 +132,11 @@ public:
|
||||
|
||||
void BeginEdit(int row, int col, wxGrid *grid);
|
||||
|
||||
#if wxCHECK_VERSION(3,0,0)
|
||||
bool EndEdit(int row, int col, const wxGrid *grid,
|
||||
const wxString & oldval, wxString *newval);
|
||||
void ApplyEdit(int, int, wxGrid *);
|
||||
#else
|
||||
bool EndEdit(int row, int col, wxGrid *grid);
|
||||
#endif
|
||||
|
||||
bool EndEdit(int row, int col, const wxGrid *grid, const wxString &oldval, wxString *newval);
|
||||
|
||||
void ApplyEdit(int row, int col, wxGrid *grid);
|
||||
|
||||
void Reset();
|
||||
|
||||
@ -174,7 +171,7 @@ public:
|
||||
|
||||
wxArrayString mChoices;
|
||||
wxString mOld;
|
||||
wxString mNew;
|
||||
wxString mValueAsString;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -1594,15 +1594,15 @@ void NumericTextCtrl::OnKeyDown(wxKeyEvent &event)
|
||||
// Convert numeric keypad entries.
|
||||
if ((keyCode >= WXK_NUMPAD0) && (keyCode <= WXK_NUMPAD9)) keyCode -= WXK_NUMPAD0 - '0';
|
||||
|
||||
wxChar *theDigit = &mValueString[mDigits[mFocusedDigit].pos];
|
||||
if (keyCode >= '0' && keyCode <= '9') {
|
||||
if (*theDigit == wxChar('-')) {
|
||||
int digitPosition = mDigits[mFocusedDigit].pos;
|
||||
if (mValueString[digitPosition] == wxChar('-')) {
|
||||
mValue = 0;
|
||||
ValueToControls();
|
||||
// Beware relocation of the string
|
||||
theDigit = &mValueString[mDigits[mFocusedDigit].pos];
|
||||
digitPosition = mDigits[mFocusedDigit].pos;
|
||||
}
|
||||
*theDigit = wxChar(keyCode);
|
||||
mValueString[digitPosition] = wxChar(keyCode);
|
||||
ControlsToValue();
|
||||
ValueToControls();
|
||||
mFocusedDigit = (mFocusedDigit + 1) % (mDigits.GetCount());
|
||||
@ -1614,9 +1614,9 @@ void NumericTextCtrl::OnKeyDown(wxKeyEvent &event)
|
||||
mFocusedDigit--;
|
||||
mFocusedDigit += mDigits.GetCount();
|
||||
mFocusedDigit %= mDigits.GetCount();
|
||||
theDigit = &mValueString[mDigits[mFocusedDigit].pos];
|
||||
if (*theDigit != wxChar('-'))
|
||||
*theDigit = '0';
|
||||
wxString::reference theDigit = mValueString[mDigits[mFocusedDigit].pos];
|
||||
if (theDigit != wxChar('-'))
|
||||
theDigit = '0';
|
||||
ControlsToValue();
|
||||
ValueToControls();
|
||||
Updated();
|
||||
|
Loading…
x
Reference in New Issue
Block a user