summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpetasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e>2014-09-21 16:54:49 (GMT)
committerpetasisg@gmail.com <petasisg@gmail.com@f3661a36-4baa-549a-d6c7-40e0ffef350e>2014-09-21 16:54:49 (GMT)
commit6689ede984a803f7a01b4d61ea385d997b3e76bb (patch)
treee256f2a1fa57263f4f860d505c1781c885c2c0ec
parenta4478b5df7516a90af3df53910bbebef6d2d4fcf (diff)
downloadtkdnd-6689ede984a803f7a01b4d61ea385d997b3e76bb.zip
tkdnd-6689ede984a803f7a01b4d61ea385d997b3e76bb.tar.gz
tkdnd-6689ede984a803f7a01b4d61ea385d997b3e76bb.tar.bz2
Generic drop implementation for OS X
-rw-r--r--Changelog1
-rw-r--r--demos/complex_source.tcl8
-rw-r--r--library/tkdnd_macosx.tcl168
-rw-r--r--library/tkdnd_windows.tcl6
-rw-r--r--macosx/macdnd.m16
-rw-r--r--win/OleDND.h2
6 files changed, 72 insertions, 129 deletions
diff --git a/Changelog b/Changelog
index bbef044..a1aafb6 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,5 @@
2014-09-21 Petasis George <petasis@iit.demokritos.gr>
+ * library/tkdnd_macosx.tcl:
* library/tkdnd_unix.tcl: Changed implementation to re-use the
generic implementation.
diff --git a/demos/complex_source.tcl b/demos/complex_source.tcl
index 717231b..9de48c0 100644
--- a/demos/complex_source.tcl
+++ b/demos/complex_source.tcl
@@ -5,13 +5,17 @@ set filename [file normalize [info script]]
##
## Drag source
##
-pack [ttk::button .drag_source -text " Drag Source "] \
+pack [ttk::button .drag_source -text " Drag Source (Ttk widget)"] \
+ -fill x -padx 20 -pady 20
+pack [button .drag_source_tk -text " Drag Source (Tk widget)"] \
-fill x -padx 20 -pady 20
tkdnd::drag_source register .drag_source
+tkdnd::drag_source register .drag_source_tk
## Event <<DragInitCmd>>
-bind .drag_source <<DragInitCmd>> my_data
+bind .drag_source <<DragInitCmd>> my_data
+bind .drag_source_tk <<DragInitCmd>> my_data
proc my_data {} {
list copy [list \
diff --git a/library/tkdnd_macosx.tcl b/library/tkdnd_macosx.tcl
index a571c33..a233771 100644
--- a/library/tkdnd_macosx.tcl
+++ b/library/tkdnd_macosx.tcl
@@ -52,153 +52,91 @@ if {[tk windowingsystem] eq "aqua" && "AppKit" ni [winfo server .]} {
}
namespace eval macdnd {
- variable _dropped_data
proc initialise { } {
- variable _tkdnd2platform
- variable _platform2tkdnd
-
- ## Initialize the tkdnd 2 platform & platform 2 tkdnd arrays for
- ## type conversion...
- array set _platform2tkdnd [list \
+ ## Mapping from platform types to TkDND types...
+ ::tkdnd::generic::initialise_platform_to_tkdnd_types [list \
NSPasteboardTypeString DND_Text \
NSFilenamesPboardType DND_Files \
]
- foreach type [array names _platform2tkdnd] {
- lappend _tkdnd2platform($_platform2tkdnd($type)) $type
- }
};# initialise
};# namespace macdnd
# ----------------------------------------------------------------------------
-# Command macdnd::_HandleEnter
-# ----------------------------------------------------------------------------
-proc macdnd::_HandleEnter { path drag_source typelist } {
- ::tkdnd::xdnd::_HandleXdndEnter $path $drag_source $typelist
-};# macdnd::_HandleEnter
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_HandlePosition
-# ----------------------------------------------------------------------------
-proc macdnd::_HandlePosition { drop_target rootX rootY } {
- ::tkdnd::xdnd::_HandleXdndPosition $drop_target $rootX $rootY
-};# macdnd::_HandlePosition
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_HandleLeave
-# ----------------------------------------------------------------------------
-proc macdnd::_HandleLeave { args } {
- ::tkdnd::xdnd::_HandleXdndLeave
-};# macdnd::_HandleLeave
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_HandleDrop
-# ----------------------------------------------------------------------------
-proc macdnd::_HandleDrop { drop_target data args } {
- variable _dropped_data
- set _dropped_data $data
- ::tkdnd::xdnd::_HandleXdndDrop 0
-};# macdnd::_HandleDrop
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_GetDroppedData
-# ----------------------------------------------------------------------------
-proc macdnd::_GetDroppedData { time } {
- variable _dropped_data
- return $_dropped_data
-};# macdnd::_GetDroppedData
-proc xdnd::_GetDroppedData { time } {
- ::tkdnd::macdnd::_GetDroppedData $time
-};# xdnd::_GetDroppedData
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_GetDragSource
-# ----------------------------------------------------------------------------
-proc macdnd::_GetDragSource { } {
- ::tkdnd::xdnd::_GetDragSource
-};# macdnd::_GetDragSource
-
-# ----------------------------------------------------------------------------
-# Command macdnd::_GetDropTarget
+# Command macdnd::HandleEnter
# ----------------------------------------------------------------------------
-proc macdnd::_GetDropTarget { } {
- ::tkdnd::xdnd::_GetDropTarget
-};# macdnd::_GetDropTarget
+proc macdnd::HandleEnter { path drag_source typelist } {
+ variable _pressedkeys
+ variable _actionlist
+ set _pressedkeys 1
+ set _actionlist { copy move link ask private }
+ ::tkdnd::generic::HandleEnter $path $drag_source $typelist $typelist \
+ $_actionlist $_pressedkeys
+};# macdnd::HandleEnter
# ----------------------------------------------------------------------------
-# Command macdnd::_GetDragSourceCommonTypes
+# Command macdnd::HandlePosition
# ----------------------------------------------------------------------------
-proc macdnd::_GetDragSourceCommonTypes { } {
- ::tkdnd::xdnd::_GetDragSourceCommonTypes
-};# macdnd::_GetDragSourceCommonTypes
+proc macdnd::HandlePosition { drop_target rootX rootY {drag_source {}} } {
+ variable _pressedkeys
+ variable _last_mouse_root_x; set _last_mouse_root_x $rootX
+ variable _last_mouse_root_y; set _last_mouse_root_y $rootY
+ ::tkdnd::generic::HandlePosition $drop_target $drag_source \
+ $_pressedkeys $rootX $rootY
+};# macdnd::HandlePosition
# ----------------------------------------------------------------------------
-# Command macdnd::_GetDropTargetCommonTypes
+# Command macdnd::HandleLeave
# ----------------------------------------------------------------------------
-proc macdnd::_GetDropTargetCommonTypes { } {
- ::tkdnd::xdnd::_GetDropTargetCommonTypes
-};# macdnd::_GetDropTargetCommonTypes
+proc macdnd::HandleLeave { args } {
+ ::tkdnd::generic::HandleLeave
+};# macdnd::HandleLeave
# ----------------------------------------------------------------------------
-# Command macdnd::_supported_types
+# Command macdnd::HandleDrop
# ----------------------------------------------------------------------------
-proc macdnd::_supported_types { types } {
- ::tkdnd::xdnd::_supported_types $types
-}; # macdnd::_supported_types
+proc macdnd::HandleDrop { drop_target data args } {
+ variable _pressedkeys
+ variable _last_mouse_root_x
+ variable _last_mouse_root_y
+ ## Get the dropped data...
+ ::tkdnd::generic::SetDroppedData $data
+ ::tkdnd::generic::HandleDrop {} {} $_pressedkeys \
+ $_last_mouse_root_x $_last_mouse_root_y 0
+};# macdnd::HandleDrop
# ----------------------------------------------------------------------------
-# Command macdnd::_platform_specific_types
+# Command macdnd::GetDragSourceCommonTypes
# ----------------------------------------------------------------------------
-proc macdnd::_platform_specific_types { types } {
- ::tkdnd::xdnd::_platform_specific_types $types
-}; # macdnd::_platform_specific_types
+proc macdnd::GetDragSourceCommonTypes { } {
+ ::tkdnd::generic::GetDragSourceCommonTypes
+};# macdnd::GetDragSourceCommonTypes
# ----------------------------------------------------------------------------
-# Command macdnd::_normalise_data
+# Command macdnd::platform_specific_types
# ----------------------------------------------------------------------------
-proc macdnd::_normalise_data { type data } {
- ::tkdnd::xdnd::_normalise_data $type $data
-}; # macdnd::_normalise_data
+proc macdnd::platform_specific_types { types } {
+ ::tkdnd::generic::platform_specific_types $types
+}; # macdnd::platform_specific_types
# ----------------------------------------------------------------------------
-# Command macdnd::_platform_specific_type
+# Command macdnd::platform_specific_type
# ----------------------------------------------------------------------------
-proc macdnd::_platform_specific_type { type } {
- variable _tkdnd2platform
- if {[info exists _tkdnd2platform($type)]} {
- return $_tkdnd2platform($type)
- }
- list $type
-}; # macdnd::_platform_specific_type
-proc xdnd::_platform_specific_type { type } {
- ::tkdnd::macdnd::_platform_specific_type $type
-}; # xdnd::_platform_specific_type
+proc macdnd::platform_specific_type { type } {
+ ::tkdnd::generic::platform_specific_type $type
+}; # macdnd::platform_specific_type
# ----------------------------------------------------------------------------
-# Command macdnd::_platform_independent_type
+# Command tkdnd::platform_independent_types
# ----------------------------------------------------------------------------
-proc macdnd::_platform_independent_type { type } {
- variable _platform2tkdnd
- if {[info exists _platform2tkdnd($type)]} {
- return $_platform2tkdnd($type)
- }
- return $type
-}; # macdnd::_platform_independent_type
-proc xdnd::_platform_independent_type { type } {
- ::tkdnd::macdnd::_platform_independent_type $type
-}; # xdnd::_platform_independent_type
+proc ::tkdnd::platform_independent_types { types } {
+ ::tkdnd::generic::platform_independent_types $types
+}; # tkdnd::platform_independent_types
# ----------------------------------------------------------------------------
-# Command macdnd::_supported_type
+# Command macdnd::platform_independent_type
# ----------------------------------------------------------------------------
-proc macdnd::_supported_type { type } {
- variable _platform2tkdnd
- if {[info exists _platform2tkdnd($type)]} {
- return 1
- }
- return 0
-}; # macdnd::_supported_type
-proc xdnd::_supported_type { type } {
- ::tkdnd::macdnd::_supported_type $type
-}; # xdnd::_supported_type
+proc macdnd::platform_independent_type { type } {
+ ::tkdnd::generic::platform_independent_type $type
+}; # macdnd::platform_independent_type
diff --git a/library/tkdnd_windows.tcl b/library/tkdnd_windows.tcl
index 6475179..9f06f6c 100644
--- a/library/tkdnd_windows.tcl
+++ b/library/tkdnd_windows.tcl
@@ -108,11 +108,11 @@ proc olednd::HandleDrop { drop_target pressedkeys rootX rootY type data } {
};# olednd::HandleXdndDrop
# ----------------------------------------------------------------------------
-# Command olednd::_GetDropTypes
+# Command olednd::GetDragSourceCommonTypes
# ----------------------------------------------------------------------------
-proc olednd::GetDropTypes { drop_target } {
+proc olednd::GetDragSourceCommonTypes { drop_target } {
::tkdnd::generic::GetDragSourceCommonTypes
-};# olednd::GetDropTypes
+};# olednd::GetDragSourceCommonTypes
# ----------------------------------------------------------------------------
# Command olednd::platform_specific_types
diff --git a/macosx/macdnd.m b/macosx/macdnd.m
index ae0504c..a33b03c 100644
--- a/macosx/macdnd.m
+++ b/macosx/macdnd.m
@@ -311,7 +311,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
/*
* Standard Cocoa method for entering drop target;
- * Calls tkdnd::macdnd::_HandleEnter
+ * Calls ::tkdnd::macdnd::HandleEnter
*/
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender {
static char *DropActions[] = {
@@ -330,7 +330,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
Tcl_Obj* objv[4], *element, *result;
int i, index, status;
- objv[0] = Tcl_NewStringObj("tkdnd::macdnd::_HandleEnter", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::macdnd::HandleEnter", -1);
objv[1] = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
objv[2] = Tcl_NewLongObj(0);
objv[3] = Tcl_NewListObj(0, NULL);
@@ -412,7 +412,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
mouse_tkwin = Tk_CoordsToWindow(rootX, tk_Y, tkwin);
if (mouse_tkwin == NULL) return NSDragOperationNone;
- objv[0] = Tcl_NewStringObj("tkdnd::macdnd::_HandlePosition", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::macdnd::HandlePosition", -1);
objv[1] = Tcl_NewStringObj(Tk_PathName(mouse_tkwin), -1);
objv[2] = Tcl_NewIntObj(rootX);
objv[3] = Tcl_NewIntObj(tk_Y);
@@ -458,7 +458,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
/*
* Standard Cocoa method for handling drop operation
- * Calls tkdnd::macdnd::_HandleDrop
+ * Calls ::tkdnd::macdnd::HandleDrop
*/
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender {
static char *DropActions[] = {
@@ -478,7 +478,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
const NSString *type;
/* Retrieve the common types, as prefered by the drag source... */
- objv[0] = Tcl_NewStringObj("tkdnd::macdnd::_GetDragSourceCommonTypes", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::macdnd::GetDragSourceCommonTypes", -1);
/* Evaluate the command and get the result...*/
TkDND_Status_Eval(1);
// printf("Status=%d (%d)\n", status, TCL_OK);fflush(0);
@@ -537,7 +537,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
Tcl_DecrRefCount(result);
if (data == NULL) data = Tcl_NewStringObj(NULL, 0);
- objv[0] = Tcl_NewStringObj("tkdnd::macdnd::_HandleDrop", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::macdnd::HandleDrop", -1);
objv[1] = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
objv[2] = data;
@@ -572,7 +572,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
/*
* Standard Cocoa method for handling drop operation
- * Calls tkdnd::macdnd::_HandleXdndDrop
+ * Calls ::tkdnd::macdnd::HandleXdndDrop
*/
- (void)draggingExited:(id < NSDraggingInfo >)sender {
Tk_Window tkwin = TkMacOSXGetTkWindow([self window]);
@@ -581,7 +581,7 @@ const NSString *TKDND_Obj2NSString(Tcl_Interp *interp, Tcl_Obj *obj) {
Tcl_Obj* objv[4];
int i;
- objv[0] = Tcl_NewStringObj("tkdnd::macdnd::_HandleLeave", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::macdnd::HandleLeave", -1);
objv[1] = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
objv[2] = Tcl_NewLongObj(0);
objv[3] = Tcl_NewListObj(0, NULL);
diff --git a/win/OleDND.h b/win/OleDND.h
index 4c968c8..209bab9 100644
--- a/win/OleDND.h
+++ b/win/OleDND.h
@@ -823,7 +823,7 @@ class TkDND_DropTarget: public IDropTarget {
drop_active = false;
#endif
// Get the drop format list.
- objv[0] = Tcl_NewStringObj("::tkdnd::olednd::GetDropTypes", -1);
+ objv[0] = Tcl_NewStringObj("::tkdnd::olednd::GetDragSourceCommonTypes", -1);
objv[1] = Tcl_NewStringObj(Tk_PathName(tkwin), -1);
TkDND_Status_Eval(2); if (status != TCL_OK) return S_OK;
result = Tcl_GetObjResult(interp); Tcl_IncrRefCount(result);