Here is one example: How to drag a file from the windows filemanager (or something else) and drop it into a bitmap control. You can use any other control or the program window too. This example shows the power of using OOP.
This would create a common bitmap in HMG4 syntax (without assigning a picture)
Code: Select all
With Object BITMAP():New( "oMyImage" )
:Row := 10
:Col := 10
:Width := 200
:Height := 200
:Stretch := .F.
:ScaledToHeight := .F.
:ScaledToWidth := .F.
:Alignment := LBL_CENTER
:VAlignment := LBL_VCENTER
:Smoothing := 1
end
In OOP this is made by inheritance. This means you copy all properties and methods of a given class, add some new oder change some. You can do this often without knowing or understanding the code of the class.
In this example we want to create a new class called DROPBITMAP that is derived from the BITMAP class.
The creation of our bitmap need only a little change:
Code: Select all
With Object DROPBITMAP():New( "oMyImage" )
:Row := 10
:Col := 10
.....
end
Code: Select all
/*==============================================================================
DROPBITMAP class
==============================================================================*/
CLASS DROPBITMAP FROM BITMAP
// Methods
METHOD New SETGET
ENDCLASS
/*..............................................................................
New
..............................................................................*/
METHOD New( cName, oParent ) CLASS DROPBITMAP
Super:New( cName, oParent )
::oQTObject:setAcceptDrops(.T.)
::oQTObject:connect( QEvent_DragEnter ,{|oEvent|oEvent:acceptProposedAction()} )
::oQTObject:connect( QEvent_DragMove , {|oEvent|oEvent:acceptProposedAction()} )
::oQTObject:connect( QEvent_Drop , {|oEvent|DropEvent( oEvent )} )
::oQTObject:connect( QEvent_DragLeave ,{|oEvent|oEvent:accept()} )
RETURN Self
DropEvent() is no build in function, this is where we can react.
Here is a sample:
Code: Select all
FUNCTION DropEvent( oEvent )
LOCAL oMimeData, oUrlList, oURL, cFile, i
oMimeData := oEvent:mimeData()
IF oMimeData:hasUrls() // <-- a file reference is dropped with one or more files in it
oUrlList := oMimeData:urls()
FOR i := 0 TO oUrlList:size() - 1
oURL := oUrlList:at(i)
cFile := oURL:toLocalFile() // <-- here you get the file name(s)
.....
NEXT
ENDIF
oEvent:acceptProposedAction()
RETURN .F.
Ricci