This example will take you throught the steps of creating a custom palette. The palette sample code and project files can be found in the Samples\NewPalette folder.
The palette in this project is a simple floating palette version of the Colorer sample plug-in. The palette has two controls, a list box that allows the user to choose a color and a button for applying that color to the currently selected items.
The NewPalette plug-in project has been based on the PageMaker class library framework (as all of the plug-ins have.) An empty framework has been provided in the PCLFrame plug-in project.
These steps outline how the NewPalette.add plug-in was created. In the following sections we will cover each of these in detail. The code snippets are taken directly from the NewPalette sample - which you should refer to for more detail.
CIPMWinStyle
interface
Plug-in Palettes
menu
The NewPalette project was created using the FramePlugin project, which is an empty plug-in. Once a copy of the project was made, we changed all of the "FramePlugin" names and references to "NewPalette" (including the class name in Main.cpp, NewPalette.cpp, and NewPalette.h.
For more information on the requirements of an Adobe PageMaker plug-in project, see the notes for the MacOS and for Windows.
The Colorer palette is not going appear in the Plug-ins menu (under Utilities), instead it will appear in the Plug-in Palettes menu (found in the Windows menu.) The plug-in won't initially be invoked by the user, and so, to make sure that we get a chance to add our palette, we register the plug-in to receive event notification.
In the ADNI resource, we set the property for the plug-in to be registered
for events. This means that the PageMaker application will, during start-up,
call the plug-in with the kPMRegister
opCode.
In the NewPalette.cpp
file we have the implementation of the
DoRegister
method, which is where we handle the kPMRegister
opCode
.
PageMaker allows the plug-ins to register during start-up, but does so
before parts of the rest of the application have actually been initialized,
so we cannot use any of the Commands or Queries, and other than adding our
own interfaces, or registering for event notification, using the component
interfaces can bring some unpredictable results. So, in the DoRegister
method for our NewPalette project, we register for the application startup
event.
void NewPalette::DoRegister() { // This is where you register your plug-in to receive event notification, // DoRegister is also the first opportunity to add interfaces to PageMaker. CIBasic *basic = NULL; gInterfaceMgr->AcquirePMInterface( (unsigned long)PMIID_BASIC, (void **)&basic ); if ( basic == NULL ) throw CQ_FAILURE; // Generic failure. basic->RegisterPMEvent( (PMEventID) PMEVT_APP_STARTUP_AFTER ); gInterfaceMgr->ReleasePMInterface( basic ); }
Note: We could use the NewPalette::BuildMessage function (inherited from PPluginCall) to give a specific error rather than just throwing a generic error.
We've registered the plug-in to receive the PMEVT_APP_STARTUP_AFTER
event, and when the event happens, we will create the window. When creating
a custom window within PageMaker you will use two interfaces, the CIPMWinStyle
interface and the CIPMWindow
interface. CIPMWindow
is the interface that you use to manage and manipulate the window, while
CIPMWinStyle
is used to set the window properties when the
window is created. CIPMWindow
, you will use as an interface
to a single window. Managing multiple windows is accomplished by acquiring
the interface multiple times (each time you call AcquirePMInterface
a new CIPMWindow
object is instantiated.) When ReleasePMInterface
is called with a pointer to the CIPMWindow
interface, the associated
window is destroyed - so you will want to wait until you are finished with
the window, and, if applicable have removed it from the Plug-in Palettes
menu. CIPMWinStyle,
on the otherhand, is used during the creation
of a window as a template, and has no other tie to a specific window, so
the interface can be released after the window has been created, or used
in the creation of more windows.