Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
// -*- C++ -*-
//
// Package:     TableWidget
// Class  :     FWFramedTextTableCellRenderer
//
// Implementation:
//     <Notes on implementation>
//
// Original Author:  Chris Jones
//         Created:  Mon Feb  2 16:43:54 EST 2009
//

// system include files
#include <iostream>
#include "TGClient.h"
#include "TGFont.h"
#include "TVirtualX.h"

// user include files
#include "Fireworks/TableWidget/interface/FWFramedTextTableCellRenderer.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const TGGC* iTextContext,
                                                             const TGGC* iFillContext,
                                                             Justify iJustify)
    : m_context(iTextContext), m_frameContext(iFillContext), m_font(nullptr), m_justify(iJustify) {
  //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
  m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
}

// FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const FWFramedTextTableCellRenderer& rhs)
// {
//    // do actual copying here;
// }

FWFramedTextTableCellRenderer::~FWFramedTextTableCellRenderer() {}

//
// assignment operators
//
// const FWFramedTextTableCellRenderer& FWFramedTextTableCellRenderer::operator=(const FWFramedTextTableCellRenderer& rhs)
// {
//   //An exception safe implementation is
//   FWFramedTextTableCellRenderer temp(rhs);
//   swap(rhs);
//
//   return *this;
// }

//
// member functions
//
void FWFramedTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
  // GContext_t c = m_frameContext->GetGC();

  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX - 1, iY + iHeight);
  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX + iWidth, iY - 1, iX + iWidth, iY + iHeight);
  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX + iWidth, iY - 1);
  gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY + iHeight, iX + iWidth, iY + iHeight);

  FontMetrics_t metrics;
  m_font->GetFontMetrics(&metrics);
  int dX = 2;
  if (m_justify == kJustifyRight) {
    int w = width();
    dX = iWidth - w;
  }
  if (m_justify == kJustifyCenter) {
    int w = width();
    dX = (iWidth - w) / 2;
  }

  gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent, m_data.c_str(), m_data.size());
}

void FWFramedTextTableCellRenderer::setData(const std::string& iData) { m_data = iData; }

void FWFramedTextTableCellRenderer::setJustify(Justify iJustify) { m_justify = iJustify; }

//
// const member functions
//
UInt_t FWFramedTextTableCellRenderer::width() const {
  if (!m_data.empty()) {
    return m_font->TextWidth(m_data.c_str(), -1) + 3;
  }
  return 0;
}
UInt_t FWFramedTextTableCellRenderer::height() const { return m_font->TextHeight(); }

const TGFont* FWFramedTextTableCellRenderer::font() const { return m_font; }

//
// static member functions
//
const TGGC& FWFramedTextTableCellRenderer::getDefaultGC() {
  static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
  return *s_default;
}

const TGGC& FWFramedTextTableCellRenderer::getFillGC() {
  // Return graphics context for highlighted frame background.
  static const TGGC* s_default = nullptr;
  if (!s_default) {
    GCValues_t gval;
    gval.fMask = kGCForeground | kGCBackground | kGCTile | kGCFillStyle | kGCGraphicsExposures;
    gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
    gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
    gval.fFillStyle = kFillTiled;
    gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
    gval.fGraphicsExposures = kFALSE;
    s_default = gClient->GetGC(&gval, kTRUE);
  }
  return *s_default;
}