CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Fireworks/TableWidget/src/FWFramedTextTableCellRenderer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     TableWidget
00004 // Class  :     FWFramedTextTableCellRenderer
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Mon Feb  2 16:43:54 EST 2009
00011 // $Id: FWFramedTextTableCellRenderer.cc,v 1.3 2010/06/18 12:44:24 yana Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include "TGClient.h"
00017 #include "TGFont.h"
00018 #include "TVirtualX.h"
00019 
00020 // user include files
00021 #include "Fireworks/TableWidget/interface/FWFramedTextTableCellRenderer.h"
00022 
00023 
00024 //
00025 // constants, enums and typedefs
00026 //
00027 
00028 //
00029 // static data member definitions
00030 //
00031 
00032 //
00033 // constructors and destructor
00034 //
00035 FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const TGGC* iTextContext, const TGGC* iFillContext, Justify iJustify):
00036    m_context(iTextContext),
00037    m_frameContext(iFillContext),
00038    m_font(0),
00039    m_justify(iJustify)
00040 {
00041    //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
00042    m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
00043 }
00044 
00045 // FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const FWFramedTextTableCellRenderer& rhs)
00046 // {
00047 //    // do actual copying here;
00048 // }
00049 
00050 FWFramedTextTableCellRenderer::~FWFramedTextTableCellRenderer()
00051 {
00052 }
00053 
00054 //
00055 // assignment operators
00056 //
00057 // const FWFramedTextTableCellRenderer& FWFramedTextTableCellRenderer::operator=(const FWFramedTextTableCellRenderer& rhs)
00058 // {
00059 //   //An exception safe implementation is
00060 //   FWFramedTextTableCellRenderer temp(rhs);
00061 //   swap(rhs);
00062 //
00063 //   return *this;
00064 // }
00065 
00066 //
00067 // member functions
00068 //
00069 void 
00070 FWFramedTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00071 {
00072    // GContext_t c = m_frameContext->GetGC();
00073 
00074    gVirtualX->DrawLine(iID,m_frameContext->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
00075    gVirtualX->DrawLine(iID,m_frameContext->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
00076    gVirtualX->DrawLine(iID,m_frameContext->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
00077    gVirtualX->DrawLine(iID,m_frameContext->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);
00078 
00079    FontMetrics_t metrics;
00080    m_font->GetFontMetrics(&metrics);
00081    int dX=2;
00082    if(m_justify==kJustifyRight) {
00083       int w = width();
00084       dX = iWidth-w;
00085    }
00086    if(m_justify==kJustifyCenter) {
00087       int w = width();
00088       dX = (iWidth-w)/2;
00089 
00090    }
00091 
00092    gVirtualX->DrawString(iID,m_context->GetGC(),iX+dX,iY+metrics.fAscent, m_data.c_str(),m_data.size());
00093 }
00094 
00095 void
00096 FWFramedTextTableCellRenderer::setData(const std::string& iData) {
00097    m_data = iData;
00098 }
00099 
00100 void 
00101 FWFramedTextTableCellRenderer::setJustify(Justify iJustify)
00102 {
00103    m_justify=iJustify;
00104 }
00105 
00106 //
00107 // const member functions
00108 //
00109 UInt_t 
00110 FWFramedTextTableCellRenderer::width() const
00111 {
00112    if(m_data.size()) {
00113       return m_font->TextWidth(m_data.c_str(),-1)+3;
00114    }
00115    return 0;
00116 }
00117 UInt_t 
00118 FWFramedTextTableCellRenderer::height() const
00119 {
00120    return m_font->TextHeight();
00121 }
00122 
00123 const TGFont* 
00124 FWFramedTextTableCellRenderer::font() const
00125 {
00126    return m_font;
00127 }
00128 
00129 //
00130 // static member functions
00131 //
00132 const TGGC&  
00133 FWFramedTextTableCellRenderer::getDefaultGC()
00134 {
00135    static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
00136    return *s_default;
00137 }
00138 
00139 const TGGC &
00140 FWFramedTextTableCellRenderer::getFillGC()
00141 {
00142    // Return graphics context for highlighted frame background.
00143    static const TGGC* s_default = 0;
00144    if (!s_default) {
00145       GCValues_t gval;
00146       gval.fMask = kGCForeground | kGCBackground | kGCTile |
00147                    kGCFillStyle  | kGCGraphicsExposures;
00148       gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
00149       gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
00150       gval.fFillStyle  = kFillTiled;
00151       gval.fTile       = gClient->GetResourcePool()->GetCheckeredPixmap();
00152       gval.fGraphicsExposures = kFALSE;
00153       s_default = gClient->GetGC(&gval, kTRUE);
00154    }
00155    return *s_default;
00156 }