Files
libreoffice/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx

1036 lines
34 KiB
C++
Raw Normal View History

/*************************************************************************
*
* $RCSfile: WinFileOpenImpl.cxx,v $
*
* $Revision: 1.15 $
*
* last change: $Author: tra $ $Date: 2002-03-27 10:35:59 $
*
* 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): _______________________________________
*
*
************************************************************************/
//------------------------------------------------------------------------
// includes
//------------------------------------------------------------------------
#ifndef _WINFILEOPENIMPL_HXX_
#include "WinFileOpenImpl.hxx"
#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif
#ifndef _OSL_FILE_HXX_
#include <osl/file.hxx>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_FILEPICKEREVENT_HPP_
#include <com/sun/star/ui/dialogs/FilePickerEvent.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_EXECUTABLEDIALOGRESULTS_HPP_
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_COMMONFILEPICKERELEMENTIDS_HPP_
#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_FILEPREVIEWIMAGEFORMATS_HPP_
#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
#endif
#ifndef _COM_SUN_STAR_UI_DIALOGS_LISTBOXCONTROLACTIONS_HPP_
#include <com/sun/star/ui/dialogs/ListBoxControlActions.hpp>
#endif
#ifndef _WINIMPLHELPER_HXX_
#include "..\misc\WinImplHelper.hxx"
#endif
#ifndef _FILEPICKER_HXX_
#include "filepicker.hxx"
#endif
#ifndef _CONTROLACCESS_HXX_
#include "controlaccess.hxx"
#endif
#ifndef _RTL_USTRBUF_HXX_
#include <rtl/ustrbuf.hxx>
#endif
#include <systools/win32/comdlg9x.h>
#include <systools/win32/user9x.h>
#ifndef _RESOURCEPROVIDER_HXX_
#include "..\misc\resourceprovider.hxx"
#endif
2001-07-09 11:58:25 +00:00
#ifndef _RTL_STRING_HXX_
#include <rtl/string.hxx>
#endif
#ifndef _THREAD_HXX_
#include <osl/thread.hxx>
#endif
#ifndef _FILEPICKERSTATE_HXX_
#include "filepickerstate.hxx"
#endif
//------------------------------------------------------------------------
// namespace directives
//------------------------------------------------------------------------
using namespace std;
using rtl::OUString;
using rtl::OUStringBuffer;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Any;
using ::com::sun::star::ui::dialogs::FilePickerEvent;
using ::com::sun::star::lang::IllegalArgumentException;
using ::com::sun::star::ui::dialogs::XFilePicker;
using ::com::sun::star::beans::StringPair;
using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds;
using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds;
using namespace ::com::sun::star::ui::dialogs::ListboxControlActions;
//-------------------------------------------------------------------------
// to distinguish what to do in the enum child window callback function
//-------------------------------------------------------------------------
enum ECW_ACTION_T
{
2002-03-21 06:37:13 +00:00
INIT_CUSTOM_CONTROLS,
CACHE_CONTROL_VALUES
};
2001-07-09 11:58:25 +00:00
struct EnumParam
{
ECW_ACTION_T m_action;
CWinFileOpenImpl* m_instance;
EnumParam( ECW_ACTION_T action, CWinFileOpenImpl* instance ):
m_action( action ),
m_instance( instance )
{}
};
//-------------------------------------------------------------------------
//
//-------------------------------------------------------------------------
const OUString BACKSLASH = OUString::createFromAscii( "\\" );
const OUString FILTER_SEPARATOR = OUString::createFromAscii( "------------------------------------------" );
const OUString ALL_FILES_WILDCARD = OUString::createFromAscii( "*.*" );
const sal_Bool ALLOW_DUPLICATES = sal_True;
//-------------------------------------------------------------------------
// ctor
//-------------------------------------------------------------------------
CWinFileOpenImpl::CWinFileOpenImpl(
CFilePicker* aFilePicker,
sal_Bool bFileOpenDialog,
sal_uInt32 dwFlags,
sal_uInt32 dwTemplateId,
2002-03-21 06:37:13 +00:00
HINSTANCE hInstance) :
CFileOpenDialog(bFileOpenDialog, dwFlags, dwTemplateId, hInstance),
m_filterContainer( new CFilterContainer()),
m_Preview(new CPreviewAdapter(hInstance)),
m_CustomControlFactory(new CCustomControlFactory()),
m_CustomControls(m_CustomControlFactory->CreateCustomControlContainer()),
m_FilePicker(aFilePicker),
m_bInitialSelChanged(sal_True),
m_HelpPopupWindow(hInstance, m_hwndFileOpenDlg),
m_ExecuteFilePickerState(new CExecuteFilePickerState()),
m_NonExecuteFilePickerState(new CNonExecuteFilePickerState())
{
m_FilePickerState = m_NonExecuteFilePickerState;
}
//------------------------------------------------------------------------
// dtor
//------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
CWinFileOpenImpl::~CWinFileOpenImpl()
{
delete m_ExecuteFilePickerState;
delete m_NonExecuteFilePickerState;
}
//------------------------------------------------------------------------
// we expect the directory in URL format
//------------------------------------------------------------------------
void CWinFileOpenImpl::setDisplayDirectory( const OUString& aDirectory )
throw( IllegalArgumentException, RuntimeException )
{
OUString aSysDirectory;
if( aDirectory.getLength( ) > 0 )
{
if ( ::osl::FileBase::E_None !=
2002-03-21 06:37:13 +00:00
::osl::FileBase::getSystemPathFromFileURL(aDirectory,aSysDirectory))
throw IllegalArgumentException(
2002-03-21 06:37:13 +00:00
OUString::createFromAscii("Invalid directory"),
static_cast<XFilePicker*>(m_FilePicker), 1);
// we ensure that there is a trailing '/' at the end of
// he given file url, because the windows functions only
// works correctly when providing "c:\" or an environment
// variable like "=c:=c:\.." etc. is set, else the
// FolderPicker would stand in the root of the shell
// hierarchie which is the desktop folder
2002-03-21 06:37:13 +00:00
if ( aSysDirectory.lastIndexOf(BACKSLASH) != (aSysDirectory.getLength() - 1))
aSysDirectory += BACKSLASH;
}
// call base class method
2002-03-21 06:37:13 +00:00
CFileOpenDialog::setDisplayDirectory(aSysDirectory);
}
//------------------------------------------------------------------------
// we return the directory in URL format
//------------------------------------------------------------------------
OUString CWinFileOpenImpl::getDisplayDirectory( ) throw( RuntimeException )
{
return m_FilePickerState->getDisplayDirectory( this );
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::setDefaultName( const OUString& aName )
throw( IllegalArgumentException, RuntimeException )
{
// we don't set the default name directly
// because this influences how the file open
// dialog sets the initial path when it is about
// to open (see MSDN: OPENFILENAME)
// so we save the default name which should
// appear in the file-name-box and set
// this name when processing onInitDone
m_defaultName = aName;
}
//-----------------------------------------------------------------------------------------
// return format: URL
// if multiselection is allowed there are two different cases
// 1. one file selected: the sequence contains one entry path\filename.ext
// 2. multiple files selected: the sequence contains multiple entries
// the first entry is the path url, all other entries are file names
//-----------------------------------------------------------------------------------------
Sequence< OUString > SAL_CALL CWinFileOpenImpl::getFiles( ) throw(RuntimeException)
{
return m_FilePickerState->getFiles( this );
}
//-----------------------------------------------------------------------------------------
// shows the FileOpen/FileSave dialog
//-----------------------------------------------------------------------------------------
sal_Int16 SAL_CALL CWinFileOpenImpl::execute( ) throw(RuntimeException)
{
2002-03-21 06:37:13 +00:00
sal_Int16 rc = CFileOpenDialog::doModal();
if ( 1 == rc )
rc = ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK;
else if ( 0 == rc )
rc = ::com::sun::star::ui::dialogs::ExecutableDialogResults::CANCEL;
else
throw RuntimeException(
OUString::createFromAscii( "Error executing dialog" ),
static_cast< XFilePicker* >( m_FilePicker ) );
return rc;
}
//-----------------------------------------------------------------------------------------
// appends a new filter
// returns false if the title (aTitle) was already added or the title or the filter are
// empty
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::appendFilter( const OUString& aTitle, const OUString& aFilter )
throw(IllegalArgumentException, RuntimeException)
{
sal_Bool bRet = m_filterContainer->addFilter( aTitle, aFilter );
if ( !bRet )
throw IllegalArgumentException(
OUString::createFromAscii("filter already exists"),
static_cast< XFilePicker* >( m_FilePicker ),
1 );
// #95345# see MSDN OPENFILENAME
// If nFilterIndex is zero and lpstrCustomFilter is NULL,
// the system uses the first filter in the lpstrFilter buffer.
// to reflect this we must set the filter index so that calls
// to getSelectedFilterIndex without explicitly calling
// setFilterIndex before does not return 0 which leads to a
// false state
if ( 0 == getSelectedFilterIndex() )
CFileOpenDialog::setFilterIndex( 1 );
}
//-----------------------------------------------------------------------------------------
// sets a current filter
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::setCurrentFilter( const OUString& aTitle )
throw( IllegalArgumentException, RuntimeException)
{
sal_Int32 filterPos = m_filterContainer->getFilterPos( aTitle );
if ( filterPos < 0 )
throw IllegalArgumentException(
OUString::createFromAscii( "filter doesn't exist"),
static_cast< XFilePicker* >( m_FilePicker ),
1 );
// filter index of the base class starts with 1
CFileOpenDialog::setFilterIndex( filterPos + 1 );
}
//-----------------------------------------------------------------------------------------
// returns the currently selected filter
//-----------------------------------------------------------------------------------------
OUString SAL_CALL CWinFileOpenImpl::getCurrentFilter( ) throw(RuntimeException)
{
sal_uInt32 nIndex = getSelectedFilterIndex( );
OUString currentFilter;
if ( nIndex > 0 )
{
// filter index of the base class starts with 1
sal_Bool bRet = m_filterContainer->getFilter( nIndex - 1, currentFilter );
OSL_ASSERT( bRet );
}
return currentFilter;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
inline void SAL_CALL CWinFileOpenImpl::appendFilterGroupSeparator( )
{
m_filterContainer->addFilter( FILTER_SEPARATOR, ALL_FILES_WILDCARD, ALLOW_DUPLICATES );
}
//-----------------------------------------------------------------------------------------
// XFilterGroupManager
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::appendFilterGroup( const OUString& sGroupTitle, const Sequence< StringPair >& aFilters )
throw (IllegalArgumentException, RuntimeException)
{
OSL_ENSURE( 0 == sGroupTitle.getLength( ), "appendFilterGroup: Parameter 'GroupTitle' currently ignored" );
sal_Int32 nFilters = aFilters.getLength( );
OSL_PRECOND( nFilters > 0, "Empty filter list" );
if ( nFilters > 0 )
{
// append a separator before the next group if
// there is already a group of filters
if ( m_filterContainer->numFilter( ) > 0 )
appendFilterGroupSeparator( );
for ( int i = 0; i < nFilters; i++ )
appendFilter( aFilters[i].First, aFilters[i].Second );
}
}
//=================================================================================================================
// XExtendedFilePicker
//=================================================================================================================
void SAL_CALL CWinFileOpenImpl::setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const Any& aValue )
throw(RuntimeException)
{
OSL_ASSERT( m_FilePickerState );
m_FilePickerState->setValue( aControlId, aControlAction, aValue );
}
//-----------------------------------------------------------------------------------------
// returns the value of an custom template element
// we assume that there are only checkboxes or comboboxes
//-----------------------------------------------------------------------------------------
Any SAL_CALL CWinFileOpenImpl::getValue( sal_Int16 aControlId, sal_Int16 aControlAction )
throw(RuntimeException)
{
OSL_ASSERT( m_FilePickerState );
return m_FilePickerState->getValue( aControlId, aControlAction );
}
//-----------------------------------------------------------------------------------------
// enables a custom template element
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::enableControl( sal_Int16 ControlID, sal_Bool bEnable )
throw(RuntimeException)
{
OSL_ASSERT( m_FilePickerState );
m_FilePickerState->enableControl( ControlID, bEnable );
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::setLabel( sal_Int16 aControlId, const ::rtl::OUString& aLabel )
throw (RuntimeException)
{
m_FilePickerState->setLabel( aControlId, aLabel );
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
OUString SAL_CALL CWinFileOpenImpl::getLabel( sal_Int16 aControlId )
throw (RuntimeException)
{
return m_FilePickerState->getLabel( aControlId );
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
Sequence< sal_Int16 > SAL_CALL CWinFileOpenImpl::getSupportedImageFormats()
throw (RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->getSupportedImageFormats();
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Int32 SAL_CALL CWinFileOpenImpl::getTargetColorDepth()
throw (RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->getTargetColorDepth();
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableWidth()
throw (RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->getAvailableWidth();
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableHeight()
throw (::com::sun::star::uno::RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->getAvailableHeight();
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::setImage(sal_Int16 aImageFormat, const Any& aImage)
throw (IllegalArgumentException, RuntimeException)
{
2002-03-21 06:37:13 +00:00
m_Preview->setImage(aImageFormat,aImage);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Bool SAL_CALL CWinFileOpenImpl::setShowState(sal_Bool bShowState)
throw (::com::sun::star::uno::RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->setShowState(bShowState);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Bool SAL_CALL CWinFileOpenImpl::getShowState()
throw (RuntimeException)
{
2002-03-21 06:37:13 +00:00
return m_Preview->getShowState();
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::cancel()
{
2002-03-21 06:37:13 +00:00
if (IsWindow(m_hwndFileOpenDlg))
{
// simulate a mouse click to the
// cancel button
PostMessageA(
m_hwndFileOpenDlg,
WM_COMMAND,
2002-03-21 06:37:13 +00:00
MAKEWPARAM(IDCANCEL,BN_CLICKED),
(LPARAM)GetDlgItem(m_hwndFileOpenDlg, IDCANCEL));
}
}
//-----------------------------------------------------------------------------------------
// returns the id of a custom template element
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused()
{
2002-03-21 06:37:13 +00:00
sal_Int32 nID = GetDlgCtrlID(GetFocus());
// we don't forward id's of standard file open
// dialog elements (ctlFirst is defined in dlgs.h
// in MS Platform SDK)
2002-03-21 06:37:13 +00:00
if (nID >= ctlFirst)
nID = 0;
return nID;
}
2002-03-21 06:37:13 +00:00
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
inline sal_Bool SAL_CALL CWinFileOpenImpl::IsCustomControlHelpRequested(LPHELPINFO lphi) const
{
return ((lphi->iCtrlId != IDOK) && (lphi->iCtrlId != IDCANCEL) && (lphi->iCtrlId < ctlFirst));
}
//-----------------------------------------------------------------------------------------
// our own DlgProc because we do subclass the dialog
// we catch the WM_NCDESTROY message in order to erase an entry in our static map
// if one instance dies
//-----------------------------------------------------------------------------------------
unsigned int CALLBACK CWinFileOpenImpl::SubClassFunc(
2002-03-21 06:37:13 +00:00
HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam)
{
2001-07-09 11:58:25 +00:00
unsigned int lResult = 0;
2002-03-21 06:37:13 +00:00
CWinFileOpenImpl* pImpl = dynamic_cast<CWinFileOpenImpl*>(getCurrentInstance(hWnd));
2002-03-21 06:37:13 +00:00
switch(wMessage)
{
case WM_HELP:
{
2002-03-21 06:37:13 +00:00
LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
2002-03-21 06:37:13 +00:00
if (pImpl->IsCustomControlHelpRequested(lphi))
pImpl->onCustomControlHelpRequest(lphi);
else
lResult = CallWindowProcA(
2002-03-21 06:37:13 +00:00
reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
hWnd,wMessage,wParam,lParam);
}
break;
2002-03-21 06:37:13 +00:00
case WM_SIZE:
lResult = CallWindowProcA(
reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
hWnd,wMessage,wParam,lParam);
pImpl->onWMSize(hWnd,wParam,LOWORD(lParam),HIWORD(lParam));
break;
case WM_WINDOWPOSCHANGED:
lResult = CallWindowProcA(
reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
hWnd,wMessage,wParam,lParam);
pImpl->onWMWindowPosChanged(hWnd);
break;
case WM_SHOWWINDOW:
lResult = CallWindowProcA(
reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
hWnd,wMessage,wParam,lParam);
pImpl->onWMShow(hWnd,(BOOL)wParam,(int)lParam);
break;
default:
// !!! we use CallWindowProcA
lResult = CallWindowProcA(
2002-03-21 06:37:13 +00:00
reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc),
hWnd,wMessage,wParam,lParam);
break;
} // switch
return lResult;
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::InitControlLabel( HWND hWnd )
{
CResourceProvider aResProvider;
//-----------------------------------------
// set the labels for all extendet controls
//-----------------------------------------
2002-03-21 06:37:13 +00:00
sal_Int16 aCtrlId = GetDlgCtrlID(hWnd);
OUString aLabel = aResProvider.getResString(aCtrlId);
if ( aLabel.getLength( ) )
setLabel( aCtrlId, aLabel );
}
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
// There may be problems with the layout of our custom controls,
// so that they are not aligned with the standard controls of the
// FileOpen dialog.
// We use a simple algorithm to move the custom controls to their
// proper position and resize them.
// Our approach is to align all static text controls with the
// static text control "File name" of the FileOpen dialog,
// all checkboxes and all list/comboboxes will be left aligned with
// the standard combobox edt1 (defined in MS platform sdk dlgs.h)
// and all push buttons will be left aligned with the standard
// "OK" button
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::InitCustomControlContainer(HWND hCustomControl)
{
2002-03-21 06:37:13 +00:00
m_CustomControls->AddControl(
m_CustomControlFactory->CreateCustomControl(hCustomControl,m_hwndFileOpenDlg));
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::CacheControlState(HWND hWnd)
{
2002-03-21 06:37:13 +00:00
OSL_ASSERT(m_FilePickerState && m_NonExecuteFilePickerState);
m_ExecuteFilePickerState->cacheControlState(hWnd, m_NonExecuteFilePickerState);
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc(HWND hWnd, LPARAM lParam)
{
2001-07-09 11:58:25 +00:00
EnumParam* enumParam = (EnumParam*)lParam;
CWinFileOpenImpl* pImpl = enumParam->m_instance;
2002-03-21 06:37:13 +00:00
OSL_ASSERT(pImpl);
BOOL bRet = TRUE;
2002-03-21 06:37:13 +00:00
switch(enumParam->m_action)
{
2002-03-21 06:37:13 +00:00
case INIT_CUSTOM_CONTROLS:
pImpl->InitControlLabel(hWnd);
pImpl->InitCustomControlContainer(hWnd);
break;
case CACHE_CONTROL_VALUES:
2002-03-21 06:37:13 +00:00
pImpl->CacheControlState(hWnd);
break;
2001-07-09 11:58:25 +00:00
default:
// should not end here
2002-03-21 06:37:13 +00:00
OSL_ASSERT(sal_False);
}
return bRet;
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
sal_uInt32 SAL_CALL CWinFileOpenImpl::onFileOk()
{
2002-03-21 06:37:13 +00:00
m_NonExecuteFilePickerState->reset();
2001-07-09 11:58:25 +00:00
2002-03-21 06:37:13 +00:00
EnumParam enumParam(CACHE_CONTROL_VALUES,this);
2001-07-09 11:58:25 +00:00
EnumChildWindows(
m_hwndFileOpenDlgChild,
CWinFileOpenImpl::EnumChildWndProc,
2002-03-21 06:37:13 +00:00
(LPARAM)&enumParam);
return 0;
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::onSelChanged(HWND hwndListBox)
{
// the windows file open dialog sends an initial
// SelChanged message after the InitDone message
// when the dialog is about to be opened
// if the lpstrFile buffer of the OPENFILENAME is
// empty (zero length string) the windows file open
// dialog sends a WM_SETTEXT message with an empty
// string to the file name edit line
// this would overwritte our text when we would set
// the default name in onInitDone, so we have to
// remeber that this is the first SelChanged message
// and set the default name here to overwrite the
// windows setting
2002-03-21 06:37:13 +00:00
InitialSetDefaultName();
FilePickerEvent evt;
2002-03-21 06:37:13 +00:00
m_FilePicker->fileSelectionChanged(evt);
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::onInitDone()
{
2002-03-21 06:37:13 +00:00
m_Preview->setParent(m_hwndFileOpenDlg);
2001-07-09 11:58:25 +00:00
2002-03-21 06:37:13 +00:00
// but now we have a valid parent handle
m_HelpPopupWindow.setParent(m_hwndFileOpenDlg);
// initialize controls from cache
2002-03-21 06:37:13 +00:00
EnumParam enumParam(INIT_CUSTOM_CONTROLS,this);
2001-07-09 11:58:25 +00:00
EnumChildWindows(
m_hwndFileOpenDlgChild,
CWinFileOpenImpl::EnumChildWndProc,
2002-03-21 06:37:13 +00:00
(LPARAM)&enumParam);
2001-07-09 11:58:25 +00:00
2002-03-21 06:37:13 +00:00
m_ExecuteFilePickerState->setHwnd(m_hwndFileOpenDlgChild);
m_ExecuteFilePickerState->initFilePickerControls(
2002-03-21 06:37:13 +00:00
m_NonExecuteFilePickerState->getControlCommand());
m_FilePickerState = m_ExecuteFilePickerState;
2002-03-21 06:37:13 +00:00
SetDefaultExtension();
2002-03-21 06:37:13 +00:00
m_CustomControls->Align();
m_CustomControls->SetFont(
reinterpret_cast<HFONT>(SendMessageA(m_hwndFileOpenDlg, WM_GETFONT, 0, 0)));
// call the parent function to center the
// dialog to it's parent
CFileOpenDialog::onInitDone();
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
void SAL_CALL CWinFileOpenImpl::onFolderChanged()
{
FilePickerEvent evt;
2002-03-21 06:37:13 +00:00
m_FilePicker->directoryChanged(evt);
}
//-----------------------------------------------------------------
//
//-----------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::onTypeChanged(sal_uInt32 nFilterIndex)
{
2002-03-21 06:37:13 +00:00
SetDefaultExtension();
2001-07-09 11:58:25 +00:00
FilePickerEvent evt;
evt.ElementId = LISTBOX_FILTER;
2002-03-21 06:37:13 +00:00
m_FilePicker->controlStateChanged(evt);
}
//-----------------------------------------------------------------------------------------
// onMessageCommand handler
//-----------------------------------------------------------------------------------------
sal_uInt32 SAL_CALL CWinFileOpenImpl::onCtrlCommand(
2002-03-21 06:37:13 +00:00
HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode)
{
2002-03-21 06:37:13 +00:00
SetDefaultExtension();
2001-07-09 11:58:25 +00:00
2002-03-21 06:37:13 +00:00
if (ctrlId < ctlFirst)
{
FilePickerEvent evt;
evt.ElementId = ctrlId;
2002-03-21 06:37:13 +00:00
m_FilePicker->controlStateChanged(evt);
}
return 0;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
LRESULT SAL_CALL CWinFileOpenImpl::onWMSize(HWND hwnd, WPARAM type, WORD width, WORD height)
{
m_Preview->notifyParentSizeChanged();
m_CustomControls->Align();
m_FilePicker->dialogSizeChanged();
return 0;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
LRESULT SAL_CALL CWinFileOpenImpl::onWMShow(HWND hwnd, BOOL bShow, int fState)
{
m_Preview->notifyParentShow(bShow);
return 0;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
LRESULT SAL_CALL CWinFileOpenImpl::onWMWindowPosChanged(HWND hwnd)
{
LONG wl = GetWindowLong(hwnd,GWL_STYLE);
m_Preview->notifyParentWindowPosChanged(wl & WS_VISIBLE);
return 0;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
LRESULT SAL_CALL CWinFileOpenImpl::onCustomControlHelpRequest(LPHELPINFO lphi)
{
FilePickerEvent evt;
evt.ElementId = lphi->iCtrlId;
OUString aPopupHelpText = m_FilePicker->helpRequested(evt);
if (aPopupHelpText.getLength())
{
m_HelpPopupWindow.setText(aPopupHelpText);
DWORD dwMsgPos = GetMessagePos();
m_HelpPopupWindow.show(LOWORD(dwMsgPos),HIWORD(dwMsgPos));
}
return 0;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::onInitDialog(HWND hwndDlg, HWND hwndChild)
{
// subclass the dialog window
m_pfnOldDlgProc =
reinterpret_cast< DLGPROC >(
SetWindowLong( hwndDlg,
DWL_DLGPROC,
2002-03-21 06:37:13 +00:00
reinterpret_cast<DWORD>(SubClassFunc)));
}
//-----------------------------------------------------------------------------------------
// processing before showing the dialog
//-----------------------------------------------------------------------------------------
sal_Bool SAL_CALL CWinFileOpenImpl::preModal( )
{
CFileOpenDialog::setFilter(
2002-03-21 06:37:13 +00:00
makeWinFilterBuffer(*m_filterContainer.get()));
return sal_True;
}
//-----------------------------------------------------------------------------------------
// processing after showing the dialog
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void CWinFileOpenImpl::postModal(sal_Int16 nDialogResult)
{
2002-03-21 06:37:13 +00:00
CFileOpenDialog::postModal(nDialogResult);
m_FilePickerState = m_NonExecuteFilePickerState;
2001-07-09 11:58:25 +00:00
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::SetDefaultExtension()
2001-07-09 11:58:25 +00:00
{
// !!! HACK !!!
OSVERSIONINFOA OSVerInfo;
OSVerInfo.dwOSVersionInfoSize = sizeof( OSVERSIONINFOA );
GetVersionExA( &OSVerInfo );
// if windows 95/98
sal_Bool bIsWin9x = ( VER_PLATFORM_WIN32_WINDOWS == OSVerInfo.dwPlatformId );
HWND hwndChkSaveWithExt = GetDlgItem( m_hwndFileOpenDlgChild, 100 );
if ( hwndChkSaveWithExt )
{
Any aAny = CheckboxGetState( hwndChkSaveWithExt );
sal_Bool bChecked = *reinterpret_cast< const sal_Bool* >( aAny.getValue( ) );
if ( bChecked )
{
sal_uInt32 nIndex = getSelectedFilterIndex( );
OUString currentFilter;
if ( nIndex > 0 )
{
// filter index of the base class starts with 1
sal_Bool bRet = m_filterContainer->getFilter( nIndex - 1, currentFilter );
if ( currentFilter.getLength( ) )
{
OUString FilterExt;
m_filterContainer->getFilter( currentFilter, FilterExt );
sal_Int32 posOfPoint = FilterExt.indexOf( L'.' );
const sal_Unicode* pFirstExtStart = FilterExt.getStr( ) + posOfPoint + 1;
sal_Int32 posOfSemiColon = FilterExt.indexOf( L';' ) - 1;
if ( posOfSemiColon < 0 )
posOfSemiColon = FilterExt.getLength( ) - 1;
FilterExt = OUString( pFirstExtStart, posOfSemiColon - posOfPoint );
if ( bIsWin9x )
{
rtl::OString tmp = rtl::OUStringToOString( FilterExt, osl_getThreadTextEncoding( ) );
SendMessageA( m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, (LPARAM)( tmp.getStr( ) ) );
}
else
{
SendMessageW( m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, (LPARAM)( FilterExt.getStr( ) ) );
}
}
}
}
else
{
if ( bIsWin9x )
SendMessageA( m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, (LPARAM)"" );
else
SendMessageW( m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, (LPARAM)L"");
}
}
// !!! HACK !!!
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
2002-03-21 06:37:13 +00:00
void SAL_CALL CWinFileOpenImpl::InitialSetDefaultName()
{
// manually setting the file name that appears
// initially in the file-name-box of the file
// open dialog (reason: see above setDefaultName)
2002-03-21 06:37:13 +00:00
if (m_bInitialSelChanged && m_defaultName.getLength())
{
sal_Int32 edt1Id = edt1;
// under W2k the there is a combobox instead
// of an edit field for the file name edit field
// the control id of this box is cmb13 and not
// edt1 as before so we must use this id
if (IsWindows2000Platform())
edt1Id = cmb13;
2002-03-21 06:37:13 +00:00
HWND hwndEdt1 = GetDlgItem(m_hwndFileOpenDlg, edt1Id);
SetWindowTextW(hwndEdt1, m_defaultName.getStr());
}
m_bInitialSelChanged = sal_False;
}