// This code is part of «VDF GUIdance»
// Visit us @ http://www.vdf-guidance.com
// e-Mail us @ info@vdf-guidance.com
// VDF GUIdance is a mutual project of
// Frank Vandervelpen - Vandervelpen Systems and
// Wil van Antwerpen  - Antwise Solutions
// All software source code should be used «AS IS» without any warranty.

// Author: Wil van Antwerpen
//
// (c) 1999-2018, Antwise Solutions
// ** 11-11-2002 WvA Updated code to work with the latest version of the
//                   vWin32fh package.
// ** 06-06-2018 WvA Updated code to have no warnings on DF19.1
Use  Windows.pkg
Use  dfPanel.pkg

Use vWin32fh.pkg

// This is a small demoprogram on how to use the API functions.
// It doesn't show all the functionality of the vWin32fh package, but you will
// get the basic idea.

Register_Object oShowIt

Object Main is a Panel
    Set Label to "Windows File-handling Demo"
    Set Size to 165 200
    Property String psSelectedFile    ""
    Property String psSelectedFolder  ""
    Property String psOperation       ""

    Object oHuppeldepup is a modalpanel
        Set Size to 95 250
        Object oSelectFile is a form
            Set Location to 10 70
            Set Size to 13 170
            Set Label to "Select file"
            Set Prompt_Button_Mode to PB_PromptOn
            Set form_Button_Bitmap Item 0  to "ABNew.bmp"

            Procedure Prompt
                String sValue
                Send DoSelectFile
                Get psSelectedFile to sValue
                Set Value Item 0 to sValue
            End_Procedure
        End_Object

        Object oSelectFolder is a form
            Set Location to 30 70
            Set Size to 13 170
            Set Label to "Select folder"
            Set Prompt_Button_Mode to PB_PromptOn
            Set form_Button_Bitmap Item 0  to "OpenFold.bmp"

            Procedure Prompt
                String sValue
                Send DoSelectFolder
                Get psSelectedFolder to sValue
                Set Value Item 0 to sValue
            End_Procedure
        End_Object

        Object oDone_bn is a Button
            Set Location to 50 190
            Procedure Activating
                String sOperation
                Forward Send Activating
                Get psOperation to sOperation
                Set Label to sOperation
            End_Procedure

            Procedure OnClick
                Send DoFileOperation
                Send Close_Panel
            End_Procedure
        End_Object

        Object oCancel_bn is a Button
            Set Location to 50 135
            Set Label to "Cancel"

            Procedure OnClick
                Send Close_Panel
            End_Procedure
        End_Object

        Procedure DoFileOperation
            String  sSource
            String  sDestination
            String  sOperation
            Integer iRetVal
            Get psOperation to sOperation
            Get psSelectedFile to sSource
            Get psSelectedFolder to sDestination
            If (sOperation = "Copy") Begin
                Move (vCopyFile(sSource,sDestination)) to iRetVal
                If (iRetVal = 0) ;
                Send DoEditWriteln to oShowIt "File copied succesfully"
            End
            Else If (sOperation = "Move") Begin
                Move (vMoveFile(sSource,sDestination)) to iRetVal
                If (iRetVal = 0) ;
                Send DoEditWriteln to oShowIt "File moved succesfully"
            End
            Else If (sOperation = "Delete") Begin
                Move (vDeleteFile(sSource)) to iRetVal
                If (iRetVal = 0) ;
                Send DoEditWriteln to oShowIt "File deleted succesfully"
            End
        End_Procedure

        Procedure DoSelectFile
            String sSelectedFile
            String sMsg
            Move (vSelect_File("Text files|*.txt|Batch files|*.bat|System files|*.sys|All files|*.*","Select a file","C:\")) to sSelectedFile
            If (sSelectedFile <> "") ;
              Move ("The file"*sSelectedFile*"is Selected.") to sMsg
            Else ;
              Move "No file is selected." to sMsg
            Set psSelectedFile to sSelectedFile
            Send DoEditWriteln to oShowIt sMsg
        End_Procedure

        Procedure DoSelectFolder
            String sSelectedFolder
            String sMsg
            Move (vSHBrowseForFolder("Select a folder")) to sSelectedFolder
            If (sSelectedFolder <> "") ;
              Move ("The folder"*sSelectedFolder*"is Selected.") to sMsg
            Else ;
              Move "No file is selected." to sMsg
            Set psSelectedFolder to sSelectedFolder
            Send DoEditWriteln to oShowIt sMsg
        End_Procedure

        Procedure Popup
            String sOperation
            Get psOperation to sOperation
            If (sOperation="Delete") Begin
              Set Visible_State of oSelectFolder to False
              Set Enabled_State of oSelectFolder to False  
            End
            Else Begin
              Set Visible_State of oSelectFolder to True
              Set Enabled_State of oSelectFolder to True
            End
            Append sOperation " - file demonstration with Windows 32 API functions"
            Set Label to sOperation
            Forward Send Popup
        End_Procedure
    End_Object

    Object oCopy_bn is a Button
        Set Location to 10 10
        Set Label to "Copy File"
        Procedure OnClick
            Set psOperation to "Copy"
            Send Popup to oHuppeldepup
        End_Procedure
    End_Object

    Object oMove_bn is a Button
        Set Location to 10 65
        Set Label to "Move File"
        Procedure OnClick
            Set psOperation to "Move"
            Send Popup to oHuppeldepup
        End_Procedure
    End_Object

    Object oRename_bn is a Button
        Set Location to 25 10
        Set Label to "Rename File"
        Procedure OnClick
            String sMsg
            Move "not implemented in demo, API functions are there" to sMsg
            Send DoEditWriteln to oShowIt sMsg
        End_Procedure
    End_Object

    Object oDelete_bn is a Button
        Set Location to 25 65
        Set Label to "Delete File"
        Procedure OnClick
            Set psOperation to "Delete"
            Send Popup to oHuppeldepup
        End_Procedure
    End_Object

    Object oDDE_bn is a Button
        Set Location to 25 120
        Set Label to "Dance"
        Procedure OnClick
            String sMsg
            Move "https://www.vdf-guidance.com" to sMsg
            Send vShellExecute "OPEN" sMsg "" ""
            Send DoEditWriteln to oShowIt sMsg
        End_Procedure
    End_Object

    Object oShowit is a Edit
        Set Location to 45 10
        Set Size to 70 175
        Set Enabled_State to False

        Procedure doEditWriteln String sText
            Send append_text (sText + (Character(13)) + (Character(10)) )
        End_Procedure
    End_Object

End_Object

Send Popup to (Main(Self))
Start_UI