update dev300-m58
[ooovba.git] / fpicker / source / aqua / FilterHelper.hxx
blobc77f93f26bb60a744ec9b431d6d6f679e422d90d
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: FilterHelper.hxx,v $
10 * $Revision: 1.4 $
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 #ifndef _FILTERHELPER_HXX_
32 #define _FILTERHELPER_HXX_
34 // #ifndef _COM_SUN_STAR_UNO_TYPE_HXX_
35 // #include <com/sun/star/uno/Type.hxx>
36 // #endif
38 // #ifndef INCLUDED_CPPU_UNOTYPE_HXX
39 // #include <cppu/unotype.hxx>
40 // #endif
42 // #ifndef _TYPELIB_TYPECLASS_H_
43 // #include "typelib/typeclass.h"
44 // #endif
46 // #ifndef _TYPELIB_TYPEDESCRIPTION_H_
47 // #include "typelib/typedescription.h"
48 // #endif
50 #include <com/sun/star/beans/StringPair.hpp>
51 #include <com/sun/star/uno/Sequence.hxx>
53 #ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HXX_
54 #include <com/sun/star/lang/IllegalArgumentException.hpp>
55 #endif
57 #ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HXX_
58 #include <com/sun/star/uno/RuntimeException.hpp>
59 #endif
61 // #ifndef _RTL_USTRING_H_
62 // #include <rtl/ustring.hxx>
63 // #endif
65 #include <list>
66 #include <vector>
68 #include <premac.h>
69 #include <Cocoa/Cocoa.h>
70 #include <postmac.h>
72 typedef ::com::sun::star::beans::StringPair UnoFilterEntry;
73 typedef ::com::sun::star::uno::Sequence< UnoFilterEntry > UnoFilterList; // can be transported more effectively
74 typedef ::std::list<NSString *> NSStringList;
75 typedef ::std::list<rtl::OUString> OUStringList;
77 struct FilterEntry
79 protected:
80 rtl::OUString m_sTitle;
81 OUStringList m_sFilterSuffixList;
82 UnoFilterList m_aSubFilters;
84 public:
85 FilterEntry( const rtl::OUString& _rTitle, const OUStringList _rFilter )
86 : m_sTitle( _rTitle )
87 , m_sFilterSuffixList( _rFilter )
91 FilterEntry( const rtl::OUString& _rTitle, const UnoFilterList& _rSubFilters );
93 rtl::OUString getTitle() const { return m_sTitle; }
94 OUStringList getFilterSuffixList() const { return m_sFilterSuffixList; }
96 /// determines if the filter has sub filter (i.e., the filter is a filter group in real)
97 sal_Bool hasSubFilters( ) const;
99 /** retrieves the filters belonging to the entry
100 @return
101 the number of sub filters
103 sal_Int32 getSubFilters( UnoFilterList& _rSubFilterList );
105 // helpers for iterating the sub filters
106 const UnoFilterEntry* beginSubFilters() const { return m_aSubFilters.getConstArray(); }
107 const UnoFilterEntry* endSubFilters() const { return m_aSubFilters.getConstArray() + m_aSubFilters.getLength(); }
110 typedef ::std::vector < FilterEntry > FilterList;
112 class FilterHelper {
114 public:
115 FilterHelper();
116 virtual ~FilterHelper();
118 //XFilterManager delegates
119 void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter )
120 throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
122 void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle )
123 throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
125 ::rtl::OUString SAL_CALL getCurrentFilter( )
126 throw( ::com::sun::star::uno::RuntimeException );
128 //XFilterGroupManager delegates
129 void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters )
130 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
133 //accessor
134 FilterList* getFilterList();
135 NSStringList* getFilterNames();
137 //misc
138 void SetCurFilter( const rtl::OUString& rFilter );
139 void SetFilterAtIndex(unsigned index);
140 OUStringList getCurrentFilterSuffixList();
141 int getCurrentFilterIndex();
142 void SetFilters();
143 sal_Bool filenameMatchesFilter(NSString * sFilename);
145 private:
146 FilterList *m_pFilterList;
147 rtl::OUString m_aCurrentFilter;
148 NSStringList *m_pFilterNames;
150 int implAddFilter( const rtl::OUString rFilter, const OUStringList rSuffixList);
151 int implAddFilterGroup( const rtl::OUString rFilter,
152 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters );
154 sal_Bool FilterNameExists( const rtl::OUString rTitle );
155 sal_Bool FilterNameExists( const UnoFilterList& _rGroupedFilters );
157 void ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter );
159 void fillSuffixList(OUStringList& aSuffixList, const ::rtl::OUString& suffixString);
163 #endif //_FILTERHELPER_HXX_