Go to the documentation of this file.00001 #ifndef Fireworks_TableWidget_FWTextTreeCellRenderer_h
00002 #define Fireworks_TableWidget_FWTextTreeCellRenderer_h
00003
00004 #include <cassert>
00005
00006 #include "Fireworks/TableWidget/interface/FWTextTableCellRenderer.h"
00007 #include "Fireworks/TableWidget/interface/GlobalContexts.h"
00008 #include "Fireworks/TableWidget/src/FWTabularWidget.h"
00009
00010 #include "TGTextEntry.h"
00011 #include "TGPicture.h"
00012 #include "TSystem.h"
00013 #include "TGClient.h"
00014
00015 class FWTextTreeCellRenderer : public FWTextTableCellRenderer
00016 {
00017 protected:
00018 const static int s_iconOffset = 2;
00019
00020 public:
00021
00022 FWTextTreeCellRenderer(const TGGC* iContext = &(getDefaultGC()),
00023 const TGGC* iHighlightContext = &(getDefaultHighlightGC()),
00024 Justify iJustify = kJustifyLeft)
00025 : FWTextTableCellRenderer(iContext, iHighlightContext, iJustify),
00026 m_indentation(0),
00027 m_editor(0),
00028 m_showEditor(false),
00029 m_isParent(false),
00030 m_isOpen(false)
00031 {}
00032
00033
00034 static const TString& coreIcondir() {
00035 static TString path = Form("%s/src/Fireworks/Core/icons/",gSystem->Getenv("CMSSW_BASE"));
00036 if ( gSystem->AccessPathName(path.Data()) ){
00037 assert(gSystem->Getenv("CMSSW_RELEASE_BASE"));
00038 path = Form("%s/src/Fireworks/Core/icons/",gSystem->Getenv("CMSSW_RELEASE_BASE"));
00039 }
00040
00041 return path;
00042 }
00043
00044 static
00045 const TGPicture* closedImage()
00046 {
00047 static const TGPicture* s_picture=gClient->GetPicture(coreIcondir()+"arrow-black-right.png");
00048 return s_picture;
00049 }
00050
00051 static
00052 const TGPicture* openedImage()
00053 {
00054 static const TGPicture* s_picture=gClient->GetPicture(coreIcondir()+"arrow-black-down.png");
00055 return s_picture;
00056 }
00057
00058 static
00059 int iconWidth()
00060 {
00061 return openedImage()->GetWidth() + s_iconOffset;
00062 }
00063
00064 virtual void setIndentation(int indentation = 0) { m_indentation = indentation; }
00065 virtual void setCellEditor(TGTextEntry *editor) { m_editor = editor; }
00066 virtual void showEditor(bool value) { m_showEditor = value; }
00067
00068 void setIsParent(bool value) {m_isParent = value; }
00069 void setIsOpen(bool value) {m_isOpen = value; }
00070
00071 virtual UInt_t width() const
00072 {
00073 int w = FWTextTableCellRenderer::width() + 15 + m_indentation;
00074 if (m_isParent) w += iconWidth();
00075 return w;
00076 }
00077
00078 virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00079 {
00080 if (m_showEditor && m_editor)
00081 {
00082
00083
00084
00085 static TGGC editGC(FWTextTableCellRenderer::getDefaultGC());
00086 editGC.SetForeground(m_editor->GetBackground());
00087 gVirtualX->FillRectangle(iID, editGC(), iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00088 iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00089
00090 if ( iY > -2)
00091 {
00092
00093 if (!m_editor->IsMapped())
00094 {
00095 m_editor->MapWindow();
00096 m_editor->SetFocus();
00097 }
00098 m_editor->MoveResize(iX , iY, m_editor->GetWidth(), m_editor->GetHeight());
00099 m_editor->SetCursorPosition( data().size());
00100 gClient->NeedRedraw(m_editor);
00101
00102 return;
00103 }
00104 else
00105 {
00106
00107 if (m_editor->IsMapped()) m_editor->UnmapWindow();
00108 }
00109 }
00110
00111 if (selected())
00112 {
00113 GContext_t c = highlightContext()->GetGC();
00114 gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00115 iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00116 }
00117 int xOffset = 0;
00118 if(m_isParent) {
00119 if(m_isOpen) {
00120 openedImage()->Draw(iID,graphicsContext()->GetGC(),m_indentation+iX,iY +2);
00121 xOffset += openedImage()->GetWidth() + s_iconOffset;
00122 } else {
00123 closedImage()->Draw(iID,graphicsContext()->GetGC(),m_indentation+iX,iY +2);
00124 xOffset += closedImage()->GetWidth() + s_iconOffset;
00125 }
00126 }
00127
00128 FontMetrics_t metrics;
00129 font()->GetFontMetrics(&metrics);
00130
00131
00132 gVirtualX->DrawString(iID, graphicsContext()->GetGC(),
00133 iX+m_indentation+xOffset, iY+metrics.fAscent,
00134 data().c_str(),data().size());
00135 }
00136 private:
00137 int m_indentation;
00138 TGTextEntry *m_editor;
00139 bool m_showEditor;
00140 bool m_isParent;
00141 bool m_isOpen;
00142 const TGGC* m_editContext;
00143 };
00144
00145 #endif