CMS 3D CMS Logo

FWFramedTextTableCellRenderer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: TableWidget
4 // Class : FWFramedTextTableCellRenderer
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
21 
22 //
23 // constants, enums and typedefs
24 //
25 
26 //
27 // static data member definitions
28 //
29 
30 //
31 // constructors and destructor
32 //
34  const TGGC* iFillContext,
35  Justify iJustify)
36  : m_context(iTextContext), m_frameContext(iFillContext), m_font(nullptr), m_justify(iJustify) {
37  //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
38  m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
39 }
40 
41 // FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const FWFramedTextTableCellRenderer& rhs)
42 // {
43 // // do actual copying here;
44 // }
45 
47 
48 //
49 // assignment operators
50 //
51 // const FWFramedTextTableCellRenderer& FWFramedTextTableCellRenderer::operator=(const FWFramedTextTableCellRenderer& rhs)
52 // {
53 // //An exception safe implementation is
54 // FWFramedTextTableCellRenderer temp(rhs);
55 // swap(rhs);
56 //
57 // return *this;
58 // }
59 
60 //
61 // member functions
62 //
63 void FWFramedTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
64  // GContext_t c = m_frameContext->GetGC();
65 
66  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX - 1, iY + iHeight);
67  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX + iWidth, iY - 1, iX + iWidth, iY + iHeight);
68  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX + iWidth, iY - 1);
69  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY + iHeight, iX + iWidth, iY + iHeight);
70 
71  FontMetrics_t metrics;
72  m_font->GetFontMetrics(&metrics);
73  int dX = 2;
74  if (m_justify == kJustifyRight) {
75  int w = width();
76  dX = iWidth - w;
77  }
78  if (m_justify == kJustifyCenter) {
79  int w = width();
80  dX = (iWidth - w) / 2;
81  }
82 
83  gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent, m_data.c_str(), m_data.size());
84 }
85 
87 
89 
90 //
91 // const member functions
92 //
94  if (!m_data.empty()) {
95  return m_font->TextWidth(m_data.c_str(), -1) + 3;
96  }
97  return 0;
98 }
99 UInt_t FWFramedTextTableCellRenderer::height() const { return m_font->TextHeight(); }
100 
101 const TGFont* FWFramedTextTableCellRenderer::font() const { return m_font; }
102 
103 //
104 // static member functions
105 //
107  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
108  return *s_default;
109 }
110 
112  // Return graphics context for highlighted frame background.
113  static const TGGC* s_default = nullptr;
114  if (!s_default) {
115  GCValues_t gval;
116  gval.fMask = kGCForeground | kGCBackground | kGCTile | kGCFillStyle | kGCGraphicsExposures;
117  gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
118  gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
119  gval.fFillStyle = kFillTiled;
120  gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
121  gval.fGraphicsExposures = kFALSE;
122  s_default = gClient->GetGC(&gval, kTRUE);
123  }
124  return *s_default;
125 }
const double w
Definition: UKUtility.cc:23
#define nullptr
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
UInt_t height() const override
returns the minimum height of the cell to which the renderer is representing
FWFramedTextTableCellRenderer(const TGGC *iTextContext=&(getDefaultGC()), const TGGC *iFillContext=&(getFillGC()), Justify iJustify=kJustifyLeft)