Changed PrusaBitmapTextRenderer's inheritance to wxDataViewRenderer instead of wxDataViewCustomRenderer :

to fix name editing under OSX
This commit is contained in:
YuSanka 2018-12-14 16:07:28 +01:00
parent dae01af2ac
commit 907e510535
3 changed files with 41 additions and 11 deletions

View File

@ -1654,7 +1654,9 @@ void ObjectList::change_part_type()
void ObjectList::last_volume_is_deleted(const int obj_idx) void ObjectList::last_volume_is_deleted(const int obj_idx)
{ {
if (obj_idx < 0 || (*m_objects).empty() || (*m_objects)[obj_idx]->volumes.empty()) if (obj_idx < 0 || m_objects->empty() ||
obj_idx <= m_objects->size() ||
(*m_objects)[obj_idx]->volumes.empty())
return; return;
auto volume = (*m_objects)[obj_idx]->volumes[0]; auto volume = (*m_objects)[obj_idx]->volumes[0];

View File

@ -1228,6 +1228,14 @@ void PrusaObjectDataViewModel::SetVolumeType(const wxDataViewItem &item, const i
ItemChanged(item); ItemChanged(item);
} }
PrusaBitmapTextRenderer::PrusaBitmapTextRenderer(wxDataViewCellMode mode /*= wxDATAVIEW_CELL_EDITABLE*/,
int align /*= wxDVR_DEFAULT_ALIGNMENT*/):
wxDataViewRenderer(wxT("PrusaDataViewBitmapText"), mode, align)
{
SetMode(mode);
SetAlignment(align);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// PrusaDataViewBitmapText // PrusaDataViewBitmapText
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1251,6 +1259,13 @@ bool PrusaBitmapTextRenderer::GetValue(wxVariant& WXUNUSED(value)) const
return false; return false;
} }
#if wxUSE_ACCESSIBILITY
wxString PrusaBitmapTextRenderer::GetAccessibleDescription() const
{
return m_value.GetText();
}
#endif // wxUSE_ACCESSIBILITY
bool PrusaBitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state) bool PrusaBitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state)
{ {
int xoffset = 0; int xoffset = 0;
@ -1291,12 +1306,12 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
PrusaDataViewBitmapText data; PrusaDataViewBitmapText data;
data << value; data << value;
m_bmp_from_editing_item = data.GetBitmap();
m_was_unusable_symbol = false; m_was_unusable_symbol = false;
wxPoint position = labelRect.GetPosition(); wxPoint position = labelRect.GetPosition();
if (m_bmp_from_editing_item.IsOk()) { if (data.GetBitmap().IsOk()) {
const int bmp_width = m_bmp_from_editing_item.GetWidth(); const int bmp_width = data.GetBitmap().GetWidth();
position.x += bmp_width; position.x += bmp_width;
labelRect.SetWidth(labelRect.GetWidth() - bmp_width); labelRect.SetWidth(labelRect.GetWidth() - bmp_width);
} }
@ -1304,6 +1319,7 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab
wxTextCtrl* text_editor = new wxTextCtrl(parent, wxID_ANY, data.GetText(), wxTextCtrl* text_editor = new wxTextCtrl(parent, wxID_ANY, data.GetText(),
position, labelRect.GetSize(), wxTE_PROCESS_ENTER); position, labelRect.GetSize(), wxTE_PROCESS_ENTER);
text_editor->SetInsertionPointEnd(); text_editor->SetInsertionPointEnd();
text_editor->SelectAll();
return text_editor; return text_editor;
} }
@ -1323,7 +1339,17 @@ bool PrusaBitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant&
} }
} }
value << PrusaDataViewBitmapText(text_editor->GetValue(), m_bmp_from_editing_item); // The icon can't be edited so get its old value and reuse it.
wxVariant valueOld;
GetView()->GetModel()->GetValue(valueOld, m_item, 0);
PrusaDataViewBitmapText bmpText;
bmpText << valueOld;
// But replace the text with the value entered by user.
bmpText.SetText(text_editor->GetValue());
value << bmpText;
return true; return true;
} }

View File

@ -519,15 +519,18 @@ public:
// PrusaBitmapTextRenderer // PrusaBitmapTextRenderer
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class PrusaBitmapTextRenderer : public wxDataViewCustomRenderer class PrusaBitmapTextRenderer : public wxDataViewRenderer//CustomRenderer
{ {
public: public:
PrusaBitmapTextRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, PrusaBitmapTextRenderer(wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
int align = wxDVR_DEFAULT_ALIGNMENT): int align = wxDVR_DEFAULT_ALIGNMENT);//:
wxDataViewCustomRenderer(wxT("PrusaDataViewBitmapText"), mode, align) {} // wxDataViewRenderer/*CustomRenderer*/(wxT("PrusaDataViewBitmapText"), mode, align) {}
bool SetValue(const wxVariant &value); bool SetValue(const wxVariant &value);
bool GetValue(wxVariant &value) const; bool GetValue(wxVariant &value) const;
#if wxUSE_ACCESSIBILITY
virtual wxString GetAccessibleDescription() const override;
#endif // wxUSE_ACCESSIBILITY
virtual bool Render(wxRect cell, wxDC *dc, int state); virtual bool Render(wxRect cell, wxDC *dc, int state);
virtual wxSize GetSize() const; virtual wxSize GetSize() const;
@ -542,8 +545,7 @@ public:
private: private:
PrusaDataViewBitmapText m_value; PrusaDataViewBitmapText m_value;
wxBitmap m_bmp_from_editing_item; bool m_was_unusable_symbol {false};
bool m_was_unusable_symbol;
}; };