Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Advanced Color Imaging on the Mac OS /
Chapter 1 - Palette Manager / Using the Palette Manager


Designating a Default Palette for Your Application

You can define a default palette for the Operating System to use whenever your application creates a color window or displays a dialog box without an associated palette. Defining a default palette is especially useful in the following cases:

If your application does not define a default palette, the system will use its own default palette to define the color environment for the old-style dialogs and alerts. If the system palette does not contain appropriate colors, unsuitable colors will be displayed.

There are two ways that you can define a default palette for your application: by creating a palette resource that the Palette Manager can then use to create the default palette or by using the SetPalette or NSetPalette function to assign a default palette.

You set a palette resource (a resource of type 'pltt') as your application's default by assigning it a resource ID of 0. The Palette Manager loads the application default palette and stores it in a low-memory global variable called AppPalette. When your application opens a new color window, the Palette Manager automatically looks for a palette resource from which to create a palette to assign to the window. It looks in the resource fork for a palette resource with the same ID as that of the window. If you haven't created a specific resource for the window and if you haven't assigned a palette to the window with the SetPalette or NSetPalette function, the Palette Manager creates a palette from the default application resource and assigns this palette to the window. If the Palette Manager cannot find the default application resource, it uses the system default palette resource ('pltt' ID = 0 in the System file). If the System file has no default palette, the Palette Manager creates a special two-entry palette (black and white) and assigns this palette to the window.

IMPORTANT
If you are running an application from a development environment, such as MPW, you could have trouble automatically assigning the default application palette. The Palette Manager loads the default palette when a call is made to InitPalettes (generally, InitWindows makes this call). Then InitPalettes uses Get1Resource rather than GetResource to load the 'pltt' resource with ID equal to 0. The problem is that Get1Resource assumes your application is at the top of the resource chain and retrieves the resource only if it is in the first file. However, because the development environment, not your application, is at the top of the resource chain, the Palette Manager will be unable to load the default application resource. In this case, it loads the default system resource, if it exists, or the special two-entry palette instead.
The other way to assign a default palette is to create a palette and then assign it with the SetPalette or NSetPalette function as follows:

defPalette = NewPalette (numcolor, mycolors, pmAnimated, 0x1500);
SetPalette ((WindowPtr) -1, defPalette, TRUE);
This method of assigning a default palette is useful if, for example, you give the user an opportunity in a menu or preference file to change the palette to another setting.

Once your application has set its color environment by calling InitWindows (or InitPalettes in unusual instances when there are no menus), you can find the default palette for your application by using the GetPalette function:

myPaletteHndl = GetPalette ((WindowPtr) -1); 

Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 NOV 1996