CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/Fireworks/TableWidget/src/FWTextTableCellRenderer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     TableWidget
00004 // Class  :     FWTextTableCellRenderer
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: FWTextTableCellRenderer.cc,v 1.5 2011/03/02 18:34:17 amraktad 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/FWTextTableCellRenderer.h"
00022 #include "Fireworks/TableWidget/src/FWTabularWidget.h"
00023 
00024 
00025 //
00026 // constants, enums and typedefs
00027 //
00028 
00029 //
00030 // static data member definitions
00031 //
00032 
00033 //
00034 // constructors and destructor
00035 //
00036 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify):
00037    m_context(iContext),
00038    m_highlightContext(iHighlightContext),
00039    m_font(0),
00040    m_isSelected(false),
00041    m_justify(iJustify)
00042 {
00043    //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
00044    m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
00045 }
00046 
00047 // FWTextTableCellRenderer::FWTextTableCellRenderer(const FWTextTableCellRenderer& rhs)
00048 // {
00049 //    // do actual copying here;
00050 // }
00051 
00052 FWTextTableCellRenderer::~FWTextTableCellRenderer()
00053 {
00054 }
00055 
00056 //
00057 // assignment operators
00058 //
00059 // const FWTextTableCellRenderer& FWTextTableCellRenderer::operator=(const FWTextTableCellRenderer& rhs)
00060 // {
00061 //   //An exception safe implementation is
00062 //   FWTextTableCellRenderer temp(rhs);
00063 //   swap(rhs);
00064 //
00065 //   return *this;
00066 // }
00067 
00068 //
00069 // member functions
00070 //
00071 void 
00072 FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00073 {
00074  
00075    if(m_isSelected) {
00076       GContext_t c = m_highlightContext->GetGC();
00077       gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00078                                iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00079       /*
00080         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
00081         gVirtualX->DrawLine(iID,m_context->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
00082         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
00083         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);*
00084       */
00085    }
00086 
00087 
00088 
00089    FontMetrics_t metrics;
00090    m_font->GetFontMetrics(&metrics);
00091    int dX=0;
00092    if(m_justify==kJustifyRight) {
00093       int w = width();
00094       dX = iWidth-w;
00095    }
00096    if(m_justify==kJustifyCenter) {
00097       int w = width();
00098       dX = (iWidth-w)/2;
00099 
00100    }
00101 
00102    gVirtualX->DrawString(iID,m_context->GetGC(),iX+dX,iY+metrics.fAscent +1, m_data.c_str(),m_data.size());
00103 }
00104 
00105 void
00106 FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
00107    m_data = iData;
00108    m_isSelected=iIsSelected;
00109 }
00110 
00111 void
00112 FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
00113    m_data = iData;
00114    m_isSelected=iIsSelected;
00115 }
00116 
00117 void 
00118 FWTextTableCellRenderer::setJustify(Justify iJustify)
00119 {
00120    m_justify=iJustify;
00121 }
00122 
00123 //
00124 // const member functions
00125 //
00126 UInt_t 
00127 FWTextTableCellRenderer::width() const
00128 {
00129    if(m_data.size()) {
00130       return m_font->TextWidth(m_data.c_str(),-1);// + 2*kTextBuffer;
00131    }
00132    return 0;
00133 }
00134 UInt_t 
00135 FWTextTableCellRenderer::height() const
00136 {
00137    return m_font->TextHeight(); //+  2*kTextBuffer;
00138 }
00139 
00140 const TGFont* 
00141 FWTextTableCellRenderer::font() const
00142 {
00143    return m_font;
00144 }
00145 
00146 //
00147 // static member functions
00148 //
00149 const TGGC&  
00150 FWTextTableCellRenderer::getDefaultGC()
00151 {
00152    static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
00153    return *s_default;
00154 }
00155 
00156 const TGGC &
00157 FWTextTableCellRenderer::getDefaultHighlightGC()
00158 {
00159    // Return graphics context for highlighted frame background.
00160    static const TGGC* s_default = 0;
00161    if (!s_default) {
00162       GCValues_t gval;
00163       gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle  | kGCGraphicsExposures;
00164       gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
00165       gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
00166       gval.fFillStyle  = kFillOpaqueStippled; // kFillTiled;
00167       gval.fStipple    = gClient->GetResourcePool()->GetCheckeredBitmap();
00168       gval.fGraphicsExposures = kFALSE;
00169       s_default = gClient->GetGC(&gval, kTRUE);
00170    }
00171    return *s_default;
00172 }