Technote 1172Writing Plug-ins for Desktop Printer UtilityBy C. S. LinUpdated by Dave Polaschek Apple Worldwide Developer Technical Support |
CONTENTS
Limits and Assumptions |
Apple’s Desktop Printer Utility (DTPU) is an application used to create or configure various types of Desktop Printers (DTPs) supported by the LaserWriter 8 printer driver. The built-in DTP types currently provided by DTPU version 1.1 include AppleTalk (PAP) printer, LPR printer, infrared printer, Hold printer, PostScript translator, and Custom application translator. Third-party plug-in support was added in DTPU version 1.2. This document describes how to write plug-ins for DTPU version 1.2 and later. A DTPU plug-in is a mechanism for programmers to write shared libraries which can be recognized by DTPU and provide means to configure different types of desktop printers that are not built into DTPU. A good use of this is to provide user interface for configuring external hoses for LaserWriter 8. See Technote 1144: Writing Custom Hoses for LaserWriter 8 for information about writing LaserWriter 8 communication hoses. |
IntroductionA DTPU window has either one or two panes, depending on the type of the desktop printer it represents. The upper pane, which is common to all types of Desktop Printers, is used to select the PostScript™ Printer Description (PPD) file for the printer. The lower pane, if one exists, is used to configure properties or characteristics specific to that DTP. Examples of this are an AppleTalk address for an AppleTalk DTP (see Figure 2) and a domain name address for an LPR DTP. ![]() Figure 1 - Single pane DTPU window![]() Figure 2 - Double pane DTPU window for PAP DTPDevelopers who need to configure desktop printers with more information than just the basic PPD file configuration may want to consider writing a DTPU plug-in. A DTPU plug-in allows developers to customize the lower pane of their DTP window to a small extent, and to display a dialog window when the lower "Change" button is clicked (or when the lower icon is double-clicked). |
Plug-in RequirementsPlease read the related document Technote 1170: The Printing Plug-ins Manager for requirements of writing LaserWriter plug-ins. In order for shared library plug-ins to be recognized by DTPU, they have to be kept in the “Printing Plug-ins” folder within the Extension folder of the active System Folder.
The type in the
subtype: '=AS ' Developers attempting to write a DTPU plug-in will need the following files:
|
Interaction between DTPU and plug-insWhen the "New" menu item is selected in DTPU, the following dialog window is displayed for users to select the type of DTP to create: ![]() Figure 4 - DTP type selection dialogIf DTPU recognizes a plug-in in the "Printing Plug-ins" folder, it adds the plug-in’s type (item 1 in Figure 4) to the selection list and provides some explanation (item 2 in Figure 4) in the space below the list when the plug-in type is selected. DTPU asks each plug-in for this informational string. Once a plug-in DTP type is chosen, DTPU displays a DTP window similar to the one in Figure 5. The content of items 1-4 are controlled by the plug-ins. Again, DTPU obtains the text strings from plug-ins and displays them on behalf of the plug-ins. Item 2 is a 32 pixel x 32 pixel icon. Plug-ins can also provide an icon drawing routine which will be called by DTPU whenever it needs to draw the icon. More information about how a plug-in can control these items is provided in the PlugInDtpInfo Structure and DTP Window Display sections. ![]() Figure 5 - Example of a plug-in DTP windowWhen the lower change button (item 5 in Figure 5) is clicked, DTPU calls the plug-in to display a configuration dialog window. The window displayed by the included sample code is shown in Figure 6. This window is entirely owned by the plug-in. A plug-in can put any number of items of any type in this window and position the items wherever appropriate. User interaction directed to this dialog window should be handled by the plug-in. DTPU provides a callback routine to handle events that are not related to this dialog window. Plug-ins should use movable modal dialog windows for this purpose whenever possible. More information about how to control this window is given in the Configuration Dialog Window section. ![]() Figure 6 - Movable modal dialog controlled by plug-ins |
Plug-in Interface
The Plug-in interface is in C. Although DTPU is written in C++ using PowerPlant, plug-ins do not have to use C++ or PowerPlant. All routines provided by plug-ins should return a result of type
Plug-ins must provide the following routines and point each of their corresponding Open and CloseDtpuPluginOpen
All DTPU plug-ins must export a routine named |
OSStatus DtpuPluginOpen(PlugInDtpInfo *plugInDtpInfoP, void* inRefCon, Collection inCollection); |
If |
Note: |
Unless otherwise stated, the |
closeProc OSStatus closeProc(void *refcon); |
The field
DTPU calls this routine to give a plug-in a chance to release any system resources allocated in the DTP Window DisplayTo display the lower pane of the DTPU window on behalf of plug-ins, DTPU must call the following three routines: |
getIconTitle closeProc OSStatus getIconTitle(Str255 outIconTitle, void *refcon); |
The field
The plug-in should set the content of |
getUsageText OSStatus getUsageText(Str255 outUsageText, void *refcon); |
The field
The plug-in should set the content of |
drawIcon OSStatus drawIcon(Rect* inFrameP, Boolean inHilite, void* inRefCon); |
The field This is the plug-in’s optional routine to draw an icon representing the printer or its setting. Plug-ins that don’t want to draw their own icons should set this field to NULL, in which case a generic LaserWriter icon is displayed.
The icon is positioned as item 2 in Figure 5. Plug-ins can use Mac Toolbox routines such as
Copy&Paste + Drag&DropDTPU supports Copy & Paste and Drag & Drop between DTP documents. One can copy or drag the lower pane icon (item 2 in Figure 5) and paste or drop it into another DTP window provided the two DTP windows have compatible data types. This allows a user to copy the configuration information from one DTP to another, which can simplify the configuration process. Because DTPU does not know the meaning of a plug-in’s internal data, plug-ins have to provide the following six routines to help DTPU determine if the data can be used. |
clipboardOk OSStatus clipboardOk(Boolean* outAceptableP, void *refcon); |
The field clipboardOkProc in data structure
DTPU calls this routine to decide if the content in the clipboard is acceptable to a plug-in’s DTP. Plug-ins should use |
pasteClipboard OSStatus pasteClipboard(void *refcon); |
The field
DTPU calls this routine to paste the clipboard into a plug-in’s internal DTP data. The plug-in should use |
placeInClipboard OSStatus placeInClipboard(void *refcon); |
The field DTPU calls this routine to place a plug-in’s internal data in the clipboard. The plug-in should use
The field addDragDataProc in data structure PlugInDtpInfo should be set to the address of the plug-in’s addDragData routine.
DTPU calls this routine when the plug-in’s icon is being dragged. The plug-in should use
The field
DTPU calls this routine to decide if the content of a drag is acceptable to a plug-in’s DTP. Plug-ins should use
The field
DTPU calls this routine to drop data onto plug-in’s DTP. Plug-ins should use DTP SavingWhenever DTPU needs to save a DTP which has a custom plug-in type, it needs assistance from the following three routines provided by plug-ins:
The field
DTPU calls
For example, the domain name address required by an LPR hose at print time can be saved in extended
The field
DTPU calls
The field
DTPU calls Configuration Dialog Window
The field DTPU calls configure whenever the lower "Change…" button (item 5, Figure 5) is clicked or the lower icon (item 2, Figure 5) is double-clicked. In response to this user interaction, a plug-in should display a movable modal dialog window such as the one shown in Figure 6. The content of the dialog is decided by the plug-in.
A plug-in’s configure routine should call
DTPU handles command key-down events, and events not specifically for the plug-in’s window.
Upon entering this routine, the Edit menu is disabled. Plug-ins should enable/disable the Cut, Copy, and Paste menu items as desired if the dialog has editable text items. Plug-ins should keep this menu updated for the duration of the execution of this configure routine. The command key-down events for Edit, however, are handled by DTPU through the callback. The ![]() Figure 8 - Edit menu enabled by plug-inPlug-ins should not return control back to DTPU until the user either confirms or cancels the settings in the dialog window. A value of “0” for user confirmation or a value “1” for user cancellation should be returned as a result of this routine. Any other value causes an error. |
SummaryThis Technote explains how to add a plug-in (or plug-ins) to the system that will be used by Desktop Printer Utility. These plug-ins can configure desktop printers that use third-party custom hoses as described in Technote 1144: Writing Custom Hoses for LaserWriter 8. With the information contained in this Technote and the sample code which accompanies it, you should be able to extend Desktop Printer Utility and Desktop Printing in general. |
|
|
Thanks to Rich Blanchard, John Blanchard, Paul Danbold, David Gelphman, and Ingrid Kelly.