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 
9 
10 #include "TGTextEntry.h"
11 #include "TGPicture.h"
12 #include "TSystem.h"
13 #include "TGClient.h"
14 
16 {
17 protected:
18  const static int s_iconOffset = 2;
19 
20 public:
21 
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(0),
31  {}
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
45  const TGPicture* closedImage()
46  {
47  static const TGPicture* s_picture=gClient->GetPicture(coreIcondir()+"arrow-black-right.png");
48  return s_picture;
49  }
50 
51  static
52  const TGPicture* openedImage()
53  {
54  static const TGPicture* s_picture=gClient->GetPicture(coreIcondir()+"arrow-black-down.png");
55  return s_picture;
56  }
57 
58  static
59  int iconWidth()
60  {
61  return openedImage()->GetWidth() + s_iconOffset;
62  }
63 
64  virtual void setIndentation(int indentation = 0) { m_indentation = indentation; }
65  virtual void setCellEditor(TGTextEntry *editor) { m_editor = editor; }
66  virtual void showEditor(bool value) { m_showEditor = value; }
67 
68  void setIsParent(bool value) {m_isParent = value; }
69  void setIsOpen(bool value) {m_isOpen = value; }
70 
71  virtual UInt_t width() const
72  {
74  if (m_isParent) w += iconWidth();
75  return w;
76  }
77 
78  virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
79  {
80  if (m_showEditor && m_editor)
81  {
82  // printf("renderer draw editor %d %d %d %d \n", iX, iY, m_editor->GetWidth(), m_editor->GetHeight());
83 
84  // fill to cover buffer offset
85  static TGGC editGC(FWTextTableCellRenderer::getDefaultGC());
86  editGC.SetForeground(m_editor->GetBackground());
87  gVirtualX->FillRectangle(iID, editGC(), iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
89 
90  if ( iY > -2)
91  {
92  // redraw editor
93  if (!m_editor->IsMapped())
94  {
95  m_editor->MapWindow();
96  m_editor->SetFocus();
97  }
98  m_editor->MoveResize(iX , iY, m_editor->GetWidth(), m_editor->GetHeight());
99  m_editor->SetCursorPosition( data().size());
100  gClient->NeedRedraw(m_editor);
101 
102  return;
103  }
104  else
105  {
106  // hide editor if selected entry scrolled away
107  if (m_editor->IsMapped()) m_editor->UnmapWindow();
108  }
109  }
110 
111  if (selected())
112  {
113  GContext_t c = highlightContext()->GetGC();
114  gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
116  }
117  int xOffset = 0;
118  if(m_isParent) {
119  if(m_isOpen) {
120  openedImage()->Draw(iID,graphicsContext()->GetGC(),m_indentation+iX,iY +2);
121  xOffset += openedImage()->GetWidth() + s_iconOffset;
122  } else {
123  closedImage()->Draw(iID,graphicsContext()->GetGC(),m_indentation+iX,iY +2);
124  xOffset += closedImage()->GetWidth() + s_iconOffset;
125  }
126  }
127 
128  FontMetrics_t metrics;
129  font()->GetFontMetrics(&metrics);
130 
131 
132  gVirtualX->DrawString(iID, graphicsContext()->GetGC(),
133  iX+m_indentation+xOffset, iY+metrics.fAscent,
134  data().c_str(),data().size());
135  }
136 private:
138  TGTextEntry *m_editor;
141  bool m_isOpen;
142  const TGGC* m_editContext;
143 };
144 
145 #endif
virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
const TGGC * highlightContext() const
int path() const
Definition: HLTadd.h:3
static const TString & coreIcondir()
static const TGGC & getDefaultGC()
const TGFont * font() const
static const TGPicture * closedImage()
static const TGPicture * openedImage()
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()
unsigned int UInt_t
Definition: FUTypes.h:12
tuple editor
Definition: idDealer.py:73
FWTextTreeCellRenderer(const TGGC *iContext=&(getDefaultGC()), const TGGC *iHighlightContext=&(getDefaultHighlightGC()), Justify iJustify=kJustifyLeft)
static const int kTextBuffer
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)