Use DFAllEnt.pkg
Use cCJStandardCommandBarSystem.pkg
Use cCJSkinFramework.pkg

Object oHtmlHelp is a cHtmlHelp
End_Object

Global_Variable Handle ghoMainPanel 
Use AutoReindex.dg                                  // Must be USEd right after declaration of ghoMainPanel.

Object oApplication is a cApplication
    Set peHelpType to htHtmlHelp
    Set pbPreserveEnvironment to False
    // Check that the 'correct' collating.cfg is used when the program is
    // started. The data in the database was entered with an english (standard)
    // collating sequence. If another df_collate.cfg is encountered, automatically
    // reindex all data tables, prior starting the program.
    // Note: We cannot use the event OnCreate for this, because the psDataPath
    // et. al. is set after that event. Instead we augment the
    // predefined cApplication's DoOpenworkSpace message.
    Procedure DoOpenWorkspace String sWorkspace
        Forward Send DoOpenWorkspace sWorkspace     // cApplication class procedure.
        Send DoCheckCollatingSequence               // Needs to be send right after the forward send...
    End_Procedure // DoOpenWorkspace
    
    Use DoCheckCollatingSequence.pkg                // The package contains the DoCheckCollatingSequence procedure.
End_Object

Object oCJSkinFramework1 is a cCJSkinFramework
    Set psSkinFile to "Office2007.cjstyles"
    Set psSkinIni to "NormalBlue.ini"
End_Object

// We use this slightly augmented class instead of the standard
// VDF cNoChangeUpstartComboForm class. Why? Well, the standard class triggers the
// OnChange event upon program start because we set a default value
// of each combo and that slows down the loading, plus that it serves
// no purpose doing so.                     
Class cNoChangeUpstartComboForm is a ComboForm 
    Procedure Construct_Object
        Forward Send Construct_Object
        Set Entry_State      to False
        Set Combo_Sort_State to False
    End_Procedure
//    Procedure OnChange
//        If (not(Focus(Desktop) = Self)) Procedure_Return
//        Forward Send OnChange
//    End_Procedure    
End_Class // cNoChangeUpstartComboForm

Use oEditContextMenu.pkg
Use oDEOEditContextMenu.pkg

Register_Procedure Set phoReportControl Integer 0

