File indexing completed on 2024-04-06 12:11:53
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/FWTextTableCellRenderer.h"
0021 #include "Fireworks/TableWidget/interface/FWTabularWidget.h"
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify)
0035 : m_context(iContext),
0036 m_highlightContext(iHighlightContext),
0037 m_font(nullptr),
0038 m_isSelected(false),
0039 m_justify(iJustify) {
0040
0041 m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
0042 }
0043
0044
0045
0046
0047
0048
0049 FWTextTableCellRenderer::~FWTextTableCellRenderer() {}
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 void FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight) {
0067 if (m_isSelected) {
0068 GContext_t c = m_highlightContext->GetGC();
0069 gVirtualX->FillRectangle(iID,
0070 c,
0071 iX - FWTabularWidget::kTextBuffer,
0072 iY - FWTabularWidget::kTextBuffer,
0073 iWidth + 2 * FWTabularWidget::kTextBuffer,
0074 iHeight + 2 * FWTabularWidget::kTextBuffer);
0075
0076
0077
0078
0079
0080
0081 }
0082
0083 FontMetrics_t metrics;
0084 m_font->GetFontMetrics(&metrics);
0085 int dX = 0;
0086 if (m_justify == kJustifyRight) {
0087 int w = width();
0088 dX = iWidth - w;
0089 }
0090 if (m_justify == kJustifyCenter) {
0091 int w = width();
0092 dX = (iWidth - w) / 2;
0093 }
0094
0095 gVirtualX->DrawString(iID, m_context->GetGC(), iX + dX, iY + metrics.fAscent + 1, m_data.c_str(), m_data.size());
0096 }
0097
0098 void FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
0099 m_data = iData;
0100 m_isSelected = iIsSelected;
0101 }
0102
0103 void FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
0104 m_data = iData;
0105 m_isSelected = iIsSelected;
0106 }
0107
0108 void FWTextTableCellRenderer::setJustify(Justify iJustify) { m_justify = iJustify; }
0109
0110
0111
0112
0113 UInt_t FWTextTableCellRenderer::width() const {
0114 if (!m_data.empty()) {
0115 return m_font->TextWidth(m_data.c_str(), -1);
0116 }
0117 return 0;
0118 }
0119 UInt_t FWTextTableCellRenderer::height() const {
0120 return m_font->TextHeight();
0121 }
0122
0123 const TGFont* FWTextTableCellRenderer::font() const { return m_font; }
0124
0125
0126
0127
0128 const TGGC& FWTextTableCellRenderer::getDefaultGC() {
0129 static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
0130 return *s_default;
0131 }
0132
0133 const TGGC& FWTextTableCellRenderer::getDefaultHighlightGC() {
0134
0135 static const TGGC* s_default = nullptr;
0136 if (!s_default) {
0137 GCValues_t gval;
0138 gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
0139 gval.fForeground = gVirtualX->GetPixel(kGray);
0140 gval.fBackground = gVirtualX->GetPixel(kWhite);
0141 gval.fFillStyle = kFillOpaqueStippled;
0142 gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
0143 gval.fGraphicsExposures = kFALSE;
0144 s_default = gClient->GetGC(&gval, kTRUE);
0145 }
0146 return *s_default;
0147 }