1*b9e67834SAndre Fischer /************************************************************** 2*b9e67834SAndre Fischer * 3*b9e67834SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 4*b9e67834SAndre Fischer * or more contributor license agreements. See the NOTICE file 5*b9e67834SAndre Fischer * distributed with this work for additional information 6*b9e67834SAndre Fischer * regarding copyright ownership. The ASF licenses this file 7*b9e67834SAndre Fischer * to you under the Apache License, Version 2.0 (the 8*b9e67834SAndre Fischer * "License"); you may not use this file except in compliance 9*b9e67834SAndre Fischer * with the License. You may obtain a copy of the License at 10*b9e67834SAndre Fischer * 11*b9e67834SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 12*b9e67834SAndre Fischer * 13*b9e67834SAndre Fischer * Unless required by applicable law or agreed to in writing, 14*b9e67834SAndre Fischer * software distributed under the License is distributed on an 15*b9e67834SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b9e67834SAndre Fischer * KIND, either express or implied. See the License for the 17*b9e67834SAndre Fischer * specific language governing permissions and limitations 18*b9e67834SAndre Fischer * under the License. 19*b9e67834SAndre Fischer * 20*b9e67834SAndre Fischer *************************************************************/ 21*b9e67834SAndre Fischer 22*b9e67834SAndre Fischer #include "precompiled_sfx2.hxx" 23*b9e67834SAndre Fischer 24*b9e67834SAndre Fischer #include "sidebar/EnumContext.hxx" 25*b9e67834SAndre Fischer 26*b9e67834SAndre Fischer namespace sfx2 { namespace sidebar { 27*b9e67834SAndre Fischer 28*b9e67834SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 29*b9e67834SAndre Fischer 30*b9e67834SAndre Fischer namespace { 31*b9e67834SAndre Fischer 32*b9e67834SAndre Fischer typedef ::std::map<rtl::OUString,EnumContext::Application> ApplicationMap; 33*b9e67834SAndre Fischer typedef ::std::vector<rtl::OUString> ApplicationVector; 34*b9e67834SAndre Fischer static ApplicationMap maApplicationMap; 35*b9e67834SAndre Fischer static ApplicationVector maApplicationVector; 36*b9e67834SAndre Fischer 37*b9e67834SAndre Fischer typedef ::std::map<rtl::OUString,EnumContext::Context> ContextMap; 38*b9e67834SAndre Fischer typedef ::std::vector<rtl::OUString> ContextVector; 39*b9e67834SAndre Fischer static ContextMap maContextMap; 40*b9e67834SAndre Fischer static ContextVector maContextVector; 41*b9e67834SAndre Fischer 42*b9e67834SAndre Fischer } 43*b9e67834SAndre Fischer 44*b9e67834SAndre Fischer 45*b9e67834SAndre Fischer 46*b9e67834SAndre Fischer EnumContext::EnumContext (void) 47*b9e67834SAndre Fischer : meApplication(Application_Other), 48*b9e67834SAndre Fischer meContext(Context_Default) 49*b9e67834SAndre Fischer { 50*b9e67834SAndre Fischer } 51*b9e67834SAndre Fischer 52*b9e67834SAndre Fischer 53*b9e67834SAndre Fischer 54*b9e67834SAndre Fischer 55*b9e67834SAndre Fischer EnumContext::EnumContext ( 56*b9e67834SAndre Fischer const Application eApplication, 57*b9e67834SAndre Fischer const Context eContext) 58*b9e67834SAndre Fischer : meApplication(eApplication), 59*b9e67834SAndre Fischer meContext(eContext) 60*b9e67834SAndre Fischer { 61*b9e67834SAndre Fischer } 62*b9e67834SAndre Fischer 63*b9e67834SAndre Fischer 64*b9e67834SAndre Fischer 65*b9e67834SAndre Fischer 66*b9e67834SAndre Fischer sal_Int32 EnumContext::GetCombinedContext(void) const 67*b9e67834SAndre Fischer { 68*b9e67834SAndre Fischer return CombinedEnumContext(meApplication, meContext); 69*b9e67834SAndre Fischer } 70*b9e67834SAndre Fischer 71*b9e67834SAndre Fischer 72*b9e67834SAndre Fischer 73*b9e67834SAndre Fischer 74*b9e67834SAndre Fischer bool EnumContext::operator== (const EnumContext aOther) 75*b9e67834SAndre Fischer { 76*b9e67834SAndre Fischer return meApplication==aOther.meApplication 77*b9e67834SAndre Fischer && meContext==aOther.meContext; 78*b9e67834SAndre Fischer } 79*b9e67834SAndre Fischer 80*b9e67834SAndre Fischer 81*b9e67834SAndre Fischer 82*b9e67834SAndre Fischer 83*b9e67834SAndre Fischer void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Application eApplication) 84*b9e67834SAndre Fischer { 85*b9e67834SAndre Fischer maApplicationMap[rsName] = eApplication; 86*b9e67834SAndre Fischer OSL_ASSERT(eApplication<=__LastApplicationEnum); 87*b9e67834SAndre Fischer if (maApplicationVector.size() <= eApplication) 88*b9e67834SAndre Fischer maApplicationVector.resize(eApplication+1); 89*b9e67834SAndre Fischer maApplicationVector[eApplication]=rsName; 90*b9e67834SAndre Fischer } 91*b9e67834SAndre Fischer 92*b9e67834SAndre Fischer 93*b9e67834SAndre Fischer 94*b9e67834SAndre Fischer 95*b9e67834SAndre Fischer void EnumContext::ProvideApplicationContainers (void) 96*b9e67834SAndre Fischer { 97*b9e67834SAndre Fischer if (maApplicationMap.empty()) 98*b9e67834SAndre Fischer { 99*b9e67834SAndre Fischer maApplicationVector.resize(static_cast<size_t>(EnumContext::__LastApplicationEnum)+1); 100*b9e67834SAndre Fischer AddEntry(A2S("com.sun.star.text.TextDocument"), EnumContext::Application_Writer); 101*b9e67834SAndre Fischer AddEntry(A2S("com.sun.star ?calc?"), EnumContext::Application_Calc); 102*b9e67834SAndre Fischer AddEntry(A2S("com.sun.star ?draw?"), EnumContext::Application_Draw); 103*b9e67834SAndre Fischer AddEntry(A2S("com.sun.star.presentation.PresentationDocument"), EnumContext::Application_Impress); 104*b9e67834SAndre Fischer AddEntry(A2S("other"), EnumContext::Application_Other); 105*b9e67834SAndre Fischer } 106*b9e67834SAndre Fischer } 107*b9e67834SAndre Fischer 108*b9e67834SAndre Fischer 109*b9e67834SAndre Fischer 110*b9e67834SAndre Fischer 111*b9e67834SAndre Fischer EnumContext::Application EnumContext::GetApplicationEnum (const ::rtl::OUString& rsApplicationName) 112*b9e67834SAndre Fischer { 113*b9e67834SAndre Fischer ProvideApplicationContainers(); 114*b9e67834SAndre Fischer 115*b9e67834SAndre Fischer ApplicationMap::const_iterator iApplication( 116*b9e67834SAndre Fischer maApplicationMap.find(rsApplicationName)); 117*b9e67834SAndre Fischer if (iApplication != maApplicationMap.end()) 118*b9e67834SAndre Fischer return iApplication->second; 119*b9e67834SAndre Fischer else 120*b9e67834SAndre Fischer return EnumContext::Application_Other; 121*b9e67834SAndre Fischer } 122*b9e67834SAndre Fischer 123*b9e67834SAndre Fischer 124*b9e67834SAndre Fischer 125*b9e67834SAndre Fischer 126*b9e67834SAndre Fischer const ::rtl::OUString& EnumContext::GetApplicationName (const Application eApplication) 127*b9e67834SAndre Fischer { 128*b9e67834SAndre Fischer ProvideApplicationContainers(); 129*b9e67834SAndre Fischer 130*b9e67834SAndre Fischer const sal_Int32 nIndex (eApplication); 131*b9e67834SAndre Fischer if (nIndex<0 || nIndex>= __LastApplicationEnum) 132*b9e67834SAndre Fischer return maApplicationVector[Application_Other]; 133*b9e67834SAndre Fischer else 134*b9e67834SAndre Fischer return maApplicationVector[nIndex]; 135*b9e67834SAndre Fischer } 136*b9e67834SAndre Fischer 137*b9e67834SAndre Fischer 138*b9e67834SAndre Fischer 139*b9e67834SAndre Fischer 140*b9e67834SAndre Fischer void EnumContext::AddEntry (const ::rtl::OUString& rsName, const Context eApplication) 141*b9e67834SAndre Fischer { 142*b9e67834SAndre Fischer maContextMap[rsName] = eApplication; 143*b9e67834SAndre Fischer OSL_ASSERT(eApplication<=__LastContextEnum); 144*b9e67834SAndre Fischer if (maContextVector.size() <= eApplication) 145*b9e67834SAndre Fischer maContextVector.resize(eApplication+1); 146*b9e67834SAndre Fischer maContextVector[eApplication]=rsName; 147*b9e67834SAndre Fischer } 148*b9e67834SAndre Fischer 149*b9e67834SAndre Fischer 150*b9e67834SAndre Fischer 151*b9e67834SAndre Fischer 152*b9e67834SAndre Fischer void EnumContext::ProvideContextContainers (void) 153*b9e67834SAndre Fischer { 154*b9e67834SAndre Fischer if (maContextMap.empty()) 155*b9e67834SAndre Fischer { 156*b9e67834SAndre Fischer maContextVector.resize(static_cast<size_t>(__LastContextEnum)+1); 157*b9e67834SAndre Fischer AddEntry(A2S("text-edit"), Context_Text); 158*b9e67834SAndre Fischer AddEntry(A2S("text"), Context_Text); 159*b9e67834SAndre Fischer AddEntry(A2S("default"), Context_Default); 160*b9e67834SAndre Fischer } 161*b9e67834SAndre Fischer } 162*b9e67834SAndre Fischer 163*b9e67834SAndre Fischer 164*b9e67834SAndre Fischer 165*b9e67834SAndre Fischer 166*b9e67834SAndre Fischer EnumContext::Context EnumContext::GetContextEnum (const ::rtl::OUString& rsContextName) 167*b9e67834SAndre Fischer { 168*b9e67834SAndre Fischer ProvideContextContainers(); 169*b9e67834SAndre Fischer 170*b9e67834SAndre Fischer ContextMap::const_iterator iContext( 171*b9e67834SAndre Fischer maContextMap.find(rsContextName)); 172*b9e67834SAndre Fischer if (iContext != maContextMap.end()) 173*b9e67834SAndre Fischer return iContext->second; 174*b9e67834SAndre Fischer else 175*b9e67834SAndre Fischer return EnumContext::Context_Default; 176*b9e67834SAndre Fischer } 177*b9e67834SAndre Fischer 178*b9e67834SAndre Fischer 179*b9e67834SAndre Fischer 180*b9e67834SAndre Fischer 181*b9e67834SAndre Fischer const ::rtl::OUString& EnumContext::GetContextName (const Context eContext) 182*b9e67834SAndre Fischer { 183*b9e67834SAndre Fischer ProvideContextContainers(); 184*b9e67834SAndre Fischer 185*b9e67834SAndre Fischer const sal_Int32 nIndex (eContext); 186*b9e67834SAndre Fischer if (nIndex<0 || nIndex>= __LastContextEnum) 187*b9e67834SAndre Fischer return maContextVector[Context_Default]; 188*b9e67834SAndre Fischer else 189*b9e67834SAndre Fischer return maContextVector[nIndex]; 190*b9e67834SAndre Fischer } 191*b9e67834SAndre Fischer 192*b9e67834SAndre Fischer 193*b9e67834SAndre Fischer 194*b9e67834SAndre Fischer 195*b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar 196