From 9425f33a1fb121f6ad08aceb0760c34cf17463db Mon Sep 17 00:00:00 2001 From: Tino Rachui Date: Thu, 21 Mar 2002 06:37:13 +0000 Subject: #89491#support for resizing --- .../source/win32/filepicker/WinFileOpenImpl.cxx | 479 +++++++++------------ .../source/win32/filepicker/WinFileOpenImpl.hxx | 62 ++- fpicker/source/win32/filepicker/dibpreview.cxx | 346 +++++++++------ fpicker/source/win32/filepicker/dibpreview.hxx | 74 ++-- 4 files changed, 479 insertions(+), 482 deletions(-) (limited to 'fpicker') diff --git a/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx b/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx index 56c3e1808b99..b4e95d754b68 100644 --- a/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx +++ b/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx @@ -2,9 +2,9 @@ * * $RCSfile: WinFileOpenImpl.cxx,v $ * - * $Revision: 1.13 $ + * $Revision: 1.14 $ * - * last change: $Author: tra $ $Date: 2001-12-18 13:26:26 $ + * last change: $Author: tra $ $Date: 2002-03-21 07:37:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -111,10 +111,6 @@ #include "controlaccess.hxx" #endif -#ifndef _DIBPREVIEW_HXX_ -#include "dibpreview.hxx" -#endif - #ifndef _RTL_USTRBUF_HXX_ #include #endif @@ -167,8 +163,7 @@ using namespace ::com::sun::star::ui::dialogs::ListboxControlActions; enum ECW_ACTION_T { - CHECK_PREVIEW = 0, - INIT_CONTROL_LABEL, + INIT_CUSTOM_CONTROLS, CACHE_CONTROL_VALUES }; @@ -201,15 +196,17 @@ CWinFileOpenImpl::CWinFileOpenImpl( sal_Bool bFileOpenDialog, sal_uInt32 dwFlags, sal_uInt32 dwTemplateId, - HINSTANCE hInstance ) : - CFileOpenDialog( bFileOpenDialog, dwFlags, dwTemplateId, hInstance ), - m_filterContainer( new CFilterContainer( ) ), - m_FilePicker( aFilePicker ), - m_bPreviewExists( sal_False ), - m_bInitialSelChanged( sal_True ), - m_HelpPopupWindow( hInstance, m_hwndFileOpenDlg ), - m_ExecuteFilePickerState( new CExecuteFilePickerState( ) ), - m_NonExecuteFilePickerState( new CNonExecuteFilePickerState( ) ) + 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; } @@ -218,7 +215,7 @@ CWinFileOpenImpl::CWinFileOpenImpl( // dtor //------------------------------------------------------------------------ -CWinFileOpenImpl::~CWinFileOpenImpl( ) +CWinFileOpenImpl::~CWinFileOpenImpl() { delete m_ExecuteFilePickerState; delete m_NonExecuteFilePickerState; @@ -235,11 +232,10 @@ void CWinFileOpenImpl::setDisplayDirectory( const OUString& aDirectory ) if( aDirectory.getLength( ) > 0 ) { if ( ::osl::FileBase::E_None != - ::osl::FileBase::getSystemPathFromFileURL( aDirectory, aSysDirectory ) ) + ::osl::FileBase::getSystemPathFromFileURL(aDirectory,aSysDirectory)) throw IllegalArgumentException( - OUString::createFromAscii( "Invalid directory" ), - static_cast< XFilePicker* >( m_FilePicker ), - 1 ); + OUString::createFromAscii("Invalid directory"), + static_cast(m_FilePicker), 1); // we ensure that there is a trailing '/' at the end of // he given file url, because the windows functions only @@ -247,12 +243,12 @@ void CWinFileOpenImpl::setDisplayDirectory( const OUString& aDirectory ) // variable like "=c:=c:\.." etc. is set, else the // FolderPicker would stand in the root of the shell // hierarchie which is the desktop folder - if ( aSysDirectory.lastIndexOf( BACKSLASH ) != (aSysDirectory.getLength( ) - 1) ) + if ( aSysDirectory.lastIndexOf(BACKSLASH) != (aSysDirectory.getLength() - 1)) aSysDirectory += BACKSLASH; } // call base class method - CFileOpenDialog::setDisplayDirectory( aSysDirectory ); + CFileOpenDialog::setDisplayDirectory(aSysDirectory); } //------------------------------------------------------------------------ @@ -261,7 +257,6 @@ void CWinFileOpenImpl::setDisplayDirectory( const OUString& aDirectory ) OUString CWinFileOpenImpl::getDisplayDirectory( ) throw( RuntimeException ) { - OSL_ASSERT( m_FilePickerState ); return m_FilePickerState->getDisplayDirectory( this ); } @@ -292,7 +287,6 @@ void SAL_CALL CWinFileOpenImpl::setDefaultName( const OUString& aName ) Sequence< OUString > SAL_CALL CWinFileOpenImpl::getFiles( ) throw(RuntimeException) { - OSL_ASSERT( m_FilePickerState ); return m_FilePickerState->getFiles( this ); } @@ -302,7 +296,7 @@ Sequence< OUString > SAL_CALL CWinFileOpenImpl::getFiles( ) throw(RuntimeExcept sal_Int16 SAL_CALL CWinFileOpenImpl::execute( ) throw(RuntimeException) { - sal_Int16 rc = CFileOpenDialog::doModal( ); + sal_Int16 rc = CFileOpenDialog::doModal(); if ( 1 == rc ) rc = ::com::sun::star::ui::dialogs::ExecutableDialogResults::OK; @@ -457,7 +451,6 @@ void SAL_CALL CWinFileOpenImpl::enableControl( sal_Int16 ControlID, sal_Bool bEn void SAL_CALL CWinFileOpenImpl::setLabel( sal_Int16 aControlId, const ::rtl::OUString& aLabel ) throw (RuntimeException) { - OSL_ASSERT( m_FilePickerState ); m_FilePickerState->setLabel( aControlId, aLabel ); } @@ -468,7 +461,6 @@ void SAL_CALL CWinFileOpenImpl::setLabel( sal_Int16 aControlId, const ::rtl::OUS OUString SAL_CALL CWinFileOpenImpl::getLabel( sal_Int16 aControlId ) throw (RuntimeException) { - OSL_ASSERT( m_FilePickerState ); return m_FilePickerState->getLabel( aControlId ); } @@ -476,128 +468,87 @@ OUString SAL_CALL CWinFileOpenImpl::getLabel( sal_Int16 aControlId ) // //----------------------------------------------------------------------------------------- -Sequence< sal_Int16 > SAL_CALL CWinFileOpenImpl::getSupportedImageFormats( ) +Sequence< sal_Int16 > SAL_CALL CWinFileOpenImpl::getSupportedImageFormats() throw (RuntimeException) { - Sequence< sal_Int16 > imgFormatList( 1 ); - imgFormatList[0] = ::com::sun::star::ui::dialogs::FilePreviewImageFormats::BITMAP; - return imgFormatList; + return m_Preview->getSupportedImageFormats(); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -sal_Int32 SAL_CALL CWinFileOpenImpl::getTargetColorDepth( ) +sal_Int32 SAL_CALL CWinFileOpenImpl::getTargetColorDepth() throw (RuntimeException) { - if ( m_DIBPreview.get( ) ) - return m_DIBPreview->getColorDepth( ); - - return 0; + return m_Preview->getTargetColorDepth(); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableWidth( ) +sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableWidth() throw (RuntimeException) { - if ( m_DIBPreview.get( ) ) - return m_DIBPreview->getWidth( ); - - return 0; + return m_Preview->getAvailableWidth(); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableHeight( ) +sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableHeight() throw (::com::sun::star::uno::RuntimeException) { - if ( m_DIBPreview.get( ) ) - return m_DIBPreview->getHeight( ); - - return 0; + return m_Preview->getAvailableHeight(); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::setImage( sal_Int16 aImageFormat, const Any& aImage ) +void SAL_CALL CWinFileOpenImpl::setImage(sal_Int16 aImageFormat, const Any& aImage) throw (IllegalArgumentException, RuntimeException) { - if ( m_DIBPreview.get( ) ) - { - if ( aImageFormat != ::com::sun::star::ui::dialogs::FilePreviewImageFormats::BITMAP ) - throw IllegalArgumentException( - OUString::createFromAscii("unsupported image format"), - static_cast< XFilePicker* >( m_FilePicker ), - 1 ); - - if ( aImage.hasValue( ) && - (aImage.getValueType( ) != getCppuType( (Sequence< sal_Int8 >*) 0 ) ) ) - throw IllegalArgumentException( - OUString::createFromAscii("invalid image data"), - static_cast< XFilePicker* >( m_FilePicker ), - 2 ); - - Sequence< sal_Int8 > ImageData; - - // if the any has no value we have an - // empty Sequence which clears the - // preview window - if ( aImage.hasValue( ) ) - aImage >>= ImageData; - - m_DIBPreview->setImage( ImageData ); - } + m_Preview->setImage(aImageFormat,aImage); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -sal_Bool SAL_CALL CWinFileOpenImpl::setShowState( sal_Bool bShowState ) +sal_Bool SAL_CALL CWinFileOpenImpl::setShowState(sal_Bool bShowState) throw (::com::sun::star::uno::RuntimeException) { - if ( m_DIBPreview.get( ) ) - return m_DIBPreview->show( bShowState ); - - return sal_False; + return m_Preview->setShowState(bShowState); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -sal_Bool SAL_CALL CWinFileOpenImpl::getShowState( ) +sal_Bool SAL_CALL CWinFileOpenImpl::getShowState() throw (RuntimeException) { - if ( m_DIBPreview.get( ) ) - return m_DIBPreview->isVisible( ); - - return sal_False; + return m_Preview->getShowState(); } //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::cancel( ) +void SAL_CALL CWinFileOpenImpl::cancel() { - if ( IsWindow( m_hwndFileOpenDlg ) ) + if (IsWindow(m_hwndFileOpenDlg)) { // simulate a mouse click to the // cancel button PostMessageA( m_hwndFileOpenDlg, WM_COMMAND, - MAKEWPARAM( IDCANCEL, BN_CLICKED ), - (LPARAM)GetDlgItem( m_hwndFileOpenDlg, IDCANCEL ) ); + MAKEWPARAM(IDCANCEL,BN_CLICKED), + (LPARAM)GetDlgItem(m_hwndFileOpenDlg, IDCANCEL)); } } @@ -605,19 +556,28 @@ void SAL_CALL CWinFileOpenImpl::cancel( ) // returns the id of a custom template element //----------------------------------------------------------------------------------------- -sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused( ) +sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused() { - sal_Int32 nID = GetDlgCtrlID( GetFocus( ) ); + 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) - if ( nID >= ctlFirst ) + if (nID >= ctlFirst) nID = 0; return nID; } +//----------------------------------------------------------------------------------------- +// +//----------------------------------------------------------------------------------------- + +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 @@ -625,56 +585,56 @@ sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused( ) //----------------------------------------------------------------------------------------- unsigned int CALLBACK CWinFileOpenImpl::SubClassFunc( - HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam ) + HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam) { unsigned int lResult = 0; - CWinFileOpenImpl* pImpl = - dynamic_cast< CWinFileOpenImpl* >( - getCurrentInstance( hWnd ) ); - OSL_ASSERT( pImpl ); + CWinFileOpenImpl* pImpl = dynamic_cast(getCurrentInstance(hWnd)); - switch( wMessage ) + switch(wMessage) { case WM_HELP: { - LPHELPINFO lphi = reinterpret_cast< LPHELPINFO >( lParam ); - - // we handle only our own elements ourself - if ( (lphi->iCtrlId != IDOK) && (lphi->iCtrlId != IDCANCEL) && (lphi->iCtrlId < ctlFirst) ) - { - FilePickerEvent evt; - evt.ElementId = lphi->iCtrlId; - - OUString aPopupHelpText = pImpl->m_FilePicker->helpRequested( evt ); - - if ( aPopupHelpText.getLength( ) ) - { - pImpl->m_HelpPopupWindow.setText( aPopupHelpText ); + LPHELPINFO lphi = reinterpret_cast(lParam); - DWORD dwMsgPos = GetMessagePos( ); - pImpl->m_HelpPopupWindow.show( LOWORD( dwMsgPos ), HIWORD( dwMsgPos ) ); - } - } - else // call the standard help + if (pImpl->IsCustomControlHelpRequested(lphi)) + pImpl->onCustomControlHelpRequest(lphi); + else lResult = CallWindowProcA( - reinterpret_cast< WNDPROC >( pImpl->m_pfnOldDlgProc ), - hWnd, - wMessage, - wParam, - lParam ); + reinterpret_cast(pImpl->m_pfnOldDlgProc), + hWnd,wMessage,wParam,lParam); } break; + case WM_SIZE: + lResult = CallWindowProcA( + reinterpret_cast(pImpl->m_pfnOldDlgProc), + hWnd,wMessage,wParam,lParam); + + pImpl->onWMSize(hWnd,wParam,LOWORD(lParam),HIWORD(lParam)); + break; + + case WM_WINDOWPOSCHANGED: + lResult = CallWindowProcA( + reinterpret_cast(pImpl->m_pfnOldDlgProc), + hWnd,wMessage,wParam,lParam); + + pImpl->onWMWindowPosChanged(hWnd); + break; + + case WM_SHOWWINDOW: + lResult = CallWindowProcA( + reinterpret_cast(pImpl->m_pfnOldDlgProc), + hWnd,wMessage,wParam,lParam); + + pImpl->onWMShow(hWnd,(BOOL)wParam,(int)lParam); + break; + default: // !!! we use CallWindowProcA lResult = CallWindowProcA( - reinterpret_cast< WNDPROC >( pImpl->m_pfnOldDlgProc ), - hWnd, - wMessage, - wParam, - lParam ); - + reinterpret_cast(pImpl->m_pfnOldDlgProc), + hWnd,wMessage,wParam,lParam); break; } // switch @@ -694,65 +654,69 @@ void SAL_CALL CWinFileOpenImpl::InitControlLabel( HWND hWnd ) // set the labels for all extendet controls //----------------------------------------- - sal_Int16 aCtrlId = GetDlgCtrlID( hWnd ); - OUString aLabel = aResProvider.getResString( aCtrlId ); + sal_Int16 aCtrlId = GetDlgCtrlID(hWnd); + OUString aLabel = aResProvider.getResString(aCtrlId); if ( aLabel.getLength( ) ) setLabel( aCtrlId, aLabel ); } //----------------------------------------------------------------- -// +// 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 //----------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::CacheControlState( HWND hWnd ) +void SAL_CALL CWinFileOpenImpl::InitCustomControlContainer(HWND hCustomControl) { - OSL_ASSERT( m_FilePickerState && m_NonExecuteFilePickerState ); - m_ExecuteFilePickerState->cacheControlState( hWnd, m_NonExecuteFilePickerState ); + m_CustomControls->AddControl( + m_CustomControlFactory->CreateCustomControl(hCustomControl,m_hwndFileOpenDlg)); } //----------------------------------------------------------------- // //----------------------------------------------------------------- -sal_Bool SAL_CALL CWinFileOpenImpl::HasPreview( HWND hWnd ) +void SAL_CALL CWinFileOpenImpl::CacheControlState(HWND hWnd) { - if ( CHECKBOX_PREVIEW == GetDlgCtrlID( hWnd ) ) - m_bPreviewExists = sal_True; - - return m_bPreviewExists; + OSL_ASSERT(m_FilePickerState && m_NonExecuteFilePickerState); + m_ExecuteFilePickerState->cacheControlState(hWnd, m_NonExecuteFilePickerState); } //----------------------------------------------------------------- // //----------------------------------------------------------------- -BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc( HWND hWnd, LPARAM lParam ) +BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc(HWND hWnd, LPARAM lParam) { EnumParam* enumParam = (EnumParam*)lParam; CWinFileOpenImpl* pImpl = enumParam->m_instance; - OSL_ASSERT( pImpl ); + OSL_ASSERT(pImpl); BOOL bRet = TRUE; - switch( enumParam->m_action ) + switch(enumParam->m_action) { - case CHECK_PREVIEW: - if ( pImpl->HasPreview( hWnd ) ) - bRet = FALSE; - break; - - case INIT_CONTROL_LABEL: - pImpl->InitControlLabel( hWnd ); - break; + case INIT_CUSTOM_CONTROLS: + pImpl->InitControlLabel(hWnd); + pImpl->InitCustomControlContainer(hWnd); + break; case CACHE_CONTROL_VALUES: - pImpl->CacheControlState( hWnd ); + pImpl->CacheControlState(hWnd); break; default: // should not end here - OSL_ASSERT( sal_False ); + OSL_ASSERT(sal_False); } return bRet; @@ -764,14 +728,14 @@ BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc( HWND hWnd, LPARAM lParam ) sal_uInt32 SAL_CALL CWinFileOpenImpl::onFileOk() { - m_NonExecuteFilePickerState->reset( ); + m_NonExecuteFilePickerState->reset(); - EnumParam enumParam( CACHE_CONTROL_VALUES, this ); + EnumParam enumParam(CACHE_CONTROL_VALUES,this); EnumChildWindows( m_hwndFileOpenDlgChild, CWinFileOpenImpl::EnumChildWndProc, - (LPARAM)&enumParam ); + (LPARAM)&enumParam); return 0; } @@ -780,7 +744,7 @@ sal_uInt32 SAL_CALL CWinFileOpenImpl::onFileOk() // //----------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::onSelChanged( HWND hwndListBox ) +void SAL_CALL CWinFileOpenImpl::onSelChanged(HWND hwndListBox) { // the windows file open dialog sends an initial // SelChanged message after the InitDone message @@ -794,10 +758,10 @@ void SAL_CALL CWinFileOpenImpl::onSelChanged( HWND hwndListBox ) // remeber that this is the first SelChanged message // and set the default name here to overwrite the // windows setting - InitialSetDefaultName( ); + InitialSetDefaultName(); FilePickerEvent evt; - m_FilePicker->fileSelectionChanged( evt ); + m_FilePicker->fileSelectionChanged(evt); } //----------------------------------------------------------------- @@ -806,118 +770,33 @@ void SAL_CALL CWinFileOpenImpl::onSelChanged( HWND hwndListBox ) void SAL_CALL CWinFileOpenImpl::onInitDone() { - // we check if the checkbox is present and if so - // create a preview window - EnumParam enumParam( CHECK_PREVIEW, this ); + m_Preview->setParent(m_hwndFileOpenDlg); - EnumChildWindows( - m_hwndFileOpenDlgChild, - CWinFileOpenImpl::EnumChildWndProc, - (LPARAM)&enumParam ); - - // create and display the preview control - - if ( m_bPreviewExists ) - { - // lst1 is the file listbox and is defined by MS in dlgs.h - HWND hwndFileListbox = GetDlgItem( m_hwndFileOpenDlg, lst1 ); - OSL_ASSERT( IsWindow( hwndFileListbox ) ); - - // save the original size of the file listbox - RECT rcFileListbox; - GetWindowRect( hwndFileListbox, &rcFileListbox ); - - m_SizeFileListBoxOriginal = std::make_pair( - rcFileListbox.right - rcFileListbox.left, - rcFileListbox.bottom - rcFileListbox.top ); - - // shrink the width of the fileopen file listbox - sal_uInt32 newWidthFileListbox = - static_cast< sal_uInt32 >( - (rcFileListbox.right - rcFileListbox.left) / 2); - - // resize the fileopen file listbox - SetWindowPos( hwndFileListbox, - NULL, 0, 0, newWidthFileListbox, - m_SizeFileListBoxOriginal.second, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); - - // get the new size of the file listbox - GetWindowRect( hwndFileListbox, &rcFileListbox ); - - POINT ulCorner; - ulCorner.x = rcFileListbox.right; - ulCorner.y = rcFileListbox.top; - - ScreenToClient( m_hwndFileOpenDlg, &ulCorner ); - - DIMENSION_T sizePreviewWnd = std::make_pair( - (rcFileListbox.right - rcFileListbox.left) - 3, - (rcFileListbox.bottom - rcFileListbox.top) ); - - // we try to get a window handle to a control with - // the id 1119 which is defined as stc32 in the - // Platform SDK header files and has a special - // meaning (see MSDN under the title: - // "Explorer-Style Custom Templates") - // if this control is available, all standard controls, - // will be placed on this control, so we have to use - // it as parent for our preview window else the stc32 - // control may paint over the client area of our - // preview control - // if there is no stc32 control, all standard controls - // are childs of the dialog box itself - HWND hwndParent; - HWND hwndStc32 = GetDlgItem( m_hwndFileOpenDlgChild, 1119 ); - if ( IsWindow( hwndStc32 ) ) - hwndParent = hwndStc32; - else - hwndParent = m_hwndFileOpenDlg; - - // as parent we use the - CDIBPreview* pDIBPreview = new CDIBPreview( - ulCorner.x, - ulCorner.y, - sizePreviewWnd.first, - sizePreviewWnd.second, - hwndParent, - m_ofn.hInstance ); - - m_DIBPreview.reset( pDIBPreview ); - - // restore the origional size of the file listbox on failure - if ( m_DIBPreview.get( ) && - !(m_DIBPreview->getWidth( ) && m_DIBPreview->getHeight( )) ) - { - SetWindowPos( hwndFileListbox, - NULL, 0, 0, - m_SizeFileListBoxOriginal.first, - m_SizeFileListBoxOriginal.second, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); - } - } + // but now we have a valid parent handle + m_HelpPopupWindow.setParent(m_hwndFileOpenDlg); // initialize controls from cache - enumParam.m_action = INIT_CONTROL_LABEL; - enumParam.m_instance = this; + EnumParam enumParam(INIT_CUSTOM_CONTROLS,this); EnumChildWindows( m_hwndFileOpenDlgChild, CWinFileOpenImpl::EnumChildWndProc, - (LPARAM)&enumParam ); + (LPARAM)&enumParam); - m_ExecuteFilePickerState->setHwnd( m_hwndFileOpenDlgChild ); + m_ExecuteFilePickerState->setHwnd(m_hwndFileOpenDlgChild); m_ExecuteFilePickerState->initFilePickerControls( - m_NonExecuteFilePickerState->getControlCommand( ) ); + m_NonExecuteFilePickerState->getControlCommand()); m_FilePickerState = m_ExecuteFilePickerState; - SetDefaultExtension( ); + SetDefaultExtension(); - // but now we have a valid parent handle - m_HelpPopupWindow.setParent( m_hwndFileOpenDlg ); + m_CustomControls->Align(); + + m_CustomControls->SetFont( + reinterpret_cast(SendMessageA(m_hwndFileOpenDlg, WM_GETFONT, 0, 0))); // call the parent function to center the // dialog to it's parent @@ -931,20 +810,20 @@ void SAL_CALL CWinFileOpenImpl::onInitDone() void SAL_CALL CWinFileOpenImpl::onFolderChanged() { FilePickerEvent evt; - m_FilePicker->directoryChanged( evt ); + m_FilePicker->directoryChanged(evt); } //----------------------------------------------------------------- // //----------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::onTypeChanged( sal_uInt32 nFilterIndex ) +void SAL_CALL CWinFileOpenImpl::onTypeChanged(sal_uInt32 nFilterIndex) { - SetDefaultExtension( ); + SetDefaultExtension(); FilePickerEvent evt; evt.ElementId = LISTBOX_FILTER; - m_FilePicker->controlStateChanged( evt ); + m_FilePicker->controlStateChanged(evt); } //----------------------------------------------------------------------------------------- @@ -952,15 +831,70 @@ void SAL_CALL CWinFileOpenImpl::onTypeChanged( sal_uInt32 nFilterIndex ) //----------------------------------------------------------------------------------------- sal_uInt32 SAL_CALL CWinFileOpenImpl::onCtrlCommand( - HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode ) + HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode) { - SetDefaultExtension( ); + SetDefaultExtension(); - if ( ctrlId < ctlFirst ) + if (ctrlId < ctlFirst) { FilePickerEvent evt; evt.ElementId = ctrlId; - m_FilePicker->controlStateChanged( evt ); + 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; @@ -970,14 +904,14 @@ sal_uInt32 SAL_CALL CWinFileOpenImpl::onCtrlCommand( // //----------------------------------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::onInitDialog( HWND hwndDlg, HWND hwndChild ) +void SAL_CALL CWinFileOpenImpl::onInitDialog(HWND hwndDlg, HWND hwndChild) { // subclass the dialog window m_pfnOldDlgProc = reinterpret_cast< DLGPROC >( SetWindowLong( hwndDlg, DWL_DLGPROC, - reinterpret_cast< DWORD >( SubClassFunc ) ) ); + reinterpret_cast(SubClassFunc))); } //----------------------------------------------------------------------------------------- @@ -987,7 +921,7 @@ void SAL_CALL CWinFileOpenImpl::onInitDialog( HWND hwndDlg, HWND hwndChild ) sal_Bool SAL_CALL CWinFileOpenImpl::preModal( ) { CFileOpenDialog::setFilter( - makeWinFilterBuffer( *m_filterContainer.get( ) ) ); + makeWinFilterBuffer(*m_filterContainer.get())); return sal_True; } @@ -996,10 +930,9 @@ sal_Bool SAL_CALL CWinFileOpenImpl::preModal( ) // processing after showing the dialog //----------------------------------------------------------------------------------------- -void CWinFileOpenImpl::postModal( sal_Int16 nDialogResult ) +void CWinFileOpenImpl::postModal(sal_Int16 nDialogResult) { - CFileOpenDialog::postModal( nDialogResult ); - + CFileOpenDialog::postModal(nDialogResult); m_FilePickerState = m_NonExecuteFilePickerState; } @@ -1007,7 +940,7 @@ void CWinFileOpenImpl::postModal( sal_Int16 nDialogResult ) // //----------------------------------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::SetDefaultExtension( ) +void SAL_CALL CWinFileOpenImpl::SetDefaultExtension() { // !!! HACK !!! @@ -1079,12 +1012,12 @@ void SAL_CALL CWinFileOpenImpl::SetDefaultExtension( ) // //----------------------------------------------------------------------------------------- -void SAL_CALL CWinFileOpenImpl::InitialSetDefaultName( ) +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) - if ( m_bInitialSelChanged && m_defaultName.getLength( ) ) + if (m_bInitialSelChanged && m_defaultName.getLength()) { sal_Int32 edt1Id = edt1; @@ -1092,11 +1025,11 @@ void SAL_CALL CWinFileOpenImpl::InitialSetDefaultName( ) // 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 ( IsWin2000( ) ) + if (IsWindows2000()) edt1Id = cmb13; - HWND hwndEdt1 = GetDlgItem( m_hwndFileOpenDlg, edt1Id ); - SetWindowTextW( hwndEdt1, m_defaultName.getStr( ) ); + HWND hwndEdt1 = GetDlgItem(m_hwndFileOpenDlg, edt1Id); + SetWindowTextW(hwndEdt1, m_defaultName.getStr()); } m_bInitialSelChanged = sal_False; diff --git a/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx b/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx index 7731ff3ff47c..7ea6247787e1 100644 --- a/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx +++ b/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx @@ -2,9 +2,9 @@ * * $RCSfile: WinFileOpenImpl.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.9 $ * - * last change: $Author: tra $ $Date: 2001-10-16 14:03:12 $ + * last change: $Author: tra $ $Date: 2002-03-21 07:37:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -87,14 +87,22 @@ #include "FileOpenDlg.hxx" #endif -#ifndef _DIBPREVIEW_HXX_ -#include "dibpreview.hxx" +#ifndef _PREVIEWADAPTER_HXX_ +#include "previewadapter.hxx" #endif #ifndef _HELPPOPUPWINDOW_HXX_ #include "helppopupwindow.hxx" #endif +#ifndef _CUSTOMCONTROL_HXX_ +#include "customcontrol.hxx" +#endif + +#ifndef _CUSTOMCONTROLFACTORY_HXX_ +#include "customcontrolfactory.hxx" +#endif + #include #include #include @@ -210,8 +218,16 @@ public: virtual sal_Bool SAL_CALL getShowState( ) throw (::com::sun::star::uno::RuntimeException); + //------------------------------------------------ + // XCancelable + //------------------------------------------------ + virtual void SAL_CALL cancel( ); + //------------------------------------------------ + // Implementation details + //------------------------------------------------ + protected: sal_Int16 SAL_CALL getFocused( ); @@ -231,18 +247,24 @@ protected: virtual sal_uInt32 SAL_CALL onCtrlCommand( HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode ); + + LRESULT SAL_CALL onWMSize(HWND hwnd, WPARAM type, WORD width, WORD height ); + LRESULT SAL_CALL onWMShow(HWND hwnd, BOOL bShow, int fState); + LRESULT SAL_CALL onWMWindowPosChanged(HWND hwnd); + LRESULT SAL_CALL onCustomControlHelpRequest(LPHELPINFO lphi); + private: inline void SAL_CALL appendFilterGroupSeparator( ); + inline sal_Bool SAL_CALL IsCustomControlHelpRequested(LPHELPINFO lphi) const; + // initialize all controls from cache void SAL_CALL InitControlLabel( HWND hWnd ); + void SAL_CALL InitCustomControlContainer(HWND hCustomControl); // save the control state void SAL_CALL CacheControlState( HWND hWnd ); - // checks wether there is the checkbox preview - sal_Bool SAL_CALL HasPreview( HWND hWnd ); - void SAL_CALL SetDefaultExtension( ); void SAL_CALL InitialSetDefaultName( ); @@ -250,21 +272,19 @@ private: static BOOL CALLBACK EnumChildWndProc( HWND hWnd, LPARAM lParam ); - typedef std::pair< int, int > DIMENSION_T; - private: - std::auto_ptr< CFilterContainer > m_filterContainer; - std::auto_ptr< CDIBPreview > m_DIBPreview; - sal_Bool m_bPreviewExists; - CFilePicker* m_FilePicker; - DLGPROC m_pfnOldDlgProc; - DIMENSION_T m_SizeFileListBoxOriginal; - rtl::OUString m_defaultName; - sal_Bool m_bInitialSelChanged; - CHelpPopupWindow m_HelpPopupWindow; - CFilePickerState* m_FilePickerState; - CExecuteFilePickerState* m_ExecuteFilePickerState; - CNonExecuteFilePickerState* m_NonExecuteFilePickerState; + std::auto_ptr m_filterContainer; + std::auto_ptr m_Preview; + std::auto_ptr m_CustomControlFactory; + std::auto_ptr m_CustomControls; + CFilePicker* m_FilePicker; + DLGPROC m_pfnOldDlgProc; + rtl::OUString m_defaultName; + sal_Bool m_bInitialSelChanged; + CHelpPopupWindow m_HelpPopupWindow; + CFilePickerState* m_FilePickerState; + CExecuteFilePickerState* m_ExecuteFilePickerState; + CNonExecuteFilePickerState* m_NonExecuteFilePickerState; }; diff --git a/fpicker/source/win32/filepicker/dibpreview.cxx b/fpicker/source/win32/filepicker/dibpreview.cxx index 8fca79d15612..b91915c32a71 100644 --- a/fpicker/source/win32/filepicker/dibpreview.cxx +++ b/fpicker/source/win32/filepicker/dibpreview.cxx @@ -2,9 +2,9 @@ * * $RCSfile: dibpreview.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: tra $ $Date: 2001-07-11 09:20:28 $ + * last change: $Author: tra $ $Date: 2002-03-21 07:37:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,17 @@ #include #endif +#ifndef _COM_SUN_STAR_UI_DIALOG_FILEPREVIEWIMAGEFORMATS_HPP_ +#include +#endif + +#ifndef _USTRING_HXX_ +#include +#endif + +#include +#include + #include //------------------------------------------------------------------------ @@ -78,6 +89,10 @@ //------------------------------------------------------------------------ using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Any; +using ::com::sun::star::lang::IllegalArgumentException; +using rtl::OUString; //------------------------------------------------------------------------ // @@ -85,9 +100,7 @@ using ::com::sun::star::uno::Sequence; namespace /* private */ { - const char* CURRENT_INSTANCE = "CurrInst"; - }; //------------------------------------------------------------------------ @@ -114,38 +127,36 @@ sal_Int32 CDIBPreview::s_RegisterDibPreviewWndCount = 0; // //--------------------------------------------------- -CDIBPreview::CDIBPreview( - sal_Int32 x, - sal_Int32 y, - sal_Int32 cx, - sal_Int32 cy, - HWND aParent, - HINSTANCE hInstance, - sal_Bool bShow ) : - m_hwnd( NULL ), - m_hInstance( hInstance ), - m_bWndClassRegistered( sal_False ) +CDIBPreview::CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow) : + m_Instance(instance) { - if ( RegisterDibPreviewWindowClass( ) ) + RegisterDibPreviewWindowClass(); + + DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; + + if (bShowWindow) + dwStyle |= WS_VISIBLE; + + m_Hwnd = CreateWindowExW( + WS_EX_CLIENTEDGE, PREVIEWWND_CLASS_NAME, L"", + dwStyle, + 0, 0, 0, 0, + parent, + (HMENU)0x0, // for child windows this will + // be used as child window identifier + m_Instance, + (LPVOID)this // pass a pointer to the current + // instance of this class + ); + + bool bSuccess = IsWindow(m_Hwnd); + + OSL_POSTCOND(bSuccess,"Coud not create preview window"); + + if (!bSuccess) { - m_bWndClassRegistered = sal_True; - - // create the preview window in invisible state - sal_uInt32 dwStyle = bShow ? (WS_CHILD | WS_VISIBLE ) : (WS_CHILD ); - m_hwnd = CreateWindowExW( - WS_EX_CLIENTEDGE, - PREVIEWWND_CLASS_NAME, - L"", dwStyle, - x, y, cx, cy, - aParent, - (HMENU)0x0, // for child windows this will - // be used as child window identifier - m_hInstance, - (LPVOID)this // pass a pointer to the current - // instance of this class - ); - - OSL_ASSERT( IsWindow( m_hwnd ) ); + UnregisterDibPreviewWindowClass(); + throw std::runtime_error("Could not create preview window"); } } @@ -159,29 +170,33 @@ CDIBPreview::~CDIBPreview( ) // preview window because it will be destroyed // by it's parent window (the FileOpen dialog) // but we have to unregister the window class - if ( m_bWndClassRegistered ) - UnregisterDibPreviewWindowClass( ); + //if ( m_bWndClassRegistered ) + UnregisterDibPreviewWindowClass(); } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- +//------------------------------- -void SAL_CALL CDIBPreview::setWidth( sal_Int32 cx_new ) +sal_Int32 SAL_CALL CDIBPreview::getTargetColorDepth() throw (RuntimeException) { - SetWindowPos( - m_hwnd, NULL, 0, 0, cx_new, getHeight( ), - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); + HDC hdc = GetDC(m_Hwnd); + int clrRes = 0; + + if (hdc) + clrRes = GetDeviceCaps(hdc, COLORRES); + + return clrRes; } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- +//------------------------------- -sal_Int32 SAL_CALL CDIBPreview::getWidth( ) const +sal_Int32 SAL_CALL CDIBPreview::getAvailableWidth() throw (RuntimeException) { RECT rect; - sal_Bool bRet = GetClientRect( m_hwnd, &rect ); + sal_Bool bRet = GetClientRect(m_Hwnd,&rect); sal_Int32 cx = 0; @@ -191,25 +206,14 @@ sal_Int32 SAL_CALL CDIBPreview::getWidth( ) const return cx; } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- - -void SAL_CALL CDIBPreview::setHeight( sal_Int32 cy_new ) -{ - SetWindowPos( - m_hwnd, NULL, 0, 0, getWidth( ), cy_new, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); -} - -//--------------------------------------------------- -// -//--------------------------------------------------- +//------------------------------- -sal_Int32 SAL_CALL CDIBPreview::getHeight( ) const +sal_Int32 SAL_CALL CDIBPreview::getAvailableHeight() throw (RuntimeException) { RECT rect; - sal_Bool bRet = GetClientRect( m_hwnd, &rect ); + sal_Bool bRet = GetClientRect(m_Hwnd,&rect); sal_Int32 cy = 0; @@ -219,95 +223,147 @@ sal_Int32 SAL_CALL CDIBPreview::getHeight( ) const return cy; } -//--------------------------------------------------- -// shows or hides the preview window -//--------------------------------------------------- +//------------------------------- +// +//------------------------------- -sal_Bool SAL_CALL CDIBPreview::show( sal_Bool bShow ) +void SAL_CALL CDIBPreview::setImage(sal_Int16 aImageFormat, const Any& aImage) + throw (IllegalArgumentException, RuntimeException) { - sal_Bool bRet = sal_False; + PreviewBase::setImage(aImageFormat,aImage); - if ( IsWindow( m_hwnd ) ) - { - ShowWindow( m_hwnd, bShow ? SW_SHOW : SW_HIDE ); - bRet = sal_True; - } + // if the any has no value we have an + // empty Sequence which clears the + // preview window + osl::ClearableMutexGuard aGuard(m_PaintLock); + + m_Image.realloc(0); + m_ImageData >>= m_Image; - return bRet; + aGuard.clear(); + + InvalidateRect(m_Hwnd,NULL,FALSE); + UpdateWindow(m_Hwnd); } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- +//------------------------------- -sal_Bool SAL_CALL CDIBPreview::isVisible( ) const +sal_Bool SAL_CALL CDIBPreview::setShowState(sal_Bool bShowState) throw (RuntimeException) { - return IsWindowVisible( m_hwnd ); + PreviewBase::setShowState(bShowState); + ShowWindow(m_Hwnd, m_bShowState ? SW_SHOW : SW_HIDE); + return sal_True; } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- +//------------------------------- -int SAL_CALL CDIBPreview::getColorDepth( ) +sal_Bool SAL_CALL CDIBPreview::getShowState() throw (RuntimeException) { - HDC hdc = GetDC( m_hwnd ); - int clrRes = 0; - - if ( hdc ) - clrRes = GetDeviceCaps( hdc, COLORRES ); - - return clrRes; + return (sal_Bool)IsWindowVisible(m_Hwnd); } -//--------------------------------------------------- +//------------------------------- // -//--------------------------------------------------- +//------------------------------- -void SAL_CALL CDIBPreview::setImage( const Sequence< sal_Int8 >& ImageData ) +HWND SAL_CALL CDIBPreview::getWindowHandle() const { - // save the new image data and force a redraw - m_ImageData = ImageData; - InvalidateRect( m_hwnd, NULL, TRUE ); - UpdateWindow( m_hwnd ); + return m_Hwnd; } + //--------------------------------------------------- // //--------------------------------------------------- -void SAL_CALL CDIBPreview::onPaint( HWND hWnd, HDC hDC ) +void SAL_CALL CDIBPreview::onPaint(HWND hWnd, HDC hDC) { - BITMAPFILEHEADER* pbmfh; - BITMAPINFO * pbmi; - BYTE * pBits; - int cxDib; - int cyDib; + BITMAPFILEHEADER* pbmfh; + BITMAPINFO * pbmi; + BYTE * pBits; + int cxDib; + int cyDib; + + osl::MutexGuard aGuard(m_PaintLock); try { - pbmfh = reinterpret_cast< BITMAPFILEHEADER* >( m_ImageData.getArray( ) ); + pbmfh = reinterpret_cast(m_Image.getArray()); - if ( !IsBadReadPtr( pbmfh, sizeof( BITMAPFILEHEADER ) ) && - (pbmfh->bfType == *(WORD*)"BM") ) + if ( !IsBadReadPtr( pbmfh, sizeof(BITMAPFILEHEADER)) && + (pbmfh->bfType == *(WORD*)"BM")) { - pbmi = reinterpret_cast< BITMAPINFO * >( (pbmfh + 1) ); - pBits = reinterpret_cast< BYTE * >( ((DWORD)pbmfh) + pbmfh->bfOffBits ); + pbmi = reinterpret_cast((pbmfh + 1)); + pBits = reinterpret_cast(((DWORD)pbmfh) + pbmfh->bfOffBits); cxDib = pbmi->bmiHeader.biWidth; cyDib = abs (pbmi->bmiHeader.biHeight); - int oldMode = SetStretchBltMode( hDC, COLORONCOLOR ); + int oldMode = SetStretchBltMode(hDC, COLORONCOLOR); + + int nWidth = getAvailableWidth(); + int nHeight = getAvailableHeight(); + + int nX = abs(nWidth - cxDib) / 2; + int nY = abs(nHeight - cyDib) / 2; int GDIError = StretchDIBits( - hDC, 0, 0, getWidth( ), getHeight( ), + hDC, nX, nY, cxDib, cyDib, 0, 0, cxDib, cyDib, pBits, pbmi, DIB_RGB_COLORS, SRCCOPY); - OSL_ASSERT( GDI_ERROR != GDIError ); + OSL_ASSERT(GDI_ERROR != GDIError); + + // paint the border + RECT rc; + + if (nY > 0) + { + // top + rc.left = 0; + rc.top = 0; + rc.right = nWidth; + rc.bottom = nY; + FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); + + // bottom + rc.left = 0; + rc.top = nHeight - nY - 1; + rc.right = nWidth; + rc.bottom = nHeight; + FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); + } + + if (nX > 0) + { + // left + rc.left = 0; + rc.top = nY; + rc.right = nX; + rc.bottom = nHeight - nY; + FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); + + // right + rc.left = nWidth - nX - 1; + rc.top = nY; + rc.right = nWidth; + rc.bottom = nHeight - nY; + FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); + } + } + else // clear background + { + RECT rc; + GetClientRect(hWnd,&rc); + FillRect(hDC,&rc,(HBRUSH)(COLOR_INACTIVEBORDER + 1)); } } catch(...) { + OSL_ASSERT(sal_False); } } @@ -316,11 +372,11 @@ void SAL_CALL CDIBPreview::onPaint( HWND hWnd, HDC hDC ) //--------------------------------------------------- LRESULT CALLBACK CDIBPreview::WndProc( - HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) + HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT lResult = 0; - switch( uMsg ) + switch(uMsg) { // we connect a pointer to the current instance @@ -328,12 +384,12 @@ LRESULT CALLBACK CDIBPreview::WndProc( case WM_CREATE: { LPCREATESTRUCT lpcs = - reinterpret_cast< LPCREATESTRUCT >( lParam ); + reinterpret_cast< LPCREATESTRUCT >(lParam); - OSL_ASSERT( lpcs->lpCreateParams ); + OSL_ASSERT(lpcs->lpCreateParams); // connect the instance handle to the window - SetPropA( hWnd, CURRENT_INSTANCE, lpcs->lpCreateParams ); + SetPropA(hWnd,CURRENT_INSTANCE,lpcs->lpCreateParams); } break; @@ -342,34 +398,36 @@ LRESULT CALLBACK CDIBPreview::WndProc( case WM_NCDESTROY: { // RemoveProp returns the saved value on success - CDIBPreview* pImpl = reinterpret_cast< CDIBPreview* >( - RemovePropA( hWnd, CURRENT_INSTANCE ) ); + CDIBPreview* pImpl = reinterpret_cast( + RemovePropA(hWnd,CURRENT_INSTANCE)); - OSL_ASSERT( pImpl ); + OSL_ASSERT(pImpl); } break; case WM_PAINT: { - CDIBPreview* pImpl = reinterpret_cast< CDIBPreview* >( - GetPropA( hWnd, CURRENT_INSTANCE ) ); + CDIBPreview* pImpl = reinterpret_cast( + GetPropA(hWnd,CURRENT_INSTANCE)); - OSL_ASSERT( pImpl ); + OSL_ASSERT(pImpl); HDC hDC; PAINTSTRUCT ps; - hDC = BeginPaint( hWnd, &ps ); - pImpl->onPaint( hWnd, hDC ); - EndPaint( hWnd, &ps ); + hDC = BeginPaint(hWnd,&ps); + pImpl->onPaint(hWnd,hDC); + EndPaint(hWnd,&ps); } break; - default: -#pragma message( "####################################" ) -#pragma message( " fix this" ) -#pragma message( "####################################" ) + // ignore this message in order to + // avoid flickering during paint + case WM_ERASEBKGND: + lResult = 1; + break; + default: return DefWindowProcA( hWnd, uMsg, wParam, lParam ); } @@ -380,21 +438,21 @@ LRESULT CALLBACK CDIBPreview::WndProc( // //--------------------------------------------------- -ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass( ) +ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass() { osl::MutexGuard aGuard( s_Mutex ); - if ( 0 == s_ClassAtom ) + if (0 == s_ClassAtom) { // register the preview window class WNDCLASSEXW wndClsEx; - ZeroMemory( &wndClsEx, sizeof( WNDCLASSEXW ) ); + ZeroMemory(&wndClsEx, sizeof(WNDCLASSEXW)); - wndClsEx.cbSize = sizeof( WNDCLASSEXW ); + wndClsEx.cbSize = sizeof(WNDCLASSEXW); wndClsEx.style = CS_HREDRAW | CS_VREDRAW; wndClsEx.lpfnWndProc = CDIBPreview::WndProc; - wndClsEx.hInstance = m_hInstance; - wndClsEx.hbrBackground = (HBRUSH)( COLOR_INACTIVEBORDER + 1 ); + wndClsEx.hInstance = m_Instance; + wndClsEx.hbrBackground = (HBRUSH)(COLOR_INACTIVEBORDER + 1); wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME; // register the preview window class @@ -402,15 +460,19 @@ ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass( ) // if the dll is unloaded // Win2000 - the window class must be unregistered manually // if the dll is unloaded - s_ClassAtom = RegisterClassExW( &wndClsEx ); - OSL_ASSERT( s_ClassAtom ); + s_ClassAtom = RegisterClassExW(&wndClsEx); + + OSL_POSTCOND(s_ClassAtom,"Could not register preview window class"); + + if (0 == s_ClassAtom) + throw std::runtime_error("Preview window class could not be registered"); } // increment the register class counter // so that we keep track of the number // of class registrations - if ( 0 != s_ClassAtom ) - s_RegisterDibPreviewWndCount++; + //if ( 0 != s_ClassAtom ) + s_RegisterDibPreviewWndCount++; return s_ClassAtom; } @@ -419,7 +481,7 @@ ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass( ) // //--------------------------------------------------- -void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass( ) +void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass() { osl::MutexGuard aGuard( s_Mutex ); @@ -429,17 +491,15 @@ void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass( ) // update the register class counter // and unregister the window class if // counter drops to zero - if ( 0 != s_ClassAtom ) + if (0 != s_ClassAtom) { s_RegisterDibPreviewWndCount--; - OSL_ASSERT( s_RegisterDibPreviewWndCount >= 0 ); + OSL_ASSERT(s_RegisterDibPreviewWndCount >= 0); } - if ( 0 == s_RegisterDibPreviewWndCount ) + if (0 == s_RegisterDibPreviewWndCount) { - UnregisterClass( - (LPCTSTR)MAKELONG( s_ClassAtom, 0 ), m_hInstance ); - + UnregisterClass((LPCTSTR)MAKELONG(s_ClassAtom,0),m_Instance); s_ClassAtom = 0; } -} \ No newline at end of file +} diff --git a/fpicker/source/win32/filepicker/dibpreview.hxx b/fpicker/source/win32/filepicker/dibpreview.hxx index 16255c53e497..36d603cb592d 100644 --- a/fpicker/source/win32/filepicker/dibpreview.hxx +++ b/fpicker/source/win32/filepicker/dibpreview.hxx @@ -2,9 +2,9 @@ * * $RCSfile: dibpreview.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: tra $ $Date: 2001-07-11 09:20:28 $ + * last change: $Author: tra $ $Date: 2002-03-21 07:37:13 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -66,12 +66,8 @@ // includes //------------------------------------------------------------------------ -#ifndef _SAL_TYPES_H_ -#include -#endif - -#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX -#include +#ifndef _PREVIEWBASE_HXX_ +#include "previewbase.hxx" #endif #ifndef _OSL_MUTEX_HXX_ @@ -90,47 +86,37 @@ // it's enough to go the simple way - KISS. //--------------------------------------------- -class CDIBPreview +class CDIBPreview : public PreviewBase { public: - // clients can create instances only - // through the static create method - CDIBPreview( - sal_Int32 x, - sal_Int32 y, - sal_Int32 cx, - sal_Int32 cy, - HWND aParent, - HINSTANCE hInstance, - sal_Bool bShow = sal_True ); - // dtor - ~CDIBPreview( ); + // ctor + CDIBPreview(HINSTANCE instance,HWND parent,sal_Bool bShowWindow = sal_False); - // window size information + // dtor + virtual ~CDIBPreview( ); - void SAL_CALL setWidth( sal_Int32 cx_new ); + // preview interface implementation - sal_Int32 SAL_CALL getWidth( ) const; + virtual sal_Int32 SAL_CALL getTargetColorDepth() + throw (::com::sun::star::uno::RuntimeException); - void SAL_CALL setHeight( sal_Int32 cy_new ); + virtual sal_Int32 SAL_CALL getAvailableWidth() + throw (::com::sun::star::uno::RuntimeException); - sal_Int32 SAL_CALL getHeight( ) const; + virtual sal_Int32 SAL_CALL getAvailableHeight() + throw (::com::sun::star::uno::RuntimeException); - // shows the preview window - // possible values see SHOW_STATE - sal_Bool SAL_CALL show( sal_Bool bShow ); + virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const ::com::sun::star::uno::Any& aImage) + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); - // returns true when the preview window is - // visible and - // false if not - sal_Bool SAL_CALL isVisible( ) const; + virtual sal_Bool SAL_CALL setShowState(sal_Bool bShowState) + throw (::com::sun::star::uno::RuntimeException); - // returns the currently supported color - // resolution of the preview window - int SAL_CALL getColorDepth( ); + virtual sal_Bool SAL_CALL getShowState() + throw (::com::sun::star::uno::RuntimeException); - void SAL_CALL setImage( const ::com::sun::star::uno::Sequence< sal_Int8 >& pImageData ); + virtual HWND SAL_CALL getWindowHandle() const; private: virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC ); @@ -141,12 +127,10 @@ private: static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); private: - HWND m_hwnd; - HINSTANCE m_hInstance; - ::com::sun::star::uno::Sequence< sal_Int8 > m_ImageData; - sal_Int32 m_cx; - sal_Int32 m_cy; - sal_Bool m_bWndClassRegistered; + HINSTANCE m_Instance; + HWND m_Hwnd; + com::sun::star::uno::Sequence m_Image; + osl::Mutex m_PaintLock; // the preview window class has to be registered only // once per process, so multiple instance of this class @@ -157,8 +141,8 @@ private: // prevent copy and assignment private: - CDIBPreview( const CDIBPreview& ); - CDIBPreview& operator=( const CDIBPreview& ); + CDIBPreview(const CDIBPreview&); + CDIBPreview& operator=(const CDIBPreview&); }; -- cgit