1*40df464eSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*40df464eSAndrew Rist * distributed with this work for additional information 6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance 9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at 10*40df464eSAndrew Rist * 11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*40df464eSAndrew Rist * 13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*40df464eSAndrew Rist * software distributed under the License is distributed on an 15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the 17*40df464eSAndrew Rist * specific language governing permissions and limitations 18*40df464eSAndrew Rist * under the License. 19*40df464eSAndrew Rist * 20*40df464eSAndrew Rist *************************************************************/ 21*40df464eSAndrew Rist 22*40df464eSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svl.hxx" 26cdf0e10cSrcweir #include <svl/pickerhistory.hxx> 27cdf0e10cSrcweir #include <svl/pickerhistoryaccess.hxx> 28cdf0e10cSrcweir #include <cppuhelper/weakref.hxx> 29cdf0e10cSrcweir #include <vector> 30cdf0e10cSrcweir 31cdf0e10cSrcweir //......................................................................... 32cdf0e10cSrcweir namespace svt 33cdf0e10cSrcweir { 34cdf0e10cSrcweir //......................................................................... 35cdf0e10cSrcweir using namespace ::com::sun::star::uno; 36cdf0e10cSrcweir 37cdf0e10cSrcweir namespace 38cdf0e10cSrcweir { 39cdf0e10cSrcweir typedef ::com::sun::star::uno::WeakReference< XInterface > InterfaceAdapter; 40cdf0e10cSrcweir typedef ::std::vector< InterfaceAdapter > InterfaceArray; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // ---------------------------------------------------------------- getFolderPickerHistory()43cdf0e10cSrcweir InterfaceArray& getFolderPickerHistory() 44cdf0e10cSrcweir { 45cdf0e10cSrcweir static InterfaceArray s_aHistory; 46cdf0e10cSrcweir return s_aHistory; 47cdf0e10cSrcweir } 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ---------------------------------------------------------------- getFilePickerHistory()50cdf0e10cSrcweir InterfaceArray& getFilePickerHistory() 51cdf0e10cSrcweir { 52cdf0e10cSrcweir static InterfaceArray s_aHistory; 53cdf0e10cSrcweir return s_aHistory; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir 56cdf0e10cSrcweir // ---------------------------------------------------------------- implPushBackPicker(InterfaceArray & _rHistory,const Reference<XInterface> & _rxPicker)57cdf0e10cSrcweir void implPushBackPicker( InterfaceArray& _rHistory, const Reference< XInterface >& _rxPicker ) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir if ( !_rxPicker.is() ) 60cdf0e10cSrcweir return; 61cdf0e10cSrcweir 62cdf0e10cSrcweir //============================================================= 63cdf0e10cSrcweir // first, check which of the objects we hold in s_aHistory can be removed 64cdf0e10cSrcweir { 65cdf0e10cSrcweir InterfaceArray aCleanedHistory; 66cdf0e10cSrcweir for ( InterfaceArray::const_iterator aLoop = _rHistory.begin(); 67cdf0e10cSrcweir aLoop != _rHistory.end(); 68cdf0e10cSrcweir ++aLoop 69cdf0e10cSrcweir ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir Reference< XInterface > xCurrent( aLoop->get() ); 72cdf0e10cSrcweir if ( xCurrent.is() ) 73cdf0e10cSrcweir { 74cdf0e10cSrcweir if ( aCleanedHistory.empty() ) 75cdf0e10cSrcweir // make some room, assume that all interfaces (from here on) are valie 76cdf0e10cSrcweir aCleanedHistory.reserve( _rHistory.size() - ( aLoop - _rHistory.begin() ) ); 77cdf0e10cSrcweir aCleanedHistory.push_back( InterfaceAdapter( xCurrent ) ); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir _rHistory.swap( aCleanedHistory ); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir //============================================================= 84cdf0e10cSrcweir // then push_back the picker 85cdf0e10cSrcweir _rHistory.push_back( InterfaceAdapter( _rxPicker ) ); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir //----------------------------------------------------------------- implGetTopMostPicker(const InterfaceArray & _rHistory)89cdf0e10cSrcweir Reference< XInterface > implGetTopMostPicker( const InterfaceArray& _rHistory ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir Reference< XInterface > xTopMostAlive; 92cdf0e10cSrcweir 93cdf0e10cSrcweir //============================================================= 94cdf0e10cSrcweir // search the first picker which is still alive ... 95cdf0e10cSrcweir for ( InterfaceArray::const_reverse_iterator aLoop = _rHistory.rbegin(); 96cdf0e10cSrcweir ( aLoop != _rHistory.rend() ) && !xTopMostAlive.is(); 97cdf0e10cSrcweir ++aLoop 98cdf0e10cSrcweir ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir xTopMostAlive = aLoop->get(); 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir return xTopMostAlive; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir //--------------------------------------------------------------------- GetTopMostFolderPicker()108cdf0e10cSrcweir Reference< XInterface > GetTopMostFolderPicker( ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir return implGetTopMostPicker( getFolderPickerHistory() ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //--------------------------------------------------------------------- GetTopMostFilePicker()114cdf0e10cSrcweir Reference< XInterface > GetTopMostFilePicker( ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir return implGetTopMostPicker( getFilePickerHistory() ); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //--------------------------------------------------------------------- addFolderPicker(const Reference<XInterface> & _rxPicker)120cdf0e10cSrcweir void addFolderPicker( const Reference< XInterface >& _rxPicker ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir implPushBackPicker( getFolderPickerHistory(), _rxPicker ); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir //--------------------------------------------------------------------- addFilePicker(const Reference<XInterface> & _rxPicker)126cdf0e10cSrcweir void addFilePicker( const Reference< XInterface >& _rxPicker ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir implPushBackPicker( getFilePickerHistory(), _rxPicker ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir //......................................................................... 132cdf0e10cSrcweir } // namespace svt 133cdf0e10cSrcweir //......................................................................... 134cdf0e10cSrcweir 135