The Bitmap Editor Application > Step 3: Modifying and Saving a Bitmap > Changing the Document Palette
 
Changing the Document Palette
Earlier in this step, the palette used to modify the document bitmap was the palette of the document (as seen in the DrawBitmapInteractor::handleEvent method). One way to change the drawing color is to modify the document palette. To do so, a new action must first be added to our application—the ColorChooser action:
1. Launch the Application Framework Wizard.
2. Open the BitmapEditor.odv file.
3. Click on Actions:
4. Click New Action to add a new action.
5. Change the Command name of the created action to ColorChooser.
6. Change the description of the action.
7. Change the tooltip description.
8. In the Bitmaps tab, change the bitmap of the action to icrespan.png.
9. Click on Document types.
10. Click Toolbars in the tree:
11. Select one of the commands in the document-specific toolbar (MyCommands).
12. Add a new action to the toolbar.
13. Change the category to Project.
14. Change the created action to the ColorChooser action.
15. Save the document.
The event must now be caught at the document level. To do this, the document interface is modified as follows:
IlvDvBeginInterface(BitmapDocument)
Action(ColorChooser, colorChooser)
IlvDvEndInterface1(IlvDvDocument)
This means that the BitmapDocument::colorChooser method will be called when the ColorChooser action is triggered. Here is the code of the BitmapDocument::colorChooser method:
void
BitmapDocument::colorChooser()
{
IlvColorSelector dialog(getDisplay());
IlvColor* color = dialog.get(IlTrue);
if (color) {
IlvPalette* palette = getPalette();
setPalette(getDisplay()->getPalette(palette->getBackground(),
color,
palette->getPattern(),
palette->getColorPattern(),
palette->getFont(),
palette->getLineStyle(),
palette->getLineWidth(),
palette->getFillStyle(),
palette->getArcMode(),
palette->getFillRule()));
}
}
The method displays a color selector and then changes the document palette by calling the BitmapDocument::setPalette method.
The Bitmap Editor application at the end of Step 3 is shown in figure 1.3:
Figure 1.3    The Bitmap Editor Application After Step 3

Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.