⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ribbonnotepaddemomain.cpp

📁 胜天进销存源码,国产优秀的进销存
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	Editor->OnChange(Editor);
  }
  else {
    FCanOnChange = true;
  }
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  if (Editor->Modified)
    switch (QuerySaveFile()) {
      case ID_YES: CanClose = SaveFile(false); return;
      case ID_NO: CanClose = true; return;
      case ID_CANCEL: CanClose = false;
    }
}
//---------------------------------------------------------------------------

int __fastcall TRibbonDemoMainForm::GetEditorCol()
{
  return (Editor->SelStart - SendMessage(Handle, EM_LINEINDEX, EditorRow, 0));
}
//---------------------------------------------------------------------------

int __fastcall TRibbonDemoMainForm::GetEditorRow()
{
  return (SendMessage(Handle, EM_LINEFROMCHAR, Editor->SelStart, 0));
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::MakeNewDocument()
{
  Editor->Clear();
  SetModified(False);
  FileName = sDefaultDocName;
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::OpenFile(AnsiString AFileName)
{
  if (Editor->Modified)
  {
    switch (QuerySaveFile()) {
      case mrYes    : if (! SaveFile(false)) return; break;
      case mrCancel : return;
    }

  }
  OpenDialog->FileName = AFileName;
  if ((AFileName != "") || OpenDialog->Execute()) {
    FileName = OpenDialog->FileName;
    Editor->Lines->LoadFromFile(FileName);
    SetModified(false);
  }
}
//---------------------------------------------------------------------------

int __fastcall TRibbonDemoMainForm::QuerySaveFile()
{
  String S = "Do you want to save the changes you made to " + Ribbon->DocumentName + "?";
  String Title = Application->Title;
  return (Application->MessageBox(S.c_str(), Title.c_str(), /*MB_ICONQUESTION ||*/ MB_YESNOCANCEL));
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::ReplaceOne(TObject *Sender)
{
  TReplaceDialog *ADialog = ((TReplaceDialog*) Sender);
  int ReplacedCount, OldSelStart, PrevSelStart;
  AnsiString S;

  ReplacedCount = 0;
  OldSelStart = Editor->SelStart;
  if (ADialog->Options.Contains(frReplaceAll)) Screen->Cursor = crHourGlass;
  do
  {
    if ((Editor->SelLength > 0) && ((Editor->SelText == ADialog->FindText) ||
      (!(ADialog->Options.Contains(frMatchCase)) &&
       (AnsiUpperCase(Editor->SelText) == AnsiUpperCase(ADialog->FindText)))))
    {
      Editor->SelText = ADialog->ReplaceText;
      ReplacedCount++;
    }
    PrevSelStart = Editor->SelStart;
    FindOne(Sender);
  }
  while (ADialog->Options.Contains(frReplaceAll) && (Editor->SelStart != PrevSelStart));
  if (ADialog->Options.Contains(frReplaceAll))
  {
    Screen->Cursor = crDefault;
    if (ReplacedCount == 0) 
      S = sRichEditTextNotFound;
    else
    {
      Editor->SelStart = OldSelStart;
      S = Format(sRichEditReplaceAllResult, ARRAYOFCONST((ReplacedCount)));
    }
    Application->MessageBox(S.c_str(), sRichEditFoundResultCaption,
      MB_ICONINFORMATION);
  }
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::RibbonResize(TObject *Sender)
{
  const Space = 8;

  Editor->SetBounds(Space, Ribbon->Height + Space, ClientWidth - Space * 2,
    ClientHeight - (Ribbon->Height + dxStatusBar->Height + Space * 2));
  if (Ribbon->QuickAccessToolbar->Position == qtpAboveRibbon)
    dxBarLargeButton8->Down = true;
  else
    dxBarLargeButton9->Down = true;
}
//---------------------------------------------------------------------------

bool __fastcall TRibbonDemoMainForm::SaveFile(bool ASaveAs, bool APlainText)
{
  bool Result;

  SaveDialog->FileName = ChangeFileExt(ExtractFileName(FileName), "");

  if (APlainText)
    SaveDialog->Filter = TXTFilter;
  else
    SaveDialog->Filter = RTFFilter;

  ASaveAs = ASaveAs || (FileName == "") || (FileName == sDefaultDocName);
  Result = !ASaveAs || SaveDialog->Execute();
  if (Result)
  {
    Editor->PlainText = APlainText;
    Editor->Lines->SaveToFile(SaveDialog->FileName);
    if (!APlainText)
    {
      SetModified(false);
      if (ASaveAs)
        FileName = SaveDialog->FileName;
    };
  }
  return Result;
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::SetColorScheme(AnsiString AName)
{
  Ribbon->ColorSchemeName = AName;
  dxBarLargeButtonBlueScheme->Down = (AName == "Blue");
  dxBarLargeButtonBlackScheme->Down = (AName == "Black");
  dxBarLargeButtonSilverScheme->Down = (AName == "Silver");
  dxStatusBar->Invalidate();
  Panel1->Color = Ribbon->ColorScheme->GetPartColor(rfspRibbonForm);
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::SetFileName(AnsiString Value)
{
  int AIndex;

  Ribbon->DocumentName = ExtractFileName(Value);
  FFileName = Value;

  if (FileExists(FFileName))
  {
    AIndex = ApplicationMenu->ExtraPaneItems->IndexOf(FFileName);
    if (AIndex > -1)
      ApplicationMenu->ExtraPaneItems->Delete(AIndex);
    ApplicationMenu->ExtraPaneItems->Insert(0)->Text = FFileName;
  }
}
//---------------------------------------------------------------------------

void TRibbonDemoMainForm::AssignFontColorGlyph()
{
  dxBarButtonFontColor->Glyph = rgiFontColor->Glyph;
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::FontColorChanged(TObject *Sender)
{
  AssignFontColorGlyph();
  dxBarButtonFontColorClick(NULL);
}
//---------------------------------------------------------------------------

void TRibbonDemoMainForm::SetFontColor()
{
  Editor->SelAttributes->Color = FColorPickerController->Color;
  FEditorUndoController->AddAction(6);
}
//---------------------------------------------------------------------------

void TRibbonDemoMainForm::Undo(int Count)
{
  FEditorUndoController->Lock();
  try
  {
	while (Count > 0)
	{
	  SendMessage(Editor->Handle, EM_UNDO, 0, 0);
	  FEditorUndoController->PopUndo();
	  Count--;
	}
  }
  __finally
  {
	FEditorUndoController->UnLock();
  }
}
//---------------------------------------------------------------------------

void TRibbonDemoMainForm::AddSymbolItem(TdxRibbonGalleryGroup *AGroup, int ACode)
{
  TdxRibbonGalleryGroupItem *AItem;
  String AFont;
  TcxBitmap *ABitmap;
  WideChar AChar;

  AItem = AGroup->Items->Add();
  AFont = "Times New Roman";
  AItem->Caption = AFont + " #" + IntToStr(ACode);
  AItem->Description = AFont;
  AItem->Tag = ACode;

  // CreateBitmap
  try
  {
	int AGlyphSize;
	TRect R;

	AGlyphSize = 32 * Screen->PixelsPerInch / 96;
	R = Rect(0, 0, AGlyphSize, AGlyphSize);
	ABitmap = new TcxBitmap(AGlyphSize, AGlyphSize, pf32bit);
	ABitmap->Canvas->Brush->Color = (TColor)0xFAFAFA;
	ABitmap->Canvas->FillRect(R);
	ABitmap->Canvas->Font->Name = AFont;
	ABitmap->Canvas->Font->Color = (TColor)0x5C534C;
	ABitmap->Canvas->Font->Size = 16 * Screen->PixelsPerInch / 96;
	AChar = (WideChar)ACode;
	DrawTextW(ABitmap->Canvas->Handle, &AChar, 1, &R, DT_CENTER || DT_VCENTER || DT_SINGLELINE);
	ABitmap->TransformBitmap(btmSetOpaque);
	AItem->Glyph = ABitmap;
  }
  __finally
  {
	ABitmap->Free();
  }
}
//---------------------------------------------------------------------------

void TRibbonDemoMainForm::InitSymbolGallery()
{
  const
	int AMathMap[] = {0xB1, 0x2260, 0x2264, 0x2265, 0xF7, 0xD7, 0x221E, 0x2211};
	int AGreekMap[] = {0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA};
	int ASymbolMap[] = {0xA9, 0xAE, 0x2122};
	int ACurrencyMap[] = {0x20AC, 0x24, 0xA3, 0xA5, 0x20A3};

  int I;

  for (I = 0; I < 8; I++)
	AddSymbolItem(rgiItemSymbol->GalleryGroups->Items[0], AMathMap[I]);
  for (I = 0; I < 10; I++)
	AddSymbolItem(rgiItemSymbol->GalleryGroups->Items[1], AGreekMap[I]);
  for (I = 0; I < 3; I++)
	AddSymbolItem(rgiItemSymbol->GalleryGroups->Items[2], ASymbolMap[I]);
  for (I = 0; I < 5; I++)
	AddSymbolItem(rgiItemSymbol->GalleryGroups->Items[3], ACurrencyMap[I]);
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::SetModified(bool Value)
{
  Editor->Modified = Value;
  if (Value)
  {
    stModified->ImageIndex = 2;
    stModified->Caption = "Modified";
  }
  else
  {
    stModified->ImageIndex = -1;
    stModified->Caption = "";
  }
  dxBarButtonSave->Enabled = Value;
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::ShowItems(bool AShow)
{
  BarManager->LockUpdate = true;
  try
  {
    if (!AShow) 
    {
      btnLineNumber->Caption = "";
      btnColumnNumber->Caption = "";
      stModified->Caption = "";
	}
	BarManager->Groups[0]->Enabled = AShow;
  }
  __finally
  {
	BarManager->LockUpdate = false;
  }

}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::RibbonHelpButtonClick(TdxCustomRibbon *Sender)
{
  ShowMessage("Clicked!");
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::RibbonHideMinimizedByClick(
	  TdxCustomRibbon *Sender, DWORD AWnd, TShiftState AShift,
	  const TPoint &APos, bool &AAllowProcessing)
{
  AAllowProcessing = ((HWND *)AWnd != Editor->Handle);
}
//---------------------------------------------------------------------------
void __fastcall TRibbonDemoMainForm::dxBarButtonOptionsClick(
	  TObject *Sender)
{
  String AColorSchemeName;
  TScreenTipOptions AScreenTipOptions;
  AColorSchemeName = Ribbon->ColorSchemeName;
  AScreenTipOptions.ShowScreenTips = BarManager->ShowHint;
  AScreenTipOptions.ShowDescripitons = dxBarScreenTipRepository1->ShowDescription;
  if (RibbonDemoOptionsForm->GetOptions(AColorSchemeName, AScreenTipOptions))
  {
	SetColorScheme(AColorSchemeName);
	BarManager->ShowHint = AScreenTipOptions.ShowScreenTips;
	dxBarScreenTipRepository1->ShowDescription = AScreenTipOptions.ShowDescripitons;
  }
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::dxBarButtonFontColorClick(TObject *Sender)
{
  SetFontColor();
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::rgiItemSymbolGroupItemClick(
	  TdxRibbonGalleryItem *Sender, TdxRibbonGalleryGroupItem *AItem)
{
//
}
//---------------------------------------------------------------------------

__fastcall TRichEditUndoController::TRichEditUndoController(TdxRibbonGalleryItem *AGalleryItem,
  TRichEdit *AEditor)
{
  FGalleryItem = AGalleryItem;
  FEditor = AEditor;
}
//---------------------------------------------------------------------------

void TRichEditUndoController::AnalyseMessage()
{
  int AMessageID;
  if (!FIsLocked)
  {
	AMessageID = SendMessage(FEditor->Handle, EM_GETUNDONAME, 0, 0);
	if ((AMessageID > 1) || (AMessageID == 1) && (AMessageID != FLastMessageID))
	  AddAction(AMessageID);
  }
}
//---------------------------------------------------------------------------

void TRichEditUndoController::Lock()
{
  FIsLocked = True;
  FLastMessageID = 0;
}
//---------------------------------------------------------------------------

void TRichEditUndoController::UnLock()
{
  FIsLocked = False;
}
//---------------------------------------------------------------------------

void TRichEditUndoController::AddAction(int AnActionID)
{
  String RichEditAction[7] = {"Unknown", "Typing", "Delete",
	  "Drug And Drop", "Cut", "Paste", "Color Change"};
  //if (AnActionID != 6 /*|| (FEditor->GetSelLength() != 0)*/)
	PushUndo(RichEditAction[AnActionID]);
  FLastMessageID = AnActionID;
}
//---------------------------------------------------------------------------

void TRichEditUndoController::PopUndo()
{
  TdxRibbonGalleryGroup *AGroup;
  AGroup = FGalleryItem->GalleryGroups->Items[0];
  if (AGroup->Items->Count > 0)
	AGroup->Items->Delete(0);
}
//---------------------------------------------------------------------------

void TRichEditUndoController::PushUndo(String AnAction)
{
  TdxRibbonGalleryGroup *AGroup;
  AGroup = RibbonDemoMainForm->rgiUndo->GalleryGroups->Items[0];
  AGroup->Items->Insert(0);
  AGroup->Items->Items[0]->Caption = AnAction;
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::rgiUndoHotTrackedItemChanged(
  TdxRibbonGalleryGroupItem *APrevHotTrackedGroupItem,
  TdxRibbonGalleryGroupItem *ANewHotTrackedGroupItem)
{
  int ACount;
  String AString;
  if (ANewHotTrackedGroupItem != NULL)
  {
	ACount = ANewHotTrackedGroupItem->Index + 1;
	bstSelectionInfo->Caption = "Undo " + IntToStr(ACount);
	if (ACount == 1)
	{
	  AString = " Action";
	}
	else
	{
	  AString = " Actions";
	}
	bstSelectionInfo->Caption = bstSelectionInfo->Caption + AString;
  }
  else
	bstSelectionInfo->Caption = "Cancel";
}
//---------------------------------------------------------------------------

void __fastcall TRibbonDemoMainForm::rgiUndoGroupItemClick(
	  TdxRibbonGalleryItem *Sender, TdxRibbonGalleryGroupItem *AItem)
{
  Undo(AItem->Index + 1);
}
//---------------------------------------------------------------------------
#undef HDC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -