Exemplo n.º 1
0
//
/// Saves the contents of the Editor to a file whose name is specified by FileName.
/// Returns true if the write operation is successful.
/// The caller is responsible for any error UI
//
bool
TEditFile::Write(LPCTSTR fileName)
{
  if (!fileName)
  {
    if (FileName)
      fileName = FileName;
    else
      return false;
  }

  TFile file(fileName, TFile::WriteOnly|TFile::PermExclusive|TFile::CreateAlways);
  if (!file.IsOpen())
    return false;

  bool success = false;
  LPTSTR editBuffer = LockBuffer();
  if (editBuffer) {
    success = file.Write(editBuffer, static_cast<int>(::_tcslen(editBuffer)));
    UnlockBuffer(editBuffer);
    if (success)
      ClearModify();
  }
  return success;
}
Exemplo n.º 2
0
//
/// Begins the edit of a new file after calling CanClear to determine that it is
/// safe to clear the text of the editor.
//
void
TEditFile::NewFile()
{
  if (CanClear()) {
    Clear();
    Invalidate();
    ClearModify();
    SetFileName(0);
  }
}
Exemplo n.º 3
0
void StyleManager::EnterStyle()
{
	RichText::FormatInfo f;
	const RichStyle& s = style.Get(list.GetKey());
	f.Set(s.format);
	para.Set(unit, f);
	height <<= RichEdit::DotToPt(s.format.GetHeight());
	face <<= s.format.GetFace();
	bold = s.format.IsBold();
	italic = s.format.IsItalic();
	underline = s.format.IsUnderline();
	strikeout = s.format.IsStrikeout();
	capitals = s.format.capitals;
	ink <<= s.format.ink;
	paper <<= s.format.paper;
	next <<= s.next;
	ClearModify();
	SetupFont0();
	para.EnableNumbering();
}
Exemplo n.º 4
0
//
/// Reads the contents of a previously specified file into the Editor. Returns true
/// if read operation is successful.
/// The caller is responsible for any error UI
//
bool
TEditFile::Read(LPCTSTR fileName)
{
  if (!fileName)
  {
    if (FileName)
      fileName = FileName;
    else
      return false;
  }

  bool   success = false;
  TFile file(fileName, TFile::ReadOnly|TFile::OpenExisting);

  if (file.IsOpen()) {
    long  charsToRead = file.Length();
    if (charsToRead >= 0) {
      Clear();

      // Lock and resize Editor's buffer to the size of the file
      // Then if OK, read the file into editBuffer
      //
      LPTSTR editBuffer = LockBuffer(uint(charsToRead+1));
      if (editBuffer) {
        if (file.Read(editBuffer, uint(charsToRead)) == uint(charsToRead)) {

          // 0 terminate Editor's buffer
          //
          editBuffer[int(charsToRead)] = 0;
          success = true;
          ClearModify();
        }
        UnlockBuffer(editBuffer, true);
      }
    }
  }
  return success;
}
Exemplo n.º 5
0
void ParaFormatting::Set(int unit, const RichText::FormatInfo& formatinfo)
{
	font = formatinfo;
	ruler.Set(unit, RichText::RULER & formatinfo.paravalid ? formatinfo.ruler : Null);
	before.Set(unit, RichText::BEFORE & formatinfo.paravalid ? formatinfo.before : Null);
	lm.Set(unit, RichText::LM & formatinfo.paravalid ? formatinfo.lm : Null);
	indent.Set(unit, RichText::INDENT & formatinfo.paravalid ? formatinfo.indent : Null);
	rm.Set(unit, RichText::RM & formatinfo.paravalid ? formatinfo.rm : Null);
	after.Set(unit, RichText::AFTER & formatinfo.paravalid ? formatinfo.after : Null);
	if(RichText::ALIGN & formatinfo.paravalid)
		align <<= formatinfo.align == ALIGN_LEFT    ? 0 :
		          formatinfo.align == ALIGN_CENTER  ? 1 :
		          formatinfo.align == ALIGN_RIGHT   ? 2 :
		                                            3;
	if(RichText::NEWPAGE & formatinfo.paravalid)
		page = formatinfo.newpage;
	else {
		page = Null;
		page.ThreeState();
	}
	if(RichText::KEEP & formatinfo.paravalid)
		keep = formatinfo.keep;
	else {
		keep = Null;
		keep.ThreeState();
	}
	if(RichText::KEEPNEXT & formatinfo.paravalid)
		keepnext = formatinfo.keepnext;
	else {
		keepnext = Null;
		keepnext.ThreeState();
	}
	if(RichText::ORPHAN & formatinfo.paravalid)
		orphan = formatinfo.orphan;
	else {
		orphan = Null;
		orphan.ThreeState();
	}
	if(RichText::RULERINK & formatinfo.paravalid)
		rulerink <<= formatinfo.rulerink;
	else
		rulerink <<= Null;
	if(RichText::RULERSTYLE & formatinfo.paravalid)
		rulerstyle <<= formatinfo.rulerstyle;
	else
		rulerstyle <<= Null;
	tabpos.SetUnit(unit);
	if(RichText::BULLET & formatinfo.paravalid)
		bullet <<= formatinfo.bullet;
	else
		bullet <<= Null;
	if(RichText::SPACING & formatinfo.paravalid)
		linespacing <<= formatinfo.linespacing;
	else
		linespacing <<= Null;
	if(RichText::NUMBERING & formatinfo.paravalid) {
		before_number = formatinfo.before_number.ToWString();
		after_number = formatinfo.after_number.ToWString();
		reset_number = formatinfo.reset_number;
		for(int i = 0; i < 8; i++)
			n[i] = formatinfo.number[i];
	}
	else {
		before_number <<= Null;
		after_number <<= Null;
		reset_number <<= Null;
		reset_number.ThreeState();
		for(int i = 0; i < 8; i++)
			n[i] = Null;
	}
	tabs.Clear();
	if(RichText::TABS & formatinfo.paravalid)
		for(int i = 0; i < formatinfo.tab.GetCount(); i++)
			tabs.Add(formatinfo.tab[i].pos, formatinfo.tab[i].align, formatinfo.tab[i].fillchar);
	tabsize.Set(unit, RichText::TABSIZE & formatinfo.paravalid ? formatinfo.tabsize : Null);
	keepindent = formatinfo.indent != ComputeIndent();
	SetupIndent();
	ClearModify();
	modified = false;
}