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 //
25 // constants, enums and typedefs
26 //
27 
28 //
29 // static data member definitions
30 //
31 
32 //
33 // constructors and destructor
34 //
35 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify):
36  m_context(iContext),
37  m_highlightContext(iHighlightContext),
38  m_font(nullptr),
39  m_isSelected(false),
40  m_justify(iJustify)
41 {
42  //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
43  m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
44 }
45 
46 // FWTextTableCellRenderer::FWTextTableCellRenderer(const FWTextTableCellRenderer& rhs)
47 // {
48 // // do actual copying here;
49 // }
50 
52 {
53 }
54 
55 //
56 // assignment operators
57 //
58 // const FWTextTableCellRenderer& FWTextTableCellRenderer::operator=(const FWTextTableCellRenderer& rhs)
59 // {
60 // //An exception safe implementation is
61 // FWTextTableCellRenderer temp(rhs);
62 // swap(rhs);
63 //
64 // return *this;
65 // }
66 
67 //
68 // member functions
69 //
70 void
71 FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
72 {
73 
74  if(m_isSelected) {
75  GContext_t c = m_highlightContext->GetGC();
76  gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
78  /*
79  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
80  gVirtualX->DrawLine(iID,m_context->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
81  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
82  gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);*
83  */
84  }
85 
86 
87 
88  FontMetrics_t metrics;
89  m_font->GetFontMetrics(&metrics);
90  int dX=0;
92  int w = width();
93  dX = iWidth-w;
94  }
96  int w = width();
97  dX = (iWidth-w)/2;
98 
99  }
100 
101  gVirtualX->DrawString(iID,m_context->GetGC(),iX+dX,iY+metrics.fAscent +1, m_data.c_str(),m_data.size());
102 }
103 
104 void
105 FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
106  m_data = iData;
107  m_isSelected=iIsSelected;
108 }
109 
110 void
111 FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
112  m_data = iData;
113  m_isSelected=iIsSelected;
114 }
115 
116 void
118 {
119  m_justify=iJustify;
120 }
121 
122 //
123 // const member functions
124 //
125 UInt_t
127 {
128  if(!m_data.empty()) {
129  return m_font->TextWidth(m_data.c_str(),-1);// + 2*kTextBuffer;
130  }
131  return 0;
132 }
133 UInt_t
135 {
136  return m_font->TextHeight(); //+ 2*kTextBuffer;
137 }
138 
139 const TGFont*
141 {
142  return m_font;
143 }
144 
145 //
146 // static member functions
147 //
148 const TGGC&
150 {
151  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
152  return *s_default;
153 }
154 
155 const TGGC &
157 {
158  // Return graphics context for highlighted frame background.
159  static const TGGC* s_default = nullptr;
160  if (!s_default) {
161  GCValues_t gval;
162  gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
163  gval.fForeground = gVirtualX->GetPixel(kGray);//gClient->GetResourcePool()->GetFrameHiliteColor();
164  gval.fBackground = gVirtualX->GetPixel(kWhite);//gClient->GetResourcePool()->GetFrameBgndColor();
165  gval.fFillStyle = kFillOpaqueStippled; // kFillTiled;
166  gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
167  gval.fGraphicsExposures = kFALSE;
168  s_default = gClient->GetGC(&gval, kTRUE);
169  }
170  return *s_default;
171 }
const double w
Definition: UKUtility.cc:23
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
FWTextTableCellRenderer(const TGGC *iContext=&(getDefaultGC()), const TGGC *iHighlightContext=&(getDefaultHighlightGC()), Justify iJustify=kJustifyLeft)
#define nullptr
static const TGGC & getDefaultGC()
const TGFont * font() const
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
static const TGGC & getDefaultHighlightGC()
void setData(const std::string &, bool isSelected)
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
static const int kTextBuffer