fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / statusbarmerger.cxx
blob6946e9ac6be2b7ec3b471ac4d477b5c3c5d96444
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <uielement/statusbarmerger.hxx>
21 using rtl::OUString;
22 using com::sun::star::frame::XFrame;
23 using com::sun::star::uno::Reference;
24 using com::sun::star::beans::PropertyValue;
25 using com::sun::star::uno::Sequence;
27 namespace framework
29 namespace {
31 static const char MERGE_STATUSBAR_URL[] = "URL";
32 static const char MERGE_STATUSBAR_TITLE[] = "Title";
33 static const char MERGE_STATUSBAR_CONTEXT[] = "Context";
34 static const char MERGE_STATUSBAR_ALIGN[] = "Alignment";
35 static const char MERGE_STATUSBAR_AUTOSIZE[] = "AutoSize";
36 static const char MERGE_STATUSBAR_OWNERDRAW[] = "OwnerDraw";
37 static const char MERGE_STATUSBAR_WIDTH[] = "Width";
39 static const char STATUSBAR_ALIGN_CENTER[] = "center";
40 static const char STATUSBAR_ALIGN_RIGHT[] = "right";
42 static const char MERGECOMMAND_ADDAFTER[] = "AddAfter";
43 static const char MERGECOMMAND_ADDBEFORE[] = "AddBefore";
44 static const char MERGECOMMAND_REPLACE[] = "Replace";
45 static const char MERGECOMMAND_REMOVE[] = "Remove";
47 static const char MERGEFALLBACK_ADDLAST[] = "AddLast";
48 static const char MERGEFALLBACK_ADDFIRST[] = "AddFirst";
49 static const char MERGEFALLBACK_IGNORE[] = "Ignore";
51 static void lcl_ConvertSequenceToValues(
52 const Sequence< PropertyValue > &rSequence,
53 AddonStatusbarItem &rItem )
55 OUString sAlignment;
56 bool bAutoSize = false;
57 bool bOwnerDraw = false;
59 PropertyValue aPropVal;
60 for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
62 aPropVal = rSequence[i];
63 if ( aPropVal.Name == MERGE_STATUSBAR_URL )
64 aPropVal.Value >>= rItem.aCommandURL;
65 else if ( aPropVal.Name == MERGE_STATUSBAR_TITLE )
66 aPropVal.Value >>= rItem.aLabel;
67 else if ( aPropVal.Name == MERGE_STATUSBAR_CONTEXT )
68 aPropVal.Value >>= rItem.aContext;
69 else if ( aPropVal.Name == MERGE_STATUSBAR_ALIGN )
70 aPropVal.Value >>= sAlignment;
71 else if ( aPropVal.Name == MERGE_STATUSBAR_AUTOSIZE )
72 aPropVal.Value >>= bAutoSize;
73 else if ( aPropVal.Name == MERGE_STATUSBAR_OWNERDRAW )
74 aPropVal.Value >>= bOwnerDraw;
75 else if ( aPropVal.Name == MERGE_STATUSBAR_WIDTH )
77 sal_Int32 aWidth = 0;
78 aPropVal.Value >>= aWidth;
79 rItem.nWidth = sal_uInt16( aWidth );
83 sal_uInt16 nItemBits(0);
84 if ( bAutoSize )
85 nItemBits |= SIB_AUTOSIZE;
86 if ( bOwnerDraw )
87 nItemBits |= SIB_USERDRAW;
88 if ( sAlignment == STATUSBAR_ALIGN_CENTER )
89 nItemBits |= SIB_CENTER;
90 else if ( sAlignment == STATUSBAR_ALIGN_RIGHT )
91 nItemBits |= SIB_RIGHT;
92 else
93 // if unset, defaults to left alignment
94 nItemBits |= SIB_LEFT;
95 rItem.nItemBits = nItemBits;
98 static void lcl_CreateStatusbarItem( StatusBar* pStatusbar,
99 sal_uInt16 nPos,
100 sal_uInt16 nItemId,
101 const AddonStatusbarItem& rAddonItem )
103 pStatusbar->InsertItem( nItemId,
104 rAddonItem.nWidth,
105 rAddonItem.nItemBits,
106 STATUSBAR_OFFSET,
107 nPos );
108 pStatusbar->SetItemCommand( nItemId, rAddonItem.aCommandURL );
109 pStatusbar->SetQuickHelpText( nItemId, rAddonItem.aLabel );
110 pStatusbar->SetAccessibleName( nItemId, rAddonItem.aLabel );
112 // add-on specific data
113 AddonStatusbarItemData *pUserData = new AddonStatusbarItemData;
114 pUserData->aLabel = rAddonItem.aLabel;
115 pUserData->nItemBits = rAddonItem.nItemBits;
116 pStatusbar->SetItemData( nItemId, pUserData );
119 static bool lcl_MergeItems( StatusBar* pStatusbar,
120 sal_uInt16 nPos,
121 sal_uInt16 nModIndex,
122 sal_uInt16& rItemId,
123 const ::rtl::OUString& rModuleIdentifier,
124 const AddonStatusbarItemContainer& rAddonItems )
126 const sal_uInt16 nSize( rAddonItems.size() );
127 for ( sal_Int32 i = 0; i < nSize; i++ )
129 const AddonStatusbarItem& rItem = rAddonItems[i];
130 if ( !StatusbarMerger::IsCorrectContext( rItem.aContext, rModuleIdentifier ) )
131 continue;
133 sal_uInt16 nInsPos = nPos + nModIndex + i;
134 if ( nInsPos > pStatusbar->GetItemCount() )
135 nInsPos = STATUSBAR_APPEND;
137 lcl_CreateStatusbarItem( pStatusbar, nInsPos, rItemId, rItem );
138 ++rItemId;
141 return true;
144 static bool lcl_ReplaceItem( StatusBar* pStatusbar,
145 sal_uInt16 nPos,
146 sal_uInt16& rItemId,
147 const ::rtl::OUString& rModuleIdentifier,
148 const AddonStatusbarItemContainer& rAddonToolbarItems )
150 pStatusbar->RemoveItem( pStatusbar->GetItemId( nPos ) );
151 return lcl_MergeItems( pStatusbar, nPos, 0, rItemId, rModuleIdentifier, rAddonToolbarItems );
154 static bool lcl_RemoveItems( StatusBar* pStatusbar,
155 sal_uInt16 nPos,
156 const ::rtl::OUString& rMergeCommandParameter )
158 sal_Int32 nCount = rMergeCommandParameter.toInt32();
159 if ( nCount > 0 )
161 for ( sal_Int32 i = 0; i < nCount; i++ )
163 if ( nPos < pStatusbar->GetItemCount() )
164 pStatusbar->RemoveItem( nPos );
167 return true;
172 bool StatusbarMerger::IsCorrectContext(
173 const OUString& rContext,
174 const OUString& rModuleIdentifier )
176 return (( rContext.getLength() == 0 ) || ( rContext.indexOf( rModuleIdentifier ) >= 0 ));
179 bool StatusbarMerger::ConvertSeqSeqToVector(
180 const Sequence< Sequence< PropertyValue > > &rSequence,
181 AddonStatusbarItemContainer& rContainer )
183 for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ )
185 AddonStatusbarItem aStatusBarItem;
186 lcl_ConvertSequenceToValues( rSequence[i], aStatusBarItem );
187 rContainer.push_back( aStatusBarItem );
190 return true;
193 sal_uInt16 StatusbarMerger::FindReferencePos(
194 StatusBar* pStatusbar,
195 const OUString& rReferencePoint )
197 for ( sal_uInt16 nPos = 0; nPos < pStatusbar->GetItemCount(); nPos++ )
199 const ::rtl::OUString rCmd = pStatusbar->GetItemCommand( pStatusbar->GetItemId( nPos ) );
200 if ( rReferencePoint == rCmd )
201 return nPos;
204 return STATUSBAR_ITEM_NOTFOUND;
207 bool StatusbarMerger::ProcessMergeOperation(
208 StatusBar* pStatusbar,
209 sal_uInt16 nPos,
210 sal_uInt16& rItemId,
211 const ::rtl::OUString& rModuleIdentifier,
212 const ::rtl::OUString& rMergeCommand,
213 const ::rtl::OUString& rMergeCommandParameter,
214 const AddonStatusbarItemContainer& rItems )
216 if ( rMergeCommand == MERGECOMMAND_ADDAFTER )
217 return lcl_MergeItems( pStatusbar, nPos, 1, rItemId, rModuleIdentifier, rItems );
218 else if ( rMergeCommand == MERGECOMMAND_ADDBEFORE )
219 return lcl_MergeItems( pStatusbar, nPos, 0, rItemId, rModuleIdentifier, rItems );
220 else if ( rMergeCommand == MERGECOMMAND_REPLACE )
221 return lcl_ReplaceItem( pStatusbar, nPos, rItemId, rModuleIdentifier, rItems );
222 else if ( rMergeCommand == MERGECOMMAND_REMOVE )
223 return lcl_RemoveItems( pStatusbar, nPos, rMergeCommandParameter );
225 return false;
228 bool StatusbarMerger::ProcessMergeFallback(
229 StatusBar* pStatusbar,
230 sal_uInt16 /*nPos*/,
231 sal_uInt16& rItemId,
232 const ::rtl::OUString& rModuleIdentifier,
233 const ::rtl::OUString& rMergeCommand,
234 const ::rtl::OUString& rMergeFallback,
235 const AddonStatusbarItemContainer& rItems )
237 // fallback IGNORE or REPLACE/REMOVE item not found
238 if (( rMergeFallback == MERGEFALLBACK_IGNORE ) ||
239 ( rMergeCommand == MERGECOMMAND_REPLACE ) ||
240 ( rMergeCommand == MERGECOMMAND_REMOVE ) )
242 return true;
244 else if (( rMergeCommand == MERGECOMMAND_ADDBEFORE ) ||
245 ( rMergeCommand == MERGECOMMAND_ADDAFTER ) )
247 if ( rMergeFallback == MERGEFALLBACK_ADDFIRST )
248 return lcl_MergeItems( pStatusbar, 0, 0, rItemId, rModuleIdentifier, rItems );
249 else if ( rMergeFallback == MERGEFALLBACK_ADDLAST )
250 return lcl_MergeItems( pStatusbar, STATUSBAR_APPEND, 0, rItemId, rModuleIdentifier, rItems );
253 return false;
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */