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