]> gitweb.factorcode.org Git - factor.git/commitdiff
ui.windows.drop-target: new vocab
authorAlexander Ilin <alex.ilin@protonmail.com>
Mon, 14 Aug 2023 20:49:36 +0000 (22:49 +0200)
committerAlexander Ilin <alex.ilin@protonmail.com>
Mon, 14 Aug 2023 20:55:09 +0000 (22:55 +0200)
extra/ui/windows/drop-target/authors.txt [new file with mode: 0644]
extra/ui/windows/drop-target/drop-target.factor [new file with mode: 0644]
extra/ui/windows/drop-target/platforms.txt [new file with mode: 0644]
extra/ui/windows/drop-target/summary.txt [new file with mode: 0644]

diff --git a/extra/ui/windows/drop-target/authors.txt b/extra/ui/windows/drop-target/authors.txt
new file mode 100644 (file)
index 0000000..8e1955f
--- /dev/null
@@ -0,0 +1 @@
+Alexander Ilin
diff --git a/extra/ui/windows/drop-target/drop-target.factor b/extra/ui/windows/drop-target/drop-target.factor
new file mode 100644 (file)
index 0000000..264b567
--- /dev/null
@@ -0,0 +1,30 @@
+! Copyright (C) 2019 Alexander Ilin.
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors kernel math namespaces
+ui.gadgets ui.gadgets.worlds ui.gestures
+windows.dropfiles windows.user32 ;
+IN: ui.windows.drop-target
+
+TUPLE: drop-target < world
+    on-file-drop ; ! ( seq -- )
+
+TUPLE: world-attributes < ui.gadgets.worlds:world-attributes
+    { on-file-drop initial: [ drop ] } ;
+
+: make-topmost ( world topmost? -- )
+    [ handle>> hWnd>> ] [ HWND_TOPMOST HWND_NOTOPMOST ? ] bi* 0 0 0 0
+    SWP_NOSIZE SWP_NOMOVE bitor SWP_NOACTIVATE bitor SetWindowPos drop ;
+
+M: drop-target graft*
+    [ call-next-method ] [ world-accept-files ] [ t make-topmost ] tri ;
+
+: handle-drop ( drop-target -- )
+    on-file-drop>> [ dropped-files get-global swap call( files -- ) ] when* ;
+
+drop-target H{
+    { T{ file-drop } [ handle-drop ] }
+} set-gestures
+
+: <drop-target> ( world-attributes -- world )
+    clone drop-target >>world-class [ <world> ] keep on-file-drop>>
+    >>on-file-drop ;
diff --git a/extra/ui/windows/drop-target/platforms.txt b/extra/ui/windows/drop-target/platforms.txt
new file mode 100644 (file)
index 0000000..8e1a559
--- /dev/null
@@ -0,0 +1 @@
+windows
diff --git a/extra/ui/windows/drop-target/summary.txt b/extra/ui/windows/drop-target/summary.txt
new file mode 100644 (file)
index 0000000..d8bea6d
--- /dev/null
@@ -0,0 +1 @@
+A window that accepts files drag-and-dropped from the operating system