themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_own_colormap.cxx
blob3a7668858bfe8e471e86f887403a53ab4f411938
1 //
2 // "$Id: Fl_own_colormap.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Private colormap support for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 // Using the default system colormap can be a bad idea on PseudoColor
29 // visuals, since typically every application uses the default colormap and
30 // you can run out of colormap entries easily.
32 // The solution is to always create a new colormap on PseudoColor displays
33 // and copy the first 16 colors from the default colormap so that we won't
34 // get huge color changes when switching windows.
36 #include <config.h>
37 #include <FL/Fl.H>
38 #include <FL/x.H>
40 /** \fn Fl::own_colormap()
41 Makes FLTK use its own colormap. This may make FLTK display better
42 and will reduce conflicts with other programs that want lots of colors.
43 However the colors may flash as you move the cursor between windows.
45 <P>This does nothing if the current visual is not colormapped.
47 #ifdef WIN32
48 // There is probably something relevant to do on MSWindows 8-bit displays
49 // but I don't know what it is
51 void Fl::own_colormap() {}
53 #elif defined(__APPLE__)
54 // MacOS X always provides a TrueColor interface...
56 void Fl::own_colormap() {}
57 #else
58 // X version
60 void Fl::own_colormap() {
61 fl_open_display();
62 #if USE_COLORMAP
63 switch (fl_visual->c_class) {
64 case GrayScale :
65 case PseudoColor :
66 case DirectColor :
67 break;
68 default:
69 return; // don't do anything for non-colormapped visuals
71 int i;
72 XColor colors[16];
73 // Get the first 16 colors from the default colormap...
74 for (i = 0; i < 16; i ++) colors[i].pixel = i;
75 XQueryColors(fl_display, fl_colormap, colors, 16);
76 // Create a new colormap...
77 fl_colormap = XCreateColormap(fl_display,
78 RootWindow(fl_display,fl_screen),
79 fl_visual->visual, AllocNone);
80 // Copy those first 16 colors to our own colormap:
81 for (i = 0; i < 16; i ++)
82 XAllocColor(fl_display, fl_colormap, colors + i);
83 #endif
86 #endif
89 // End of "$Id: Fl_own_colormap.cxx 7903 2010-11-28 21:06:39Z matt $".