Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016 #include "TGClient.h"
00017 #include "TGFont.h"
00018 #include "TVirtualX.h"
00019
00020
00021 #include "Fireworks/TableWidget/interface/FWTextTableCellRenderer.h"
00022 #include "Fireworks/TableWidget/src/FWTabularWidget.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 FWTextTableCellRenderer::FWTextTableCellRenderer(const TGGC* iContext, const TGGC* iHighlightContext, Justify iJustify):
00037 m_context(iContext),
00038 m_highlightContext(iHighlightContext),
00039 m_font(0),
00040 m_isSelected(false),
00041 m_justify(iJustify)
00042 {
00043
00044 m_font = gClient->GetFontPool()->FindFontByHandle(m_context->GetFont());
00045 }
00046
00047
00048
00049
00050
00051
00052 FWTextTableCellRenderer::~FWTextTableCellRenderer()
00053 {
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void
00072 FWTextTableCellRenderer::draw(Drawable_t iID, int iX, int iY, unsigned int iWidth, unsigned int iHeight)
00073 {
00074
00075 if(m_isSelected) {
00076 GContext_t c = m_highlightContext->GetGC();
00077 gVirtualX->FillRectangle(iID, c, iX - FWTabularWidget::kTextBuffer, iY - FWTabularWidget::kTextBuffer,
00078 iWidth + 2*FWTabularWidget::kTextBuffer, iHeight + 2*FWTabularWidget::kTextBuffer);
00079
00080
00081
00082
00083
00084
00085 }
00086
00087
00088
00089 FontMetrics_t metrics;
00090 m_font->GetFontMetrics(&metrics);
00091 int dX=0;
00092 if(m_justify==kJustifyRight) {
00093 int w = width();
00094 dX = iWidth-w;
00095 }
00096 if(m_justify==kJustifyCenter) {
00097 int w = width();
00098 dX = (iWidth-w)/2;
00099
00100 }
00101
00102 gVirtualX->DrawString(iID,m_context->GetGC(),iX+dX,iY+metrics.fAscent +1, m_data.c_str(),m_data.size());
00103 }
00104
00105 void
00106 FWTextTableCellRenderer::setData(const std::string& iData, bool iIsSelected) {
00107 m_data = iData;
00108 m_isSelected=iIsSelected;
00109 }
00110
00111 void
00112 FWTextTableCellRenderer::setData(const char* iData, bool iIsSelected) {
00113 m_data = iData;
00114 m_isSelected=iIsSelected;
00115 }
00116
00117 void
00118 FWTextTableCellRenderer::setJustify(Justify iJustify)
00119 {
00120 m_justify=iJustify;
00121 }
00122
00123
00124
00125
00126 UInt_t
00127 FWTextTableCellRenderer::width() const
00128 {
00129 if(m_data.size()) {
00130 return m_font->TextWidth(m_data.c_str(),-1);
00131 }
00132 return 0;
00133 }
00134 UInt_t
00135 FWTextTableCellRenderer::height() const
00136 {
00137 return m_font->TextHeight();
00138 }
00139
00140 const TGFont*
00141 FWTextTableCellRenderer::font() const
00142 {
00143 return m_font;
00144 }
00145
00146
00147
00148
00149 const TGGC&
00150 FWTextTableCellRenderer::getDefaultGC()
00151 {
00152 static const TGGC* s_default = gClient->GetResourcePool()->GetFrameGC();
00153 return *s_default;
00154 }
00155
00156 const TGGC &
00157 FWTextTableCellRenderer::getDefaultHighlightGC()
00158 {
00159
00160 static const TGGC* s_default = 0;
00161 if (!s_default) {
00162 GCValues_t gval;
00163 gval.fMask = kGCForeground | kGCBackground | kGCStipple | kGCFillStyle | kGCGraphicsExposures;
00164 gval.fForeground = gVirtualX->GetPixel(kGray);
00165 gval.fBackground = gVirtualX->GetPixel(kWhite);
00166 gval.fFillStyle = kFillOpaqueStippled;
00167 gval.fStipple = gClient->GetResourcePool()->GetCheckeredBitmap();
00168 gval.fGraphicsExposures = kFALSE;
00169 s_default = gClient->GetGC(&gval, kTRUE);
00170 }
00171 return *s_default;
00172 }