Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:33

0001 // -*- C++ -*-
0002 //
0003 // Package:     TableWidget
0004 // Class  :     FWFramedTextTableCellRenderer
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Mon Feb  2 16:43:54 EST 2009
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include "TGClient.h"
0016 #include "TGFont.h"
0017 #include "TVirtualX.h"
0018 
0019 // user include files
0020 #include "Fireworks/TableWidget/interface/FWFramedTextTableCellRenderer.h"
0021 
0022 //
0023 // constants, enums and typedefs
0024 //
0025 
0026 //
0027 // static data member definitions
0028 //
0029 
0030 //
0031 // constructors and destructor
0032 //
0033 FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const TGGC* iTextContext,
0034                                                              const TGGC* iFillContext,
0035                                                              Justify iJustify)
0036     : m_context(iTextContext), m_frameContext(iFillContext), m_font(nullptr), m_justify(iJustify) {
0037   //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
0038   m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
0039 }
0040 
0041 // FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const FWFramedTextTableCellRenderer& rhs)
0042 // {
0043 //    // do actual copying here;
0044 // }
0045 
0046 FWFramedTextTableCellRenderer::~FWFramedTextTableCellRenderer() {}
0047 
0048 //
0049 // assignment operators
0050 //
0051 // const FWFramedTextTableCellRenderer& FWFramedTextTableCellRenderer::operator=(const FWFramedTextTableCellRenderer& rhs)
0052 // {
0053 //   //An exception safe implementation is
0054 //   FWFramedTextTableCellRenderer temp(rhs);
0055 //   swap(rhs);
0056 //
0057 //   return *this;
0058 // }
0059 
0060 //
0061 // member functions
0062 //
0063 void FWFramedTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
0064   // GContext_t c = m_frameContext->GetGC();
0065 
0066   gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX - 1, iY + iHeight);
0067   gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX + iWidth, iY - 1, iX + iWidth, iY + iHeight);
0068   gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX + iWidth, iY - 1);
0069   gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY + iHeight, iX + iWidth, iY + iHeight);
0070 
0071   FontMetrics_t metrics;
0072   m_font->GetFontMetrics(&metrics);
0073   int dX = 2;
0074   if (m_justify == kJustifyRight) {
0075     int w = width();
0076     dX = iWidth - w;
0077   }
0078   if (m_justify == kJustifyCenter) {
0079     int w = width();
0080     dX = (iWidth - w) / 2;
0081   }
0082 
0083   gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent, m_data.c_str(), m_data.size());
0084 }
0085 
0086 void FWFramedTextTableCellRenderer::setData(const std::string& iData) { m_data = iData; }
0087 
0088 void FWFramedTextTableCellRenderer::setJustify(Justify iJustify) { m_justify = iJustify; }
0089 
0090 //
0091 // const member functions
0092 //
0093 UInt_t FWFramedTextTableCellRenderer::width() const {
0094   if (!m_data.empty()) {
0095     return m_font->TextWidth(m_data.c_str(), -1) + 3;
0096   }
0097   return 0;
0098 }
0099 UInt_t FWFramedTextTableCellRenderer::height() const { return m_font->TextHeight(); }
0100 
0101 const TGFont* FWFramedTextTableCellRenderer::font() const { return m_font; }
0102 
0103 //
0104 // static member functions
0105 //
0106 const TGGC& FWFramedTextTableCellRenderer::getDefaultGC() {
0107   static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
0108   return *s_default;
0109 }
0110 
0111 const TGGC& FWFramedTextTableCellRenderer::getFillGC() {
0112   // Return graphics context for highlighted frame background.
0113   static const TGGC* s_default = nullptr;
0114   if (!s_default) {
0115     GCValues_t gval;
0116     gval.fMask = kGCForeground | kGCBackground | kGCTile | kGCFillStyle | kGCGraphicsExposures;
0117     gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
0118     gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
0119     gval.fFillStyle = kFillTiled;
0120     gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
0121     gval.fGraphicsExposures = kFALSE;
0122     s_default = gClient->GetGC(&gval, kTRUE);
0123   }
0124   return *s_default;
0125 }