📄 cnreport.h
字号:
//---------------------------------------------------------------------------
#ifndef CNReportH
#define CNReportH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <db.hpp>
#include <printers.hpp>
#include <FileCtrl.hpp>
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#define TEXT_ALIGN_LEFT 0x0
#define TEXT_ALIGN_CENTER 0x1
#define TEXT_ALIGN_RIGHT 0x2
#define TEXT_ALIGN_TOP 0x0
#define TEXT_ALIGN_VCENTER 0x1
#define TEXT_ALIGN_BOTTOM 0x2
#define LINE_LEFT1 0x1
#define LINE_LEFT2 0x2
#define LINE_LEFT3 0x4
#define LINE_RIGHT1 0x100
#define LINE_RIGHT2 0x200
#define LINE_RIGHT3 0x400
#define CN_SIGN 0xAA55
#define MAX_TEXT_LEN 3000
#define trunc(a) int(a)
class TCNReportCell;
class TCNReportLine;
class TCNReportControl;
class PACKAGE TCNReportControl : public TWinControl
{
friend class TCNReportCell;
friend class TCNReportLine;
private:
bool FPreviewStatus;
TList* FLineList;
TList* FSelectCells;
TCNReportCell* FEditCell;
int FReportScale;
int FPageWidth;
int FPageHeight;
int FLeftMargin;
int FRightMargin;
int FTopMargin;
int FBottomMargin;
tagLOGFONTA FCellFont;
tagLOGFONTA FcellFont_d;
int FLeftMargin1;
int FRightMargin1;
int FTopMargin1;
int FBottomMargin1;
// 换页加表头(不加表头)
bool FNewTable;
// 定义打印多少行后从新加表头
int FDataLine;
int FTablePerPage;
// 鼠标操作支持
TPoint FMousePoint;
// 编辑、颜色及字体
HWND FEditWnd;
HBRUSH FEditBrush;
HFONT FEditFont;
public:
__fastcall virtual TCNReportControl(TComponent* AOwner);
__fastcall virtual ~TCNReportControl(void);
void __fastcall SaveToFile(AnsiString FileName);
void __fastcall LoadFromFile(AnsiString FileName);
void __fastcall PrintIt(void);
void __fastcall ResetContent(void);
void __fastcall SetScale(const int Value);
__property tagLOGFONTA CellFont = {read=FCellFont, write=FCellFont};
__property tagLOGFONTA CellFont_d = {read=FcellFont_d, write=FcellFont_d};
void __fastcall CalcWndSize(void);
void __fastcall NewTable(int ColNumber, int RowNumber);
void __fastcall InsertLine(void);
bool __fastcall CanInsert(void);
void __fastcall AddLine(void);
bool __fastcall CanAdd(void);
void __fastcall DeleteLine(void);
void __fastcall InsertCell(void);
void __fastcall DeleteCell(void);
void __fastcall AddCell(void);
void __fastcall CombineCell(void);
void __fastcall SplitCell(void);
void __fastcall VSplitCell(int Number);
bool __fastcall CanSplit(void);
void __fastcall SetCellLines(bool bLeftLine, bool bTopLine, bool bRightLine, bool bBottomLine, int nLeftLineWidth, int nTopLineWidth, int nRightLineWidth, int nBottomLineWidth);
void __fastcall SetCellDiagonal(unsigned NewDiagonal);
void __fastcall SetCellColor(unsigned NewTextColor, unsigned NewBackColor);
void __fastcall SetCellFont(const tagLOGFONTA &CellFont);
void __fastcall SetCellAlign(int NewHorzAlign, int NewVertAlign);
void __fastcall SetMargin(int nLeftMargin, int nTopMargin, int nRightMargin, int nBottomMargin);
TRect __fastcall GetMargin();
TFont* __fastcall GetcellFont(void);
void __fastcall UpdateLines(void);
void __fastcall StartMouseDrag(const TPoint &point);
void __fastcall StartMouseSelect(const TPoint &point, bool bSelectFlag, Byte shift_down);
void __fastcall MouseMoveHandler(const tagMSG &message);
bool __fastcall AddSelectedCell(TCNReportCell* Cell);
bool __fastcall RemoveSelectedCell(TCNReportCell* Cell);
void __fastcall RemoveAllSelectedCell(void);
bool __fastcall IsCellSelected(TCNReportCell* Cell);
TCNReportCell* __fastcall CellFromPoint(const TPoint &point);
__property bool IsPreview = {read=FPreviewStatus, write=FPreviewStatus, default=0};
__property int ReportScale = {read=FReportScale, write=SetScale, default=100};
__property bool IsNewTable = {read=FNewTable, write=FNewTable, default=1};
__property int DataLine = {read=FDataLine, write=FDataLine, default=2147483647};
__property int TablePerPage = {read=FTablePerPage, write=FTablePerPage, default=2147483647};
__published:
__property Left ;
__property Top ;
__property Cursor ;
__property Hint ;
__property Visible ;
__property Enabled ;
__property PopupMenu;
__property OnMouseMove ;
__property OnMouseDown ;
__property OnMouseUp ;
__property ShowHint ;
public:
inline __fastcall TCNReportControl(HWND ParentWindow) : TWinControl(ParentWindow) { }
protected:
virtual void __fastcall CreateWnd(void);
// void __fastcall WndProc(Messages::TMessage &Message);
public:
void __fastcall WMLButtonDown(TWMMouse &Message);
void __fastcall WMLButtonDblClk(TWMMouse &Message);
void __fastcall WMMouseMove(TWMMouse &Message);
void __fastcall WMContextMenu(TWMContextMenu &Message);
void __fastcall WMPaint(TWMPaint &Message);
void __fastcall WMCommand(TWMCommand &Message);
void __fastcall WMCtlColor(TMessage &Message);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_LBUTTONDOWN,TWMMouse,WMLButtonDown)
VCL_MESSAGE_HANDLER(WM_LBUTTONDBLCLK,TWMMouse,WMLButtonDblClk)
VCL_MESSAGE_HANDLER(WM_MOUSEMOVE,TWMMouse,WMMouseMove)
// MESSAGE_HANDLER(WM_CONTEXTMENU,TWMContextMenu,WMContextMenu)
VCL_MESSAGE_HANDLER(WM_PAINT,TWMPaint,WMPaint)
VCL_MESSAGE_HANDLER(WM_COMMAND,TWMCommand,WMCommand)
VCL_MESSAGE_HANDLER(WM_CTLCOLOREDIT,TMessage,WMCtlColor)
END_MESSAGE_MAP (TWinControl);
};
class TCNReportLine : public TObject
{
friend class TCNReportCell;
friend class TCNReportControl;
friend class TCNReportRunTime;
private:
TCNReportControl* FReportControl; // Report Control的指针
TList* FCells; // 保存所有在该行中的CELL
int FIndex; // 行的索引
int FMinHeight;
int FDragHeight;
int FLineTop;
TRect FLineRect;
int __fastcall GetLineHeight(void);
TRect __fastcall GetLineRect();
void __fastcall SetDragHeight(const int Value);
void __fastcall SetLineTop(const int Value);
public:
__property TCNReportControl* ReportControl = {read=FReportControl, write=FReportControl};
__property int Index = {read=FIndex, write=FIndex, nodefault};
__property int LineHeight = {read=GetLineHeight, write=SetDragHeight, nodefault};
__property int LineTop = {read=FLineTop, write=SetLineTop, nodefault};
__property TRect LineRect = {read=GetLineRect};
__property TRect PrevLineRect = {read=FLineRect};
void __fastcall CalcLineHeight(void);
void __fastcall CreateLine(int LineLeft, int CellNumber, int PageWidth);
void __fastcall CopyLine(TCNReportLine* Line, bool bInsert);
public:
__fastcall TCNReportLine(void);
__fastcall virtual ~TCNReportLine(void);
};
class TCNReportCell : public TObject
{
friend class TCNReportLine;
friend class TCNReportControl;
friend class TCNReportRunTime;
private:
int FLeftMargin; // 左边的空格
TCNReportLine* FOwnerLine; // 隶属行
TCNReportCell* FOwnerCell; // 隶属的单元格
TList* FCellsList; // 覆盖的Cell
int FCellIndex; // Cell在行中的索引
int FCellLeft;
int FCellWidth;
TRect FCellRect; // 计算得来
TRect FTextRect;
int FDragCellHeight;
int FMinCellHeight;
int FRequiredCellHeight;
// Cell的Top属性从隶属的行中取得
// int GetCellTop();
// Cell的Height属性从隶属行和跨越行中取得
// int GetCellHeight();
// border
bool FLeftLine;
int FLeftLineWidth;
bool FTopLine;
int FTopLineWidth;
bool FRightLine;
int FRightLineWidth;
bool FBottomLine;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -