CMS 3D CMS Logo

FWTextTreeCellRenderer.h
Go to the documentation of this file.
1 #ifndef Fireworks_TableWidget_FWTextTreeCellRenderer_h
2 #define Fireworks_TableWidget_FWTextTreeCellRenderer_h
3 
4 #include <cassert>
5 #include <iostream>
6 
10 
11 #include "TGTextEntry.h"
12 #include "TGPicture.h"
13 #include "TSystem.h"
14 #include "TGClient.h"
15 #include "TVirtualX.h"
16 
18 protected:
19  const static int s_iconOffset = 2;
20 
21 public:
22  FWTextTreeCellRenderer(const TGGC* iContext = &(getDefaultGC()),
23  const TGGC* iHighlightContext = &(getDefaultHighlightGC()),
24  Justify iJustify = kJustifyLeft)
25  : FWTextTableCellRenderer(iContext, iHighlightContext, iJustify),
26  m_indentation(0),
27  m_editor(nullptr),
30  m_isOpen(false),
31  m_blackIcon(true) {}
32 
33  // Where to find the icons
34  static const TString& coreIcondir() {
35  static TString path = Form("%s/src/Fireworks/Core/icons/", gSystem->Getenv("CMSSW_BASE"));
36  if (gSystem->AccessPathName(path.Data())) { // cannot find directory
37  assert(gSystem->Getenv("CMSSW_RELEASE_BASE"));
38  path = Form("%s/src/Fireworks/Core/icons/", gSystem->Getenv("CMSSW_RELEASE_BASE"));
39  }
40 
41  return path;
42  }
43 
44  static const TGPicture* closedImage(bool isBlack = true) {
45  static const TGPicture* s_picture_white = gClient->GetPicture(coreIcondir() + "arrow-white-right-blackbg.png");
46  static const TGPicture* s_picture_black = gClient->GetPicture(coreIcondir() + "arrow-black-right.png");
47 
48  return isBlack ? s_picture_black : s_picture_white;
49  }
50 
51  static const TGPicture* openedImage(bool isBlack = true) {
52  static const TGPicture* s_picture_white = gClient->GetPicture(coreIcondir() + "arrow-white-down-blackbg.png");
53  static const TGPicture* s_picture_black = gClient->GetPicture(coreIcondir() + "arrow-black-down.png");
54 
55  return isBlack ? s_picture_black : s_picture_white;
56  }
57 
58  static int iconWidth() { return openedImage(true)->GetWidth() + s_iconOffset; }
59 
60  virtual void setIndentation(int indentation = 0) { m_indentation = indentation; }
61  virtual void setCellEditor(TGTextEntry* editor) { m_editor = editor; }
62  virtual void showEditor(bool value) { m_showEditor = value; }
63 
64  void setIsParent(bool value) { m_isParent = value; }
65  void setIsOpen(bool value) { m_isOpen = value; }
66  void setBlackIcon(bool value) { m_blackIcon = value; }
67 
68  UInt_t width() const override {
70  if (m_isParent)
71  w += iconWidth();
72  return w;
73  }
74 
75  void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override {
76  if (m_showEditor && m_editor) {
77  // printf("renderer draw editor %d %d %d %d \n", iX, iY, m_editor->GetWidth(), m_editor->GetHeight());
78 
79  // fill to cover buffer offset
80  static TGGC editGC(FWTextTableCellRenderer::getDefaultGC());
81  editGC.SetForeground(m_editor->GetBackground());
82  gVirtualX->FillRectangle(iID,
83  editGC(),
86  iWidth + 2 * FWTabularWidget::kTextBuffer,
87  iHeight + 2 * FWTabularWidget::kTextBuffer);
88 
89  if (iY > -2) {
90  // redraw editor
91  if (!m_editor->IsMapped()) {
92  m_editor->MapWindow();
93  m_editor->SetFocus();
94  }
95  m_editor->MoveResize(iX, iY, m_editor->GetWidth(), m_editor->GetHeight());
96  m_editor->SetCursorPosition(data().size());
97  gClient->NeedRedraw(m_editor);
98 
99  return;
100  } else {
101  // hide editor if selected entry scrolled away
102  if (m_editor->IsMapped())
103  m_editor->UnmapWindow();
104  }
105  }
106 
107  if (selected()) {
108  GContext_t c = highlightContext()->GetGC();
109  gVirtualX->FillRectangle(iID,
110  c,
113  iWidth + 2 * FWTabularWidget::kTextBuffer,
114  iHeight + 2 * FWTabularWidget::kTextBuffer);
115  }
116  int xOffset = 0;
117  if (m_isParent) {
118  const TGPicture* img = m_isOpen ? openedImage(m_blackIcon) : closedImage(m_blackIcon);
119  img->Draw(iID, graphicsContext()->GetGC(), m_indentation + iX, iY + 2);
120  xOffset += img->GetWidth() + s_iconOffset;
121  }
122 
123  FontMetrics_t metrics;
124  font()->GetFontMetrics(&metrics);
125 
126  gVirtualX->DrawString(iID,
127  graphicsContext()->GetGC(),
128  iX + m_indentation + xOffset,
129  iY + metrics.fAscent,
130  data().c_str(),
131  data().size());
132  }
133 
134 private:
136  TGTextEntry* m_editor;
139  bool m_isOpen;
141 };
142 
143 #endif
FWTextTreeCellRenderer::openedImage
static const TGPicture * openedImage(bool isBlack=true)
Definition: FWTextTreeCellRenderer.h:51
funct::false
false
Definition: Factorize.h:29
FWTextTableCellRenderer.h
FWTextTreeCellRenderer::FWTextTreeCellRenderer
FWTextTreeCellRenderer(const TGGC *iContext=&(getDefaultGC()), const TGGC *iHighlightContext=&(getDefaultHighlightGC()), Justify iJustify=kJustifyLeft)
Definition: FWTextTreeCellRenderer.h:22
FWTextTreeCellRenderer::s_iconOffset
const static int s_iconOffset
Definition: FWTextTreeCellRenderer.h:19
FWTextTableCellRenderer::Justify
Justify
Definition: FWTextTableCellRenderer.h:37
FWTextTableCellRenderer::graphicsContext
const TGGC * graphicsContext() const
Definition: FWTextTableCellRenderer.h:45
FWTextTreeCellRenderer
Definition: FWTextTreeCellRenderer.h:17
cms::cuda::assert
assert(be >=bs)
FWTextTreeCellRenderer::m_blackIcon
bool m_blackIcon
Definition: FWTextTreeCellRenderer.h:140
FWTextTableCellRenderer
Definition: FWTextTableCellRenderer.h:32
FWTextTreeCellRenderer::showEditor
virtual void showEditor(bool value)
Definition: FWTextTreeCellRenderer.h:62
FWTextTableCellRenderer::kJustifyLeft
Definition: FWTextTableCellRenderer.h:37
FWTabularWidget::kTextBuffer
static const int kTextBuffer
Definition: FWTabularWidget.h:35
FWTextTableCellRenderer::getDefaultHighlightGC
static const TGGC & getDefaultHighlightGC()
Definition: FWTextTableCellRenderer.cc:133
FWTextTableCellRenderer::width
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
Definition: FWTextTableCellRenderer.cc:113
FWTextTreeCellRenderer::iconWidth
static int iconWidth()
Definition: FWTextTreeCellRenderer.h:58
FWTextTreeCellRenderer::closedImage
static const TGPicture * closedImage(bool isBlack=true)
Definition: FWTextTreeCellRenderer.h:44
w
const double w
Definition: UKUtility.cc:23
FWTextTableCellRenderer::selected
bool selected()
Definition: FWTextTableCellRenderer.h:60
FWTextTreeCellRenderer::m_editor
TGTextEntry * m_editor
Definition: FWTextTreeCellRenderer.h:136
FWTextTableCellRenderer::highlightContext
const TGGC * highlightContext() const
Definition: FWTextTableCellRenderer.h:46
FWTextTreeCellRenderer::m_isParent
bool m_isParent
Definition: FWTextTreeCellRenderer.h:138
FWTextTreeCellRenderer::m_isOpen
bool m_isOpen
Definition: FWTextTreeCellRenderer.h:139
funct::true
true
Definition: Factorize.h:173
FWTabularWidget.h
FWTextTableCellRenderer::data
const std::string & data()
Definition: FWTextTableCellRenderer.h:56
FWTextTableCellRenderer::getDefaultGC
static const TGGC & getDefaultGC()
Definition: FWTextTableCellRenderer.cc:128
FWTextTreeCellRenderer::coreIcondir
static const TString & coreIcondir()
Definition: FWTextTreeCellRenderer.h:34
phase1PixelTopology::xOffset
constexpr int16_t xOffset
Definition: phase1PixelTopology.h:18
value
Definition: value.py:1
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
FWTextTableCellRenderer::font
const TGFont * font() const
Definition: FWTextTableCellRenderer.cc:123
FWTextTreeCellRenderer::setBlackIcon
void setBlackIcon(bool value)
Definition: FWTextTreeCellRenderer.h:66
GlobalContexts.h
relativeConstraints.value
value
Definition: relativeConstraints.py:53
printContent_cfi.indentation
indentation
Definition: printContent_cfi.py:10
FWTextTreeCellRenderer::setCellEditor
virtual void setCellEditor(TGTextEntry *editor)
Definition: FWTextTreeCellRenderer.h:61
FWTextTreeCellRenderer::setIsOpen
void setIsOpen(bool value)
Definition: FWTextTreeCellRenderer.h:65
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
FWTextTreeCellRenderer::m_indentation
int m_indentation
Definition: FWTextTreeCellRenderer.h:135
FWTextTreeCellRenderer::m_showEditor
bool m_showEditor
Definition: FWTextTreeCellRenderer.h:137
FWTextTreeCellRenderer::setIsParent
void setIsParent(bool value)
Definition: FWTextTreeCellRenderer.h:64
FWTextTreeCellRenderer::draw
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
Definition: FWTextTreeCellRenderer.h:75
FWTextTreeCellRenderer::width
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
Definition: FWTextTreeCellRenderer.h:68
FWTextTreeCellRenderer::setIndentation
virtual void setIndentation(int indentation=0)
Definition: FWTextTreeCellRenderer.h:60
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443