1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <uielement/statusbarmerger.hxx>
using rtl::OUString;
using com::sun::star::frame::XFrame;
using com::sun::star::uno::Reference;
using com::sun::star::beans::PropertyValue;
using com::sun::star::uno::Sequence;
namespace framework
{
namespace {
static const char MERGE_STATUSBAR_URL[] = "URL";
static const char MERGE_STATUSBAR_TITLE[] = "Title";
static const char MERGE_STATUSBAR_CONTEXT[] = "Context";
static const char MERGE_STATUSBAR_ALIGN[] = "Alignment";
static const char MERGE_STATUSBAR_AUTOSIZE[] = "AutoSize";
static const char MERGE_STATUSBAR_OWNERDRAW[] = "OwnerDraw";
static const char MERGE_STATUSBAR_WIDTH[] = "Width";
static const char STATUSBAR_ALIGN_LEFT[] = "left";
static const char STATUSBAR_ALIGN_CENTER[] = "center";
static const char STATUSBAR_ALIGN_RIGHT[] = "right";
static const char MERGECOMMAND_ADDAFTER[] = "AddAfter";
static const char MERGECOMMAND_ADDBEFORE[] = "AddBefore";
static const char MERGECOMMAND_REPLACE[] = "Replace";
static const char MERGECOMMAND_REMOVE[] = "Remove";
static const char MERGEFALLBACK_ADDLAST[] = "AddLast";
static const char MERGEFALLBACK_ADDFIRST[] = "AddFirst";
static const char MERGEFALLBACK_IGNORE[] = "Ignore";
static void lcl_ConvertSequenceToValues(
const Sequence< PropertyValue > &rSequence,
AddonStatusbarItem &rItem )
{
OUString sAlignment;
sal_Bool bAutoSize = sal_False;
sal_Bool bOwnerDraw = sal_False;
PropertyValue aPropVal;
for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
{
aPropVal = rSequence[i];
if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_URL ) ) )
aPropVal.Value >>= rItem.aCommandURL;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_TITLE ) ) )
aPropVal.Value >>= rItem.aLabel;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_CONTEXT ) ) )
aPropVal.Value >>= rItem.aContext;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_ALIGN ) ) )
aPropVal.Value >>= sAlignment;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_AUTOSIZE ) ) )
aPropVal.Value >>= bAutoSize;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_OWNERDRAW ) ) )
aPropVal.Value >>= bOwnerDraw;
else if ( aPropVal.Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGE_STATUSBAR_WIDTH ) ) )
{
sal_Int32 aWidth = 0;
aPropVal.Value >>= aWidth;
rItem.nWidth = sal_uInt16( aWidth );
}
}
sal_uInt16 nItemBits(0);
if ( bAutoSize )
nItemBits |= SIB_AUTOSIZE;
if ( bOwnerDraw )
nItemBits |= SIB_USERDRAW;
if ( sAlignment.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STATUSBAR_ALIGN_CENTER )))
nItemBits |= SIB_CENTER;
else if ( sAlignment.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STATUSBAR_ALIGN_RIGHT )))
nItemBits |= SIB_RIGHT;
else
// if unset, defaults to left alignment
nItemBits |= SIB_LEFT;
rItem.nItemBits = nItemBits;
}
static void lcl_CreateStatusbarItem( StatusBar* pStatusbar,
sal_uInt16 nPos,
sal_uInt16 nItemId,
const AddonStatusbarItem& rAddonItem )
{
pStatusbar->InsertItem( nItemId,
rAddonItem.nWidth,
rAddonItem.nItemBits,
STATUSBAR_OFFSET,
nPos );
pStatusbar->SetItemCommand( nItemId, rAddonItem.aCommandURL );
pStatusbar->SetQuickHelpText( nItemId, rAddonItem.aLabel );
pStatusbar->SetAccessibleName( nItemId, rAddonItem.aLabel );
// add-on specific data
AddonStatusbarItemData *pUserData = new AddonStatusbarItemData;
pUserData->aLabel = rAddonItem.aLabel;
pUserData->nItemBits = rAddonItem.nItemBits;
pStatusbar->SetItemData( nItemId, pUserData );
}
static bool lcl_MergeItems( StatusBar* pStatusbar,
sal_uInt16 nPos,
sal_uInt16 nModIndex,
sal_uInt16& rItemId,
const ::rtl::OUString& rModuleIdentifier,
const AddonStatusbarItemContainer& rAddonItems )
{
const sal_uInt16 nSize( rAddonItems.size() );
for ( sal_Int32 i = 0; i < nSize; i++ )
{
const AddonStatusbarItem& rItem = rAddonItems[i];
if ( !StatusbarMerger::IsCorrectContext( rItem.aContext, rModuleIdentifier ) )
continue;
sal_uInt16 nInsPos = nPos + nModIndex + i;
if ( nInsPos > pStatusbar->GetItemCount() )
nInsPos = STATUSBAR_APPEND;
lcl_CreateStatusbarItem( pStatusbar, nInsPos, rItemId, rItem );
++rItemId;
}
return true;
}
static bool lcl_ReplaceItem( StatusBar* pStatusbar,
sal_uInt16 nPos,
sal_uInt16& rItemId,
const ::rtl::OUString& rModuleIdentifier,
const AddonStatusbarItemContainer& rAddonToolbarItems )
{
pStatusbar->RemoveItem( pStatusbar->GetItemId( nPos ) );
return lcl_MergeItems( pStatusbar, nPos, 0, rItemId, rModuleIdentifier, rAddonToolbarItems );
}
static bool lcl_RemoveItems( StatusBar* pStatusbar,
sal_uInt16 nPos,
const ::rtl::OUString& rMergeCommandParameter )
{
sal_Int32 nCount = rMergeCommandParameter.toInt32();
if ( nCount > 0 )
{
for ( sal_Int32 i = 0; i < nCount; i++ )
{
if ( nPos < pStatusbar->GetItemCount() )
pStatusbar->RemoveItem( nPos );
}
}
return true;
}
}
bool StatusbarMerger::IsCorrectContext(
const OUString& rContext,
const OUString& rModuleIdentifier )
{
return (( rContext.getLength() == 0 ) || ( rContext.indexOf( rModuleIdentifier ) >= 0 ));
}
bool StatusbarMerger::ConvertSeqSeqToVector(
const Sequence< Sequence< PropertyValue > > &rSequence,
AddonStatusbarItemContainer& rContainer )
{
for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
{
AddonStatusbarItem aStatusBarItem;
lcl_ConvertSequenceToValues( rSequence[i], aStatusBarItem );
rContainer.push_back( aStatusBarItem );
}
return true;
}
sal_uInt16 StatusbarMerger::FindReferencePos(
StatusBar* pStatusbar,
const OUString& rReferencePoint )
{
for ( sal_uInt16 nPos = 0; nPos < pStatusbar->GetItemCount(); nPos++ )
{
const ::rtl::OUString rCmd = pStatusbar->GetItemCommand( pStatusbar->GetItemId( nPos ) );
if ( rReferencePoint == rCmd )
return nPos;
}
return STATUSBAR_ITEM_NOTFOUND;
}
bool StatusbarMerger::ProcessMergeOperation(
StatusBar* pStatusbar,
sal_uInt16 nPos,
sal_uInt16& rItemId,
const ::rtl::OUString& rModuleIdentifier,
const ::rtl::OUString& rMergeCommand,
const ::rtl::OUString& rMergeCommandParameter,
const AddonStatusbarItemContainer& rItems )
{
if ( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_ADDAFTER ) ) )
return lcl_MergeItems( pStatusbar, nPos, 1, rItemId, rModuleIdentifier, rItems );
else if ( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_ADDBEFORE ) ) )
return lcl_MergeItems( pStatusbar, nPos, 0, rItemId, rModuleIdentifier, rItems );
else if ( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_REPLACE ) ) )
return lcl_ReplaceItem( pStatusbar, nPos, rItemId, rModuleIdentifier, rItems );
else if ( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_REMOVE ) ) )
return lcl_RemoveItems( pStatusbar, nPos, rMergeCommandParameter );
return false;
}
bool StatusbarMerger::ProcessMergeFallback(
StatusBar* pStatusbar,
sal_uInt16 /*nPos*/,
sal_uInt16& rItemId,
const ::rtl::OUString& rModuleIdentifier,
const ::rtl::OUString& rMergeCommand,
const ::rtl::OUString& rMergeFallback,
const AddonStatusbarItemContainer& rItems )
{
// fallback IGNORE or REPLACE/REMOVE item not found
if (( rMergeFallback.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGEFALLBACK_IGNORE ))) ||
( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_REPLACE ))) ||
( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_REMOVE ))) )
{
return true;
}
else if (( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_ADDBEFORE ))) ||
( rMergeCommand.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGECOMMAND_ADDAFTER ))) )
{
if ( rMergeFallback.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGEFALLBACK_ADDFIRST )))
return lcl_MergeItems( pStatusbar, 0, 0, rItemId, rModuleIdentifier, rItems );
else if ( rMergeFallback.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MERGEFALLBACK_ADDLAST )))
return lcl_MergeItems( pStatusbar, STATUSBAR_APPEND, 0, rItemId, rModuleIdentifier, rItems );
}
return false;
}
}
|