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