CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Fireworks/TableWidget/interface/FWTextTreeCellRenderer.h

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