/src/libreoffice/sw/source/uibase/config/barcfg.cxx
Line | Count | Source |
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 | | #include <osl/diagnose.h> |
21 | | #include <com/sun/star/uno/Sequence.hxx> |
22 | | #include <wrtsh.hxx> |
23 | | #include <barcfg.hxx> |
24 | | |
25 | | using namespace utl; |
26 | | using namespace com::sun::star::uno; |
27 | | |
28 | 0 | #define SEL_TYPE_TABLE_TEXT 0 |
29 | 2 | #define SEL_TYPE_LIST_TEXT 1 |
30 | 0 | #define SEL_TYPE_TABLE_LIST 2 |
31 | 0 | #define SEL_TYPE_BEZIER 3 |
32 | 108 | #define SEL_TYPE_GRAPHIC 4 |
33 | | |
34 | | SwToolbarConfigItem::SwToolbarConfigItem( bool bWeb ) : |
35 | 18 | ConfigItem(bWeb ? u"Office.WriterWeb/ObjectBar"_ustr : u"Office.Writer/ObjectBar"_ustr, |
36 | 18 | ConfigItemMode::ReleaseTree) |
37 | 18 | { |
38 | 108 | for(int i = 0; i <= SEL_TYPE_GRAPHIC; ++i) |
39 | 90 | m_aTbxIdArray[i] = -1; |
40 | | |
41 | 18 | Sequence<OUString> aNames = GetPropertyNames(); |
42 | 18 | Sequence<Any> aValues = GetProperties(aNames); |
43 | 18 | const Any* pValues = aValues.getConstArray(); |
44 | 18 | OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed"); |
45 | 18 | if(aValues.getLength() == aNames.getLength()) |
46 | 18 | { |
47 | 108 | for(int nProp = 0; nProp < aNames.getLength(); nProp++) |
48 | 90 | { |
49 | 90 | if(pValues[nProp].hasValue()) |
50 | 0 | { |
51 | 0 | sal_Int32 nVal = 0; |
52 | 0 | pValues[nProp] >>= nVal; |
53 | 0 | m_aTbxIdArray[nProp] = nVal; |
54 | 0 | } |
55 | 90 | } |
56 | 18 | } |
57 | 18 | } |
58 | | |
59 | | SwToolbarConfigItem::~SwToolbarConfigItem() |
60 | 0 | { |
61 | 0 | } |
62 | | |
63 | | static sal_Int32 lcl_getArrayIndex(SelectionType nSelType) |
64 | 4 | { |
65 | 4 | sal_Int32 nRet = -1; |
66 | 4 | if(nSelType & SelectionType::NumberList) |
67 | 2 | { |
68 | 2 | if(nSelType & SelectionType::Table) |
69 | 0 | nRet = SEL_TYPE_TABLE_LIST; |
70 | 2 | else |
71 | 2 | nRet = SEL_TYPE_LIST_TEXT; |
72 | 2 | } |
73 | 2 | else if(nSelType & SelectionType::Table) |
74 | 0 | nRet = SEL_TYPE_TABLE_TEXT; |
75 | 2 | else if(nSelType & SelectionType::Ornament) |
76 | 0 | nRet = SEL_TYPE_BEZIER; |
77 | 2 | else if(nSelType & SelectionType::Graphic) |
78 | 0 | nRet = SEL_TYPE_GRAPHIC; |
79 | 4 | return nRet; |
80 | 4 | } |
81 | | |
82 | | void SwToolbarConfigItem::SetTopToolbar(SelectionType nSelType, ToolbarId eBarId) |
83 | 4 | { |
84 | 4 | sal_Int32 nProp = lcl_getArrayIndex(nSelType); |
85 | 4 | if(nProp >= 0) |
86 | 2 | { |
87 | 2 | m_aTbxIdArray[nProp] = static_cast<sal_Int32>(eBarId); |
88 | 2 | SetModified(); |
89 | 2 | } |
90 | 4 | } |
91 | | |
92 | | Sequence<OUString> SwToolbarConfigItem::GetPropertyNames() |
93 | 18 | { |
94 | 18 | static constexpr OUString aPropNames[] = |
95 | 18 | { |
96 | 18 | u"Selection/Table"_ustr, // SEL_TYPE_TABLE_TEXT |
97 | 18 | u"Selection/NumberedList"_ustr, // SEL_TYPE_LIST_TEXT |
98 | 18 | u"Selection/NumberedList_InTable"_ustr, // SEL_TYPE_TABLE_LIST |
99 | 18 | u"Selection/BezierObject"_ustr, // SEL_TYPE_BEZIER |
100 | 18 | u"Selection/Graphic"_ustr //SEL_TYPE_GRAPHIC |
101 | 18 | }; |
102 | 18 | const int nCount = 5; |
103 | 18 | Sequence<OUString> aNames(nCount); |
104 | 18 | OUString* pNames = aNames.getArray(); |
105 | 108 | for(int i = 0; i < nCount; i++) |
106 | 90 | pNames[i] = aPropNames[i]; |
107 | 18 | return aNames; |
108 | 18 | } |
109 | | |
110 | | void SwToolbarConfigItem::ImplCommit() |
111 | 0 | { |
112 | 0 | Sequence<OUString> aNames = GetPropertyNames(); |
113 | |
|
114 | 0 | Sequence<Any> aValues(aNames.getLength()); |
115 | 0 | Any* pValues = aValues.getArray(); |
116 | |
|
117 | 0 | for(int nProp = 0; nProp < aNames.getLength(); nProp++) |
118 | 0 | pValues[nProp] <<= m_aTbxIdArray[nProp]; |
119 | 0 | PutProperties(aNames, aValues); |
120 | 0 | } |
121 | | |
122 | 0 | void SwToolbarConfigItem::Notify( const css::uno::Sequence< OUString >& ) {} |
123 | | |
124 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |