CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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
static const TGPicture * closedImage(bool isBlack=true)
const edm::EventSetup & c
const double w
Definition: UKUtility.cc:23
const TGGC * highlightContext() const
assert(be >=bs)
void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) override
static const TString & coreIcondir()
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
static const TGGC & getDefaultGC()
const TGFont * font() const
virtual void setCellEditor(TGTextEntry *editor)
static const TGGC & getDefaultHighlightGC()
const TGGC * graphicsContext() const
UInt_t width() const override
returns the minimum width of the cell to which the renderer is representing
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
tuple size
Write out results.
virtual void showEditor(bool value)