mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 14:16:07 -06:00
RichEdit: Insert special character
This commit is contained in:
parent
e541ef6786
commit
9a903a20d7
6 changed files with 66 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ public:
|
|||
const VectorMap<String, Vector<Tuple<int, String>>>& UnicodeSymbols();
|
||||
|
||||
String SelectFontSymbolSvg(Sizef& sz);
|
||||
int SelectFontSymbol(Font& fnt);
|
||||
int SelectSpecialSymbol();
|
||||
|
||||
class DiagramEditor : public Ctrl, Diagram::PaintInfo {
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -309,6 +309,7 @@ void RichEdit::StdBar(Bar& menu)
|
|||
}
|
||||
if(allow_objects) {
|
||||
LoadImageTool(menu);
|
||||
InsertCharacterTool(menu);
|
||||
InsertDiagramTool(menu);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -39,16 +39,16 @@ String AsSvgPath(Font font, int c, Sizef& sz) {
|
|||
}
|
||||
|
||||
struct SelectSymbolDlg : WithSelectSymbolLayout<TopWindow> {
|
||||
Vector<Tuple<Sizef, String>> svg;
|
||||
Vector<Tuple<Sizef, String, Font, int>> 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<Sizef, String, Font, int> 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<Sizef, String> h = dlg.svg[dlg.result];
|
||||
return dlg.svg[dlg.result];
|
||||
}
|
||||
|
||||
int SelectFontSymbol(Font& fnt)
|
||||
{
|
||||
Tuple<Sizef, String, Font, int> h = sSelectSymbol();
|
||||
fnt = h.c;
|
||||
return h.d;
|
||||
}
|
||||
|
||||
String SelectFontSymbolSvg(Sizef& sz)
|
||||
{
|
||||
Tuple<Sizef, String, Font, int> h = sSelectSymbol();
|
||||
sz = h.a;
|
||||
return h.b;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(); });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue