Gadgets > The ViewFile Application: Building a Simple File Browser > Step 4: Adding View Frames
 
Step 4: Adding View Frames
This last step explains how to add view frame support to the ViewFile application. Including view frames into the application allows you to display and browse through several hierarchical lists of files at the same time. For more information, see View Frames.
All changes made in this step are reflected in the file viewfile.cpp.
This step shows you how to perform the following tasks:
*Choosing the Desktop View
*Creating View Frames
*Adding New Menus and Items to View Frames
*Previewing the Application
Choosing the Desktop View
View frames are displayed inside a desktop view. The first operation consists of choosing the desktop view where view frames will be displayed. The best place to put the desktop view is the main workspace view pane, where the unique file viewer was displayed in Step 3: Adding Docking Bars. The desktop manager that will manage all the view frames can be created from this view.
Creating the Desktop Manager
The FileViewerApplication::makePanels member function must be modified to include a call to initDesktopManager, which creates the desktop manager using the main workspace view pane.
void
FileViewerApplication::makePanels()
{
// Initialize the main window.
initMainWindow();
 
// Initialize the desktop manager.
initDesktopManager();
 
// Initialize the panes.
initPanes();
 
// Initialize the application.
configureApplication();
 
// Update the main window layout.
getMainWindow()->updatePanes(IlvTrue);
 
// Show it.
getMainWindow()->show();
}
Here is the detail of initDesktopManager:
void
FileViewerApplication::initDesktopManager()
{
createDesktopManager(getMainWindow()->
getMainWorkspaceViewPane()->getView());
}
The factory member function FileViewerApplication::createDesktopManager returns an instance of the IlvDesktopManager class:
IlvDesktopManager*
FileViewerApplication::createDesktopManager(IlvView* view) const
{
return new IlvDesktopManager(view);
}
Initializing the Desktop Manager
You must also modify FileViewerApplication::configureApplication to initialize the desktop manager:
void
FileViewerApplication::configureApplication()
{
// The desktop manager is maximized by default.
getDesktopManager()->
makeMaximizedStateButtons((IlvToolBar*)
((IlvGraphicPane*)getMainWindow()->
getPane("Menu Bar", IlvTrue))->getObject());
getDesktopManager()->maximize(0);
 
// Create a frame initialized at "/".
getDesktopManager()->setCurrentFrame(createNewFrame(IlvRect(0,
0,
400,
200), "/"));
}
makeMaximizedStateButtons specifies where the buttons of the view frame should appear when it is maximized.
See “Maximized View Frames” in View Frames.
The buttons are displayed inside the menu bar, as shown here:
Then, the desktop manager is maximized, and a default frame is created by FileViewerApplication::createNewFrame.
Creating View Frames
The member function FileViewerApplication::createNewFrame creates a new frame that encapsulates the file viewer and its associated window:
IlvViewFrame*
FileViewerApplication::createNewFrame(const IlvRect& rect,
const char* path) const
{
// Create a view frame in the desktop manager view.
IlvViewFrame* vframe = new IlvViewFrame(getDesktopManager()->getView(),
path,
rect,
IlvFalse);
vframe->setDestroyCallback(DestroyFrame);
// Create a file viewer window inside the view frame.
FileViewerWindow* viewerWindow = createFileViewerWindow(vframe, rect);
// Create the file viewer in the file viewer window.
FileViewer* viewer = createFileViewer(viewerWindow);
// Associate the viewer window with the viewer.
SetFileViewer(viewerWindow, viewer);
// Initialize the file viewer.
viewer->init(IlvPathName(path));
return vframe;
}
The member function IlvView::setDestroyCallback sets a destroy callback that handles the deletion of the created frame. See “Closing View Frames” in View Frames.
Then, the file viewer window is created as a subview of the view frame. See “Creating a Client View” in View Frames. Finally, a file viewer is connected to the view frame and initialized.
Adding New Menus and Items to View Frames
To add new menu items to the menu bar, you must modify the member function FileViewerApplication::initMenuBar as follows:
void
FileViewerApplication::initMenuBar()
{
// The menu bar is in fact an IlvToolBar.
IlvToolBar* menubar = new IlvToolBar(getDisplay(), IlvPoint(0, 0));
// Add three items.
menubar->addLabel("File");
menubar->addLabel("Windows");
menubar->addLabel("Help");
// Create the pane that will encapsulate the menu bar.
IlvGraphicPane* menubarPane = new ApplicationMenuBarPane("Menu Bar",
menubar);
// Change the mode of the menu bar to make it show items on several
// rows, if needed.
menubar->setConstraintMode(IlvTrue);
// Add the pane to the application on top of the main workspace.
getMainWindow()->addRelativeDockingPane(menubarPane,
IlvDockableMainWindow::
GetMainWorkspaceName(),
IlvTop);
// Now fill the menus with popup menus.
IlvPopupMenu* menu;
// Menu File: New / Separator / Exit.
menu = new IlvPopupMenu(getDisplay());
menu->addLabel("New (Ctrl+N)");
menu->getItem(0)->setBitmap(getBitmap("newBm"));
menu->getItem(0)->setCallback(AddNewFrame);
menu->getItem(0)->setClientData(this);
menu->getItem(0)->setAcceleratorText("Ctrl+N");
menu->getItem(0)->setAcceleratorKey(IlvCtrlChar('N'));
menu->addItem(IlvMenuItem());
menu->addLabel("Exit");
menu->getItem(2)->setCallback(ExitApplication);
menu->getItem(2)->setClientData(this);
menubar->getItem(0)->setMenu(menu, IlvFalse);
// Menu Windows: Cascade / Tile Horizontally / Tile Vertically.
menu = new IlvPopupMenu(getDisplay());
menu->addLabel("Cascade");
menu->getItem(0)->setCallback(CascadeFrames);
menu->getItem(0)->setClientData(this);
menu->addLabel("Tile Horizontally");
menu->getItem(1)->setCallback(TileHorizontallyFrames);
menu->getItem(1)->setClientData(this);
menu->addLabel("Tile Vertically");
menu->getItem(2)->setCallback(TileVerticallyFrames);
menu->getItem(2)->setClientData(this);
menubar->getItem(1)->setMenu(menu, IlvFalse);
// Menu Help: About.
menu = new IlvPopupMenu(getDisplay());
menu->addLabel("About");
menubar->getItem(2)->setMenu(menu, IlvFalse);
menu->getItem(0)->setCallback(ShowAboutPanel);
menu->getItem(0)->setClientData(this);
}
The menu bar has a Windows menu that contains the sub-items shown in the following figure:
The callbacks used by the Windows menu invoke the corresponding member functions on the desktop manager:
static void
CascadeFrames(IlvGraphic* g, IlvAny arg)
{
FileViewerApplication* application = (FileViewerApplication*)arg;
application->getDesktopManager()->cascadeFrames();
}
 
