diff --git a/src/data/format/clipboard.cpp b/src/data/format/clipboard.cpp index 1b38d807..19d1cfb5 100644 --- a/src/data/format/clipboard.cpp +++ b/src/data/format/clipboard.cpp @@ -155,9 +155,12 @@ CardsOnClipboard::CardsOnClipboard(const SetP& set, const String id, const vecto } String temp_path = wxFileName::CreateTempFileName(_("mse")) + _(".png"); img.SaveFile(temp_path, wxBITMAP_TYPE_PNG); - wxFileDataObject* data = new wxFileDataObject(); - data->AddFile(temp_path); - Add(data); + wxFileDataObject* fileData = new wxFileDataObject(); + fileData->AddFile(temp_path); + Add(fileData); + wxImageDataObject* imgData = new wxImageDataObject(); + imgData->SetImage(img); + Add(imgData); } // Conversion to serialized card format Add(new CardsDataObject(set, id, cards), true); diff --git a/src/gui/control/card_list.cpp b/src/gui/control/card_list.cpp index a71205aa..5d0da217 100644 --- a/src/gui/control/card_list.cpp +++ b/src/gui/control/card_list.cpp @@ -58,7 +58,7 @@ CardListBase* CardSelectEvent::getTheCardList() const { // ----------------------------------------------------------------------------- : CardListBase CardListBase::CardListBase(Window* parent, int id, long additional_style) - : ItemList(parent, id, additional_style, true) + : ItemList(parent, id, additional_style, true) , drop_timer(this, ID_DROP_TIMER) { drop_target = new CardListDropTarget(this); } @@ -626,17 +626,23 @@ void CardListBase::onChar(wxKeyEvent& ev) { } } -void CardListBase::onBeginDrag(wxListEvent&) { - vector cards; - getSelection(cards); - String transaction_id = generate_uid(); - CardsOnClipboard* card_data = new CardsOnClipboard(set, transaction_id, cards); - drop_target->ignored_id = transaction_id; - wxDropSource drag_source(this); - drag_source.SetData(*card_data); - drag_source.DoDragDrop(wxDrag_CopyOnly); +void CardListBase::onBeginDrag(wxListEvent&) { + drop_timer.Start(200, wxTIMER_ONE_SHOT); } +void CardListBase::OnDragTimer(wxTimerEvent& ev) { + if (ev.GetId() == ID_DROP_TIMER && wxGetMouseState().LeftIsDown()) { + vector cards; + getSelection(cards); + String transaction_id = generate_uid(); + CardsOnClipboard* card_data = new CardsOnClipboard(set, transaction_id, cards); + drop_target->ignored_id = transaction_id; + wxDropSource drag_source(this); + drag_source.SetData(*card_data); + drag_source.DoDragDrop(wxDrag_CopyOnly); + } +} + void CardListBase::onDrag(wxMouseEvent& ev) { ev.Skip(); if (!allowModify()) return; @@ -704,7 +710,8 @@ BEGIN_EVENT_TABLE(CardListBase, ItemList) EVT_LIST_COL_RIGHT_CLICK (wxID_ANY, CardListBase::onColumnRightClick) EVT_LIST_COL_END_DRAG (wxID_ANY, CardListBase::onColumnResize) EVT_LIST_ITEM_ACTIVATED (wxID_ANY, CardListBase::onItemActivate) - EVT_LIST_BEGIN_DRAG (wxID_ANY, CardListBase::onBeginDrag) + EVT_LIST_BEGIN_DRAG (wxID_ANY, CardListBase::onBeginDrag) + EVT_TIMER (ID_DROP_TIMER, CardListBase::OnDragTimer) EVT_CHAR ( CardListBase::onChar) EVT_MOTION ( CardListBase::onDrag) EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns) diff --git a/src/gui/control/card_list.hpp b/src/gui/control/card_list.hpp index 25946cc2..dfcd245e 100644 --- a/src/gui/control/card_list.hpp +++ b/src/gui/control/card_list.hpp @@ -70,8 +70,9 @@ public: inline void setCard(const CardP& card, bool event = false) { selectItem(card, true, event); } // --------------------------------------------------- : Clipboard and Drag'n'Drop - + CardListDropTarget* drop_target; + wxTimer drop_timer; bool canCut() const override; bool canCopy() const override; @@ -167,7 +168,8 @@ private: void onItemActivate (wxListEvent&); void onSelectColumns (wxCommandEvent&); void onChar (wxKeyEvent&); - void onBeginDrag (wxListEvent&); + void onBeginDrag (wxListEvent&); + void OnDragTimer (wxTimerEvent&); void onDrag (wxMouseEvent&); void onContextMenu (wxContextMenuEvent&); }; diff --git a/src/script/functions/json.cpp b/src/script/functions/json.cpp index 74817680..2ca44b8e 100644 --- a/src/script/functions/json.cpp +++ b/src/script/functions/json.cpp @@ -321,7 +321,10 @@ ScriptValueP json_to_mse(const boost::json::value& jv, Set* set) { // if the string contains nul bytes, we have to use the std::string constructor, even though we can't specify the encoding if (nulpos < string.size()) return to_script(String(string)); // if the string doesn't contain nul bytes, we can use the constructor that allows to specify the encoding - else return to_script(String(cstring, wxConvUTF8)); + String wxstring(cstring, wxConvUTF8); + if (!wxstring.empty()) return to_script(wxstring); + // if all else fails, use "Whatever Works" + return to_script(String(cstring, wxConvWhateverWorks)); } else if (jv.is_array()) { boost::json::array array = jv.get_array(); diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index 7c984243..79f72302 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -279,6 +279,8 @@ enum ControlID { ID_MOVE_DOWN, ID_SHOW, ID_HIDE, + // Card list drag'n'drop timer + ID_DROP_TIMER, // Card select ID_SELECT_CARDS, ID_SELECTION_CHOICE,