Page 1 of 1

Clear RichViewEdit completely

Posted: Wed Aug 10, 2011 6:11 am
by Marsianin
Just want to know how should I clean RichViewEdit from previous documents?
I need to clear all styles, get defaults etc.

The problem I've got is when I clear RVE and RVStyle the documents here will get fixed width ignoring window size and RVRuler doesn't helps.
Word wrap works fine if window/form size is smaller than RVE document width. And when form width is smaller then document width bottom scrollbar appears.

Here is my code to clear RVE:

Code: Select all

      RichViewEdit1.Clear;
      RVStyle1.TextStyles.Clear;
      RVRuler1.AdjustPosition;
      RichViewEdit1.ApplyStyleConversion(TEXT_APPLYSTYLE);
      // This will apply my default style:
      //   FontInfo.FontName:=EditorFontName;
      //   FontInfo.Size:=EditorFontSize;
      //   FontInfo.Color:=DefTextColor;
      //   FontInfo.BackColor:=clNone;
      //   FontInfo.Style:=[];
      //   ...
      //   NewStyleNo:=RVStyle1.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties);
      //   if NewStyleNo=-1 then begin
      //   RVStyle1.TextStyles.Add;
      //   ...
And once document width changed with RVRuler it becames fixed and when I make main form smaller than that width - I get bottom scrollbar. How can I bring dynamic document width back?

Posted: Wed Aug 10, 2011 8:33 am
by Sergey Tkachenko
The code below resets all properties that can be loaded/saved in RVF.

Code: Select all

// document
RichViewEdit1.Clear;
// styles
RVStyle1.TextStyles.Clear;
with RVStyle1.TextStyles.Add do begin
  FontName:=EditorFontName; 
  Size:=EditorFontSize; 
  Color:=DefTextColor; 
end;
RVStyle1.ParaStyles.Clear;
RVStyle1.ParaStyles.Add;
RVStyle1.ListStyles.Clear;
// background
RichViewEdit1.BackgroundStyle := bsNoBitmap;
RichViewEdit1.BackgroundBitmap := nil;
// margins (I assume they are measured in pixels)
RichViewEdit1.LeftMargin := 10; 
RichViewEdit1.RightMargin := 10; 
RichViewEdit1.TopMargin := 10; 
RichViewEdit1.BottomMargin := 10; 
// other layout properties
RichViewEdit1.MinTextWidth := 0;
RichViewEdit1.MaxTextWidth := 0;
RichViewEdit1.BiDiMode := rvbdUnspecified;
// formatting
RichViewEdit1.Format;

Posted: Wed Aug 10, 2011 11:19 pm
by Marsianin
Ok, after this code everything clears and works fine but if the ruler set to some fixed document width (21cm for example) new document in this RVE will use this width too :shock:
So how can I reset RVRuler?
Once you change document width via ruler it became fixed and if form is smaller than this width bottom scrollbar appears. I need to know how to reset it.

Posted: Thu Aug 11, 2011 3:05 pm
by Sergey Tkachenko
Call Ruler1.UpdateRulerMargins after this code.

Posted: Fri Aug 12, 2011 2:03 am
by Marsianin
Tried:

Code: Select all

  RVRuler1.UpdateRulerIndents;
  RVRuler1.UpdateRulerMargins;
Did not help :x

Posted: Fri Aug 12, 2011 2:09 am
by Marsianin
And when you have RVE with Align=AtClient with RVRuler resizing main window moves right page boundary in the ruler according window size.
But once moved by the user (right page bound in the ruler) it fixes and even if you make window smaller than page width it will not resize.
How can I bring back this dynamic page width behavior?

Posted: Fri Aug 12, 2011 8:27 am
by Sergey Tkachenko
Include rvoClientTextWidth in RichViewEdit.Options

The ruler can work in two modes:
1) rvoClientTextWidth is included in RichViewEdit.Options. In this mode, the ruler only changes margins.
2) If excluded, the ruler changes not only margins, but document width (by assigning MaxTextWidth and MinTextWidth)

Posted: Fri Aug 12, 2011 9:30 pm
by Marsianin
Ok, set rvoClientTextWidth and it helped.

But new document still inherits boundaries from ruler from previous document.