Customizing Predefined Dialog Boxes

This section shows you how to program modifications to a predefined dialog box to fit the needs of an application.

IlvFileChooser

There are 2 options for customizing the IlvFileChooser Dialog Box:

  • Use the IlvFileChooserOptions class to specify options of the IlvFileChooser dialog. This class enables you to make changes easily, for example, changing a label or the size of a button.

    The following code fragment shows how to add file filters to the Filter list of the IlvFileChooser dialog:

 

if (filename && filename[0] && IlvFileExists(filename)) ...

IlvFileChooserOptions* opt = new IlvFileChooserOptions(IlvFileChooserOpen);

opt->addFilter("All files (*.*)","*");

opt->addFilter("Ilv files (*.ilv)","ilv");

opt->addFilter("Iva files (*.iva)","iva");

opt->addFilter("Views files (*.iva,*.ilv)","iva|ilv");

dlg = new IlvFileChooser(getDisplay(),0,0,opt);

if (dlg->get() > 0) {

IlString filename = dlg->getResult(0);

if ((filename. getLength() > 0) && IlvFileExists((const char*)filename)) {

...

}

}

delete dlg;

  • Use a subclass of the IlvFileChooserOptions class to provide a specific implementation for virtual functions.

    The following code fragment shows how to change the width of labels File name and Filter and to hide the Up directory button:

class MyOptionsClass : public IlvFileChooserOptions

{

public:

MyOptionsClass(IlvFileChooserType typ = IlvFileChooserOpen,

IlvFileChooserSelection sel

= IlvFileChooserFileSelection):

IlvFileChooserOptions(typ, sel) {

}

 

virtual IlInt getLabelWidth() const { return 100; }

virtual IlBoolean isUpDirectoryButtonShown() const { return IlFalse; }

};

 

MyOptionsClass* opt = new MyOptionsClass();

dlg = new IlvFileChooser(getDisplay(), 0, 0, opt);

if (dlg->get() > 0) {

IlString filename = dlg->getResult(0);

if ((filename.getLength() > 0) && IlvFileExists((const char*)filename))

{

...

}

}

delete dlg;

With either option, if you want to provide your own Apply button or sheet, you need to create a subclass of the IlvFileChooser class itself. You are also responsible for the connection between your created gadgets and the IlvFileChooser methods which manage events. For example, call the processApply method when the Apply button is clicked.

The following code fragment creates a subclass of IlvFileChooser where:

  • The label of the Apply button is Validate

  • The Apply button is represented by a bitmap image

  • The sheet is always single selection

class MyFileChooser : public IlvFileChooser

{

public:

MyFileChooser(IlvDisplay* display,

const char* dir = 0,

const char* title = 0,

IlvFileChooserOptions* options = 0,

IlvSystemView transientFor = 0,

IlUInt properties = 0)

: IlvFileChooser(display, dir, title, options, transientFor, properties) {}

 

virtual IlvButton* createApplyButton(const IlvRect& rect,

const IlString& label) const;

virtual IlvFileChooserSheet* createSheet(const IlvRect& rect) const;

};

 

// Set Apply button characteristics

static void

MyApplyCB(IlvGraphic*, IlAny arg)

{

MyFileChooser* dlg = (MyFileChooser*)arg;

if (dlg)

dlg->processApply();

}

 

IlvButton*

MyFileChooser::createApplyButton(const IlvRect& rect,

const IlString& label) const

{

// Read the bitmap

IlvBitmap* bmp = getDisplay()->readBitmap("my bitmap file name");

// Create a button

IlvButton* btn = new IlvButton(getDisplay(), "Validate", rect);

btn->setBitmap(bmp);

// Connect the button to a callback to manage the click events

btn->addCallback(btn->CallbackSymbol(), MyApplyCB, (IlAny)this);

return btn;

}

 

// Set sheet to single selection mode

static void

MySheetSelectionCB(IlvGraphic*, IlAny arg)

{

MyFileChooser* dlg = (MyFileChooser*)arg;

if (dlg)

dlg->selectionChanged();

}

 

IlvFileChooserSheet*

MyFileChooser::createSheet(const IlvRect& rect) const

{

IlvFileChooserSheet* sheet =

new IlvFileChooserSheet(getDisplay(), rect, (IlvFileChooser*)this);

 

// Disable multi selection

sheet->setExclusive(IlTrue);

// Disable edition

sheet->allowEdit(IlFalse);

// Connect the sheet with the dialog to manage the selection changes

sheet->setCallback(sheet->CallbackSymbol(), MySheetSelectionCB, (IlAny)this);

return sheet;

}

Note
  • The IlvFileChooser dialog does not have a .ilv file. It is a fully dynamic creation dialog where each gadget is created using code, and then added into the container with a specific dynamic geometry.

  • The methods which return a created gadget must not return a null value. If you want to hide the Filter list, you can remove all filters from the IlvFileChooserOptions object when it is used to initialize the IlvFileChooser dialog, or use an IlvFileChooserOptions object with a selection type in IlvFileChooserDirectorySelection. If you choose this second option, you cannot select a file.