Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "312) Why can't I install my own colormap using XInstallColormap?"
Next document is "314) How do I get correct shadow colors to match other color"

313) How do I install a private colormap?

[Last modified: Jan 96]

Answer:  Mark Buser (buser@tartan.com) writes:  If you find that your
XAllocNamedColor is failing or XpmCreatePixmapFromData is dieing from
XpmColorFaileds, you may have exhausted the number of colormap entries.  One
way to install a new colormap is the following:


    Toplevel = XtVaAppInitialize ( &app, ...
    ...
    dpy = XtDisplay (Toplevel);
    cmap = DefaultColormapOfScreen ( XtScreen( Toplevel) );
    ...
    /* Detect color errors due to colormap depletion */
    ...
    if (colors_depleted) {
      cmap = XCopyColormapAndFree ( dpy, cmap );
      ...

      /* Run through color allocation again to see if ok now */
      ...
    }

    /* Install colormap into toplevel widget.  This must be done
    ** before any child widgets are created.
    */
    XtVaSetValues ( Toplevel, XmNcolormap, cmap, NULL);

    /* Create any children of toplevel, they will inherit new colormap */
    ...


This is only one way to go, there are other possibilities, but this seems to
be the simplest.

Parent document is top of "Motif FAQ (Part 9 of 9)"
Previous document is "312) Why can't I install my own colormap using XInstallColormap?"
Next document is "314) How do I get correct shadow colors to match other color"