Gadgets > Creating GUI Applications with Rogue Wave Views Studio > Extending Rogue Wave Views Studio > Integrating your Own Graphic Objects > Defining a New Command to Add an Object
 
Defining a New Command to Add an Object
To add an instance of a user-defined class to Rogue Wave® Views Studio, you have to write a new command. The class IlvStClickAddObject defines a command that can be used to add an object at the position indicated by a mouse click. To create an instance of a user-defined graphic class, you will have to redefine its virtual member function makeObject in a derived class, as shown in the example below:
#include <ivstudio/edit.h>
 
class MyAddClass: public IlvStClickAddObject {
protected:
virtual IlvStError* makeObject(IlvGraphic*& obj, IlvStudio* ed, IlvAny) {
MyClass* mc = new MyClass(ed->getDisplay(), IlvRect(0, 0, 40, 40));
obj = mc;
return 0;
}
};
The following command constructor creates and returns a new instance of the user-defined class:
static IlvStCommand*
MkMyAddClass(IlvStudio*)
{
return new MyAddClass;
}
You can then create a subclass of IlvStExtension and define the initializeCommandDescriptors method to register the command constructor, as follows:
IlBoolean
MyStudioExtension::initializeCommandDescriptors()
{
getEditor()->registerCommand("AddMyClass", MkMyAddClass);
return IlTrue;
}
In an option file, you can write your command declaration like this:
studio {
// ...
command AddMyClass {
label "MyClass";
prompt "Add an object of my class";
category add;
}
// ...
}
The name given to the command is the same as the one registered with the editor. In this example, the command is displayed in the add category of the Commands panel.
If required, you can declare your option file using the ILVSTOPTIONFILE environment variable.

Version 6.0
Copyright © 2015, Rogue Wave Software, Inc. All Rights Reserved.