add 200ms delay before starting drag'n'drop

This commit is contained in:
GenevensiS
2026-01-07 04:34:08 +01:00
parent aeae27c7e3
commit 608de308fd
5 changed files with 34 additions and 17 deletions
+6 -3
View File
@@ -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);
+8 -1
View File
@@ -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);
}
@@ -627,6 +627,11 @@ void CardListBase::onChar(wxKeyEvent& ev) {
}
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<CardP> cards;
getSelection(cards);
String transaction_id = generate_uid();
@@ -635,6 +640,7 @@ void CardListBase::onBeginDrag(wxListEvent&) {
wxDropSource drag_source(this);
drag_source.SetData(*card_data);
drag_source.DoDragDrop(wxDrag_CopyOnly);
}
}
void CardListBase::onDrag(wxMouseEvent& ev) {
@@ -705,6 +711,7 @@ BEGIN_EVENT_TABLE(CardListBase, ItemList)
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_TIMER (ID_DROP_TIMER, CardListBase::OnDragTimer)
EVT_CHAR ( CardListBase::onChar)
EVT_MOTION ( CardListBase::onDrag)
EVT_MENU (ID_SELECT_COLUMNS, CardListBase::onSelectColumns)
+2
View File
@@ -72,6 +72,7 @@ public:
// --------------------------------------------------- : Clipboard and Drag'n'Drop
CardListDropTarget* drop_target;
wxTimer drop_timer;
bool canCut() const override;
bool canCopy() const override;
@@ -168,6 +169,7 @@ private:
void onSelectColumns (wxCommandEvent&);
void onChar (wxKeyEvent&);
void onBeginDrag (wxListEvent&);
void OnDragTimer (wxTimerEvent&);
void onDrag (wxMouseEvent&);
void onContextMenu (wxContextMenuEvent&);
};
+4 -1
View File
@@ -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();
+2
View File
@@ -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,