Rogue Wave Views Gadgets > Using Common Gadgets > Using IlvNotebook > Handling Notebook Pages
 
Handling Notebook Pages
The pages of a notebook are implemented by the class IlvNotebookPage, 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
*Displaying the Contents of a Page
*Customizing a Notebook Page
*Changing the Color of a Notebook Page
*Setting the Content of Tabs
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 the addPage member functions:
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 the notebook related to a page using getNotebook.
To know how many pages there are in a notebook, use getPagesCardinal.
To retrieve the internal notebook page array, use getPages. To retrieve the first page, call:
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 with getView.
You can load an .ilv file into a notebook page with the member function setFileName and retrieve this file with getFileName.
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
You can change the view held by an IlvNotebookPage using the member function setView. You can also redefine the member function createView in a subclass of IlvNotebookPage. See Displaying the Contents of a 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
Each page of the notebook can have a different background color. To change this color, use the member function setBackground. When you change the background color of a notebook page, this color is applied to the background of its view.
Setting the Content of Tabs
The notebook tab can contain a label and/or a bitmap. To set the label that appears in a notebook tab, use the member function setLabel. Use getLabel to retrieve this label.
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 the member function setBitmap. Use getBitmap to retrieve this bitmap.

Version 5.6
Copyright © 2012, Rogue Wave Software, Inc. All Rights Reserved.