CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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    {}
00034 
00035    // Where to find the icons
00036    static const TString& coreIcondir() {
00037       static TString path = Form("%s/src/Fireworks/Core/icons/",gSystem->Getenv("CMSSW_BASE"));
00038       if ( gSystem->AccessPathName(path.Data()) ){ // cannot find directory
00039          assert(gSystem->Getenv("CMSSW_RELEASE_BASE"));
00040          path = Form("%s/src/Fireworks/Core/icons/",gSystem->Getenv("CMSSW_RELEASE_BASE"));
00041       }
00042 
00043       return path;
00044    }
00045 
00046    static
00047    const TGPicture* closedImage(bool isBlack = true)
00048    {
00049       static const TGPicture* s_picture_white = gClient->GetPicture(coreIcondir()+"arrow-white-right-blackbg.png");
00050       static const TGPicture* s_picture_black = gClient->GetPicture(coreIcondir()+"arrow-black-right.png");
00051 
00052       return isBlack ? s_picture_black : s_picture_white;
00053    }
00054 
00055    static
00056    const TGPicture* openedImage(bool isBlack = true)
00057    {
00058       static const TGPicture* s_picture_white = gClient->GetPicture(coreIcondir()+"arrow-white-down-blackbg.png");
00059       static const TGPicture* s_picture_black = gClient->GetPicture(coreIcondir()+"arrow-black-down.png");
00060 
00061       return isBlack ? s_picture_black : s_picture_white;
00062    }
00063 
00064 
00065    static
00066    int iconWidth()
00067    {
00068       return  openedImage(true)->GetWidth() + s_iconOffset;
00069    }
00070 
00071    virtual void setIndentation(int indentation = 0) { m_indentation = indentation; }
00072    virtual void setCellEditor(TGTextEntry *editor) { m_editor = editor; }
00073    virtual void showEditor(bool value) { m_showEditor = value; }
00074  
00075 
00076    void setIsParent(bool value) {m_isParent = value; }
00077    void setIsOpen(bool value) {m_isOpen = value; }
00078    void setBlackIcon(bool value) { m_blackIcon = value; }
00079 
00080    virtual UInt_t width() const
00081    {
00082       int w = FWTextTableCellRenderer::width() + 15 + m_indentation;
00083       if (m_isParent)   w += iconWidth();
00084       return w;
00085    }
00086 
00087    virtual void draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00088    {      
00089       if (m_showEditor && m_editor)
00090       {
00091          //  printf("renderer draw editor %d %d %d %d \n", iX, iY, m_editor->GetWidth(), m_editor->GetHeight());
00092 
00093          // fill to cover buffer offset
00094          static TGGC editGC(FWTextTableCellRenderer::getDefaultGC()); 
00095          editGC.SetForeground(m_editor->GetBackground());
00096          gVirtualX->FillRectangle(iID, editGC(), iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00097                                   iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00098 
00099          if ( iY > -2)
00100          {
00101             // redraw editor
00102             if (!m_editor->IsMapped())
00103             {
00104                m_editor->MapWindow();
00105                m_editor->SetFocus();
00106             }
00107             m_editor->MoveResize(iX , iY, m_editor->GetWidth(), m_editor->GetHeight());
00108             m_editor->SetCursorPosition( data().size());
00109             gClient->NeedRedraw(m_editor);
00110        
00111             return;
00112          }
00113          else
00114          {
00115             // hide editor if selected entry scrolled away
00116             if (m_editor->IsMapped()) m_editor->UnmapWindow();
00117          }
00118       }
00119 
00120       if (selected())
00121       {
00122          GContext_t c = highlightContext()->GetGC();
00123          gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00124                                   iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00125       } 
00126       int xOffset = 0;
00127       if(m_isParent) {
00128          const TGPicture* img = m_isOpen ?  openedImage(m_blackIcon) : closedImage(m_blackIcon);         
00129          img->Draw(iID,graphicsContext()->GetGC(),m_indentation+iX,iY +2);
00130          xOffset += img->GetWidth() + s_iconOffset;
00131       }
00132 
00133       FontMetrics_t metrics;
00134       font()->GetFontMetrics(&metrics);
00135 
00136 
00137       gVirtualX->DrawString(iID, graphicsContext()->GetGC(),
00138                             iX+m_indentation+xOffset, iY+metrics.fAscent, 
00139                             data().c_str(),data().size());
00140    }
00141 private:
00142    int            m_indentation;
00143    TGTextEntry    *m_editor;
00144    bool           m_showEditor;
00145    bool           m_isParent;
00146    bool           m_isOpen;
00147    bool           m_blackIcon;
00148    const TGGC*    m_editContext;
00149 };
00150 
00151 #endif