📄 featuresdemomain.cpp
字号:
}
}
}
void __fastcall TFeaturesMainForm::SetVertStyle(TRect ARect, int ACol, TcxSSEdgeLineStyle AStyle)
{
if (AStyle != lsNone)
for (int i = ARect.Top; i <= ARect.Bottom; i++)
{
TcxSSCellObject *CellObject = ActiveSpreadSheet->GetCellObject(ACol, i);
try {
CellObject->Style->Borders->Edges[eLeft]->Style = AStyle;
}
__finally {
delete CellObject;
}
}
}
void __fastcall TFeaturesMainForm::MeasureItem(TObject *Sender, TCanvas *ACanvas,
int &Width, int &Height)
{
Width = 14;
Height = 24;
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::DrawItem(TObject *Sender, TCanvas *ACanvas,
TRect &ARect, bool Selected)
{
if (Selected)
ACanvas->Brush->Color = clHighlight;
else
ACanvas->Brush->Color = clMenu;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(ARect);
imgBordersImages->Draw(ACanvas, ARect.Left + 2, ARect.Top + 2, ((TMenuItem*)Sender)->ImageIndex, true);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::BordersClick(TObject *Sender)
{
TcxSSEdgeLineStyle AOutBorders[12][4] =
{{lsDefault, lsDefault, lsDefault, lsDefault},
{lsNone, lsNone, lsNone, lsDouble},
{lsNone, lsThin, lsNone, lsThick},
{lsNone, lsNone, lsNone, lsThin},
{lsNone, lsNone, lsNone, lsThick},
{lsThin, lsThin, lsThin, lsThin},
{lsThin, lsNone, lsNone, lsNone},
{lsNone, lsThin, lsNone, lsThin},
{lsThin, lsThin, lsThin, lsThin},
{lsNone, lsNone, lsThin, lsNone},
{lsNone, lsThin, lsNone, lsDouble},
{lsThick, lsThick, lsThick, lsThick}};
TcxSSEdgeLineStyle AInBorders[2] = {lsDefault, lsThin};
TRect ARect;
SheetBook->BeginUpdate();
try {
ARect = ActiveSpreadSheet->SelectionRect;
int AKey = ((TMenuItem*)Sender)->ImageIndex;
SetVertStyle(ARect, ARect.Left, AOutBorders[AKey][eLeft]);
SetHorzStyle(ARect, ARect.Top, AOutBorders[AKey][eTop]);
SetVertStyle(ARect, ARect.Right + 1, AOutBorders[AKey][eRight]);
SetHorzStyle(ARect, ARect.Bottom + 1, AOutBorders[AKey][eBottom]);
for (int i = ARect.Top + 1; i <= ARect.Bottom; i++)
SetHorzStyle(ARect, i, AInBorders[AKey == 5]);
for (int i = ARect.Left + 1; i <= ARect.Right; i++)
SetVertStyle(ARect, i, AInBorders[AKey == 5]);
}
__finally{
SheetBook->EndUpdate();
SheetBook->UpdateControl();
}
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actSaveAsExecute(TObject *Sender)
{
//
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::tbBorderStyleClick(TObject *Sender)
{
TRect ARect;
TPoint APoint;
ARect = tbBorderStyle->BoundsRect;
ARect.Left = tbsFormatting->ClientToScreen(Point(ARect.Left, ARect.Top)).x;
ARect.Top = tbsFormatting->ClientToScreen(Point(ARect.Left, ARect.Top)).y;
ARect.Right = tbsFormatting->ClientToScreen(Point(ARect.Right, ARect.Bottom)).x;
ARect.Bottom = tbsFormatting->ClientToScreen(Point(ARect.Right, ARect.Bottom)).y;
tbBorderStyle->Down = true;
pmBorders->Popup(ARect.Left, ARect.Bottom);
tbBorderStyle->Down = false;
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::cbxFontKeyPress(TObject *Sender, char &Key)
{
if (Key == 13)
_WINUSER_::SetFocus(SheetBook->Handle);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::pmUndoPopup(TObject *Sender)
{
while (((TPopupMenu*)Sender)->Items->Count > 0)
((TPopupMenu*)Sender)->Items->Delete(0);
TMenuItem *Item;
for(int i=0; i <= SheetBook->History->UndoActions->Count; i++)
{
Item = new TMenuItem(static_cast<TPopupMenu*>(Sender));
if (i < SheetBook->History->UndoActions->Count)
Item->Caption = SheetBook->History->UndoActions->Item[i]->Description;
else
Item->Caption = " ";
Item->OnMeasureItem = URMeasureItem;
Item->OnDrawItem = URDrawItem;
Item->OnClick = UndoItemClick;
static_cast<TPopupMenu*>(Sender)->Items->Add(Item);
}
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::pmRedoPopup(TObject *Sender)
{
while (((TPopupMenu*)Sender)->Items->Count > 0)
((TPopupMenu*)Sender)->Items->Delete(0);
TMenuItem *Item;
for(int i=0; i <= SheetBook->History->RedoActions->Count; i++)
{
Item = new TMenuItem((TComponent*)Sender);
if (i < SheetBook->History->RedoActions->Count)
Item->Caption = SheetBook->History->RedoActions->Item[i]->Description;
else
Item->Caption = " ";
Item->OnMeasureItem = URMeasureItem;
Item->OnDrawItem = URDrawItem;
Item->OnClick = RedoItemClick;
((TPopupMenu*)Sender)->Items->Add(Item);
}
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::URMeasureItem(TObject *Sender,
TCanvas *ACanvas, int &Width, int &Height)
{
Width = 90;
if (((TMenuItem*)Sender)->MenuIndex == ((TPopupMenu*)((TComponent*)Sender)->Owner)->Items->Count - 1)
Height = ACanvas->TextHeight("W") + FSummaryItemHeight; else
Height = ACanvas->TextHeight("W");
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::URDrawItem(TObject *Sender,
TCanvas *ACanvas, const TRect &ARect, bool Selected)
{
String Str;
if (((TComponent*)Sender)->Owner->Name == "pmUndo")
Str = "Undo %d Actions";
else
Str = "Redo %d Actions";
DrawUndoRedoItem((TPopupMenu*)((TComponent*)Sender)->Owner, (TMenuItem*)Sender, ACanvas, ARect, Selected, Str);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::UndoItemClick(TObject *Sender)
{
if (((TMenuItem*)Sender)->MenuIndex < ((TPopupMenu*)((TMenuItem*)Sender)->Owner)->Items->Count - 1)
SheetBook->History->Undo(((TMenuItem*)Sender)->MenuIndex + 1);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::RedoItemClick(TObject *Sender)
{
if (((TMenuItem*)Sender)->MenuIndex < ((TPopupMenu*)((TMenuItem*)Sender)->Owner)->Items->Count - 1)
SheetBook->History->Redo(((TMenuItem*)Sender)->MenuIndex + 1);
}
//---------------------------------------------------------------------------
void __fastcall UpdatePreviousItems(TPopupMenu *APopupMenu, TCanvas *ACanvas, const TRect ARect, int AIndex)
{
TRect Rec;
Rec = ARect;
String Str;
int i;
for(i = AIndex - 1; i >= 0; i--){
Rec = Rect(Rec.Left, ACanvas->TextHeight('W') * i, Rec.Right, ACanvas->TextHeight('W') * (i + 1));
ACanvas->Brush->Color = clHighlight;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(Rec);
ACanvas->TextRect(Rec, Rec.Left, Rec.Top, APopupMenu->Items[0].Items[i]->Caption);
}
}
void __fastcall UpdateNextItems(TPopupMenu *APopupMenu, TCanvas *ACanvas, TRect ARect, int Index)
{
TRect Rec;
Rec = ARect;
String Str;
for (int i=Index+1; i <= APopupMenu->Items->Count - 2; i++){
Rec = Rect(Rec.Left, Rec.Top + ACanvas->TextHeight('W'), Rec.Right, Rec.Bottom + ACanvas->TextHeight('W'));
ACanvas->Brush->Color = clMenu;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(Rec);
ACanvas->TextRect(Rec, Rec.Left, Rec.Top, APopupMenu->Items[0].Items[i]->Caption);
}
}
void __fastcall TFeaturesMainForm::DrawActionsCount(TPopupMenu *APopupMenu, TCanvas *ACanvas, TMenuItem *ASender, const TRect ARect, String AInfoStr)
{
TRect Rec;
int ActionsCount, Btn;
String Str;
if ((APopupMenu->Items->Count - 1) == ASender->MenuIndex)
{
Btn = (APopupMenu->Items->Count - 1) * ACanvas->TextHeight('W') - 1 + (ARect.Bottom - ARect.Top);
ActionsCount = ASender->MenuIndex;
} else
{
Btn = (APopupMenu->Items->Count - 1) * ACanvas->TextHeight('W') - 1 + FSummaryItemHeight + (ARect.Bottom - ARect.Top);
ActionsCount = ASender->MenuIndex + 1;
}
Rec = Rect(ARect.Left + 1, (APopupMenu->Items->Count - 1) * ACanvas->TextHeight('W') + 1,
ARect.Right - 1, Btn);
ACanvas->Brush->Color = clMenu;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(Rec);
Str = Format(AInfoStr, ARRAYOFCONST(((int)ActionsCount)));
div_t lft = div(Rec.Left + Rec.Right, 2), tw = div(ACanvas->TextWidth(Str), 2);
int leftpar = lft.quot - tw.quot;
div_t tp = div(Rec.Top + Rec.Bottom, 2), th = div(ACanvas->TextHeight(Str), 2);
int toppar = tp.quot - th.quot;
Frame3D(ACanvas, Rec, clBtnShadow, clBtnHighlight, 1);
ACanvas->TextRect(Rec, leftpar, toppar, Str);
}
void __fastcall TFeaturesMainForm::DrawUndoRedoItem(TPopupMenu *APopupMenu, TMenuItem *ASender, TCanvas *ACanvas, const TRect ARect, bool Selected, String AInfoStr)
{
if (ASender->MenuIndex == (APopupMenu->Items->Count - 1)) {
ACanvas->Brush->Color = clMenu;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(ARect);
if (Selected){
UpdatePreviousItems(APopupMenu, ACanvas, ARect, ASender->MenuIndex);
}
}
else{
if (Selected){
ACanvas->Brush->Color = clHighlight;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(Rect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom));
UpdatePreviousItems(APopupMenu, ACanvas, ARect, ASender->MenuIndex);
}
else {
ACanvas->Brush->Color = clMenu;
ACanvas->Brush->Style = bsSolid;
ACanvas->FillRect(ARect);
UpdateNextItems(APopupMenu, ACanvas, ARect, ASender->MenuIndex);
}
ACanvas->TextRect(ARect, ARect.Left, ARect.Top, ASender->Caption);
}
DrawActionsCount(APopupMenu, ACanvas, ASender, ARect, AInfoStr);
}
void __fastcall TFeaturesMainForm::actHistory(TObject *Sender)
{
((TCustomAction*)(Sender))->Enabled = (SheetBook->History->UndoActions->Count > 0);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actRedoUpdate(TObject *Sender)
{
((TCustomAction*)(Sender))->Enabled = (SheetBook->History->RedoActions->Count > 0);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actUndoExecute(TObject *Sender)
{
SheetBook->History->Undo(1);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::actRedoExecute(TObject *Sender)
{
SheetBook->History->Redo(1);
}
//---------------------------------------------------------------------------
void __fastcall TFeaturesMainForm::IsEditorMode(TObject *Sender)
{
((TCustomAction*)Sender)->Enabled = !((TFeatureChildForm*)ActiveMDIChild)->IsEditorMode;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -