diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-09-11 14:30:42 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2017-09-19 15:22:47 +0200 |
commit | 901bacd637c6f2ca7394a9f13f1c5b7fb56a63ce (patch) | |
tree | cffc6caa94a45215435e2ca6847f753ddb3d39d6 | |
parent | TSCP: Extend the BAF policy with marking and IP parts (diff) | |
download | core-901bacd637c6f2ca7394a9f13f1c5b7fb56a63ce.tar.gz core-901bacd637c6f2ca7394a9f13f1c5b7fb56a63ce.zip |
TSCP: Classification Text Editor based on EditEngine
Change-Id: I70f4999fe3a787b866ee1f8959cf1eb225b81f07
-rw-r--r-- | extras/source/glade/libreoffice-catalog.xml.in | 6 | ||||
-rw-r--r-- | include/svx/ClassificationEditView.hxx | 70 | ||||
-rw-r--r-- | include/svx/ClassificationField.hxx | 65 | ||||
-rw-r--r-- | svx/Library_svx.mk | 1 | ||||
-rw-r--r-- | svx/source/dialog/ClassificationEditView.cxx | 182 |
5 files changed, 323 insertions, 1 deletions
diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in index 73ef75c861af..8fb5d4c803c7 100644 --- a/extras/source/glade/libreoffice-catalog.xml.in +++ b/extras/source/glade/libreoffice-catalog.xml.in @@ -677,6 +677,10 @@ generic-name="Text View" parent="GtkTextView" icon-name="widget-gtk-textentry"/> + <glade-widget-class title="Text View" name="svxlo-ClassificationEditView" + generic-name="Text View" parent="GtkTextView" + icon-name="widget-gtk-textentry"/> + <glade-widget-class title="Combo Image Button" name="sclo-ScExtIButton" generic-name="Combo Image Button" parent="GtkButton" icon-name="widget-gtk-button"/> @@ -684,7 +688,7 @@ <glade-widget-class title="Open Document ListBox" name="dbulo-OpenDocumentListBox" generic-name="Open Document ListBox" parent="GtkComboBox" icon-name="widget-gtk-combobox"/> - + <glade-widget-class title="Fill Type ListBox" name="svxlo-SvxFillTypeBox" generic-name="Fill Type ListBox" parent="GtkComboBox" icon-name="widget-gtk-combobox"/> diff --git a/include/svx/ClassificationEditView.hxx b/include/svx/ClassificationEditView.hxx new file mode 100644 index 000000000000..f045ce33e165 --- /dev/null +++ b/include/svx/ClassificationEditView.hxx @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_SVX_CLASSIFICATIONEDITVIEW_HXX +#define INCLUDED_SVX_CLASSIFICATIONEDITVIEW_HXX + +#include <sal/config.h> +#include <svx/svxdllapi.h> +#include <vcl/dialog.hxx> +#include <editeng/flditem.hxx> +#include <editeng/numitem.hxx> +#include <editeng/editeng.hxx> +#include <editeng/editview.hxx> + +namespace svx { + +class ClassificationEditEngine : public EditEngine +{ +public: + ClassificationEditEngine(SfxItemPool* pItemPool); + + virtual OUString CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor) override; +}; + +class SVX_DLLPUBLIC ClassificationEditView : public Control +{ +public: + ClassificationEditView(vcl::Window* pParent, WinBits nBits); + virtual ~ClassificationEditView() override; + + virtual void dispose() override; + + using Control::SetFont; + using Control::SetText; + + void SetCharAttributes(); + + void InsertField(const SvxFieldItem& rField); + + void InvertSelectionWeight(); + + void SetNumType(SvxNumType eNumType); + + std::unique_ptr<ClassificationEditEngine> pEdEngine; + std::unique_ptr<EditView> pEdView; + +protected: + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; + virtual void MouseMove( const MouseEvent& rMEvt ) override; + virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; + virtual void KeyInput( const KeyEvent& rKEvt ) override; + virtual void Command( const CommandEvent& rCEvt ) override; + virtual void GetFocus() override; + virtual void LoseFocus() override; + virtual void Resize() override; +}; + +} // end svx namespace + +#endif // INCLUDED_SVX_CLASSIFICATIONEDITVIEW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svx/ClassificationField.hxx b/include/svx/ClassificationField.hxx new file mode 100644 index 000000000000..ab2b01a8e122 --- /dev/null +++ b/include/svx/ClassificationField.hxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#ifndef INCLUDED_SVX_CLASSIFICATIONFIELD_HXX +#define INCLUDED_SVX_CLASSIFICATIONFIELD_HXX + +#include <sal/config.h> +#include <svx/svxdllapi.h> + +namespace svx { + +enum class ClassificationType +{ + CLASSIFICATION, + MARKINGS, + TEXT, +}; + +class SVX_DLLPUBLIC ClassificationField : public SvxFieldData +{ +public: + ClassificationType meType; + OUString msDescription; + + ClassificationField(ClassificationType eType, OUString const & sDescription) + : SvxFieldData() + , meType(eType) + , msDescription(sDescription) + {} + + ClassificationField* Clone() const override + { + return new ClassificationField(meType, msDescription); + } + + bool operator==(const SvxFieldData& rOther) const override + { + if (typeid(rOther) != typeid(*this)) + return false; + + const ClassificationField& rOtherField = static_cast<const ClassificationField&>(rOther); + return (meType == rOtherField.meType) && + (msDescription == rOtherField.msDescription); + } +}; + +struct SVX_DLLPUBLIC ClassificationResult +{ + ClassificationType meType; + OUString msString; + sal_Int32 mnParagraph; +}; + +} // end svx namespace + +#endif // INCLUDED_SVX_CLASSIFICATIONFIELD_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/Library_svx.mk b/svx/Library_svx.mk index b24478828ff2..1189b8c29bc0 100644 --- a/svx/Library_svx.mk +++ b/svx/Library_svx.mk @@ -117,6 +117,7 @@ $(eval $(call gb_Library_add_exception_objects,svx,\ svx/source/dialog/crashreportdlg \ svx/source/dialog/crashreportui) \ svx/source/dialog/ctredlin \ + svx/source/dialog/ClassificationEditView \ svx/source/dialog/databaseregistrationui \ svx/source/dialog/dialcontrol \ svx/source/dialog/dlgctl3d \ diff --git a/svx/source/dialog/ClassificationEditView.cxx b/svx/source/dialog/ClassificationEditView.cxx new file mode 100644 index 000000000000..9f8b2c8ecdb5 --- /dev/null +++ b/svx/source/dialog/ClassificationEditView.cxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <svx/ClassificationEditView.hxx> +#include <svx/ClassificationField.hxx> + +#include <vcl/svapp.hxx> +#include <vcl/settings.hxx> +#include <svl/itemset.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/eeitem.hxx> + +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL makeClassificationEditView(VclPtr<vcl::Window> & rRet, VclPtr<vcl::Window> & pParent, VclBuilder::stringmap &) +{ + rRet = VclPtr<svx::ClassificationEditView>::Create(pParent, WB_BORDER|WB_TABSTOP); +} + +namespace svx { + +ClassificationEditEngine::ClassificationEditEngine(SfxItemPool* pItemPool) + : EditEngine(pItemPool) +{} + +OUString ClassificationEditEngine::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 /*nPara*/, + sal_Int32 /*nPos*/, Color*& /*rTxtColor*/, Color*& /*rFldColor*/) +{ + OUString aString; + const ClassificationField* pClassificationField = dynamic_cast<const ClassificationField*>(rField.GetField()); + if (pClassificationField) + aString = pClassificationField->msDescription; + else + aString = "Unknown"; + return aString; +} + +ClassificationEditView::ClassificationEditView(vcl::Window* pParent, WinBits nBits) + : Control(pParent, nBits) +{ + EnableRTL(false); + + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + Color aBgColor = rStyleSettings.GetWindowColor(); + + SetMapMode(MapUnit::MapTwip); + SetPointer(PointerStyle::Text); + SetBackground(aBgColor); + + Size aSize(GetOutputSize()); + aSize.Height() *= 4; + + pEdEngine.reset(new ClassificationEditEngine(EditEngine::CreatePool())); + pEdEngine->SetPaperSize( aSize ); + pEdEngine->SetRefDevice( this ); + + pEdEngine->SetControlWord(pEdEngine->GetControlWord() | EEControlBits::MARKFIELDS); + + pEdView.reset(new EditView(pEdEngine.get(), this)); + pEdView->SetOutputArea(tools::Rectangle(Point(0,0), GetOutputSize())); + + pEdView->SetBackgroundColor(aBgColor); + pEdEngine->InsertView(pEdView.get()); +} + +ClassificationEditView::~ClassificationEditView() +{ + disposeOnce(); +} + +void ClassificationEditView::dispose() +{ + Control::dispose(); +} + +void ClassificationEditView::Resize() +{ + Size aOutputSize(GetOutputSize()); + Size aSize(aOutputSize); + aSize.Height() *= 4; + pEdEngine->SetPaperSize(aSize); + pEdView->SetOutputArea(tools::Rectangle(Point(0,0), aOutputSize)); + Control::Resize(); +} + +void ClassificationEditView::InsertField(const SvxFieldItem& rFieldItem) +{ + pEdView->InsertField(rFieldItem); + pEdView->Invalidate(); +} + +void ClassificationEditView::InvertSelectionWeight() +{ + std::unique_ptr<SfxItemSet> pSet(new SfxItemSet(pEdEngine->GetAttribs(pEdView->GetSelection()))); + FontWeight eFontWeight = WEIGHT_BOLD; + if (const SfxPoolItem* pItem = pSet->GetItem(EE_CHAR_WEIGHT, true)) + { + const SvxWeightItem* pWeightItem = dynamic_cast<const SvxWeightItem*>(pItem); + if (pWeightItem && pWeightItem->GetWeight() == WEIGHT_BOLD) + eFontWeight = WEIGHT_NORMAL; + } + + SvxWeightItem aWeight(eFontWeight, EE_CHAR_WEIGHT); + pSet->Put(aWeight); + pEdEngine->QuickSetAttribs(*pSet, pEdView->GetSelection()); + pEdView->Invalidate(); +} + +void ClassificationEditView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) +{ + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + Color aBgColor = rStyleSettings.GetWindowColor(); + + pEdView->SetBackgroundColor(aBgColor); + + SetBackground(aBgColor); + + Control::Paint(rRenderContext, rRect); + + pEdView->Paint(rRect); + + if (HasFocus()) + pEdView->ShowCursor(); +} + +void ClassificationEditView::MouseMove(const MouseEvent& rMEvt) +{ + pEdView->MouseMove(rMEvt); +} + +void ClassificationEditView::MouseButtonDown(const MouseEvent& rMEvt) +{ + if (!HasFocus()) + GrabFocus(); + + pEdView->MouseButtonDown(rMEvt); +} + +void ClassificationEditView::MouseButtonUp(const MouseEvent& rMEvt) +{ + pEdView->MouseButtonUp(rMEvt); +} + +void ClassificationEditView::KeyInput(const KeyEvent& rKEvt) +{ + sal_uInt16 nKey = rKEvt.GetKeyCode().GetModifier() + rKEvt.GetKeyCode().GetCode(); + + if (nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT) + { + Control::KeyInput( rKEvt ); + } + else if (!pEdView->PostKeyEvent(rKEvt)) + { + Control::KeyInput(rKEvt); + } +} + +void ClassificationEditView::Command(const CommandEvent& rCEvt) +{ + pEdView->Command(rCEvt); +} + +void ClassificationEditView::GetFocus() +{ + pEdView->ShowCursor(); + + Control::GetFocus(); +} + +void ClassificationEditView::LoseFocus() +{ + Control::LoseFocus(); +} + +} // end sfx2 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |