123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714 |
- #include "StdAfx.h"
- #include "Xcell.h"
- #include "XTable.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- XCell::XCell(XTable* parent)
- {
- rowSpan = 0;
- colSpan = 0;
- backColor = RGB (255,255,255);
- borderColor = RGB (0xDC,0xDC,0xDC);
- borderStyle = 0;
- text = "";
- textFontSize = 14;
- textFontFace = "Arial";
- textFont = NULL;
- textColor = RGB (0,0,0);
- label = "";
- labelFontSize = 14;
- labelFontFace = "Arial";
- labelFont = NULL;
- labelColor = RGB (0,0,0);
- backMode = TRANSPARENT;
- format = 0;
- overlap = false;
- leftMargin = 4;
- rightMargin = 4;
- }
- XCell::~XCell()
- {
- delete textFont;
- delete labelFont;
- }
- XCell& XCell::operator = (XCell& cell)
- {
- if (&cell == this) return *this;
- rowSpan = cell.rowSpan;
- colSpan = cell.colSpan;
- text = cell.text;
- textColor = cell.textColor;
- delete textFont;
- textFont = NULL;
- if (cell.textFont)
- {
- LOGFONT logFont;
- cell.textFont->GetLogFont (&logFont);
- textFont = new CFont;
- textFont->CreateFontIndirect (&logFont);
- }
- textFontSize = cell.textFontSize;
- textFontFace = cell.textFontFace;
- label = cell.label;
- labelColor = cell.labelColor;
- delete labelFont;
- labelFont = NULL;
- if (cell.labelFont)
- {
- LOGFONT logFont;
- cell.labelFont->GetLogFont (&logFont);
- labelFont = new CFont;
- labelFont->CreateFontIndirect (&logFont);
- }
- labelFontSize = cell.labelFontSize;
- labelFontFace = cell.labelFontFace;
- format = cell.format;
- leftMargin = cell.leftMargin;
- rightMargin = cell.rightMargin;
- backMode = cell.backMode;
- backColor = cell.backColor;
- borderColor = cell.borderColor;
- borderStyle = cell.borderStyle;
- overlap = cell.overlap;
- table = cell.table;
- return *this;
- }
- int XCell::ToXML (CMarkup& markup)
- {
- TCHAR buf[32];
- if (colSpan > 1)
- markup.AddChildAttrib ("colSpan", colSpan);
- if (rowSpan > 1)
- markup.AddChildAttrib ("rowSpan", rowSpan);
- if (backColor != table->defaultCell.backColor)
- {
- sprintf (buf, "#%.2x%.2x%.2x", GetRValue(backColor), GetGValue(backColor), GetBValue(backColor));
- markup.AddChildAttrib ("backColor", buf);
- }
- if (textColor != table->defaultCell.textColor)
- {
- sprintf (buf, "#%.2x%.2x%.2x", GetRValue(textColor), GetGValue(textColor), GetBValue(textColor));
- markup.AddChildAttrib ("textColor", textColor);
- }
- if (backMode != table->defaultCell.backMode)
- {
- if (backMode == TRANSPARENT)
- markup.AddChildAttrib ("backMode", "transparent");
- else
- markup.AddChildAttrib ("backMode", "opaque");
- }
- if (textFontSize != table->defaultCell.textFontSize)
- markup.AddChildAttrib ("fontSize", textFontSize);
- if (textFontFace != table->defaultCell.textFontFace)
- markup.AddChildAttrib ("fontFace", textFontFace);
- if (textFontSize != table->defaultCell.textFontSize)
- markup.AddChildAttrib ("fontWeight", textFontSize);
- int align = GetAlignment();
- if (align != table->defaultCell.GetAlignment())
- {
- if (align & ALIGN_CENTER)
- markup.AddChildAttrib("align", "center");
- else if (align & ALIGN_RIGHT)
- markup.AddChildAttrib("align", "right");
- if (align & ALIGN_MIDDLE)
- markup.AddChildAttrib("vlign", "middle");
- else if (align & ALIGN_BOTTOM)
- markup.AddChildAttrib("valign", "bottom");
- }
- bool ellipsis = GetEllipsis ();
- if (ellipsis != table->defaultCell.GetEllipsis())
- {
- if (ellipsis)
- markup.AddChildAttrib ("ellipsis", "true");
- else
- markup.AddChildAttrib ("ellipsis", "false");
- }
- bool singleLine = GetSingleLine();
- if (singleLine != table->defaultCell.GetSingleLine ())
- {
- if (overlap)
- markup.AddChildAttrib ("singleline", "true");
- else
- markup.AddChildAttrib ("singleline", "false");
- }
- bool wordBreak = GetWordbreak();
- if (wordBreak != table->defaultCell.GetWordbreak ())
- {
- if (wordBreak)
- markup.AddChildAttrib ("wordbreak", "true");
- else
- markup.AddChildAttrib ("wordbreak", "false");
- }
- if (leftMargin != table->defaultCell.leftMargin)
- markup.AddChildAttrib ("leftMargin", leftMargin);
- if (rightMargin != table->defaultCell.rightMargin)
- markup.AddChildAttrib ("rightMargin", rightMargin);
- bool overlap = GetOverlap ();
- if (overlap != table->defaultCell.GetOverlap ())
- {
- if (overlap)
- markup.AddChildAttrib ("overlap", "true");
- else
- markup.AddChildAttrib ("overlap", "false");
- }
- if (label != table->defaultCell.label)
- markup.AddChildAttrib ("label", label);
- if (text != "")
- markup.SetChildData(text);
- return 0;
- }
- int XCell::FromXML (CMarkup& markup)
- {
- CString value;
- *this = table->defaultCell;
- colSpan = 1;
- rowSpan = 1;
- value = markup.GetChildAttrib("colSpan");
- if (value != "")
- colSpan = atoi (value);
- value = markup.GetChildAttrib("rowSpan");
- if (value != "")
- rowSpan = atoi (value);
- value = markup.GetChildAttrib("backColor");
- if (value != "")
- {
- if (*value == '#')
- sscanf(value, "#%x", &backColor);
- else
- backColor = atoi (value);
- backColor = RGB (GetBValue(backColor), GetGValue(backColor), GetRValue(backColor));
- }
- value = markup.GetChildAttrib("textColor");
- if (value != "")
- {
- if (*value == '#')
- sscanf(value, "#%x", &textColor);
- else
- textColor = atoi (value);
-
- textColor = RGB (GetBValue(textColor), GetGValue(textColor), GetRValue(textColor));
- }
- value = markup.GetChildAttrib("fontWeight");
- if (value != "")
- textFontSize = atoi (value);
- value = markup.GetChildAttrib("fontFace");
- if (value != "")
- textFontFace = value;
- value = markup.GetChildAttrib("backMode");
- if (value != "opaque")
- backMode = TRANSPARENT;
- else
- backMode = OPAQUE;
- value = markup.GetChildAttrib("align");
- if (value == "center")
- SetAlignment(ALIGN_CENTER);
- else if (value == "right")
- SetAlignment(ALIGN_RIGHT);
- value = markup.GetChildAttrib("valign");
- if (value == "middle")
- SetAlignment(ALIGN_MIDDLE);
- else if (value == "bottom")
- SetAlignment(ALIGN_BOTTOM);
- value = markup.GetChildAttrib("ellipsis");
- if (value == "true")
- SetEllipsis(true);
- else
- SetEllipsis(false);
- value = markup.GetChildAttrib("singleline");
- if (value == "true")
- SetSingleLine(true);
- else
- SetSingleLine(false);
- value = markup.GetChildAttrib("wordbreak");
- if (value == "true")
- SetWordbreak(true);
- else
- SetWordbreak(false);
- value = markup.GetChildAttrib("leftMargin");
- if (value != "")
- leftMargin = atoi (value);
- value = markup.GetChildAttrib("rightMargin");
- if (value != "")
- rightMargin = atoi (value);
- value = markup.GetChildAttrib("overlap");
- if (value == "true")
- overlap = true;
- else
- overlap = false;
- label = markup.GetChildAttrib("label");
- text = markup.GetChildData();
- if (text != "")
- text = markup.GetChildData();
- return 0;
- }
- int XCell::SetSpan(int rows, int cols)
- {
- rowSpan = rows;
- colSpan = cols;
- return 0;
- }
- int XCell::SetText(CString str)
- {
- text = str;
- return 0;
- }
- CString XCell::GetText()
- {
- return text;
- }
- int XCell::SetTextColor(COLORREF color)
- {
- textColor = color;
- return 0;
- }
- COLORREF XCell::GetTextColor()
- {
- return textColor;
- }
- int XCell::SetAlignment (int align)
- {
- if ( (align & ~ALIGN_MASK) != 0) return -1;
- format = (format & ~ALIGN_MASK) | align;
- return 0;
- }
- int XCell::GetAlignment ()
- {
- return format & ALIGN_MASK;
- }
- int XCell::SetFormat (int format)
- {
- this->format = format;
- return 0;
- }
- int XCell::GetFormat ()
- {
- return format;
- }
- int XCell::SetSingleLine (bool enable)
- {
- if (enable)
- format |= DT_SINGLELINE;
- else
- format &= ~DT_SINGLELINE;
- return 0;
- }
- bool XCell::GetSingleLine ()
- {
- return (format & DT_SINGLELINE) != 0;
- }
- int XCell::SetWordbreak (bool enable)
- {
- if (enable)
- {
- format |= DT_WORDBREAK;
- format |= DT_EDITCONTROL;
- }
- else
- {
- format &= ~DT_WORDBREAK;
- format &= ~DT_EDITCONTROL;
- }
- return 0;
- }
- bool XCell::GetWordbreak ()
- {
- return (format & DT_WORDBREAK) != 0;
- }
- int XCell::SetEllipsis (bool enable)
- {
- if (enable)
- format |= DT_END_ELLIPSIS;
- else
- format &= ~DT_END_ELLIPSIS;
- return 0;
- }
- bool XCell::GetEllipsis ()
- {
- return (format & DT_END_ELLIPSIS) != 0;
- }
- int XCell::SetLeftMargin (int pixels)
- {
- leftMargin = pixels;
- return 0;
- }
- int XCell::GetLeftMargin ()
- {
- return leftMargin;
- }
- int XCell::SetRightMargin (int pixels)
- {
- rightMargin = pixels;
- return 0;
- }
- int XCell::GetRightMargin ()
- {
- return rightMargin;
- }
- int XCell::SetLabel (CString str)
- {
- label = str;
- return 0;
- }
- CString XCell::GetLabel ()
- {
- return label;
- }
- int XCell::SetOverlap (bool enable)
- {
- overlap = enable;
- return 0;
- }
- bool XCell::GetOverlap ()
- {
- return overlap;
- }
- int XCell::SetTextFont(CFont* font)
- {
- LOGFONT longfont;
- if (!font->GetLogFont(&longfont))
- return -1;
- if (textFont)
- {
- delete textFont;
- textFont = NULL;
- }
-
- textFont = new CFont;
- textFont->CreateFontIndirect(&longfont);
- return 0;
- }
- CFont* XCell::GetTextFont()
- {
- return textFont;
- }
- int XCell::SetTextFontSize(int size)
- {
- textFontSize = size;
- return 0;
- }
- int XCell::GetTextFontSize()
- {
- return textFontSize;
- }
- int XCell::SetLabelColor(COLORREF color)
- {
- labelColor = color;
- return 0;
- }
- COLORREF XCell::GetLabelColor()
- {
- return labelColor;
- }
- int XCell::SetLabelFont(CFont* font)
- {
- LOGFONT logfont;
- if (!font->GetLogFont(&logfont))
- return -1;
- if (labelFont)
- {
- labelFont->DeleteObject();
- labelFont = NULL;
- }
- labelFont = new CFont;
- labelFont->CreateFontIndirect(&logfont);
- return 0;
- }
- CFont* XCell::GetLabelFont()
- {
- return labelFont;
- }
- int XCell::SetLabelFontSize(int size)
- {
- labelFontSize = size;
- return 0;
- }
- int XCell::GetLabelFontSize()
- {
- return labelFontSize;
- }
- int XCell::SetBackMode(int mode)
- {
- backMode = mode;
- return 0;
- }
- int XCell::GetBackMode()
- {
- return backMode;
- }
- int XCell::SetBackColor(COLORREF color)
- {
- backColor = color;
- return 0;
- }
- COLORREF XCell::GetBackColor()
- {
- return backColor;
- }
- int XCell::SetBorderSyle(int syle)
- {
- borderStyle = syle;
- return 0;
- }
- int XCell::GetBorderSyle()
- {
- return borderStyle;
- }
- int XCell::DrawText(CDC* pDC, RECT rect)
- {
- if (text.IsEmpty()) return 0;
- COLORREF oldTextColor = pDC->SetTextColor (textColor);
- int oldBkMode = pDC->SetBkMode (backMode);
- CFont* oldFont;
- CFont tempFont;
- if (textFont)
- oldFont = pDC->SelectObject (textFont);
- else
- {
- tempFont.CreateFont (textFontSize,0,0, 0, FW_NORMAL, FALSE, FALSE, 0,
- ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, textFontFace);
- oldFont = pDC->SelectObject (&tempFont);
- }
- if (leftMargin)
- rect.left += leftMargin;
- if (rightMargin)
- rect.right -= rightMargin;
- pDC->DrawText (text, &rect, format);
- // pDC->DrawText (text, &rect, DT_VCENTER|DT_SINGLELINE);
- pDC->SetTextColor(oldTextColor);
- pDC->SetBkMode (oldBkMode);
- pDC->SelectObject (oldFont);
- tempFont.DeleteObject ();
- return 0;
- }
- int XCell::DrawLabel(CDC* pDC, RECT rect)
- {
- return 0;
- }
- int XCell::Draw(CDC* pDC, RECT rect)
- {
- DrawBorder (pDC, rect);
- RECT rect1;
- rect1.left = rect.left+1;
- rect1.top = rect.top+1;
- rect1.right = rect.right;
- rect1.bottom = rect.bottom;
- DrawBackground (pDC, rect1);
- DrawText (pDC, rect1);
- return 0;
- }
- int XCell::DrawBorder(CDC* pDC, RECT rect)
- {
- CPen linePen (PS_SOLID, 1, borderColor);
- CPen* pOldPen = pDC->SelectObject(&linePen);
- pDC->MoveTo (rect.left, rect.top);
- pDC->LineTo (rect.right, rect.top);
- pDC->LineTo (rect.right, rect.bottom);
- pDC->LineTo (rect.left, rect.bottom);
- pDC->LineTo (rect.left, rect.top);
- pDC->SelectObject(pOldPen);
- return 0;
- }
- int XCell::DrawHitBorder (CDC* pDC, RECT rect, COLORREF color)
- {
- CPen pen (PS_SOLID, 3, color);
- CPen* oldPen = pDC->SelectObject(&pen);
- pDC->MoveTo (rect.left, rect.top);
- pDC->LineTo (rect.right, rect.top);
- pDC->LineTo (rect.right, rect.bottom);
- pDC->LineTo (rect.left, rect.bottom);
- pDC->LineTo (rect.left, rect.top);
- pDC->SelectObject(oldPen);
-
- return 0;
- }
- int XCell::DrawBackground (CDC* pDC, RECT rect)
- {
- CBrush bkBrush (backColor);
- pDC->FillRect (&rect, &bkBrush);
- return 0;
- }
- int XCell::CalcTextRect (CDC* pDC, RECT* rect)
- {
- CFont* oldFont;
- CFont tempFont;
- if (textFont)
- oldFont = pDC->SelectObject (textFont);
- else
- {
- tempFont.CreateFont (textFontSize,0,0, 0, FW_NORMAL, FALSE, FALSE, 0,
- ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
- DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, textFontFace);
- oldFont = pDC->SelectObject (&tempFont);
- }
- if (leftMargin)
- rect->left += leftMargin;
- pDC->DrawText (text, rect, format | DT_CALCRECT);
- // pDC->DrawText ("eee3333ttt tt2ww wwddddffffffffvvvvgg2 33 44", rect, format | DT_CALCRECT);
- // pDC->DrawText (text, rect, DT_EDITCONTROL | DT_WORDBREAK | DT_CALCRECT);
-
- pDC->SelectObject (oldFont);
- tempFont.DeleteObject ();
- return 0;
- }
|