Skip to content

Instantly share code, notes, and snippets.

@lukpazera
Last active November 25, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukpazera/8239a7830430dc53c83e to your computer and use it in GitHub Desktop.
Save lukpazera/8239a7830430dc53c83e to your computer and use it in GitHub Desktop.
Setting up dependencies between channels on a custom item requires implementing ChannelUI interface .
/*
* If you want to create dependencies between channels on a custom item
* such that one channel enable state depends on some other channel value
* (on the same item) you need to implement ChannelUI interface for your item.
*/
/* This is needed to obtain the implemented custom item type.
* (see DependencyCountIndex() method below)
*/
static CLxItemType cit_self (MY_CUSTOM_ITEM_TYPE_NAME);
class CPackage :
public CLxImpl_Package,
public CLxImpl_ChannelUI
{
// Declarations of other custom item methods go there...
// Declarations of ChannelUI methods.
LxResult cui_Enabled (const char* channelName, ILxUnknownID msg, ILxUnknownID item, ILxUnknownID read) LXx_OVERRIDE;
LxResult cui_DependencyCount (const char* channelName, unsigned* count) LXx_OVERRIDE;
LxResult cui_DependencyByIndex (const char* channelName, unsigned index, LXtItemType* depItemType, const char** depChannelName) LXx_OVERRIDE;
};
/* Enabled method will be called to query whether a channel of given name
* (first argument) should be enabled or disabled.
* Returning LXe_OK means enabled, LXe_CMD_DISABLED otherwise.
*/
LxResult
CPackage::cui_Enabled(
const char *channelName,
ILxUnknownID msg,
ILxUnknownID item,
ILxUnknownID read)
{
LxResult result = LXe_OK;
if (0 == strcmp (channelName, CHAN_TO_ENABLE_DISABLE_NAME)) {
CLxUser_Item chanItem (item);
CLxUser_ChannelRead chanRead (read);
int otherChanVal = chanRead.IValue (chanItem, SOME_OTHER_CHAN_NAME);
if (someValue != otherChanVal) {
result = LXe_CMD_DISABLED;
}
}
return result;
}
/*
* We need to set up dependencies between channels which will take care of notifications
* and Enabled() method will be called correctly, whenever our channel needs to update
* its enabled/disabled state.
* Note that notifications work for setting up dependencies between channels on the same item.
* If you need to make one of custom item's channels dependent on a channel from a different item
* you will have to handle notifications yourself.
*/
/*
* DependencyCount() needs to return a number of channels given channel
* (which name is passed as first argument) will depend on.
* In our case we make the channel dependent on one other channel.
*/
LxResult
CPackage::cui_DependencyCount (const char* channelName, unsigned* count)
{
if (0 == strcmp (channelName, CHAN_TO_ENABLE_DISABLE_NAME)) {
count[0] = 1;
}
else {
count[0] = 0;
}
return LXe_OK;
}
/*
* This method will be called for every channel that has dependency count of at least 1
* and it will be called for every dependency index. So if a channel depends on 2 other channels
* this method will be called twice for a given channel, once with index 0 and once with index 1.
* You need to return name of a channel queried channel depends on for every index.
* You also have to set the item type properly (to your custom item type).
*/
LxResult
CPackage::cui_DependencyByIndex (
const char *channelName,
unsigned index,
LXtItemType *depItemType,
const char **depChannelName)
{
LxResult result = LXe_OUTOFBOUNDS;
if (0 == strcmp (channelName, CHAN_TO_ENABLE_DISABLE_NAME))
{
depItemType[0] = cit_self;
depChannelName[0] = SOME_OTHER_CHAN_NAME;
result = LXe_OK;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment