//####
//# Legal Notice :
//#    Copyright, Harman International, 2015
//#    Private, proprietary information, the sole property of Harman.  The
//#    contents, ideas, and concepts expressed herein are not to be disclosed
//#    except within the confines of a confidential relationship and only
//#    then on a need to know basis.
//#
//#    Any entity in possession of this Harman Software shall not, and shall not
//#    permit any other person to, disclose, display, loan, publish, transfer
//#    (whether by sale, assignment, exchange, gift, operation of law or
//#    otherwise), license, sublicense, copy, or otherwise disseminate this
//#    Harman Software.
//#
//#    This Harman Software is owned by Harman and is protected by United States
//#    copyright laws, patent laws, international treaty provisions, and/or
//#    state of Texas trade secret laws.
//#
//#    Portions of this Harman Software may, from time to time, include
//#    pre-release code and such code may not be at the level of performance,
//#    compatibility and functionality of the final code. The pre-release code
//#    may not operate correctly and may be substantially modified prior to
//#    final release or certain features may not be generally released. Harman is
//#    not obligated to make or support any pre-release code. All pre-release
//#    code is provided "as is" with no warranties.
//#
//#    This Harman Software is provided with restricted rights. Use, duplication,
//#    or disclosure by the Government is subject to restrictions as set forth
//#    in subparagraph (1)(ii) of The Rights in Technical Data and Computer
//#    Software clause at DFARS 252.227-7013 or subparagraphs (1) and (2) of
//#    the Commercial Computer Software Restricted Rights at 48 CFR 52.227-19,
//#    as applicable.
//####

PROGRAM_NAME='TVGuide_CUSTOM_EVENT'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)
DEFINE_DEVICE
dvTP = 10001:1:0

DEFINE_CONSTANT
// TV Channels Listview button address
INTEGER btnTvListview = 12

DEFINE_VARIABLE

DEFINE_EVENT
 
// The custom event that is raised whenever a TV listview item
// is selected on the panel.
// Custom event data has three integers, a data string and an
// encoding string.  This is not enough to represent what could
// potentially be a very complex DATA_RECORD.  So the listview
// custom event will include a payload ID that can then be used
// to retrieve the contents of the DATA_RECORD.
CUSTOM_EVENT[dvTP,btnTvListview,LISTVIEW_ON_ROW_SELECT_EVENT]
{
    // Variables to hold the ID and type for the payload
    SLONG payloadId
    SLONG payloadType
    // The function to retrieve the payload data takes an array of 1 or more
    // strings that specify which DATA_FIELDs we wish to retrieve.  In our
    // example we're interested in 3 fields and 16 characters is long enough
    // to hold the id.
    CHAR fields[3][16]
    // Create a DATA_RECORD to hold the retrieved data
    DATA_RECORD record
    // Get the payload ID from the custom event
    payloadId = custom.value1
    // Get the data type from the custom event
    payloadType = custom.value2
    // Always check for a valid payload ID and check the payload
    // type.  Future improvements to the feature may have other
    // payload types.    
    if (payloadId > 0 && payloadType == DATA_STRUCTURE_DATARECORD)
    {
        // Specify which DATA_FIELD ids we want to retrieve from the payload
 	fields[1] = 'NAME'
	fields[2] = 'CHANNEL CODE'
	fields[3] = 'ICON'
	// When retrieving the data, always check the return value.  If the
	// return value is greater than zero then the DATA_RECORD that was
	// passed in will be populated with the requested DATA_FIELDs.
	if (DATA_GET_EVENT_RECORD(dvTP, payloadId, fields, record) > 0)
	{
	    // Put the channel number and name at the bottom of the TV
	    // subpage and show the subpage
	    SEND_COMMAND dvTP,"'^TXT-13,0,Channel ',record.content[2].value,' - ',record.content[1].value"
	    SEND_COMMAND dvTP,"'^BMX-77,0,',record.content[3].value,',1,10'"
	}
    }
}

DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)

