//--------------------------------------------------------------------------- #include #include //#include //#include #include #pragma hdrstop #include "TPDocObject.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // // External Functions // //--------------------------------------------------------------------------- TCursor __fastcall GetCursor(TPDocControlMode dcm) { switch (dcm) { case dcmLeftTop: case dcmRightBottom: return crSizeNWSE; case dcmRightTop: case dcmLeftBottom: return crSizeNESW; case dcmCenterTop: case dcmCenterBottom: case dcmVertical: return crSizeNS; case dcmLeftCenter: case dcmRightCenter: case dcmHorizental: return crSizeWE; case dcmFirst: case dcmMedium: case dcmLast: return crHandPoint; } return crArrow; } //--------------------------------------------------------------------------- bool __fastcall TextLoadFromFile(HANDLE hFile, AnsiString &Text) { DWORD dwRead; int n; char *str = NULL; if (!ReadFile(hFile, &n, sizeof(int), &dwRead, NULL)) return false; if (n > 0) { if ((str = new char[n + 1]) == NULL) goto fail; str[n] = 0; if (!ReadFile(hFile, str, n, &dwRead, NULL)) goto fail; Text = str; delete str; } return true; fail: if (str) delete str; return false; } //--------------------------------------------------------------------------- bool __fastcall TextSaveToFile(HANDLE hFile, AnsiString Text) { DWORD dwWrite; int n; n = Text.Length(); if (!WriteFile(hFile, &n, sizeof(int), &dwWrite, NULL)) return false; if (n > 0) { if (!WriteFile(hFile, Text.c_str(), n, &dwWrite, NULL)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall ImageLoadFromFile(HANDLE hFile, TTexpiaBitmap *&Image) { DWORD dwRead; int w, h; WORD bpp; RGBQUAD rgb[256]; if (!ReadFile(hFile, &bpp, sizeof(WORD), &dwRead, NULL)) return NULL; if (bpp) { if (!ReadFile(hFile, &w, sizeof(int), &dwRead, NULL)) return NULL; if (!ReadFile(hFile, &h, sizeof(int), &dwRead, NULL)) return NULL; if ((Image = new TTexpiaBitmap) == NULL) return NULL; if (bpp == 8) { if (!ReadFile(hFile, rgb, 256 * sizeof(RGBQUAD), &dwRead, NULL)) goto fail; if (!Image->Create(w, h, bpp, rgb)) goto fail; } else { if (!Image->Create(w, h, bpp)) goto fail; } if (!Image->LoadFromTexpiaFile(hFile, cmZLib)) goto fail; } return true; fail: if (Image) { delete Image; Image = NULL; } return false; } //--------------------------------------------------------------------------- bool __fastcall ImageSaveToFile(HANDLE hFile, TTexpiaBitmap *Image) { DWORD dwWrite; int w, h; WORD bpp; RGBQUAD rgb[256]; if (Image) { bpp = Image->BitsPerPixel; if (!WriteFile(hFile, &bpp, sizeof(WORD), &dwWrite, NULL)) return false; w = Image->Width; if (!WriteFile(hFile, &w, sizeof(int), &dwWrite, NULL)) return false; h = Image->Height; if (!WriteFile(hFile, &h, sizeof(int), &dwWrite, NULL)) return false; if (bpp == 8) { Image->GetColors(0, 256, rgb); if (!WriteFile(hFile, rgb, 256 * sizeof(RGBQUAD), &dwWrite, NULL)) return false; } if (!Image->SaveToTexpiaFile(hFile, cmZLib)) return false; } else { bpp = 0; if (!WriteFile(hFile, &bpp, sizeof(WORD), &dwWrite, NULL)) return false; } return true; } //--------------------------------------------------------------------------- // // TPDocViewStatus // //--------------------------------------------------------------------------- __fastcall TPDocViewStatus::TPDocViewStatus() { Position.x = Position.y = 0; ZoomIn = ZoomOut = 1; } //--------------------------------------------------------------------------- __fastcall TPDocViewStatus::TPDocViewStatus(POINT pt, int zi, int zo) { Position = pt; ZoomIn = zi; ZoomOut = zo; } //--------------------------------------------------------------------------- int __fastcall TPDocViewStatus::View2PatternX(int X) { return Position.x + X * ZoomOut / ZoomIn; } //--------------------------------------------------------------------------- int __fastcall TPDocViewStatus::View2PatternY(int Y) { return Position.y + Y * ZoomOut / ZoomIn; } //--------------------------------------------------------------------------- int __fastcall TPDocViewStatus::Pattern2ViewX(int X) { return (X - Position.x) * ZoomIn / ZoomOut; } //--------------------------------------------------------------------------- int __fastcall TPDocViewStatus::Pattern2ViewY(int Y) { return (Y - Position.y) * ZoomIn / ZoomOut; } //--------------------------------------------------------------------------- RECT __fastcall TPDocViewStatus::ChangeRect(RECT rc) { rc.left = rc.left * ZoomIn / ZoomOut; rc.top = rc.top * ZoomIn / ZoomOut; rc.right = rc.right * ZoomIn / ZoomOut; rc.bottom = rc.bottom * ZoomIn / ZoomOut; return rc; } //--------------------------------------------------------------------------- // // TPDocObject // //--------------------------------------------------------------------------- __fastcall TPDocObject::TPDocObject() { Parent = NULL; } //--------------------------------------------------------------------------- TFont *__fastcall TPDocObject::GetFont() { return NULL; } //--------------------------------------------------------------------------- // // TPDocElement // //--------------------------------------------------------------------------- __fastcall TPDocElement::TPDocElement(TPDocElementType t, RECT rc, TPDocLineStyle fstyle, TColor fcolor) : TPDocObject() { Type = t; Range = rc; ControlMode = dcmNone; FrameStyle = fstyle; FrameColor = fcolor; } //--------------------------------------------------------------------------- __fastcall TPDocElement::~TPDocElement() { } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- RECT __fastcall TPDocElement::ConvertRange(TPDocViewStatus *vs) { RECT rc; rc = Range; if (Parent) { rc.left += Parent->Range.left; rc.top += Parent->Range.top; rc.right += Parent->Range.left; rc.bottom += Parent->Range.top; } if (vs) { rc.left = rc.left - vs->Position.x; rc.top = rc.top - vs->Position.y; rc.right = rc.right - vs->Position.x; rc.bottom = rc.bottom - vs->Position.y; } return rc; } //--------------------------------------------------------------------------- POINT __fastcall TPDocElement::ConvertPoint(POINT tp, TPDocViewStatus *vs) { if (Parent) { tp.x += Parent->Range.left; tp.y += Parent->Range.top; } if (vs) { tp.x -= vs->Position.x; tp.y -= vs->Position.y; } return tp; } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintRange(HDC hDC, RECT rc) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int p; hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(psDash, 1, clBlack); hOldPen = SelectObject(hDC, hPen); Rectangle(hDC, rc.left, rc.top, rc.right + 1, rc.bottom + 1); SelectObject(hDC, hOldPen); DeleteObject(hPen); SelectObject(hDC, hOldBrush); } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintImage(HDC hDC, TTexpiaBitmap *Image, SIZE s, int x, int y) { double rx, ry, r; HDC hImageDC; int rvalue = 0; if (!Image) return; rx = (double)s.cx / Image->Width; ry = (double)s.cy / Image->Height; r = rx < ry ? rx : ry; hImageDC = Image->CreateDC(); if (r < 1.0) { if (s.cx > Image->Width*r) x += (s.cx - Image->Width*r)/2; if (s.cy > Image->Height*r) y += (s.cy - Image->Height*r)/2; SetStretchBltMode(hDC, COLORONCOLOR); rvalue = StretchBlt(hDC, x, y, Image->Width * r, Image->Height * r, hImageDC, 0, 0, Image->Width, Image->Height, SRCCOPY); if (rvalue == 0) ShowMessage("Image Copy fail //s"); } else { rvalue = BitBlt(hDC, x + (s.cx - Image->Width) / 2, y + (s.cy - Image->Height) / 2, Image->Width, Image->Height, hImageDC, 0, 0, SRCCOPY); if (rvalue == 0) ShowMessage("Image Copy fail //b"); } Image->DeleteDC(hImageDC); } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintSelect(HDC hDC, RECT rc, TPDocPaintSelectInEvent func) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int p; PaintRange(hDC, rc); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); if (func) func(hDC, rc); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); if (hOldBrush) SelectObject(hDC, hOldBrush); } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintSelectReport(HDC hDC, void *data, TPDocPaintSelectInReportEvent func) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int p; hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); if (func) func(hDC, data); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); if (hOldBrush) SelectObject(hDC, hOldBrush); } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintSelectInCommon(HDC hDC, RECT rc) { int p; Rectangle(hDC, rc.left-2, rc.top-2, rc.left+3, rc.top+3); Rectangle(hDC, rc.right-2, rc.top-2, rc.right+3, rc.top+3); Rectangle(hDC, rc.left-2, rc.bottom-2, rc.left+3, rc.bottom+3); Rectangle(hDC, rc.right-2, rc.bottom-2, rc.right+3, rc.bottom+3); p = (rc.right + rc.left) / 2; Rectangle(hDC, p-2, rc.top-2, p+3, rc.top+3); Rectangle(hDC, p-2, rc.bottom-2, p+3, rc.bottom+3); p = (rc.bottom + rc.top) / 2; Rectangle(hDC, rc.left-2, p-2, rc.left+3, p+3); Rectangle(hDC, rc.right-2, p-2, rc.right+3, p+3); } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int nOldROP = 0; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); nOldROP = SetROP2(hDC, R2_NOT); Rectangle(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), vs.Pattern2ViewX(FOldRect.right + 1), vs.Pattern2ViewY(FOldRect.bottom + 1)); } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintForm(HDC hDC) { } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool select, int language) { } //--------------------------------------------------------------------------- bool __fastcall TPDocElement::isExist(POINT pt) { return pt.x >= Range.left && pt.y >= Range.top && pt.x <= Range.right && pt.y <= Range.bottom; } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocElement::GetControlMode(int X, int Y) { int p; TPDocControlMode dcm; if (Y >= Range.top - 2 && Y < Range.top + 3) { if (X >= Range.left - 2 && X < Range.left + 3) { return dcmLeftTop; } else if (X >= Range.right - 2 && X < Range.right + 3) { return dcmRightTop; } else { p = (Range.right + Range.left) /2; if (X >= p - 2 && X < p + 3) { return dcmCenterTop; } } } else if (Y >= Range.bottom - 2 && Y < Range.bottom + 3) { if (X >= Range.left - 2 && X < Range.left + 3) { return dcmLeftBottom; } else if (X >= Range.right - 2 && X < Range.right + 3) { return dcmRightBottom; } else { p = (Range.right + Range.left) /2; if (X >= p - 2 && X < p + 3) { return dcmCenterBottom; } } } else { p = (Range.bottom + Range.top) /2; if (Y >= p - 2 && Y < p + 3) { if (X >= Range.left - 2 && X < Range.left + 3) { return dcmLeftCenter; } else if (X >= Range.right - 2 && X < Range.right + 3) { return dcmRightCenter; } } } return X >= Range.left && Y >= Range.top && X <= Range.right && Y <= Range.bottom ? dcmMove : dcmNone; } //--------------------------------------------------------------------- void __fastcall TPDocElement::GetNewRange(int X, int Y) { FOldRect = Range; switch (ControlMode) { case dcmLeftTop: FOldRect.left = X; FOldRect.top = Y; break; case dcmCenterTop: FOldRect.top = Y; break; case dcmRightTop: FOldRect.top = Y; FOldRect.right = X; break; case dcmLeftCenter: FOldRect.left = X; break; case dcmRightCenter: FOldRect.right = X; break; case dcmLeftBottom: FOldRect.left = X; FOldRect.bottom = Y; break; case dcmCenterBottom: FOldRect.bottom = Y; break; case dcmRightBottom: FOldRect.right = X; FOldRect.bottom = Y; break; case dcmMove: FOldRect.left += X - FOldPoint.x; FOldRect.top += Y - FOldPoint.y; FOldRect.right += X - FOldPoint.x; FOldRect.bottom += Y - FOldPoint.y; break; } } //--------------------------------------------------------------------- void __fastcall TPDocElement::ControlModeMouseDown(int X, int Y) { FOldPoint = Point(X, Y); FOldRect = Range; } //--------------------------------------------------------------------- void __fastcall TPDocElement::ControlModeMouseMove(HDC hDC, TPDocViewStatus &vs, int X, int Y) { PaintControl(hDC, vs); GetNewRange(X, Y); PaintControl(hDC, vs); } //--------------------------------------------------------------------- void __fastcall TPDocElement::ControlModeMouseUp() { switch (ControlMode) { case dcmMove: Range = FOldRect; break; default: /* Range.left = min(FOldRect.left, FOldRect.right); Range.top = min(FOldRect.top, FOldRect.bottom); Range.right = max(FOldRect.left, FOldRect.right); Range.bottom = max(FOldRect.top, FOldRect.bottom);*/ break; } } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintFrame(HDC hDC, RECT rc, TPDocLineStyle ls, TColor c) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; if (ls != dlsNone) { rc.right += 1; rc.bottom += 1; try { if (ls == dlsTwo) { hPen = CreatePen(psSolid, 1, c); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); Rectangle(hDC, rc.left+4, rc.top+4, rc.right-4, rc.bottom-4); } else if (ls == dlsOne || ls == dlsHeavy) { hPen = CreatePen(psSolid, ls == dlsHeavy ? 3 : 1, c); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom); } } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } } //--------------------------------------------------------------------------- void __fastcall TPDocElement::PaintFrame(HDC hDC, RECT rc) { PaintFrame(hDC, rc, FrameStyle, FrameColor); } //--------------------------------------------------------------------------- // // TPDocLine // //--------------------------------------------------------------------------- __fastcall TPDocLine::TPDocLine(TPDocObject *Sender, RECT rc, TPDocLineType lt, TColor c, TPDocLineStyle ls) : TPDocElement(detLine, rc) { Parent = Sender; Type = lt; Color = c; Style = ls; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintForm(HDC hDC, RECT rc) { HPEN hPen = NULL, hOldPen = NULL; int p; try { switch (Type) { case dltHorizental: if (Style == dlsTwo) { hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, rc.left, rc.top-2, NULL); LineTo(hDC, rc.right, rc.top-2); MoveToEx(hDC, rc.left, rc.top+2, NULL); LineTo(hDC, rc.right, rc.top+2); } else if (Style == dlsOne || Style == dlsHeavy) { hPen = CreatePen(psSolid, Style == dlsHeavy ? 3 : 1, Color); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, rc.left, rc.top, NULL); LineTo(hDC, rc.right, rc.top); } break; case dltVertical: if (Style == dlsTwo) { hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, rc.left-2, rc.top, NULL); LineTo(hDC, rc.left-2, rc.bottom); MoveToEx(hDC, rc.left+2, rc.top, NULL); LineTo(hDC, rc.left+2, rc.bottom); } else if (Style == dlsOne || Style == dlsHeavy) { hPen = CreatePen(psSolid, Style == dlsHeavy ? 3 : 1, Color); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, rc.left, rc.top, NULL); LineTo(hDC, rc.left, rc.bottom); } break; case dltOblique: if (Style == dlsOne || Style == dlsHeavy) { hPen = CreatePen(psSolid, Style == dlsHeavy ? 3 : 1, Color); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, rc.left, rc.top, NULL); LineTo(hDC, rc.right, rc.bottom); } break; } } __finally { if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintSelectInHorizental(HDC hDC, RECT rc) { Rectangle(hDC, rc.left-2, rc.top-2, rc.left+3, rc.top+3); Rectangle(hDC, rc.right-2, rc.top-2, rc.right+3, rc.top+3); } //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintSelectInVertical(HDC hDC, RECT rc) { Rectangle(hDC, rc.left-2, rc.top-2, rc.left+3, rc.top+3); Rectangle(hDC, rc.left-2, rc.bottom-2, rc.left+3, rc.bottom+3); } //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int nOldROP = 0; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); nOldROP = SetROP2(hDC, R2_NOT); if (Type == dltHorizental) { MoveToEx(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldRect.right), vs.Pattern2ViewY(FOldRect.top)); } else if (Type == dltVertical) { MoveToEx(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.bottom)); } else { hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), vs.Pattern2ViewX(FOldRect.right + 1), vs.Pattern2ViewY(FOldRect.bottom + 1)); } } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocLine::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) { switch (Type) { case dltHorizental: PaintSelect(hDC, rc, &PaintSelectInHorizental); break; case dltVertical: PaintSelect(hDC, rc, &PaintSelectInVertical); break; case dltOblique: PaintSelect(hDC, rc, &PaintSelectInCommon); break; } } else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- bool __fastcall TPDocLine::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!ReadFile(hFile, &Type, sizeof(TPDocLineType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Style, sizeof(TPDocLineStyle), &dwRead, NULL)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocLine::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!WriteFile(hFile, &Type, sizeof(TPDocLineType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Style, sizeof(TPDocLineStyle), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocLine::GetControlMode(int X, int Y) { TPDocControlMode dcm; if (Type == dltHorizental) { if (Y >= Range.top - 2 && Y < Range.top + 3) { if (X >= Range.left - 2 && X < Range.left + 3) { return dcmLeftCenter; } else if (X >= Range.right - 2 && X < Range.right + 3) { return dcmRightCenter; } } } else if (Type == dltVertical) { if (X >= Range.left - 2 && X < Range.left + 3) { if (Y >= Range.top - 2 && Y < Range.top + 3) { return dcmCenterTop; } else if (Y >= Range.bottom - 2 && Y < Range.bottom + 3) { return dcmCenterBottom; } } } else { return TPDocElement::GetControlMode(X, Y); } return X >= Range.left && Y >= Range.top && X <= Range.right && Y <= Range.bottom ? dcmMove : dcmNone; } //--------------------------------------------------------------------------- // // TPDocBox // //--------------------------------------------------------------------------- __fastcall TPDocBox::TPDocBox(TPDocObject *Sender, RECT rc, TColor c, TPDocLineStyle ls) : TPDocElement(detBox, rc) { Parent = Sender; Color = c; Style = ls; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocBox::PaintForm(HDC hDC, RECT range) { PaintFrame(hDC, range, Style, Color); PaintFrame(hDC, range); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocBox::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocBox::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- bool __fastcall TPDocBox::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Style, sizeof(TPDocLineStyle), &dwRead, NULL)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocBox::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Style, sizeof(TPDocLineStyle), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocColorChip // //--------------------------------------------------------------------------- __fastcall TPDocColorChip::TPDocColorChip(TPDocObject *Sender, RECT rc, int m, AnsiString n, TColor c) : TPDocElement(detColorChip, rc) { Parent = Sender; Margin = m; Name = n; Color = c; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocColorChip::PaintForm(HDC hDC, RECT range) { PaintFrame(hDC, range); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocColorChip::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocColorChip::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocColorChip::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hBrush = NULL, hOldBrush = NULL; RECT rc; rc = ConvertRange(&vs); rc.left += Margin; rc.top += Margin; rc.right -= Margin; rc.bottom -= Margin; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hBrush = CreateSolidBrush(Color); hOldBrush = SelectObject(hDC, hBrush); Rectangle(hDC, rc.left, rc.top, rc.right+1, rc.bottom+1); } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hBrush) DeleteObject(hBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- bool __fastcall TPDocColorChip::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Margin, sizeof(int), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Name)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocColorChip::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Margin, sizeof(int), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Name)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocText // //--------------------------------------------------------------------------- __fastcall TPDocText::TPDocText(TPDocObject *Sender, TPDocElementType ot, RECT rc, TPDocAlign ta) : TPDocElement(ot, rc) { Parent = Sender; FNewFont = false; Font = Parent->GetFont(); Align = ta; } //--------------------------------------------------------------------------- __fastcall TPDocText::~TPDocText() { if (FNewFont) { if (Font) delete Font; } } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- bool __fastcall TPDocText::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; TFontCharset charset; TColor color; AnsiString FName; int size; TFontStyles fstyle; if (!ReadFile(hFile, &FNewFont, sizeof(bool), &dwRead, NULL)) return false; if (FNewFont) { Font = new TFont; if (!ReadFile(hFile, &charset, sizeof(TFontCharset), &dwRead, NULL)) return false; Font->Charset = charset; if (!ReadFile(hFile, &color, sizeof(TColor), &dwRead, NULL)) return false; Font->Color = color; if (!TextLoadFromFile(hFile, FName)) return false; Font->Name = FName; if (!ReadFile(hFile, &size, sizeof(int), &dwRead, NULL)) return false; Font->Size = size; if (!ReadFile(hFile, &fstyle, sizeof(TFontStyle), &dwRead, NULL)) return false; Font->Style = fstyle; } else { Font = Parent->GetFont(); } if (!ReadFile(hFile, &Align, sizeof(TPDocAlign), &dwRead, NULL)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocText::SaveToFile(HANDLE hFile) { DWORD dwWrite; TFontCharset charset; TColor color; int size; TFontStyles fstyle; if (!WriteFile(hFile, &FNewFont, sizeof(bool), &dwWrite, NULL)) return false; if (FNewFont) { charset = Font->Charset; if (!WriteFile(hFile, &charset, sizeof(TFontCharset), &dwWrite, NULL)) return false; color = Font->Color; if (!WriteFile(hFile, &color, sizeof(TColor), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Font->Name)) return false; size = Font->Size; if (!WriteFile(hFile, &size, sizeof(int), &dwWrite, NULL)) return false; fstyle = Font->Style; if (!WriteFile(hFile, &fstyle, sizeof(TFontStyle), &dwWrite, NULL)) return false; } if (!WriteFile(hFile, &Align, sizeof(TPDocAlign), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- void __fastcall TPDocText::PaintText(HDC hDC, TFont *Font, RECT rc, TPDocAlign Align, AnsiString Text, bool multiline) { HFONT hOldFont; TEXTMETRIC tm; int px, py, i = 0, cnt, l, len; char *ch, *nch, *sp, *ep, *tp; WORD wAlign; hOldFont = SelectObject(hDC, Font->Handle); SetBkMode(hDC, TRANSPARENT); wAlign = GetTextAlign(hDC); GetTextMetrics(hDC, &tm); SetTextColor(hDC, Font->Color); if (Align != daCenterVertical) { switch (Align) { case daLeftTop: SetTextAlign(hDC, TA_LEFT); px = rc.left + 2; py = rc.top + 2; break; case daCenterTop: SetTextAlign(hDC, TA_CENTER); px = (rc.right + rc.left) / 2; py = rc.top + 2; break; case daRightTop: SetTextAlign(hDC, TA_RIGHT); px = rc.right - 2; py = rc.top + 2; break; case daLeftCenter: SetTextAlign(hDC, TA_LEFT); px = rc.left + 2; py = (rc.bottom + rc.top - tm.tmHeight) / 2; break; case daCenter2: SetTextAlign(hDC, TA_CENTER); px = (rc.right + rc.left) / 2; py = (rc.bottom + rc.top - tm.tmHeight) / 2; break; case daRightCenter: SetTextAlign(hDC, TA_RIGHT); px = rc.right - 2; py = (rc.bottom + rc.top - tm.tmHeight) / 2; break; case daLeftBottom: SetTextAlign(hDC, TA_LEFT); px = rc.left + 2; py = rc.bottom - tm.tmHeight - 2; break; case daCenterBottom: SetTextAlign(hDC, TA_CENTER); px = (rc.right + rc.left) / 2; py = rc.bottom - tm.tmHeight - 2; break; case daRightBottom: SetTextAlign(hDC, TA_RIGHT); px = rc.right - 2; py = rc.bottom - tm.tmHeight - 2; break; } if (!multiline) { // date, edit, label, number, formula... ExtTextOut(hDC, px, py, ETO_CLIPPED, &rc, Text.c_str(), Text.Length(), NULL); } else { // for only sheaflabel.... sp = Text.c_str(); // ÁٹٲÞÀ» ÇØÁÖ±â À§ÇÔ.. ep = sp; tp = strchr(ep, '\n'); while(tp != NULL) { len = tp - ep - 1; ExtTextOut(hDC, px, py+tm.tmHeight*i, ETO_CLIPPED, &rc, ep, len, NULL); i++; ep = tp + 1; tp = strchr(ep, '\n'); } if (*ep) { // when text is not ended with null character!! len = Text.Length() - (ep - sp); ExtTextOut(hDC, px, py+tm.tmHeight*i, ETO_CLIPPED, &rc, ep, len, NULL); } } } else { // ¼¼·Î ÀÔ·Â... SetTextAlign(hDC, TA_CENTER); ch = Text.c_str(); cnt = TextLength(ch); px = (rc.right + rc.left)/2; py = (rc.bottom + rc.top - cnt*tm.tmHeight)/2; i = 0; while(*ch) { nch = CharNext(ch); l = nch - ch; ExtTextOut(hDC, px, py+tm.tmHeight*i, ETO_CLIPPED, &rc, ch, l, NULL); ch = nch; i++; } } SetTextAlign(hDC, wAlign); SelectObject(hDC, hOldFont); } //--------------------------------------------------------------------------- int __fastcall TPDocText::TextLength(char *ch) { int cnt = 0; while(*ch) { ch = CharNext(ch); cnt++; } return cnt; } //--------------------------------------------------------------------------- void __fastcall TPDocText::PaintNumber(HDC hDC, TFont *Font, RECT rc, TPDocAlign Align, double Number, int Precision, bool decimal) { AnsiString Text, fmt; TFraction *fract; int remainder, portion, value; if (decimal) { // ½ÊÁø¼ö Ç¥½Ã ¹æ¹ý if (Precision > 0) { fmt = Format("%%.%df", OPENARRAY(TVarRec, (Precision))); Text = Format(fmt, OPENARRAY(TVarRec, (Number))); } else { value = (int)Number; Text = Format("%d", OPENARRAY(TVarRec, (value))); } } else { // ºÐ¼ö Ç¥½Ã ¹æ¹ý.. fract = new TFraction(10); fract->Value(Number); if (fract->denominator == 1) { value = (int)Number; Text = Format("%d", OPENARRAY(TVarRec, (value))); } else { portion = (int)(fract->numerator/fract->denominator); remainder = fract->numerator - portion*fract->denominator; if (Number >= 0 ) { // positive if (portion) { Text = Format("%d %d/%d", OPENARRAY(TVarRec, (portion, remainder, fract->denominator))); } else{ Text = Format("%d/%d", OPENARRAY(TVarRec, (remainder, fract->denominator))); } } else { // negitive if (portion) { Text = Format("-%d %d/%d", OPENARRAY(TVarRec, (portion, remainder, fract->denominator))); } else{ Text = Format("-%d/%d", OPENARRAY(TVarRec, (remainder, fract->denominator))); } } } delete fract; } PaintText(hDC, Font, rc, Align, Text); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- TFont *__fastcall TPDocText::GetFont() { return Font; } //--------------------------------------------------------------------------- void __fastcall TPDocText::SetFont(TFont *font, TColor color) { if (font) { if (FNewFont) { Font->Assign(font); } else { Font = new TFont; Font->Assign(font); FNewFont = true; } // Font->Color = color; } else { if (Font) delete Font; Font = Parent->GetFont(); FNewFont = false; } } //--------------------------------------------------------------------------- // // TPDocNomber // //--------------------------------------------------------------------------- int TPDocNumber::FIDCount = 0; //--------------------------------------------------------------------------- __fastcall TPDocNumber::TPDocNumber(TPDocObject *Sender, RECT rc, TPDocAlign ta, int p, bool h, AnsiString n) : TPDocText(Sender, detNumber, rc, ta) { FID = ++FIDCount; Number = ""; FPrecision = p; FHide = h; Name = n; FDecimal = true; FIndex = -1; bFIndex = false; } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetPrecision(int ivalue) { FPrecision = ivalue; } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetHide(bool bvalue) { FHide = bvalue; } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetDecimal(bool decimal) { FDecimal = decimal; } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetIndex(int value) { FIndex = value; } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocNumber::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daLeftTop, Format("N%d", OPENARRAY(TVarRec, (FID)))); } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { double num; if (!bPrint || !FHide) { if (Number.Length() > 0) { try { num = StrToFloat(Number); PaintNumber(hDC, Font, ConvertRange(&vs), Align, num, FPrecision, FDecimal); } catch (EConvertError&) { PaintText(hDC, Font, ConvertRange(&vs), Align, Number); } } } } //--------------------------------------------------------------------------- void __fastcall TPDocNumber::SetNumber(AnsiString value) { AnsiString format, ff; double dval; if (value.Length() > 0) { try { if (Precision) { ff = AnsiString::StringOfChar('0', Precision); format = "0."+ff; } else { format = "0"; } dval = StrToFloat(value); Number = FormatFloat(format, dval); } catch (EConvertError&) { Number = value; } } else { Number = value; } } //--------------------------------------------------------------------------- bool __fastcall TPDocNumber::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; /* if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &FID, sizeof(int), &dwRead, NULL)) return false; if (Version <= 3) { // replace with AnsiString from Version 4 if (!ReadFile(hFile, &FNumber, sizeof(double), &dwRead, NULL)) return false; } if (!ReadFile(hFile, &FPrecision, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FHide, sizeof(bool), &dwRead, NULL)) return false; // if (Version == 3) { if (Version >= 3) { if (!ReadFile(hFile, &FDecimal, sizeof(bool), &dwRead, NULL)) return false; } if (!TextLoadFromFile(hFile, Name)) return false; if (Version >= 4) { if (!TextLoadFromFile(hFile, Number)) return false; } if (Version >= 6) { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; } return true; */ if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &FID, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FPrecision, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FHide, sizeof(bool), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FDecimal, sizeof(bool), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (!TextLoadFromFile(hFile, Number)) return false; if (Version >= 6) { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocNumber::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &FID, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FPrecision, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FHide, sizeof(bool), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FDecimal, sizeof(bool), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Name)) return false; if (!TextSaveToFile(hFile, Number)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- // // Postfix // //--------------------------------------------------------------------------- class Postfix { private: char *infix, buf; int ifp, pfp; int __fastcall factor(); int __fastcall term(); public: char *postfix; __fastcall Postfix(char *); __fastcall ~Postfix(); int __fastcall convert(); }; //--------------------------------------------------------------------------- __fastcall Postfix::Postfix(char *ifd) { infix = ifd; ifp = pfp = 0; postfix = (char *)calloc(strlen(infix)+1, 1); } //--------------------------------------------------------------------------- __fastcall Postfix::~Postfix() { if (postfix) free(postfix); } //--------------------------------------------------------------------------- int __fastcall Postfix::factor() { // if (buf=='N' || buf=='C') { if (buf=='N' || buf=='F') { postfix[pfp++] = buf; while (buf=infix[ifp], isdigit(buf)) { ifp++; postfix[pfp++] = buf; } } else if (buf=='I') { int m = 0, p = 0; postfix[pfp++] = buf; while (1) { buf = infix[ifp]; if (!m && buf=='-') { ifp++; postfix[pfp++] = buf; } else if (!p && buf=='.') { ifp++; postfix[pfp++] = buf; p++; } else if (isdigit(buf)) { ifp++; postfix[pfp++] = buf; } else break; m++; } } else if (buf=='(') { if (convert()) return -1; if (buf!=')') return -1; } else return -1; buf = infix[ifp++]; return 0; } //--------------------------------------------------------------------------- int __fastcall Postfix::term() { char optor; if (factor()) return -1; while (buf=='*' || buf=='/') { optor = buf; buf = infix[ifp++]; if (factor()) return -1; postfix[pfp++] = optor; } return 0; } //--------------------------------------------------------------------------- int __fastcall Postfix::convert() { char optor; buf = infix[ifp++]; if (term()) return -1; while (buf=='+' || buf=='-') { optor = buf; buf = infix[ifp++]; if (term()) return -1; postfix[pfp++] = optor; } return 0; } //--------------------------------------------------------------------------- // // TPDocFormula // //--------------------------------------------------------------------------- int TPDocFormula::FIDCount = 0; //--------------------------------------------------------------------------- __fastcall TPDocFormula::TPDocFormula(TPDocObject *Sender, RECT rc, TPDocAlign ta, int p, bool h, AnsiString n, AnsiString f) : TPDocText(Sender, detFormula, rc, ta) { FID = ++FIDCount; FPrecision = p; FHide = h; Name = n; Formula = f; FDecimal = true; ANumber = ""; FIndex = -1; bFIndex = false; // Data = new bool; //added by k3dogs(20001029) formula¿¡¼­ ÀÚµ¿ °è»ê ÈÄ °³°³ÀÇ formula->ANumber¼öÁ¤ÇÒ ¼ö ÀÖ°Ô Ãß°¡. //boundary check¿¡¼­ ¸Þ¸ð¸®°¡ ¼¾´Ù°í ÇØ¼­¸®. Data = false; //ÃʱâÈ­.. trueÀÌ¸é ¼öÁ¤µÈ °ÍÀ¸·Î ÀÚµ¿°è»ê¿¡¼­ Á¦¿ÜµÈ´Ù. } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetPrecision(int ivalue) { FPrecision = ivalue; } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetHide(bool bvalue) { FHide = bvalue; } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetDecimal(bool decimal) { FDecimal = decimal; } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetIndex(int value) { FIndex = value; } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocFormula::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daLeftTop, Format("F%d", OPENARRAY(TVarRec, (FID)))); } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { double num; AnsiString temp; if (!bPrint || !FHide) { if (Formula.Length() > 0) { num = ((TPDocSheet *)Sender)->Calculation(Formula); temp = FloatToStr(num); SetNumber(temp); PaintNumber(hDC, Font, ConvertRange(&vs), Align, num, FPrecision, FDecimal); } else { if (ANumber.Length() > 0) { try { num = StrToFloat(ANumber); PaintNumber(hDC, Font, ConvertRange(&vs), Align, num, FPrecision, FDecimal); } catch (EConvertError&) { PaintText(hDC, Font, ConvertRange(&vs), Align, ANumber); } } } } } //--------------------------------------------------------------------------- void __fastcall TPDocFormula::SetNumber(AnsiString value) { AnsiString format, ff; double dval; int ival; if (value.Length() > 0) { try { if (Precision) { ff = AnsiString::StringOfChar('0', Precision); format = "0."+ff; } else { format = "0"; } dval = StrToFloat(value); ANumber = FormatFloat(format, dval); } catch (EConvertError&) { ANumber = value; } } else { ANumber = value; } } //--------------------------------------------------------------------------- bool __fastcall TPDocFormula::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; /* if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &FID, sizeof(int), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Formula)) return false; if (!ReadFile(hFile, &FPrecision, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FHide, sizeof(bool), &dwRead, NULL)) return false; // if (Version == 3) { if (Version >= 3) { if (!ReadFile(hFile, &FDecimal, sizeof(bool), &dwRead, NULL)) return false; } if (!TextLoadFromFile(hFile, Name)) return false; if (Version >= 4) { if (!TextLoadFromFile(hFile, ANumber)) return false; } if (Version >= 6) { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; } return true; */ if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &FID, sizeof(int), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Formula)) return false; if (!ReadFile(hFile, &FPrecision, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FHide, sizeof(bool), &dwRead, NULL)) return false; if (!ReadFile(hFile, &FDecimal, sizeof(bool), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (!TextLoadFromFile(hFile, ANumber)) return false; if (Version >= 6) { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; } if (Version >= 7) { //by k3dogs formula ÀÚµ¿°è»ê ÈÄ formula->ANumber º¯°æ¿©ºÎ ÀúÀå. if (!ReadFile(hFile, &Data, sizeof(bool), &dwRead, NULL)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocFormula::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &FID, sizeof(int), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Formula)) return false; if (!WriteFile(hFile, &FPrecision, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FHide, sizeof(bool), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FDecimal, sizeof(bool), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Name)) return false; if (!TextSaveToFile(hFile, ANumber)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Data, sizeof(bool), &dwWrite, NULL)) return false; //by k3dogs return true; } //--------------------------------------------------------------------------- // // TPDocDate // //--------------------------------------------------------------------------- __fastcall TPDocDate::TPDocDate(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString n) : TPDocText(Sender, detDate, rc, ta) { Date = ""; Name = n; FIndex= -1; bFIndex = false; } //--------------------------------------------------------------------------- void __fastcall TPDocDate::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocDate::SetIndex(int value) { FIndex = value; } //--------------------------------------------------------------------------- void __fastcall TPDocDate::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocDate::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocDate::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daCenter2, "Date"); } //--------------------------------------------------------------------------- void __fastcall TPDocDate::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { PaintText(hDC, Font, ConvertRange(&vs), daCenter2, Date); } //--------------------------------------------------------------------------- bool __fastcall TPDocDate::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; /* if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (Version <= 3) { if (!ReadFile(hFile, &Time, sizeof(SYSTEMTIME), &dwRead, NULL)) return false; } else if (Version >= 4) { if (!TextLoadFromFile(hFile, Date)) return false; } if (!TextLoadFromFile(hFile, Name)) return false; if (Version >= 5) if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; return true; */ if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, Date)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocDate::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, Date)) return false; // Version >= 4 if (!TextSaveToFile(hFile, Name)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocImage // //--------------------------------------------------------------------------- __fastcall TPDocImage::TPDocImage(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString str) : TPDocText(Sender, detImage, rc, ta) { Image = NULL; ImgTitle = str; } //--------------------------------------------------------------------------- __fastcall TPDocImage::~TPDocImage() { if (Image) delete Image; } //--------------------------------------------------------------------------- void __fastcall TPDocImage::PaintForm(HDC hDC, RECT rc) { if (ImgTitle.Length() > 0) { PaintText(hDC, Font, rc, Align, ImgTitle); } PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocImage::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocImage::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; TSize s; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daCenter2, "Image"); } //--------------------------------------------------------------------------- void __fastcall TPDocImage::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { RECT rc; TSize s; int th = 0; HFONT hOldFont; TEXTMETRIC tm; if (Image) { if (ImgTitle != "") { hOldFont = SelectObject(hDC, Font->Handle); GetTextMetrics(hDC, &tm); th = tm.tmHeight; SelectObject(hDC, hOldFont); } rc = ConvertRange(&vs); s.cx = rc.right - rc.left - 6; // ¿©À¯ºÐÀ» ³Ö¾îÁÜ. s.cy = rc.bottom - rc.top - th - 6; PaintImage(hDC, Image, s, rc.left + 3, rc.top + th + 3); } } //--------------------------------------------------------------------------- bool __fastcall TPDocImage::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &Zoom, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Align, sizeof(TPDocAlign), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, ImgTitle)) return false; if (!TextLoadFromFile(hFile, ImgDir)) return false; if (!ImageLoadFromFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocImage::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &Zoom, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Align, sizeof(TPDocAlign), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, ImgTitle)) return false; if (!TextSaveToFile(hFile, ImgDir)) return false; if (!ImageSaveToFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocSignature // //--------------------------------------------------------------------------- __fastcall TPDocSignature::TPDocSignature(TPDocObject *Sender, RECT rc) : TPDocElement(detSignature, rc) { Image = NULL; } //--------------------------------------------------------------------------- __fastcall TPDocSignature::~TPDocSignature() { if (Image) delete Image; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocSignature::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocSignature::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocSignature::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; TSize s; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------- ------------------------------------------------------------ void __fastcall TPDocSignature::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { int tw = 0, sw = 0; RECT rc; TSize s; sw = CheckFrame(); if (sw > 0) tw = 2*sw - 1; if (Image) { rc = ConvertRange(&vs); s.cx = rc.right - rc.left - tw; s.cy = rc.bottom - rc.top - tw; PaintImage(hDC, Image, s, rc.left + sw, rc.top + sw); } } //--------------------------------------------------------------------------- bool __fastcall TPDocSignature::LoadFromFile(HANDLE hFile, int Version) { if (!ImageLoadFromFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSignature::SaveToFile(HANDLE hFile) { if (!ImageSaveToFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSignature::MakeBitmap() { int tw = 0, ww, hh; RECT rt; tw = CheckFrame(); if (tw > 0) tw = 2*tw - 1; ww = Range.right-Range.left - tw; hh = Range.bottom-Range.top - tw; rt = Rect(0, 0, ww, hh); if (Image == NULL) { if ((Image = new TTexpiaBitmap) == NULL) goto fail; if (!Image->Create(ww, hh, 24)) goto fail; } Image->FillRect(rt, clWhite); return true; fail: if (Image) { delete Image; Image = NULL; } return false; } //--------------------------------------------------------------------------- void __fastcall TPDocSignature::DrawLine(POINT sp, POINT ep) { HPEN hPen = NULL, hOldPen = NULL; HDC hDC = NULL; if (Image) { if (CheckRange(sp, ep)) { try { hDC = Image->CreateDC(); hPen = CreatePen(psSolid, 2, clBlack); hOldPen = SelectObject(hDC, hPen); MoveToEx(hDC, sp.x-Range.left, sp.y-Range.top, NULL); LineTo(hDC, ep.x-Range.left, ep.y-Range.top); } __finally { if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); if (hDC) Image->DeleteDC(hDC); } } } } //--------------------------------------------------------------------------- bool __fastcall TPDocSignature::CheckRange(POINT sp, POINT ep) { int tw = 0; RECT rt = Range; tw = CheckFrame(); if (tw > 0) rt = Rect(rt.left+tw, rt.top+tw, rt.right-tw+1, rt.bottom-tw+1); if ((sp.x < rt.left) || (sp.x >= rt.right) || (sp.y < rt.top) || (sp.y >= rt.bottom)) { return false; } if ((ep.x < rt.left) || (ep.x >= rt.right) || (ep.y < rt.top) || (ep.y >= rt.bottom)) { return false; } return true; } //--------------------------------------------------------------------------- int __fastcall TPDocSignature::CheckFrame() { int tw = 0; switch(FrameStyle) { // ÇÁ·¹ÀÓÀÌ Àִ°æ¿ì ±×¸¸Å­ ±×·ÁÁÙ ¼ö ÀÖ´Â ¿µ¿ªÀÌ ÁÙ¾îµé±â¶§¹®¿¡.. case dlsOne: tw = 2; break; case dlsTwo: tw = 5; break; case dlsHeavy: tw = 4; break; } return tw; } //--------------------------------------------------------------------------- // // TPDocLabel // //--------------------------------------------------------------------------- __fastcall TPDocLabel::TPDocLabel(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString t) : TPDocText(Sender, detLabel, rc, ta) { Text = t; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocLabel::PaintForm(HDC hDC, RECT rc) { if (Text.Length() > 0) { PaintText(hDC, Font, rc, Align, Text); } PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocLabel::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocLabel::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocLabel::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { } //--------------------------------------------------------------------------- bool __fastcall TPDocLabel::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, Text)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocLabel::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, Text)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocEdit // //--------------------------------------------------------------------------- __fastcall TPDocEdit::TPDocEdit(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString n) : TPDocText(Sender, detEdit, rc, ta) { Name = n; FIndex = -1; bFIndex = false; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocEdit::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::SetIndex(int value) { FIndex = value; } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocEdit::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daCenter2, "Edit"); } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { AnsiString Text; switch (language) { case 0: Text = K_Text; break; case 1: Text = E_Text; break; case 2: Text = I_Text; break; case 3: Text = C_Text; break; case 4: Text = J_Text; break; } if (Text.Length() > 0) { PaintText(hDC, Font, ConvertRange(&vs), Align, Text); } } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::SetText(AnsiString kt, AnsiString et, AnsiString it, AnsiString ct, AnsiString jt) { K_Text = kt; E_Text = et; I_Text = it; C_Text = ct; J_Text = jt; } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::GetText(AnsiString &kt, AnsiString &et, AnsiString &it, AnsiString &ct, AnsiString &jt) { kt = K_Text; et = E_Text; it = I_Text; ct = C_Text; jt = J_Text; } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::SetK_Text(AnsiString kt) { if(kt.Length() == 0) { E_Text = ""; I_Text = ""; C_Text = ""; J_Text = ""; } K_Text = kt; } //--------------------------------------------------------------------------- void __fastcall TPDocEdit::GetK_Text(AnsiString &kt) { kt = K_Text; } //--------------------------------------------------------------------------- bool __fastcall TPDocEdit::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; /* if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, Text)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (Version >= 5) if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; return true; */ if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (Version <= 5) { if (!TextLoadFromFile(hFile, K_Text)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; } else { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Name)) return false; if (!TextLoadFromFile(hFile, K_Text)) return false; if (!TextLoadFromFile(hFile, E_Text)) return false; if (!TextLoadFromFile(hFile, I_Text)) return false; if (!TextLoadFromFile(hFile, C_Text)) return false; if (!TextLoadFromFile(hFile, J_Text)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocEdit::SaveToFile(HANDLE hFile) { DWORD dwWrite; /* if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, Text)) return false; if (!TextSaveToFile(hFile, Name)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; return true; */ if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Name)) return false; if (!TextSaveToFile(hFile, K_Text)) return false; if (!TextSaveToFile(hFile, E_Text)) return false; if (!TextSaveToFile(hFile, I_Text)) return false; if (!TextSaveToFile(hFile, C_Text)) return false; if (!TextSaveToFile(hFile, J_Text)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocMemo // //--------------------------------------------------------------------------- __fastcall TPDocMemo::TPDocMemo(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString t) : TPDocText(Sender, detMemo, rc, ta) { Title = t; TitleHeight = 0; FIndex = -1; bFIndex = false; bNewFont = false; MFont = NULL; } //--------------------------------------------------------------------------- __fastcall TPDocMemo::~TPDocMemo() { if (bNewFont) { if (MFont) { delete MFont; MFont = NULL; } } } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocMemo::PaintForm(HDC hDC, RECT rc) { if (Title.Length() > 0) { PaintText(hDC, Font, rc, Align, Title); } PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocMemo::SetIndex(int value) { FIndex = value; } //--------------------------------------------------------------------------- void __fastcall TPDocMemo::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocMemo::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocMemo::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; TEXTMETRIC tm; HFONT hOldFont; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); PaintText(hDC, Font, rc, daCenter2, "Memo"); if (Title.Length() > 0) { hOldFont = SelectObject(hDC, Font->Handle); GetTextMetrics(hDC, &tm); TitleHeight = tm.tmHeight; SelectObject(hDC, hOldFont); } } //--------------------------------------------------------------------------- void __fastcall TPDocMemo::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { HFONT hOldFont = NULL; RECT rc; TEXTMETRIC tm; int i=0, len = 0, sy; char *sp, *tp, *ep; WORD wAlign; if (Text.Length() > 0) { rc = ConvertRange(&vs); try { if (bNewFont && MFont) { hOldFont = SelectObject(hDC, MFont->Handle); SetTextColor(hDC, MFont->Color); } else { hOldFont = SelectObject(hDC, Font->Handle); SetTextColor(hDC, Font->Color); } SetBkMode(hDC, TRANSPARENT); wAlign = GetTextAlign(hDC); SetTextAlign(hDC, TA_LEFT); GetTextMetrics(hDC, &tm); sp = Text.c_str(); ep = sp; tp = strchr(ep, '\n'); sy = rc.top+TitleHeight; while(tp != NULL) { // FontÀÇ Height°¡ ¹Ù²ð ¼ö ÀÖ´Ù.. len = tp - ep - 1; ExtTextOut(hDC, rc.left+2, sy+tm.tmHeight*i, ETO_CLIPPED, &rc, ep, len, NULL); i++; ep = tp + 1; tp = strchr(ep, '\n'); } if (*ep) { // when text is not ended with null character!! len = Text.Length() - (ep - sp); ExtTextOut(hDC, rc.left+2, sy+tm.tmHeight*i, ETO_CLIPPED, &rc, ep, len, NULL); } SetTextAlign(hDC, wAlign); } __finally { if (hOldFont) SelectObject(hDC, hOldFont); } } } //--------------------------------------------------------------------------- bool __fastcall TPDocMemo::SetFont(TFont *Font, TColor C) { if (MFont == NULL && bNewFont == false) { MFont = new TFont; bNewFont = true; } MFont->Assign(Font); MFont->Charset = DEFAULT_CHARSET; // MFont->Color = C; // MFont->Name = "MS Sans Serif"; // MFont->Size = 10; // MFont->Color = clBlack; } //--------------------------------------------------------------------------- TFont *__fastcall TPDocMemo::GetFont() { if (bNewFont) return MFont; else return TPDocText::GetFont(); } //--------------------------------------------------------------------------- bool __fastcall TPDocMemo::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; TFontCharset charset; TColor color; AnsiString FName; int size; TFontStyles fstyle; if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, Title)) return false; if (!TextLoadFromFile(hFile, Text)) return false; if (!ReadFile(hFile, &TitleHeight, sizeof(int), &dwRead, NULL)) return false; if (Version >= 5) { if (!ReadFile(hFile, &FIndex, sizeof(int), &dwRead, NULL)) return false; //================ For Font... if (!ReadFile(hFile, &bNewFont, sizeof(bool), &dwRead, NULL)) return false; if (bNewFont) { MFont = new TFont; if (!ReadFile(hFile, &charset, sizeof(TFontCharset), &dwRead, NULL)) return false; MFont->Charset = charset; if (!ReadFile(hFile, &color, sizeof(TColor), &dwRead, NULL)) return false; MFont->Color = color; if (!TextLoadFromFile(hFile, FName)) return false; MFont->Name = FName; if (!ReadFile(hFile, &size, sizeof(int), &dwRead, NULL)) return false; MFont->Size = size; if (!ReadFile(hFile, &fstyle, sizeof(TFontStyle), &dwRead, NULL)) return false; MFont->Style = fstyle; } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocMemo::SaveToFile(HANDLE hFile) { DWORD dwWrite; TFontCharset charset; TColor color; AnsiString FName; int size; TFontStyles fstyle; if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, Title)) return false; if (!TextSaveToFile(hFile, Text)) return false; if (!WriteFile(hFile, &TitleHeight, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FIndex, sizeof(int), &dwWrite, NULL)) return false; //============================ for font.... if (!WriteFile(hFile, &bNewFont, sizeof(bool), &dwWrite, NULL)) return false; if (bNewFont) { charset = MFont->Charset; if (!WriteFile(hFile, &charset, sizeof(TFontCharset), &dwWrite, NULL)) return false; color = MFont->Color; if (!WriteFile(hFile, &color, sizeof(TColor), &dwWrite, NULL)) return false; FName = MFont->Name; if (!TextSaveToFile(hFile, FName)) return false; size = MFont->Size; if (!WriteFile(hFile, &size, sizeof(int), &dwWrite, NULL)) return false; fstyle = MFont->Style; if (!WriteFile(hFile, &fstyle, sizeof(TFontStyle), &dwWrite, NULL)) return false; } return true; } //--------------------------------------------------------------------------- // // TPDocInput // //--------------------------------------------------------------------------- __fastcall TPDocInput::TPDocInput(TPDocObject *Sender, RECT rc, TPDocAlign ta, TColor c, TPDocInputStyle s, AnsiString t, int p, TPDocInputMethod m) : TPDocText(Sender, detInput, rc, ta) { TPDocEdit *dp; RECT src; Text = t; Color = c; Style = s; Position = p; Method = m; if (Style == disHorizental) { src = Rect(p, 0, rc.right - rc.left, rc.bottom - rc.top); } else { src = Rect(0, p, rc.right - rc.left, rc.bottom - rc.top); } dp = new TPDocEdit(this, src); IPElement = (TPDocElement *)dp; bFIndex = false; } //--------------------------------------------------------------------------- __fastcall TPDocInput::~TPDocInput() { RemoveData(); } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocInput::RemoveData() { if (IPElement) { switch (IPElement->Type) { case detColorChip: delete (TPDocColorChip *)IPElement; break; case detNumber: delete (TPDocNumber *)IPElement; break; case detFormula: delete (TPDocFormula *)IPElement; break; case detDate: delete (TPDocDate *)IPElement; break; case detEdit: delete (TPDocEdit *)IPElement; break; case detImage: delete (TPDocImage *)IPElement; break; } } } //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintForm(HDC hDC, RECT range) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int p; RECT rc; try { hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, range.left, range.top, range.right + 1, range.bottom + 1); if (Style == disVertical) { p = Position ? Position : range.bottom - range.top; MoveToEx(hDC, range.left, range.top + p, NULL); LineTo(hDC, range.right, range.top + p); if (Text.Length() > 0) { if (IPElement->Type != detImage || Method != dimAuto) { rc = Rect(range.left, range.top, range.right, range.top + p); PaintText(hDC, Font, rc, Align, Text); } } } else { p = Position ? Position : range.right - range.left; MoveToEx(hDC, range.left + p, range.top, NULL); LineTo(hDC, range.left + p, range.bottom); if (Text.Length() > 0) { if (IPElement->Type != detImage || Method != dimAuto) { rc = Rect(range.left, range.top, range.left + p, range.bottom); PaintText(hDC, Font, rc, Align, Text); } } } } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } PaintFrame(hDC, range); //right range?? } //--------------------------------------------------------------------------- void __fastcall TPDocInput::SetInputStyle(TPDocInputStyle instyle) { if (instyle !=Style) { if (instyle == disHorizental) { Position = (Range.right - Range.left)/2; IPElement->Range = Rect(Position, 0, Range.right - Range.left, Range.bottom - Range.top); } else { Position = (Range.bottom - Range.top)/2; IPElement->Range = Rect(0, Position, Range.right - Range.left, Range.bottom - Range.top); } Style = instyle; } } //--------------------------------------------------------------------------- void __fastcall TPDocInput::SetbIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintSelectIn(HDC hDC, RECT rc) { int px, py; PaintSelectInCommon(hDC, rc); if (Style == disVertical) { px = (rc.right + rc.left) / 2; py = rc.top+Position; } else { px = rc.left+Position; py = (rc.bottom + rc.top) / 2; } Rectangle(hDC, px-2, py-2, px+3, py+3); } //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int nOldROP = 0; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); nOldROP = SetROP2(hDC, R2_NOT); Rectangle(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), vs.Pattern2ViewX(FOldRect.right + 1), vs.Pattern2ViewY(FOldRect.bottom + 1)); if (Style == disVertical) { MoveToEx(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top + FOldPosition), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldRect.right), vs.Pattern2ViewY(FOldRect.top + FOldPosition)); } else { MoveToEx(hDC, vs.Pattern2ViewX(FOldRect.left + FOldPosition), vs.Pattern2ViewY(FOldRect.top), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldRect.left + FOldPosition), vs.Pattern2ViewY(FOldRect.bottom)); } } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); IPElement->PaintForm(hDC); } //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectIn); else PaintRange(hDC, rc); IPElement->PaintDesign(hDC, vs, false); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocInput::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { int p; RECT range, rc; range = ConvertRange(&vs); IPElement->PaintReport(Sender, hDC, vs, bPrint, bselect, language); if (IPElement->Type == detImage && Method == dimAuto) { // this case Text is had to be changed... if (((TPDocImage *)IPElement)->Image != NULL) { if (Style == disVertical) { p = Position ? Position : range.bottom - range.top; if (Text.Length() > 0) { rc = Rect(range.left, range.top, range.right, range.top + p); PaintText(hDC, Font, rc, Align, Text); } } else { p = Position ? Position : range.right - range.left; if (Text.Length() > 0) { rc = Rect(range.left, range.top, range.left + p, range.bottom); PaintText(hDC, Font, rc, Align, Text); } } } } } //--------------------------------------------------------------------------- void __fastcall TPDocInput::SetImgDir(AnsiString imgdir) { ImageDir = imgdir; } //--------------------------------------------------------------------------- void __fastcall TPDocInput::SetInputText(AnsiString itext) { Text = itext; } //--------------------------------------------------------------------------- bool __fastcall TPDocInput::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; TPDocElement *dp; TPDocElementType et; RECT rt; RemoveData(); if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Style, sizeof(TPDocInputStyle), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, Text)) return false; if (!ReadFile(hFile, &Position, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Method, sizeof(TPDocInputMethod), &dwRead, NULL)) return false; if (!ReadFile(hFile, &et, sizeof(TPDocElementType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &rt, sizeof(RECT), &dwRead, NULL)) return false; switch (et) { case detColorChip: dp = new TPDocColorChip(this, rt); break; case detNumber: dp = new TPDocNumber(this, rt); break; case detFormula: dp = new TPDocFormula(this, rt); break; case detDate: dp = new TPDocDate(this, rt); break; case detEdit: dp = new TPDocEdit(this, rt); break; case detImage: dp = new TPDocImage(this, rt); break; } if (dp) { if (!dp->LoadFromFile(hFile, Version)) return false; IPElement = (TPDocElement *)dp; } else { return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocInput::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Style, sizeof(TPDocInputStyle), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, Text)) return false; if (!WriteFile(hFile, &Position, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Method, sizeof(TPDocInputMethod), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &IPElement->Type, sizeof(TPDocElementType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &IPElement->Range, sizeof(RECT), &dwWrite, NULL)) return false; if (!IPElement->SaveToFile(hFile)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocInput::isExist(POINT pt) { if (TPDocElement::isExist(pt)) { if (Style == disVertical) { FSelectTitle = pt.y - Range.top < Position; } else { FSelectTitle = pt.x - Range.left < Position; } return true; } return false; } //--------------------------------------------------------------------------- void __fastcall TPDocInput::SetElement(TPDocElement *Element, TPDocElementType et) { RECT src = IPElement->Range; /* switch (IPElement->Type) { case detColorChip: delete (TPDocColorChip *)IPElement; break; case detNumber: delete (TPDocNumber *)IPElement; break; case detFormula: delete (TPDocFormula *)IPElement; break; case detEdit: delete (TPDocEdit *)IPElement; break; case detImage: delete (TPDocImage *)IPElement; break; } */ RemoveData(); switch (et) { case detColorChip: IPElement = (TPDocElement *)(new TPDocColorChip(Element, src)); break; case detNumber: IPElement = (TPDocElement *)(new TPDocNumber(Element, src)); break; case detFormula: IPElement = (TPDocElement *)(new TPDocFormula(Element, src)); break; case detDate: IPElement = (TPDocElement *)(new TPDocDate(Element, src)); break; case detEdit: IPElement = (TPDocElement *)(new TPDocEdit(Element, src)); break; case detImage: IPElement = (TPDocElement *)(new TPDocImage(Element, src)); break; } } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocInput::GetControlMode(int X, int Y) { int px, py; if (Style == disVertical) { px = (Range.right + Range.left) / 2; py = Range.top+Position; } else { px = Range.left+Position; py = (Range.bottom + Range.top) / 2; } if (X >= px - 2 && X < px + 3 && Y >= py - 2 && Y < py + 3) { return Style == disVertical ? dcmVertical : dcmHorizental; } return TPDocElement::GetControlMode(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocInput::GetNewRange(int X, int Y) { switch (ControlMode) { case dcmHorizental: if (X < Range.left) { FOldPosition = 0; } else if (X >= Range.right) { FOldPosition = Range.right - Range.left; } else { FOldPosition = X - Range.left; } break; case dcmVertical: if (Y < Range.top) { FOldPosition = 0; } else if (Y >= Range.bottom) { FOldPosition = Range.bottom - Range.top; } else { FOldPosition = Y - Range.top; } break; default: TPDocElement::GetNewRange(X, Y); break; } } //--------------------------------------------------------------------- void __fastcall TPDocInput::ControlModeMouseDown(int X, int Y) { FOldPosition = Position; TPDocElement::ControlModeMouseDown(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocInput::ControlModeMouseMove(HDC hDC, TPDocViewStatus &vs, int X, int Y) { PaintControl(hDC, vs); GetNewRange(X, Y); PaintControl(hDC, vs); } //--------------------------------------------------------------------- void __fastcall TPDocInput::ControlModeMouseUp() { switch (ControlMode) { case dcmHorizental: case dcmVertical: Position = FOldPosition; break; default: TPDocElement::ControlModeMouseUp(); break; } if (Style == disHorizental) { IPElement->Range = Rect(Position, 0, Range.right - Range.left, Range.bottom - Range.top); } else { IPElement->Range = Rect(0, Position, Range.right - Range.left, Range.bottom - Range.top); } } //--------------------------------------------------------------------------- // // TPDocChart // //--------------------------------------------------------------------------- int TPDocChart::FIDCount = 0; #ifdef KIDO //--------------------------------------------------------------------------- __fastcall TPDocChart::TPDocChart(TPDocObject *Sender, RECT rc, TPDocAlign ta, int col, int row, TColor c, bool beditformula, TPDocElementType et) : TPDocText(Sender, detChart, rc, ta) { int i, x, y, gx, gy; TPDocEdit *ep; TPDocColorChip *cp; TPDocNumber *np; TPDocFormula *fp; // TPDocNumber *dp; FID = ++FIDCount; Cols = col; Rows = row; Color = c; EditFormula = beditformula; Cell = new TList; gx = (rc.right - rc.left) / Cols; PosX = new int[Cols + 1]; for (i = 0; i < Cols; i++) PosX[i] = i * gx; PosX[i] = rc.right - rc.left; gy = (rc.bottom - rc.top) / Rows; PosY = new int[Rows + 1]; for (i = 0; i < Rows; i++) PosY[i] = i * gy; PosY[i] = rc.bottom - rc.top; for (y = 0; y < Rows; y++) { for (x = 0; x < Cols; x++) { switch (et) { case detEdit : ep = new TPDocEdit(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(ep); break; case detColorChip : cp = new TPDocColorChip(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(cp); break; case detNumber : np = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(np); break; case detFormula : fp = new TPDocFormula(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(fp); break; // dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); // Cell->Add(dp); } } } bFIndex = false; } //--------------------------------------------------------------------------- #else __fastcall TPDocChart::TPDocChart(TPDocObject *Sender, RECT rc, TPDocAlign ta, int col, int row, TColor c, TPDocElementType et) : TPDocText(Sender, detChart, rc, ta) { int i, x, y, gx, gy; TPDocEdit *ep; TPDocColorChip *cp; TPDocNumber *np; TPDocFormula *fp; // TPDocNumber *dp; FID = ++FIDCount; Cols = col; Rows = row; Color = c; Cell = new TList; gx = (rc.right - rc.left) / Cols; PosX = new int[Cols + 1]; for (i = 0; i < Cols; i++) PosX[i] = i * gx; PosX[i] = rc.right - rc.left; gy = (rc.bottom - rc.top) / Rows; PosY = new int[Rows + 1]; for (i = 0; i < Rows; i++) PosY[i] = i * gy; PosY[i] = rc.bottom - rc.top; for (y = 0; y < Rows; y++) { for (x = 0; x < Cols; x++) { switch (et) { case detEdit : ep = new TPDocEdit(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(ep); break; case detColorChip : cp = new TPDocColorChip(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(cp); break; case detNumber : np = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(np); break; case detFormula : fp = new TPDocFormula(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(fp); break; // dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); // Cell->Add(dp); } } } bFIndex = false; } //--------------------------------------------------------------------------- #endif __fastcall TPDocChart::~TPDocChart() { RemoveData(); } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocChart::RemoveData() { char *sp; TPDocElement *dp; if (Cell) { while (Cell->Count) { dp = (TPDocElement *)Cell->First(); Cell->Remove(dp); switch (dp->Type) { case detColorChip: delete (TPDocColorChip *)dp; break; case detNumber: delete (TPDocNumber *)dp; break; case detFormula: delete (TPDocFormula *)dp; break; case detLabel: delete (TPDocLabel *)dp; break; case detEdit: delete (TPDocEdit *)dp; break; case detImage: delete (TPDocImage *)dp; break; } } delete Cell; Cell = NULL; } if (PosY) { delete PosY; PosY = NULL; } if (PosX) { delete PosX; PosX = NULL; } } //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintForm(HDC hDC, RECT rc) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int i, x, y, gx, gy; TPDocElement *dp; char str[5]; try { hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, rc.left, rc.top, rc.right + 1, rc.bottom + 1); for (i = 0; i < Cols; i++) { x = rc.left + PosX[i]; if (x < rc.right) { if (i > 0) { MoveToEx(hDC, x, rc.top, NULL); LineTo(hDC, x, rc.bottom); } } } for (i = 1; i < Rows; i++) { y = rc.top + PosY[i]; if (y < rc.bottom) { MoveToEx(hDC, rc.left, y, NULL); LineTo(hDC, rc.right, y); } } } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocChart::SetbFIndex(bool bvalue) { bFIndex = bvalue; } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintSelectIn(HDC hDC, RECT rc) { int i, px, py; PaintSelectInCommon(hDC, rc); py = rc.top + PosY[1] / 2; for (i = 1; i < Cols; i++) { px = rc.left + PosX[i]; if (px < rc.right) { Rectangle(hDC, px-2, py-2, px+3, py+3); } } px = rc.left + PosX[1] / 2; for (i = 1; i < Rows; i++) { py = rc.top + PosY[i]; if (py < rc.bottom) { Rectangle(hDC, px-2, py-2, px+3, py+3); } } } //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int nOldROP = 0; int i, x, y; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); nOldROP = SetROP2(hDC, R2_NOT); Rectangle(hDC, vs.Pattern2ViewX(FOldRect.left), vs.Pattern2ViewY(FOldRect.top), vs.Pattern2ViewX(FOldRect.right + 1), vs.Pattern2ViewY(FOldRect.bottom + 1)); for (i = 1; i < Cols; i++) { if (ControlMode == dcmHorizental && i == FNumber) x = vs.Pattern2ViewX(FOldRect.left + FOldPosition); else x = vs.Pattern2ViewX(FOldRect.left + PosX[i]); if (x < FOldRect.right) { MoveToEx(hDC, x, vs.Pattern2ViewY(FOldRect.top), NULL); LineTo(hDC, x, vs.Pattern2ViewY(FOldRect.bottom)); } } for (i = 1; i < Rows; i++) { if (ControlMode == dcmVertical && i == FNumber) y = vs.Pattern2ViewY(FOldRect.top + FOldPosition); else y = vs.Pattern2ViewY(FOldRect.top + PosY[i]); if (y < FOldRect.bottom) { MoveToEx(hDC, vs.Pattern2ViewX(FOldRect.left), y, NULL); LineTo(hDC, vs.Pattern2ViewX(FOldRect.right), y); } } } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- bool __fastcall TPDocChart::SetCellSize(int col, int row, TPDocElementType et) { int i, x, y, gx, gy; TPDocNumber *dp; RemoveData(); Cols = col; Rows = row; Cell = new TList; gx = (Range.right - Range.left) / Cols; if ((PosX = new int[Cols + 1]) == NULL) goto fail; for (i = 0; i < Cols; i++) PosX[i] = i * gx; PosX[i] = Range.right - Range.left; gy = (Range.bottom - Range.top) / Rows; if ((PosY = new int[Rows + 1]) == NULL) goto fail; for (i = 0; i < Rows; i++) PosY[i] = i * gy; PosY[i] = Range.bottom - Range.top; for (y = 0; y < Rows; y++) { for (x = 0; x < Cols; x++) { switch (et) { case detEdit : dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(dp); break; case detColorChip : dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(dp); break; case detNumber : dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(dp); break; case detFormula : dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1])); Cell->Add(dp); break; // if ((dp = new TPDocNumber(this, Rect(PosX[x], PosY[y], PosX[x + 1], PosY[y + 1]))) == NULL) goto fail; // Cell->Add(dp); } } } return true; fail: RemoveData(); return false; } //--------------------------------------------------------------------------- void __fastcall TPDocChart::SetElement(TPDocElement *Element, TPDocElementType et) { int n; RECT rt; n = FSelectRow * Cols + FSelectCol; TPDocElement *dp = (TPDocElement *)Cell->Items[n]; rt = dp->Range; Cell->Remove(dp); delete dp; switch (et) { case detColorChip: Cell->Insert(n, new TPDocColorChip(Element, rt)); break; case detNumber: Cell->Insert(n, new TPDocNumber(Element, rt)); break; case detFormula: Cell->Insert(n, new TPDocFormula(Element, rt)); break; case detLabel: Cell->Insert(n, new TPDocLabel(Element, rt)); break; case detEdit: Cell->Insert(n, new TPDocEdit(Element, rt)); break; case detImage: Cell->Insert(n, new TPDocImage(Element, rt)); break; } } //--------------------------------------------------------------------------- TPDocElement * __fastcall TPDocChart::GetSelectElement() { int n = FSelectRow * Cols + FSelectCol; TPDocElement *dp; dp = (TPDocElement *)Cell->Items[n]; return dp; } //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintForm(HDC hDC) { int i; TPDocElement *dp; PaintForm(hDC, ConvertRange()); for (i = 0; i < Cell->Count; i++) { dp = (TPDocElement *)Cell->Items[i]; dp->PaintForm(hDC); } } //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; TPDocElement *dp; TEXTMETRIC tm; int i, x, y; char str[5]; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectIn); else PaintRange(hDC, rc); PaintForm(hDC, rc); for (i = 0; i < Cell->Count; i++) { dp = (TPDocElement *)Cell->Items[i]; dp->PaintDesign(hDC, vs, false); } for (i = 0; i < Cols; i++) { x = rc.left + PosX[i]; if (x < rc.right) { sprintf(str, "%c1", 'A'+i); PaintText(hDC, Font, Rect(x, rc.top, rc.left + PosX[i + 1], rc.top + PosY[1]), daRightTop, str); } } for (i = 1; i < Rows; i++) { y = rc.top + PosY[i]; if (y < rc.bottom) { sprintf(str, "A%d", i+1); PaintText(hDC, Font, Rect(rc.left, y, rc.left + PosX[1], rc.top + PosY[i + 1]), daRightTop, str); } } GetTextMetrics(hDC, &tm); PaintText(hDC, Font, Rect(rc.left, rc.top - tm.tmHeight, rc.right, rc.top), daLeftBottom, Format("C%d", OPENARRAY(TVarRec, (FID)))); } //--------------------------------------------------------------------------- void __fastcall TPDocChart::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { int i, j, k, center; double gab; AnsiString C_Value; RECT rc; TPDocElement *dp; int cnt; rc = ConvertRange(&vs); #ifdef KIDO if (EditFormula) { //±âµµ»ê¾÷ÀÇ ÆíÂ÷¿¡ ÀÇÇØ °ªÀÌ °è»êµÇ´Â ºÎºÐ.... if ((Rows == 1) || (Cols < 4)) //ÆíÂ÷¿¡ ÀÇÇØ °è»êµÇ¾îÁú ºÎºÐÀÌ ¾ø´Â°æ¿ìÀ̹ǷΠgoto next; //ÀϹÝÀûÀÎ Chartó·³ Ç¥½Ã.... dp = (TPDocElement *)Cell->Items[Cols]; if(dp->Type != detEdit) //Chart¸¦ Çü½Ä¿¡ ¸Â°Ô ¸¸µéÁö ¸øÇÑ °æ¿ì... goto next; //ÀϹÝÀûÀÎ Chartó·³ Ç¥½Ã.... ((TPDocEdit *)dp)->GetK_Text(C_Value); center = FindCenter(C_Value); // Áß½ÉÀÌ µÇ´Â À§Ä¡¸¦ ±¸ÇÔ.. ResetFormula(); for (j=0; jItems[j*Cols + k]; if (k>1 && dp->Type == detFormula) { // Formula must be setted... /* blocked by k3dogs ÀÚµ¿°è»ê¸¸ µÇ´Â °æ¿ì. SetFormula(j, k, center); } dp->PaintReport(Sender, hDC, vs, bPrint, bselect, language); } */ //==========by k3dogs(20001029) Data°ªÀÌ trueÀ̸é SetFormula¸¦ Áö³ªÃļ­ ÀÚµ¿°è»ê¿¡¼­ Á¦¿ÜµÇ¾î ANumber¸¦ º¸Á¸ÇÑ´Ù. if ( (0<= FSelectRow< Rows) && (0<= FSelectCol< Cols) && (0<= (FSelectRow*Cols+FSelectCol) < Rows*Cols) ) { ((TPDocFormula *)dp)->Data = true; if ( (FSelectCol == 0 && FSelectRow == 1)) { ((TPDocFormula *)dp)->Data = false; } if ( FSelectCol == center || FSelectCol == 1) { if (FSelectRow == j) ((TPDocFormula *)dp)->Data = false; } if ( (((TPDocFormula *)dp)->Data==false) ) SetFormula(j, k, center); } } dp->PaintReport(Sender, hDC, vs, bPrint, bselect, language); } //========================================================= } else { // TPDocEdit·Î¼­ ¹®ÀÚµéÀÌ µé¾î°£´Ù... for (k=0; kItems[k]; dp->PaintReport(Sender, hDC, vs, bPrint, bselect, language); } } } } else { // ÀϹÝÀûÀÎ Â÷Æ®¿Í °°ÀÌ ±×·ÁÁø´Ù. next: for (i = 0; i < Cell->Count; i++) { dp = (TPDocElement *)Cell->Items[i]; dp->PaintReport(Sender, hDC, vs, bPrint, bselect, language); } } #else for (i = 0; i < Cell->Count; i++) { dp = (TPDocElement *)Cell->Items[i]; dp->PaintReport(Sender, hDC, vs, bPrint, bselect, language); } #endif } //--------------------------------------------------------------------------- int __fastcall TPDocChart::FindCenter(AnsiString C_Value) { int i; AnsiString str; TPDocElement *sep; if (C_Value.Length() > 0) { for (i=2; iItems[i]; if (sep->Type == detEdit) { ((TPDocEdit *)sep)->GetK_Text(str); if(C_Value.AnsiCompare(str) == 0) return i; } } return -1; //can't find center..... } else { return -1; //can't find center..... } } //--------------------------------------------------------------------------- void __fastcall TPDocChart::SetFormula(int row, int col, int center) { int gab, absgab, CID; double value; AnsiString ff, txt; TPDocElement *sep; TPDocFormula *fp, *cfp; TPDocNumber *np; if (center == col || center < 0) return; sep = (TPDocElement *)Cell->Items[row*Cols+center]; if (((TPDocFormula *)sep)->ANumber.Length() == 0) return; sep = (TPDocElement *)Cell->Items[col]; ((TPDocEdit *)sep)->GetK_Text(txt); if (txt.Length() == 0) return; sep = (TPDocElement *)Cell->Items[row*Cols+center]; cfp = (TPDocFormula *)sep; sep = (TPDocElement *)Cell->Items[row*Cols+col]; if (sep->Type == detFormula) { fp = (TPDocFormula *)sep; sep = (TPDocElement *)Cell->Items[row*Cols+1]; np = (TPDocNumber *)sep; if (np->Number.Length() > 0) { try { value = StrToFloat(np->Number); gab = col - center; absgab = fabs(gab); CID = cfp->ID; // ¸Å¹ø ãÀ»°ÍÀÌ ¾Æ´Ï¶ó PaintReport¿¡¼­ ã´Â°ÍÀÌ ¾î¶³Áö... if (gab > 0) ff = "+I" + IntToStr(absgab)+ "*I" + FloatToStr(value); else ff = "-I" + IntToStr(absgab)+ "*I" + FloatToStr(value); fp->Formula ="F"+IntToStr(CID) + ff; } catch (EConvertError&) { return; } } } } //--------------------------------------------------------------------------- void __fastcall TPDocChart::ResetFormula() { int i; TPDocElement *sep; for (i=0; iCount; i++) { sep = (TPDocElement *)Cell->Items[i]; if (sep->Type == detFormula) { if (((TPDocFormula *)sep)->Formula.Length() > 0) { ((TPDocFormula *)sep)->Formula = ""; // ((TPDocFormula *)sep)->ANumber = ""; blocked by k3dogs(20001029) } if ( ((TPDocFormula *)sep)->ANumber.Length()<= 0 ) ((TPDocFormula *)sep)->ANumber = ""; //added by k3dogs(20001029) } } } //--------------------------------------------------------------------------- bool __fastcall TPDocChart::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; int i, count; TPDocElement *dp; RECT rc; TPDocElementType et; RemoveData(); if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &FID, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Cols, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Rows, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; #ifdef KIDO if (!ReadFile(hFile, &EditFormula, sizeof(bool), &dwRead, NULL)) return false; #endif PosX = new int[Cols + 1]; if (!ReadFile(hFile, PosX + 1, (Cols - 1) * sizeof(int), &dwRead, NULL)) return false; PosX[0] = 0; PosX[Cols] = Range.right - Range.left; PosY = new int[Rows + 1]; if (!ReadFile(hFile, PosY + 1, (Rows - 1) * sizeof(int), &dwRead, NULL)) return false; PosY[0] = 0; PosY[Rows] = Range.bottom - Range.top; Cell = new TList; for (i = 0; i < Cols * Rows; i++) { if (!ReadFile(hFile, &et, sizeof(TPDocElementType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &rc, sizeof(RECT), &dwRead, NULL)) return false; switch (et) { case detColorChip: dp = new TPDocColorChip(this, rc); break; case detNumber: dp = new TPDocNumber(this, rc); break; case detFormula: dp = new TPDocFormula(this, rc); break; case detLabel: dp = new TPDocLabel(this, rc); break; case detEdit: dp = new TPDocEdit(this, rc); break; case detImage: dp = new TPDocImage(this, rc); break; case detNone: dp = NULL; break; default: dp = NULL; break; } if (dp) { if (!dp->LoadFromFile(hFile, Version)) return false; Cell->Add(dp); } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocChart::SaveToFile(HANDLE hFile) { DWORD dwWrite; int i, count; TPDocElement *dp; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &FID, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Cols, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Rows, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; #ifdef KIDO if (!WriteFile(hFile, &EditFormula, sizeof(bool), &dwWrite, NULL)) return false; #endif if (!WriteFile(hFile, PosX + 1, (Cols - 1) * sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, PosY + 1, (Rows - 1) * sizeof(int), &dwWrite, NULL)) return false; for (i = 0; i < Cell->Count; i++) { dp = (TPDocElement *)Cell->Items[i]; if (!WriteFile(hFile, &dp->Type, sizeof(TPDocElementType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &dp->Range, sizeof(RECT), &dwWrite, NULL)) return false; if (!dp->SaveToFile(hFile)) return false; } return true; } //--------------------------------------------------------------------------- POINT __fastcall TPDocChart::GetRowCol() { return Point(Rows, Cols); } //--------------------------------------------------------------------------- bool __fastcall TPDocChart::isExist(POINT pt) { int i, x, y; if (TPDocElement::isExist(pt)) { for (i = 1; i <= Cols; i++) { x = Range.left + PosX[i]; if (pt.x < x) { FSelectCol = i - 1; break; } } for (i = 1; i <= Rows; i++) { y = Range.top + PosY[i]; if (pt.y < y) { FSelectRow = i - 1; break; } } return true; } return false; } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocChart::GetControlMode(int X, int Y) { int i, px, py; py = Range.top + PosY[1] / 2; for (i = 1; i < Cols; i++) { px = Range.left + PosX[i]; if (px < Range.right) { if (X >= px - 2 && X < px + 3 && Y >= py - 2 && Y < py + 3) { FNumber = i; return dcmHorizental; } } } px = Range.left + PosX[1] / 2; for (i = 1; i < Rows; i++) { py = Range.top + PosY[i]; if (py < Range.bottom) { if (X >= px - 2 && X < px + 3 && Y >= py - 2 && Y < py + 3) { FNumber = i; return dcmVertical; } } } return TPDocElement::GetControlMode(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocChart::GetNewRange(int X, int Y) { switch (ControlMode) { case dcmHorizental: if (X - Range.left < PosX[FNumber - 1] + 3) { FOldPosition = PosX[FNumber - 1] + 3; } else if (X - Range.left >= PosX[FNumber + 1] - 3) { FOldPosition = PosX[FNumber + 1] - 3; } else { FOldPosition = X - Range.left; } break; case dcmVertical: if (Y - Range.top <= PosY[FNumber - 1] + 3) { FOldPosition = PosY[FNumber - 1] + 3; } else if (Y - Range.top >= PosY[FNumber + 1] - 3) { FOldPosition = PosY[FNumber + 1] - 3; } else { FOldPosition = Y - Range.top; } break; default: TPDocElement::GetNewRange(X, Y); break; } } //--------------------------------------------------------------------- void __fastcall TPDocChart::ControlModeMouseDown(int X, int Y) { switch (ControlMode) { case dcmHorizental: FOldPosition = PosX[FNumber]; break; case dcmVertical: FOldPosition = PosY[FNumber]; break; } TPDocElement::ControlModeMouseDown(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocChart::ControlModeMouseMove(HDC hDC, TPDocViewStatus &vs, int X, int Y) { PaintControl(hDC, vs); GetNewRange(X, Y); PaintControl(hDC, vs); } //--------------------------------------------------------------------- void __fastcall TPDocChart::ControlModeMouseUp() { int i, x, y; TPDocObject *dp; switch (ControlMode) { case dcmHorizental: PosX[FNumber] = FOldPosition; break; case dcmVertical: PosY[FNumber] = FOldPosition; break; default: TPDocElement::ControlModeMouseUp(); PosX[Cols] = Range.right - Range.left; PosY[Rows] = Range.bottom - Range.top; break; } for (y = i = 0; y < Rows; y++) { for (x = 0; x < Cols; x++, i++) { dp = (TPDocObject *)Cell->Items[i]; dp->Range.left = PosX[x]; dp->Range.top = PosY[y]; dp->Range.right = PosX[x + 1]; dp->Range.bottom = PosY[y + 1]; } } } //--------------------------------------------------------------------------- // // TPDocArrow // //--------------------------------------------------------------------------- __fastcall TPDocArrow::TPDocArrow(TPDocObject *Sender, RECT rc, TPDocArrowType at, POINT tsp, POINT tep, POINT ttp, TPDocAlign ta, AnsiString t, TColor c) : TPDocText(Sender, detArrow, rc, ta) { Parent = Sender; K_Text = t; Type = at; Color = c; sp = tsp; ep = tep; tp = ttp; //==========================//¸ÇóÀ½ ¼±ÅÃÇßÀ»¶§ controlmodedown¿¡ µé¾î°¡Áö ¸øÇؼ­ FOldArrow[0] = sp; //FOldArrowÀÇ °ªÀÌ Á¤ÇØÁöÁö ¾Ê¾Æ¼­ ±×¸²À» ±×¸®Áö ¸øÇϱ⠶§¹®¿¡.. FOldArrow[1] = ep; //if select at first time, as cannot get into controlmodedown event, FOldArrow is not defined, FOldArrow[2] = tp; //so cannot draw line from sp to ep. //========================== } //-------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- void __fastcall TPDocArrow::PaintSelectIn(HDC hDC, void *data) { POINT ttp; int tx, ty; ArrowData *ad = (ArrowData *)data; Rectangle(hDC, ad->fad.x-2, ad->fad.y-2, ad->fad.x+3, ad->fad.y+3); Rectangle(hDC, ad->ead.x-2, ad->ead.y-2, ad->ead.x+3, ad->ead.y+3); if (Type == dat3Point) { Rectangle(hDC, ad->tad.x-2, ad->tad.y-2, ad->tad.x+3, ad->tad.y+3); } } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; int nOldROP = 0; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); nOldROP = SetROP2(hDC, R2_NOT); MoveToEx(hDC, vs.Pattern2ViewX(FOldArrow[0].x), vs.Pattern2ViewY(FOldArrow[0].y), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldArrow[1].x), vs.Pattern2ViewY(FOldArrow[1].y)); if (Type == dat3Point) { LineTo(hDC, vs.Pattern2ViewX(FOldArrow[2].x), vs.Pattern2ViewY(FOldArrow[2].y)); } } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::PaintForm(HDC hDC) { } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { HPEN hPen = NULL, hOldPen = NULL; HBRUSH hBrush = NULL, hOldBrush = NULL; RECT rc; POINT pt[3], mp, ssp, eep, ttp; double theta, yy, ty, tx; ArrowData AD, TD; AnsiString Text; TPDocViewStatus vsc(vs.Position); if (ControlMode != dcmNone) { PaintControl(hDC, vsc); return; } if (bselect) { PaintControl(hDC, vsc); AD.fad = ConvertPoint(FOldArrow[0], &vs); AD.ead = ConvertPoint(FOldArrow[1], &vs); if (Type == dat3Point) { AD.tad = ConvertPoint(FOldArrow[2], &vs); } PaintSelectReport(hDC, &AD, &PaintSelectIn); ArrowTextOut(hDC, &AD, language); return; } AD.fad = ConvertPoint(sp, &vs); AD.ead = ConvertPoint(ep, &vs); if (Type == dat3Point) { AD.tad = ConvertPoint(tp, &vs); } try { hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); hBrush = CreateSolidBrush(Color); hOldBrush = SelectObject(hDC, hBrush); MoveToEx(hDC, AD.fad.x, AD.fad.y, NULL); LineTo(hDC, AD.ead.x, AD.ead.y); if (Type == dat3Point) { LineTo(hDC, AD.tad.x, AD.tad.y); } DrawArrow(hDC, &AD); if (Type == datBoth_Normal || Type == datBoth_Hor_Over || Type == datBoth_Hor_Below || Type == datBoth_Ver_Left || Type == datBoth_Ver_Right) { DrawAddedLine(hDC, &AD); TD.fad = AD.ead; TD.ead = AD.fad; DrawArrow(hDC, &TD); } ArrowTextOut(hDC, &AD, language); } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hBrush) DeleteObject(hBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::DrawArrow(HDC hDC, ArrowData *AD) { double theta, tx, ty, yy; POINT pt[3]; HPEN hPen = NULL, hOldPen = NULL; HBRUSH hBrush = NULL, hOldBrush = NULL; pt[0] = AD->fad; if (AD->fad.x == AD->ead.x) { if (AD->fad.y < AD->ead.y) { pt[1] = Point(AD->fad.x-3, AD->fad.y+6); pt[2] = Point(AD->fad.x+3, AD->fad.y+6); } else { pt[1] = Point(AD->fad.x-3, AD->fad.y-6); pt[2] = Point(AD->fad.x+3, AD->fad.y-6); } } else if (AD->fad.y == AD->ead.y) { if (AD->fad.x < AD->ead.x) { pt[1] = Point(AD->fad.x+6, AD->fad.y-3); pt[2] = Point(AD->fad.x+6, AD->fad.y+3); } else { pt[1] = Point(AD->fad.x-6, AD->fad.y-3); pt[2] = Point(AD->fad.x-6, AD->fad.y+3); } } else { theta = atan(double(AD->fad.y-AD->ead.y) / (AD->ead.x-AD->fad.x)); yy = 6*fabs(sin(theta)); ty = 3*cos(theta); tx = 3*fabs(sin(theta)); if (AD->fad.x < AD->ead.x) { if (AD->fad.y < AD->ead.y) { pt[1] = Point(AD->fad.x+6*cos(theta)-tx, AD->fad.y+yy+ty); pt[2] = Point(AD->fad.x+6*cos(theta)+tx, AD->fad.y+yy-ty); } else { pt[1] = Point(AD->fad.x+6*cos(theta)-tx, AD->fad.y-yy-ty); pt[2] = Point(AD->fad.x+6*cos(theta)+tx, AD->fad.y-yy+ty); } } else { if (AD->fad.y < AD->ead.y) { pt[1] = Point(AD->fad.x-6*cos(theta)-tx, AD->fad.y+yy-ty); pt[2] = Point(AD->fad.x-6*cos(theta)+tx, AD->fad.y+yy+ty); } else { pt[1] = Point(AD->fad.x-6*cos(theta)-tx, AD->fad.y-yy+ty); pt[2] = Point(AD->fad.x-6*cos(theta)+tx, AD->fad.y-yy-ty); } } } Polygon(hDC, pt, 3); } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::ArrowTextOut(HDC hDC, ArrowData *AD, int language) { int th; HFONT hOldFont; WORD wAlign; AnsiString Text; switch(language) { case 0: Text = K_Text; break; case 1: Text = E_Text; break; case 2: Text = I_Text; break; case 3: Text = C_Text; break; case 4: Text = J_Text; break; } try { hOldFont = SelectObject(hDC, Font->Handle); SetBkMode(hDC, TRANSPARENT); wAlign = GetTextAlign(hDC); SetTextColor(hDC, Font->Color); if (Type == datSingle) { if (AD->fad.x == AD->ead.x) { SetTextAlign(hDC, TA_CENTER); } else { if (AD->fad.x < AD->ead.x) { SetTextAlign(hDC, TA_LEFT); } else { SetTextAlign(hDC, TA_RIGHT); } } } else if (Type == datBoth_Normal || Type == datBoth_Hor_Over || Type == datBoth_Hor_Below) { SetTextAlign(hDC, TA_CENTER); } else if (Type == datBoth_Ver_Left) { //È­»ìÇ¥ÀÇ ¿ÞÂÊÀ¸·Î ±ÛÀ» ¾´´Ù. SetTextAlign(hDC, TA_RIGHT); } else if (Type == datBoth_Ver_Right) { //È­»ìÇ¥ÀÇ ¿À¸¥ÂÊÀ¸·Î ±ÛÀ» ¾´´Ù. SetTextAlign(hDC, TA_LEFT); } else if (Type == dat3Point) { if (AD->ead.x < AD->tad.x) { SetTextAlign(hDC, TA_LEFT); } else { SetTextAlign(hDC, TA_RIGHT); } } DrawText(hDC, AD, Text); SetTextAlign(hDC, wAlign); } __finally { if (hOldFont) SelectObject(hDC, hOldFont); } } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::DrawText(HDC hDC, ArrowData *AD, AnsiString Text) { TEXTMETRIC tm; int i=0, len = 0, lcnt, both = 1; char *sp, *tp, *ep; POINT tsp; AnsiString str; int sum=0, ts = 0; GetTextMetrics(hDC, &tm); tsp = AD->ead; lcnt = FindLineCount(Text); // ±Û¾¾ÀÇ ³ôÀ̸¸Å­ À§¿¡¼­ ½ÃÀÛ. switch (Type) { case datSingle: if (AD->ead.x == AD->fad.x) { if (AD->ead.y > AD->fad.y) { lcnt = 0; tsp.y += 2; } } else { tsp.y -= tm.tmHeight/2; if (AD->ead.x > AD->fad.x) tsp.x += 2; else tsp.x -= 2; lcnt = lcnt/2; } break; case datBoth_Normal: both = 2; tsp.x = (AD->fad.x + AD->ead.x)/2; tsp.y = (AD->fad.y + AD->ead.y)/2; break; case datBoth_Hor_Over: tsp.x = (AD->fad.x + AD->ead.x)/2; break; case datBoth_Hor_Below: lcnt = 0; tsp.x = (AD->fad.x + AD->ead.x)/2; tsp.y += 2; break; case datBoth_Ver_Left: both = 2; tsp.x -= 2; tsp.y = (AD->fad.y + AD->ead.y - tm.tmHeight)/2; break; case datBoth_Ver_Right: both = 2; tsp.x += 2; tsp.y = (AD->fad.y + AD->ead.y - tm.tmHeight)/2; break; case dat3Point: // ÇØÁÙ°Ô ¾ø´ç.... break; } sp = Text.c_str(); ep = sp; tp = strchr(ep, '\n'); while(tp != NULL) { len = tp - ep - 1; // Range of rc is right??? ExtTextOut(hDC, tsp.x, tsp.y - tm.tmHeight*(lcnt/both - i), ETO_CLIPPED, NULL, ep, len, NULL); i++; ep = tp + 1; tp = strchr(ep, '\n'); } if (*ep) { // when text is not ended with null character!! len = Text.Length() - (ep - sp); ExtTextOut(hDC, tsp.x, tsp.y - tm.tmHeight*(lcnt/both - i), ETO_CLIPPED, NULL, ep, len, NULL); } } //-------------------------------------------------------------------------- int __fastcall TPDocArrow::FindLineCount(AnsiString Text) { char *sp, *ep, *tp; int i=0; sp = Text.c_str(); ep = sp; tp = strchr(ep, '\n'); while(tp != NULL) { i++; ep = tp + 1; tp = strchr(ep, '\n'); } i++; return i; } //-------------------------------------------------------------------------- void __fastcall TPDocArrow::DrawAddedLine(HDC hDC, ArrowData *AD) { double theta, slope, xx, yy; POINT pt[4]; if (AD->fad.x == AD->ead.x) { pt[0] = Point(AD->fad.x-10, AD->fad.y); pt[1] = Point(AD->fad.x+10, AD->fad.y); pt[2] = Point(AD->ead.x-10, AD->ead.y); pt[3] = Point(AD->ead.x+10, AD->ead.y); } else if (AD->fad.y == AD->ead.y) { pt[0] = Point(AD->fad.x, AD->fad.y-10); pt[1] = Point(AD->fad.x, AD->fad.y+10); pt[2] = Point(AD->ead.x, AD->ead.y-10); pt[3] = Point(AD->ead.x, AD->ead.y+10); } else { theta = atan(double(AD->fad.y-AD->ead.y) / (AD->ead.x-AD->fad.x)); yy = 10*fabs(cos(theta)); xx = 10*fabs(sin(theta)); slope = double(AD->fad.y-AD->ead.y) / (AD->ead.x-AD->fad.x); if (slope < 0) xx = -xx; //slope¿¡ µû¶ó xx °ªÀÌ ¹Ù²î¾î¾ßÇÑ´Ù. pt[0] = Point(AD->fad.x-xx, AD->fad.y-yy); pt[1] = Point(AD->fad.x+xx, AD->fad.y+yy); pt[2] = Point(AD->ead.x-xx, AD->ead.y-yy); pt[3] = Point(AD->ead.x+xx, AD->ead.y+yy); } MoveToEx(hDC, pt[0].x, pt[0].y, NULL); LineTo(hDC, pt[1].x, pt[1].y); MoveToEx(hDC, pt[2].x, pt[2].y, NULL); LineTo(hDC, pt[3].x, pt[3].y); } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::SetText(AnsiString kt, AnsiString et, AnsiString it, AnsiString ct, AnsiString jt) { K_Text = kt; E_Text = et; I_Text = it; C_Text = ct; J_Text = jt; } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::GetText(AnsiString &kt, AnsiString &et, AnsiString &it, AnsiString &ct, AnsiString &jt) { kt = K_Text; et = E_Text; it = I_Text; ct = C_Text; jt = J_Text; } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::SetK_Text(AnsiString kt) { if (kt.Length() == 0) { E_Text = ""; I_Text = ""; C_Text = ""; J_Text = ""; } K_Text = kt; } //--------------------------------------------------------------------------- void __fastcall TPDocArrow::GetK_Text(AnsiString &kt) { kt = K_Text; } //--------------------------------------------------------------------------- bool __fastcall TPDocArrow::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; /* if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, Text)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Type, sizeof(TPDocArrowType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &sp, sizeof(POINT), &dwRead, NULL)) return false; if (!ReadFile(hFile, &ep, sizeof(POINT), &dwRead, NULL)) return false; if (Type == dat3Point) { if (!ReadFile(hFile, &tp, sizeof(POINT), &dwRead, NULL)) return false; } return true; */ if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (Version <= 5) { if (!TextLoadFromFile(hFile, K_Text)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Type, sizeof(TPDocArrowType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &sp, sizeof(POINT), &dwRead, NULL)) return false; if (!ReadFile(hFile, &ep, sizeof(POINT), &dwRead, NULL)) return false; if (Type == dat3Point) { if (!ReadFile(hFile, &tp, sizeof(POINT), &dwRead, NULL)) return false; } } else { if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Type, sizeof(TPDocArrowType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &sp, sizeof(POINT), &dwRead, NULL)) return false; if (!ReadFile(hFile, &ep, sizeof(POINT), &dwRead, NULL)) return false; if (Type == dat3Point) { if (!ReadFile(hFile, &tp, sizeof(POINT), &dwRead, NULL)) return false; } if (!TextLoadFromFile(hFile, K_Text)) return false; if (!TextLoadFromFile(hFile, E_Text)) return false; if (!TextLoadFromFile(hFile, I_Text)) return false; if (!TextLoadFromFile(hFile, C_Text)) return false; if (!TextLoadFromFile(hFile, J_Text)) return false; } //by k3dogs(20001029)arrow ÃʱâÈ­°¡ µÇÁö ¾Ê¾Æ¼­. »ý¼ºÀÚ¿¡ ÀÖ¾î¾ß Çϴµ¥ TPDocElement »ý¼ºÀÚ°¡ ¸¶¶¥Ä¡ ¾Ê¾Æ ¿©±â ³Ö¾ú´Ù. //==========================//¸ÇóÀ½ ¼±ÅÃÇßÀ»¶§ controlmodedown¿¡ µé¾î°¡Áö ¸øÇؼ­ FOldArrow[0] = sp; //FOldArrowÀÇ °ªÀÌ Á¤ÇØÁöÁö ¾Ê¾Æ¼­ ±×¸²À» ±×¸®Áö ¸øÇϱ⠶§¹®¿¡.. FOldArrow[1] = ep; //if select at first time, as cannot get into controlmodedown event, FOldArrow is not defined, FOldArrow[2] = tp; //so cannot draw line from sp to ep. //========================== return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocArrow::SaveToFile(HANDLE hFile) { DWORD dwWrite; /* if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, Text)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Type, sizeof(TPDocArrowType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &sp, sizeof(POINT), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &ep, sizeof(POINT), &dwWrite, NULL)) return false; if (Type == dat3Point) { if (!WriteFile(hFile, &tp, sizeof(POINT), &dwWrite, NULL)) return false; } return true; */ if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Type, sizeof(TPDocArrowType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &sp, sizeof(POINT), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &ep, sizeof(POINT), &dwWrite, NULL)) return false; if (Type == dat3Point) { if (!WriteFile(hFile, &tp, sizeof(POINT), &dwWrite, NULL)) return false; } if (!TextSaveToFile(hFile, K_Text)) return false; if (!TextSaveToFile(hFile, E_Text)) return false; if (!TextSaveToFile(hFile, I_Text)) return false; if (!TextSaveToFile(hFile, C_Text)) return false; if (!TextSaveToFile(hFile, J_Text)) return false; return true; } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocArrow::GetControlMode(int X, int Y) { TPDocControlMode dcm; if ((X >= sp.x-2) && (X < sp.x+3) && (Y >= sp.y-2) && (Y < sp.y+3)) { return dcmFirst; } if (Type == dat3Point) { if ((X >= tp.x-2) && (X < tp.x+3) && (Y >= tp.y-2) && (Y < tp.y+3)) { return dcmMedium; } } if ((X >= ep.x-2) && (X < ep.x+3) && (Y >= ep.y-2) && (Y < ep.y+3)) { return dcmLast; } return X >= Range.left && Y >= Range.top && X <= Range.right && Y <= Range.bottom ? dcmMove : dcmNone; } //--------------------------------------------------------------------- void __fastcall TPDocArrow::GetNewRange(int X, int Y) { int tx, ty; bool bfrect = true; switch (ControlMode) { case dcmFirst: switch (Type) { case datSingle: case datBoth_Normal: case dat3Point: FOldArrow[0] = Point(X, Y); break; case datBoth_Hor_Over: case datBoth_Hor_Below: FOldArrow[0] = Point(X, FOldArrow[0].y); break; case datBoth_Ver_Left: case datBoth_Ver_Right: FOldArrow[0] = Point(FOldArrow[0].x, Y); break; } break; case dcmMedium: FOldArrow[2] = Point(X, Y); FOldArrow[1].y = FOldArrow[2].y; break; case dcmLast: switch (Type) { case datSingle: case datBoth_Normal: FOldArrow[1] = Point(X, Y); break; case datBoth_Hor_Over: case datBoth_Hor_Below: FOldArrow[1] = Point(X, FOldArrow[1].y); break; case datBoth_Ver_Left: case datBoth_Ver_Right: FOldArrow[1] = Point(FOldArrow[1].x, Y); break; case dat3Point: FOldArrow[1] = Point(X, Y); FOldArrow[2].y = FOldArrow[1].y; break; } break; case dcmMove: tx = X - FOldPoint.x; ty = Y - FOldPoint.y; FOldArrow[0] = Point(sp.x+tx, sp.y+ty); FOldArrow[1] = Point(ep.x+tx, ep.y+ty); if (Type == dat3Point) { FOldArrow[2] = Point(tp.x+tx, tp.y+ty); } FOldRect = Rect(Range.left+tx, Range.top+ty, Range.right+tx, Range.bottom+ty); bfrect = false; break; } if (bfrect) { FOldRect = ReArrangeRect(false); } } //--------------------------------------------------------------------- void __fastcall TPDocArrow::ControlModeMouseDown(int X, int Y) { FOldArrow[0] = sp; FOldArrow[1] = ep; if (Type == dat3Point) { FOldArrow[2] = tp; } FOldRect = Range; FOldPoint = Point(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocArrow::ControlModeMouseMove(HDC hDC, TPDocViewStatus &vs, int X, int Y) { PaintControl(hDC, vs); GetNewRange(X, Y); PaintControl(hDC, vs); } //--------------------------------------------------------------------- void __fastcall TPDocArrow::ControlModeMouseUp() { bool bfrect = true; switch (ControlMode) { case dcmFirst: sp = FOldArrow[0]; break; case dcmMedium: tp = FOldArrow[2]; ep = FOldArrow[1]; break; case dcmLast: ep = FOldArrow[1]; if (Type == dat3Point) { tp = FOldArrow[2]; } break; case dcmMove: sp = FOldArrow[0]; ep = FOldArrow[1]; if (Type == dat3Point) { tp = FOldArrow[2]; } Range = FOldRect; bfrect = false; break; } if (bfrect) { Range = ReArrangeRect(true); } //qe È­»ìÇ¥ÀÇ ½¬¿î Ȱ¼ºÈ­¸¦ À§ÇØ ¹üÀ§¸¦ ³ÐÈù´Ù. if((Range.right - Range.left) < 8 ){ Range.left = Range.left -5; Range.right = Range.right + 5; } if((Range.bottom - Range.top) < 8){ Range.top = Range.top - 5; Range.bottom = Range.bottom + 5; } } //--------------------------------------------------------------------------- RECT __fastcall TPDocArrow::ReArrangeRect(bool breal) { long tx, ty; POINT pt[3]; RECT rt; if (breal) { pt[0] = sp; pt[1] = ep; if (Type == dat3Point) { pt[2] = tp; } } else { pt[0] = FOldArrow[0]; pt[1] = FOldArrow[1]; if (Type == dat3Point) { pt[2] = FOldArrow[2]; } } if (Type == dat3Point) { /* tx = min(pt[0].x, pt[1].x); tx = min(pt[2].x, tx); ty = min(pt[0].y, pt[1].y); ty = min(pt[2].y, ty); rt.left = tx; rt.top = ty; tx = max(pt[0].x, pt[1].x); tx = max(pt[2].x, tx); ty = max(pt[0].y, pt[1].y); ty = max(pt[2].y, ty); rt.right = tx; rt.bottom = ty; */ } else { if (pt[0].x < pt[1].x) { rt.left = pt[0].x; rt.right = pt[1].x; } else { rt.left = pt[1].x; rt.right = pt[0].x; } if (pt[0].y < pt[1].y) { rt.top = pt[0].y; rt.bottom = pt[1].y; } else { rt.top = pt[1].y; rt.bottom = pt[0].y; } } return rt; } //--------------------------------------------------------------------------- // // TPDocSheafImage // //--------------------------------------------------------------------------- __fastcall TPDocSheafImage::TPDocSheafImage(TPDocObject *Sender, RECT rc) : TPDocText(Sender, detSheafImage, rc) //TPDocElement(detSheafImage, rc) { Parent = Sender; Image = NULL; FOldRect = Range; // SelectedÀÎ °æ¿ì¿¡PaintControl¿¡¼­ FOldRect¸¦ ÃʱâÈ­ÇØÁà¾ßÇÔ.... } //--------------------------------------------------------------------------- __fastcall TPDocSheafImage::~TPDocSheafImage() { if (Image) delete Image; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocSheafImage::PaintForm(HDC hDC) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafImage::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafImage::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { RECT rc; TSize s; HPEN hPen = NULL, hOldPen = NULL; HBRUSH hOldBrush = NULL; TPDocViewStatus vsc(vs.Position); if (ControlMode != dcmNone) { PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bselect) { PaintControl(hDC, vsc); // ÇÊ¿äÇѰ¡?? ¾ø´ø°Å °°Àºµ¥... // ¸Ç óÀ½ÀÇ °æ¿ì FOldRect°¡ ÃʱâÈ­ µÇ¾î¾ß ÇÔ->»ý¼ºÀÚ¿¡... PaintSelect(hDC, rc, &PaintSelectInCommon); return; } if (Image) { s.cx = rc.right - rc.left - 6; // ¿©À¯ºÐÀ» ³Ö¾îÁÜ. s.cy = rc.bottom - rc.top - 6; PaintImage(hDC, Image, s, rc.left + 3, rc.top + 3); } #ifndef KIDO if (!bPrint) { try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); hOldBrush = SelectObject(hDC, GetStockObject(NULL_BRUSH)); Rectangle(hDC, rc.left, rc.top, rc.right+1, rc.bottom+1); } __finally { if (hOldBrush) SelectObject(hDC, hOldBrush); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } #endif } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafImage::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; TColor C; if (Version >= 5) { if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!ReadFile(hFile, &Zoom, sizeof(int), &dwRead, NULL)) return false; if (!TextLoadFromFile(hFile, ImgDir)) return false; if (!ImageLoadFromFile(hFile, Image)) return false; } else { if (!ReadFile(hFile, &Zoom, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &C, sizeof(TColor), &dwRead, NULL)) return false; if (!ImageLoadFromFile(hFile, Image)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafImage::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!WriteFile(hFile, &Zoom, sizeof(int), &dwWrite, NULL)) return false; if (!TextSaveToFile(hFile, ImgDir)) return false; if (!ImageSaveToFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocSheafLabel // //--------------------------------------------------------------------------- __fastcall TPDocSheafLabel::TPDocSheafLabel(TPDocObject *Sender, RECT rc, TPDocAlign ta, AnsiString t) : TPDocText(Sender, detSheafLabel, rc, ta) { K_Text = t; FOldRect = Range; // PaintControl¿¡¼­ ÃʱâÈ­ µÇ¾îÀÖ¾î¾ß ¿¡·¯¹ß»ýÀÌ ¾ÈµÊ... } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- /*void __fastcall TPDocSheafLabel::PaintForm(HDC hDC, RECT rc) { } */ //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::PaintForm(HDC hDC) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { RECT rc; AnsiString Text; TPDocViewStatus vsc(vs.Position); if (ControlMode != dcmNone) { PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); switch (language) { case 0: Text = K_Text; break; case 1: Text = E_Text; break; case 2: Text = I_Text; break; case 3: Text = C_Text; break; case 4: Text = J_Text; break; } if (bselect) { PaintControl(hDC, vsc); // ¸Ç óÀ½¿¡ FOldRect°¡ ÃʱâÈ­ µÇ¾îÀÖ¾î¾ß ÇÔ.-->»ý¼ºÀÚ¿¡¼­.... if (Text.Length() > 0) PaintText(hDC, Font, rc, Align, Text, true); PaintSelect(hDC, rc, &PaintSelectInCommon); return; } #ifndef KIDO if (!bPrint) PaintFrame(hDC, rc, dlsOne, clBlack); // right Range?? && be viewed in ReportTool #endif if (Text.Length() > 0) { PaintText(hDC, Font, rc, Align, Text, true); } } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::SetText(AnsiString kt, AnsiString et, AnsiString it, AnsiString ct, AnsiString jt) { K_Text = kt; E_Text = et; I_Text = it; C_Text = ct; J_Text = jt; } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::GetText(AnsiString &kt, AnsiString &et, AnsiString &it, AnsiString &ct, AnsiString &jt) { kt = K_Text; et = E_Text; it = I_Text; ct = C_Text; jt = J_Text; } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::SetK_Text(AnsiString kt) { if (kt.Length() == 0) { E_Text = ""; I_Text = ""; C_Text = ""; J_Text = ""; } K_Text = kt; } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLabel::GetK_Text(AnsiString &kt) { kt = K_Text; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafLabel::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!TPDocText::LoadFromFile(hFile, Version)) return false; if (!TextLoadFromFile(hFile, K_Text)) return false; if (!TextLoadFromFile(hFile, E_Text)) return false; if (!TextLoadFromFile(hFile, I_Text)) return false; if (!TextLoadFromFile(hFile, C_Text)) return false; if (!TextLoadFromFile(hFile, J_Text)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafLabel::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!TPDocText::SaveToFile(hFile)) return false; if (!TextSaveToFile(hFile, K_Text)) return false; if (!TextSaveToFile(hFile, E_Text)) return false; if (!TextSaveToFile(hFile, I_Text)) return false; if (!TextSaveToFile(hFile, C_Text)) return false; if (!TextSaveToFile(hFile, J_Text)) return false; return true; } //--------------------------------------------------------------------------- // // TPDocImage // //--------------------------------------------------------------------------- #ifdef KIDO __fastcall TPDocTextImage::TPDocTextImage(TPDocObject *Sender, RECT rc) : TPDocElement(detTextImage, rc) { Image = NULL; } //--------------------------------------------------------------------------- __fastcall TPDocTextImage::~TPDocTextImage() { if (Image) delete Image; } //--------------------------------------------------------------------------- void __fastcall TPDocTextImage::PaintForm(HDC hDC, RECT rc) { PaintFrame(hDC, rc); } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocTextImage::PaintForm(HDC hDC) { PaintForm(hDC, ConvertRange()); } //--------------------------------------------------------------------------- void __fastcall TPDocTextImage::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { RECT rc; TSize s; if (ControlMode != dcmNone) { TPDocViewStatus vsc(vs.Position); PaintControl(hDC, vsc); return; } rc = ConvertRange(&vs); if (bSelect) PaintSelect(hDC, rc, &PaintSelectInCommon); else PaintRange(hDC, rc); PaintForm(hDC, rc); } //--------------------------------------------------------------------------- void __fastcall TPDocTextImage::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { RECT rc; TSize s; if (Image) { rc = ConvertRange(&vs); s.cx = rc.right - rc.left - 6; // ¿©À¯ºÐÀ» ³Ö¾îÁÜ. s.cy = rc.bottom - rc.top - 6; PaintImage(hDC, Image, s, rc.left + 3, rc.top + 3); } } //--------------------------------------------------------------------------- bool __fastcall TPDocTextImage::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!ReadFile(hFile, &Zoom, sizeof(int), &dwRead, NULL)) return false; if (!ImageLoadFromFile(hFile, Image)) return false; return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocTextImage::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!WriteFile(hFile, &Zoom, sizeof(int), &dwWrite, NULL)) return false; if (!ImageSaveToFile(hFile, Image)) return false; return true; } #endif //--------------------------------------------------------------------------- // // TPDocSheafLine // //--------------------------------------------------------------------------- __fastcall TPDocSheafLine::TPDocSheafLine(TPDocObject *Sender, RECT rc, TPDocSheafLineType lt, POINT tsp, POINT tep, TColor c) : TPDocElement(detSheafLine, rc) { Parent = Sender; Type = lt; Color = c; sp = tsp; ep = tep; FOldArrow[0] = sp; FOldArrow[1] = ep; } //--------------------------------------------------------------------------- // Private Methods //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintForm(HDC hDC, RECT rc) { } //--------------------------------------------------------------------------- // Protected Methods //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintSelectIn(HDC hDC, void *data) { ArrowData *ad = (ArrowData *)data; Rectangle(hDC, ad->fad.x-2, ad->fad.y-2, ad->fad.x+3, ad->fad.y+3); Rectangle(hDC, ad->ead.x-2, ad->ead.y-2, ad->ead.x+3, ad->ead.y+3); } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintControl(HDC hDC, TPDocViewStatus &vs) { HPEN hPen = NULL, hOldPen = NULL; int nOldROP = 0; try { hPen = CreatePen(psSolid, 1, clBlack); hOldPen = SelectObject(hDC, hPen); nOldROP = SetROP2(hDC, R2_NOT); MoveToEx(hDC, vs.Pattern2ViewX(FOldArrow[0].x), vs.Pattern2ViewY(FOldArrow[0].y), NULL); LineTo(hDC, vs.Pattern2ViewX(FOldArrow[1].x), vs.Pattern2ViewY(FOldArrow[1].y)); } __finally { if (nOldROP) SetROP2(hDC, nOldROP); if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintForm(HDC hDC) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintDesign(HDC hDC, TPDocViewStatus &vs, bool bSelect) { } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::PaintReport(TPDocObject *Sender, HDC hDC, TPDocViewStatus &vs, bool bPrint, bool bselect, int language) { RECT rc; ArrowData AD; TPDocViewStatus vsc(vs.Position); if (ControlMode != dcmNone) { PaintControl(hDC, vsc); return; } if (bselect) { PaintControl(hDC, vsc); AD.fad = ConvertPoint(FOldArrow[0], &vs); AD.ead = ConvertPoint(FOldArrow[1], &vs); PaintSelectReport(hDC, &AD, &PaintSelectIn); return; } DrawLine(hDC, &vs); } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::DrawLine(HDC hDC, TPDocViewStatus *vs) { HPEN hPen = NULL, hOldPen = NULL; POINT csp, cep; csp = ConvertPoint(sp, vs); cep = ConvertPoint(ep, vs); try { switch (Type) { case dsltNormal: hPen = CreatePen(psSolid, 1, Color); hOldPen = SelectObject(hDC, hPen); break; case dsltDash: hPen = CreatePen(psDash, 1, Color); hOldPen = SelectObject(hDC, hPen); break; case dsltThick: hPen = CreatePen(psSolid, 3, Color); hOldPen = SelectObject(hDC, hPen); break; } MoveToEx(hDC, csp.x, csp.y, NULL); LineTo(hDC, cep.x, cep.y); } __finally { if (hOldPen) SelectObject(hDC, hOldPen); if (hPen) DeleteObject(hPen); } } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafLine::LoadFromFile(HANDLE hFile, int Version) { DWORD dwRead; if (!ReadFile(hFile, &Type, sizeof(TPDocLineType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &Color, sizeof(TColor), &dwRead, NULL)) return false; if (!ReadFile(hFile, &sp, sizeof(POINT), &dwRead, NULL)) return false; if (!ReadFile(hFile, &ep, sizeof(POINT), &dwRead, NULL)) return false; //by k3dogs(20001029)arrow ÃʱâÈ­°¡ µÇÁö ¾Ê¾Æ¼­. »ý¼ºÀÚ¿¡ ÀÖ¾î¾ß ÇÑ´Ù°í ÇÔ. //==========================//¸ÇóÀ½ ¼±ÅÃÇßÀ»¶§ controlmodedown¿¡ µé¾î°¡Áö ¸øÇؼ­ FOldArrow[0] = sp; //FOldArrowÀÇ °ªÀÌ Á¤ÇØÁöÁö ¾Ê¾Æ¼­ ±×¸²À» ±×¸®Áö ¸øÇϱ⠶§¹®¿¡.. FOldArrow[1] = ep; //if select at first time, as cannot get into controlmodedown event, FOldArrow is not defined, //so cannot draw line from sp to ep. //========================== return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheafLine::SaveToFile(HANDLE hFile) { DWORD dwWrite; if (!WriteFile(hFile, &Type, sizeof(TPDocLineType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Color, sizeof(TColor), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &sp, sizeof(POINT), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &ep, sizeof(POINT), &dwWrite, NULL)) return false; return true; } //--------------------------------------------------------------------------- TPDocControlMode __fastcall TPDocSheafLine::GetControlMode(int X, int Y) { TPDocControlMode dcm; if ((X > sp.x-2) && (X < sp.x+3) && (Y > sp.y-2) && (Y < sp.y+3)) return dcmFirst; if ((X > ep.x-2) && (X < ep.x+3) && (Y > ep.y-2) && (Y < ep.y+3)) return dcmLast; return X >= Range.left && Y >= Range.top && X <= Range.right && Y <= Range.bottom ? dcmMove : dcmNone; } //--------------------------------------------------------------------------- void __fastcall TPDocSheafLine::GetNewRange(int X, int Y) { int tx, ty; bool bfrect = true; switch (ControlMode) { case dcmFirst: FOldArrow[0] = Point(X, Y); break; case dcmLast: FOldArrow[1] = Point(X, Y); break; case dcmMove: tx = X - FOldPoint.x; ty = Y - FOldPoint.y; FOldArrow[0] = Point(sp.x+tx, sp.y+ty); FOldArrow[1] = Point(ep.x+tx, ep.y+ty); FOldRect = Rect(Range.left+tx, Range.top+ty, Range.right+tx, Range.bottom+ty); bfrect = false; break; } if (bfrect) { FOldRect = ReArrangeRect(false); } } //--------------------------------------------------------------------- void __fastcall TPDocSheafLine::ControlModeMouseDown(int X, int Y) { FOldArrow[0] = sp; FOldArrow[1] = ep; FOldRect = Range; FOldPoint = Point(X, Y); } //--------------------------------------------------------------------- void __fastcall TPDocSheafLine::ControlModeMouseMove(HDC hDC, TPDocViewStatus &vs, int X, int Y) { PaintControl(hDC, vs); GetNewRange(X, Y); PaintControl(hDC, vs); } //--------------------------------------------------------------------- void __fastcall TPDocSheafLine::ControlModeMouseUp() { bool bfrect = true; switch (ControlMode) { case dcmFirst: sp = FOldArrow[0]; break; case dcmLast: ep = FOldArrow[1]; break; case dcmMove: sp = FOldArrow[0]; ep = FOldArrow[1]; Range = FOldRect; bfrect = false; break; } if (bfrect) { Range = ReArrangeRect(true); } //qe ¶óÀÎÀÇ ½¬¿î Ȱ¼ºÈ­¸¦ À§ÇØ ¹üÀ§¸¦ ³ÐÈù´Ù. if((Range.right - Range.left) < 8 ){ Range.left = Range.left -5; Range.right = Range.right + 5; } if((Range.bottom - Range.top) < 8){ Range.top = Range.top - 5; Range.bottom = Range.bottom + 5; } } //--------------------------------------------------------------------------- RECT __fastcall TPDocSheafLine::ReArrangeRect(bool breal) { long tx, ty; POINT pt[2]; RECT rt; if (breal) { pt[0] = sp; pt[1] = ep; } else { pt[0] = FOldArrow[0]; pt[1] = FOldArrow[1]; } if (pt[0].x < pt[1].x) { rt.left = pt[0].x; rt.right = pt[1].x; } else { rt.left = pt[1].x; rt.right = pt[0].x; } if (pt[0].y < pt[1].y) { rt.top = pt[0].y; rt.bottom = pt[1].y; } else { rt.top = pt[1].y; rt.bottom = pt[0].y; } return rt; } //--------------------------------------------------------------------------- // // TPDocCommonData // //--------------------------------------------------------------------------- __fastcall TPDocCommonData::TPDocCommonData() { Type = detNone; Data = NULL; } //--------------------------------------------------------------------------- __fastcall TPDocCommonData::TPDocCommonData(TPDocElementType t, int id) { Type = t; ID = id; switch (Type) { case detColorChip: Data = new TColor; *(TColor *)Data = clWhite; // colorchipÀÌ ÀÓÀÇÀÇ Ä®¶ó·Î ä¿öÁö´Â °ÍÀ» ¸·±âÀ§ÇØ. break; case detEdit: case detNumber: case detFormula: case detDate: Data = new AnsiString; break; default: Data = NULL; break; } } //--------------------------------------------------------------------------- __fastcall TPDocCommonData::~TPDocCommonData() { /* switch (Type) { case detColorChip: delete (TColor *)Data; Data = NULL; break; case detEdit: delete (AnsiString *)Data; Data = NULL; break; case detNumber: case detFormula: delete (double *)Data; Data = NULL; break; case detDate: delete (SYSTEMTIME *)Data; Data = NULL; break; } Type = detNone; */ switch (Type) { case detColorChip: delete (TColor *)Data; Data = NULL; break; case detEdit: case detNumber: case detFormula: case detDate: delete (AnsiString *)Data; Data = NULL; break; } Type = detNone; } //--------------------------------------------------------------------------- // // TPDocSheet // //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetOrientation(TPrinterOrientation orient) { RECT rt = Range; if ( FOrientation != orient) { FOrientation = orient; Range = Rect(0, 0, rt.bottom, rt.right); } } //--------------------------------------------------------------------------- __fastcall TPDocSheet::TPDocSheet() : TPDocObject() { Range.left = 0; Range.top = 0; DotsPerInch = 160; Range.right = 7.6*160; //¿©À¯ºÐÀ» À§ÇØ 7.8*11 inch Range.bottom = 10.8*160; FOrientation = poPortrait; FFont = new TFont; FFont->Charset = DEFAULT_CHARSET; FFont->Color = clBlack; FFont->Name = "MS Sans Serif"; FFont->Size = 10; Element = new TList; Bitmap = NULL; SheetType = dstA4; IndexCount = -1; } //--------------------------------------------------------------------------- __fastcall TPDocSheet::~TPDocSheet() { TPDocElement *dp; if (Bitmap) delete Bitmap; if (Element) { while (Element->Count) { dp = (TPDocElement *)Element->First(); Element->Remove(dp); delete dp; } delete Element; } if (FFont) delete FFont; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddLine(RECT rc, TPDocLineType lt, TColor c, TPDocLineStyle ls) { TPDocLine *dp = new TPDocLine(this, rc, lt, c, ls); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddBox(RECT rc, TColor c, TPDocLineStyle ls) { TPDocBox *dp = new TPDocBox(this, rc, c, ls); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddColorChip(RECT rc, int m, AnsiString n, TColor c) { TPDocColorChip *dp = new TPDocColorChip(this, rc, m, n, c); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddNumber(RECT rc, TPDocAlign ta, int p, bool h, AnsiString n) { TPDocNumber *dp = new TPDocNumber(this, rc, ta, p, h, n); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddFormula(RECT rc, TPDocAlign ta, int p, bool h, AnsiString n, AnsiString f) { TPDocFormula *dp = new TPDocFormula(this, rc, ta, p, h, n, f); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddDate(RECT rc, TPDocAlign ta, AnsiString n) { TPDocDate *dp = new TPDocDate(this, rc, ta, n); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddLabel(RECT rc, TPDocAlign ta, AnsiString t) { TPDocLabel *dp = new TPDocLabel(this, rc, ta, t); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddEdit(RECT rc, TPDocAlign ta, AnsiString n) { TPDocEdit *dp = new TPDocEdit(this, rc, ta, n); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddMemo(RECT rc, TPDocAlign ta, AnsiString t) { TPDocMemo *dp = new TPDocMemo(this, rc, ta, t); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddInput(RECT rc, TPDocAlign ta, TColor c, TPDocInputStyle s, AnsiString t, int p, TPDocInputMethod m) { TPDocInput *dp = new TPDocInput(this, rc, ta, c, s, t, p, m); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddImage(RECT rc, TPDocAlign ta, AnsiString t) { TPDocImage *dp = new TPDocImage(this, rc, ta, t); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddSignature(RECT rc) { TPDocSignature *dp = new TPDocSignature(this, rc); Element->Add(dp); } //--------------------------------------------------------------------------- #ifdef KIDO bool __fastcall TPDocSheet::AddChart(RECT rc, TPDocAlign ta, int col, int row, TColor c, bool beditformula, TPDocElementType et) { TPDocChart *dp; dp = new TPDocChart(this, rc, ta, col, row, c, beditformula, et); Element->Add(dp); return true; } //--------------------------------------------------------------------------- #else bool __fastcall TPDocSheet::AddChart(RECT rc, TPDocAlign ta, int col, int row, TColor c, TPDocElementType et) { TPDocChart *dp; dp = new TPDocChart(this, rc, ta, col, row, c, et); Element->Add(dp); return true; } //--------------------------------------------------------------------------- #endif void __fastcall TPDocSheet::AddArrow(RECT rc, TPDocArrowType at, POINT sp, POINT ep, POINT tp, TPDocAlign ta, AnsiString t, TColor c) { TPDocArrow *dp; dp = new TPDocArrow(this, rc, at, sp, ep, tp, ta, t, c); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddSheafImage(RECT rc) { TPDocSheafImage *dp; dp = new TPDocSheafImage(this, rc); Element->Add(dp); } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddSheafLabel(RECT rc, TPDocAlign ta, AnsiString t) { TPDocSheafLabel *dp = new TPDocSheafLabel(this, rc, ta, t); Element->Add(dp); } //--------------------------------------------------------------------------- #ifdef KIDO void __fastcall TPDocSheet::AddTextImage(RECT rc) { TPDocTextImage *dp = new TPDocTextImage(this, rc); Element->Add(dp); } //--------------------------------------------------------------------------- #endif void __fastcall TPDocSheet::AddSheafLine(RECT rc, TPDocSheafLineType lt, POINT tsp, POINT tep, TColor c) { TPDocSheafLine *dp = new TPDocSheafLine(this, rc, lt, tsp, tep, c); Element->Add(dp); } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::CheckName(AnsiString str, TPDocElement *s) { int i; AnsiString name = ""; TPDocElement *sep; for (i=0; iCount; i++) { sep = (TPDocElement *)Element->Items[i]; if (sep->Type == detInput) { if (!CheckName_Input(str, s, (TPDocInput *)sep)) return false; } else if (sep->Type == detChart) { if (!CheckName_Chart(str, s, (TPDocChart *)sep)) return false; } else { if (s != sep) { switch (sep->Type) { case detColorChip: name = ((TPDocColorChip *)sep)->Name; break; case detNumber: name = ((TPDocNumber *)sep)->Name; break; case detFormula: name = ((TPDocFormula *)sep)->Name; break; case detDate: name = ((TPDocDate *)sep)->Name; break; case detEdit: name = ((TPDocEdit *)sep)->Name; break; } if (name.Length() > 0) { if (str.AnsiCompare(name) == 0) { return false; } name = ""; } } } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::CheckName_Input(AnsiString str, TPDocElement *s, TPDocInput *ip) { AnsiString name = ""; if (s) { if (s == ip->IPElement) // if two Elements are same, don't need to check... return true; } switch (ip->IPElement->Type) { case detColorChip: name = ((TPDocColorChip *)ip->IPElement)->Name; break; case detNumber: name = ((TPDocNumber *)ip->IPElement)->Name; break; case detFormula: name = ((TPDocFormula *)ip->IPElement)->Name; break; case detDate: name = ((TPDocDate *)ip->IPElement)->Name; break; case detEdit: name = ((TPDocEdit *)ip->IPElement)->Name; break; } if (name.Length()> 0) { if (str.AnsiCompare(name) == 0) { return false; } } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::CheckName_Chart(AnsiString str, TPDocElement *s, TPDocChart *cp) { int i, cnt; AnsiString name = ""; TPDocElement *sep; cnt = cp->Cell->Count; for (i=0; iCell->Items[i]; if (s) { if (s == sep) // if two Elements are same, don't need to check... return true; } switch (sep->Type) { case detColorChip: name = ((TPDocColorChip *)sep)->Name; break; case detNumber: name = ((TPDocNumber *)sep)->Name; break; case detFormula: name = ((TPDocFormula *)sep)->Name; break; case detDate: name = ((TPDocDate *)sep)->Name; break; case detEdit: name = ((TPDocEdit *)sep)->Name; break; } if (name.Length()> 0) { if (str.AnsiCompare(name) == 0) { return false; } name=""; } } return true; } //--------------------------------------------------------------------------- TFont *__fastcall TPDocSheet::GetFont() { return FFont; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetFont(TFont *font, TColor color) { FFont->Assign(font); // FFont->Color = color; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::RemoveData(TPDocElement *dp) { Element->Remove(dp); delete dp; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::RemoveData() { TPDocElement *dp; while (Element->Count) { dp = (TPDocElement *)Element->First(); Element->Remove(dp); delete dp; } ResetFIDCount(); } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::LoadFromFile(HANDLE hFile, int Version) { int i, n; TPDocElement *dp; DWORD dwRead; TPDocElementType Type; RECT rc; TPDocLineStyle fstyle = dlsNone; TColor fc; if (!TextLoadFromFile(hFile, Title)) return false; if (!ReadFile(hFile, &DotsPerInch, sizeof(int), &dwRead, NULL)) return false; if (!ReadFile(hFile, &rc, sizeof(RECT), &dwRead, NULL)) return false; Range = rc; if (!ReadFile(hFile, &FOrientation, sizeof(TPrinterOrientation), &dwRead, NULL)) return false; if (!ReadFile(hFile, &SheetType, sizeof(TPDocSheetType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &n, sizeof(int), &dwRead, NULL)) return false; if (Version >= 5) if (!ReadFile(hFile, &IndexCount, sizeof(int), &dwRead, NULL)) return false; for (i = 0; i < n; i++) { if (!ReadFile(hFile, &Type, sizeof(TPDocElementType), &dwRead, NULL)) return false; if (!ReadFile(hFile, &rc, sizeof(RECT), &dwRead, NULL)) return false; if (!ReadFile(hFile, &fstyle, sizeof(TPDocLineStyle), &dwRead, NULL)) return false; if (fstyle != dlsNone) { if (!ReadFile(hFile, &fc, sizeof(TColor), &dwRead, NULL)) return false; } switch (Type) { case detLine: dp = new TPDocLine(this, rc); break; case detBox: dp = new TPDocBox(this, rc); break; case detColorChip: dp = new TPDocColorChip(this, rc); break; case detSignature: dp = new TPDocSignature(this, rc); break; case detNumber: dp = new TPDocNumber(this, rc); break; case detFormula: dp = new TPDocFormula(this, rc); break; case detDate: dp = new TPDocDate(this, rc); break; case detLabel: dp = new TPDocLabel(this, rc); break; case detEdit: dp = new TPDocEdit(this, rc); break; case detMemo: dp = new TPDocMemo(this, rc); break; case detImage: dp = new TPDocImage(this, rc); break; case detInput: dp = new TPDocInput(this, rc); break; case detChart: dp = new TPDocChart(this, rc); break; case detArrow: dp = new TPDocArrow(this, rc); break; case detSheafImage: dp = new TPDocSheafImage(this, rc); break; case detSheafLabel: dp = new TPDocSheafLabel(this, rc); break; #ifdef KIDO case detTextImage: dp = new TPDocTextImage(this, rc); break; #endif case detSheafLine: dp = new TPDocSheafLine(this, rc); break; } dp->FrameStyle = fstyle; if (fstyle != dlsNone) { // if fstyle == dslNone, what I do for FrameColor ??????? dp->FrameColor = fc; } if (!dp->LoadFromFile(hFile, Version)) return false; Element->Add(dp); } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::SaveToFile(HANDLE hFile) { int i, n; TPDocElement *dp; DWORD dwWrite; if (!TextSaveToFile(hFile, Title)) return false; if (!WriteFile(hFile, &DotsPerInch, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &Range, sizeof(RECT), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &FOrientation, sizeof(TPrinterOrientation), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &SheetType, sizeof(TPDocSheetType), &dwWrite, NULL)) return false; n = Element->Count; if (!WriteFile(hFile, &n, sizeof(int), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &IndexCount, sizeof(int), &dwWrite, NULL)) return false; for (i = 0; i < n; i++) { dp = (TPDocElement *)Element->Items[i]; if (!WriteFile(hFile, &dp->Type, sizeof(TPDocElementType), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &dp->Range, sizeof(RECT), &dwWrite, NULL)) return false; if (!WriteFile(hFile, &dp->FrameStyle, sizeof(TPDocLineStyle), &dwWrite, NULL)) return false; if (dp->FrameStyle != dlsNone) { if (!WriteFile(hFile, &dp->FrameColor, sizeof(TColor), &dwWrite, NULL)) return false; } if (!dp->SaveToFile(hFile)) return false; } return true; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::LoadFromFile(AnsiString Filename) { HANDLE hFile = INVALID_HANDLE_VALUE; int version; DWORD dwRead; RemoveData(); if ((hFile = CreateFile(Filename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; // dwFileSize = GetFileSize(hFile, NULL); // if ((hFileMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, dwFileSize, // NULL)) == NULL) goto fail; if (!ReadFile(hFile, &version, sizeof(int), &dwRead, NULL)) goto fail; if (!LoadFromFile(hFile, version)) goto fail; CloseHandle(hFile); SetFIDCount(); return true; fail: RemoveData(); if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); return false; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::SaveToFile(AnsiString Filename) { HANDLE hFile = INVALID_HANDLE_VALUE; // int version = 0; // int version = 1; // int version = 2; // 1--->2 In TPDocInput, to save Method and ImageDir; // int version = 3; // 2--->3 In Number & Formula, to save type of number (decimal or fraction); // int version = 4; // 3--->4 In Date, SYSTEMTIME--> Replace with AnsiString // int version = 5; // 4--->5 For Index // int version = 6; // 5--->6 For Index Number and Formula int version = 7; //6--->7 For Formula Data DWORD dwWrite; if ((hFile = CreateFile(Filename.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!WriteFile(hFile, &version, sizeof(int), &dwWrite, NULL)) goto fail; if (!SaveToFile(hFile)) goto fail; CloseHandle(hFile); return true; fail: if (hFile!=INVALID_HANDLE_VALUE) { CloseHandle(hFile); DeleteFile(Filename.c_str()); } return false; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::ResetFIDCount() { TPDocNumber::FIDCount = 0; TPDocFormula::FIDCount = 0; TPDocChart::FIDCount = 0; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetFIDCount() { int nfid=0, ffid=0, cfid=0; int i, cnt, tcnt, k; TPDocElement *dp, *tp; TPDocInput *ip; TPDocChart *cp; cnt = Element->Count; for (i=0; iItems[i]; if (dp->Type == detNumber) { if (((TPDocNumber *)dp)->ID > nfid) nfid = ((TPDocNumber *)dp)->ID; } else if (dp->Type == detFormula) { if (((TPDocFormula *)dp)->ID > ffid) ffid = ((TPDocFormula *)dp)->ID; } else if (dp->Type == detInput) { tp = ((TPDocInput *)dp)->IPElement; if (tp->Type == detNumber) { if (((TPDocNumber *)tp)->ID > nfid) { nfid = ((TPDocNumber *)tp)->ID; } } else if (tp->Type == detFormula) { if (((TPDocFormula *)tp)->ID > ffid) { ffid = ((TPDocFormula *)tp)->ID; } } } else if (dp->Type == detChart) { cp = (TPDocChart *)dp; if (cp->ID > cfid) { cfid = cp->ID; } tcnt = cp->Cell->Count; for (k=0; kCell->Items[k]; if (tp->Type == detNumber) { if (((TPDocNumber *)tp)->ID > nfid) { nfid = ((TPDocNumber *)tp)->ID; } } else if (tp->Type == detFormula) { if (((TPDocFormula *)tp)->ID > ffid) { ffid = ((TPDocFormula *)tp)->ID; } } } } } TPDocNumber::FIDCount = nfid; TPDocFormula::FIDCount = ffid; TPDocChart::FIDCount = cfid; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetRange(int w, int h) { Range = Rect(0, 0, w, h); } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::FindRange(RECT sr, RECT tr, POINT pt) { double sl, dl, mx1, mx2, my1, my2; //¸¶¿ì½º Ä¿¼­¿¡ ¿µ¿ªÀÇ Áß½ÉÀÌ °¡Àå °¡±î¿î °´Ã¼¸¦ ¼±ÅÃÇÑ´Ù. modified by qe mx1 = (sr.left + sr.right)/2; my1 = (sr.top + sr.bottom)/2; sl = (pt.x - mx1)*(pt.x - mx1) + (pt.y - my1)*(pt.y - my1); mx2 = (tr.left + tr.right)/2; my2 = (tr.top + tr.bottom)/2; dl = (pt.x - mx2)*(pt.x - mx2) + (pt.y - my2)*(pt.y - my2); return dl < sl; } //--------------------------------------------------------------------------- TPDocElement *__fastcall TPDocSheet::Select(POINT pt) { TPDocElement *dp, *tp = NULL; bool next = false; for (int i = 0; i < Element->Count; i++) { dp = (TPDocElement *)Element->Items[i]; if (dp->isExist(pt)) { //===================== // ÀÛÀº ¿µ¿ªÀÇ °´Ã¼°¡ Å« °´Ã¼ÀÇ ¾È¿¡ ÀÖ´Â °æ¿ì... if (next) { if (FindRange(tp->Range, dp->Range, pt)) tp = dp; } else { tp = dp; next = true; } //===================== } } return tp; } //--------------------------------------------------------------------------- //================================ char ch, num[20]; // where do I declare ?? int pfp; Postfix *pf; //================================ char * __fastcall TPDocSheet::Constant() { int i = 0, m = 0, p = 0; while (1) { ch = pf->postfix[pfp]; if (!m && ch=='-') { pfp++; num[i++] = ch; } else if (!p && ch=='.') { pfp++; num[i++] = ch; p++; } else if (isdigit(ch)) { pfp++; num[i++] = ch; } else break; m++; } num[i] = 0; return num; } //--------------------------------------------------------------------------- char * __fastcall TPDocSheet::Variable() { int i = 0; while (ch=pf->postfix[pfp], isdigit(ch)) { pfp++; num[i++] = ch; } num[i] = 0; return num; } /*--------------------------------------------------------------------------- char * __fastcall TPDocSheet::FMsearch(TPDocElementType Type) { int i; TPDocElement *dp; for (i=0; iCount; i++) { dp = (TPDocElement *)Element->Items[i]; if (dp->Type == Type) { ; // yield(dp); What do I do?? } } } */ //--------------------------------------------------------------------------- double __fastcall TPDocSheet::Calculation(AnsiString Formula) { return 0; /* int i, j, cnt, ccnt, k; double td1, td2, d; TPDocElement *dp, *tp; TPDocNumber *np; TPDocFormula *fp; TPDocInput *ip; TPDocChart *cp; stack< double, vector > > s; if (Element) { cnt = Element->Count; } else { cnt = 0; } if (Formula !="") { pf = new Postfix(Formula.c_str()); if (!pf->convert()) { pfp = 0; while (ch=pf->postfix[pfp++], ch) { switch (ch) { case 'N': d = 0.0; j = atoi(Variable()); for (i=0; iItems[i]; if (dp->Type == detNumber) { np = (TPDocNumber *)dp; if (np->ID == j) { if (np->Number.Length() > 0) { try { d = StrToFloat(np->Number); } catch (EConvertError&) { d = 0.0; } } break; } } else if (dp->Type == detInput) { ip = (TPDocInput*)dp; if (ip->IPElement->Type == detNumber) { np = (TPDocNumber *)ip->IPElement; if (np->ID == j) { if (np->Number.Length() > 0) { try { d = StrToFloat(np->Number); } catch (EConvertError&) { d = 0.0; } } break; } } } else if (dp->Type == detChart) { cp = (TPDocChart *)dp; ccnt = cp->Cell->Count; for (k=0; kCell->Items[k]; if (tp->Type == detNumber) { np = (TPDocNumber *)tp; if (np->ID == j) { //Is it right?? if (np->Number.Length() > 0) { try { d = StrToFloat(np->Number); } catch (EConvertError&) { d = 0.0; } } break; } } } } } break; // case 'C': // d = 0.0; j = atoi(Variable()); // for (i=0; iItems[i]; // if (dp->Type == detChart) { // cp =(TPDocChart *)dp; // ccnt = cp->Cell->Count; // for (k=0; kCell->Items[k]; // if (tp->Type == detNumber) { // np = (TPDocNumber *)tp; // if (np->ID == j) { //Is it right?? // d = np->Number; // break; // } // } // } // } // } // break; case 'F': d = 0.0; j = atoi(Variable()); for (i=0; iItems[i]; if (dp->Type == detFormula) { fp = (TPDocFormula *)dp; if (fp->ID == j) { if (fp->ANumber.Length() > 0) { try { d = StrToFloat(fp->ANumber); } catch (EConvertError&) { d = 0.0; } } break; } } else if (dp->Type == detInput) { ip = (TPDocInput*)dp; if (ip->IPElement->Type == detFormula) { fp = (TPDocFormula *)ip->IPElement; if (fp->ID == j) { if (fp->ANumber.Length() > 0) { try { d = StrToFloat(fp->ANumber); } catch (EConvertError&) { d = 0.0; } } break; } } } else if (dp->Type == detChart) { cp = (TPDocChart *)dp; ccnt = cp->Cell->Count; for (k=0; kCell->Items[k]; if (tp->Type == detFormula) { fp = (TPDocFormula *)tp; if (fp->ID == j) { //Is it right?? if (fp->ANumber.Length() > 0) { try { d = StrToFloat(fp->ANumber); } catch (EConvertError&) { d = 0.0; } } break; } } } } } break; case 'I': d = atof(Constant()); break; case '+': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1+td2; break; case '-': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1-td2; break; case '*': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1*td2; break; case '/': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); if (td2!=0.0) d = td1/(td2); break; } s.push(d); } td1 = s.top(); s.pop(); } delete pf; } else { td1 = 0; } return td1;*/ /* if (Formula !="") { pf = new Postfix(Formula.c_str()); if (!pf->convert()) { pfp = 0; while (ch=pf->postfix[pfp++], ch) { switch (ch) { case 'N': d = 0.0; j = atoi(Variable()); for (i=0; iItems[i]; if (dp->Type == detNumber) { np = (TPDocNumber *)dp; if (np->ID == j) { d = np->Number; break; } } else if (dp->Type == detInput) { ip = (TPDocInput*)dp; if (ip->IPElement->Type == detNumber) { np = (TPDocNumber *)ip->IPElement; if (np->ID == j) { d = np->Number; break; } } } else if (dp->Type == detChart) { cp = (TPDocChart *)dp; ccnt = cp->Cell->Count; for (k=0; kCell->Items[k]; if (tp->Type == detNumber) { np = (TPDocNumber *)tp; if (np->ID == j) { //Is it right?? d = np->Number; break; } } } } } break; // case 'C': // d = 0.0; j = atoi(Variable()); // for (i=0; iItems[i]; // if (dp->Type == detChart) { // cp =(TPDocChart *)dp; // ccnt = cp->Cell->Count; // for (k=0; kCell->Items[k]; // if (tp->Type == detNumber) { // np = (TPDocNumber *)tp; // if (np->ID == j) { //Is it right?? // d = np->Number; // break; // } // } // } // } // } // break; case 'F': d = 0.0; j = atoi(Variable()); for (i=0; iItems[i]; if (dp->Type == detFormula) { fp = (TPDocFormula *)dp; if (fp->ID == j) { d = fp->Number; break; } } else if (dp->Type == detInput) { ip = (TPDocInput*)dp; if (ip->IPElement->Type == detFormula) { fp = (TPDocFormula *)ip->IPElement; if (fp->ID == j) { d = fp->Number; break; } } } else if (dp->Type == detChart) { cp = (TPDocChart *)dp; ccnt = cp->Cell->Count; for (k=0; kCell->Items[k]; if (tp->Type == detFormula) { fp = (TPDocFormula *)tp; if (fp->ID == j) { //Is it right?? d = fp->Number; break; } } } } } break; case 'I': d = atof(Constant()); break; case '+': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1+td2; break; case '-': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1-td2; break; case '*': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); d = td1*td2; break; case '/': td2 = s.top(); s.pop(); td1 = s.top(); s.pop(); if (td2!=0.0) d = td1/(td2); break; } s.push(d); } td1 = s.top(); s.pop(); } delete pf; } else { td1 = 0; } return td1; */ /* char ch, num[20]; int j, k, pfp; double d, *d1, *d2; Postfix *pf; GStack(double) s; char *constant() { int i = 0, m = 0, p = 0; while (1) { ch = pf->postfix[pfp]; if (!m && ch=='-') { pfp++; num[i++] = ch; } else if (!p && ch=='.') { pfp++; num[i++] = ch; p++; } else if (isdigit(ch)) { pfp++; num[i++] = ch; } else break; m++; } num[i] = 0; return num; } char *variable() { int i = 0; while (ch=pf->postfix[pfp], isdigit(ch)) { pfp++; num[i++] = ch; } num[i] = 0; return num; } while (1) { k = 0; for fc <- FMsearch(5) do { if (fc->u.c.num>0) { s.clear(); fc->u.c.value = 0.0; if (fc->u.c.express) { pf = new Postfix(fc->u.c.express); if (!pf->convert()) { pfp = 0; while (ch=pf->postfix[pfp++], ch) { switch (ch) { case 'N': d = 0.0; j = atoi(variable()); for f <- FMsearch(4) do { if (f->u.n.num==j) { d = f->u.n.value; break; } } break; case 'C': d = 0.0; j = atoi(variable()); for f <- FMsearch(5) do { if (abs(f->u.c.num)==j) { if (f->u.c.num<0) { d = f->u.c.value; break; } else { delete pf; goto jump; } } } break; case 'I': d = atof(constant()); break; case '+': d2 = s.pop(); d1 = s.pop(); d = *d1+(*d2); delete d1; delete d2; break; case '-': d2 = s.pop(); d1 = s.pop(); d = *d1-(*d2); delete d1; delete d2; break; case '*': d2 = s.pop(); d1 = s.pop(); d = *d1*(*d2); delete d1; delete d2; break; case '/': d2 = s.pop(); d1 = s.pop(); if (*d2!=0.0) d = *d1/(*d2); delete d1; delete d2; break; } s.push(new double(d)); } d1 = s.pop(); fc->u.c.value = *d1; delete d1; } delete pf; } fc->u.c.num *= -1; k++; jump:; } } if (!k) break; } for fc <- FMsearch(5) do { if (fc->u.c.num<0) fc->u.c.num *= -1; } return 0; */ } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::MakeBitmap(int zi, int zo) { HDC hDC = NULL, thDC = NULL; TPDocElement *dp; TTexpiaBitmap *temp = NULL; int i; if (Bitmap) { delete Bitmap; Bitmap = NULL; } if ((Bitmap = new TTexpiaBitmap) == NULL) goto fail; if (!Bitmap->Create(Range.right, Range.bottom, 24)) goto fail; Bitmap->FillRect(Range, clWhite); if ((hDC = Bitmap->CreateDC()) == NULL) goto fail; for (i = 0; i < Element->Count; i++) { dp = (TPDocElement *)Element->Items[i]; dp->PaintForm(hDC); } Bitmap->DeleteDC(hDC); return true; fail: if (Bitmap) { if (hDC) Bitmap->DeleteDC(hDC); delete Bitmap; Bitmap = NULL; } return false; } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::DeleteBitmap() { if (Bitmap) { delete Bitmap; Bitmap = NULL; } } //--------------------------------------------------------------------------- /* void __fastcall TPDocSheet::AddCommonData(TPDocCommonDataMap &cdm) { int i, n; TPDocElement *ep; AnsiString name = ""; TPDocCommonData *cdp = NULL; TPDocCommonDataMap::iterator p; typedef TPDocCommonDataMap::value_type value_type; for (i = 0; i < Element->Count; i++) { ep = (TPDocElement *)Element->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; break; case detEdit: name = ((TPDocEdit *)ep)->Name; break; case detNumber: name = ((TPDocNumber *)ep)->Name; break; case detFormula: name = ((TPDocFormula *)ep)->Name; break; case detDate: name = ((TPDocDate *)ep)->Name; break; case detInput: name = ""; AddCommonData_Input((TPDocInput *)ep, cdm); break; case detChart: AddCommonData_Chart((TPDocChart *)ep, cdm); name = ""; break; default: name = ""; break; } if (name.Length() > 0) { p = cdm.find(name); //¸¸¾à ãÁö ¸øÇϸé end()°ªÀ» ³Ñ±è if (p == cdm.end()) { cdm.insert(value_type(AnsiString(name), new TPDocCommonData(ep->Type, ID))); } } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddCommonData_Input(TPDocInput *ip, TPDocCommonDataMap &cdm) { AnsiString name=""; TPDocCommonData *cdp = NULL; TPDocCommonDataMap::iterator p; typedef TPDocCommonDataMap::value_type value_type; switch (ip->IPElement->Type) { case detColorChip: name = ((TPDocColorChip *)ip->IPElement)->Name; break; case detEdit: name = ((TPDocEdit *)ip->IPElement)->Name; break; case detNumber: name = ((TPDocNumber *)ip->IPElement)->Name; break; case detFormula: name = ((TPDocFormula *)ip->IPElement)->Name; break; case detDate: name = ((TPDocDate *)ip->IPElement)->Name; break; default: name = ""; break; } if (name.Length() > 0) { p = cdm.find(name); //¸¸¾à ãÁö ¸øÇϸé end()°ªÀ» ³Ñ±è if (p == cdm.end()) { cdm.insert(value_type(AnsiString(name), new TPDocCommonData(ip->IPElement->Type, ID))); } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::AddCommonData_Chart(TPDocChart *cp, TPDocCommonDataMap &cdm) { int i, cnt; TPDocElement *ep; AnsiString name = ""; TPDocCommonData *cdp = NULL; TPDocCommonDataMap::iterator p; typedef TPDocCommonDataMap::value_type value_type; cnt = cp->Cell->Count; for (i = 0; i < cnt; i++) { ep = (TPDocElement *)cp->Cell->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; break; case detEdit: name = ((TPDocEdit *)ep)->Name; break; case detNumber: name = ((TPDocNumber *)ep)->Name; break; case detFormula: name = ((TPDocFormula *)ep)->Name; break; case detDate: name = ((TPDocDate *)ep)->Name; break; default: name = ""; break; } if (name.Length() > 0) { p = cdm.find(name); //¸¸¾à ãÁö ¸øÇϸé end()°ªÀ» ³Ñ±è if (p == cdm.end()) { cdm.insert(value_type(AnsiString(name), new TPDocCommonData(ep->Type, ID))); } } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::GetCommonData(TPDocCommonDataMap &cdm) { int i; TPDocElement *ep; AnsiString name = "", txt; TPDocCommonDataMap::iterator p; for (i = 0; i < Element->Count; i++) { ep = (TPDocElement *)Element->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { /*(p)*/ /* *((TColor *)((&p)->second->Data)) = ((TPDocColorChip *)ep)->Color; } break; case detEdit: name = ((TPDocEdit *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ep)->GetK_Text(txt); *(AnsiString *)p->second->Data = txt; } break; case detNumber: name = ((TPDocNumber *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocNumber *)ep)->Number; } break; case detFormula: name = ((TPDocFormula *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocFormula *)ep)->ANumber; } break; case detDate: name = ((TPDocDate *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocDate *)ep)->Date; // Version >= 4 } break; case detInput: GetCommonData_Input((TPDocInput *)ep, cdm); break; case detChart: GetCommonData_Chart((TPDocChart *)ep, cdm); break; } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::GetCommonData_Input(TPDocInput *ip, TPDocCommonDataMap &cdm) { AnsiString name = "", txt; TPDocCommonDataMap::iterator p; switch (ip->IPElement->Type) { case detColorChip: name = ((TPDocColorChip *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { *(TColor *)p->second->Data = ((TPDocColorChip *)ip->IPElement)->Color; } break; case detEdit: name = ((TPDocEdit *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ip->IPElement)->GetK_Text(txt); *(AnsiString *)p->second->Data = txt; } break; case detNumber: name = ((TPDocNumber *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocNumber *)ip->IPElement)->Number; } break; case detFormula: name = ((TPDocFormula *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocFormula *)ip->IPElement)->ANumber; } break; case detDate: name = ((TPDocDate *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocDate *)ip->IPElement)->Date; } break; } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::GetCommonData_Chart(TPDocChart *cp, TPDocCommonDataMap &cdm) { int i, cnt; TPDocElement *ep; AnsiString name = "", txt; TPDocCommonDataMap::iterator p; cnt = cp->Cell->Count; for (i = 0; i < cnt; i++) { ep = (TPDocElement *)cp->Cell->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(TColor *)p->second->Data = ((TPDocColorChip *)ep)->Color; } break; case detEdit: name = ((TPDocEdit *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ep)->GetK_Text(txt); *(AnsiString *)p->second->Data = txt; } break; case detNumber: name = ((TPDocNumber *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocNumber *)ep)->Number; } break; case detFormula: name = ((TPDocFormula *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocFormula *)ep)->ANumber; } break; case detDate: name = ((TPDocDate *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { *(AnsiString *)p->second->Data = ((TPDocDate *)ep)->Date; } break; } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetCommonData(TPDocCommonDataMap &cdm) { int i; TPDocElement *ep; AnsiString name = ""; TPDocCommonDataMap::iterator p; for (i = 0; i < Element->Count; i++) { ep = (TPDocElement *)Element->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocColorChip *)ep)->Color = *(TColor *)p->second->Data; } break; case detEdit: name = ((TPDocEdit *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ep)->SetText(*(AnsiString *)p->second->Data); } break; case detNumber: name = ((TPDocNumber *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocNumber *)ep)->Number = *(AnsiString *)p->second->Data; } break; case detFormula: name = ((TPDocFormula *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocFormula *)ep)->ANumber = *(AnsiString *)p->second->Data; } break; case detDate: name = ((TPDocDate *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocDate *)ep)->Date = *(AnsiString *)p->second->Data; } break; case detInput: SetCommonData_Input((TPDocInput *)ep, cdm); break; case detChart: SetCommonData_Chart((TPDocChart *)ep, cdm); break; } } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetCommonData_Input(TPDocInput *ip, TPDocCommonDataMap &cdm) { AnsiString name = ""; TPDocCommonDataMap::iterator p; switch (ip->IPElement->Type) { case detColorChip: name = ((TPDocColorChip *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocColorChip *)ip->IPElement)->Color = *(TColor *)p->second->Data; } break; case detEdit: name = ((TPDocEdit *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ip->IPElement)->SetText(*(AnsiString *)p->second->Data); } break; case detNumber: name = ((TPDocNumber *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocNumber *)ip->IPElement)->Number = *(AnsiString *)p->second->Data; } break; case detFormula: name = ((TPDocFormula *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocFormula *)ip->IPElement)->ANumber = *(AnsiString *)p->second->Data; } break; case detDate: name = ((TPDocDate *)ip->IPElement)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocDate *)ip->IPElement)->Date = *(AnsiString *)p->second->Data; } break; } } //--------------------------------------------------------------------------- void __fastcall TPDocSheet::SetCommonData_Chart(TPDocChart *cp, TPDocCommonDataMap &cdm) { int i, cnt; TPDocElement *ep; AnsiString name = ""; TPDocCommonDataMap::iterator p; cnt = cp->Cell->Count; for (i = 0; i < cnt; i++) { ep = (TPDocElement *)cp->Cell->Items[i]; switch (ep->Type) { case detColorChip: name = ((TPDocColorChip *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocColorChip *)ep)->Color = *(TColor *)p->second->Data; } break; case detEdit: name = ((TPDocEdit *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocEdit *)ep)->SetText(*(AnsiString *)p->second->Data); } break; case detNumber: name = ((TPDocNumber *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocNumber *)ep)->Number = *(AnsiString *)p->second->Data; } break; case detFormula: name = ((TPDocFormula *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocFormula *)ep)->ANumber = *(AnsiString *)p->second->Data; } break; case detDate: name = ((TPDocDate *)ep)->Name; p = cdm.find(name); if (p != cdm.end()) { ((TPDocDate *)ep)->Date = *(AnsiString *)p->second->Data; } break; } } } */ //--------------------------------------------------------------------------- void __fastcall TPDocSheet::PaintData(HDC hDC, TPDocSheet *sheet, bool bprint) { int i;//, cnt = 0; TPDocElement *ep; TPDocViewStatus vs; for (i=0; iCount; i++) { ep = (TPDocElement *)Element->Items[i]; ep->PaintReport(sheet, hDC, vs, bprint, false, 0); // 0-->Korean } } //--------------------------------------------------------------------------- bool __fastcall TPDocSheet::SendToPrinter(int page, bool bCenter, int language) { HDC hPrintDC, hDC = NULL, phDC = NULL; TRect Src, Dst; int WidthRes, HeightRes, x, y, i, sx, sy; TSize Area, n, s; TTexpiaBitmap dBitmap, tBitmap; TPDocElement *ep; TPDocViewStatus vs; Printer()->Title = Title; Printer()->Copies = page; Printer()->Orientation = Orientation; Printer()->BeginDoc(); hPrintDC = Printer()->Handle; WidthRes = GetDeviceCaps(hPrintDC, LOGPIXELSX); HeightRes = GetDeviceCaps(hPrintDC, LOGPIXELSY); Area.cx = GetDeviceCaps(hPrintDC, HORZRES) * DotsPerInch / WidthRes; Area.cy = GetDeviceCaps(hPrintDC, VERTRES) * DotsPerInch / HeightRes; n.cx = ((Bitmap->Width - 1) / Area.cx) + 1; n.cy = ((Bitmap->Height - 1) / Area.cy) + 1; if (!tBitmap.Create(Bitmap->Width, Bitmap->Height, Bitmap->BitsPerPixel)) goto fail; if ((phDC = tBitmap.CreateDC()) == NULL) goto fail; if ((hDC = Bitmap->CreateDC()) == NULL) goto fail; BitBlt(phDC, 0, 0, tBitmap.Width, tBitmap.Height, hDC, 0, 0, SRCCOPY); Bitmap->DeleteDC(hDC); hDC = NULL; //============================ for (i=0; iCount; i++) { ep = (TPDocElement *)Element->Items[i]; ep->PaintReport((TPDocObject *)ep, phDC, vs, true, false, language); } //============================ // PaintData(phDC, true); //============================ if (!dBitmap.Create(Area.cx, Area.cy, Bitmap->BitsPerPixel)) goto fail; for (y = 0; y < n.cy; y++) { Src.Top = y * Area.cy; s.cy = tBitmap.Height - Src.Top; if (s.cy > Area.cy) s.cy = Area.cy; for (x = 0; x < n.cx; x++) { if ((x > 0) || (y > 0)) Printer()->NewPage(); Src.Left = x * Area.cx; s.cx = tBitmap.Width - Src.Left; if (s.cx > Area.cx) s.cx = Area.cx; if (s.cx != dBitmap.Width || s.cy != dBitmap.Height) { if (!dBitmap.Resize(s.cx, s.cy, clWhite)) goto fail; } if ((hDC = dBitmap.CreateDC()) == NULL) goto fail; if (!BitBlt(hDC, 0, 0, s.cx, s.cy, phDC, Src.Left, Src.Top, SRCCOPY)) goto fail; dBitmap.DeleteDC(hDC); hDC = NULL; if (bCenter) { sx = 0; sy = 0; } else { sx = 1; sy = 1; } // if (!L_PrintBitmapFast(hPrintDC, dBitmap.Handle, sx, sy, s.cx * WidthRes / DotsPerInch, // s.cy * HeightRes / DotsPerInch, false)) goto fail; // not printed in some printers // LEADTOOLS V10 -> 15 : L_PrintBitmapExt() -> L_PrintBitmap() - by monkman (2007.06.15) if (!L_PrintBitmap(hPrintDC, dBitmap.Handle, sx, sy, s.cx * WidthRes / DotsPerInch, s.cy * HeightRes / DotsPerInch, false)) goto fail; } } tBitmap.DeleteDC(phDC); Printer()->EndDoc(); return true; fail: if (hDC) dBitmap.DeleteDC(hDC); if (phDC) tBitmap.DeleteDC(phDC); return false; } //--------------------------------------------------------------------------- // // TPDocSheaf // //--------------------------------------------------------------------------- __fastcall TPDocSheaf::TPDocSheaf() { ID = 0; Sheet = new TList; } //--------------------------------------------------------------------------- __fastcall TPDocSheaf::~TPDocSheaf() { RemoveData(); if (Sheet) delete Sheet; } //--------------------------------------------------------------------------- // Public Methods //--------------------------------------------------------------------------- TPDocSheet *__fastcall TPDocSheaf::GetSheet(int n) { return (TPDocSheet *)Sheet->Items[n]; } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::AddSheet(TPDocSheet *Value) { Value->ID = ID++; Sheet->Add(Value); } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::InsertSheet(int Index, TPDocSheet *Value) { Value->ID = ID++; // What is ID? Must know about ID --use, mean, plus and minus... Sheet->Insert(Index, Value); } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::MoveSheet(int Source, int Target) { /* TPDocSheet *dp; dp = GetSheet(Source); if (Source > Target) { Sheet->Insert(Target, dp); dp = GetSheet(Source + 1); } else { if (Target == (Sheet->Count - 1)) { Sheet->Add(dp); } else { Sheet->Insert(Target + 1, dp); } } Sheet->Remove(dp); */ Sheet->Move(Source, Target); } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::DeleteSheet(int Index) { TPDocSheet *dp = (TPDocSheet *)Sheet->Items[Index]; Sheet->Remove(dp); if (dp) delete dp; } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::RemoveData() { TPDocSheet *dp; int *id; // TPDocCommonData *cdm; ID = 0; if (Sheet) { while (Sheet->Count) { dp = (TPDocSheet *)Sheet->First(); Sheet->Remove(dp); delete dp; } } /* while (CommonDataMap.size()) { TPDocCommonDataMap::iterator p = CommonDataMap.begin(); delete CommonDataMap[p->first]; CommonDataMap.erase(p); } */ } //--------------------------------------------------------------------------- bool __fastcall TPDocSheaf::LoadFromFile(AnsiString Filename) { HANDLE hFile = INVALID_HANDLE_VALUE; int version, n, i; DWORD dwRead; TPDocSheet *dp; RemoveData(); if ((hFile = CreateFile(Filename.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; // dwFileSize = GetFileSize(hFile, NULL); // if ((hFileMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, dwFileSize, // NULL)) == NULL) goto fail; if (!ReadFile(hFile, &version, sizeof(int), &dwRead, NULL)) goto fail; if (!TextLoadFromFile(hFile, Title)) return false; if (!ReadFile(hFile, &n, sizeof(int), &dwRead, NULL)) goto fail; for (i = 0; i < n; i++) { dp = new TPDocSheet; if (!dp->LoadFromFile(hFile, version)) goto fail; dp->ID = ID++; Sheet->Add(dp); } CloseHandle(hFile); return true; fail: RemoveData(); if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); return false; } //--------------------------------------------------------------------------- bool __fastcall TPDocSheaf::SaveToFile(AnsiString Filename) { HANDLE hFile = INVALID_HANDLE_VALUE; // int version = 1, n, i; //version===> must be same to version of Sheet // int version = 2, n, i; //version===> must be same to version of Sheet // int version = 3, n, i; //version===> must be same to version of Sheet // int version = 4, n, i; //version===> must be same to version of Sheet // int version = 5, n, i; //version===> must be same to version of Sheet // int version = 6, n, i; //version===> must be same to version of Sheet int version = 7, n, i; //version===> must be same to version of Sheet DWORD dwWrite; TPDocSheet *dp; if ((hFile = CreateFile(Filename.c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto fail; if (!WriteFile(hFile, &version, sizeof(int), &dwWrite, NULL)) goto fail; if (!TextSaveToFile(hFile, Title)) return false; n = Sheet->Count; if (!WriteFile(hFile, &n, sizeof(int), &dwWrite, NULL)) return false; for (i = 0; i < n; i++) { dp = (TPDocSheet *)Sheet->Items[i]; if (!dp->SaveToFile(hFile)) return false; } CloseHandle(hFile); return true; fail: if (hFile!=INVALID_HANDLE_VALUE) { CloseHandle(hFile); DeleteFile(Filename.c_str()); } return false; } //--------------------------------------------------------------------------- int __fastcall TPDocSheaf::GetCount() { return Sheet->Count; } //--------------------------------------------------------------------------- /* void __fastcall TPDocSheaf::AddCommonData(int n) { TPDocSheet *sheet = (TPDocSheet *)Sheet->Items[n]; sheet->AddCommonData(CommonDataMap); } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::GetCommonData(int n) { TPDocSheet *sheet = (TPDocSheet *)Sheet->Items[n]; sheet->GetCommonData(CommonDataMap); } //--------------------------------------------------------------------------- void __fastcall TPDocSheaf::SetCommonData(int n) { TPDocSheet *sheet = (TPDocSheet *)Sheet->Items[n]; sheet->SetCommonData(CommonDataMap); } */ //--------------------------------------------------------------------------- /* int __fastcall min(int f,int s){ if(fs)return f; else return s; } */ //---------------------------------------------------------------------------