# HG changeset patch # User didier # Date 1256681765 -3600 # Branch trunk # Node ID 21313a7ec1929904488d5f686cb39747d4c875c1 # Parent fc4cd7fcbf163f18fd47788fb5f7d1f52b860f6b Extracting StyleManager diff -r fc4cd7fcbf16 -r 21313a7ec192 uppsrc/RichEdit/ParaFormat.cpp --- a/uppsrc/RichEdit/ParaFormat.cpp +++ b/uppsrc/RichEdit/ParaFormat.cpp @@ -2,31 +2,6 @@ NAMESPACE_UPP -struct ParaFormating : public WithParaLayout -{ - DropList n[8]; - UnitEdit tabpos; - DropList tabtype; - DropList tabfill; - bool keepindent; - Font font; - bool modified; - - void EnableNumbering(); - RichPara::NumberFormat GetNumbering(); - bool IsNumbering(); - void SetupIndent(); - int ComputeIndent(); - void SetMod() { modified = true; } - bool IsChanged() { return IsModified() || modified; } - - void Set(int unit, const RichText::FormatInfo& formatinfo); - dword Get(RichText::FormatInfo& formatinfo); - - typedef ParaFormating CLASSNAME; - - ParaFormating(); -}; RichPara::NumberFormat ParaFormating::GetNumbering() { @@ -409,30 +384,6 @@ void RichEdit::SetStyle() } } -struct StyleManager : public WithStylesLayout { - ParaFormating para; - int unit; - ArrayMap style; - Index dirty; - FontHeight height; - EditString name; - - void EnterStyle(); - void SaveStyle(); - void SetupFont(); - void SetupFont0(); - void Create(); - void ReloadNextStyles(); - void Remove(); - - void GetFont(Font& font); - - void Menu(Bar& bar); - - typedef StyleManager CLASSNAME; - - StyleManager(); -}; void StyleManager::EnterStyle() { @@ -557,6 +510,42 @@ StyleManager::StyleManager() face <<= height <<= italic <<= bold <<= underline <<= strikeout <<= THISBACK(SetupFont); } +void StyleManager::load(const String& text) +{ + RichText rtxt = ParseQTF(text); + load(rtxt); +} + +void StyleManager::load(const RichText& text) +{ + unit = UNIT_DOT; + int i; + for(i = 0; i < text.GetStyleCount(); i++) + list.Add(text.GetStyleId(i), text.GetStyle(i).name); + list.Sort(1, sCompareStyle); + for(i = 0; i < text.GetStyleCount(); i++) { + Uuid id = list.Get(i, 0); + style.Add(id, text.GetStyle(id)); + } + int q = list.Find(RichStyle::GetDefaultId()); + if(q >= 0) + list.SetDisplay(q, 0, Single()); + ReloadNextStyles(); +} + +RichText StyleManager::AsRichText() +{ + RichText output; + output.SetStyles(style); + return output; +} + +String StyleManager::AsQTF() +{ + return Upp::AsQTF(AsRichText()); +} + + void RichEdit::Styles() { NextUndo(); diff -r fc4cd7fcbf16 -r 21313a7ec192 uppsrc/RichEdit/RichEdit.h --- a/uppsrc/RichEdit/RichEdit.h +++ b/uppsrc/RichEdit/RichEdit.h @@ -706,6 +706,63 @@ public: RichEditWithToolBar(); }; + +struct ParaFormating : public WithParaLayout +{ + DropList n[8]; + UnitEdit tabpos; + DropList tabtype; + DropList tabfill; + bool keepindent; + Font font; + bool modified; + + void EnableNumbering(); + RichPara::NumberFormat GetNumbering(); + bool IsNumbering(); + void SetupIndent(); + int ComputeIndent(); + void SetMod() { modified = true; } + bool IsChanged() { return IsModified() || modified; } + + void Set(int unit, const RichText::FormatInfo& formatinfo); + dword Get(RichText::FormatInfo& formatinfo); + + typedef ParaFormating CLASSNAME; + + ParaFormating(); +}; + +struct StyleManager : public WithStylesLayout { + ParaFormating para; + int unit; + RichStyles style; + Index dirty; + FontHeight height; + EditString name; + + void EnterStyle(); + void SaveStyle(); + void SetupFont(); + void SetupFont0(); + void Create(); + void ReloadNextStyles(); + void Remove(); + + void GetFont(Font& font); + + void Menu(Bar& bar); + + typedef StyleManager CLASSNAME; + + StyleManager(); + + void load(const RichText& stylesText); + void load(const String& text); + RichText AsRichText(); + String AsQTF(); +}; + END_UPP_NAMESPACE #endif