diff --git a/uppsrc/RichEdit/Clip.cpp b/uppsrc/RichEdit/Clip.cpp index a6e85c874..d3ed79a34 100644 --- a/uppsrc/RichEdit/Clip.cpp +++ b/uppsrc/RichEdit/Clip.cpp @@ -34,6 +34,20 @@ void RichEdit::InsertImage() ClipPaste(clip, "image/raw"); } +void RichEdit::InsertCharacter() +{ + int c = SelectSpecialSymbol(); + + if(IsNull(c)) + return; + + RichText clip; + RichPara p; + p.Cat(WString(c, 1), formatinfo); + clip.Cat(p); + ClipPaste(clip, "text/QTF"); +} + void RichEdit::InsertDiagram() { if(!allow_objects) diff --git a/uppsrc/RichEdit/DiagramEditor.h b/uppsrc/RichEdit/DiagramEditor.h index b84c1ceff..fe0146439 100644 --- a/uppsrc/RichEdit/DiagramEditor.h +++ b/uppsrc/RichEdit/DiagramEditor.h @@ -42,6 +42,8 @@ public: const VectorMap>>& UnicodeSymbols(); String SelectFontSymbolSvg(Sizef& sz); +int SelectFontSymbol(Font& fnt); +int SelectSpecialSymbol(); class DiagramEditor : public Ctrl, Diagram::PaintInfo { public: diff --git a/uppsrc/RichEdit/Mouse.cpp b/uppsrc/RichEdit/Mouse.cpp index 79eaf1b27..9fec3c5cd 100644 --- a/uppsrc/RichEdit/Mouse.cpp +++ b/uppsrc/RichEdit/Mouse.cpp @@ -309,6 +309,7 @@ void RichEdit::StdBar(Bar& menu) } if(allow_objects) { LoadImageTool(menu); + InsertCharacterTool(menu); InsertDiagramTool(menu); } } diff --git a/uppsrc/RichEdit/RichEdit.h b/uppsrc/RichEdit/RichEdit.h index 08fcc66ea..80569c6ec 100644 --- a/uppsrc/RichEdit/RichEdit.h +++ b/uppsrc/RichEdit/RichEdit.h @@ -651,6 +651,7 @@ private: void ZoomClip(RichText& text) const; void InsertImage(); + void InsertCharacter(); void InsertDiagram(); RichObject Adjust(RichObject o); @@ -799,6 +800,7 @@ public: void PastePlainTextTool(Bar& bar, dword key = K_CTRL_V|K_SHIFT); void ObjectTool(Bar& bar, dword key = 0); void LoadImageTool(Bar& bar, dword key = 0); + void InsertCharacterTool(Bar& bar, dword key = 0); void InsertDiagramTool(Bar& bar, dword key = 0); void FindReplaceTool(Bar& bar, dword key = K_CTRL_F); diff --git a/uppsrc/RichEdit/SelectSymbol.cpp b/uppsrc/RichEdit/SelectSymbol.cpp index a1b37ab9a..44b4feb1a 100644 --- a/uppsrc/RichEdit/SelectSymbol.cpp +++ b/uppsrc/RichEdit/SelectSymbol.cpp @@ -39,16 +39,16 @@ String AsSvgPath(Font font, int c, Sizef& sz) { } struct SelectSymbolDlg : WithSelectSymbolLayout { - Vector> svg; + Vector> svg; int result; - SelectSymbolDlg(); + SelectSymbolDlg(bool show_variants = true); void Sync(); void Variants(int codepoint); }; -SelectSymbolDlg::SelectSymbolDlg() +SelectSymbolDlg::SelectSymbolDlg(bool show_variants) { CtrlLayout(*this, "Insert symbol"); search.NullText(t_("Search")); @@ -57,12 +57,22 @@ SelectSymbolDlg::SelectSymbolDlg() search ^= group ^= [=] { Sync(); }; symbols.NoHyperlinkDecoration(); - symbols.WhenLink << [=](const String& s) { Variants(Atoi(s)); }; symbols.MonoGlyphs(); - result = -1; - variants.NoHyperlinkDecoration(); - variants.WhenLink << [=](const String& s) { result = Atoi(s); Break(IDOK); }; + if(show_variants) { + symbols.WhenLink << [=](const String& s) { Variants(Atoi(s)); }; + result = -1; + variants.NoHyperlinkDecoration(); + variants.WhenLink << [=](const String& s) { result = Atoi(s); Break(IDOK); }; + } + else { + variants.Hide(); + Logc vy = variants.GetPos().y; + Logc y = symbols.GetPos().y; + y.SetB(vy.GetA() + vy.GetB() - y.GetA()); + symbols.SetPosY(y); + symbols.WhenLink << [=](const String& s) { result = Atoi(s); Break(IDOK); }; + } } void SelectSymbolDlg::Sync() @@ -101,7 +111,7 @@ void SelectSymbolDlg::Variants(int codepoint) if(h.Find(img) < 0) { qtf << "[^" << h.GetCount() << "^ " << " " << AsQTF(CreatePNGObject(img, sz.cx, sz.cy)) << "], "; h.Add(img); - svg.Add(MakeTuple(szf0, svgpath)); + svg.Add(MakeTuple(szf0, svgpath, fnt, codepoint)); } } } @@ -109,14 +119,35 @@ void SelectSymbolDlg::Variants(int codepoint) variants.SetQTF(qtf); } -String SelectFontSymbolSvg(Sizef& sz) +int SelectSpecialSymbol() +{ + SelectSymbolDlg dlg(false); + dlg.Sync(); + if(dlg.Execute() != IDOK) + return Null; + return dlg.result; +} + +static Tuple sSelectSymbol() { SelectSymbolDlg dlg; dlg.Sync(); if(dlg.Execute() != IDOK || dlg.result < 0 || dlg.result >= dlg.svg.GetCount()) - return Null; + return MakeTuple(Null, Null, Null, Null); - Tuple h = dlg.svg[dlg.result]; + return dlg.svg[dlg.result]; +} + +int SelectFontSymbol(Font& fnt) +{ + Tuple h = sSelectSymbol(); + fnt = h.c; + return h.d; +} + +String SelectFontSymbolSvg(Sizef& sz) +{ + Tuple h = sSelectSymbol(); sz = h.a; return h.b; } diff --git a/uppsrc/RichEdit/Tool.cpp b/uppsrc/RichEdit/Tool.cpp index b0d09f01c..a47b97b45 100644 --- a/uppsrc/RichEdit/Tool.cpp +++ b/uppsrc/RichEdit/Tool.cpp @@ -352,6 +352,11 @@ void RichEdit::LoadImageTool(Bar& bar, dword key) bar.Add(!IsReadOnly(), t_("Insert image from file.."), CtrlImg::open(), THISBACK(InsertImage)); } +void RichEdit::InsertCharacterTool(Bar& bar, dword key) +{ + bar.Add(!IsReadOnly(), t_("Insert special character.."), DiagramImg::FontSvg(), [=] { InsertCharacter(); }); +} + void RichEdit::InsertDiagramTool(Bar& bar, dword key) { bar.Add(!IsReadOnly(), t_("Insert diagram.."), DiagramImg::Diagram(), [=] { InsertDiagram(); });