CMS 3D CMS Logo

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