RSS    

   Реферат: Разработка текстового редактора

RightInd->Left = Ruler->ClientWidth-6-int(

(RichEdit1->Paragraph->RightIndent+GutterWid)*RulerAdj);

if (CurrText()->Style==CurrText()->Style  >> fsItalic)

 ToolButton17->Down=false;

 else ToolButton17->Down=true;

if (CurrText()->Style==CurrText()->Style  >> fsBold)

 ToolButton15->Down=false;

 else ToolButton15->Down=true;

if (CurrText()->Style==CurrText()->Style  >> fsUnderline)

 ToolButton3->Down=false;

 else ToolButton3->Down=true;

Edit2->Text = itoa(RichEdit1->SelAttributes->Size, sizebuf, 10);

if (RichEdit1->Paragraph->Alignment == taLeftJustify)

LeftAlign->Down=true;

else LeftAlign->Down=false;

if (RichEdit1->Paragraph->Alignment == taCenter)

CenterAlign->Down=true;

else CenterAlign->Down=false;

if (RichEdit1->Paragraph->Alignment == taRightJustify)

RightAlign->Down=true;

else RightAlign->Down=false;

if(RichEdit1->Paragraph->Numbering == TNumberingStyle(nsBullet))

ToolButton14->Down=true;

else ToolButton14->Down=false;

                    }

     catch (...) {

       FUpdating = False;

                 }

     FUpdating = False;

 }

TTextAttributes *__fastcall TForm1::CurrText(void)

{

    return RichEdit1->SelAttributes;

}

void __fastcall TForm1::FileNew1Execute(TObject *Sender)

{

FFileName = LoadStr(sUntitled);

RichEdit1->Lines->Clear();

RichEdit1->Modified = false;

}

void __fastcall TForm1::FileOpen1Execute(TObject *Sender)

{

   if (OpenDialog->Execute())

{

      RichEdit1->Lines->LoadFromFile(OpenDialog->FileName);

      FFileName = OpenDialog->FileName;

      RichEdit1->SetFocus();

      RichEdit1->Modified = false;

     RichEdit1->ReadOnly = OpenDialog->Options.Contains(ofReadOnly);

                Form1->Caption = OpenDialog->FileName;

}

}

void __fastcall TForm1::FileSave1Execute(TObject *Sender)

{

if (FFileName == LoadStr(sUntitled))

           {

        FileSaveAs1Execute(Sender);

        Form1->Caption = SaveDialog->FileName; }

else

{

     RichEdit1->Lines->SaveToFile(FFileName);

     RichEdit1->Modified = false;     }

}

void __fastcall TForm1::FileSaveAs1Execute(TObject *Sender)

{

String str;

TVarRec vrs[1];

if (SaveDialog->Execute())

{

      if (FileExists(SaveDialog->FileName))

      {

         str = FmtLoadStr(sOverwrite, OPENARRAY(TVarRec, (SaveDialog->FileName)));

         if (MessageDlg(str, mtConfirmation, TMsgDlgButtons() << mbYes << mbNo <<

          mbCancel, 0) != IDYES)

         return;

      }

      RichEdit1->Lines->SaveToFile(SaveDialog->FileName);

      FFileName = SaveDialog->FileName;

      RichEdit1->Modified = false;

}

}

void __fastcall TForm1::CheckFileSave(void)

{

if ( RichEdit1->Modified ) {

        switch(MessageBox(Handle, "Save Changes?",

          "Confirmation",MB_YESNOCANCEL | MB_ICONQUESTION))

        {  case ID_YES    : FileSave1Execute(this);

           case ID_CANCEL : Abort();

        }

     }

}

void __fastcall TForm1::FileExit1Execute(TObject *Sender)

{

Close();

}

void __fastcall TForm1::HelpAbout1Execute(TObject *Sender)

{

AboutBox->ShowModal();

}

void __fastcall TForm1::UndoClick(TObject *Sender)

{

if ( RichEdit1->HandleAllocated() )

        SendMessage(RichEdit1->Handle, EM_UNDO, 0, 0);

}

void __fastcall TForm1::PrintClick(TObject *Sender)

{

if (PrintDialog1->Execute()) RichEdit1->Print(OpenDialog->FileName);

}

void __fastcall TForm1::Print_SetupClick(TObject *Sender)

{

PrinterSetupDialog1->Execute();

}

void __fastcall TForm1::FindClick(TObject *Sender)

{

  FindDialog1->FindText = RichEdit1->SelText;

    FindDialog1->Execute();

      }

