Try to fix DnD under OSX

+ try to fix wxEVT_CHAR under OSX
+ some code-rebase
This commit is contained in:
YuSanka 2018-12-11 09:37:58 +01:00
parent 05fef33b10
commit edd79883a1
2 changed files with 49 additions and 35 deletions

View File

@ -60,11 +60,7 @@ ObjectList::ObjectList(wxWindow* parent) :
#endif //__WXMSW__ #endif //__WXMSW__
}); });
Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [this](wxDataViewEvent& event) { // Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX
context_menu();
});
Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX
#ifdef __WXMSW__ #ifdef __WXMSW__
GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) { GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) {
@ -73,15 +69,15 @@ ObjectList::ObjectList(wxWindow* parent) :
}); });
#endif //__WXMSW__ #endif //__WXMSW__
Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, [this](wxDataViewEvent& e) { on_begin_drag(e); }); Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, &ObjectList::OnContextMenu, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, [this](wxDataViewEvent& e) { on_drop_possible(e); });
Bind(wxEVT_DATAVIEW_ITEM_DROP, [this](wxDataViewEvent& e) { on_drop(e); }); Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, &ObjectList::OnBeginDrag, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, &ObjectList::OnDropPossible, this);
Bind(wxEVT_DATAVIEW_ITEM_DROP, &ObjectList::OnDrop, this);
Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &ObjectList::ItemValueChanged, this);
Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, [this](wxCommandEvent& e) { last_volume_is_deleted(e.GetInt()); }); Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED, [this](wxCommandEvent& e) { last_volume_is_deleted(e.GetInt()); });
// Bind(wxEVT_DATAVIEW_ITEM_START_EDITING, &ObjectList::OnStartEditing, this);
// Bind(wxEVT_DATAVIEW_ITEM_EDITING_DONE, &ObjectList::OnEditingDone, this);
Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, &ObjectList::ItemValueChanged, this);
} }
ObjectList::~ObjectList() ObjectList::~ObjectList()
@ -97,6 +93,10 @@ void ObjectList::create_objects_ctrl()
// 2. change it to the normal min value (200) after first whole App updating/layouting // 2. change it to the normal min value (200) after first whole App updating/layouting
SetMinSize(wxSize(-1, 1500)); // #ys_FIXME SetMinSize(wxSize(-1, 1500)); // #ys_FIXME
#ifdef __WXOSX__
Connect(wxEVT_CHAR, wxKeyEventHandler(ObjectList::OnChar), NULL, this);
#endif //__WXOSX__
m_sizer = new wxBoxSizer(wxVERTICAL); m_sizer = new wxBoxSizer(wxVERTICAL);
m_sizer->Add(this, 1, wxGROW | wxLEFT, 20); m_sizer->Add(this, 1, wxGROW | wxLEFT, 20);
@ -255,7 +255,7 @@ void ObjectList::update_objects_list_extruder_column(int extruders_count)
m_prevent_update_extruder_in_config = false; m_prevent_update_extruder_in_config = false;
} }
void ObjectList::set_extruder_column_hidden(bool hide) void ObjectList::set_extruder_column_hidden(const bool hide) const
{ {
GetColumn(1)->SetHidden(hide); GetColumn(1)->SetHidden(hide);
} }
@ -333,13 +333,21 @@ void ObjectList::selection_changed()
} }
part_selection_changed(); part_selection_changed();
// #ifdef __WXOSX__
// update_extruder_in_config(m_selected_extruder);
// #endif //__WXOSX__
} }
void ObjectList::context_menu() void ObjectList::OnChar(wxKeyEvent& event)
{
if (event.GetKeyCode() == WXK_DELETE && event.GetKeyCode() == WXK_BACK){
printf("WXK_BACK\n");
remove();
}
else if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_SHIFT))
select_item_all_children();
else
event.Skip();
}
void ObjectList::OnContextMenu(wxDataViewEvent&)
{ {
wxDataViewItem item; wxDataViewItem item;
wxDataViewColumn* col; wxDataViewColumn* col;
@ -422,7 +430,7 @@ struct draging_item_data
int vol_idx; int vol_idx;
}; };
void ObjectList::on_begin_drag(wxDataViewEvent &event) void ObjectList::OnBeginDrag(wxDataViewEvent &event)
{ {
wxDataViewItem item(event.GetItem()); wxDataViewItem item(event.GetItem());
@ -437,7 +445,7 @@ void ObjectList::on_begin_drag(wxDataViewEvent &event)
/* Under MSW or OSX, DnD moves an item to the place of another selected item /* Under MSW or OSX, DnD moves an item to the place of another selected item
* But under GTK, DnD moves an item between another two items. * But under GTK, DnD moves an item between another two items.
* And as a result - call EVT_CHANGE_SELECTION to unselect all items. * And as a result - call EVT_CHANGE_SELECTION to unselect all items.
* To prevent such behavior use g_prevent_list_events * To prevent such behavior use m_prevent_list_events
**/ **/
m_prevent_list_events = true;//it's needed for GTK m_prevent_list_events = true;//it's needed for GTK
@ -445,29 +453,31 @@ void ObjectList::on_begin_drag(wxDataViewEvent &event)
obj->SetText(wxString::Format("%d", m_objects_model->GetVolumeIdByItem(item))); obj->SetText(wxString::Format("%d", m_objects_model->GetVolumeIdByItem(item)));
event.SetDataObject(obj); event.SetDataObject(obj);
event.SetDragFlags(/*wxDrag_AllowMove*/wxDrag_DefaultMove); // allows both copy and move; event.SetDragFlags(/*wxDrag_AllowMove*/wxDrag_DefaultMove); // allows both copy and move;
printf("BeginDrag\n");
} }
void ObjectList::on_drop_possible(wxDataViewEvent &event) void ObjectList::OnDropPossible(wxDataViewEvent &event)
{ {
wxDataViewItem item(event.GetItem()); wxDataViewItem item(event.GetItem());
// only allow drags for item or background, not containers // only allow drags for item or background, not containers
if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || if (event.GetDataFormat() != wxDF_UNICODETEXT || item.IsOk() &&
event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume) (m_objects_model->GetParent(item) == wxDataViewItem(0) || m_objects_model->GetItemType(item) != itVolume))
event.Veto(); event.Veto();
printf("DropPossible\n");
} }
void ObjectList::on_drop(wxDataViewEvent &event) void ObjectList::OnDrop(wxDataViewEvent &event)
{ {
wxDataViewItem item(event.GetItem()); wxDataViewItem item(event.GetItem());
// only allow drops for item, not containers if (m_selected_object_id < 0 || event.GetDataFormat() != wxDF_UNICODETEXT ||
if (m_selected_object_id < 0 || item.IsOk() && ( m_objects_model->GetParent(item) == wxDataViewItem(0) ||
item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || m_objects_model->GetItemType(item) != itVolume) ) {
event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume) {
event.Veto(); event.Veto();
return; return;
} }
printf("Drop\n");
wxTextDataObject obj; wxTextDataObject obj;
obj.SetData(wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer()); obj.SetData(wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer());
@ -495,6 +505,8 @@ void ObjectList::on_drop(wxDataViewEvent &event)
m_parts_changed = true; m_parts_changed = true;
parts_changed(m_selected_object_id); parts_changed(m_selected_object_id);
printf("DropCompleted\n");
// m_prevent_list_events = false; // m_prevent_list_events = false;
} }

