summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--svx/source/sidebar/inspector/InspectorTextPanel.cxx1
-rw-r--r--sw/source/uibase/sidebar/SwPanelFactory.cxx2
-rw-r--r--sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx182
-rw-r--r--sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx25
4 files changed, 197 insertions, 13 deletions
diff --git a/svx/source/sidebar/inspector/InspectorTextPanel.cxx b/svx/source/sidebar/inspector/InspectorTextPanel.cxx
index 68ac911a6408..07ab0ab38ca4 100644
--- a/svx/source/sidebar/inspector/InspectorTextPanel.cxx
+++ b/svx/source/sidebar/inspector/InspectorTextPanel.cxx
@@ -49,6 +49,7 @@ InspectorTextPanel::InspectorTextPanel(vcl::Window* pParent,
void InspectorTextPanel::updateEntries(std::vector<OUString> store)
{
+ mxListBoxStyles->clear();
for (OUString& str : store)
mxListBoxStyles->append_text(str);
}
diff --git a/sw/source/uibase/sidebar/SwPanelFactory.cxx b/sw/source/uibase/sidebar/SwPanelFactory.cxx
index b073b2801733..b3d1bbf6932f 100644
--- a/sw/source/uibase/sidebar/SwPanelFactory.cxx
+++ b/sw/source/uibase/sidebar/SwPanelFactory.cxx
@@ -172,7 +172,7 @@ Reference<ui::XUIElement> SAL_CALL SwPanelFactory::createUIElement (
}
else if (rsResourceURL.endsWith("/WriterInspectorTextPanel"))
{
- VclPtr<vcl::Window> pPanel = sw::sidebar::WriterInspectorTextPanel::Create( pParentWindow, xFrame);
+ VclPtr<vcl::Window> pPanel = sw::sidebar::WriterInspectorTextPanel::Create( pParentWindow, xFrame, pBindings);
xElement = sfx2::sidebar::SidebarPanelBase::Create(
rsResourceURL,
xFrame,
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
index c0fc42be0ac4..10277c7eabe4 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
@@ -18,16 +18,24 @@
*/
#include "WriterInspectorTextPanel.hxx"
-
+#include <svx/svxids.hrc>
+#include <doc.hxx>
+#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <com/sun/star/text/XTextRange.hpp>
+#include <com/sun/star/text/XTextCursor.hpp>
+#include <com/sun/star/awt/FontSlant.hpp>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
-using namespace css;
+#include <unotextrange.hxx>
namespace sw::sidebar
{
-VclPtr<vcl::Window>
-WriterInspectorTextPanel::Create(vcl::Window* pParent,
- const css::uno::Reference<css::frame::XFrame>& rxFrame)
+VclPtr<vcl::Window> WriterInspectorTextPanel::Create(vcl::Window* pParent,
+ const uno::Reference<frame::XFrame>& rxFrame,
+ SfxBindings* pBindings)
{
if (pParent == nullptr)
throw lang::IllegalArgumentException(
@@ -35,17 +43,175 @@ WriterInspectorTextPanel::Create(vcl::Window* pParent,
if (!rxFrame.is())
throw lang::IllegalArgumentException("no XFrame given to WriterInspectorTextPanel::Create",
nullptr, 1);
+ if (pBindings == nullptr)
+ throw lang::IllegalArgumentException(
+ "no SfxBindings given to WriterInspectorTextPanel::Create", nullptr, 2);
- return VclPtr<WriterInspectorTextPanel>::Create(pParent, rxFrame);
+ return VclPtr<WriterInspectorTextPanel>::Create(pParent, rxFrame, pBindings);
}
-WriterInspectorTextPanel::WriterInspectorTextPanel(
- vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rxFrame)
+
+WriterInspectorTextPanel::WriterInspectorTextPanel(vcl::Window* pParent,
+ const uno::Reference<frame::XFrame>& rxFrame,
+ SfxBindings* pBindings)
: InspectorTextPanel(pParent, rxFrame)
+ , maCharStyle(SID_STYLE_FAMILY1, *pBindings, *this)
+{
+}
+
+void WriterInspectorTextPanel::NotifyItemUpdate(const sal_uInt16 nSId,
+ const SfxItemState /*eState*/,
+ const SfxPoolItem* /*pState*/)
{
+ SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
std::vector<OUString> store;
+ switch (nSId)
+ {
+ case SID_STYLE_FAMILY1:
+ {
+ if (pDocSh)
+ {
+ SwDoc* pDoc = pDocSh->GetDoc();
+ SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
+
+ uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(
+ pDocSh->GetBaseModel(), uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies
+ = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(
+ xStyleFamilies->getByName("CharacterStyles"), uno::UNO_QUERY);
+
+ uno::Reference<text::XTextCursor> xCursor
+ = dynamic_cast<text::XTextCursor*>(pCursor);
+ uno::Reference<text::XTextRange> xRange(
+ SwXTextRange::CreateXTextRange(*pDoc, *pCursor->GetPoint(), nullptr));
+ uno::Reference<beans::XPropertySet> properties(xRange, uno::UNO_QUERY_THROW);
+
+ OUString aCurrentStyleName, aDisplayName;
+ properties->getPropertyValue("CharStyleName") >>= aCurrentStyleName;
+ std::vector<OUString> aStyleNames;
+ std::unordered_map<OUString, bool> maRedefined;
+ if (aCurrentStyleName.isEmpty())
+ aCurrentStyleName = "Standard";
+
+ while (true)
+ {
+ const uno::Reference<style::XStyle> xProp1(
+ xStyleFamily->getByName(aCurrentStyleName), uno::UNO_QUERY);
+ const uno::Reference<beans::XPropertySet> xProp1Set(
+ xStyleFamily->getByName(aCurrentStyleName), uno::UNO_QUERY);
+ OUString aParentCharStyle = xProp1->getParentStyle();
+ xProp1Set->getPropertyValue("DisplayName") >>= aDisplayName;
+ if (aParentCharStyle.isEmpty())
+ {
+ break; // when current style is "Standard"
+ }
+ const uno::Sequence<beans::Property> xProp1SetInfo
+ = xProp1Set->getPropertySetInfo()->getProperties();
+ const uno::Reference<beans::XPropertySet> xProp2Set(
+ xStyleFamily->getByName(aParentCharStyle), uno::UNO_QUERY);
+
+ try
+ {
+ for (const beans::Property& rProperty : xProp1SetInfo)
+ {
+ if (maRedefined[rProperty.Name])
+ continue;
+ if (xProp1Set->getPropertyValue(rProperty.Name)
+ != xProp2Set->getPropertyValue(rProperty.Name))
+ {
+ OUString aPropertyValuePair;
+ const uno::Any aAny = xProp1Set->getPropertyValue(rProperty.Name);
+ maRedefined[rProperty.Name] = true;
+ WriterInspectorTextPanel::GetPropertyValues(rProperty, aAny,
+ aPropertyValuePair);
+ if (!aPropertyValuePair.isEmpty())
+ aStyleNames.push_back(" " + aPropertyValuePair);
+ }
+ }
+ }
+ catch (const uno::Exception&)
+ {
+ //do nothing
+ }
+
+ aStyleNames.push_back(aDisplayName);
+ aCurrentStyleName = aParentCharStyle;
+ }
+
+ const uno::Reference<beans::XPropertySet> xStyleProps(
+ xStyleFamily->getByName(aDisplayName), uno::UNO_QUERY);
+ const uno::Sequence<beans::Property> xPropVal
+ = xStyleProps->getPropertySetInfo()->getProperties();
+ for (const beans::Property& rProperty : xPropVal)
+ {
+ OUString aPropertyValuePair;
+ const uno::Any aAny = xStyleProps->getPropertyValue(rProperty.Name);
+ if (maRedefined[rProperty.Name])
+ continue;
+ WriterInspectorTextPanel::GetPropertyValues(rProperty, aAny,
+ aPropertyValuePair);
+ if (!aPropertyValuePair.isEmpty())
+ aStyleNames.push_back(" " + aPropertyValuePair);
+ }
+ aStyleNames.push_back(" " + aDisplayName);
+
+ // Top Parent goes first, then its properties, then child styles...current style goes last
+ for (auto itr = aStyleNames.rbegin(); itr != aStyleNames.rend(); ++itr)
+ {
+ store.push_back(*itr);
+ }
+ }
+ }
+ break;
+ }
InspectorTextPanel::updateEntries(store);
}
+void WriterInspectorTextPanel::GetPropertyValues(const beans::Property rProperty,
+ const uno::Any& rAny, OUString& rString)
+{
+ OUString aValue;
+ double fValue;
+ bool bValue;
+ short sValue;
+ long lValue;
+ awt::FontSlant iValue;
+
+ rString = rProperty.Name + " ";
+
+ if (rAny >>= bValue)
+ {
+ rString += OUString::boolean(bValue);
+ }
+ else if ((rAny >>= aValue) && !(aValue.isEmpty()))
+ {
+ rString += aValue;
+ }
+ else if (rAny >>= iValue)
+ {
+ rString += (iValue == awt::FontSlant_ITALIC) ? OUStringLiteral("italic")
+ : OUStringLiteral("normal");
+ }
+ else if ((rAny >>= fValue) || fValue)
+ {
+ if (rString == "CharWeight ")
+ rString += (fValue > 100) ? OUStringLiteral("bold") : OUStringLiteral("normal");
+ else
+ rString += OUString::number((round(fValue * 100)) / 100.00);
+ }
+ else if ((rAny >>= sValue) || sValue)
+ {
+ rString += OUString::number(sValue);
+ }
+ else if ((rAny >>= lValue) || lValue)
+ {
+ if (rString == "CharColor ")
+ rString += OUString::number(sal_Int16(lValue));
+ else
+ rString += OUString::number(lValue);
+ }
+}
+
} // end of namespace svx::sidebar
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
index 85b8dc7a9f2f..d99b6c5a6f0f 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
@@ -19,22 +19,39 @@
#pragma once
#include <sfx2/weldutils.hxx>
-#include <svx/sidebar/InspectorTextPanel.hxx>
+#include <sfx2/sidebar/ControllerItem.hxx>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <svx/sidebar/InspectorTextPanel.hxx>
namespace sw
{
namespace sidebar
{
-class WriterInspectorTextPanel final : public svx::sidebar::InspectorTextPanel
+class WriterInspectorTextPanel final
+ : public svx::sidebar::InspectorTextPanel,
+ public sfx2::sidebar::ControllerItem::ItemUpdateReceiverInterface
{
public:
static VclPtr<vcl::Window> Create(vcl::Window* pParent,
- const css::uno::Reference<css::frame::XFrame>& rxFrame);
+ const css::uno::Reference<css::frame::XFrame>& rxFrame,
+ SfxBindings* pBindings);
WriterInspectorTextPanel(vcl::Window* pParent,
- const css::uno::Reference<css::frame::XFrame>& rxFrame);
+ const css::uno::Reference<css::frame::XFrame>& rxFrame,
+ SfxBindings* pBindings);
// virtual ~WriterInspectorTextPanel();
+ virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState,
+ const SfxPoolItem* pState) override;
+
+ virtual void GetControlState(const sal_uInt16 /*nSId*/,
+ boost::property_tree::ptree& /*rState*/) override{};
+
+private:
+ sfx2::sidebar::ControllerItem maCharStyle;
+
+ static void GetPropertyValues(const css::beans::Property rProperty, const css::uno::Any& rAny,
+ OUString& rString);
};
}
} // end of namespace svx::sidebar