// DrgNDrop.pkg // // Author: Stuart W. Booth // Feb '97 // // Simple prototype of dragging & dropping in Visual DataFlex // // INTERFACE: // // All classes that import this mixin-class must respect the following messages: // // Changed by Michael Kurz 05.04.2001 // -Renamed all Communications Messages // -Flexibel Icon using. // -The Receivin Object should determine if it can receive the Data NOT the Source Object! // //-------------------------------------------------------------------------------------- // DRAG AND DROP INTERFACE FUNCTION // // DONATING OBJECT: // // Delivers a NameTag of the Data which is used in the receiving Object to know // if it can insert the Dragged data. Register_Function DragAndDrop_DataType Returns String // needed // // Is Called by the receiving Object to get the Data, can be a String // or a whole Object, whatever. Register_Function DragAndDrop_GetData Returns String // needed // Is Called after the receiving Object had successfully accepted // the Data. (For Deleting when data was moved) Register_Function DragAndDrop_Success Returns Integer // optional // Can be Implemented to use a special cursor For its data when // dragged. Register_Function DragAndDrop_IconFile String sDataType Returns String // optional // // RECEIVING OBJECT: // // Is called during the Drag process to check if an Object can accept // the Dragged Data Register_Function DragAndDrop_CanReceiveData String sDataType Returns Integer // needed // // Is called when the data is dropped, should return true if successful. // if so a DragAndDrop_Success is called in the Src Object. Register_Function DragAndDrop_DropData Integer hoSrcObj Returns Integer // needed // General DataTypes. Define DragAndDrop_NoData For "" Define DragAndDrop_Text For "DD_TEXT" Register_Object oDad #IFDEF GET_MKLoadImage #ELSE Define IMAGE_BITMAP For 0 Define IMAGE_ICON For 1 Define IMAGE_CURSOR For 2 Define LR_LOADFROMFILE For |CI$0010 Define LR_CREATEDIBSECTION For |CI$2000 External_functionEx LoadImage "LoadImageA" user32.dll Handle hInst Pointer pPic Integer iTyp Integer iX Integer iY Integer iFlag Returns Integer Function MKLoadImage Global String sBMPe Integer iX Integer iY Returns Handle String sBMP Pointer pBMP Integer iIconStyle Handle hwnd Move sBMPe To sBMP GetAddress Of sBMP To pBMP Move IMAGE_BITMAP To iIconStyle // Std. If (Uppercase(Right(sBMP,3))) Eq "ICO" Move IMAGE_ICON To iIconStyle // Icon If (Uppercase(Right(sBMP,3))) Eq "CUR" Move IMAGE_CURSOR To iIconStyle // Cursor Move (LoadImage(0,pBMP,iIconStyle,iX,iY,(LR_LOADFROMFILE + LR_CREATEDIBSECTION))) To hwnd Function_Return hwnd End_Function #ENDIF Class cDaD Is an BasicPanel Procedure Construct_Object Forward Send Construct_Object Property Integer pbDragging Public 0 // are we in a Drag operation? Property Integer phoSource Public 0 // which object started the drag operation Property String psDataType Public "" // Type of the Data which is Dragged. Property Integer phCursorYes Public 0 Property Integer phCursorNo Public (LoadCursor(0,IDC_NO)) // you may override in the instance Set Visible_State To False // we want it "visible" to Windows (to get a window-handle) - but not us End_Procedure // Function ObjectUnderCursor Returns Integer Handle hWnd Integer x y hoDrop String sPoint Pointer lpsPoint ZeroType tPoint To sPoint GetAddress Of sPoint To lpsPoint Move (GetCursorPos(lpsPoint)) To windowindex GetBuff From sPoint At tPoint.x To x GetBuff From sPoint At tPoint.y To y Move (WindowFromPoint(x,y)) To hWnd GET_OBJECT_FROM_WINDOW hWnd To hoDrop Function_Return hoDrop End_Function // Calls a function in an Object without causing an ivalid message if not defined. // Can handle from 0 to 2 Parameters. Function CallFunctionSilent Integer hoID Integer iGet String sPara1 String sPara2 Returns String Integer iDel String sRet If hoID Begin Get Delegation_Mode Of hoID To iDel Set Delegation_Mode Of hoID To No_Delegate_Or_Error If NUM_Arguments Eq 2 Get iGet Of hoID To sRet If NUM_Arguments Eq 3 Get iGet Of hoID sPara1 To sRet If NUM_Arguments Ge 4 Get iGet Of hoID sPara1 sPara2 To sRet Set Delegation_Mode Of hoID To iDel End Function_Return sRet End_Function Procedure DoStartDrag Integer hoSource String sDataType Integer iRet Send Set_Mouse_Capture Move (SendMessage(Window_Handle(Self),WM_LBUTTONDOWN,1,1)) To iRet // To reach the Mouse_Drag to be sent. Set pbDragging To True Set phoSource To hoSource Set psDataType To sDataType End_Procedure Procedure Mouse_Drag Integer iWin Integer iChar Integer hoUnderCursor bDragOK iRet String sIcon If (Not(pbDragging(current_object))) Procedure_Return Get ObjectUnderCursor To hoUnderCursor Get CallFunctionSilent hoUnderCursor Get_DragAndDrop_CanReceiveData (psDataType(Self)) To bDragOK If bDragOK If (phCursorYes(Self)) Eq 0 Begin Get CallFunctionSilent (phoSource(Self)) Get_DragAndDrop_IconFile (psDataType(Self)) To sIcon If sIcon Eq "" Move "DragDrop.Cur" To sIcon Get_File_Path sIcon To sIcon Set phCursorYes To (MKLoadImage(sIcon,32,32)) If (phCursorYes(Self)=0) Set phCursorYes To (LoadCursor(0,IDC_IBEAM)) End If bDragOK Move (SetCursor(phCursorYes(current_object))) To iRet Else Move (SetCursor(phCursorNo(current_object))) To iRet End_Procedure Procedure Mouse_Up Integer hoDrop iRet If (Not(pbDragging(current_object))) Procedure_Return // Free the Mouse again. Send Release_Mouse_Capture Set pbDragging To False // Delete the Cursor Handle. If (phCursorYes(Self)) Begin Move (DeleteObject(phCursorYes(Self))) To iRet Set phCursorYes To 0 End // Call Drop notifications and inform the src object if successful. Get ObjectUnderCursor To hoDrop Get CallFunctionSilent hoDrop Get_DragAndDrop_DropData (phoSource(Self)) To iRet If iRet Get CallFunctionSilent (phoSource(Self)) Get_DragAndDrop_Success To iRet End_Procedure End_Class // Object to act as drag&drop helper. Object oDaD Is a cDaD Send Page_Object True End_Object // Put IMPORT_CLASS_PROTOCOL cDragAndDrop_mx in a class definition // and supply the basic handlers needed by the interface (described above) // // NOTE: you will not be able to use Mouse_Drag in your classes that // import this class. This event is used privately to provide the public interface. Class cDragAndDrop_mx Is a Mixin Procedure Mouse_Drag Integer iWin Integer iChar String sDataType Forward Send Mouse_Drag iWin iChar Get DragAndDrop_DataType To sDataType If sDataType Ne DragAndDrop_NoData Begin Send Release_Mouse_Capture Send DoStartDrag To (oDaD(current_object)) current_object sDataType End End_Procedure End_Class //IGNORE THIS CODE BELOW. You may want to use it to augment your // standard List classes, as it reduces the flickering when dragging // the mouse over items (but not when being Dragged, obviously). //Class cList is a List // Procedure Construct_Object // Forward Send Construct_Object // Property Integer piLastItem Public 0 // End_Procedure // Procedure Mouse_Drag Integer iWin Integer iChar // If (iWin -1) eq (piLastItem(current_object)) Procedure_Return // Set piLastItem To (iWin -1) // Forward Send Mouse_Drag iWin iChar // End_Procedure //End_Class