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 23 24 #ifndef _FILTER_CONTAINER_HXX_ 25 #define _FILTER_CONTAINER_HXX_ 26 27 #include <sal/types.h> 28 #include <rtl/ustring.hxx> 29 30 #include <vector> 31 32 //------------------------------------------------------ 33 // helper class, only useable by OFilterContainer 34 //------------------------------------------------------ 35 36 class CFilterContainer 37 { 38 public: 39 // defines a filter entry which is made of a name and a filter value 40 // e.g. 'Text *.txt' 41 typedef std::pair< rtl::OUString, rtl::OUString > FILTER_ENTRY_T; 42 43 public: 44 explicit CFilterContainer( sal_Int32 initSize = 0 ); 45 46 // add a new filter 47 // returns true if the filter was successfully added 48 // returns false if duplicates are not allowed and 49 // the filter is already in the container 50 sal_Bool SAL_CALL addFilter( 51 const ::rtl::OUString& aName, 52 const ::rtl::OUString& aFilter, 53 sal_Bool bAllowDuplicates = sal_False ); 54 55 // delete the specified filter returns true on 56 // success and false if the filter was not found 57 sal_Bool SAL_CALL delFilter( const ::rtl::OUString& aName ); 58 59 // the number of filter already added 60 sal_Int32 SAL_CALL numFilter( ); 61 62 // clear all entries 63 void SAL_CALL empty( ); 64 65 // retrieve a filter from the container both methods 66 // return true on success and false if the specified 67 // filter was not found 68 sal_Bool SAL_CALL getFilter( const ::rtl::OUString& aName, ::rtl::OUString& theFilter ) const; 69 sal_Bool SAL_CALL getFilter( sal_Int32 aIndex, ::rtl::OUString& theFilter ) const; 70 71 // returns the position of the specified filter or -1 72 // if the filter was not found 73 sal_Int32 SAL_CALL getFilterPos( const ::rtl::OUString& aName ) const; 74 75 // starts enumerating the filter in the container 76 void SAL_CALL beginEnumFilter( ); 77 78 // returns true if another filter has been retrieved 79 sal_Bool SAL_CALL getNextFilter( FILTER_ENTRY_T& nextFilterEntry ); 80 81 // cache current filter 82 void SAL_CALL setCurrentFilter( const ::rtl::OUString& aName ); 83 84 // returns cached current filter 85 ::rtl::OUString SAL_CALL getCurrentFilter() const; 86 87 protected: 88 typedef std::vector< FILTER_ENTRY_T > FILTER_VECTOR_T; 89 90 private: 91 // prevent copy and assignment 92 CFilterContainer( const CFilterContainer& ); 93 CFilterContainer& SAL_CALL operator=( const CFilterContainer& ); 94 95 sal_Int32 SAL_CALL getFilterTagPos( const ::rtl::OUString& aName ) const; 96 97 private: 98 FILTER_VECTOR_T m_vFilters; 99 FILTER_VECTOR_T::const_iterator m_iter; 100 sal_Bool m_bIterInitialized; 101 ::rtl::OUString m_sCurrentFilter; 102 }; 103 104 //---------------------------------------------------------------- 105 // a helper function to create a filter buffer in the format 106 // the Win32 API requires, e.g. "Text\0*.txt\0Doc\0*.doc;*xls\0\0" 107 //---------------------------------------------------------------- 108 109 rtl::OUString SAL_CALL makeWinFilterBuffer( CFilterContainer& aFilterContainer ); 110 111 #endif 112