Hi,
I wrote code which works in windows and linux, but not on macos.
It seems that only DragImage() is working in macos.
DragFile() and DragText() does nothing.
Unfortunately the receiver is JavaScript which can only handle the last two.
Any idea?
I also tried PB 5.46 since somewhere was written that this works for DragFile(), but it doesn't too.
Can I use some NS.... or Cocoa stuff to do this?
I use PB 6.00 on Monterey 12.6
Need help with Drag
Re: Need help with Drag
Unfortunately, the drag method has been changed internally from macOS to mark text or listing. Fred has not yet found a solution (and neither have I).
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Need help with Drag
this kind of works but its only one way and need more thought
Code: Select all
#Window = 0
Enumeration
#SourceText
#TargetText
EndEnumeration
Global DragItem.s
Global elt
Procedure CBDragStart()
DragItem.s = GetGadgetItemText(EventGadget(),GetGadgetState(EventGadget()))
elt = ElapsedMilliseconds() + 2000
EndProcedure
Procedure cbDragDrop()
If ElapsedMilliseconds() < elt
If Dragitem <> ""
AddGadgetItem(EventGadget(),-1,DragItem)
EndIf
EndIf
EndProcedure
If OpenWindow(#Window, 0, 0, 760, 310, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
;
ListIconGadget(#SourceText, 10, 10, 140, 140, "Drag Text here", 130)
AddGadgetItem(#SourceText, -1, "hello world")
AddGadgetItem(#SourceText, -1, "The quick brown fox jumped over the lazy dog")
AddGadgetItem(#SourceText, -1, "abcdefg")
AddGadgetItem(#SourceText, -1, "123456789")
; Create the target gadgets
ListIconGadget(#TargetText, 10, 160, 140, 140, "Drop Text here", 130)
;crude drag and drop
BindEvent(#PB_Event_Gadget,@CBDragStart(),#window,#SourceText,#PB_EventType_LeftClick)
BindEvent(#PB_Event_Gadget,@CBDragDrop(), #window,#TargetText,#PB_EventType_LeftClick)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
End
Re: Need help with Drag
Thanks for the response.
I need to drag from a PN program to a web-browser React code.
So the 'internal' solution does not work for me.
It looks that I have to add a file upload in the react stuff.
Or I have to do it via Clipboard.
The only thing I found is the NSPasetboard stuff, but I can not implement it.
I need to drag from a PN program to a web-browser React code.
So the 'internal' solution does not work for me.
It looks that I have to add a file upload in the react stuff.
Or I have to do it via Clipboard.
The only thing I found is the NSPasetboard stuff, but I can not implement it.
Re: Need help with Drag
Drag and drop works with an EditorGadget.
But not with the ListViewGadget.
For this, the existing methods must be replaced by your own methods. See Class PBListViewTableView
I don't yet know what else has to be done. But I am also interested
But not with the ListViewGadget.
For this, the existing methods must be replaced by your own methods. See Class PBListViewTableView
I don't yet know what else has to be done. But I am also interested
Code: Select all
;-TOP Dump Object Methods
; by mk-soft, 29.12.2019 - 06.11.2022, v1.08.2
Structure ArrayOfMethods
i.i[0]
EndStructure
ImportC ""
class_copyMethodList(*Class, *p_methodCount)
; -> An array of pointers of type Method describing
; the instance methods implemented by the class
; Any instance methods implemented by superclasses are Not included
; You must free the array with free()
class_getName(*Class) ; -> UnsafePointer<Int8> -> *string
sel_getName(*Selector); -> const char *
method_getName(*Method) ; -> Selector
method_getTypeEncoding(*Method) ; -> const char *
method_getReturnType(*Method, *dst, dst_len) ; -> void
method_getNumberOfArguments(*Method) ; -> unsigned int
method_getArgumentType(*Method, index, *dst, dst_len) ; -> void
NSGetSizeAndAlignment(*StringPtr, *p_size, *p_align)
; -> const char *
; Obtains the actual size and the aligned size of an encoded type.
EndImport
; ----
Procedure.s GetArgumentType(*String)
Protected r1.s, arg.s, size.i, ofs.i
arg = PeekS(*String, -1, #PB_UTF8)
r1 + arg + " - "
If Left(arg, 1) = "^"
r1 + "A pointer to type of "
arg = Mid(arg, 2)
EndIf
Select arg
Case "c" : r1 + "A char "
Case "i" : r1 + "An int "
Case "s" : r1 + "A short "
Case "l" : r1 + "A long "
Case "q" : r1 + "A long long"
Case "C" : r1 + "An unsigned char "
Case "I" : r1 + "An unsigned int "
Case "S" : r1 + "An unsigned short "
Case "L" : r1 + "An unsigned long "
Case "Q" : r1 + "An unsigned long long "
Case "f" : r1 + "A float "
Case "d" : r1 + "A double "
Case "B" : r1 + "A C++ bool Or a C99 _Bool "
Case "v" : r1 + "A void"
Case "*" : r1 + "A character string (char *) "
Case "@" : r1 + "An object (whether statically typed Or typed id) "
Case "#" : r1 + "A class object (Class) "
Case ":" : r1 + "A method selector (SEL) "
Default:
NSGetSizeAndAlignment(*String, @size, @ofs)
r1 + "[" + Str(size) + " bytes]"
EndSelect
If Right(arg, 1) = "?"
r1 + "An unknown type (e.g. function pointer)"
EndIf
ProcedureReturn r1
EndProcedure
; ----
Procedure.s DumpObjectMethods(*Object, SuperLevel = 0, HidePrivate = #True, ShowEncoding = #False, FirstArgument = 2)
Protected r1.s, i, c, n, methodCount, Method.s
Protected *Class, *SuperClass, *Method, *Methods.ArrayOfMethods
Protected *String
*Class = object_getclass_(*Object)
If *Class
*String = AllocateMemory(1024)
r1 = PeekS(class_getName(*Class), -1, #PB_UTF8)
If SuperLevel
For i = 1 To SuperLevel
*SuperClass = class_getsuperclass_(*Class)
If *SuperClass
*Class = *SuperClass
r1 + " -> " + PeekS(class_getName(*Class), -1, #PB_UTF8)
Else
Break
EndIf
Next
EndIf
*Methods = class_copyMethodList(*Class, @methodCount)
r1 + #LF$ + #LF$ + "Count of Methods: " + methodCount + #LF$ + #LF$
For i = 0 To methodCount - 1
*Method = *Methods\i[i];
Method = PeekS(sel_getName(method_getName(*Method)), -1, #PB_UTF8)
If HidePrivate And Left(Method, 1) = "_"
Continue
EndIf
r1 + "Method " + Method + #LF$
If ShowEncoding
r1 + " * Encoding " + PeekS(method_getTypeEncoding(*Method), -1, #PB_UTF8) + #LF$
EndIf
method_getReturnType(*Method, *String, 1024)
r1 + " -- ReturnType = " + GetArgumentType(*String) + #LF$
c = method_getNumberOfArguments(*Method)
For n = FirstArgument To c - 1
method_getArgumentType(*Method, n, *String, 1024)
r1 + " -- Argument " + Str(n - FirstArgument + 1) + " = " + GetArgumentType(*String) + #LF$
Next
r1 + #LF$
Next
r1 + "End Class" + #LF$ + #LF$
If *Methods
free_(*Methods)
EndIf
FreeMemory(*String)
Else
r1 = "Object is nil" + #LF$
EndIf
ProcedureReturn r1
EndProcedure
; ****
;-TOP
#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"
Enumeration Windows
#Main
EndEnumeration
Enumeration MenuBar
#MainMenu
EndEnumeration
Enumeration MenuItems
#MainMenuAbout
#MainMenuExit
EndEnumeration
Enumeration Gadgets
#MainEdit
#MainButtonOk
#MainButtonCancel
EndEnumeration
Enumeration StatusBar
#MainStatusBar
EndEnumeration
Procedure DragCallback(DragReference, isStart)
Debug "DragCallback " + isStart
EndProcedure
Procedure UpdateWindow()
Protected dx, dy
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
; Resize gadgets
ResizeGadget(#MainEdit, 5, 5, dx - 10, dy - 45)
ResizeGadget(#MainButtonok, 10, dy - 35, 120, 30)
ResizeGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30)
EndProcedure
Procedure Main()
Protected dx, dy
#MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
; Menu
CreateMenu(#MainMenu, WindowID(#Main))
MenuTitle("&File")
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
MenuItem(#PB_Menu_About, "")
CompilerElse
MenuItem(#MainMenuAbout, "About")
MenuBar()
CompilerEndIf
MenuItem(#MainMenuExit, "E&xit")
; StatusBar
CreateStatusBar(#MainStatusBar, WindowID(#Main))
AddStatusBarField(#PB_Ignore)
; Gadgets
dx = WindowWidth(#Main)
dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
;EditorGadget(#MainEdit, 5, 5, dx -10, dy - 45)
ListViewGadget(#MainEdit, 5, 5, dx -10, dy - 45)
ButtonGadget(#MainButtonok, 10, dy - 35, 120, 30, "Ok")
ButtonGadget(#MainButtonCancel, dx - 130, dy - 35, 120, 30, "Abbruch")
; Bind Events
BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
; Drop
EnableGadgetDrop(#MainEdit, #PB_Drop_Text, #PB_Drag_Copy | #PB_Drag_Move)
; Drag (Not Work)
SetDragCallback(@DragCallback())
Debug DumpObjectMethods(GadgetID(#MainEdit), 0)
; Event Loop
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Main
Break
EndSelect
Case #PB_Event_Menu
Select EventMenu()
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Case #PB_Menu_About
PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
Case #PB_Menu_Preferences
Case #PB_Menu_Quit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
CompilerEndIf
Case #MainMenuAbout
MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
Case #MainMenuExit
PostEvent(#PB_Event_CloseWindow, #Main, #Null)
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #MainEdit
Select EventType()
Case #PB_EventType_DragStart
;
EndSelect
Case #MainButtonOk
;
Case #MainButtonCancel
;
EndSelect
Case #PB_Event_GadgetDrop
AddGadgetItem(#MainEdit, -1, EventDropText())
EndSelect
ForEver
EndIf
EndProcedure : Main()
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive