1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SALGTKFILEPICKER_HXX_ 29 #define _SALGTKFILEPICKER_HXX_ 30 31 //_______________________________________________________________________________________________________________________ 32 // includes of other projects 33 //_______________________________________________________________________________________________________________________ 34 35 #include <cppuhelper/compbase10.hxx> 36 #include <com/sun/star/lang/XInitialization.hpp> 37 #include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp> 38 #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 39 #include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp> 40 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 41 #include <com/sun/star/ui/dialogs/XFilePreview.hpp> 42 #include <com/sun/star/beans/StringPair.hpp> 43 44 #ifndef _SALGTKPICKER_HXX_ 45 #include "SalGtkPicker.hxx" 46 #endif 47 48 #include <memory> 49 50 #ifndef _RTL_USTRING_H_ 51 #include <rtl/ustring.hxx> 52 #endif 53 54 #include <list> 55 56 //---------------------------------------------------------- 57 // Implementation class for the XFilePicker Interface 58 //---------------------------------------------------------- 59 60 //---------------------------------------------------------- 61 // forward declarations 62 //---------------------------------------------------------- 63 64 using namespace rtl; 65 66 struct FilterEntry; 67 struct ElementEntry_Impl; 68 69 typedef ::std::list < FilterEntry > FilterList; 70 typedef ::std::list < ElementEntry_Impl > ElementList; 71 typedef ::com::sun::star::beans::StringPair UnoFilterEntry; 72 typedef ::com::sun::star::uno::Sequence< UnoFilterEntry > UnoFilterList; // can be transported more effectively 73 74 75 //---------------------------------------------------------- 76 // class declaration 77 //---------------------------------------------------------- 78 79 class SalGtkFilePicker : 80 public SalGtkPicker, 81 public cppu::WeakComponentImplHelper10< 82 ::com::sun::star::ui::dialogs::XFilterManager, 83 ::com::sun::star::ui::dialogs::XFilterGroupManager, 84 ::com::sun::star::ui::dialogs::XFilePickerControlAccess, 85 ::com::sun::star::ui::dialogs::XFilePickerNotifier, 86 ::com::sun::star::ui::dialogs::XFilePreview, 87 ::com::sun::star::ui::dialogs::XFilePicker2, 88 ::com::sun::star::lang::XInitialization, 89 ::com::sun::star::util::XCancellable, 90 ::com::sun::star::lang::XEventListener, 91 ::com::sun::star::lang::XServiceInfo > 92 { 93 public: 94 95 // constructor 96 SalGtkFilePicker( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceMgr ); 97 98 //------------------------------------------------------------------------------------ 99 // XFilePickerNotifier 100 //------------------------------------------------------------------------------------ 101 102 virtual void SAL_CALL addFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) 103 throw( ::com::sun::star::uno::RuntimeException ); 104 virtual void SAL_CALL removeFilePickerListener( const ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener >& xListener ) 105 throw( ::com::sun::star::uno::RuntimeException ); 106 107 //------------------------------------------------------------------------------------ 108 // XExecutableDialog functions 109 //------------------------------------------------------------------------------------ 110 111 virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) 112 throw( ::com::sun::star::uno::RuntimeException ); 113 114 virtual sal_Int16 SAL_CALL execute( ) 115 throw( ::com::sun::star::uno::RuntimeException ); 116 117 //------------------------------------------------------------------------------------ 118 // XFilePicker functions 119 //------------------------------------------------------------------------------------ 120 121 virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode ) 122 throw( ::com::sun::star::uno::RuntimeException ); 123 124 virtual void SAL_CALL setDefaultName( const ::rtl::OUString& aName ) 125 throw( ::com::sun::star::uno::RuntimeException ); 126 127 virtual void SAL_CALL setDisplayDirectory( const ::rtl::OUString& aDirectory ) 128 throw( com::sun::star::lang::IllegalArgumentException, 129 ::com::sun::star::uno::RuntimeException ); 130 131 virtual ::rtl::OUString SAL_CALL getDisplayDirectory( ) 132 throw( ::com::sun::star::uno::RuntimeException ); 133 134 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getFiles( ) 135 throw( ::com::sun::star::uno::RuntimeException ); 136 137 //------------------------------------------------------------------------------------ 138 // XFilePicker2 functions 139 //------------------------------------------------------------------------------------ 140 141 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedFiles() 142 throw (::com::sun::star::uno::RuntimeException); 143 144 //------------------------------------------------------------------------------------ 145 // XFilterManager functions 146 //------------------------------------------------------------------------------------ 147 148 virtual void SAL_CALL appendFilter( const ::rtl::OUString& aTitle, const ::rtl::OUString& aFilter ) 149 throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); 150 151 virtual void SAL_CALL setCurrentFilter( const ::rtl::OUString& aTitle ) 152 throw( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException ); 153 154 virtual ::rtl::OUString SAL_CALL getCurrentFilter( ) 155 throw( ::com::sun::star::uno::RuntimeException ); 156 157 //------------------------------------------------------------------------------------ 158 // XFilterGroupManager functions 159 //------------------------------------------------------------------------------------ 160 161 virtual void SAL_CALL appendFilterGroup( const ::rtl::OUString& sGroupTitle, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aFilters ) 162 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 163 164 //------------------------------------------------------------------------------------ 165 // XFilePickerControlAccess functions 166 //------------------------------------------------------------------------------------ 167 168 virtual void SAL_CALL setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const ::com::sun::star::uno::Any& aValue ) 169 throw (::com::sun::star::uno::RuntimeException); 170 171 virtual ::com::sun::star::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) 172 throw (::com::sun::star::uno::RuntimeException); 173 174 virtual void SAL_CALL enableControl( sal_Int16 nControlId, sal_Bool bEnable ) 175 throw(::com::sun::star::uno::RuntimeException ); 176 177 virtual void SAL_CALL setLabel( sal_Int16 nControlId, const ::rtl::OUString& aLabel ) 178 throw (::com::sun::star::uno::RuntimeException); 179 180 virtual ::rtl::OUString SAL_CALL getLabel( sal_Int16 nControlId ) 181 throw (::com::sun::star::uno::RuntimeException); 182 183 //------------------------------------------------ 184 // XFilePreview 185 //------------------------------------------------ 186 187 virtual ::com::sun::star::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats( ) 188 throw (::com::sun::star::uno::RuntimeException); 189 190 virtual sal_Int32 SAL_CALL getTargetColorDepth( ) 191 throw (::com::sun::star::uno::RuntimeException); 192 193 virtual sal_Int32 SAL_CALL getAvailableWidth( ) 194 throw (::com::sun::star::uno::RuntimeException); 195 196 virtual sal_Int32 SAL_CALL getAvailableHeight( ) 197 throw (::com::sun::star::uno::RuntimeException); 198 199 virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage ) 200 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); 201 202 virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState ) 203 throw (::com::sun::star::uno::RuntimeException); 204 205 virtual sal_Bool SAL_CALL getShowState( ) 206 throw (::com::sun::star::uno::RuntimeException); 207 208 //------------------------------------------------ 209 // XInitialization 210 //------------------------------------------------ 211 212 virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) 213 throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); 214 215 //------------------------------------------------ 216 // XCancellable 217 //------------------------------------------------ 218 219 virtual void SAL_CALL cancel( ) 220 throw( ::com::sun::star::uno::RuntimeException ); 221 222 //------------------------------------------------ 223 // XEventListener 224 //------------------------------------------------ 225 226 using cppu::WeakComponentImplHelperBase::disposing; 227 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) 228 throw(::com::sun::star::uno::RuntimeException); 229 230 //------------------------------------------------ 231 // XServiceInfo 232 //------------------------------------------------ 233 234 virtual ::rtl::OUString SAL_CALL getImplementationName( ) 235 throw(::com::sun::star::uno::RuntimeException); 236 237 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) 238 throw(::com::sun::star::uno::RuntimeException); 239 240 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) 241 throw(::com::sun::star::uno::RuntimeException); 242 243 //------------------------------------------------------------------------------------ 244 // FilePicker Event functions 245 //------------------------------------------------------------------------------------ 246 247 void SAL_CALL fileSelectionChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ); 248 void SAL_CALL directoryChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ); 249 rtl::OUString SAL_CALL helpRequested( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ) const; 250 void SAL_CALL controlStateChanged( ::com::sun::star::ui::dialogs::FilePickerEvent aEvent ); 251 252 private: 253 // prevent copy and assignment 254 SalGtkFilePicker( const SalGtkFilePicker& ); 255 SalGtkFilePicker& operator=( const SalGtkFilePicker& ); 256 257 sal_Bool FilterNameExists( const ::rtl::OUString& rTitle ); 258 sal_Bool FilterNameExists( const UnoFilterList& _rGroupedFilters ); 259 260 void ensureFilterList( const ::rtl::OUString& _rInitialCurrentFilter ); 261 262 // to instanciate own services 263 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceMgr; 264 265 private: 266 ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePickerListener > 267 m_xListener; 268 ::rtl::OUString msPlayLabel; 269 FilterList *m_pFilterList; 270 GtkWidget *m_pVBox; 271 272 GtkWidget *m_pFilterExpander; 273 GtkWidget *m_pFilterView; 274 GtkListStore *m_pFilterStore; 275 276 enum { 277 AUTOEXTENSION, 278 PASSWORD, 279 FILTEROPTIONS, 280 READONLY, 281 LINK, 282 PREVIEW, 283 SELECTION, 284 TOGGLE_LAST 285 }; 286 287 GtkWidget *m_pToggles[ TOGGLE_LAST ]; 288 289 bool mbToggleVisibility[TOGGLE_LAST]; 290 bool mbToggleChecked[TOGGLE_LAST]; 291 292 static const rtl::OString m_ToggleLabels[TOGGLE_LAST]; 293 294 enum { 295 PLAY, 296 BUTTON_LAST }; 297 298 GtkWidget *m_pButtons[ BUTTON_LAST ]; 299 300 enum { 301 VERSION, 302 TEMPLATE, 303 IMAGE_TEMPLATE, 304 LIST_LAST 305 }; 306 307 GtkWidget *m_pHBoxs[ LIST_LAST ]; 308 GtkWidget *m_pAligns[ LIST_LAST ]; 309 GtkWidget *m_pLists[ LIST_LAST ]; 310 GtkWidget *m_pListLabels[ LIST_LAST ]; 311 bool mbListVisibility[ LIST_LAST ]; 312 bool mbButtonVisibility[ BUTTON_LAST ]; 313 gulong mnHID_FolderChange; 314 gulong mnHID_SelectionChange; 315 316 ::rtl::OUString m_aCurrentFilter; 317 ::rtl::OUString m_aInitialFilter; 318 319 bool bVersionWidthUnset; 320 sal_Bool mbPreviewState; 321 gulong mHID_Preview; 322 GtkWidget* m_pPreview; 323 GtkFileFilter* m_pPseudoFilter; 324 sal_Int32 m_PreviewImageWidth; 325 sal_Int32 m_PreviewImageHeight; 326 327 GtkWidget *getWidget( sal_Int16 nControlId, GType *pType = NULL); 328 329 void SetCurFilter( const OUString& rFilter ); 330 void SetFilters(); 331 void UpdateFilterfromUI(); 332 333 void implChangeType( GtkTreeSelection *selection ); 334 GtkFileFilter * implAddFilter( const OUString& rFilter, const OUString& rType ); 335 void implAddFilterGroup( const OUString& rFilter, 336 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair>& _rFilters ); 337 void updateCurrentFilterFromName(const gchar* filtername); 338 void unselect_type(); 339 void InitialMapping(); 340 341 void HandleSetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction, 342 const ::com::sun::star::uno::Any& rValue); 343 ::com::sun::star::uno::Any HandleGetListValue(GtkComboBox *pWidget, sal_Int16 nControlAction) const; 344 345 static void expander_changed_cb( GtkExpander *expander, SalGtkFilePicker *pobjFP ); 346 static void preview_toggled_cb (GtkObject *cb, SalGtkFilePicker *pobjFP); 347 static void filter_changed_cb (GtkFileChooser *file_chooser, GParamSpec *pspec, SalGtkFilePicker *pobjFP); 348 static void type_changed_cb( GtkTreeSelection *selection, SalGtkFilePicker *pobjFP ); 349 static void folder_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); 350 static void selection_changed_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); 351 static void update_preview_cb (GtkFileChooser *file_chooser, SalGtkFilePicker *pobjFP); 352 static void dialog_mapped_cb(GtkWidget *widget, SalGtkFilePicker *pobjFP); 353 public: 354 virtual ~SalGtkFilePicker(); 355 356 }; 357 /* vi:set tabstop=4 shiftwidth=4 expandtab: */ 358 #endif // _SALGTKFILEPICKER_HXX_ 359