void __fastcall TForm1::FindDialog1Find(TObject *Sender)

{

  int FoundAt, StartPos, ToEnd;

  if (RichEdit1->SelLength)

    StartPos = RichEdit1->SelStart + RichEdit1->SelLength;

  else

    StartPos = 0;

  ToEnd = RichEdit1->Text.Length() - StartPos;

  FoundAt = RichEdit1->FindText(FindDialog1->FindText, StartPos, ToEnd, TSearchTypes()<< stMatchCase);

  if (FoundAt != -1)

  {

    RichEdit1->SetFocus();

    RichEdit1->SelStart = FoundAt;

    RichEdit1->SelLength = FindDialog1->FindText.Length();

  }

}

void __fastcall TForm1::ReplaceDialog1Replace(TObject *Sender)

{

    if (RichEdit1->SelLength == 0)

        FindDialog1Find(Sender);

    else

    {

        RichEdit1->SelText =  ReplaceDialog1->ReplaceText;

        FindDialog1Find(Sender);

    }

    if (ReplaceDialog1->Options.Contains(frReplaceAll))

        while (RichEdit1->SelLength !=0)

            ReplaceDialog1Replace(Sender);

}

void __fastcall TForm1::ReplaceClick(TObject *Sender)

{

ReplaceDialog1->Execute();

}

void __fastcall TForm1::N5Click(TObject *Sender)

{

FontDialog1->Options << fdApplyButton;

 FontDialog1->Execute();

}

void __fastcall TForm1::FontDialog1Apply(TObject *Sender, HWND Wnd)

{

if (ActiveControl->ClassNameIs("TEdit"))

   ((TEdit *)ActiveControl)->Font->Assign(FontDialog1->Font);

  else if (ActiveControl->ClassNameIs("TRichEdit"))

    ((TRichEdit *)ActiveControl)->SelAttributes->Assign(FontDialog1->Font);

  else

    MessageBeep(0);

}

void __fastcall TForm1::prClick(TObject *Sender)

{

ToolButton8->Visible=false;

}

void __fastcall TForm1::rp1Click(TObject *Sender)

{

ToolButton8->Visible=true;

}

void __fastcall TForm1::CenterAlignClick(TObject *Sender)

{

  RichEdit1->Paragraph->Alignment = taCenter;

}

void __fastcall TForm1::LeftAlignClick(TObject *Sender)

{

 RichEdit1->Paragraph->Alignment = taLeftJustify;

}

void __fastcall TForm1::RightAlignClick(TObject *Sender)

{

  RichEdit1->Paragraph->Alignment = taRightJustify;

}

void __fastcall TForm1::SetupRuler(void)

{    int iCtr = 1;

     char sTmp[201];

     while (iCtr < 200)

     Ruler->Caption = (AnsiString)sTmp;

}

void __fastcall TForm1::FormCreate(TObject *Sender)

{

 OpenDialog->InitialDir = ExtractFilePath(ParamStr(0));

 SaveDialog->InitialDir = OpenDialog->InitialDir;

 SetupRuler();

 for (int i = 0; i < Screen->Fonts->Count; i++)

  ComboBox1->Items->Add(Screen->Fonts->Strings[i]);

  RichEdit1->SelStart = 0;

}

void __fastcall TForm1::ToolButton14Click(TObject *Sender)

{

 if(RichEdit1->Paragraph->Numbering == TNumberingStyle(nsBullet))

   RichEdit1->Paragraph->Numbering = TNumberingStyle(nsNone);

 else

   RichEdit1->Paragraph->Numbering = TNumberingStyle(nsBullet);

}

void __fastcall TForm1::ComboBox1Change(TObject *Sender)

{

   TCharsetObject* ChasrsetObject;

   if ( !FUpdating ){

   ChasrsetObject = (TCharsetObject*)ComboBox1->Items->Objects[ComboBox1->ItemIndex];

   CurrText()->Name = ComboBox1->Items->Strings[ComboBox1->ItemIndex];

}

}

void __fastcall TForm1::ToolButton15Click(TObject *Sender)

{

 if (CurrText()->Style == CurrText()->Style >> fsBold)

     CurrText()->Style = CurrText()->Style << fsBold;

  else

     CurrText()->Style = CurrText()->Style >> fsBold;

}

void __fastcall TForm1::ToolButton17Click(TObject *Sender)

{

  if (CurrText()->Style ==CurrText()->Style  >> fsItalic)

     CurrText()->Style = CurrText()->Style << fsItalic;

  else

     CurrText()->Style = CurrText()->Style >> fsItalic;

}

