1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27
28 #include <tools/debug.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <wrtsh.hxx>
32 #include "barcfg.hxx"
33
34 #include <unomid.h>
35
36 using namespace utl;
37 using rtl::OUString;
38 using namespace com::sun::star::uno;
39
40 #define SEL_TYPE_TABLE_TEXT 0
41 #define SEL_TYPE_LIST_TEXT 1
42 #define SEL_TYPE_TABLE_LIST 2
43 #define SEL_TYPE_BEZIER 3
44 #define SEL_TYPE_GRAPHIC 4
45
46 /* ---------------------------------------------------------------------------
47
48 ---------------------------------------------------------------------------*/
SwToolbarConfigItem(sal_Bool bWeb)49 SwToolbarConfigItem::SwToolbarConfigItem( sal_Bool bWeb ) :
50 ConfigItem(bWeb ? C2U("Office.WriterWeb/ObjectBar") : C2U("Office.Writer/ObjectBar"),
51 CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE)
52 {
53 for(sal_uInt16 i = 0; i <= SEL_TYPE_GRAPHIC; i++ )
54 aTbxIdArray[i] = -1;
55
56 Sequence<OUString> aNames = GetPropertyNames();
57 Sequence<Any> aValues = GetProperties(aNames);
58 const Any* pValues = aValues.getConstArray();
59 DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
60 if(aValues.getLength() == aNames.getLength())
61 {
62 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
63 {
64 if(pValues[nProp].hasValue())
65 {
66 sal_Int32 nVal = 0;
67 pValues[nProp] >>= nVal;
68 aTbxIdArray[nProp] = nVal;
69 }
70 }
71 }
72 }
73 /* ---------------------------------------------------------------------------
74
75 ---------------------------------------------------------------------------*/
~SwToolbarConfigItem()76 SwToolbarConfigItem::~SwToolbarConfigItem()
77 {
78 }
79 /* ---------------------------------------------------------------------------
80
81 ---------------------------------------------------------------------------*/
lcl_getArrayIndex(int nSelType)82 sal_Int32 lcl_getArrayIndex(int nSelType)
83 {
84 sal_Int32 nRet = -1;
85 if(nSelType & nsSelectionType::SEL_NUM)
86 {
87 if(nSelType & nsSelectionType::SEL_TBL)
88 nRet = SEL_TYPE_TABLE_LIST;
89 else
90 nRet = SEL_TYPE_LIST_TEXT;
91 }
92 else if(nSelType & nsSelectionType::SEL_TBL)
93 nRet = SEL_TYPE_TABLE_TEXT;
94 else if(nSelType & nsSelectionType::SEL_BEZ)
95 nRet = SEL_TYPE_BEZIER;
96 else if(nSelType & nsSelectionType::SEL_GRF)
97 nRet = SEL_TYPE_GRAPHIC;
98 return nRet;
99 }
100 /* -----------------------------10.10.00 14:38--------------------------------
101
102 ---------------------------------------------------------------------------*/
SetTopToolbar(sal_Int32 nSelType,sal_Int32 nBarId)103 void SwToolbarConfigItem::SetTopToolbar( sal_Int32 nSelType, sal_Int32 nBarId )
104 {
105 sal_Int32 nProp = lcl_getArrayIndex(nSelType);
106 if(nProp >= 0)
107 {
108 aTbxIdArray[nProp] = nBarId;
109 SetModified();
110 }
111 }
112 /* -----------------------------10.10.00 13:33--------------------------------
113
114 ---------------------------------------------------------------------------*/
GetPropertyNames()115 Sequence<OUString> SwToolbarConfigItem::GetPropertyNames()
116 {
117 static const char* aPropNames[] =
118 {
119 "Selection/Table", // SEL_TYPE_TABLE_TEXT
120 "Selection/NumberedList", // SEL_TYPE_LIST_TEXT
121 "Selection/NumberedList_InTable", // SEL_TYPE_TABLE_LIST
122 "Selection/BezierObject", // SEL_TYPE_BEZIER
123 "Selection/Graphic" //SEL_TYPE_GRAPHIC
124 };
125 const int nCount = 5;
126 Sequence<OUString> aNames(nCount);
127 OUString* pNames = aNames.getArray();
128 for(int i = 0; i < nCount; i++)
129 pNames[i] = OUString::createFromAscii(aPropNames[i]);
130 return aNames;
131 }
132 /* -----------------------------10.10.00 13:36--------------------------------
133
134 ---------------------------------------------------------------------------*/
Commit()135 void SwToolbarConfigItem::Commit()
136 {
137 Sequence<OUString> aNames = GetPropertyNames();
138
139 Sequence<Any> aValues(aNames.getLength());
140 Any* pValues = aValues.getArray();
141
142 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
143 pValues[nProp] <<= aTbxIdArray[nProp];
144 PutProperties(aNames, aValues);
145 }
146
Notify(const::com::sun::star::uno::Sequence<rtl::OUString> &)147 void SwToolbarConfigItem::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
148
149