return true;
}
-/* static */
-wxString wxControlBase::GetLabelText(const wxString& label)
-{
- // we don't want strip the TABs here, just the mnemonics
- return wxStripMenuCodes(label, wxStrip_Mnemonics);
-}
-
void wxControlBase::Command(wxCommandEvent& event)
{
(void)GetEventHandler()->ProcessEvent(event);
void wxControlBase::InitCommandEvent(wxCommandEvent& event) const
{
- event.SetEventObject((wxControlBase *)this); // const_cast
+ event.SetEventObject(const_cast<wxControlBase *>(this));
// event.SetId(GetId()); -- this is usuall done in the event ctor
#endif // wxUSE_RADIOBTN
}
+/* static */
+wxString wxControlBase::GetLabelText(const wxString& label)
+{
+ // we don't want strip the TABs here, just the mnemonics
+ return wxStripMenuCodes(label, wxStrip_Mnemonics);
+}
+
/* static */
wxString wxControlBase::RemoveMnemonics(const wxString& str)
{
+ // we don't want strip the TABs here, just the mnemonics
return wxStripMenuCodes(str, wxStrip_Mnemonics);
}
// NOTE: the following piece of code works also when len == 1
// start the removal process from the middle of the string
- // i.e. separe the string in three parts:
+ // i.e. separe the string in three parts:
// - the first one to preserve, valid range [0;initialCharToRemove-1] or the empty range if initialCharToRemove==0
// - the second one to remove, valid range [initialCharToRemove;endCharToRemove]
// - the third one to preserve, valid range [endCharToRemove+1;len-1] or the empty range if endCharToRemove==len-1
// NOTE: empty range != range [0;0] since the range [0;0] contains 1 character (the zero-th one)!
- initialCharToRemove = len/2;
- size_t endCharToRemove = len/2; // index of the last character to remove; valid range is [0;len-1]
+ initialCharToRemove = len/2; // index of the last character to remove; valid range is [0;len-1]
+ size_t endCharToRemove = initialCharToRemove - 1; // initial removal range is empty
int removedPx = 0;
+ bool removeFromStart = true;
for ( ; removedPx < excessPx; )
{
- // try to remove the last character of the first part of the string
- if (initialCharToRemove > 0)
+ const bool canRemoveFromStart = initialCharToRemove > 0;
+ const bool canRemoveFromEnd = endCharToRemove < len - 1;
+
+ if ( !canRemoveFromStart && !canRemoveFromEnd )
{
+ // we need to remove all the characters of the string!
+ break;
+ }
+
+ // Remove from the beginning in even steps and from the end
+ // in odd steps, unless we exhausted one side already:
+ removeFromStart = !removeFromStart;
+ if ( removeFromStart && !canRemoveFromStart )
+ removeFromStart = false;
+ else if ( !removeFromStart && !canRemoveFromEnd )
+ removeFromStart = true;
+
+ if ( removeFromStart )
+ {
+ // try to remove the last character of the first part of the string
+
// width of the (initialCharToRemove-1)-th character
int widthPx;
if (initialCharToRemove >= 2)
widthPx = charOffsetsPx[initialCharToRemove-1] - charOffsetsPx[initialCharToRemove-2];
else
- widthPx = charOffsetsPx[initialCharToRemove-1];
+ widthPx = charOffsetsPx[initialCharToRemove-1];
// the (initialCharToRemove-1)-th character is the first char of the string
-
+
wxASSERT(widthPx >= 0); // widthPx is zero for e.g. tab characters
// mark the (initialCharToRemove-1)-th character as removable
initialCharToRemove--;
removedPx += widthPx;
- }
- // try to remove the first character of the last part of the string
- if (endCharToRemove < len - 1 &&
- removedPx < excessPx)
+ continue; // don't remove anything else
+ }
+ else // !removeFromStart
{
+ // try to remove the first character of the last part of the string
+
// width of the (endCharToRemove+1)-th character
int widthPx = charOffsetsPx[endCharToRemove+1] -
charOffsetsPx[endCharToRemove];
// mark the (endCharToRemove+1)-th character as removable
endCharToRemove++;
removedPx += widthPx;
- }
- if (initialCharToRemove == 0 && endCharToRemove == len-1)
- {
- // we need to remove all the characters of the string!
- break;
+ continue; // don't remove anything else
}
}
return curLine;
}
- wxASSERT(initialCharToRemove >= 0 && initialCharToRemove <= len-1); // see valid range for initialCharToRemove above
+ wxASSERT(initialCharToRemove <= len-1); // see valid range for initialCharToRemove above
wxASSERT(nCharsToRemove >= 1 && nCharsToRemove <= len-initialCharToRemove); // see valid range for nCharsToRemove above
// erase nCharsToRemove characters after initialCharToRemove (included);
int removedPx;
if (initialCharToRemove >= 1)
removedPx = charOffsetsPx[initialCharToRemove+nCharsToRemove-1] - charOffsetsPx[initialCharToRemove-1];
- else
+ else
removedPx = charOffsetsPx[initialCharToRemove+nCharsToRemove-1];
wxASSERT(removedPx >= excessPx);