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

📄 ebarmdidemomain.cpp

📁 胜天进销存源码,国产优秀的进销存
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <shellapi.h>
#pragma hdrstop

#include "EBarMDIDemoMain.h"
#include "EBarMDIDemoChild.h"
#include "EBarsDemoRating.h"
#include "EBarMDIDemoAbout.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "dxBar"
#pragma link "dxBarExtItems"
#pragma link "cxControls"
#pragma link "dxStatusBar"
#pragma link "cxGraphics"
#pragma link "dxStatusBar"
#pragma resource "*.dfm"
TEBarMDIDemoMainForm *EBarMDIDemoMainForm;

char
  *sRichEditFoundResultCaption = "Information",
  *sRichEditTextNotFound = "The search text is not found.",
  *sRichEditReplaceAllResult = "Replaced %d occurances.";

//---------------------------------------------------------------------------

__fastcall TEBarMDIDemoMainForm::TEBarMDIDemoMainForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

TRichEdit *__fastcall TEBarMDIDemoMainForm::GetEditor()
{
  if (ActiveMDIChild == NULL) return NULL;
  else return ((TEBarMDIDemoChildForm*) ActiveMDIChild)->Editor;
}
//---------------------------------------------------------------------------

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

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

AnsiString __fastcall TEBarMDIDemoMainForm::GetFileName()
{
  if (ActiveMDIChild == NULL) return NULL;
  else return ((TEBarMDIDemoChildForm*) ActiveMDIChild)->FileName;
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::SetFileName(AnsiString Value)
{
  if (ActiveMDIChild != NULL)
    ((TEBarMDIDemoChildForm*) ActiveMDIChild)->FileName = Value;
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::EditorChange(TObject *Sender)
{
  if (Editor == NULL) return;
  Editor->OnSelectionChange(Editor);
  SetModified(Editor->Modified);
  dxStatusBar->Panels->Items[1]->Text = ActiveMDIChild->Caption;
  ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[1]->PanelStyle)->ImageIndex = 0;
  ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[0]->PanelStyle)->ImageIndex = 2;
  dxBarButtonUndo->Enabled = (SendMessage(Editor->Handle, EM_CANUNDO, 0, 0) != 0);
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::EditorSelectionChange(TObject *Sender)
{
  FUpdating = True;
  try
  {
    dxBarComboFontSize->OnChange = 0;
    dxBarComboFontName->OnChange = 0;
    dxBarComboFontColor->OnChange = 0;
    dxStatusBar->Panels->Items[0]->Text =
      Format("Line: %3d   Col: %3d", ARRAYOFCONST((1 + EditorRow, 1 + EditorCol)));

    dxBarButtonCopy->Enabled = Editor->SelLength > 0;
    dxBarButtonCut->Enabled = dxBarButtonCopy->Enabled;
    dxBarButtonPaste->Enabled = (SendMessage(Editor->Handle, EM_CANPASTE, 0, 0) != 0);
    dxBarButtonClear->Enabled = dxBarButtonCopy->Enabled;

    dxBarComboFontSize->Text = IntToStr(Editor->SelAttributes->Size);
    dxBarComboFontName->Text = Editor->SelAttributes->Name;
    dxBarComboFontColor->Color = Editor->SelAttributes->Color;

    dxBarButtonBold->Down = Editor->SelAttributes->Style.Contains(fsBold);
    dxBarButtonItalic->Down = Editor->SelAttributes->Style.Contains(fsItalic);
    dxBarButtonUnderline->Down = Editor->SelAttributes->Style.Contains(fsUnderline);

    dxBarButtonBullets->Down = Boolean(Editor->Paragraph->Numbering);
    switch ((int) Editor->Paragraph->Alignment)
    {
      case 0: dxBarButtonAlignLeft->Down = True; break;
      case 1: dxBarButtonAlignRight->Down = True; break;
      case 2: dxBarButtonCenter->Down = True; break;
    }
    dxBarButtonProtected->Down = Editor->SelAttributes->Protected;
  }
  __finally
  {
    FUpdating = False;
    dxBarComboFontSize->OnChange = dxBarComboFontSizeChange;
    dxBarComboFontName->OnChange = dxBarComboFontNameChange;
    dxBarComboFontColor->OnChange = dxBarComboFontColorChange;
  }
}
//---------------------------------------------------------------------------

bool __fastcall TEBarMDIDemoMainForm::SaveFile(bool ASaveAs)
{
  if (ASaveAs || (FileName == ""))
  {
    SaveDialog->FileName = FileName;
    if (!SaveDialog->Execute()) return False;
    FileName = SaveDialog->FileName;
  }
  Editor->Lines->SaveToFile(FileName);
  SetModified(False);
  return True;
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::SetModified(bool Value)
{
  Editor->Modified = Value;
  if (Value) {
    dxStatusBar->Panels->Items[2]->Text = "Modified";
    ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[2]->PanelStyle)->ImageIndex = 1;
  }
  else {
    dxStatusBar->Panels->Items[2]->Text = "";
    ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[2]->PanelStyle)->ImageIndex = 4;
  }  
  dxBarButtonSave->Enabled = Value;
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::ShowItems(bool AShow)
{
  TdxBarItemVisible AVisible;

  BarManager->LockUpdate = True;

  if (!AShow)
  {
    dxStatusBar->Panels->Items[0]->Text = "";
    dxStatusBar->Panels->Items[1]->Text = "";
  }
  BarManager->Groups[0]->Enabled = AShow;

  if (AShow) AVisible = ivAlways;
  else AVisible = ivInCustomizing;

  dxBarSubItemEdit->Visible = AVisible;
  dxBarSubItemFormat->Visible = AVisible;

  BarManager->LockUpdate = False;
  ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[0]->PanelStyle)->ImageIndex = 5;
  ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[1]->PanelStyle)->ImageIndex = 3;
  ((TdxStatusBarTextPanelStyle*)dxStatusBar->Panels->Items[2]->PanelStyle)->ImageIndex = 4;
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::FormCreate(TObject *Sender)
{
  dmCommonData->AboutFormClass = __classid(TEBarMDIDemoAboutForm);

  const AnsiString Filter = "Rich Text Files (*.RTF)|*.RTF";

  OpenDialog->Filter = Filter;
  SaveDialog->Filter = Filter;
  OpenDialog->InitialDir = ExtractFilePath(ParamStr(0));
  SaveDialog->InitialDir = OpenDialog->InitialDir;
  ShowItems(False);
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::dxBarButtonNewClick(TObject *Sender)
{
  new TEBarMDIDemoChildForm(Application);
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::dxBarButtonOpenClick(TObject *Sender)
{
  OpenDialog->FileName = "";
  if (OpenDialog->Execute())
  {
    TEBarMDIDemoChildForm *AForm = new TEBarMDIDemoChildForm(Application);
    AForm->FileName = OpenDialog->FileName;
    AForm->Editor->Lines->LoadFromFile(AForm->FileName);
    SetModified(False);
    dxBarMRUFiles->RemoveItem(OpenDialog->FileName, NULL);
  }
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::dxBarButtonCloseClick(TObject *Sender)
{
  ActiveMDIChild->Close();
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::dxBarButtonSaveClick(TObject *Sender)
{
  SaveFile(False);
}
//---------------------------------------------------------------------------

void __fastcall TEBarMDIDemoMainForm::FindOne(TObject *Sender)
{
  TFindDialog *ADialog = ((TFindDialog*) Sender);
  int StartPos, FindLength, FoundAt;
  TSearchTypes Flags;
  TPoint P;
  RECT R, CaretR, IntersectR;

  if (ADialog->Options.Contains(frDown))
  {
    if (Editor->SelLength == 0) StartPos = Editor->SelStart;
    else StartPos = Editor->SelStart + Editor->SelLength;
    FindLength = Editor->Text.Length() - StartPos;
  }
  else
  {
    StartPos = Editor->SelStart;
    FindLength = -StartPos;
  }
  Flags.Clear();
  if (ADialog->Options.Contains(frMatchCase)) Flags << stMatchCase;
  if (ADialog->Options.Contains(frWholeWord)) Flags << stWholeWord;
  Screen->Cursor = crHourGlass;
  FoundAt = Editor->FindText(ADialog->FindText, StartPos, FindLength, Flags);
  if (!(ADialog->Options.Contains(frReplaceAll))) Screen->Cursor = crDefault;
  if (FoundAt > -1)
    if (ADialog->Options.Contains(frReplaceAll))
    {
      Editor->SelStart = FoundAt;
      Editor->SelLength = ADialog->FindText.Length();
    }
    else
    {
      Editor->SetFocus();
      Editor->SelStart = FoundAt;
      Editor->SelLength = ADialog->FindText.Length();

      GetCaretPos(&P);
      P = Editor->ClientToScreen(P);
      CaretR = Rect(P.x, P.y, P.x + 2, P.y + 20);
      GetWindowRect(Editor->Handle, &R);
      if (IntersectRect(&IntersectR, &CaretR, &R))
        if (P.y < Screen->Height / 2)
          ADialog->Top = P.y + 40;
        else
          ADialog->Top = P.y - (R.bottom - R.top + 20);
    }
  else
    if (!(ADialog->Options.Contains(frReplaceAll)))
      Application->MessageBox(sRichEditTextNotFound,
        sRichEditFoundResultCaption, MB_ICONINFORMATION);

⌨️ 快捷键说明

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