RichText, RichEdit: Customization options

git-svn-id: svn://ultimatepp.org/upp/trunk@6807 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2014-01-23 12:09:05 +00:00
parent 3f18858491
commit bc8ba9b6b9
14 changed files with 100 additions and 84 deletions

View file

@ -118,4 +118,4 @@ to directly obtain virtual memory. It stores information about
the block in the header at the beginning of block, also makeing
block 16`-bytes unaligned in the process. Free then returns virtual
memory back to the system.&]
[s0; ]
[s0; ]]

View file

@ -1,7 +1,7 @@
LAYOUT(EditStringLayout, 236, 62)
ITEM(Label, lbl, SetLabel(t_("Test")).LeftPosZ(4, 68).TopPosZ(4, 19))
ITEM(EditString, text, HSizePosZ(68, 4).TopPosZ(4, 19))
ITEM(Button, ok, SetLabel(t_("OK")).HCenterPosZ(80, -10).BottomPosZ(4, 22))
LAYOUT(EditStringLayout, 376, 62)
ITEM(Label, lbl, SetLabel(t_("Test")).LeftPosZ(4, 116).TopPosZ(4, 19))
ITEM(EditString, text, HSizePosZ(124, 4).TopPosZ(4, 19))
ITEM(Button, ok, SetLabel(t_("OK")).HCenterPosZ(80, 60).BottomPosZ(4, 22))
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 80).BottomPosZ(4, 22))
END_LAYOUT

View file

@ -6,17 +6,17 @@ NAMESPACE_UPP
void RichEdit::InsertImage()
{
if(!imagefs.ExecuteOpen())
if(!imagefs.ExecuteOpen(t_("Open image from file")))
return;
String fn = ~imagefs;
if(GetFileLength(fn) >= 10 * 1024 * 1024) {
if(GetFileLength(fn) > 17000000) {
Exclamation("Image is too large!");
return;
}
String data = LoadFile(~imagefs);
String data = LoadFile(fn);
StringStream ss(data);
if(!StreamRaster::OpenAny(ss)) {
Exclamation("Invalid file format!");
Exclamation(NFormat(t_("Unsupported image format in file [* \1%s\1]."), ~imagefs));
return;
}
RichText clip;

View file

@ -112,7 +112,7 @@ void RichEdit::Paint(Draw& w)
for(int i = 0; i <= py.page; i++)
DrawFrame(w, tr.left - 1, i * (pw.size.cy + 3) + 1 - sb,
pw.size.cx + 4, pw.size.cy + 2, SColorShadow);
PaintInfo pi;
PaintInfo pi = paint_info;
pi.context = context;
pi.zoom = zoom;
pi.top = GetPageY(sb);
@ -587,6 +587,11 @@ void StdLabelDlg(String& s)
EditText(s, t_("Paragraph label"), t_("Label"), CharFilterAscii128, 100);
}
void StdIndexEntryDlg(String& s)
{
EditText(s, t_("Index Entry"), t_("Index entry"), CharFilterAscii128, 100);
}
RichEdit::RichEdit()
{
floating_zoom = Null;
@ -714,6 +719,7 @@ RichEdit::RichEdit()
WhenHyperlink = callback(StdLinkDlg);
WhenLabel = callback(StdLabelDlg);
WhenIndexEntry = callback(StdIndexEntryDlg);
p_size = Size(-1, -1);
@ -730,6 +736,8 @@ RichEdit::RichEdit()
bullet_indent = 150;
persistent_findreplace = true;
ignore_physical_size = false;
}
RichEdit::~RichEdit() {}

View file

@ -347,8 +347,11 @@ void RichEdit::Label()
void RichEdit::IndexEntry()
{
if(EditText(formatinfo.indexentry, t_("Index Entry"), t_("Index entry"))) {
indexentry <<= formatinfo.indexentry;
String s = formatinfo.indexentry.ToString();
String s0 = s;
WhenIndexEntry(s);
if(s != s0) {
formatinfo.indexentry <<= s.ToWString();
ApplyFormat(RichText::INDEXENTRY);
NextUndo();
SetFocus();
@ -553,7 +556,7 @@ void RichEdit::AdjustObjectSize()
WithObjectSizeLayout<TopWindow> d;
CtrlLayoutOKCancel(d, t_("Object position"));
Size sz = obj.GetSize();
Size psz = obj.GetPhysicalSize();
Size psz = GetPhysicalSize(obj);
if(psz.cx == 0) psz.cx = 2000;
if(psz.cy == 0) psz.cy = 2000;
d.width.Set(unit, sz.cx);

View file

@ -401,36 +401,6 @@ RichObject RichEdit::GetObject() const
return text.GetRichPos(objectpos).object;
}
void RichEdit::LoadImage()
{
FileSel fsel;
fsel.AllFilesType();
if(fsel.ExecuteOpen(t_("Open image from file"))) {
FileIn fi;
if(!fi.Open(~fsel)) {
Exclamation(NFormat(t_("Error opening file [* \1%s\1]."), ~fsel));
return;
}
Image img = StreamRaster::LoadAny(fi);
if(IsNull(img)) {
Exclamation(NFormat(t_("Unsupported image format in file [* \1%s\1]."), ~fsel));
return;
}
Size dots = img.GetDots();
if(dots.cx <= 0 || dots.cy <= 0)
dots = img.GetSize() * 6;
RichObject object = CreatePNGObject(img, dots, Size(Null));
RichText::FormatInfo finfo = GetFormatInfo();
RemoveSelection();
RichPara p;
p.Cat(object, finfo);
RichText clip;
clip.Cat(p);
Insert(GetCursor(), clip, false);
Finish();
}
}
void RichEdit::Select(int pos, int count)
{
found = false;

View file

@ -2,6 +2,13 @@
NAMESPACE_UPP
Size RichEdit::GetPhysicalSize(const RichObject& obj)
{
if(ignore_physical_size)
return 600 * obj.GetPixelSize() / 96;
return obj.GetPhysicalSize();
}
void RichEdit::CancelMode()
{
tabmove.table = 0;
@ -31,7 +38,7 @@ void RichEdit::SetObjectPercent(int p)
{
if(objectpos >= 0) {
RichObject obj = GetObject();
Size sz = obj.GetPhysicalSize() * p / 100;
Size sz = GetPhysicalSize(obj) * p / 100;
if(sz.cx > 0 && sz.cy > 0) {
obj.SetSize(sz);
obj.KeepRatio(true);
@ -189,6 +196,16 @@ void RichEdit::MouseMove(Point p, dword flags)
}
}
static bool IsObjectPercent(Sizef percent, int p)
{
return abs(percent.cx - p) < 1 && abs(percent.cy - p) < 1;
}
static bool IsObjectDelta(int delta, int d)
{
return d * 25 / 3 == delta;
}
void RichEdit::StdBar(Bar& menu)
{
int l, h;
@ -208,24 +225,30 @@ void RichEdit::StdBar(Bar& menu)
bar_object.Menu(menu, context);
if(!menu.IsEmpty())
menu.Separator();
Size sz = bar_object.GetPhysicalSize();
Size sz = GetPhysicalSize(bar_object);
Sizef percent = bar_object.GetSize();
percent = 100 * percent / Sizef(sz);
bool b = sz.cx || sz.cy;
menu.Add(t_("Object position.."), THISBACK(AdjustObjectSize));
menu.Separator();
menu.Add(b, "20 %", THISBACK1(SetObjectPercent, 20));
menu.Add(b, "40 %", THISBACK1(SetObjectPercent, 40));
menu.Add(b, "60 %", THISBACK1(SetObjectPercent, 60));
menu.Add(b, "80 %", THISBACK1(SetObjectPercent, 80));
menu.Add(b, "90 %", THISBACK1(SetObjectPercent, 90));
menu.Add(b, "100 %", THISBACK1(SetObjectPercent, 100));
menu.Add(b, "20 %", THISBACK1(SetObjectPercent, 20)).Check(IsObjectPercent(percent, 20));
menu.Add(b, "30 %", THISBACK1(SetObjectPercent, 30)).Check(IsObjectPercent(percent, 30));
menu.Add(b, "40 %", THISBACK1(SetObjectPercent, 40)).Check(IsObjectPercent(percent, 40));
menu.Add(b, "50 %", THISBACK1(SetObjectPercent, 50)).Check(IsObjectPercent(percent, 50));
menu.Add(b, "60 %", THISBACK1(SetObjectPercent, 60)).Check(IsObjectPercent(percent, 60));
menu.Add(b, "70 %", THISBACK1(SetObjectPercent, 70)).Check(IsObjectPercent(percent, 70));
menu.Add(b, "80 %", THISBACK1(SetObjectPercent, 80)).Check(IsObjectPercent(percent, 80));
menu.Add(b, "90 %", THISBACK1(SetObjectPercent, 90)).Check(IsObjectPercent(percent, 90));
menu.Add(b, "100 %", THISBACK1(SetObjectPercent, 100)).Check(IsObjectPercent(percent, 100));
menu.Break();
menu.Add(t_("3 pt up"), THISBACK1(SetObjectYDelta, -3));
menu.Add(t_("2 pt up"), THISBACK1(SetObjectYDelta, -2));
menu.Add(t_("1 pt up"), THISBACK1(SetObjectYDelta, -1));
menu.Add(t_("Baseline"), THISBACK1(SetObjectYDelta, 0));
menu.Add(t_("1 pt down"), THISBACK1(SetObjectYDelta, 1));
menu.Add(t_("2 pt down"), THISBACK1(SetObjectYDelta, 2));
menu.Add(t_("3 pt down"), THISBACK1(SetObjectYDelta, 3));
int delta = bar_object.GetYDelta();
menu.Add(t_("3 pt up"), THISBACK1(SetObjectYDelta, -3)).Check(IsObjectDelta(delta, -3));
menu.Add(t_("2 pt up"), THISBACK1(SetObjectYDelta, -2)).Check(IsObjectDelta(delta, -2));
menu.Add(t_("1 pt up"), THISBACK1(SetObjectYDelta, -1)).Check(IsObjectDelta(delta, -1));
menu.Add(t_("Baseline"), THISBACK1(SetObjectYDelta, 0)).Check(IsObjectDelta(delta, 0));
menu.Add(t_("1 pt down"), THISBACK1(SetObjectYDelta, 1)).Check(IsObjectDelta(delta, 1));
menu.Add(t_("2 pt down"), THISBACK1(SetObjectYDelta, 2)).Check(IsObjectDelta(delta, 2));
menu.Add(t_("3 pt down"), THISBACK1(SetObjectYDelta, 3)).Check(IsObjectDelta(delta, 3));
menu.Separator();
CopyTool(menu);
CutTool(menu);

View file

@ -288,6 +288,9 @@ private:
Vector<int> ffs;
int bullet_indent;
PaintInfo paint_info;
bool ignore_physical_size;
static int fh[];
@ -614,6 +617,8 @@ private:
bool BegSelTabFix();
void BegSelTabFixEnd(bool fix);
Size GetPhysicalSize(const RichObject& obj);
struct DisplayDefault : public Display {
virtual void Paint(Draw& w, const Rect& r, const Value& q,
Color ink, Color paper, dword style) const;
@ -649,6 +654,7 @@ public:
Callback WhenStartEvaluating;
Callback2<String&, WString&> WhenHyperlink;
Callback1<String&> WhenLabel;
Callback1<String&> WhenIndexEntry;
Callback1<Bar&> WhenBar;
void StdBar(Bar& menu);
@ -690,7 +696,6 @@ public:
void Cut();
void Paste();
void InsertObject(int type);
void LoadImage();
void Styles();
@ -770,30 +775,32 @@ public:
void Clear();
void Pick(pick_ RichText& t);
void SetQTF(const char *qtf) { Pick(ParseQTF(qtf, 0, context)); }
const RichText& Get() const { return text; }
String GetQTF(byte cs = CHARSET_UTF8) const { return AsQTF(text, cs); }
void SetQTF(const char *qtf) { Pick(ParseQTF(qtf, 0, context)); }
const RichText& Get() const { return text; }
String GetQTF(byte cs = CHARSET_UTF8) const { return AsQTF(text, cs); }
void ApplyStylesheet(const RichText& r);
void SetPage(const Size& sz) { pagesz = sz; Finish(); }
Size GetPage() { return pagesz; }
void SetPage(const Size& sz) { pagesz = sz; Finish(); }
Size GetPage() { return pagesz; }
RichEdit& NoRuler() { RemoveFrame(ruler); return *this; }
RichEdit& SingleLine(bool b = true) { singleline = b; return *this; }
RichEdit& NoRuler() { RemoveFrame(ruler); return *this; }
RichEdit& SingleLine(bool b = true) { singleline = b; return *this; }
RichEdit& FontFaces(const Vector<int>& face);
RichEdit& ViewBorder(int cx) { viewborder = cx; Refresh(); return *this; }
RichEdit& ShowCodes(Color c) { showcodes = c; Refresh(); return *this; }
RichEdit& Unit(int u) { unit = u; Refresh(); return *this; }
RichEdit& SpellCheck(bool b) { spellcheck = b; Refresh(); return *this; }
RichEdit& SetZoom(int z) { zoom = z; Refresh(); return *this; }
RichEdit& SetContext(void *ctx) { context = ctx; Refresh(); return *this; }
void *GetContext() const { return context; }
RichEdit& ClipZoom(Zoom z) { clipzoom = z; return *this; }
RichEdit& ClipZoom(int m, int d) { clipzoom = Zoom(m, d); return *this; }
Zoom GetClipZoom() const { return clipzoom; }
RichEdit& BulletIndent(int i) { bullet_indent = i; return *this; }
RichEdit& PersistentFindReplace(bool b = true) { persistent_findreplace = b; return *this; }
RichEdit& ViewBorder(int cx) { viewborder = cx; Refresh(); return *this; }
RichEdit& ShowCodes(Color c) { showcodes = c; Refresh(); return *this; }
RichEdit& Unit(int u) { unit = u; Refresh(); return *this; }
RichEdit& SpellCheck(bool b) { spellcheck = b; Refresh(); return *this; }
RichEdit& SetZoom(int z) { zoom = z; Refresh(); return *this; }
RichEdit& SetContext(void *ctx) { context = ctx; Refresh(); return *this; }
void *GetContext() const { return context; }
RichEdit& ClipZoom(Zoom z) { clipzoom = z; return *this; }
RichEdit& ClipZoom(int m, int d) { clipzoom = Zoom(m, d); return *this; }
Zoom GetClipZoom() const { return clipzoom; }
RichEdit& BulletIndent(int i) { bullet_indent = i; return *this; }
RichEdit& PersistentFindReplace(bool b = true) { persistent_findreplace = b; return *this; }
RichEdit& Floating(double zoomlevel_ = 1);
RichEdit& NoFloating(double zoomlevel_ = 1) { return Floating(Null); }
RichEdit& NoFloating(double zoomlevel_ = 1) { return Floating(Null); }
RichEdit& SetPaintInfo(const PaintInfo pi) { paint_info = pi; return *this; }
RichEdit& IgnorePhysicalObjectSize(bool b = true){ ignore_physical_size = b; return *this; }
struct UndoInfo {
int undoserial;

View file

@ -328,7 +328,7 @@ void RichEdit::ObjectTool(Bar& bar, dword key)
void RichEdit::LoadImageTool(Bar& bar, dword key)
{
bar.Add(!IsReadOnly(), t_("Insert image from file.."), RichEditImg::LoadImageFile(), THISBACK(LoadImage));
bar.Add(!IsReadOnly(), t_("Insert image from file.."), RichEditImg::LoadImageFile(), THISBACK(InsertImage));
}
void RichEdit::PrintTool(Bar& bar, dword key)

View file

@ -133,7 +133,7 @@ String RichObjectType::GetLink(const Value& data, Point pt, Size sz, void *conte
void RichObject::InitSize(int cx, int cy, void *context)
{
Size sz;
Size phsz = GetPixelSize();
Size phsz = 600 * GetPixelSize() / 96; // 100% size...
if(cx || cy)
sz = GetRatioSize(phsz, cx, cy);
else

View file

@ -56,6 +56,7 @@ PaintInfo::PaintInfo()
highlightpara = -1;
highlight = Yellow();
indexentry = LtGreen();
indexentrybg = false;
coloroverride = false;
context = NULL;
showlabels = false;

View file

@ -39,11 +39,15 @@ void RichPara::Flush(Draw& draw, const PaintInfo& pi, wchar *text,
int width = z * x - z * x0;
int zy0 = z * y0;
int zx0 = z * x0;
if(!IsNull(f.indexentry) && !IsNull(pi.indexentry))
if(pi.indexentrybg)
draw.DrawRect(zx0, z * y, width, z * (y + linecy) - z * y,
pi.coloroverride ? SColorPaper() : pi.indexentry);
else
draw.DrawRect(zx0, zy0, width, 2, pi.indexentry);
if(!IsNull(f.paper) && !highlight)
draw.DrawRect(zx0, z * y, width, z * (y + linecy) - z * y,
pi.coloroverride ? SColorPaper() : f.paper);
if(!IsNull(f.indexentry) && !IsNull(pi.indexentry))
draw.DrawRect(zx0, zy0, width, 2, pi.indexentry);
Font fnt = f;
int zht = z * tabs(f.GetHeight());
int ssa = 0;

View file

@ -240,7 +240,6 @@ Image RichRawImage::ToImage(const Value& data, Size sz, void *) const
One<StreamRaster> r = StreamRaster::OpenAny(ss);
if(r) {
Image x = r->GetImage();
Size outsz(min(sz.cx, 4 * x.GetWidth()), min(sz.cy, 4 * x.GetHeight()));
return Rescale(x, sz);
}
return Null;

View file

@ -268,6 +268,7 @@ struct PaintInfo {
PageY bottom;
Color hyperlink;
Color indexentry;
bool indexentrybg;
bool usecache;
bool sizetracking;
Color showcodes;