+void wxRichTextFormattingDialog::SetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox)
+{
+ int unitsIdx = 0;
+
+ if (!dim.IsValid())
+ {
+ checkBox->SetValue(false);
+ valueCtrl->SetValue(wxT("0"));
+ unitsCtrl->SetSelection(0);
+#if 0
+ dim.SetValue(0);
+ dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS);
+#endif
+ }
+ else
+ {
+ checkBox->SetValue(true);
+ if (dim.GetUnits() == wxTEXT_ATTR_UNITS_TENTHS_MM)
+ {
+ unitsIdx = 1;
+ float value = float(dim.GetValue()) / 100.0;
+ valueCtrl->SetValue(wxString::Format(wxT("%.2f"), value));
+ }
+ else if (dim.GetUnits() == wxTEXT_ATTR_UNITS_PERCENTAGE)
+ {
+ unitsIdx = 2;
+ valueCtrl->SetValue(wxString::Format(wxT("%d"), (int) dim.GetValue()));
+ }
+ else
+ {
+ unitsIdx = 0;
+ valueCtrl->SetValue(wxString::Format(wxT("%d"), (int) dim.GetValue()));
+ }
+
+ unitsCtrl->SetSelection(unitsIdx);
+ }
+}
+
+void wxRichTextFormattingDialog::GetDimensionValue(wxTextAttrDimension& dim, wxTextCtrl* valueCtrl, wxComboBox* unitsCtrl, wxCheckBox* checkBox)
+{
+ if (!checkBox->GetValue())
+ {
+ dim.Reset();
+ }
+ else
+ {
+ if (unitsCtrl->GetSelection() == 1)
+ dim.SetUnits(wxTEXT_ATTR_UNITS_TENTHS_MM);
+ else if (unitsCtrl->GetSelection() == 2)
+ dim.SetUnits(wxTEXT_ATTR_UNITS_PERCENTAGE);
+ else
+ dim.SetUnits(wxTEXT_ATTR_UNITS_PIXELS);
+
+ int value = 0;
+ if (ConvertFromString(valueCtrl->GetValue(), value, dim.GetUnits()))
+ dim.SetValue(value);
+ }
+}
+
+bool wxRichTextFormattingDialog::ConvertFromString(const wxString& string, int& ret, int scale)
+{
+ const wxChar* chars = string.GetData();
+ int remain = 2;
+ bool dot = false;
+ ret = 0;
+
+ for (unsigned int i = 0; i < string.Len() && remain; i++)
+ {
+ if (!(chars[i] >= wxT('0') && chars[i] <= wxT('9')) && !(scale == wxTEXT_ATTR_UNITS_TENTHS_MM && chars[i] == wxT('.')))
+ return false;
+
+ if (chars[i] == wxT('.'))
+ {
+ dot = true;
+ continue;
+ }
+
+ if (dot)
+ remain--;
+
+ ret = ret * 10 + chars[i] - wxT('0');
+ }
+
+ while (remain-- > 0 && scale == wxTEXT_ATTR_UNITS_TENTHS_MM)
+ ret *= 10;
+
+ return true;
+}
+