1*5d39f272SZheng Fan /************************************************************** 2*5d39f272SZheng Fan * 3*5d39f272SZheng Fan * Licensed to the Apache Software Foundation (ASF) under one 4*5d39f272SZheng Fan * or more contributor license agreements. See the NOTICE file 5*5d39f272SZheng Fan * distributed with this work for additional information 6*5d39f272SZheng Fan * regarding copyright ownership. The ASF licenses this file 7*5d39f272SZheng Fan * to you under the Apache License, Version 2.0 (the 8*5d39f272SZheng Fan * "License"); you may not use this file except in compliance 9*5d39f272SZheng Fan * with the License. You may obtain a copy of the License at 10*5d39f272SZheng Fan * 11*5d39f272SZheng Fan * http://www.apache.org/licenses/LICENSE-2.0 12*5d39f272SZheng Fan * 13*5d39f272SZheng Fan * Unless required by applicable law or agreed to in writing, 14*5d39f272SZheng Fan * software distributed under the License is distributed on an 15*5d39f272SZheng Fan * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5d39f272SZheng Fan * KIND, either express or implied. See the License for the 17*5d39f272SZheng Fan * specific language governing permissions and limitations 18*5d39f272SZheng Fan * under the License. 19*5d39f272SZheng Fan * 20*5d39f272SZheng Fan *************************************************************/ 21*5d39f272SZheng Fan 22*5d39f272SZheng Fan #include "precompiled_sfx2.hxx" 23*5d39f272SZheng Fan 24*5d39f272SZheng Fan #include "ContextList.hxx" 25*5d39f272SZheng Fan #include "Context.hxx" 26*5d39f272SZheng Fan 27*5d39f272SZheng Fan using ::rtl::OUString; 28*5d39f272SZheng Fan 29*5d39f272SZheng Fan namespace sfx2 { namespace sidebar { 30*5d39f272SZheng Fan 31*5d39f272SZheng Fan namespace { 32*5d39f272SZheng Fan static const sal_Char* gsAny = "any"; 33*5d39f272SZheng Fan } 34*5d39f272SZheng Fan 35*5d39f272SZheng Fan 36*5d39f272SZheng Fan 37*5d39f272SZheng Fan ContextList::ContextList (void) 38*5d39f272SZheng Fan : maEntries() 39*5d39f272SZheng Fan { 40*5d39f272SZheng Fan } 41*5d39f272SZheng Fan 42*5d39f272SZheng Fan 43*5d39f272SZheng Fan 44*5d39f272SZheng Fan 45*5d39f272SZheng Fan ContextList::~ContextList (void) 46*5d39f272SZheng Fan { 47*5d39f272SZheng Fan } 48*5d39f272SZheng Fan 49*5d39f272SZheng Fan 50*5d39f272SZheng Fan 51*5d39f272SZheng Fan 52*5d39f272SZheng Fan const ContextList::Entry* ContextList::GetMatch (const Context& rContext) const 53*5d39f272SZheng Fan { 54*5d39f272SZheng Fan const ::std::vector<Entry>::const_iterator iEntry = FindBestMatch(rContext); 55*5d39f272SZheng Fan if (iEntry != maEntries.end()) 56*5d39f272SZheng Fan return &*iEntry; 57*5d39f272SZheng Fan else 58*5d39f272SZheng Fan return NULL; 59*5d39f272SZheng Fan } 60*5d39f272SZheng Fan 61*5d39f272SZheng Fan 62*5d39f272SZheng Fan 63*5d39f272SZheng Fan 64*5d39f272SZheng Fan ::std::vector<ContextList::Entry>::const_iterator ContextList::FindBestMatch (const Context& rContext) const 65*5d39f272SZheng Fan { 66*5d39f272SZheng Fan sal_Int32 nBestMatch (Context::NoMatch); 67*5d39f272SZheng Fan ::std::vector<Entry>::const_iterator iBestMatch (maEntries.end()); 68*5d39f272SZheng Fan 69*5d39f272SZheng Fan for (::std::vector<Entry>::const_iterator 70*5d39f272SZheng Fan iEntry(maEntries.begin()), 71*5d39f272SZheng Fan iEnd(maEntries.end()); 72*5d39f272SZheng Fan iEntry!=iEnd; 73*5d39f272SZheng Fan ++iEntry) 74*5d39f272SZheng Fan { 75*5d39f272SZheng Fan const sal_Int32 nMatch (rContext.EvaluateMatch(iEntry->maContext)); 76*5d39f272SZheng Fan if (nMatch < nBestMatch) 77*5d39f272SZheng Fan { 78*5d39f272SZheng Fan nBestMatch = nMatch; 79*5d39f272SZheng Fan iBestMatch = iEntry; 80*5d39f272SZheng Fan } 81*5d39f272SZheng Fan if (nBestMatch == Context::OptimalMatch) 82*5d39f272SZheng Fan return iEntry; 83*5d39f272SZheng Fan } 84*5d39f272SZheng Fan 85*5d39f272SZheng Fan return iBestMatch; 86*5d39f272SZheng Fan } 87*5d39f272SZheng Fan 88*5d39f272SZheng Fan 89*5d39f272SZheng Fan 90*5d39f272SZheng Fan 91*5d39f272SZheng Fan void ContextList::AddContextDescription ( 92*5d39f272SZheng Fan const Context& rContext, 93*5d39f272SZheng Fan const bool bIsInitiallyVisible, 94*5d39f272SZheng Fan const OUString& rsMenuCommand) 95*5d39f272SZheng Fan { 96*5d39f272SZheng Fan maEntries.push_back(Entry()); 97*5d39f272SZheng Fan maEntries.back().maContext = rContext; 98*5d39f272SZheng Fan maEntries.back().mbIsInitiallyVisible = bIsInitiallyVisible; 99*5d39f272SZheng Fan maEntries.back().msMenuCommand = rsMenuCommand; 100*5d39f272SZheng Fan } 101*5d39f272SZheng Fan 102*5d39f272SZheng Fan 103*5d39f272SZheng Fan 104*5d39f272SZheng Fan 105*5d39f272SZheng Fan bool ContextList::IsEmpty (void) 106*5d39f272SZheng Fan { 107*5d39f272SZheng Fan return maEntries.empty(); 108*5d39f272SZheng Fan } 109*5d39f272SZheng Fan 110*5d39f272SZheng Fan 111*5d39f272SZheng Fan } } // end of namespace sfx2::sidebar 112