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 #include "precompiled_sfx2.hxx" 23 24 #include "ContextList.hxx" 25 #include "Context.hxx" 26 27 using ::rtl::OUString; 28 29 namespace sfx2 { namespace sidebar { 30 31 32 ContextList::ContextList (void) 33 : maEntries() 34 { 35 } 36 37 38 39 40 ContextList::~ContextList (void) 41 { 42 } 43 44 45 46 47 const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const 48 { 49 const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext); 50 if (iEntry != maEntries.end()) 51 return &*iEntry; 52 else 53 return NULL; 54 } 55 56 57 58 59 ::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const 60 { 61 sal_Int32 nBestMatch (Context::NoMatch); 62 ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end()); 63 64 for (::std::vector<Entry>::const_iterator 65 iEntry(maEntries.begin()), 66 iEnd(maEntries.end()); 67 iEntry!=iEnd; 68 ++iEntry) 69 { 70 const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext)); 71 if (nMatch < nBestMatch) 72 { 73 nBestMatch = nMatch; 74 iBestMatch = iEntry; 75 } 76 if (nBestMatch == Context::OptimalMatch) 77 return iEntry; 78 } 79 80 return iBestMatch; 81 } 82 83 84 85 86 void ContextList::AddContextDescription ( 87 const Context& rContext, 88 const bool bIsInitiallyVisible, 89 const OUString& rsMenuCommand) 90 { 91 maEntries.push_back(Entry()); 92 maEntries.back().maContext = rContext; 93 maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible; 94 maEntries.back().msMenuCommand = rsMenuCommand; 95 } 96 97 98 99 100 bool ContextList::IsEmpty (void) 101 { 102 return maEntries.empty(); 103 } 104 105 106 } } // end of namespace sfx2::sidebar 107