CMS 3D CMS Logo

FWTextTableCellRenderer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TableWidget
4 // Class : FWTextTableCellRenderer
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Mon Feb 2 16:43:54 EST 2009
11 //
12 
13 // system include files
14 #include <iostream>
15 #include "TGClient.h"
16 #include "TGFont.h"
17 #include "TVirtualX.h"
18 
19 // user include files
22 
23 //
24 // constants, enums and typedefs
25 //
26 
27 //
28 // static data member definitions
29 //
30 
31 //
32 // constructors and destructor
33 //
34 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify)
35  : m_context(iContext),
36  m_highlightContext(iHighlightContext),
37  m_font(nullptr),
38  m_isSelected(false),
39  m_justify(iJustify) {
40  //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
41  m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
42 }
43 
44 // FWTextTableCellRenderer::FWTextTableCellRenderer(const FWTextTableCellRenderer& rhs)
45 // {
46 // // do actual copying here;
47 // }
48 
50 
51 //
52 // assignment operators
53 //
54 // const FWTextTableCellRenderer& FWTextTableCellRenderer::operator=(const FWTextTableCellRenderer& rhs)
55 // {
56 // //An exception safe implementation is
57 // FWTextTableCellRenderer temp(rhs);
58 // swap(rhs);
59 //
60 // return *this;
61 // }
62 
63 //
64 // member functions
65 //
66 void FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
67  if (m_isSelected) {
68  GContext_t c = m_highlightContext->GetGC();
69  gVirtualX->FillRectangle(iID,
70  c,
73  iWidth + 2 * FWTabularWidget::kTextBuffer,
74  iHeight + 2 * FWTabularWidget::kTextBuffer);
75  /*
76  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
77  gVirtualX->DrawLine(iID,m_context->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
78  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
79  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);*
80  */
81  }
82 
83  FontMetrics_t metrics;
84  m_font->GetFontMetrics(&metrics);
85  int dX = 0;
86  if (m_justify == kJustifyRight) {
87  int w = width();
88  dX = iWidth - w;
89  }
90  if (m_justify == kJustifyCenter) {
91  int w = width();
92  dX = (iWidth - w) / 2;
93  }
94 
95  gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent + 1, m_data.c_str(), m_data.size());
96 }
97 
98 void FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
99  m_data = iData;
100  m_isSelected = iIsSelected;
101 }
102 
103 void FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
104  m_data = iData;
105  m_isSelected = iIsSelected;
106 }
107 
109 
110 //
111 // const member functions
112 //
114  if (!m_data.empty()) {
115  return m_font->TextWidth(m_data.c_str(), -1); // + 2*kTextBuffer;
116  }
117  return 0;
118 }
120  return m_font->TextHeight(); //+ 2*kTextBuffer;
121 }
122 
123 const TGFont* FWTextTableCellRenderer::font() const { return m_font; }
124 
125 //
126 // static member functions
127 //
129  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
130  return *s_default;
131 }
132 
134  // Return graphics context for highlighted frame background.
135  static const TGGC* s_default = nullptr;
136  if (!s_default) {
137  GCValues_t gval;
138  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
139  gval.fForeground = gVirtualX->GetPixel(kGray); //gClient->GetResourcePool()->GetFrameHiliteColor();
140  gval.fBackground = gVirtualX->GetPixel(kWhite); //gClient->GetResourcePool()->GetFrameBgndColor();
141  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
142  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
143  gval.fGraphicsExposures = kFALSE;
144  s_default = gClient->GetGC(&gval, kTRUE);
145  }
146  return *s_default;
147 }
FWTextTableCellRenderer::draw
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
Definition: FWTextTableCellRenderer.cc:66
FWTextTableCellRenderer::FWTextTableCellRenderer
FWTextTableCellRenderer(const TGGC *iContext=&(getDefaultGC()), const TGGC *iHighlightContext=&(getDefaultHighlightGC()), Justify iJustify=kJustifyLeft)
Definition: FWTextTableCellRenderer.cc:34
funct::false
false
Definition: Factorize.h:29
FWTextTableCellRenderer.h
FWTextTableCellRenderer::kJustifyCenter
Definition: FWTextTableCellRenderer.h:37
FWTextTableCellRenderer::Justify
Justify
Definition: FWTextTableCellRenderer.h:37
FWTabularWidget::kTextBuffer
static const int kTextBuffer
Definition: FWTabularWidget.h:35
FWTextTableCellRenderer::kJustifyRight
Definition: FWTextTableCellRenderer.h:37
FWTextTableCellRenderer::getDefaultHighlightGC
static const TGGC & getDefaultHighlightGC()
Definition: FWTextTableCellRenderer.cc:133
FWTextTableCellRenderer::m_highlightContext
const TGGC * m_highlightContext
Definition: FWTextTableCellRenderer.h:71
FWTextTableCellRenderer::width
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
Definition: FWTextTableCellRenderer.cc:113
FWTextTableCellRenderer::height
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
Definition: FWTextTableCellRenderer.cc:119
w
const double w
Definition: UKUtility.cc:23
FWTextTableCellRenderer::m_font
TGFont * m_font
Definition: FWTextTableCellRenderer.h:72
FWTabularWidget.h
FWTextTableCellRenderer::getDefaultGC
static const TGGC & getDefaultGC()
Definition: FWTextTableCellRenderer.cc:128
FWTextTableCellRenderer::m_isSelected
bool m_isSelected
Definition: FWTextTableCellRenderer.h:74
FWTextTableCellRenderer::font
const TGFont * font() const
Definition: FWTextTableCellRenderer.cc:123
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWTextTableCellRenderer::setJustify
void setJustify(Justify)
Definition: FWTextTableCellRenderer.cc:108
FWTextTableCellRenderer::setData
void setData(const std::string &, bool isSelected)
Definition: FWTextTableCellRenderer.cc:98
FWTextTableCellRenderer::m_context
const TGGC * m_context
Definition: FWTextTableCellRenderer.h:70
FWTextTableCellRenderer::~FWTextTableCellRenderer
~FWTextTableCellRenderer() override
Definition: FWTextTableCellRenderer.cc:49
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
FWTextTableCellRenderer::m_data
std::string m_data
Definition: FWTextTableCellRenderer.h:73
FWTextTableCellRenderer::m_justify
Justify m_justify
Definition: FWTextTableCellRenderer.h:75