// The code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// This is free software; you can redistribute it and/or modify it under the terms of the
// GNU Lesser General Public License.
// License: LGPLv3 - GNU LESSER GENERAL PUBLIC LICENSE Version 3 - http://www.gnu.org/licenses/lgpl.txt
//
#IF (!@ > 190)
    CompilerLevelWarning All On
#ENDIF
Use DfAllEnt.pkg
Use cCJStandardCommandBarSystem.pkg
Use cHtmlHelp.pkg
Use DFClient.pkg
Use Dfline.pkg
Use CodeSpy.pkg
Use CodeSpyStatus.vw
Use cCJSkinFramework.pkg
Use cSkinComboBoxCJMenuItem.pkg

Use vWin32fh.pkg
Use cDigitalSoftwareCertificate.pkg

Object oDigitalSoftwareCertificate is a cDigitalSoftwareCertificate
    Move Self to ghoDigitalSoftwareCertificate

    // Set pbWarnIfNotDigitallySigned = True if you like to have a warning when the
    // program is started, but the program has not been digitally signed.
    // Only applies when run outside the Studio.
    Set pbWarnIfNotDigitallySigned to False

    // This message does the actual checking for a valid digital certificate.
    // If the program has been tampered with e.g. it has been infected by a virus,
    // the user will get a warning and the program will be aborted.
    Send ValidateProgramOnStartup

End_Object

Object oHtmlHelp is a cHtmlHelp
    Procedure DoDisplayTOC
        String sPath
        Get psHelpPath of (phoWorkspace(ghoApplication)) to sPath
        Get vFolderFormat sPath to sPath
        Runprogram Shell Background (sPath + "CodeSpyInfo.htm")
    End_Procedure
End_Object

Object oApplication is a cApplication
    Set peHelpType to htHtmlHelp
    Set pbPreserveEnvironment to True
    Set psProduct to "CodeSpy - DataFlex Class Documenter"
    Set psCompany to "RDC Tools International"
    Set psVersion to (String(piVersionMajor(phoVersionInfo(Self))) + "." + String(piVersionMinor(phoVersionInfo(Self))))

    // Property is used if we should "auto-find" a record in the dbMergerView.vw
    // It should be done if the program was started from the VDF Studio's Tools menu
    Property String psApplicationManifestName

    // Accept passing a string with the name of an executable including full pathing on the command line.
    // This is used from the Studio "Tools" menu to automatically start this
    // program and to display the application record that is currently active
    // in the Studio.
    // Use this program's setup dialog to create an entry in the
    // Studio's Tools menu (for any Studio version).
    Procedure OnCreate
        Handle hoCmdLine
        String sArgument
        Integer iRetval

        Get phoCommandLine to hoCmdLine
        Get Argument of hoCmdLine 1 to sArgument
        If (sArgument <> "") Begin
            Get vFilePathExists sArgument to iRetval
            If (iRetval = True) Begin
                Set psApplicationManifestName to sArgument
            End
        End
    End_Procedure

End_Object

Object oSkin is a cCJSkinFramework
    Set psSkinFile to "iTunesA.cjstyles"
    Set psSkinIni to "Normalitunes.ini"
    Set pbLoadPreference to True
End_Object

Object oToolTipController is a cToolTipController
    Move Self to ghoToolTipController
    Set piMaxWidth to 400
    Set piDurationPopup to 14000    // 14 seconds, needed for long tooltips.
    Set pbUsePrefix to True
End_Object

Use oEditContextMenu.pkg
#IF (Required_FMAC_Version >= 17)
    Use oDEOEditContextMenu17.pkg
#ELSE
    Use oDEOEditContextMenu.pkg
#ENDIF

#IFNDEF ghoCodeDtl_DD
    Global_Variable Integer ghoCodeDtl_DD
#ENDIF

Declare_Datafile CodeDtl