void __fastcall TForm1::Edit2Change(TObject *Sender)

{

  int fontsize = atoi(Edit2->Text.c_str());

     if ((!FUpdating) &&  (fontsize))

     {

      CurrText()->Size = atoi(Edit2->Text.c_str());

     }

}

void __fastcall TForm1::ToolButton3Click(TObject *Sender)

{

 if (CurrText()->Style ==CurrText()->Style  >> fsUnderline)

     CurrText()->Style = CurrText()->Style << fsUnderline;

  else

     CurrText()->Style = CurrText()->Style >> fsUnderline;

}

void __fastcall TForm1::FirstIndMouseDown(TObject *Sender,

      TMouseButton Button, TShiftState Shift, int X, int Y)

{

TLabel * oTmpLabel = (TLabel *)Sender;

     FDragOfs = oTmpLabel->Width / 2;

     oTmpLabel->Left = oTmpLabel->Left+X-FDragOfs;

     FDragging = True;       

}

void __fastcall TForm1::FirstIndMouseUp(TObject *Sender,

      TMouseButton Button, TShiftState Shift, int X, int Y)

{

FDragging = False;

     RichEdit1->Paragraph->FirstIndent = int((FirstInd->Left+FDragOfs-GutterWid) / RulerAdj);

     LeftIndMouseUp(Sender, Button, Shift, X, Y);       

}

void __fastcall TForm1::LeftIndMouseUp(TObject *Sender,

      TMouseButton Button, TShiftState Shift, int X, int Y)

{

FDragging = False;

     RichEdit1->Paragraph->LeftIndent = int((LeftInd->Left+FDragOfs-GutterWid)/

                RulerAdj)-RichEdit1->Paragraph->FirstIndent;

     RichEdit1SelectionChange(Sender);

}

void __fastcall TForm1::FirstIndMouseMove(TObject *Sender,

      TShiftState Shift, int X, int Y)

{

if (FDragging) {

        TLabel * oTmpLabel = (TLabel *)Sender;

        oTmpLabel->Left = oTmpLabel->Left+X-FDragOfs;       

}  

}

void __fastcall TForm1::RightIndMouseUp(TObject *Sender,

      TMouseButton Button, TShiftState Shift, int X, int Y)

{

FDragging = False;

     RichEdit1->Paragraph->RightIndent =

         int((Ruler->ClientWidth-RightInd->Left+FDragOfs-2) /

         RulerAdj)-2*GutterWid;

     RichEdit1SelectionChange(Sender);

}

void __fastcall TForm1::RulerResize(TObject *Sender)

{

RulerLine->Width = (int)Ruler->ClientWidth - (RulerLine->Left*2);       

}

void __fastcall TForm1::FormPaint(TObject *Sender)

{

TRect Rct = Rect(GutterWid, 0, RichEdit1->ClientWidth-GutterWid,

                               ClientHeight);

     SendMessage(RichEdit1->Handle, EM_SETRECT, 0, long(&Rct));;

}

void __fastcall TForm1::FormResize(TObject *Sender)

{

 RichEdit1SelectionChange(Sender);

}

void __fastcall TForm1::FormActivate(TObject *Sender)

{

FileNew1Execute(Sender);

RichEdit1->SetFocus();

}

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)

{

try{

      CheckFileSave();

    }

     catch (...) {

      CanClose = False;

    }

}

void __fastcall TForm1::NRulerClick(TObject *Sender)

{

 if (Ruler->Visible==false)

 {

   Ruler->Visible=true;

   NRuler->Checked=true;}

 else {Ruler->Visible=false; NRuler->Checked=false;

 }

}

void __fastcall TForm1::NPanelClick(TObject *Sender)

{

if (Panel1->Visible==false)

 {

  Panel1->Visible=true;

  NPanel->Checked=true;

 }

else {Panel1->Visible=false;

 NPanel->Checked=false;

 }

}

void __fastcall TForm1::NBarClick(TObject *Sender)

{

if (StatusBar->Visible==false)

 {StatusBar->Visible=true;

 NBar->Checked=true;}

 else { StatusBar->Visible=false;

 NBar->Checked=false;

 }

}


Страницы: 1, 2, 3, 4


Новости


Быстрый поиск

Группа вКонтакте: новости

Пока нет

Новости в Twitter и Facebook

                   

Новости

Обратная связь

Поиск
Обратная связь
Реклама и размещение статей на сайте
© 2010.