LibreOffice Module sw (master)  1
WriterInspectorTextPanel.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
21 
22 #include <doc.hxx>
23 #include <ndtxt.hxx>
24 #include <docsh.hxx>
25 #include <wrtsh.hxx>
26 #include <unoprnms.hxx>
27 #include <editeng/unoprnms.hxx>
28 #include <com/sun/star/text/XTextRange.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/beans/XPropertyState.hpp>
31 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 #include <com/sun/star/table/BorderLine2.hpp>
33 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 
35 #include <unotextrange.hxx>
36 #include <comphelper/string.hxx>
39 #include <vcl/settings.hxx>
40 #include <inspectorproperties.hrc>
41 #include <strings.hrc>
42 
43 namespace sw::sidebar
44 {
45 static void UpdateTree(SwDocShell* pDocSh, std::vector<svx::sidebar::TreeNode>& aStore);
46 
48  const uno::Reference<frame::XFrame>& rxFrame)
49 {
50  if (pParent == nullptr)
51  throw lang::IllegalArgumentException(
52  "no parent Window given to WriterInspectorTextPanel::Create", nullptr, 0);
53  if (!rxFrame.is())
54  throw lang::IllegalArgumentException("no XFrame given to WriterInspectorTextPanel::Create",
55  nullptr, 1);
56 
57  return VclPtr<WriterInspectorTextPanel>::Create(pParent, rxFrame);
58 }
59 
61  const uno::Reference<frame::XFrame>& rxFrame)
62  : InspectorTextPanel(pParent, rxFrame)
63 {
64  SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
65  m_pShell = pDocSh->GetWrtShell();
66  if (m_pShell)
67  {
69  m_pShell->SetChgLnk(LINK(this, WriterInspectorTextPanel, AttrChangedNotify));
70  }
71 
72  // Update panel on start
73  std::vector<svx::sidebar::TreeNode> aStore;
74  if (pDocSh->GetDoc()->GetEditShell()->GetCursor()->GetNode().GetTextNode())
75  UpdateTree(pDocSh, aStore);
76  updateEntries(aStore);
77 }
78 
80 
82 {
84 
86 }
87 
88 static OUString PropertyNametoRID(const OUString& rName)
89 {
90  static const std::map<OUString, const char*> aNameToRID = {
91  { "BorderDistance", RID_BORDER_DISTANCE },
92  { "BottomBorder", RID_BOTTOM_BORDER },
93  { "BottomBorderDistance", RID_BOTTOM_BORDER_DISTANCE },
94  { "BreakType", RID_BREAK_TYPE },
95  { "Category", RID_CATEGORY },
96  { "Cell", RID_CELL },
97  { "CharAutoEscapement", RID_CHAR_AUTO_ESCAPEMENT },
98  { "CharAutoKerning", RID_CHAR_AUTO_KERNING },
99  { "CharAutoStyleName", RID_CHAR_AUTO_STYLE_NAME },
100  { "CharBackColor", RID_CHAR_BACK_COLOR },
101  { "CharBackTransparent", RID_CHAR_BACK_TRANSPARENT },
102  { "CharBorderDistance", RID_CHAR_BORDER_DISTANCE },
103  { "CharBottomBorder", RID_CHAR_BOTTOM_BORDER },
104  { "CharBottomBorderDistance", RID_CHAR_BOTTOM_BORDER_DISTANCE },
105  { "CharCaseMap", RID_CHAR_CASE_MAP },
106  { "CharColor", RID_CHAR_COLOR },
107  { "CharCombineIsOn", RID_CHAR_COMBINE_IS_ON },
108  { "CharCombinePrefix", RID_CHAR_COMBINE_PREFIX },
109  { "CharCombineSuffix", RID_CHAR_COMBINE_SUFFIX },
110  { "CharContoured", RID_CHAR_CONTOURED },
111  { "CharCrossedOut", RID_CHAR_CROSSED_OUT },
112  { "CharDiffHeight", RID_CHAR_DIFF_HEIGHT },
113  { "CharDiffHeightAsian", RID_CHAR_DIFF_HEIGHT_ASIAN },
114  { "CharDiffHeightComplex", RID_CHAR_DIFF_HEIGHT_COMPLEX },
115  { "CharEmphasis", RID_CHAR_EMPHASIS },
116  { "CharEscapement", RID_CHAR_ESCAPEMENT },
117  { "CharEscapementHeight", RID_CHAR_ESCAPEMENT_HEIGHT },
118  { "CharFlash", RID_CHAR_FLASH },
119  { "CharFontCharSet", RID_CHAR_FONT_CHAR_SET },
120  { "CharFontCharSetAsian", RID_CHAR_FONT_CHAR_SET_ASIAN },
121  { "CharFontCharSetComplex", RID_CHAR_FONT_CHAR_SET_COMPLEX },
122  { "CharFontFamily", RID_CHAR_FONT_FAMILY },
123  { "CharFontFamilyAsian", RID_CHAR_FONT_FAMILY_ASIAN },
124  { "CharFontFamilyComplex", RID_CHAR_FONT_FAMILY_COMPLEX },
125  { "CharFontName", RID_CHAR_FONT_NAME },
126  { "CharFontNameAsian", RID_CHAR_FONT_NAME_ASIAN },
127  { "CharFontNameComplex", RID_CHAR_FONT_NAME_COMPLEX },
128  { "CharFontPitch", RID_CHAR_FONT_PITCH },
129  { "CharFontPitchAsian", RID_CHAR_FONT_PITCH_ASIAN },
130  { "CharFontPitchComplex", RID_CHAR_FONT_PITCH_COMPLEX },
131  { "CharFontStyleName", RID_CHAR_FONT_STYLE_NAME },
132  { "CharFontStyleNameAsian", RID_CHAR_FONT_STYLE_NAME_ASIAN },
133  { "CharFontStyleNameComplex", RID_CHAR_FONT_STYLE_NAME_COMPLEX },
134  { "CharHeight", RID_CHAR_HEIGHT },
135  { "CharHeightAsian", RID_CHAR_HEIGHT_ASIAN },
136  { "CharHeightComplex", RID_CHAR_HEIGHT_COMPLEX },
137  { "CharHidden", RID_CHAR_HIDDEN },
138  { "CharHighlight", RID_CHAR_HIGHLIGHT },
139  { "CharInteropGrabBag", RID_CHAR_INTEROP_GRAB_BAG },
140  { "CharKerning", RID_CHAR_KERNING },
141  { "CharLeftBorder", RID_CHAR_LEFT_BORDER },
142  { "CharLeftBorderDistance", RID_CHAR_LEFT_BORDER_DISTANCE },
143  { "CharLocale", RID_CHAR_LOCALE },
144  { "CharLocaleAsian", RID_CHAR_LOCALE_ASIAN },
145  { "CharLocaleComplex", RID_CHAR_LOCALE_COMPLEX },
146  { "CharNoHyphenation", RID_CHAR_NO_HYPHENATION },
147  { "CharOverline", RID_CHAR_OVERLINE },
148  { "CharOverlineColor", RID_CHAR_OVERLINE_COLOR },
149  { "CharOverlineHasColor", RID_CHAR_OVERLINE_HAS_COLOR },
150  { "CharPosture", RID_CHAR_POSTURE },
151  { "CharPostureAsian", RID_CHAR_POSTURE_ASIAN },
152  { "CharPostureComplex", RID_CHAR_POSTURE_COMPLEX },
153  { "CharPropHeight", RID_CHAR_PROP_HEIGHT },
154  { "CharPropHeightAsian", RID_CHAR_PROP_HEIGHT_ASIAN },
155  { "CharPropHeightComplex", RID_CHAR_PROP_HEIGHT_COMPLEX },
156  { "CharRelief", RID_CHAR_RELIEF },
157  { "CharRightBorder", RID_CHAR_RIGHT_BORDER },
158  { "CharRightBorderDistance", RID_CHAR_RIGHT_BORDER_DISTANCE },
159  { "CharRotation", RID_CHAR_ROTATION },
160  { "CharRotationIsFitToLine", RID_CHAR_ROTATION_IS_FIT_TO_LINE },
161  { "CharScaleWidth", RID_CHAR_SCALE_WIDTH },
162  { "CharShadingValue", RID_CHAR_SHADING_VALUE },
163  { "CharShadowFormat", RID_CHAR_SHADOW_FORMAT },
164  { "CharShadowed", RID_CHAR_SHADOWED },
165  { "CharStrikeout", RID_CHAR_STRIKEOUT },
166  { "CharStyleName", RID_CHAR_STYLE_NAME },
167  { "CharStyleNames", RID_CHAR_STYLE_NAMES },
168  { "CharTopBorder", RID_CHAR_TOP_BORDER },
169  { "CharTopBorderDistance", RID_CHAR_TOP_BORDER_DISTANCE },
170  { "CharTransparence", RID_CHAR_TRANSPARENCE },
171  { "CharUnderline", RID_CHAR_UNDERLINE },
172  { "CharUnderlineColor", RID_CHAR_UNDERLINE_COLOR },
173  { "CharUnderlineHasColor", RID_CHAR_UNDERLINE_HAS_COLOR },
174  { "CharWeight", RID_CHAR_WEIGHT },
175  { "CharWeightAsian", RID_CHAR_WEIGHT_ASIAN },
176  { "CharWeightComplex", RID_CHAR_WEIGHT_COMPLEX },
177  { "CharWordMode", RID_CHAR_WORD_MODE },
178  { "ContinueingPreviousSubTree", RID_CONTINUING_PREVIOUS_SUB_TREE },
179  { "DisplayName", RID_DISPLAY_NAME },
180  { "DocumentIndex", RID_DOCUMENT_INDEX },
181  { "DocumentIndexMark", RID_DOCUMENT_INDEX_MARK },
182  { "DropCapCharStyleName", RID_DROP_CAP_CHAR_STYLE_NAME },
183  { "DropCapFormat", RID_DROP_CAP_FORMAT },
184  { "DropCapWholeWord", RID_DROP_CAP_WHOLE_WORD },
185  { "Endnote", RID_ENDNOTE },
186  { "FillBackground", RID_FILL_BACKGROUND },
187  { "FillBitmap", RID_FILL_BITMAP },
188  { "FillBitmapLogicalSize", RID_FILL_BITMAP_LOGICAL_SIZE },
189  { "FillBitmapMode", RID_FILL_BITMAP_MODE },
190  { "FillBitmapName", RID_FILL_BITMAP_NAME },
191  { "FillBitmapOffsetX", RID_FILL_BITMAP_OFFSET_X },
192  { "FillBitmapOffsetY", RID_FILL_BITMAP_OFFSET_Y },
193  { "FillBitmapPositionOffsetX", RID_FILL_BITMAP_POSITION_OFFSET_X },
194  { "FillBitmapPositionOffsetY", RID_FILL_BITMAP_POSITION_OFFSET_Y },
195  { "FillBitmapRectanglePoint", RID_FILL_BITMAP_RECTANGLE_POINT },
196  { "FillBitmapSizeX", RID_FILL_BITMAP_SIZE_X },
197  { "FillBitmapSizeY", RID_FILL_BITMAP_SIZE_Y },
198  { "FillBitmapStretch", RID_FILL_BITMAP_STRETCH },
199  { "FillBitmapTile", RID_FILL_BITMAP_TILE },
200  { "FillBitmapURL", RID_FILL_BITMAP_URL },
201  { "FillColor", RID_FILL_COLOR },
202  { "FillColor2", RID_FILL_COLOR2 },
203  { "FillGradient", RID_FILL_GRADIENT },
204  { "FillGradientName", RID_FILL_GRADIENT_NAME },
205  { "FillGradientStepCount", RID_FILL_GRADIENT_STEP_COUNT },
206  { "FillHatch", RID_FILL_HATCH },
207  { "FillHatchName", RID_FILL_HATCH_NAME },
208  { "FillStyle", RID_FILL_STYLE },
209  { "FillTransparence", RID_FILL_TRANSPARENCE },
210  { "FillTransparenceGradient", RID_FILL_TRANSPARENCE_GRADIENT },
211  { "FillTransparenceGradientName", RID_FILL_TRANSPARENCE_GRADIENT_NAME },
212  { "FollowStyle", RID_FOLLOW_STYLE },
213  { "Footnote", RID_FOOTNOTE },
214  { "Hidden", RID_HIDDEN },
215  { "HyperLinkEvents", RID_HYPERLINK_EVENTS },
216  { "HyperLinkName", RID_HYPERLINK_NAME },
217  { "HyperLinkTarget", RID_HYPERLINK_TARGET },
218  { "HyperLinkURL", RID_HYPERLINK_URL },
219  { "IsAutoUpdate", RID_IS_AUTO_UPDATE },
220  { "IsPhysical", RID_IS_PHYSICAL },
221  { "LeftBorder", RID_LEFT_BORDER },
222  { "LeftBorderDistance", RID_LEFT_BORDER_DISTANCE },
223  { "ListAutoFormat", RID_LIST_AUTO_FORMAT },
224  { "ListId", RID_LIST_ID },
225  { "ListLabelString", RID_LIST_LABEL_STRING },
226  { "NestedTextContent", RID_NESTED_TEXT_CONTENT },
227  { "NumberingIsNumber", RID_NUMBERING_IS_NUMBER },
228  { "NumberingLevel", RID_NUMBERING_LEVEL },
229  { "NumberingRules", RID_NUMBERING_RULES },
230  { "NumberingStartValue", RID_NUMBERING_START_VALUE },
231  { "NumberingStyleName", RID_NUMBERING_STYLE_NAME },
232  { "OutlineContentVisible", RID_OUTLINE_CONTENT_VISIBLE },
233  { "OutlineLevel", RID_OUTLINE_LEVEL },
234  { "PageDescName", RID_PAGE_DESC_NAME },
235  { "PageNumberOffset", RID_PAGE_NUMBER_OFFSET },
236  { "PageStyleName", RID_PAGE_STYLE_NAME },
237  { "ParRsid", RID_PAR_RSID },
238  { "ParaAdjust", RID_PARA_ADJUST },
239  { "ParaAutoStyleName", RID_PARA_AUTO_STYLE_NAME },
240  { "ParaBackColor", RID_PARA_BACK_COLOR },
241  { "ParaBackGraphic", RID_PARA_BACK_GRAPHIC },
242  { "ParaBackGraphicFilter", RID_PARA_BACK_GRAPHIC_FILTER },
243  { "ParaBackGraphicLocation", RID_PARA_BACK_GRAPHIC_LOCATION },
244  { "ParaBackGraphicURL", RID_PARA_BACK_GRAPHIC_URL },
245  { "ParaBackTransparent", RID_PARA_BACK_TRANSPARENT },
246  { "ParaBottomMargin", RID_PARA_BOTTOM_MARGIN },
247  { "ParaBottomMarginRelative", RID_PARA_BOTTOM_MARGIN_RELATIVE },
248  { "ParaChapterNumberingLevel", RID_PARA_CHAPTER_NUMBERING_LEVEL },
249  { "ParaConditionalStyleName", RID_PARA_CONDITIONAL_STYLE_NAME },
250  { "ParaContextMargin", RID_PARA_CONTEXT_MARGIN },
251  { "ParaExpandSingleWord", RID_PARA_EXPAND_SINGLE_WORD },
252  { "ParaFirstLineIndent", RID_PARA_FIRST_LINE_INDENT },
253  { "ParaFirstLineIndentRelative", RID_PARA_FIRST_LINE_INDENT_RELATIVE },
254  { "ParaHyphenationMaxHyphens", RID_PARA_HYPHENATION_MAX_HYPHENS },
255  { "ParaHyphenationMaxLeadingChars", RID_PARA_HYPHENATION_MAX_LEADING_CHARS },
256  { "ParaHyphenationMaxTrailingChars", RID_PARA_HYPHENATION_MAX_TRAILING_CHARS },
257  { "ParaHyphenationNoCaps", RID_PARA_HYPHENATION_NO_CAPS },
258  { "ParaInteropGrabBag", RID_PARA_INTEROP_GRAB_BAG },
259  { "ParaIsAutoFirstLineIndent", RID_PARA_IS_AUTO_FIRST_LINE_INDENT },
260  { "ParaIsCharacterDistance", RID_PARA_IS_CHARACTER_DISTANCE },
261  { "ParaIsConnectBorder", RID_PARA_IS_CONNECT_BORDER },
262  { "ParaIsForbiddenRules", RID_PARA_IS_FORBIDDEN_RULES },
263  { "ParaIsHangingPunctuation", RID_PARA_IS_HANGING_PUNCTUATION },
264  { "ParaIsHyphenation", RID_PARA_IS_HYPHENATION },
265  { "ParaIsNumberingRestart", RID_PARA_IS_NUMBERING_RESTART },
266  { "ParaKeepTogether", RID_PARA_KEEP_TOGETHER },
267  { "ParaLastLineAdjust", RID_PARA_LAST_LINE_ADJUST },
268  { "ParaLeftMargin", RID_PARA_LEFT_MARGIN },
269  { "ParaLeftMarginRelative", RID_PARA_LEFT_MARGIN_RELATIVE },
270  { "ParaLineNumberCount", RID_PARA_LINE_NUMBER_COUNT },
271  { "ParaLineNumberStartValue", RID_PARA_LINE_NUMBER_START_VALUE },
272  { "ParaLineSpacing", RID_PARA_LINE_SPACING },
273  { "ParaOrphans", RID_PARA_ORPHANS },
274  { "ParaRegisterModeActive", RID_PARA_REGISTER_MODE_ACTIVE },
275  { "ParaRightMargin", RID_PARA_RIGHT_MARGIN },
276  { "ParaRightMarginRelative", RID_PARA_RIGHT_MARGIN_RELATIVE },
277  { "ParaShadowFormat", RID_PARA_SHADOW_FORMAT },
278  { "ParaSplit", RID_PARA_SPLIT },
279  { "ParaStyleName", RID_PARA_STYLE_NAME },
280  { "ParaTabStops", RID_PARA_TAB_STOPS },
281  { "ParaTopMargin", RID_PARA_TOP_MARGIN },
282  { "ParaTopMarginRelative", RID_PARA_TOP_MARGIN_RELATIVE },
283  { "ParaUserDefinedAttributes", RID_PARA_USER_DEFINED_ATTRIBUTES },
284  { "ParaVertAlignment", RID_PARA_VERT_ALIGNMENT },
285  { "ParaWidows", RID_PARA_WIDOWS },
286  { "ReferenceMark", RID_REFERENCE_MARK },
287  { "RightBorder", RID_RIGHT_BORDER },
288  { "RightBorderDistance", RID_RIGHT_BORDER_DISTANCE },
289  { "Rsid", RID_RSID },
290  { "RubyAdjust", RID_RUBY_ADJUST },
291  { "RubyCharStyleName", RID_RUBY_CHAR_STYLE_NAME },
292  { "RubyIsAbove", RID_RUBY_IS_ABOVE },
293  { "RubyPosition", RID_RUBY_POSITION },
294  { "RubyText", RID_RUBY_TEXT },
295  { "SnapToGrid", RID_SNAP_TO_GRID },
296  { "StyleInteropGrabBag", RID_STYLE_INTEROP_GRAB_BAG },
297  { "TextField", RID_TEXT_FIELD },
298  { "TextFrame", RID_TEXT_FRAME },
299  { "TextParagraph", RID_TEXT_PARAGRAPH },
300  { "TextSection", RID_TEXT_SECTION },
301  { "TextTable", RID_TEXT_TABLE },
302  { "TextUserDefinedAttributes", RID_TEXT_USER_DEFINED_ATTRIBUTES },
303  { "TopBorder", RID_TOP_BORDER },
304  { "TopBorderDistance", RID_TOP_BORDER_DISTANCE },
305  { "UnvisitedCharStyleName", RID_UNVISITED_CHAR_STYLE_NAME },
306  { "VisitedCharStyleName", RID_VISITED_CHAR_STYLE_NAME },
307  { "WritingMode", RID_WRITING_MODE },
308  { "BorderColor", RID_BORDER_COLOR },
309  { "BorderInnerLineWidth", RID_BORDER_INNER_LINE_WIDTH },
310  { "BorderLineDistance", RID_BORDER_LINE_DISTANCE },
311  { "BorderLineStyle", RID_BORDER_LINE_STYLE },
312  { "BorderLineWidth", RID_BORDER_LINE_WIDTH },
313  { "BorderOuterLineWidth", RID_BORDER_OUTER_LINE_WIDTH },
314  };
315 
316  auto itr = aNameToRID.find(rName);
317  if (itr != aNameToRID.end())
318  return SwResId(itr->second);
319  return rName;
320 }
321 
322 static svx::sidebar::TreeNode SimplePropToTreeNode(const OUString& rName, const css::uno::Any& rVal)
323 {
324  svx::sidebar::TreeNode aCurNode;
325  aCurNode.sNodeName = PropertyNametoRID(rName);
326  aCurNode.aValue = rVal;
327 
328  return aCurNode;
329 }
330 
331 static svx::sidebar::TreeNode BorderToTreeNode(const OUString& rName, const css::uno::Any& rVal)
332 {
333  table::BorderLine2 aBorder;
334  rVal >>= aBorder;
335  svx::sidebar::TreeNode aCurNode;
336  aCurNode.sNodeName = PropertyNametoRID(rName);
338 
339  aCurNode.children.push_back(SimplePropToTreeNode("BorderColor", css::uno::Any(aBorder.Color)));
340  aCurNode.children.push_back(
341  SimplePropToTreeNode("BorderLineWidth", css::uno::Any(aBorder.LineWidth)));
342  aCurNode.children.push_back(
343  SimplePropToTreeNode("BorderLineStyle", css::uno::Any(aBorder.LineStyle)));
344  aCurNode.children.push_back(
345  SimplePropToTreeNode("BorderLineDistance", css::uno::Any(aBorder.LineDistance)));
346  aCurNode.children.push_back(
347  SimplePropToTreeNode("BorderInnerLineWidth", css::uno::Any(aBorder.InnerLineWidth)));
348  aCurNode.children.push_back(
349  SimplePropToTreeNode("BorderOuterLineWidth", css::uno::Any(aBorder.OuterLineWidth)));
350 
351  return aCurNode;
352 }
353 
354 static svx::sidebar::TreeNode LocaleToTreeNode(const OUString& rName, const css::uno::Any& rVal)
355 {
356  svx::sidebar::TreeNode aCurNode;
357  aCurNode.sNodeName = PropertyNametoRID(rName);
358  lang::Locale aLocale;
359  rVal >>= aLocale;
360  OUString aLocaleText(aLocale.Language + "-" + aLocale.Country);
361  if (!aLocale.Variant.isEmpty())
362  aLocaleText += " (" + aLocale.Variant + ")";
363  aCurNode.aValue <<= aLocaleText;
364 
365  return aCurNode;
366 }
367 
369 PropertyToTreeNode(const css::beans::Property& rProperty,
370  const uno::Reference<beans::XPropertySet>& xPropertiesSet, const bool& rIsGrey)
371 {
372  const OUString& rPropName = rProperty.Name;
373  svx::sidebar::TreeNode aCurNode;
374  const uno::Any aAny = xPropertiesSet->getPropertyValue(rPropName);
375  aCurNode.sNodeName = PropertyNametoRID(rPropName);
376 
377  // These properties are handled separately as they are stored in STRUCT and not in single data members
378  if (rPropName == "CharTopBorder" || rPropName == "CharBottomBorder"
379  || rPropName == "CharLeftBorder" || rPropName == "CharRightBorder"
380  || rPropName == "TopBorder" || rPropName == "BottomBorder" || rPropName == "LeftBorder"
381  || rPropName == "RightBorder")
382  {
383  aCurNode = BorderToTreeNode(rPropName, aAny);
384  }
385  else if (rPropName == "CharLocale")
386  {
387  aCurNode = LocaleToTreeNode(rPropName, aAny);
388  }
389  else
390  aCurNode = SimplePropToTreeNode(rPropName, aAny);
391 
392  if (rIsGrey)
393  {
394  aCurNode.isGrey = true;
395  for (svx::sidebar::TreeNode& rChildNode : aCurNode.children)
396  rChildNode.isGrey = true; // grey out all the children nodes
397  }
398 
399  return aCurNode;
400 }
401 
402 static void InsertValues(const css::uno::Reference<css::uno::XInterface>& rSource,
403  std::unordered_map<OUString, bool>& rIsDefined,
404  svx::sidebar::TreeNode& rNode, const bool& isRoot,
405  const std::vector<OUString>& rHiddenProperty)
406 {
407  uno::Reference<beans::XPropertySet> xPropertiesSet(rSource, uno::UNO_QUERY_THROW);
408  uno::Reference<beans::XPropertyState> xPropertiesState(rSource, uno::UNO_QUERY_THROW);
409  const uno::Sequence<beans::Property> aProperties
410  = xPropertiesSet->getPropertySetInfo()->getProperties();
411 
412  for (const beans::Property& rProperty : aProperties)
413  {
414  const OUString& rPropName = rProperty.Name;
415  if (std::find(rHiddenProperty.begin(), rHiddenProperty.end(), rPropName)
416  != rHiddenProperty.end())
417  continue;
418 
419  if (isRoot
420  || xPropertiesState->getPropertyState(rPropName) == beans::PropertyState_DIRECT_VALUE)
421  {
422  svx::sidebar::TreeNode aCurNode
423  = PropertyToTreeNode(rProperty, xPropertiesSet, rIsDefined[rPropName]);
424  rIsDefined[rPropName] = true;
425  rNode.children.push_back(aCurNode);
426  }
427  }
428 
431  Application::GetSettings().GetUILanguageTag().getLocale());
432 
433  std::sort(
434  rNode.children.begin(), rNode.children.end(),
435  [&aSorter](svx::sidebar::TreeNode const& rEntry1, svx::sidebar::TreeNode const& rEntry2) {
436  return aSorter.compare(rEntry1.sNodeName, rEntry2.sNodeName) < 0;
437  });
438 }
439 
440 static void UpdateTree(SwDocShell* pDocSh, std::vector<svx::sidebar::TreeNode>& aStore)
441 {
442  SwDoc* pDoc = pDocSh->GetDoc();
443  SwPaM* pCursor = pDoc->GetEditShell()->GetCursor();
444  svx::sidebar::TreeNode aCharDFNode;
445  svx::sidebar::TreeNode aCharNode;
446  svx::sidebar::TreeNode aParaNode;
447  svx::sidebar::TreeNode aParaDFNode;
448 
449  aCharNode.sNodeName = SwResId(STR_CHARACTERSTYLEFAMILY);
450  aParaNode.sNodeName = SwResId(STR_PARAGRAPHSTYLEFAMILY);
451  aCharDFNode.sNodeName = SwResId(RID_CHAR_DIRECTFORMAT);
452  aParaDFNode.sNodeName = SwResId(RID_PARA_DIRECTFORMAT);
457 
458  uno::Reference<text::XTextRange> xRange(
459  SwXTextRange::CreateXTextRange(*pDoc, *pCursor->GetPoint(), nullptr));
460  uno::Reference<beans::XPropertySet> xPropertiesSet(xRange, uno::UNO_QUERY_THROW);
461  std::unordered_map<OUString, bool> aIsDefined;
462 
463  const std::vector<OUString> aHiddenProperties{ UNO_NAME_RSID,
474 
475  InsertValues(xRange, aIsDefined, aCharDFNode, false, aHiddenProperties);
476 
477  uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(pDocSh->GetBaseModel(),
478  uno::UNO_QUERY);
479  uno::Reference<container::XNameAccess> xStyleFamilies
480  = xStyleFamiliesSupplier->getStyleFamilies();
481  OUString sCurrentCharStyle, sCurrentParaStyle, sDisplayName;
482 
483  uno::Reference<container::XNameAccess> xStyleFamily(
484  xStyleFamilies->getByName("CharacterStyles"), uno::UNO_QUERY_THROW);
485  xPropertiesSet->getPropertyValue("CharStyleName") >>= sCurrentCharStyle;
486  xPropertiesSet->getPropertyValue("ParaStyleName") >>= sCurrentParaStyle;
487 
488  if (!sCurrentCharStyle.isEmpty())
489  {
490  xPropertiesSet.set(xStyleFamily->getByName(sCurrentCharStyle), css::uno::UNO_QUERY_THROW);
491  xPropertiesSet->getPropertyValue("DisplayName") >>= sDisplayName;
492  svx::sidebar::TreeNode aCurrentChild;
493  aCurrentChild.sNodeName = sDisplayName;
495 
496  InsertValues(xPropertiesSet, aIsDefined, aCurrentChild, false, {});
497 
498  aCharNode.children.push_back(aCurrentChild);
499  }
500 
501  // Collect paragraph direct formatting
502  uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xRange, uno::UNO_QUERY_THROW);
503  uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration();
504  uno::Reference<text::XTextRange> xThisParagraphRange(xParaEnum->nextElement(), uno::UNO_QUERY);
505  if (xThisParagraphRange.is())
506  InsertValues(xThisParagraphRange, aIsDefined, aParaDFNode, false, aHiddenProperties);
507 
508  xStyleFamily.set(xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY_THROW);
509 
510  while (!sCurrentParaStyle.isEmpty())
511  {
512  uno::Reference<style::XStyle> xPropertiesStyle(xStyleFamily->getByName(sCurrentParaStyle),
513  uno::UNO_QUERY_THROW);
514  xPropertiesSet.set(xPropertiesStyle, css::uno::UNO_QUERY_THROW);
515  xPropertiesSet->getPropertyValue("DisplayName") >>= sDisplayName;
516  OUString aParentParaStyle = xPropertiesStyle->getParentStyle();
517  svx::sidebar::TreeNode aCurrentChild;
518  aCurrentChild.sNodeName = sDisplayName;
520 
521  InsertValues(xPropertiesSet, aIsDefined, aCurrentChild, aParentParaStyle.isEmpty(), {});
522 
523  aParaNode.children.push_back(aCurrentChild);
524  sCurrentParaStyle = aParentParaStyle;
525  }
526 
527  std::reverse(aParaNode.children.begin(),
528  aParaNode.children.end()); // Parent style should be first then children
529 
530  /*
531  Display Order :-
532  PARAGRAPH STYLE
533  PARAGRAPH DIRECT FORMATTING
534  CHARACTER STYLE
535  DIRECT FORMATTING
536  */
537  aStore.push_back(aParaNode);
538  aStore.push_back(aParaDFNode);
539  aStore.push_back(aCharNode);
540  aStore.push_back(aCharDFNode);
541 }
542 
543 IMPL_LINK(WriterInspectorTextPanel, AttrChangedNotify, LinkParamNone*, pLink, void)
544 {
545  if (m_oldLink.IsSet())
546  m_oldLink.Call(pLink);
547 
548  SwDocShell* pDocSh = m_pShell->GetDoc()->GetDocShell();
549  std::vector<svx::sidebar::TreeNode> aStore;
550 
551  if (pDocSh && pDocSh->GetDoc()->GetEditShell()->GetCursor()->GetNode().GetTextNode())
552  UpdateTree(pDocSh, aStore);
553 
554  updateEntries(aStore);
555 }
556 
557 } // end of namespace svx::sidebar
558 
559 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
#define UNO_NAME_RSID
Definition: unoprnms.hxx:817
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:194
static const AllSettings & GetSettings()
#define UNO_NAME_PARA_STYLE_NAME
Definition: unoprnms.hxx:171
constexpr OUStringLiteral UNO_NAME_CHAR_STYLE_NAME
Definition: doc.hxx:186
IMPL_LINK(PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button &, rButton, void)
static SfxObjectShell * Current()
#define UNO_NAME_PARA_CONDITIONAL_STYLE_NAME
Definition: unoprnms.hxx:462
static void InsertValues(const css::uno::Reference< css::uno::XInterface > &rSource, std::unordered_map< OUString, bool > &rIsDefined, svx::sidebar::TreeNode &rNode, const bool &isRoot, const std::vector< OUString > &rHiddenProperty)
PropertiesInfo aProperties
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame)
static svx::sidebar::TreeNode BorderToTreeNode(const OUString &rName, const css::uno::Any &rVal)
css::uno::Reference< css::frame::XModel > GetBaseModel() const
enum svx::sidebar::TreeNode::@3 NodeType
static svx::sidebar::TreeNode LocaleToTreeNode(const OUString &rName, const css::uno::Any &rVal)
void SetChgLnk(const Link< LinkParamNone *, void > &rLnk)
Definition: crsrsh.hxx:483
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
css::uno::Any aValue
const SwPosition * GetPoint() const
Definition: pam.hxx:207
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
SwWrtShell * GetWrtShell()
Access to the SwWrtShell belonging to SwView.
Definition: docsh.hxx:224
static svx::sidebar::TreeNode SimplePropToTreeNode(const OUString &rName, const css::uno::Any &rVal)
WriterInspectorTextPanel(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:166
Shell * m_pShell
void updateEntries(const std::vector< TreeNode > &rStore)
#define UNO_NAME_NUMBERING_START_VALUE
Definition: unoprnms.hxx:147
static svx::sidebar::TreeNode PropertyToTreeNode(const css::beans::Property &rProperty, const uno::Reference< beans::XPropertySet > &xPropertiesSet, const bool &rIsGrey)
std::vector< TreeNode > children
const Link< LinkParamNone *, void > & GetChgLnk() const
Definition: crsrsh.hxx:484
#define UNO_NAME_PARA_CONTINUEING_PREVIOUS_SUB_TREE
Definition: unoprnms.hxx:801
#define UNO_NAME_PARRSID
Definition: unoprnms.hxx:818
const LanguageTag & getLocale()
#define UNO_NAME_NUMBERING_IS_NUMBER
Definition: unoprnms.hxx:148
SvBaseLink * pLink
static OUString PropertyNametoRID(const OUString &rName)
#define UNO_NAME_PARA_IS_NUMBERING_RESTART
Definition: unoprnms.hxx:487
static VclPtr< reference_type > Create(Arg &&...arg)
Reference< XComponentContext > getProcessComponentContext()
static void UpdateTree(SwDocShell *pDocSh, std::vector< svx::sidebar::TreeNode > &aStore)
sal_Int32 compare(const OUString &rLHS, const OUString &rRHS) const
static css::uno::Reference< css::text::XTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1203
#define UNO_NAME_NUMBERING_LEVEL
#define UNO_NAME_PAGE_STYLE_NAME
Definition: unoprnms.hxx:167
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:846
OUString sDisplayName