Handling Notebook Pages
The pages of a notebook are implemented by the class , which you can subclass to meet specific requirements. Instances of IlvNotebookPage can encapsulate an IlvGadgetContainer or any other type of view. See Displaying the Contents of a Page.
This section covers the following topics:
Adding and Removing a Notebook Page
When created, a notebook has no pages. A notebook must contain at least one page.
To add a page to a notebook, use one of
IlvNotebookPage* addPage(IlvNotebookPage* page,
IlUShort idx = IlvNotebookLastPage);
IlvNotebookPage* addPage(const char* label,
IlvBitmap* bitmap = 0,
IlBoolean transparent = IlTrue,
const char* filename = 0,
IlUShort idx = IlvNotebookLastPage);
The first addPage member function lets you add a subclass of IlvNotebookPage. The second one creates a new instance of IlvNotebookPage. The idx parameter specifies the position at which the page is to be added.
An IlvNotebookPage is always related to a specific notebook, which means that you cannot share an IlvNotebookPage between two notebooks. You can retrieve
To know how many pages there are in a
To retrieve the internal notebook page array,
page = notebook->getPages()[0];
To remove a specific page, use removePage.
Displaying the Contents of a Page
The member function createView creates a view of type IlvGadgetContainer to display the contents of the page, which you can retrieve
You can load an .ilv file into a notebook page with
The member function setFileName assumes that the view is an IlvGadgetContainer or one of its subclasses. You will have to override it if you use another type of view.
Customizing a Notebook Page
This member function instantiates an invisible view with the size given as its parameter. It also loads an .ilv file (result of getFileName) into the new view.
For example, to have notebook pages encapsulate IlvScrolledView instances, subclass IlvNotebookPage as follows:
class myNotebookPage : public IlvNotebookPage
{
public:
myNotebookPage(IlvNotebook* gadget,
const char* label,
Ilvbitmap* bitmap,
IlBoolean transparent,
const char* filename)
: IlvNotebookPage(gadget, label, bitmap, transparent, filename) {}
virtual IlvView* createView(IlvAbstractView* parent,
const IlvRect& size);
};
IlvView* myNotebookPage::createView(IlvAbstractView* parent,
const IlvRect& size)
{
IlvScrolledView* scview = new IlvScrolledView(parent,size);
IlvGadgetContainer* child = new IlvGadgetContainer(scview->getClipView(),
IlvRect(0,0,100,100));
if (_filename && _filename[0])
child->readFile(_filename);
child->fitToContents();
return scview;
}
Then create a new notebook page and add it to the notebook:
myNotebookPage* np5=
new myNotebookPage(nb,”Page5”,0,IlFalse,”../snbook.ilv”);
nb->addPage(np5);
If your view can read an .ilv file, you can overload the member function setFileName.
If you need to add more drawings to your page, you can overload the draw method:
void draw(IlvPort* dst,
const IlvRect& pageRect,
const IlvTransformer* t,
const IlvRegion* clip) const;
You also need to create the following constructors for your page:
MyNotebookPage::MyNotebookPage(IlvNotebook* notebook);
MyNotebookPage::MyNotebookPage(IlvNotebook* notebook,
const char* label,
IlvBitmap* bitmap,
IlBoolean transparent,
const char* filename);
MyNotebookPage::MyNotebookPage(const MyNotebookPage& source);
MyNotebookPage::MyNotebookPage(IlvNotebook* notebook,
IlvInputFile&);
The member function write and the constructor that takes an IlvInputFile as a parameter let you extend the.ilv format of the page.
Changing the Color of a Notebook Page
Setting the Content of Tabs
This label can have a mnemonic. See Associating a Mnemonic with a Gadget Label.
To set the bitmap that appears in a notebook tab, use