Download Making Your First InDesign Plug-in
Transcript
InDesign Plug-in Cookbook 1
#10045
/* InitializeFields
*/
void WFPDialogController::InitializeFields()
{
CDialogController::InitializeFields();
}
// Put code to initialize widget values here.
We will add some code to initialize the DropDownListWidget.
By calling the CDialogController::QueryIfNilElseAddRef() method, we will obtain a pointer to the
IPanelControlData interface. This method takes an IPanelControlData interface pointer as a parameter, but if that pointer is nil, it returns the IPanelControlData interface of the same boss class,
and if the pointer is not nil, it increments the refCount to that pointer and returns it. Add the following include file at the top of WFPDialogController.cpp:
#include "IPanelControlData.h"
Next, insert the following code right after where CDialogController::InitializeFields() is called.
do {
// Get current panel control data.
InterfacePtr<IPanelControlData> pPanelData( QueryIfNilElseAddRef(nil) );
if( pPanelData == nil )
{
ASSERT_FAIL("WFPDialogController::InitializeFields: PanelControlData is nil!");
break;
}
If the pPanelData interface pointer is valid, we will call the IPanelControlData::FindWidget() in
the IPanelControlData interface to obtain an IControlView interface pointer. This method takes
a widget ID as a parameter, and returns the corresponding IControlView interface pointer. (Note:
IControlView is the interface for CControlView. Do you remember seeing CControlView somewhere before? That's right, we saw it while climbing up the hierarchy of widget type definitions!)
Insert the following code:
if( pPanelData != nil){
// Find dropdown list menu control view from panel data.
IControlView* pDropDownListControlView =
pPanelData->FindWidget( kWFPDropDownListWidgetID );
if( pDropDownListControlView == nil )
{
// Is the widget on the dialog?
ASSERT_FAIL("WFPDialogController::InitializeFields: DDListCtrlView is nil!");
break;
}
Using the obtained IControlView interface pointer, we will obtain the IDropDownListController
interface pointer, which exists in the same boss class, kDropDownListWidgetBoss. The
kDropDownListWidgetBoss is responsible for controlling the DropDownListWidget (as defined in
the resource definitions). However, to use the IDropDownListController interface, we must add
the following include statement at the top of WFPDialogController.cpp:
#include "IDropDownListController.h"
Then add the following code right after the call to pPanelData->FindWidget(...):
Making Your First InDesign Plug-In
51