/*************************************************************************
 *
 *  $RCSfile: filedlghelper.hxx,v $
 *
 *  $Revision: 1.20 $
 *
 *  last change: $Author: fs $ $Date: 2001/10/26 09:07:12 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/
#ifndef _FILEDLGHELPER_HXX
#define _FILEDLGHELPER_HXX

#ifndef  _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif
#ifndef  _COM_SUN_STAR_UNO_SEQUENCE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
#endif
#ifndef  _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#ifndef _STRING_HXX
#include <tools/string.hxx>
#endif
#ifndef _ERRCODE_HXX
#include <tools/errcode.hxx>
#endif

#ifndef _SV_DIALOG_HXX
#include <vcl/dialog.hxx>
#endif
#ifndef _SV_EDIT_HXX
#include <vcl/edit.hxx>
#endif
#ifndef _SV_BUTTON_HXX
#include <vcl/button.hxx>
#endif
#ifndef _SV_GRAPH_HXX
#include <vcl/graph.hxx>
#endif

#ifndef  _SFXDEFS_HXX
#include <sfx2/sfxdefs.hxx>
#endif
#ifndef  _SFX_SFXUNO_HXX
#include <sfx2/sfxuno.hxx>
#endif

//-----------------------------------------------------------------------------

namespace com
{
    namespace sun
    {
        namespace star
        {
            namespace ui
            {
                namespace dialogs
                {
    				class XFilePicker;
				    class XFilePickerListener;
                    struct FilePickerEvent;
                }
            }
        }
    }
}

class SfxItemSet;
class SfxObjectFactory;
class SvStringsDtor;
class Window;

//-----------------------------------------------------------------------------
/*
#define WB_PATH 				0x00100000L
#define WB_OPEN 				0x00200000L
#define WB_SAVEAS				0x00400000L
#define WB_PASSWORD 			0x01000000L
#define WB_READONLY 			0x02000000L
*/

#define SFXWB_INSERT			( 0x04000000L | WB_OPEN )   // ((WinBits)0x00200000)
#define SFXWB_PASSWORD			WB_PASSWORD                 // ((WinBits)0x01000000)
#define SFXWB_READONLY			WB_READONLY                 // ((WinBits)0x02000000)
#define SFXWB_PATHDIALOG		WB_PATH                     // ((WinBits)0x00100000)
#define SFXWB_CLASSPATH			( 0x08000000L | SFXWB_PATHDIALOG )
#define SFXWB_SHOWALLFOLDER		0x10000000L		// alle Ordner auch Mail/News/...
#define SFXWB_MULTISELECTION	0x20000000L		// Multiselection an
#define SFXWB_NOREMOTE          0x40000000L
#define SFXWB_SHOWVERSIONS		0x80000000L  	// Versionsauswahl anzeigen

#define SFXWB_GRAPHIC           0x00800000L     // FileOpen with link and preview box
#define SFXWB_SHOWSTYLES        0x01000000L     // FileOpen with link and preview box and styles

#define FILEDIALOG_FILTER_ALL   "*.*"

#define FILE_OPEN_SERVICE_NAME      "com.sun.star.ui.dialogs.FilePicker"
#define FOLDER_PICKER_SERVICE_NAME  "com.sun.star.ui.dialogs.FolderPicker"

const short FILEOPEN_SIMPLE 									= 0;
const short FILESAVE_SIMPLE 									= 1;
const short FILESAVE_AUTOEXTENSION_PASSWORD 					= 2;
const short FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS		= 3;
const short FILESAVE_AUTOEXTENSION_SELECTION					= 4;
const short FILESAVE_AUTOEXTENSION_TEMPLATE 					= 5;
const short FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE				= 6;
const short FILEOPEN_PLAY										= 7;
const short FILEOPEN_READONLY_VERSION							= 8;
const short FILEOPEN_LINK_PREVIEW								= 9;
const short FILESAVE_AUTOEXTENSION								= 10;