Object oMain is a Panel

    Move Self to ghoMainPanel
    Property Handle phoViewMenu 0
    Property Handle phoReportMenu 0

    Set Label to "CodeJock's Report Component Test"
    Set Location to 4 3
    Set Size to 300 650
    Set Sysmenu_Icon to True
    Set View_Mode to ViewMode_Zoom

    Object oCommandBarSystem is a cCJCommandBarSystem
        Set pbTimerUpdate to True

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

        Object oMenuBar is a cCJMenuBar

            Object oFileMenu is a cCJMenuItem
                Set peControlType to xtpControlPopup          
                Set psCaption to "&File"
                Set psDescription to "Find, Save, Delete, Clear information or quit this application."
                Set psCategory to "Menus"

                Object oClearMenuItem is a cCJClearMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oClearAllMenu is a cCJClearAllMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oPromptMenuItem is a cCJPromptMenuItem
                    Set pbAddToDesignerMenu to True
                    Set pbControlBeginGroup to True
                End_Object

                Object oFindMenuItem is a cCJFindMenuItem
                    Set pbAddToDesignerMenu to True
                    Set pbControlBeginGroup to True
                End_Object

                Object oFindNextMenu is a cCJFindNextMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oFindPreviousMenu is a cCJFindPreviousMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oFindFirstMenu is a cCJFindFirstMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oFindLastMenu is a cCJFindLastMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oSaveMenuItem is a cCJSaveMenuItem
                    Set pbAddToDesignerMenu to True
                    Set pbControlBeginGroup to True
                End_Object

                Object oDeleteMenuItem is a cCJDeleteMenuItem
                    Set pbAddToDesignerMenu to True
                End_Object

                Object oExitMenu is a cCJExitMenuItem
                    Set pbControlBeginGroup to True
                End_Object

            End_Object

            Object oViewMenu is a cCJMenuItem
                Set peControlType to xtpControlPopup
                Set psCaption to "&View"
                Set psToolTip to "View"
                Set psDescription to "Available Views"

                Object oReportControlWithDataTestMenuItem is a cCJMenuItem
                    Set psCaption to "Report Control Grid With Data"
                    Set psTooltip to "Report Control With Data"
                
                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient
                        Get Client_Id to hoClient
                        Send Activate_oReportControlWithDataTest of hoClient
                    End_Procedure
                End_Object

                Object oReportControlGridTestwithButtonsMenuItem is a cCJMenuItem
                    Set psCaption to "ReportControlGrid Test with Buttons"
                    Set psTooltip to "ReportControlGrid Test with Buttons"
                
                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient
                        Get Client_Id to hoClient
                        Send Activate_oReportGridWithButtonsView of hoClient
                    End_Procedure
                End_Object

                Object oReportControlGridTestwithButtonsMenuItem is a cCJMenuItem
                    Set psCaption to "ReportControlGrid Test with Buttons"
                    Set psTooltip to "ReportControlGrid Test with Buttons"
                
                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient
                        Get Client_Id to hoClient
                        Send Activate_oReportGridWithButtonsView of hoClient
                    End_Procedure
                End_Object

            End_Object

            Object oReportMenu is a cCJMenuItem
                Set peControlType to xtpControlPopup          
                Set psCaption to "&Report"
                Set psToolTip to "Report"
                Set psDescription to "Available Reports" 

                Object ooPrintPreviewMenuItem is a cCJMenuItem
                    Set psCaption to "Preview Report Control data of the active view (Close other views)"
                    Set psTooltip to "Close other views than the view you want to preview"

                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient hView ho
                        Get Client_Id to hoClient 
                        Get Next_Mdi_Dialog of hoClient True to hView     // Find first view.
                        While (hView <> 0)
                            If (Active_State(hView)) Break
                            Get Next_Mdi_Dialog of hoClient False to hView // Find next view.
                        Loop                
                        Get phoReportControl of hView to ho
                        Send PrintPreview of ho True
                    End_Procedure  
                    
                End_Object // ooPrintPreviewMenuItem
                
                Object ooPrintMenuItem is a cCJMenuItem
                    Set psCaption to "Print the ReportControlGrid with Data"
                    Set psTooltip to "Printing of the Report Object"
                
                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient ho
                        Get Client_Id to hoClient
                        Get phoReportControl of (oReportControlWithDataTest(hoClient)) to ho
                        Send PrintReport  of ho True
                    End_Procedure  
                    
                End_Object // ooPrintMenuItem   
                
                Object ooPrintSetupItem is a cCJMenuItem
                    Set psCaption to "Printer Setup"
                    Set psTooltip to "Set up Printer options for the Report Object"
                
                    Procedure OnExecute Variant vCommandBarControl
                        Handle hoClient ho
                        Get Client_Id to hoClient
                        Get phoReportControl       of (oReportControlWithDataTest(hoClient)) to ho
                        Send ShowPrintPageSetup of ho True
                    End_Procedure  
                    
                End_Object // ooPrintSetupItem   
                
            End_Object

            Object oNavigateMenu is a cCJMenuItem
                Set peControlType to xtpControlPopup      
                Set psCaption to "&Navigate"    
                Set psTooltip to "Navigate"    
                Set psDescription to "Move to different areas of the application"

                Object oNextAreaMenu is a cCJNextAreaMenu
                End_Object

                Object oPriorAreaMenu is a cCJPriorAreaMenu
                End_Object

                Object oNextViewMenu is a cCJNextViewMenu
                End_Object

                Object oPriorViewMenu is a cCJPriorViewMenu
                End_Object

                Object oPromptMenu is a cCJPromptMenuItem
                    Set pbControlBeginGroup to True
                End_Object

                Object oZoomMenu is a cCJZoomMenuItem
                End_Object

            End_Object

            Object oWindowMenu is a cCJMDIWindowsMenuItem
                Set peControlType to xtpControlPopup      
                Set psCaption to "&Window"
                Set psToolTip to "Window"
                Set psDescription to "Display Current Views and set other display options."    

                // These are the static windows items. More will be created in onInitPopup 
                Object oDisplayOptionsMenu is a cCJMenuItem
                    Set peControlType to xtpControlPopup              
                    Set psCaption to "&Display Options"
                    Set psToolTip to "Display Options"
                    Set psDescription to "Set display options"

                    Object oStatusbarMenu is a cCJStatusbarMenuItem
                    End_Object

                    Object oAutoArrangeIconsMenu is a cCJAutoArrangeIconsMenuItem
                    End_Object

                    Object oRestoreMenusMenu is a cCJRestoreMenusMenuItem
                        Set pbControlBeginGroup to True
                    End_Object

                End_Object

                Object oCascadeMenu is a cCJCascadeMenuItem
                    Set pbControlBeginGroup to True
                End_Object

                Object oHorizTile is a cCJTileHorizontally
                End_Object

                Object oVertTile is a cCJTileVertically
                End_Object

                Object oMinimizeMenuItem is a cCJMinimizeWindowsMenuItem
                    Set pbControlBeginGroup to True
                End_Object

                Object oRestoreMenuItem is a cCJRestoreWindowsMenuItem
                End_Object

                Object oArrangeIconsMenuItem is a cCJAutoArrangeIconsMenuItem
                    Set pbControlBeginGroup to True
                End_Object

            End_Object

            Object oHelpMenu is a cCJMenuItem
                Set peControlType to xtpControlPopup    
                Set psCaption to "&Help"
                Set psDescription to "Access Information for learning and using this DataFlex application."
                Set psToolTip to "Help"

                Object oHelpMenuItem is a cCJHelpMenuItem 
                End_Object

                Object oAboutMenuItem is a cCJAboutMenuItem
                End_Object

            End_Object

        End_Object

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

            Object oFindFirstTool is a cCJFindFirstMenuItem
            End_Object

            Object oFindPreviousTool is a cCJFindPreviousMenuItem
            End_Object

            Object oFindMenuTool is a cCJFindMenuItem
            End_Object

            Object oFindNextTool is a cCJFindNextMenuItem
            End_Object

            Object oFindLastTool is a cCJFindLastMenuItem
            End_Object

            Object oPromptToolItem is a cCJPromptMenuItem
                Set pbControlBeginGroup to True
            End_Object

        End_Object

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

            Object oClearToolItem is a cCJClearMenuItem
                Set peControlStyle to xtpButtonIconAndCaption
            End_Object

            Object oClearAllToolItem2 is a cCJClearAllMenuItem
                Set peControlStyle to xtpButtonIconAndCaption
            End_Object

            Object oSaveToolItem is a cCJSaveMenuItem
                Set peControlStyle to xtpButtonIconAndCaption
                Set pbControlBeginGroup to True
            End_Object

            Object oDeleteToolItem is a cCJDeleteMenuItem
                Set peControlStyle to xtpButtonIconAndCaption
            End_Object

        End_Object

        Object oEditToolBar is a cCJToolbar
            Set psTitle to "Edit Toolbar"

            Object oCutToolbarItem is a cCJCutMenuItem
            End_Object

            Object oCopyToolbarItem is a cCJCopyMenuItem
            End_Object

            Object oPasteToolbarItem is a cCJPasteMenuItem
            End_Object

            Object oDeleteEditToolbarItem is a cCJDeleteEditMenuItem
                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

        // for testing we define the view and report menus for auto activate
        Delegate Set phoViewMenu to (oViewMenu)
        Delegate Set phoReportMenu to (oReportMenu)

    End_Object

    Object oClientArea is a ClientArea

        Use Dd_debug.dg // This Provides access to dd debugger by pressing ctrl+d within any view. Good for debugging

        Use StdAbout.pkg       
        
        Use ReportControlWithDataTest.vw
        Use ReportGridWithButtons.vw

        Procedure Activate_About
            Send DoAbout "Test Windows Project" "0.0.0" "" "" ""
        End_Procedure

    End_Object


    // All of the code below are methods and augmentations which makes this work well as a test program. This:
    // 1. Supports an auto-activate feature where all dialogs in the view and report menu are activated upon startup
    // 2. forces the panel to resize if it is not large enough to accomodate all of the views.
    // This code was placed directly in the testproject template and, therefore, directly in the .src file so
    // a developer can easily modify this to fit their own needs. It is not expected that these techniques would
    // get used in actual deployed projects.

    // special test component code to activate all views and reports. For testing we assume
    // that you want to see everything.

    Procedure AutoActivate
        handle hoMenu

        // this activates all views from the view menu
        Get phoViewMenu to hoMenu
        If hoMenu begin
           Broadcast Send Execute of hoMenu
        End

        // this activates all views from the report view menu
        Get phoReportMenu to hoMenu
        If hoMenu begin
