fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_visual.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_visual.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Visual support for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 // Set the default visual according to passed switches:
00029 
00030 #include <config.h>
00031 #include <FL/Fl.H>
00032 #include <FL/x.H>
00033 
00068 #ifdef WIN32
00069 int Fl::visual(int flags) {
00070   fl_GetDC(0);
00071   if (flags & FL_DOUBLE) return 0;
00072   if (!(flags & FL_INDEX) &&
00073     GetDeviceCaps(fl_gc,BITSPIXEL) <= 8) return 0;
00074   if ((flags & FL_RGB8) && GetDeviceCaps(fl_gc,BITSPIXEL)<24) return 0;
00075   return 1;
00076 }
00077 #elif defined(__APPLE__)
00078 
00079 // \todo Mac : need to implement Visual flags
00080 int Fl::visual(int flags) {
00081   (void)flags;
00082   return 1;
00083 }
00084 
00085 #else
00086 
00087 #if USE_XDBE
00088 #include <X11/extensions/Xdbe.h>
00089 #endif
00090 
00091 static int test_visual(XVisualInfo& v, int flags) {
00092   if (v.screen != fl_screen) return 0;
00093 #if USE_COLORMAP
00094   if (!(flags & FL_INDEX)) {
00095     if (v.c_class != StaticColor && v.c_class != TrueColor) return 0;
00096     if (v.depth <= 8) return 0; // fltk will work better in colormap mode
00097   }
00098   if (flags & FL_RGB8) {
00099     if (v.depth < 24) return 0;
00100   }
00101   // for now, fltk does not like colormaps of more than 8 bits:
00102   if ((v.c_class&1) && v.depth > 8) return 0;
00103 #else
00104   // simpler if we can't use colormapped visuals at all:
00105   if (v.c_class != StaticColor && v.c_class != TrueColor) return 0;
00106 #endif
00107 #if USE_XDBE
00108   if (flags & FL_DOUBLE) {
00109     static XdbeScreenVisualInfo *xdbejunk;
00110     if (!xdbejunk) {
00111       int event_base, error_base;
00112       if (!XdbeQueryExtension(fl_display, &event_base, &error_base)) return 0;
00113       Drawable root = RootWindow(fl_display,fl_screen);
00114       int numscreens = 1;
00115       xdbejunk = XdbeGetVisualInfo(fl_display,&root,&numscreens);
00116       if (!xdbejunk) return 0;
00117     }
00118     for (int j = 0; ; j++) {
00119       if (j >= xdbejunk->count) return 0;
00120       if (xdbejunk->visinfo[j].visual == v.visualid) break;
00121     }
00122   }
00123 #endif
00124   return 1;
00125 }
00126 
00127 int Fl::visual(int flags) {
00128 #if USE_XDBE == 0
00129   if (flags & FL_DOUBLE) return 0;
00130 #endif
00131   fl_open_display();
00132   // always use default if possible:
00133   if (test_visual(*fl_visual, flags)) return 1;
00134   // get all the visuals:
00135   XVisualInfo vTemplate;
00136   int num;
00137   XVisualInfo *visualList = XGetVisualInfo(fl_display, 0, &vTemplate, &num);
00138   // find all matches, use the one with greatest depth:
00139   XVisualInfo *found = 0;
00140   for (int i=0; i<num; i++) if (test_visual(visualList[i], flags)) {
00141     if (!found || found->depth < visualList[i].depth)
00142       found = &visualList[i];
00143   }
00144   if (!found) {XFree((void*)visualList); return 0;}
00145   fl_visual = found;
00146   fl_colormap = XCreateColormap(fl_display, RootWindow(fl_display,fl_screen),
00147                                 fl_visual->visual, AllocNone);
00148   return 1;
00149 }
00150 
00151 #endif
00152 
00153 //
00154 // End of "$Id: Fl_visual.cxx 7903 2010-11-28 21:06:39Z matt $".
00155 //