Gadgets > Rogue Wave Views Gadgets > Customizing the Look and Feel > Making a User-Defined Component Look-and-Feel Dependant > Defining the Object Look-and-Feel Handler API
 
Defining the Object Look-and-Feel Handler API
The object look-and-feel handler API depends on the component you are designing. As a general rule, you should provide a way to customize its look and its behavior. This can be done by adding the following methods to your object class:
class MyComponent : public IlvGadget
{
...
virtual void draw(IlvPort* dst,
const IlvTransformer* t,
const IlvRegion* clip) const;
virtual IlBoolean handleEvent(IlvEvent& event) const;
...
 
};
You must also add these methods to the object look-and-feel handler class:
class MyComponentLFHandler : public IlvObjectLFHandler
{
MyComponentLFHandler(IlvLookFeelHandler* lfh) :
IlvObjectLFHandler(MyComponent::ClassInfo(), lfh) {}
...
virtual void draw(const MyComponent* object,
IlvPort* dst,
const IlvTransformer* t,
const IlvRegion* clip) const = 0;
virtual IlBoolean handleEvent(MyComponent* object,
IlvEvent& event) const = 0;
...
};
Notes:  
1. Since object look-and-feel handlers are shared objects, you need to give access to MyComponent instance in each method of the object look-and-feel handler class. You can do this by using the first parameter of the methods.
2. The constructor of MyComponentLFHandler uses the MyComponent::ClassInfo method to link this object handler with MyComponent class. Thus, each subclass of MyComponentLFHandler will be dedicated to MyComponent component.
The implementation of the MyComponent methods should be as follow:
void
MyComponent::draw(IlvPort* dst,
const IlvTransformer* t,
const IlvRegion* clip) const
{
MyComponent* lfhandler = (MyComponentLFHandler*)
getObjectLFHandler(MyComponent::ClassInfo());
lfhandler->draw(this, dst, t, clip);
}
and for the handleEvent method:
IlBoolean
MyComponent::handleEvent(IlvEvent& event)
{
MyComponentLFHandler* lfhandler = (MyComponentLFHandler*)
getObjectLFHandler(ClassInfo());
return lfhandler->handleEvent(this, event);
}
Of course, you can add other functionalities to your component, and make them look-and-feel dependant using the same scheme.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.