//           Broadcast Send Execute of hoMenu
        End
    End_Procedure

    // This checks all views within the client area to make sure that they fit within
    // the client area. If not we will adjust the main panel so everything fits. This
    // can only be done after the objects are all activated.

    Procedure MakeGoodPanelSize
        Handle hoView hoClient
        Integer iSize iLoc iHeight iWidth iOldSize
        Get Client_Id to hoClient
        If hoClient begin
            Get GuiSize of hoClient to iOldSize  // starting size of client area
            Move (Hi(iOldSize)) to iHeight
            Move (Low(iOldSize)) to iWidth
            // for each mdi client see if it fits, keep track of largest size needed
            Get Next_Mdi_Dialog of hoClient True to hoView // find first
            While (hoView)
                Get GuiSize of hoView to iSize    // size of view
                Get GuiLocation of hoView to iLoc // location of view
                Move (hi(iSize)+hi(iLoc)+10 max iHeight)  to iHeight // max height needed (+10 is for wiggle room)
                Move (low(iSize)+low(iLoc)+10 max iWidth) to iWidth  // max width needed
                Get Next_Mdi_Dialog of hoClient False to hoView // find next view
            Loop
            Move (iHeight-hi(iOldSize) max 0) to iHeight // get delta compared to old size. We want delta
            Move (iWidth-low(iOldSize) max 0) to iWidth  // only if the new size is bigger (i.e., > 0)
            If  (iHeight>0 or iWidth>0) begin
                Get GuiSize to iOldSize // now add the delta to the panel size
                Set GuiSize to (hi(iOldSize)+iHeight) (low(iOldSize)+iWidth)
                Send Adjust_Logicals // adjust from gui to regular size
            End
        End
    End_Procedure

    // special test program  augmentation which opens all views and report views and
    // makes sure that the size of the panel is big enough

    Procedure End_Construct_Object
        Boolean bAutoActivate
        Get Auto_Activate_State to bAutoActivate
        Forward send End_Construct_Object
        If bAutoActivate begin
            Send AutoActivate       // activate all views and report views
            Send MakeGoodPanelSize  // make sure the panel is big enough for all of this
        End
    End_Procedure

End_Object

Start_UI
