- - Lubuntu 16.04 x86 with LXDE using PB 5.43 x86 with both GTK 2 and GTK 3 and in ASCII and Unicode mode
- Linux Mint 18 x86 "Sarah" with Cinnamon using PB 5.43 x86 with both GTK 2 and GTK 3 and in ASCII and Unicode mode
- Windows XP SP3 Professional with PB 5.43 x86 in ASCII and Unicode mode
- Windows 8.1 x64 with PB 5.43 x86 and x64 in both ASCII and Unicode mode
Code: Select all
EnableExplicit
Define ImagePath.S
OpenWindow(0, 100, 100, 800, 600,
"Drag the PureBasic logo onto the right ImageGadget")
WebGadget(0, 10, 10, 380, 580 ,"http://www.purebasic.com")
ImageGadget(1, 400, 10, 390, 290, 0, #PB_Image_Border)
EditorGadget(2, 400, 300, 390, 290)
EnableGadgetDrop(1, #PB_Drop_Image, #PB_Drag_Copy)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux ; -------------------------------------------------
ProcedureC DragDataCallback(*Widget.GtkWidget,
*DragContext.GdkDragContext, x.I, y.I, *Data.GtkSelectionData, Info.I,
Time.i, *UserData)
Shared ImagePath.S
If *Data
If ImagePath = ""
ImagePath = PeekS(gtk_selection_data_get_text_(*Data), -1, #PB_UTF8)
EndIf
EndIf
EndProcedure
g_signal_connect_(GadgetID(0), "drag-data-received", @DragDataCallback(), 0)
CompilerCase #PB_OS_MacOS ; -------------------------------------------------
Define SubclassedImageGadget.I
Procedure SubclassGadget(GadgetID.I, NewClassName.S)
Protected GadgetClass.I = CocoaMessage(0, GadgetID(GadgetID), "class")
Protected NewGadgetClass.I
NewGadgetClass = objc_allocateClassPair_(GadgetClass, NewClassName, 0)
objc_registerClassPair_(NewGadgetClass)
object_setClass_(GadgetID(GadgetID), NewGadgetClass)
ProcedureReturn NewGadgetClass
EndProcedure
ProcedureC PrepareForDragOperation(Object.I, Selector.I, Sender.I)
Shared ImagePath.S
Protected Pasteboard.I
Protected URL.I
Pasteboard = CocoaMessage(0, Sender, "draggingPasteboard")
URL = CocoaMessage(0, 0, "NSURL URLFromPasteboard:", Pasteboard)
If URL
ImagePath = PeekS(CocoaMessage(0,
CocoaMessage(0, URL, "absoluteString"),
"UTF8String"), -1, #PB_UTF8)
EndIf
ProcedureReturn #True
EndProcedure
SubclassedImageGadget = SubclassGadget(1, "SubclassedImageGadget")
class_addMethod_(SubclassedImageGadget,
sel_registerName_("prepareForDragOperation:"),
@PrepareForDragOperation(), "v@:@")
CompilerCase #PB_OS_Windows ; -----------------------------------------------
Prototype AccessibleObjectFromPoint(Point.Q, *IAccessable, *VarChild)
Define AccessibleObject.AccessibleObjectFromPoint
Define CursorPos.POINT
Define OLELib.I
OLELib = OpenLibrary(#PB_Any,"OLEAcc.DLL")
If OLELib
AccessibleObject = GetFunction(OLELib, "AccessibleObjectFromPoint")
Else
MessageRequester("Error", "Loading of library OLEAcc.DLL failed!",
#MB_ICONERROR)
End
EndIf
Procedure ObjectFromPoint(x, y)
Shared AccessibleObject.AccessibleObjectFromPoint
Shared ImagePath.S
Protected Name.I
Protected *IAcc.IAccessible
Protected Length.I
Protected Path.S
Protected VT.VARIANT
If AccessibleObject(y << 32 | x, @*IAcc, @VT) = #S_OK
If *IAcc\get_accValue(VT, @Name) = #S_OK
Length = SysStringLen_(Name)
Path = Space(Length)
WideCharToMultiByte_(#CP_ACP, 0, Name, -1, @Path, Length, 0, 0)
ImagePath = PeekS(@Path, Length, #PB_UTF8)
SysFreeString_(Name)
EndIf
*IAcc\Release()
EndIf
ProcedureReturn #True
EndProcedure
CompilerEndSelect ; ---------------------------------------------------------
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Case #WM_LBUTTONDOWN
GetCursorPos_(@CursorPos.POINT)
ObjectFromPoint(CursorPos\x, CursorPos\y)
CompilerEndIf
Case #PB_Event_GadgetDrop
Select EventGadget()
Case 1
If EventDropImage(0)
SetGadgetState(1, ImageID(0))
AddGadgetItem(2, -1, ImagePath)
ImagePath = ""
EndIf
EndSelect
EndSelect
ForEver
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CloseLibrary(OLELib)
CompilerEndIf