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 20 21 #ifndef INCLUDED_SVX_DESCRIPTIONGENERATOR_HXX 22 #define INCLUDED_SVX_DESCRIPTIONGENERATOR_HXX 23 24 #include <com/sun/star/uno/Reference.hxx> 25 #include <rtl/ustrbuf.hxx> 26 #include <svx/svxdllapi.h> 27 28 namespace com::sun::star::beans { class XPropertySet; } 29 namespace com::sun::star::drawing { class XShape; } 30 31 32 namespace accessibility { 33 34 /** This class creates description strings for shapes. 35 <p>Initialized with a given shape additional calls to the 36 <member>addProperty</member> method will build a descriptive string that 37 starts with a general shape description and the shapes style. Appended 38 are all the specified property names and values that differ from the 39 default values in the style.</p> 40 */ 41 class SVX_DLLPUBLIC DescriptionGenerator 42 { 43 public: 44 enum class PropertyType { 45 Color, 46 Integer 47 }; 48 49 /** Creates a new description generator with an empty description 50 string. Usually you will want to call initialize next to specify 51 a general description of the shape. 52 @param xShape 53 The shape from which properties will be extracted by later calls 54 to <member>addProperty</member>. 55 */ 56 DescriptionGenerator (const css::uno::Reference< 57 css::drawing::XShape>& xShape); 58 59 ~DescriptionGenerator(); 60 61 /** Initialize the description with the given prefix followed by the 62 shape style in parentheses and a colon. 63 @param sPrefix 64 An introductory description of the shape that is made more 65 specific by later calls to <member>addProperty</member>. 66 */ 67 void Initialize (const OUString& sPrefix); 68 69 /** Initialize the description with the specified string from the 70 resource followed by the shape style in parentheses and a colon. 71 @param pResourceId 72 A resource id the specifies the introductory description of the 73 shape that is made more specific by later calls to 74 <member>addProperty</member>. 75 */ 76 void Initialize(const char* pResourceId); 77 78 /** Returns the description string and then resets it. Usually called 79 as last method before destroying the object. 80 @return 81 The description string in its current form. 82 */ 83 OUString operator() (void); 84 85 /** Add the given property name and its associated value to the 86 description string. If the property value does not differ from the 87 default value of the shape's style then the description string is 88 not modified. 89 @param sPropertyName 90 The Name of the property to append. 91 @param aType 92 Type of the property's value. It controls the transformation 93 into the value's string representation. 94 @param sLocalizedName 95 Localized name of the property. An empty string tells the 96 method to use the property name instead. 97 */ 98 void AddProperty (const OUString& sPropertyName, 99 PropertyType aType); 100 101 /** Append the given string as is to the current description. 102 @param sString 103 String to append to the current description. It is not modified 104 in any way. 105 */ 106 void AppendString (const OUString& sString); 107 108 private: 109 /// Reference to the shape from which the properties are extracted. 110 css::uno::Reference< css::drawing::XShape> mxShape; 111 112 /// Reference to the shape's property set. 113 css::uno::Reference< css::beans::XPropertySet> mxSet; 114 115 /// The description string that is build. 116 OUStringBuffer msDescription; 117 118 /** This flag is used to determine whether to insert a separator e.g. a 119 comma before the next property. 120 */ 121 bool mbIsFirstProperty; 122 123 /** Add a property value formatted as color to the description string. 124 */ 125 SVX_DLLPRIVATE void AddColor (const OUString& sPropertyName, 126 const OUString& sLocalizedName); 127 128 /** Add a property value formatted as integer to the description string. 129 */ 130 SVX_DLLPRIVATE void AddInteger (const OUString& sPropertyName, 131 const OUString& sLocalizedName); 132 }; 133 134 135 } // end of namespace accessibility 136 137 138 #endif 139 140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 141