// Master.sl
// Master Lookup List

Use DFClient.pkg
Use DFSelLst.pkg
Use Windows.pkg
Use Master.DD
Use CodeMast.DD

Object Master_sl is a dbModalPanel
    Set Location to 3 3
    Set Size to 259 616
    Set Label to "Please Select a Question"
    Set Border_Style to Border_Thick
    Set Minimize_Icon to False
    Set Sysmenu_Icon to ""

    Object oMaster_DD Is A Master_DataDictionary
    End_Object // oMaster_DD

    Set Main_DD To oMaster_DD
    Set Server  To oMaster_DD

    Object oSelList Is A dbList
        Set Size to 228 612
        Set Location to 10 2
        Set peAnchors to anAll
        Set Main_File to Master.File_Number
        Set Ordering to 1
        Set peResizeColumn to rcSelectedColumn
        Set Auto_Server_State to True
        Set pbHeaderTogglesDirection to True

        Begin_row
            Entry_Item Master.Id
            Entry_Item Master.Question
            Entry_Item Master.Answer
            Entry_Item Master.Subject
            Entry_Item Master.Level
            Entry_Item Master.Created
            Entry_Item Master.Date_Used
        End_row

        Set Form_Width 0 to 30
        Set Header_Label 0 to "ID"

        Set Form_Width 1 to 255
        Set Header_Label 1 to "Question"

        Set Form_Width 2 to 121
        Set Header_Label 2 to "Answer"

        Set Form_Width 3 to 60
        Set Header_Label 3 to "Subject"

        Set Header_Label 4 to "Level"
        Set Form_Width 4 to 50

        Set Form_Width 5 to 42
        Set Header_Label 5 to "Created"

        Set Form_Width 6 to 47
        Set Header_Label 6 to "Date Used"
        Set piResizeColumn to 1
        Set CurrentRowColor to clActiveCaption
        Set CurrentRowTextColor to clCaptionText
        Set CurrentCellTextColor to clCaptionText
        Set CurrentCellColor to clActiveCaption

        // Augmented to display the real type and level from table
        // CodeMast rather then the type id from the Master table.
        Procedure Entry_Display Integer iFile Integer iType
            String  sDesc sLevel
            Integer iItem
                  
            Forward Send Entry_Display iFile iType
            Get Dynamic_Quiz_Subject to sDesc  // Function in Main object
            Get Dynamic_Quiz_Level   to sLevel // Function in Main object
            
            Get Base_Item to iItem             // first item of the current row
            Set Value (iItem +3) to sDesc      // Fourth column
            Set Value (iItem +4) to sLevel     // Fifth column
        End_Procedure // Entry_Display

        // Augmented to change the Question & Answer to the proper field
        // depending on the value of Settings.LangModeOutput.
        Procedure Activating Returns Integer
            Handle hoElement
            Integer iRetval
            Move (Element(Self)) to hoElement                // Element is the prototype object of the grid.
            If      (Settings.LangModeOutput = 0) Begin
                Set Data_Field of hoElement item 1 to 1      // Field 1 = Question
                Set Data_Field of hoElement item 2 to 2      // Field 2 = Answer
            End // If      (Settings.LangModeOutput = 0) Begin
            Else If (Settings.LangModeOutput = 1) Begin
                Set Data_Field of hoElement item 1 to 8      // Field 8 = Question2
                Set Data_Field of hoElement item 2 to 9      // Field 9 = Answer2
            End // Else If (Settings.LangModeOutput = 1) Begin
            Forward Get Msg_Activating to iRetval
            Procedure_Return iRetval
        End_Procedure // Activating  
            
    End_Object // oSelList

    Object oOk_bn Is A Button
        Set Label to "&Ok"
        Set Location to 244 451
        Set peAnchors to anBottomRight

        Procedure OnClick
            Send OK of oSelList
        End_Procedure

    End_Object // oOk_bn

    Object oCancel_bn Is A Button
        Set Label to "&Cancel"
        Set Location to 244 505
        Set peAnchors to anBottomRight

        Procedure OnClick
            Send Cancel of oSelList
        End_Procedure

    End_Object // oCancel_bn

    Object oSearch_bn Is A Button
        Set Label to "&Search..."
        Set Location to 244 559
        Set peAnchors to anBottomRight

        Procedure OnClick
            Send Search of oSelList
        End_Procedure

    End_Object // oSearch_bn

    On_Key Key_Alt+Key_O Send KeyAction of oOk_bn
    On_Key Key_Alt+Key_A Send KeyAction of oCancel_bn
    On_Key Key_Alt+Key_S Send KeyAction of oSearch_bn

End_Object // Master_sl
