From 4615740ccfada8a24e9599aff44a94a042c0329d Mon Sep 17 00:00:00 2001 From: vczh Date: Sat, 9 Jan 2016 15:53:29 -0800 Subject: [PATCH] Update GacUI_Controls\TextEditor demo --- Import/GacUI.cpp | 26 +++++ Import/GacUI.h | 9 ++ .../GacUI_Controls/TextEditor/UI/Resource.xml | 6 + .../TextEditor/UI/Source/MainWindow.cpp | 105 ++++++++++++++++-- Tutorial/GacUI_Controls/TextEditor/UI/a.txt | Bin 0 -> 23288 bytes Tutorial/GacUI_Controls/TextEditor/UI/a.xml | Bin 0 -> 23288 bytes Tutorial/GacUI_Controls/UIRes/TextEditor.bin | Bin 520146 -> 872534 bytes 7 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 Tutorial/GacUI_Controls/TextEditor/UI/a.txt create mode 100644 Tutorial/GacUI_Controls/TextEditor/UI/a.xml diff --git a/Import/GacUI.cpp b/Import/GacUI.cpp index 95e95f4b..3d07ec6b 100644 --- a/Import/GacUI.cpp +++ b/Import/GacUI.cpp @@ -27470,6 +27470,12 @@ GuiTextBoxCommonInterface void GuiTextBoxCommonInterface::SetColorizer(Ptr value) { + if (!filledDefaultColors) + { + filledDefaultColors = true; + CopyFrom(defaultColors, GetTextElement()->GetColors()); + } + if(colorizer) { DetachTextEditCallback(colorizer); @@ -27480,6 +27486,11 @@ GuiTextBoxCommonInterface AttachTextEditCallback(colorizer); GetTextElement()->SetColors(colorizer->GetColors()); } + else + { + GetTextElement()->SetColors(defaultColors); + GetTextElement()->ResetTextColorIndex(0); + } } //================ auto complete @@ -39000,6 +39011,21 @@ GuiColorizedTextElement } } + void GuiColorizedTextElement::ResetTextColorIndex(vint index) + { + vint lineCount = lines.GetCount(); + for (vint i = 0; i < lineCount; i++) + { + auto& line = lines.GetLine(i); + line.lexerFinalState = -1; + line.contextFinalState = -1; + for (vint j = 0; j < line.dataLength; j++) + { + line.att[j].colorIndex = index; + } + } + } + const FontProperties& GuiColorizedTextElement::GetFont() { return font; diff --git a/Import/GacUI.h b/Import/GacUI.h index 80f8b1f2..5ed74550 100644 --- a/Import/GacUI.h +++ b/Import/GacUI.h @@ -5307,6 +5307,11 @@ Colorized Plain Text (element) /// The color table to bind. void SetColors(const ColorArray& value); /// + /// Reset color of all characters + /// + /// Color index of all characters. + void ResetTextColorIndex(vint index); + /// /// Get the font configuration for all characters. /// /// The font configuration. @@ -13974,6 +13979,7 @@ Common Interface /// Common interface for text box controls. class GuiTextBoxCommonInterface abstract : public Description { + typedef collections::Array ColorArray; protected: class ICallback : public virtual IDescriptable, public Description { @@ -14016,6 +14022,9 @@ Common Interface Ptr autoComplete; Ptr undoRedoProcessor; + bool filledDefaultColors = false; + ColorArray defaultColors; + SpinLock elementModifyLock; collections::List> textEditCallbacks; Ptr internalShortcutKeyManager; diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml b/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml index f6c9cce0..fff4ae40 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Resource.xml @@ -45,21 +45,27 @@ + textBox.observe as _(_.CanUndo() on _.SelectionChanged) commandEditUndo_Executed + textBox.observe as _(_.CanRedo() on _.SelectionChanged) commandEditRedo_Executed + textBox.observe as _(_.CanCut() on _.SelectionChanged) commandEditCut_Executed + textBox.observe as _(_.CanCopy() on _.SelectionChanged) commandEditCopy_Executed + textBox.observe as _(_.CanPaste() on self.ClipboardUpdated) commandEditPaste_Executed + textBox.SelectionText != '' commandEditDelete_Executed diff --git a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp index af2dac6e..a392ce08 100644 --- a/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp +++ b/Tutorial/GacUI_Controls/TextEditor/UI/Source/MainWindow.cpp @@ -10,6 +10,78 @@ This file is generated by: Vczh GacUI Resource Code Generator using namespace vl::stream; +namespace demo +{ + class XmlColorizer : public GuiTextBoxRegexColorizer + { + public: + XmlColorizer() + { + text::ColorEntry entry=GetCurrentTheme()->GetDefaultTextBoxColorEntry(); + SetDefaultColor(entry); + + entry.normal.text=Color(0, 128, 0); + AddToken(L"/