1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: barcfg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <tools/debug.hxx>
36 #include <com/sun/star/uno/Any.hxx>
37 #include <com/sun/star/uno/Sequence.hxx>
45 using namespace com::sun::star::uno
;
47 #define SEL_TYPE_TABLE_TEXT 0
48 #define SEL_TYPE_LIST_TEXT 1
49 #define SEL_TYPE_TABLE_LIST 2
50 #define SEL_TYPE_BEZIER 3
51 #define SEL_TYPE_GRAPHIC 4
53 /* ---------------------------------------------------------------------------
55 ---------------------------------------------------------------------------*/
56 SwToolbarConfigItem::SwToolbarConfigItem( BOOL bWeb
) :
57 ConfigItem(bWeb
? C2U("Office.WriterWeb/ObjectBar") : C2U("Office.Writer/ObjectBar"),
58 CONFIG_MODE_DELAYED_UPDATE
|CONFIG_MODE_RELEASE_TREE
)
60 for(USHORT i
= 0; i
<= SEL_TYPE_GRAPHIC
; i
++ )
63 Sequence
<OUString
> aNames
= GetPropertyNames();
64 Sequence
<Any
> aValues
= GetProperties(aNames
);
65 const Any
* pValues
= aValues
.getConstArray();
66 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
67 if(aValues
.getLength() == aNames
.getLength())
69 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
71 if(pValues
[nProp
].hasValue())
74 pValues
[nProp
] >>= nVal
;
75 aTbxIdArray
[nProp
] = nVal
;
80 /* ---------------------------------------------------------------------------
82 ---------------------------------------------------------------------------*/
83 SwToolbarConfigItem::~SwToolbarConfigItem()
86 /* ---------------------------------------------------------------------------
88 ---------------------------------------------------------------------------*/
89 sal_Int32
lcl_getArrayIndex(int nSelType
)
92 if(nSelType
& nsSelectionType::SEL_NUM
)
94 if(nSelType
& nsSelectionType::SEL_TBL
)
95 nRet
= SEL_TYPE_TABLE_LIST
;
97 nRet
= SEL_TYPE_LIST_TEXT
;
99 else if(nSelType
& nsSelectionType::SEL_TBL
)
100 nRet
= SEL_TYPE_TABLE_TEXT
;
101 else if(nSelType
& nsSelectionType::SEL_BEZ
)
102 nRet
= SEL_TYPE_BEZIER
;
103 else if(nSelType
& nsSelectionType::SEL_GRF
)
104 nRet
= SEL_TYPE_GRAPHIC
;
107 /* -----------------------------10.10.00 14:38--------------------------------
109 ---------------------------------------------------------------------------*/
110 void SwToolbarConfigItem::SetTopToolbar( sal_Int32 nSelType
, sal_Int32 nBarId
)
112 sal_Int32 nProp
= lcl_getArrayIndex(nSelType
);
115 aTbxIdArray
[nProp
] = nBarId
;
119 /* -----------------------------10.10.00 13:33--------------------------------
121 ---------------------------------------------------------------------------*/
122 Sequence
<OUString
> SwToolbarConfigItem::GetPropertyNames()
124 static const char* aPropNames
[] =
126 "Selection/Table", // SEL_TYPE_TABLE_TEXT
127 "Selection/NumberedList", // SEL_TYPE_LIST_TEXT
128 "Selection/NumberedList_InTable", // SEL_TYPE_TABLE_LIST
129 "Selection/BezierObject", // SEL_TYPE_BEZIER
130 "Selection/Graphic" //SEL_TYPE_GRAPHIC
132 const int nCount
= 5;
133 Sequence
<OUString
> aNames(nCount
);
134 OUString
* pNames
= aNames
.getArray();
135 for(int i
= 0; i
< nCount
; i
++)
136 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
139 /* -----------------------------10.10.00 13:36--------------------------------
141 ---------------------------------------------------------------------------*/
142 void SwToolbarConfigItem::Commit()
144 Sequence
<OUString
> aNames
= GetPropertyNames();
146 Sequence
<Any
> aValues(aNames
.getLength());
147 Any
* pValues
= aValues
.getArray();
149 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
150 pValues
[nProp
] <<= aTbxIdArray
[nProp
];
151 PutProperties(aNames
, aValues
);