CMS 3D CMS Logo

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