//*****************************************************************************
// SfxUrlDialog
//*****************************************************************************

#if 0 // _SOLAR__PRIVATE
#ifndef DONT_USE_FILE_DIALOG_SERVICE

class SfxUrlDialog : public ModalDialog
{
private:
	Edit			aEdit;
	OKButton		aOk;
	CancelButton	aCancel;

public:
					SfxUrlDialog( Window* pParent );

	String			GetUrl() const { return aEdit.GetText(); }
	void 			SetUrl( const String& rUrl ) { aEdit.SetText( rUrl ); }
};

#endif
#endif

//-----------------------------------------------------------------------------

namespace sfx2 { 

class FileDialogHelper_Impl;

class FileDialogHelper
{
private:
    ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePickerListener > mxImp;
	FileDialogHelper_Impl	*mpImp;

#if 0 // _SOLAR__PRIVATE

    const short              getDialogType( sal_uInt32 nFlags ) const;

#endif

public:
							 FileDialogHelper( sal_uInt32 nFlags,
											   const SfxObjectFactory& rFactory );
							 FileDialogHelper( const short nDialogType,
                                               sal_uInt32 nFlags,
											   const SfxObjectFactory& rFactory );
							 FileDialogHelper( sal_uInt32 nFlags );
							 FileDialogHelper( const short nDialogType,
                                               sal_uInt32 nFlags );

    virtual                  ~FileDialogHelper();

	ErrCode					 Execute();
	void					 SetTitle( const String&  rNewTitle );
	String					 GetPath() const;

    ::com::sun::star::uno::Sequence< ::rtl::OUString > GetMPath() const;

    void                     AddFilter( const String& rFilterName, const String& rExtension );
    void                     SetCurrentFilter( const String& rFilter );
    void                     SetDisplayDirectory( const String& rPath );

    String                   GetCurrentFilter() const;
    String                   GetDisplayDirectory() const;
    ErrCode                  GetGraphic( Graphic& rGraphic ) const;

    ::com::sun::star::uno::Reference < ::com::sun::star::ui::dialogs::XFilePicker > GetFilePicker() const;

    // XFilePickerListener methods
    virtual void SAL_CALL    FileSelectionChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
    virtual void SAL_CALL    DirectoryChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
    virtual void SAL_CALL    ControlStateChanged( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );
    virtual void SAL_CALL    DialogSizeChanged();
    virtual ::rtl::OUString SAL_CALL    HelpRequested( const ::com::sun::star::ui::dialogs::FilePickerEvent& aEvent );

	// retrieves the top-most file picker - i.e. the instance which is currently beeing executed
	static ::com::sun::star::uno::Reference< ::com::sun::star::ui::dialogs::XFilePicker >
							GetTopMostFilePicker( );

	/** sets help ids for the controls in the dialog
		@param _pControlId
			Pointer to a 0-terminated array of control ids. They must be recruited from the
			CommonFilePickerElementIds and ExtendedFilePickerElementIds values.
		@param _pHelpId
			Pointer to an array of help ids. For each element in _pControlId, there must be
			a corresponding element herein.
	*/
	void SetControlHelpIds( const sal_Int16* _pControlId, const sal_Int32* _pHelpId );
	void SetDialogHelpId( const sal_Int32 _nHelpId );

#if 0 // _SOLAR__PRIVATE
	ErrCode					 Execute( const String&   rPath,
									  SvStringsDtor*& rpURLList,
									  SfxItemSet *&   rpSet,
									  String&         rFilter );
	ErrCode					 Execute( SfxItemSet *&   rpSet,
									  String&         rFilter );
#endif
};

#if 0 // _SOLAR__PRIVATE
ErrCode FileOpenDialog_Impl( sal_uInt32 nFlags,
							 const SfxObjectFactory& rFact,
							 SvStringsDtor *& rpURLList,
							 String& rFilter,
							 SfxItemSet *& rpSet,
							 String aPath );
#endif
}

//-----------------------------------------------------------------------------

#endif
