merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / filepicker / pickerhistory.cxx
blob5d3d4ec58579aa3ab80a2ef3d1a865ed10d2d535
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pickerhistory.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include "pickerhistory.hxx"
34 #include "pickerhistoryaccess.hxx"
35 #include <cppuhelper/weakref.hxx>
36 #include <vector>
38 //.........................................................................
39 namespace svt
41 //.........................................................................
42 using namespace ::com::sun::star::uno;
44 namespace
46 typedef ::com::sun::star::uno::WeakReference< XInterface > InterfaceAdapter;
47 typedef ::std::vector< InterfaceAdapter > InterfaceArray;
49 // ----------------------------------------------------------------
50 InterfaceArray& getFolderPickerHistory()
52 static InterfaceArray s_aHistory;
53 return s_aHistory;
56 // ----------------------------------------------------------------
57 InterfaceArray& getFilePickerHistory()
59 static InterfaceArray s_aHistory;
60 return s_aHistory;
63 // ----------------------------------------------------------------
64 void implPushBackPicker( InterfaceArray& _rHistory, const Reference< XInterface >& _rxPicker )
66 if ( !_rxPicker.is() )
67 return;
69 //=============================================================
70 // first, check which of the objects we hold in s_aHistory can be removed
72 InterfaceArray aCleanedHistory;
73 for ( InterfaceArray::const_iterator aLoop = _rHistory.begin();
74 aLoop != _rHistory.end();
75 ++aLoop
78 Reference< XInterface > xCurrent( aLoop->get() );
79 if ( xCurrent.is() )
81 if ( aCleanedHistory.empty() )
82 // make some room, assume that all interfaces (from here on) are valie
83 aCleanedHistory.reserve( _rHistory.size() - ( aLoop - _rHistory.begin() ) );
84 aCleanedHistory.push_back( InterfaceAdapter( xCurrent ) );
87 _rHistory.swap( aCleanedHistory );
90 //=============================================================
91 // then push_back the picker
92 _rHistory.push_back( InterfaceAdapter( _rxPicker ) );
95 //-----------------------------------------------------------------
96 Reference< XInterface > implGetTopMostPicker( const InterfaceArray& _rHistory )
98 Reference< XInterface > xTopMostAlive;
100 //=============================================================
101 // search the first picker which is still alive ...
102 for ( InterfaceArray::const_reverse_iterator aLoop = _rHistory.rbegin();
103 ( aLoop != _rHistory.rend() ) && !xTopMostAlive.is();
104 ++aLoop
107 xTopMostAlive = aLoop->get();
110 return xTopMostAlive;
114 //---------------------------------------------------------------------
115 Reference< XInterface > GetTopMostFolderPicker( )
117 return implGetTopMostPicker( getFolderPickerHistory() );
120 //---------------------------------------------------------------------
121 Reference< XInterface > GetTopMostFilePicker( )
123 return implGetTopMostPicker( getFilePickerHistory() );
126 //---------------------------------------------------------------------
127 void addFolderPicker( const Reference< XInterface >& _rxPicker )
129 implPushBackPicker( getFolderPickerHistory(), _rxPicker );
132 //---------------------------------------------------------------------
133 void addFilePicker( const Reference< XInterface >& _rxPicker )
135 implPushBackPicker( getFilePickerHistory(), _rxPicker );
138 //.........................................................................
139 } // namespace svt
140 //.........................................................................