From 37aa211cc8aa676ecea5ee4b7763de7802b3554c Mon Sep 17 00:00:00 2001
From: David Brown <dbrown@gitlab.riscosopen.org>
Date: Wed, 3 Sep 1997 15:48:19 +0000
Subject: [PATCH] Canceling of drags implemented

---
 c/Hotlist | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 h/Hotlist |  2 ++
 2 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/c/Hotlist b/c/Hotlist
index d4c4bca..28204b9 100644
--- a/c/Hotlist
+++ b/c/Hotlist
@@ -120,6 +120,7 @@ static ToolboxEventHandler   hotlist_reset_url_handler;
 static ToolboxEventHandler   hotlist_reset_directory_handler;
 static ToolboxEventHandler   hotlist_show_descriptions_handler;
 static ToolboxEventHandler   hotlist_show_urls_handler;
+static ToolboxEventHandler   hotlist_drag_stop_handler;
 
 static WimpMessageHandler    hotlist_data_save_ack_handler;
 static WimpMessageHandler    hotlist_ram_fetch_handler;
@@ -1079,7 +1080,7 @@ static int hotlist_clear_flags(hotlist_item * list, hotlist_type type, unsigned
 
     if (type == hl_ALL || type == list->type)
     {
-      if (list->flags & ~flags != list->flags)
+      if ((list->flags & ~flags) != list->flags)
       {
         list->flags |= HOTLIST_G_REDRAW_NOW;
         changed = 1;
@@ -3247,6 +3248,11 @@ _kernel_oserror * hotlist_initialise(void)
                                           hotlist_ram_fetch_handler,
                                           NULL));
 
+  RetError(event_register_toolbox_handler(-1,
+                                          HotlistEscape,
+                                          hotlist_drag_stop_handler,
+                                          NULL));
+
   return NULL;
 }
 
@@ -4052,6 +4058,53 @@ void hotlist_start_drag(void)
 //    return 0;
 //  }
 
+/*************************************************/
+/* hotlist_drag_stop_handler()                   */
+/*                                               */
+/* Terminates any hotlist drag in progress       */
+/*************************************************/
+
+static int hotlist_drag_stop_handler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
+{
+  if (hotlist_current_highlighted)
+  {
+    hotlist_current_highlighted->flags &= ~HOTLIST_D_IS_HIGHLIGHTED;
+    hotlist_redraw_items(highlighted_itemno, highlighted_itemno);
+    hotlist_current_highlighted = NULL;
+  }
+
+  switch(hotlist_dragging)
+  {
+    default:
+    return 0;
+    break;
+
+    case HOTLIST_SOLID_DRAG_OBJECT:
+    /* Stop drag an object */
+    _swix(DragAnObject_Stop, 0);
+    deregister_null_claimant(Wimp_ENull, hotlist_null_handler, NULL);
+    hotlist_dragging = 0;
+    break;
+
+    case HOTLIST_SOLID_DRAG_SPRITE:
+    /* Stop drag a sprite */
+    _swix(DragASprite_Stop, 0);
+    deregister_null_claimant(Wimp_ENull, hotlist_null_handler, NULL);
+    hotlist_dragging = 0;
+    break;
+
+    case HOTLIST_BOX_DRAG_SELECTION:
+    /* Stop drag box */
+    wimp_drag_box(NULL);
+    deregister_null_claimant(Wimp_ENull, hotlist_null_drag_select_handler, NULL);
+    hotlist_clear_flags(hotlist_root->data.directory_content, hl_ALL, HOTLIST_G_DRAG_SELECTED);
+    hotlist_redraw_now();
+    hotlist_dragging = 0;
+    break;
+  }
+  return 1;
+}
+
 /*************************************************/
 /* hotlist_drag_completed_handler()              */
 /*                                               */
diff --git a/h/Hotlist b/h/Hotlist
index 350f0f7..9785b0a 100644
--- a/h/Hotlist
+++ b/h/Hotlist
@@ -58,6 +58,8 @@
   #define HotlistShowDesc    0x3013
   #define HotlistShowURLs    0x3014
 
+  #define HotlistEscape      0x3015
+
   /* Enumerations */
 
   typedef enum hotlist_type
-- 
GitLab