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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
// -*- C++ -*-
//
// Package:     TableWidget
// Class  :     FWTextTableCellRenderer
//
// 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/FWTextTableCellRenderer.h"
#include "Fireworks/TableWidget/interface/FWTabularWidget.h"

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify)
    : m_context(iContext),
      m_highlightContext(iHighlightContext),
      m_font(nullptr),
      m_isSelected(false),
      m_justify(iJustify) {
  //TGGC* tggc= gClient->GetGCPool()->GetGC(iContext);
  m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
}

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

FWTextTableCellRenderer::~FWTextTableCellRenderer() {}

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

//
// member functions
//
void FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
  if (m_isSelected) {
    GContext_t c = m_highlightContext->GetGC();
    gVirtualX->FillRectangle(iID,
                             c,
                             iX - FWTabularWidget::kTextBuffer,
                             iY - FWTabularWidget::kTextBuffer,
                             iWidth + 2 * FWTabularWidget::kTextBuffer,
                             iHeight + 2 * FWTabularWidget::kTextBuffer);
    /*
        gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX-1,iY+iHeight);
        gVirtualX->DrawLine(iID,m_context->GetGC(),iX+iWidth,iY-1,iX+iWidth,iY+iHeight);
        gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY-1,iX+iWidth,iY-1);
        gVirtualX->DrawLine(iID,m_context->GetGC(),iX-1,iY+iHeight,iX+iWidth,iY+iHeight);*
      */
  }

  FontMetrics_t metrics;
  m_font->GetFontMetrics(&metrics);
  int dX = 0;
  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 + 1, m_data.c_str(), m_data.size());
}

void FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
  m_data = iData;
  m_isSelected = iIsSelected;
}

void FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
  m_data = iData;
  m_isSelected = iIsSelected;
}

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

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

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

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

const TGGC& FWTextTableCellRenderer::getDefaultHighlightGC() {
  // Return graphics context for highlighted frame background.
  static const TGGC* s_default = nullptr;
  if (!s_default) {
    GCValues_t gval;
    gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
    gval.fForeground = gVirtualX->GetPixel(kGray);   //gClient->GetResourcePool()->GetFrameHiliteColor();
    gval.fBackground = gVirtualX->GetPixel(kWhite);  //gClient->GetResourcePool()->GetFrameBgndColor();
    gval.fFillStyle = kFillOpaqueStippled;           // kFillTiled;
    gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
    gval.fGraphicsExposures = kFALSE;
    s_default = gClient->GetGC(&gval, kTRUE);
  }
  return *s_default;
}