static void
TileHorizontallyFrames(IlvGraphic* g, IlvAny arg)
{
FileViewerApplication* application = (FileViewerApplication*)arg;
application->getDesktopManager()->tileFrames(IlvHorizontal);
}
 
static void
TileVerticallyFrames(IlvGraphic* g, IlvAny arg)
{
FileViewerApplication* application = (FileViewerApplication*)arg;
application->getDesktopManager()->tileFrames(IlvVertical);
}
The member function FileViewerApplication::initToolBar has also been modified to include a New item that creates a new frame when selected:
void
FileViewerApplication::initToolBar()
{
IlvToolBar* toolbar = new IlvToolBar(getDisplay(), IlvPoint(0, 0));
// Item New.
toolbar->insertBitmap(getBitmap("newBm"));
toolbar->getItem(0)->setCallback(AddNewFrame);
toolbar->getItem(0)->setClientData(this);
toolbar->getItem(0)->setToolTip("New");
// Separator.
toolbar->addItem(IlvMenuItem());
// Item Up One Level.
toolbar->insertBitmap(getBitmap("upBm"));
toolbar->getItem(2)->setCallback(UpOneLevel);
toolbar->getItem(2)->setClientData(this);
toolbar->getItem(2)->setToolTip("Up One Level");
// Encapsulate the toolbar into a graphic pane.
IlvGraphicPane* toolbarPane = new IlvAbstractBarPane("Toolbar", toolbar);
// Add the pane to the application on top of the main workspace.
getMainWindow()->addRelativeDockingPane(toolbarPane,
IlvDockableMainWindow::
GetMainWorkspaceName(),
IlvTop);
}
The callback triggered by the new item invokes the member function FileViewerApplication::createNewFrame and activates the new frame:
static void
AddNewFrame(IlvGraphic* g, IlvAny arg)
{
FileViewerApplication* application = (FileViewerApplication*)arg;
IlvViewFrame* vframe =
application->createNewFrame(IlvRect(0, 0, 400, 200), "/");
application->getDesktopManager()->setCurrentFrame(vframe);
}
Note: The New item is associated with an accelerator key allowing the user to create a new frame by pressing the Ctrl+N key combination. See “Associating Accelerators on Menu Items” in Menus, Menu Bars, and Toolbars.
Previewing the Application
You have completed this tutorial. The application window should look like this:
Figure 1.6    The Final ViewFile Application

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