TGResourcePool.cxx

Go to the documentation of this file.
00001 // @(#)root/gui:$Id: TGResourcePool.cxx 33926 2010-06-15 15:35:40Z bellenot $
00002 // Author: Fons Rademakers   19/5/2003
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2003, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 /**************************************************************************
00012 
00013     This source is based on Xclass95, a Win95-looking GUI toolkit.
00014     Copyright (C) 1996, 1997 David Barth, Ricky Ralston, Hector Peraza.
00015 
00016     Xclass95 is free software; you can redistribute it and/or
00017     modify it under the terms of the GNU Library General Public
00018     License as published by the Free Software Foundation; either
00019     version 2 of the License, or (at your option) any later version.
00020 
00021 **************************************************************************/
00022 
00023 
00024 //////////////////////////////////////////////////////////////////////////
00025 //                                                                      //
00026 // TGResourcePool                                                       //
00027 //                                                                      //
00028 // This class implements a pool for the default GUI resource set,       //
00029 // like GC's, colors, fonts, etc..                                      //
00030 //                                                                      //
00031 //////////////////////////////////////////////////////////////////////////
00032 
00033 #include "RConfigure.h"
00034 
00035 #include "TGResourcePool.h"
00036 #include "TGClient.h"
00037 #include "TGWindow.h"
00038 #include "TROOT.h"
00039 #include "TSystem.h"
00040 #include "TEnv.h"
00041 #include "TVirtualX.h"
00042 #include "TGGC.h"
00043 #include "TGPicture.h"
00044 #include "TGFont.h"
00045 #include "TGMimeTypes.h"
00046 
00047 
00048 const int gray_width  = 8;
00049 const int gray_height = 8;
00050 static unsigned char gray_bits[] = {
00051    0x55, 0xaa, 0x55, 0xaa,
00052    0x55, 0xaa, 0x55, 0xaa
00053 };
00054 
00055 
00056 ClassImp(TGResourcePool)
00057 
00058 //______________________________________________________________________________
00059 TGResourcePool::TGResourcePool(TGClient *client)
00060 {
00061    // Create the global GUI resource pool manager.
00062 
00063    fClient = client;
00064    fDefaultColormap = gVirtualX->GetColormap();
00065 
00066    // Get GUI defaults from [system].rootrc
00067    TString default_font;
00068    TString menu_font;
00069    TString menu_hi_font;
00070    TString doc_fixed_font;
00071    TString doc_prop_font;
00072    TString icon_font;
00073    TString status_font;
00074    TString backcolor;
00075    TString forecolor;
00076    TString selbackcolor;
00077    TString selforecolor;
00078    TString docbackcolor;
00079    TString docforecolor;
00080    TString tipbackcolor;
00081    TString tipforecolor;
00082    TString framebgpixmap;
00083    TString docbgpixmap;
00084    TString icon_path;
00085    TString mime_file;
00086    TString line;
00087 
00088    default_font   = gEnv->GetValue("Gui.DefaultFont",  "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
00089    menu_font      = gEnv->GetValue("Gui.MenuFont",     "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
00090    menu_hi_font   = gEnv->GetValue("Gui.MenuHiFont",   "-*-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
00091    doc_fixed_font = gEnv->GetValue("Gui.DocFixedFont", "-*-courier-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
00092    doc_prop_font  = gEnv->GetValue("Gui.DocPropFont",  "-*-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
00093    icon_font      = gEnv->GetValue("Gui.IconFont",     "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
00094    status_font    = gEnv->GetValue("Gui.StatusFont",   "-*-helvetica-medium-r-*-*-10-*-*-*-*-*-iso8859-1");
00095    backcolor      = gEnv->GetValue("Gui.BackgroundColor",         "#c0c0c0");
00096    forecolor      = gEnv->GetValue("Gui.ForegroundColor",         "black");
00097    selbackcolor   = gEnv->GetValue("Gui.SelectBackgroundColor",   "#000080");
00098    selforecolor   = gEnv->GetValue("Gui.SelectForegroundColor",   "white");
00099    docbackcolor   = gEnv->GetValue("Gui.DocumentBackgroundColor", "white");
00100    docforecolor   = gEnv->GetValue("Gui.DocumentForegroundColor", "black");
00101    tipbackcolor   = gEnv->GetValue("Gui.TooltipBackgroundColor",  "LightYellow");
00102    tipforecolor   = gEnv->GetValue("Gui.TooltipForegroundColor",  "black");
00103    framebgpixmap  = gEnv->GetValue("Gui.FrameBackgroundPixmap", "");
00104    docbgpixmap    = gEnv->GetValue("Gui.DocumentBackgroundPixmap", "");
00105 
00106 #ifndef R__WIN32
00107 #ifndef R__VMS
00108 # ifdef ROOTICONPATH
00109    icon_path = TString::Format("%s/icons:%s:.:", gSystem->HomeDirectory(),
00110                                ROOTICONPATH);
00111 #  ifdef EXTRAICONPATH
00112    icon_path += gEnv->GetValue("Gui.IconPath", EXTRAICONPATH);
00113 #  else
00114    icon_path += gEnv->GetValue("Gui.IconPath", "");
00115 #  endif
00116 # else
00117    icon_path = TString::Format("%s/icons:%s/icons:.:", gSystem->HomeDirectory(),
00118                                                        gSystem->Getenv("ROOTSYS"));
00119    icon_path += gEnv->GetValue("Gui.IconPath", "");
00120 # endif
00121    line = TString::Format("%s/.root.mimes", gSystem->HomeDirectory());
00122 #else
00123    line = TString::Format("[%s.ICONS]", gSystem->Getenv("ROOTSYS"));
00124    icon_path = gEnv->GetValue("Gui.IconPath", line.Data());
00125    line = TString::Format("%sroot.mimes", gSystem->HomeDirectory());
00126 #endif
00127 
00128    mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
00129    char *mf = gSystem->ExpandPathName(mime_file.Data());
00130    if (mf) {
00131       mime_file = mf;
00132       delete [] mf;
00133    }
00134    if (gSystem->AccessPathName(mime_file.Data(), kReadPermission))
00135 #ifdef R__VMS
00136       mime_file = TString::Format("[%s.ETC]root.mimes",gSystem->Getenv("ROOTSYS"));
00137 #else
00138 # ifdef ROOTETCDIR
00139       mime_file = TString::Format("%s/root.mimes", ROOTETCDIR);
00140 # else
00141       mime_file = TString::Format("%s/etc/root.mimes", gSystem->Getenv("ROOTSYS"));
00142 # endif
00143 #endif
00144 #else // R__WIN32
00145    icon_path = TString::Format("%s\\icons:.:\\", gSystem->Getenv("ROOTSYS"));
00146    icon_path += gEnv->GetValue("Gui.IconPath", "");
00147    line = TString::Format("%s\\root.mimes", gSystem->HomeDirectory());
00148    mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
00149    if (gSystem->AccessPathName(mime_file.Data(), kReadPermission))
00150       mime_file = TString::Format("%s\\etc\\root.mimes", gSystem->Getenv("ROOTSYS"));
00151 #endif
00152 
00153    // Setup colors...
00154    fClient->GetColorByName("white", fWhite);  // white and black always exist
00155    fClient->GetColorByName("black", fBlack);
00156    if (!fClient->GetColorByName(backcolor.Data(), fBackColor))
00157       fBackColor = fWhite;
00158    if (!fClient->GetColorByName(forecolor.Data(), fForeColor))
00159       fForeColor = fBlack;
00160    fHilite = fClient->GetHilite(fBackColor);
00161    fShadow = fClient->GetShadow(fBackColor);
00162    if (!fClient->GetColorByName(selbackcolor.Data(), fSelBackColor))
00163       fSelBackColor = fBlack;
00164    if (!fClient->GetColorByName(selforecolor.Data(), fSelForeColor))
00165       fSelForeColor = fWhite;
00166    if (!fClient->GetColorByName(docbackcolor.Data(), fDocBackColor))
00167       fDocBackColor = fWhite;
00168    if (!fClient->GetColorByName(docforecolor.Data(), fDocForeColor))
00169       fDocForeColor = fBlack;
00170    if (!fClient->GetColorByName(tipbackcolor.Data(), fTipBackColor))
00171       fTipBackColor = fWhite;
00172    if (!fClient->GetColorByName(tipforecolor.Data(), fTipForeColor))
00173       fTipForeColor = fBlack;
00174 
00175    // Setup checkered pix/bit-maps...
00176    fCheckered = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
00177                                         (const char *)gray_bits,
00178                                         gray_width, gray_height,
00179                                         fBackColor, fWhite /*fHilite*/,
00180                                         gVirtualX->GetDepth());
00181    fCheckeredBitmap = gVirtualX->CreatePixmap(fClient->GetDefaultRoot()->GetId(),
00182                                               (const char *)gray_bits,
00183                                               gray_width, gray_height,
00184                                               1, 0, 1);
00185 
00186    // Create picture pool, GC pool, font pool, mime type list, etc.
00187 
00188    // Create picture pool and pre-load some pictures...
00189    fPicturePool = new TGPicturePool(fClient, icon_path.Data());
00190 
00191    fDefaultBackPicture    = 0;
00192    fDefaultDocBackPicture = 0;
00193    if (!framebgpixmap.IsNull())
00194       fDefaultBackPicture = fPicturePool->GetPicture(framebgpixmap.Data());
00195    if (!docbgpixmap.IsNull())
00196       fDefaultDocBackPicture = fPicturePool->GetPicture(docbgpixmap.Data());
00197 
00198    // Create font pool and pre-load some fonts...
00199    fFontPool = new TGFontPool(fClient);
00200    fDefaultFont  = fFontPool->GetFont(default_font.Data());
00201    fMenuFont     = fFontPool->GetFont(menu_font.Data());
00202    fMenuHiFont   = fFontPool->GetFont(menu_hi_font.Data());
00203    fDocFixedFont = fFontPool->GetFont(doc_fixed_font.Data());
00204    fDocPropFont  = fFontPool->GetFont(doc_prop_font.Data());
00205    fIconFont     = fFontPool->GetFont(icon_font.Data());
00206    fStatusFont   = fFontPool->GetFont(status_font.Data());
00207 
00208    // Create GC pool and pre-load some GCs...
00209    fGCPool = new TGGCPool(fClient);
00210 
00211    GCValues_t gval;
00212    gval.fMask = kGCForeground | kGCBackground | kGCFont |
00213                 kGCFillStyle  | kGCGraphicsExposures;
00214    gval.fGraphicsExposures = kFALSE;
00215    gval.fFillStyle  = kFillSolid;
00216    gval.fFont       = fDefaultFont->GetFontHandle();
00217    gval.fBackground = fBackColor;
00218    gval.fForeground = fBlack;
00219    fBlackGC = fGCPool->GetGC(&gval, kTRUE);
00220 
00221    gval.fForeground = fWhite;
00222    fWhiteGC = fGCPool->GetGC(&gval, kTRUE);
00223 
00224    gval.fForeground = fHilite;
00225    fHiliteGC = fGCPool->GetGC(&gval, kTRUE);
00226 
00227    gval.fForeground = fShadow;
00228    fShadowGC = fGCPool->GetGC(&gval, kTRUE);
00229 
00230    gval.fForeground = fBackColor;
00231    fBckgndGC = fGCPool->GetGC(&gval, kTRUE);
00232 
00233    gval.fForeground = fForeColor;
00234    fFrameGC = fGCPool->GetGC(&gval, kTRUE);
00235 
00236    gval.fForeground = fSelBackColor;
00237    fSelbgndGC = fGCPool->GetGC(&gval, kTRUE);
00238 
00239    gval.fForeground = fSelForeColor;
00240    gval.fBackground = fSelBackColor;
00241    fSelGC = fGCPool->GetGC(&gval, kTRUE);
00242 
00243    gval.fFont       = fDocPropFont->GetFontHandle();
00244    gval.fForeground = fDocForeColor;
00245    gval.fBackground = fDocBackColor;
00246    fDocGC = fGCPool->GetGC(&gval, kTRUE);
00247 
00248    gval.fForeground = fDocBackColor;
00249    fDocbgndGC = fGCPool->GetGC(&gval, kTRUE);
00250 
00251    gval.fFont       = fStatusFont->GetFontHandle();
00252    gval.fForeground = fTipForeColor;
00253    gval.fBackground = fTipBackColor;
00254    fTipGC = fGCPool->GetGC(&gval, kTRUE);
00255 
00256    gval.fMask = kGCForeground | kGCBackground | kGCFillStyle |
00257                 kGCLineWidth  | kGCSubwindowMode |
00258                 kGCGraphicsExposures | kGCStipple;
00259    gval.fForeground = fBlack;
00260    gval.fBackground = fSelBackColor;
00261    gval.fLineWidth  = 0;
00262    gval.fFillStyle  = kFillStippled;
00263    gval.fSubwindowMode = kIncludeInferiors;
00264    gval.fGraphicsExposures = kFALSE;
00265    gval.fStipple = fCheckeredBitmap;
00266    fFocusGC = fGCPool->GetGC(&gval, kTRUE);
00267 
00268    // Setup cursors...
00269    fDefaultCursor = kNone;
00270    fGrabCursor    = gVirtualX->CreateCursor(kArrowRight);
00271    fTextCursor    = gVirtualX->CreateCursor(kCaret);
00272    fWaitCursor    = gVirtualX->CreateCursor(kWatch);
00273 
00274    // Read in mime type...
00275    fMimeTypeList  = new TGMimeTypes(fClient, mime_file.Data());
00276 
00277    // Clipboard handle...
00278 #ifndef R__WIN32
00279    fClipboardAtom = gVirtualX->InternAtom("_ROOT_CLIPBOARD", kFALSE);
00280 #else
00281    fClipboardAtom = gVirtualX->InternAtom("CLIPBOARD", kFALSE);
00282 #endif
00283 }
00284 
00285 //______________________________________________________________________________
00286 TGResourcePool::~TGResourcePool()
00287 {
00288    // Cleanup the resource pool...
00289 
00290    delete fPicturePool;
00291    delete fFontPool;
00292    delete fGCPool;
00293    delete fMimeTypeList;
00294 
00295    gVirtualX->DeletePixmap(fCheckered);
00296    gVirtualX->DeletePixmap(fCheckeredBitmap);
00297 }

Generated on Tue Jul 5 14:22:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1