Object oMain is a Panel
    Set Location to 84 56
    Set Size to 277 500
    Set Label to (psProduct(ghoApplication))
    Set piMinSize to (Hi(Size(Self))) (Low(Size(Self)) +1)

    Object oCommandBarSystem is a cCJCommandBarSystem
        Set pbTimerUpdate to True
        Set pbLargeIcons to True

        Procedure OnCreateCommandBars
            Handle hoOptions
            Get OptionsObject to hoOptions
            Forward Send OnCreateCommandBars
        End_Procedure

        Object oFindToolBar is a cCJToolbar
            Set psTitle to "Finding Toolbar"

            Object oFindFirstTool is a cCJFindFirstMenuItem
                Set psToolTip to "Find First (Ctrl+Home)"
            End_Object

            Object oFindPreviousTool is a cCJFindPreviousMenuItem
                Set psToolTip to "Find Previous (F9)"
            End_Object

            Object oFindMenuTool is a cCJFindMenuItem
                Set psToolTip to "Find Equal (F9)"
            End_Object

            Object oFindNextTool is a cCJFindNextMenuItem
                Set psToolTip to "Find Next (F8)"
            End_Object

            Object oFindLastTool is a cCJFindLastMenuItem
                Set psToolTip to "Find Last (Ctrl+End)"
            End_Object

        End_Object

        Object oFileToolBar is a cCJToolbar
            Set psTitle to "Data Entry Toolbar"

            Object oSaveToolItem is a cCJSaveMenuItem
                Set psCaption to "Save"
                Set psToolTip to "Save (Ctrl+S or F2)"
                Set psDescription to "Save changes"
            End_Object

            Object oDeleteToolItem is a cCJDeleteMenuItem
                Set psCaption to "Delete"
                Set psToolTip to "Delete (Shift+F2)"
            End_Object

            Object oClearToolItem is a cCJClearMenuItem
                Set psCaption to "Clear"
                Set psToolTip to "Clear (F5)"
                Set psDescription to "Clear data"
            End_Object

            Object oOpenGridItem_ToolItem is a cCJMenuItem
                Set psCaption to "Open Grid Source File in Editor"
                Set psToolTip to "Click to open grid Source File in editor, or right-click a grid line for menu opions. (Ctrl+E)"
                Set psDescription to "Opens the source file under the grid cursor in the editor"
                Set psImage to "NotepadOpen032N32.ico"
                Set psShortcut to "Double-Click"
                Set pbActiveUpdate to True

                Procedure OnExecute Variant vCommandBarControl
                    Forward Send OnExecute vCommandBarControl
                    Send OpenCurrentGridItem of (Client_Id(ghoCommandBars))
                End_Procedure

                Function IsEnabled Returns Boolean
                    Function_Return (CodeDtl.ID <> 0)
                End_Function

            End_Object

        End_Object

Define CS_SkinOffice2010Blue   for "Office2010 Blue"
Define CS_SkinOffice2010Silver for "Office2010 Silver"
Define CS_SkinOffice2010Black  for "Office2010 Black"
Define CS_SkiniTunesSilver     for "iTunes - Brushed Aluminium"

Enum_List
    Define CI_SkinOffice2010Blue for 1
    Define CI_SkinOffice2010Silver
    Define CI_SkinOffice2010Black
    Define CI_SkiniTunesSilver
