File indexing completed on 2024-04-06 12:11:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <iostream>
0015 #include "TGClient.h"
0016 #include "TGFont.h"
0017 #include "TVirtualX.h"
0018
0019
0020 #include "Fireworks/TableWidget/interface/FWFramedTextTableCellRenderer.h"
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 FWFramedTextTableCellRenderer::FWFramedTextTableCellRenderer(const TGGC* iTextContext,
0034 const TGGC* iFillContext,
0035 Justify iJustify)
0036 : m_context(iTextContext), m_frameContext(iFillContext), m_font(nullptr), m_justify(iJustify) {
0037
0038 m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
0039 }
0040
0041
0042
0043
0044
0045
0046 FWFramedTextTableCellRenderer::~FWFramedTextTableCellRenderer() {}
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 void FWFramedTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
0064
0065
0066 gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX - 1, iY + iHeight);
0067 gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX + iWidth, iY - 1, iX + iWidth, iY + iHeight);
0068 gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY - 1, iX + iWidth, iY - 1);
0069 gVirtualX->DrawLine(iID, m_frameContext->GetGC(), iX - 1, iY + iHeight, iX + iWidth, iY + iHeight);
0070
0071 FontMetrics_t metrics;
0072 m_font->GetFontMetrics(&metrics);
0073 int dX = 2;
0074 if (m_justify == kJustifyRight) {
0075 int w = width();
0076 dX = iWidth - w;
0077 }
0078 if (m_justify == kJustifyCenter) {
0079 int w = width();
0080 dX = (iWidth - w) / 2;
0081 }
0082
0083 gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent, m_data.c_str(), m_data.size());
0084 }
0085
0086 void FWFramedTextTableCellRenderer::setData(const std::string& iData) { m_data = iData; }
0087
0088 void FWFramedTextTableCellRenderer::setJustify(Justify iJustify) { m_justify = iJustify; }
0089
0090
0091
0092
0093 UInt_t FWFramedTextTableCellRenderer::width() const {
0094 if (!m_data.empty()) {
0095 return m_font->TextWidth(m_data.c_str(), -1) + 3;
0096 }
0097 return 0;
0098 }
0099 UInt_t FWFramedTextTableCellRenderer::height() const { return m_font->TextHeight(); }
0100
0101 const TGFont* FWFramedTextTableCellRenderer::font() const { return m_font; }
0102
0103
0104
0105
0106 const TGGC& FWFramedTextTableCellRenderer::getDefaultGC() {
0107 static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
0108 return *s_default;
0109 }
0110
0111 const TGGC& FWFramedTextTableCellRenderer::getFillGC() {
0112
0113 static const TGGC* s_default = nullptr;
0114 if (!s_default) {
0115 GCValues_t gval;
0116 gval.fMask = kGCForeground | kGCBackground | kGCTile | kGCFillStyle | kGCGraphicsExposures;
0117 gval.fForeground = gClient->GetResourcePool()->GetFrameHiliteColor();
0118 gval.fBackground = gClient->GetResourcePool()->GetFrameBgndColor();
0119 gval.fFillStyle = kFillTiled;
0120 gval.fTile = gClient->GetResourcePool()->GetCheckeredPixmap();
0121 gval.fGraphicsExposures = kFALSE;
0122 s_default = gClient->GetGC(&gval, kTRUE);
0123 }
0124 return *s_default;
0125 }