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),
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
size
Write out results.
static const TGPicture * closedImage(bool isBlack=true)
const double w
Definition: UKUtility.cc:23
#define nullptr
const TGGC * highlightContext() const
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
static const TString & coreIcondir()
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
virtual void setCellEditor(TGTextEntry *editor)
static const TGGC & getDefaultHighlightGC()
Definition: value.py:1
const TGGC * graphicsContext() const
virtual void setIndentation(int indentation=0)
const std::string & data()
constexpr int16_t xOffset
static const TGPicture * openedImage(bool isBlack=true)
FWTextTreeCellRenderer(const TGGC *iContext=&(getDefaultGC()), const TGGC *iHighlightContext=&(getDefaultHighlightGC()), Justify iJustify=kJustifyLeft)
static const int kTextBuffer
virtual void showEditor(bool value)