Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:53

0001 // -*- C++ -*-
0002 //
0003 // Package:     TableWidget
0004 // Class  :     FWTextTableCellRenderer
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/FWTextTableCellRenderer.h"
0021 #include "Fireworks/TableWidget/interface/FWTabularWidget.h"
0022 
0023 //
0024 // constants, enums and typedefs
0025 //
0026 
0027 //
0028 // static data member definitions
0029 //
0030 
0031 //
0032 // constructors and destructor
0033 //
0034 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify)
0035     : m_context(iContext),
0036       m_highlightContext(iHighlightContext),
0037       m_font(nullptr),
0038       m_isSelected(false),
0039       m_justify(iJustify) {
0040   //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
0041   m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
0042 }
0043 
0044 // FWTextTableCellRenderer::FWTextTableCellRenderer(const FWTextTableCellRenderer& rhs)
0045 // {
0046 //    // do actual copying here;
0047 // }
0048 
0049 FWTextTableCellRenderer::~FWTextTableCellRenderer() {}
0050 
0051 //
0052 // assignment operators
0053 //
0054 // const FWTextTableCellRenderer& FWTextTableCellRenderer::operator=(const FWTextTableCellRenderer& rhs)
0055 // {
0056 //   //An exception safe implementation is
0057 //   FWTextTableCellRenderer temp(rhs);
0058 //   swap(rhs);
0059 //
0060 //   return *this;
0061 // }
0062 
0063 //
0064 // member functions
0065 //
0066 void FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
0067   if (m_isSelected) {
0068     GContext_t c = m_highlightContext->GetGC();
0069     gVirtualX->FillRectangle(iID,
0070                              c,
0071                              iX - FWTabularWidget::kTextBuffer,
0072                              iY - FWTabularWidget::kTextBuffer,
0073                              iWidth + 2 * FWTabularWidget::kTextBuffer,
0074                              iHeight + 2 * FWTabularWidget::kTextBuffer);
0075     /*
0076         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
0077         gVirtualX->DrawLine(iID,m_context->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
0078         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
0079         gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);*
0080       */
0081   }
0082 
0083   FontMetrics_t metrics;
0084   m_font->GetFontMetrics(&metrics);
0085   int dX = 0;
0086   if (m_justify == kJustifyRight) {
0087     int w = width();
0088     dX = iWidth - w;
0089   }
0090   if (m_justify == kJustifyCenter) {
0091     int w = width();
0092     dX = (iWidth - w) / 2;
0093   }
0094 
0095   gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent + 1, m_data.c_str(), m_data.size());
0096 }
0097 
0098 void FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
0099   m_data = iData;
0100   m_isSelected = iIsSelected;
0101 }
0102 
0103 void FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
0104   m_data = iData;
0105   m_isSelected = iIsSelected;
0106 }
0107 
0108 void FWTextTableCellRenderer::setJustify(Justify iJustify) { m_justify = iJustify; }
0109 
0110 //
0111 // const member functions
0112 //
0113 UInt_t FWTextTableCellRenderer::width() const {
0114   if (!m_data.empty()) {
0115     return m_font->TextWidth(m_data.c_str(), -1);  // + 2*kTextBuffer;
0116   }
0117   return 0;
0118 }
0119 UInt_t FWTextTableCellRenderer::height() const {
0120   return m_font->TextHeight();  //+  2*kTextBuffer;
0121 }
0122 
0123 const TGFont* FWTextTableCellRenderer::font() const { return m_font; }
0124 
0125 //
0126 // static member functions
0127 //
0128 const TGGC& FWTextTableCellRenderer::getDefaultGC() {
0129   static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
0130   return *s_default;
0131 }
0132 
0133 const TGGC& FWTextTableCellRenderer::getDefaultHighlightGC() {
0134   // Return graphics context for highlighted frame background.
0135   static const TGGC* s_default = nullptr;
0136   if (!s_default) {
0137     GCValues_t gval;
0138     gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
0139     gval.fForeground = gVirtualX->GetPixel(kGray);   //gClient->GetResourcePool()->GetFrameHiliteColor();
0140     gval.fBackground = gVirtualX->GetPixel(kWhite);  //gClient->GetResourcePool()->GetFrameBgndColor();
0141     gval.fFillStyle = kFillOpaqueStippled;           // kFillTiled;
0142     gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
0143     gval.fGraphicsExposures = kFALSE;
0144     s_default = gClient->GetGC(&gval, kTRUE);
0145   }
0146   return *s_default;
0147 }