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