End_Enum_List

        Object oConfigure_Toolbar is a cCJToolbar
            Set psTitle to "Configure ToolBar"

            Object oSetup_MenuItem is a cCJMenuItem
                Set psCaption to "Con&figure"
                Set psToolTip to "Configure the program"
                Set psImage to "Configure032N32.ico"
                Procedure OnExecute Variant vCommandBarControl
                    Forward Send OnExecute vCommandBarControl
                    Send Popup of (oSetup_dg(Client_Id(ghoCommandBars)))
                End_Procedure
            End_Object

            Object oSkinsDummyMenuItem is a cCJMenuItem
                Set psImage to "Skins048N32v2.ico"
                Set psCaption to "Skin selection"
                Set peControlStyle to xtpButtonIconAndCaption
                Set peControlType to xtpControlLabel
                Set psToolTip to "Select the skin to use from the dropdown list"
                Set pbControlBeginGroup to True
            End_Object

            Object oSkinsMenuItem is a cSkinComboBoxCJMenuItem
            End_Object

        End_Object

        Object oHelp_Toolbar is a cCJToolbar
            Set psTitle to "Help ToolBar"

            Object oProgrammersFunctionLibraryMenuItem is a cCJMenuItem
                Set psImage to "ClassHelp032N32.ico"
                Set psToolTip to "CodeSpy class help"
                Procedure OnExecute Variant vCommandBarControl
                    String sPath
                    Get psHelpPath of (phoWorkspace(ghoApplication)) to sPath
                    Get vFolderFormat sPath to sPath
                    Send vShellExecute "open" (sPath + "ClassReference.htm") "" ""
                End_Procedure
            End_Object

            Object oAbout_MenuItem is a cCJAboutMenuItem
                Set pbControlBeginGroup to True
            End_Object

            Object oHelp_MenuItem is a cCJMenuItem
                Set psCaption to "&Help"
                Set psToolTip to "Help on how to use the program"
                Set psShortcut to "Alt+H or F1"
                Set psImage to "ActionHelp.ico"

                Procedure OnExecute Variant vCommandBarControl
                    String sPath
                    Get psHelpPath of (phoWorkspace(ghoApplication)) to sPath
                    Send StartFile (sPath + "\CodeSpyInfo.htm")
                End_Procedure

            End_Object

            Object oExitMenuItem is a cCJExitMenuItem
                Set psImage to "Exit032N32.ico"
                Set psToolTip to "Exit the program (Alt+F4)"
                Set pbControlBeginGroup to True
            End_Object

        End_Object

        Object oStatusBar is a cCJStatusBar

            Object oStatusPane1 is a cCJStatusBarPane
                Set piID to sbpIDIdlePane
                Set pbStyleStretch to True
            End_Object

            Object oStatusPane2 is a cCJStatusBarPane
                Set phoViewPane to Self
                Set pbStyleStretch to True
            End_Object

        End_Object

    End_Object

    Object oClientArea is a ClientArea
        Use CodeSpy2.Vw
        Use Setup2.dg
        Use StdAbout.pkg

        Procedure Activate_About
            Send DoAbout "" "" "" "Interface remake by Nils G. Svedmyr, Original work by Michael Kurz" "About.bmp" "http://www.rdctools.com"
        End_Procedure

        #IFNDEF get_HtmlShellExecute
            External_Function HtmlShellExecute "ShellExecuteA" SHELL32.DLL ;
                Handle hwnd# String lpszOp# String lpszFile# String lpszParams# ;
                String lpszDir# Integer FsShowCmd# Returns Integer
        #ENDIF

        Procedure StartFile Global String doc#
            Integer grb#
            Handle scrhDC#
            String dir#
            Move (GetDesktopWindow()) to scrhDC# // Defined in WinUser.pkg
            Move (HtmlShellExecute(scrhDC#, "Open", doc#, "", dir#, 1)) to grb#
            Procedure_Return grb#
        End_Procedure

        Procedure OpenCurrentGriditem
            String sEditorParams sEditor sFilename

            Get IniFileValue of ghoProjectIniFile (psSectionName(ghoProjectIniFile)) CS_Editor CS_Notepad to sEditor
            Get IniFileValue of ghoProjectIniFile (psSectionName(ghoProjectIniFile)) CS_EditorParams ""   to sEditorParams
            Get Field_Current_Value of ghoCodeDtl_DD Field CodeDtl.FullSourceFileName  to sFileName

            If (sEditorParams <> "") Begin
                Runprogram Background sEditor ('"' + sEditorParams + '"' * '"' + sFileName + '"')
            End
            Else Begin
                Runprogram Background sEditor ('"' + sFileName + '"')
            End
        End_Procedure

        On_Key Key_Ctrl+Key_E Send OpenCurrentGriditem
    End_Object

End_Object

Start_UI