View File

@ -104,9 +104,9 @@ public:
wxDataViewColumn* create_objects_list_extruder_column(int extruders_count); wxDataViewColumn* create_objects_list_extruder_column(int extruders_count);
void update_objects_list_extruder_column(int extruders_count); void update_objects_list_extruder_column(int extruders_count);
// show/hide "Extruder" column for Objects List // show/hide "Extruder" column for Objects List
void set_extruder_column_hidden(bool hide); void set_extruder_column_hidden(const bool hide) const;
// update extruder in current config // update extruder in current config
void update_extruder_in_config(const wxDataViewItem& item/*wxString& selection*/); void update_extruder_in_config(const wxDataViewItem& item);
void update_extruder_values_for_items(const int max_extruder); void update_extruder_values_for_items(const int max_extruder);
void init_icons(); void init_icons();
@ -114,14 +114,9 @@ public:
void set_tooltip_for_item(const wxPoint& pt); void set_tooltip_for_item(const wxPoint& pt);
void selection_changed(); void selection_changed();
void context_menu();
void show_context_menu(); void show_context_menu();
void key_event(wxKeyEvent& event); void key_event(wxKeyEvent& event);
void on_begin_drag(wxDataViewEvent &event);
void on_drop_possible(wxDataViewEvent &event);
void on_drop(wxDataViewEvent &event);
void get_settings_choice(const wxString& category_name); void get_settings_choice(const wxString& category_name);
void append_menu_item_add_generic(wxMenuItem* menu, const int type); void append_menu_item_add_generic(wxMenuItem* menu, const int type);
void append_menu_items_add_volume(wxMenu* menu); void append_menu_items_add_volume(wxMenu* menu);
@ -203,6 +198,13 @@ public:
void update_settings_items(); void update_settings_items();
private: private:
void OnChar(wxKeyEvent& event);
void OnContextMenu(wxDataViewEvent &event);
void OnBeginDrag(wxDataViewEvent &event);
void OnDropPossible(wxDataViewEvent &event);
void OnDrop(wxDataViewEvent &event);
void ItemValueChanged(wxDataViewEvent &event); void ItemValueChanged(wxDataViewEvent &event);
}; };