diff options
author | Michael Stahl <mstahl@redhat.com> | 2017-05-29 13:38:44 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2017-05-29 15:46:20 +0200 |
commit | 200f02d55c806c3ae7ce054b43e66013c508062c (patch) | |
tree | 04917633fd6df0f13993472c616804b5cd0615cd /fpicker/source | |
parent | 32260c40b265b97358fc426fb9f849c243dc7dd4 (diff) |
fpicker: remove legacy XP FilePicker implementation
Long live VistaFilePicker.
Change-Id: I362a582a1922abad66ecfd1f5c4ce1a5a25fcd11
Diffstat (limited to 'fpicker/source')
41 files changed, 4 insertions, 7597 deletions
diff --git a/fpicker/source/win32/filepicker/FPServiceInfo.hxx b/fpicker/source/win32/filepicker/FPServiceInfo.hxx index 9e03045a6bd3..36aadf4b1c97 100644 --- a/fpicker/source/win32/filepicker/FPServiceInfo.hxx +++ b/fpicker/source/win32/filepicker/FPServiceInfo.hxx @@ -17,31 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - #ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FPSERVICEINFO_HXX #define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FPSERVICEINFO_HXX -// the service name is a description of a set of -// interfaces (is the same as component categories in COM) - -#define TMPL2000_FILEOPEN_READONLY_VERSION_BOX_ID 1001 - -#define TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_ID 2001 - -#define TMPL2000_FILEOPEN_AUTOEXT_TEMPLATE_BOX_ID 3001 - -#define TMPL2000_FILESAVE_AUTOEXT_PASSWORD_BOX_ID 4001 - -#define TMPL2000_AUTOEXT_PASSWORD_FILTEROPTION_BOX 5001 - -#define TMPL2000_PLAY_PUSHBUTTON 6001 - -#define TMPL2000_AUTOEXT_SELECTION_BOX 7001 - -#define TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_SIMPLE_ID 8001 - -#define TMPL2000_FILESAVE_AUTOEXT 9001 - // the service names #define FILE_PICKER_SERVICE_NAME "com.sun.star.ui.dialogs.SystemFilePicker" diff --git a/fpicker/source/win32/filepicker/FPentry.cxx b/fpicker/source/win32/filepicker/FPentry.cxx index 7c8af8725e71..5eaf4d00c023 100644 --- a/fpicker/source/win32/filepicker/FPentry.cxx +++ b/fpicker/source/win32/filepicker/FPentry.cxx @@ -19,7 +19,6 @@ #include <cppuhelper/factory.hxx> #include <com/sun/star/container/XSet.hpp> -#include "FilePicker.hxx" #include "FPServiceInfo.hxx" #ifdef _MSC_VER @@ -45,22 +44,11 @@ static Reference< XInterface > SAL_CALL createInstance( { Reference< XInterface > xDlg; -#ifdef __IFileDialogCustomize_INTERFACE_DEFINED__ - bool bVistaOrNewer = IsWindowsVistaOrNewer(); + if (!IsWindowsVistaOrNewer()) + std::abort(); // not supported - if (bVistaOrNewer) - { - xDlg.set( - static_cast< XFilePicker2* >( - new ::fpicker::win32::vista::VistaFilePicker( rServiceManager ) ) ); - } - else -#endif - { - xDlg.set( - static_cast< XFilePicker2* >( - new CFilePicker( rServiceManager ) ) ); - } + xDlg.set(static_cast<XFilePicker2*>( + new ::fpicker::win32::vista::VistaFilePicker(rServiceManager))); return xDlg; } diff --git a/fpicker/source/win32/filepicker/FileOpenDlg.cxx b/fpicker/source/win32/filepicker/FileOpenDlg.cxx deleted file mode 100644 index 8d4537c7dcc8..000000000000 --- a/fpicker/source/win32/filepicker/FileOpenDlg.cxx +++ /dev/null @@ -1,562 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include <osl/diagnose.h> -#include "../misc/WinImplHelper.hxx" -#include "FileOpenDlg.hxx" - - -// constants - - -namespace /* private */ -{ - // we choose such large buffers because the size of - // an single line edit field can be up to 32k; if - // a user has a multi selection FilePicker and selects - // a lot of files in a large directory we may reach this - // limit and don't want to get out of memory; - // another much more elegant way would be to subclass the - // FileOpen dialog and override the BM_CLICK event of the - // OK button so that we determine the size of the text - // currently in the edit field and resize our buffer - // appropriately - in the future we will do this - const sal_Int32 MAX_FILENAME_BUFF_SIZE = 32000; - const sal_Int32 MAX_FILETITLE_BUFF_SIZE = 32000; - const sal_Int32 MAX_FILTER_BUFF_SIZE = 4096; - - const PCWSTR CURRENT_INSTANCE = L"CurrInst"; - - - // find an appropriate parent window - - - inline bool is_current_process_window(HWND hwnd) - { - DWORD pid; - GetWindowThreadProcessId(hwnd, &pid); - return (pid == GetCurrentProcessId()); - } - - HWND choose_parent_window() - { - HWND hwnd_parent = GetForegroundWindow(); - if (!is_current_process_window(hwnd_parent)) - hwnd_parent = GetDesktopWindow(); - - return hwnd_parent; - } -}; - - -CFileOpenDialog::CFileOpenDialog( - bool bFileOpenDialog, - sal_uInt32 dwFlags, - sal_uInt32 dwTemplateId, - HINSTANCE hInstance) : - m_hwndFileOpenDlg(nullptr), - m_hwndFileOpenDlgChild(nullptr), - m_bFileOpenDialog(bFileOpenDialog), - m_filterBuffer(MAX_FILTER_BUFF_SIZE), - m_fileTitleBuffer(MAX_FILETITLE_BUFF_SIZE), - m_helperBuffer(MAX_FILENAME_BUFF_SIZE), - m_fileNameBuffer(MAX_FILENAME_BUFF_SIZE), - m_pfnBaseDlgProc(nullptr) -{ - // initialize the OPENFILENAME struct - ZeroMemory(&m_ofn, sizeof(m_ofn)); - m_ofn.lStructSize = sizeof(m_ofn); - - // 0x02000000 for #97681, sfx will make the entry into - // the recent document list - m_ofn.Flags |= dwFlags | - OFN_EXPLORER | - OFN_ENABLEHOOK | - OFN_HIDEREADONLY | - OFN_PATHMUSTEXIST | - OFN_FILEMUSTEXIST | - OFN_OVERWRITEPROMPT | - OFN_ENABLESIZING | - OFN_DONTADDTORECENT; // 0x02000000 -> OFN_DONTADDTORECENT only available with new platform sdk - - // it is a little hack but how else could - // we get a parent window (using a vcl window?) - m_ofn.hwndOwner = choose_parent_window(); - - m_ofn.lpstrFile = reinterpret_cast<PWSTR>(const_cast<sal_Unicode*>(m_fileNameBuffer.getStr())); - m_ofn.nMaxFile = m_fileNameBuffer.getCapacity(); - - m_ofn.lpstrFileTitle = reinterpret_cast<PWSTR>(const_cast<sal_Unicode*>(m_fileTitleBuffer.getStr())); - m_ofn.nMaxFileTitle = m_fileTitleBuffer.getCapacity(); - - m_ofn.lpfnHook = CFileOpenDialog::ofnHookProc; - - // set a custom template - - if (dwTemplateId) - { - OSL_ASSERT(hInstance); - - m_ofn.Flags |= OFN_ENABLETEMPLATE; - m_ofn.lpTemplateName = MAKEINTRESOURCE(dwTemplateId); - m_ofn.hInstance = hInstance; - } - - // set a pointer to myself as ofn parameter - m_ofn.lCustData = reinterpret_cast<sal_IntPtr>(this); -} - - -CFileOpenDialog::~CFileOpenDialog() -{ -} - - -void SAL_CALL CFileOpenDialog::setTitle(const OUString& aTitle) -{ - m_dialogTitle = aTitle; - m_ofn.lpstrTitle = reinterpret_cast<PCWSTR>(m_dialogTitle.getStr()); -} - - -void CFileOpenDialog::setFilter(const OUString& aFilter) -{ - // Format is like - // "*.TXT" or multiple separate by ';' like "*.TXT;*.DOC;*.SXW" - // Do not include spaces in the pattern string - m_filterBuffer.ensureCapacity(aFilter.getLength()); - m_filterBuffer.setLength(0); - m_filterBuffer.append(aFilter); - m_ofn.lpstrFilter = reinterpret_cast<PCWSTR>(m_filterBuffer.getStr()); -} - - -bool CFileOpenDialog::setFilterIndex(sal_uInt32 aIndex) -{ - OSL_ASSERT(aIndex > 0); - m_ofn.nFilterIndex = aIndex; - return true; -} - - -sal_uInt32 CFileOpenDialog::getSelectedFilterIndex() const -{ - return m_ofn.nFilterIndex; -} - - -void SAL_CALL CFileOpenDialog::setDefaultName(const OUString& aName) -{ - m_fileNameBuffer.setLength(0); - m_fileNameBuffer.append(aName); - m_ofn.lpstrFile = reinterpret_cast<PWSTR>(const_cast<sal_Unicode*>(m_fileNameBuffer.getStr())); -} - - -void SAL_CALL CFileOpenDialog::setDisplayDirectory(const OUString& aDirectory) -{ - m_displayDirectory = aDirectory; - m_ofn.lpstrInitialDir = reinterpret_cast<PCWSTR>(m_displayDirectory.getStr()); -} - - -OUString SAL_CALL CFileOpenDialog::getLastDisplayDirectory() const -{ - return m_displayDirectory; -} - - -OUString SAL_CALL CFileOpenDialog::getFullFileName() const -{ - return OUString(m_fileNameBuffer.getStr(), - wcslenex(m_fileNameBuffer.getStr())); -} - - -OUString SAL_CALL CFileOpenDialog::getFileName() const -{ - return OUString(m_fileTitleBuffer.getStr()); -} - - -OUString CFileOpenDialog::getFileExtension() -{ - if (m_ofn.nFileExtension) - return OUString(m_fileNameBuffer.getStr() + m_ofn.nFileExtension, - rtl_ustr_getLength(m_fileNameBuffer.getStr() + m_ofn.nFileExtension)); - - return OUString(); -} - - -void CFileOpenDialog::setDefaultFileExtension(const OUString& aExtension) -{ - m_defaultExtension = aExtension; - m_ofn.lpstrDefExt = reinterpret_cast<PCWSTR>(m_defaultExtension.getStr()); -} - - -void SAL_CALL CFileOpenDialog::setMultiSelectionMode(bool bMode) -{ - if (bMode) - m_ofn.Flags |= OFN_ALLOWMULTISELECT; - else - m_ofn.Flags &= ~OFN_ALLOWMULTISELECT; -} - - -bool SAL_CALL CFileOpenDialog::getMultiSelectionMode() const -{ - return ((m_ofn.Flags & OFN_ALLOWMULTISELECT) > 0); -} - - -sal_Int16 SAL_CALL CFileOpenDialog::doModal() -{ - sal_Int16 nRC = -1; - - // pre-processing - if (preModal()) - { - bool bRet; - - if (m_bFileOpenDialog) - bRet = m_GetFileNameWrapper.getOpenFileName( - reinterpret_cast<LPOPENFILENAME>(&m_ofn)); - else - bRet = m_GetFileNameWrapper.getSaveFileName( - reinterpret_cast<LPOPENFILENAME>(&m_ofn)); - - nRC = 1; - - if (!bRet) - nRC = (0 == m_GetFileNameWrapper.commDlgExtendedError()) ? 0 : -1; - - // post-processing - postModal(nRC); - } - - return nRC; -} - - -sal_uInt32 SAL_CALL CFileOpenDialog::getLastDialogError() -{ - return CommDlgExtendedError(); -} - - -bool SAL_CALL CFileOpenDialog::preModal() -{ - return true; -} - - -void SAL_CALL CFileOpenDialog::postModal(sal_Int16 nDialogResult) -{ - OSL_ASSERT((-1 <= nDialogResult) && (nDialogResult <= 1)); - - if (1 == nDialogResult) - { - // Attention: assuming that nFileOffset is always greater 0 because under - // Windows there is always a drive letter or a server in a complete path - // the OPENFILENAME docu never says that nFileOffset can be 0 - m_displayDirectory = OUString(reinterpret_cast<const sal_Unicode*>(m_ofn.lpstrFile),m_ofn.nFileOffset); - } -} - - -OUString SAL_CALL CFileOpenDialog::getCurrentFilePath() const -{ - OSL_ASSERT(IsWindow(m_hwndFileOpenDlg)); - - LPARAM nLen = SendMessageW( - m_hwndFileOpenDlg, - CDM_GETFILEPATH, - m_helperBuffer.getCapacity(), - reinterpret_cast<LPARAM>(m_helperBuffer.getStr())); - - if (nLen > 0) - { - m_helperBuffer.setLength((nLen * sizeof(sal_Unicode)) - 1); - return OUString(m_helperBuffer.getStr()); - } - return OUString(); -} - - -OUString SAL_CALL CFileOpenDialog::getCurrentFolderPath() const -{ - OSL_ASSERT(IsWindow(m_hwndFileOpenDlg)); - - LPARAM nLen = SendMessageW( - m_hwndFileOpenDlg, - CDM_GETFOLDERPATH, - m_helperBuffer.getCapacity(), - reinterpret_cast<LPARAM>(m_helperBuffer.getStr())); - - if (nLen > 0) - { - m_helperBuffer.setLength((nLen * sizeof(sal_Unicode)) - 1); - return OUString(m_helperBuffer.getStr()); - } - return OUString(); -} - - -OUString SAL_CALL CFileOpenDialog::getCurrentFileName() const -{ - OSL_ASSERT(IsWindow(m_hwndFileOpenDlg)); - - LPARAM nLen = SendMessageW( - m_hwndFileOpenDlg, - CDM_GETSPEC, - m_helperBuffer.getCapacity(), - reinterpret_cast<LPARAM>(m_helperBuffer.getStr())); - - if (nLen > 0) - { - m_helperBuffer.setLength((nLen * sizeof(sal_Unicode)) - 1); - return OUString(m_helperBuffer.getStr()); - } - return OUString(); -} - - -sal_uInt32 SAL_CALL CFileOpenDialog::onShareViolation(const OUString&) -{ - return 0; -} - - -sal_uInt32 SAL_CALL CFileOpenDialog::onFileOk() -{ - return 0; -} - - -void SAL_CALL CFileOpenDialog::onSelChanged(HWND) -{ -} - - -void SAL_CALL CFileOpenDialog::onHelp() -{ -} - - -void SAL_CALL CFileOpenDialog::onInitDone() -{ - centerPositionToParent(); -} - - -void SAL_CALL CFileOpenDialog::onFolderChanged() -{ -} - - -void SAL_CALL CFileOpenDialog::onTypeChanged(sal_uInt32) -{ -} - - -sal_uInt32 SAL_CALL CFileOpenDialog::onCtrlCommand(HWND, sal_uInt16, sal_uInt16) -{ - return 0; -} - - -sal_uInt32 SAL_CALL CFileOpenDialog::onWMNotify( HWND, LPOFNOTIFY lpOfNotify ) -{ - switch(lpOfNotify->hdr.code) - { - case CDN_SHAREVIOLATION: - return onShareViolation(reinterpret_cast<const sal_Unicode*>(lpOfNotify->pszFile)); - - case CDN_FILEOK: - return onFileOk(); - - case CDN_SELCHANGE: - onSelChanged(lpOfNotify->hdr.hwndFrom); - break; - - case CDN_HELP: - onHelp(); - break; - - case CDN_INITDONE: - onInitDone(); - break; - - case CDN_FOLDERCHANGE: - onFolderChanged(); - break; - - case CDN_TYPECHANGE: - m_ofn.nFilterIndex = lpOfNotify->lpOFN->nFilterIndex; - onTypeChanged(lpOfNotify->lpOFN->nFilterIndex); - break; - } - - return 0; -} - - -void SAL_CALL CFileOpenDialog::handleInitDialog(HWND hwndDlg, HWND hwndChild) -{ - m_hwndFileOpenDlg = hwndDlg; - m_hwndFileOpenDlgChild = hwndChild; - - OSL_ASSERT(GetParent(hwndChild) == hwndDlg); - - // calling virtual function which the client can override - onInitDialog(hwndDlg); -} - - -UINT_PTR CALLBACK CFileOpenDialog::ofnHookProc( - HWND hChildDlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) -{ - HWND hwndDlg = GetParent(hChildDlg); - CFileOpenDialog* pImpl = nullptr; - - switch( uiMsg ) - { - case WM_INITDIALOG: - { - LPOPENFILENAME_ lpofn = reinterpret_cast<LPOPENFILENAME_>(lParam); - pImpl = reinterpret_cast<CFileOpenDialog*>(lpofn->lCustData); - OSL_ASSERT(pImpl); - - // subclass the base dialog for WM_NCDESTROY processing - pImpl->m_pfnBaseDlgProc = - reinterpret_cast<WNDPROC>( - SetWindowLongPtr( - hwndDlg, - GWLP_WNDPROC, - reinterpret_cast<LONG_PTR>(CFileOpenDialog::BaseDlgProc))); - // connect the instance handle to the window - SetPropW(hwndDlg, CURRENT_INSTANCE, pImpl); - pImpl->handleInitDialog(hwndDlg, hChildDlg); - } - return 0; - - case WM_NOTIFY: - { - pImpl = getCurrentInstance(hwndDlg); - return pImpl->onWMNotify( - hChildDlg, reinterpret_cast<LPOFNOTIFY>(lParam)); - } - - case WM_COMMAND: - { - pImpl = getCurrentInstance(hwndDlg); - OSL_ASSERT(pImpl); - - return pImpl->onCtrlCommand( - hChildDlg, LOWORD(wParam), HIWORD(lParam)); - } - } - - return 0; -} - - -LRESULT CALLBACK CFileOpenDialog::BaseDlgProc( - HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam) -{ - CFileOpenDialog* pImpl = nullptr; - - if (WM_NCDESTROY == wMessage) - { - pImpl = static_cast<CFileOpenDialog*>( - RemovePropW(hWnd,CURRENT_INSTANCE)); - - SetWindowLongPtr(hWnd, GWLP_WNDPROC, - reinterpret_cast<LONG_PTR>(pImpl->m_pfnBaseDlgProc)); - } - else - { - pImpl = getCurrentInstance(hWnd); - } - - OSL_ASSERT(pImpl); - - return CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnBaseDlgProc), - hWnd,wMessage,wParam,lParam); -} - - -CFileOpenDialog* SAL_CALL CFileOpenDialog::getCurrentInstance(HWND hwnd) -{ - OSL_ASSERT(IsWindow( hwnd)); - return static_cast<CFileOpenDialog*>( - GetPropW(hwnd, CURRENT_INSTANCE)); -} - - -void SAL_CALL CFileOpenDialog::centerPositionToParent() const -{ - OSL_PRECOND(IsWindow(m_hwndFileOpenDlg), "no dialog window, call method only after or in onInitDone"); - - HWND hwndParent = m_ofn.hwndOwner; - - if (!IsWindow(hwndParent)) - hwndParent = GetDesktopWindow(); - - OSL_ASSERT(IsWindow(hwndParent)); - - RECT rcPar; - GetWindowRect(hwndParent, &rcPar); - - RECT rcDlg; - GetWindowRect(m_hwndFileOpenDlg, &rcDlg); - - int lDlgW = rcDlg.right - rcDlg.left; - int lDlgH = rcDlg.bottom - rcDlg.top; - - int x = (rcPar.left + rcPar.right - lDlgW) / 2; - int y = (rcPar.top + rcPar.bottom - lDlgH) / 2; - - HDC hdc = GetDC(m_hwndFileOpenDlg); - - int hResol = GetDeviceCaps(hdc, HORZRES); - int vResol = GetDeviceCaps(hdc, VERTRES); - - ReleaseDC(m_hwndFileOpenDlg, hdc); - - if (x < 0) - x = 0; - else if ((x + lDlgW) > hResol) - x = hResol - lDlgW; - - if (y < 0) - y = 0; - else if ((y + lDlgH) > vResol) - y = vResol - lDlgH; - - SetWindowPos( - m_hwndFileOpenDlg, - nullptr, x, y, 0, 0, - SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/FileOpenDlg.hxx b/fpicker/source/win32/filepicker/FileOpenDlg.hxx deleted file mode 100644 index 28b01da16ce2..000000000000 --- a/fpicker/source/win32/filepicker/FileOpenDlg.hxx +++ /dev/null @@ -1,293 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEOPENDLG_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEOPENDLG_HXX - -#include <sal/types.h> - -#include <rtl/ustring.hxx> -#include <rtl/ustrbuf.hxx> - -#include "platform_xp.h" -#include "getfilenamewrapper.hxx" - -// because we don't want to import the new W2k platform sdk -// into our build environment if have stolen the definition -// for the new OPENFILENAME structure from the new headers - -typedef struct { - DWORD lStructSize; - HWND hwndOwner; - HINSTANCE hInstance; - LPCSTR lpstrFilter; - LPSTR lpstrCustomFilter; - DWORD nMaxCustFilter; - DWORD nFilterIndex; - LPSTR lpstrFile; - DWORD nMaxFile; - LPSTR lpstrFileTitle; - DWORD nMaxFileTitle; - LPCSTR lpstrInitialDir; - LPCSTR lpstrTitle; - DWORD Flags; - WORD nFileOffset; - WORD nFileExtension; - LPCSTR lpstrDefExt; - LPARAM lCustData; - LPOFNHOOKPROC lpfnHook; - LPCSTR lpTemplateName; -#ifdef _MAC - LPEDITMENU lpEditInfo; - LPCSTR lpstrPrompt; -#endif - void * pvReserved; - DWORD dwReserved; - DWORD FlagsEx; -} OPENFILENAMEA_, *LPOPENFILENAMEA_; - -typedef struct { - DWORD lStructSize; - HWND hwndOwner; - HINSTANCE hInstance; - LPCWSTR lpstrFilter; - LPWSTR lpstrCustomFilter; - DWORD nMaxCustFilter; - DWORD nFilterIndex; - LPWSTR lpstrFile; - DWORD nMaxFile; - LPWSTR lpstrFileTitle; - DWORD nMaxFileTitle; - LPCWSTR lpstrInitialDir; - LPCWSTR lpstrTitle; - DWORD Flags; - WORD nFileOffset; - WORD nFileExtension; - LPCWSTR lpstrDefExt; - LPARAM lCustData; - LPOFNHOOKPROC lpfnHook; - LPCWSTR lpTemplateName; - void * pvReserved; - DWORD dwReserved; - DWORD FlagsEx; -} OPENFILENAMEW_, *LPOPENFILENAMEW_; - -#ifdef UNICODE -typedef OPENFILENAMEW_ OPENFILENAME_; -typedef LPOPENFILENAMEW_ LPOPENFILENAME_; -#else -typedef OPENFILENAMEA_ OPENFILENAME_; -typedef LPOPENFILENAMEA_ LPOPENFILENAME_; -#endif // UNICODE - -// A simple wrapper class around the Win32 GetOpenFileName API. -// This class is not thread-safe and only one instance at a -// time is allowed - - -class CFileOpenDialog -{ -public: - // ctor - // bFileOpenDialog indicates if we want a FileOpen or FileSave - // dialog - // dwFlags see OPENFILENAME - // dwTemplateId - an ID for custom templates - // hInstance - an instance handle for the module - // which provides the custom template, unused if dwTemplateId - // is 0 - CFileOpenDialog( - bool bFileOpenDialog = true, - sal_uInt32 dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, - sal_uInt32 dwTemplateId = 0, - HINSTANCE hInstance = nullptr); - - virtual ~CFileOpenDialog(); - - virtual void SAL_CALL setTitle(const OUString& aTitle); - - // to set a filter string using the M$ format - // e.g. FltName\0*.txt;*.rtf\0...\0\0 - void SAL_CALL setFilter(const OUString& aFilter); - - // set the index of the current filter when the - // dialog is about to shown, the index starts with 1 - // the function succeeded if the given filter index - // is greater than zero and is a valid position - // within filter string that was previously set - bool SAL_CALL setFilterIndex(sal_uInt32 aIndex); - - // get the index of the currently selected filter - // the index of the returned filter starts with 1 - sal_uInt32 SAL_CALL getSelectedFilterIndex() const; - - // set the name and optional the path of the - // file that will be initially be shown when - // the dialog will be displayed - virtual void SAL_CALL setDefaultName(const OUString& aName); - - // set the initial directory - virtual void SAL_CALL setDisplayDirectory(const OUString& aDirectory); - - // returns only the path of the selected file - virtual OUString SAL_CALL getLastDisplayDirectory() const; - - // returns the full file name including drive letter, path - // file name and file extension - virtual OUString SAL_CALL getFullFileName() const; - - // returns the file name and the file extension without - // drive letter and path - OUString SAL_CALL getFileName() const; - - // returns the file extension of the selected file - OUString SAL_CALL getFileExtension(); - - // set a default extension, only the first three letters of - // the given extension will be used; the given extension - // should not contain a '.' - void SAL_CALL setDefaultFileExtension(const OUString& aExtension); - - // enables or disables the multiselection mode for - // the FileOpen/FileSave dialog - void SAL_CALL setMultiSelectionMode(bool bMode); - - // returns whether multi-selection mode is enabled or not - bool SAL_CALL getMultiSelectionMode() const; - - // shows the dialog, calls preModal before - // showing the dialog and postModal after - // showing the dialog - // the method returns: - // 0 - when the dialog was canceled by the user - // 1 - when the dialog was closed with ok - // -1 - when an error occurred - sal_Int16 SAL_CALL doModal(); - - // returns the last dialog error that occurred - static sal_uInt32 SAL_CALL getLastDialogError(); - - // retrievs the currently selected file - // including path and drive information - // can be called only if the dialog is - // already displayed - OUString SAL_CALL getCurrentFilePath() const; - - // retrievs the currently selected folder - OUString SAL_CALL getCurrentFolderPath() const; - - // retrievs the currently selected file name - // without drive and path - OUString SAL_CALL getCurrentFileName() const; - -protected: - // have to be overwritten when subclasses - // want to do special pre- and post-modal - // processing - - // if preModal return true processing will - // continue else doModal exit without showing - // a dialog and returns -1 - virtual bool SAL_CALL preModal(); - - // post modal processing - // the function should accept only values returned from - // doModal and act appropriately - virtual void SAL_CALL postModal(sal_Int16 nDialogResult); - - // message handler, to be overwritten by subclasses - virtual sal_uInt32 SAL_CALL onShareViolation(const OUString& aPathName); - virtual sal_uInt32 SAL_CALL onFileOk(); - virtual void SAL_CALL onSelChanged(HWND hwndListBox); - virtual void SAL_CALL onHelp(); - - // only called back if OFN_EXPLORER is set - virtual void SAL_CALL onInitDone(); - virtual void SAL_CALL onFolderChanged(); - virtual void SAL_CALL onTypeChanged(sal_uInt32 nFilterIndex); - - virtual void SAL_CALL onInitDialog(HWND hwndDlg) = 0; - - virtual sal_uInt32 SAL_CALL onCtrlCommand(HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode); - - sal_uInt32 SAL_CALL onWMNotify(HWND hwndChild, LPOFNOTIFYW lpOfNotify); - - // we use non-virtual functions to do necessary work before - // calling the virtual functions (see Gamma: Template method) - void SAL_CALL handleInitDialog(HWND hwndDlg, HWND hwndChild); - -protected: - - // handle to the window of the - // FileOpen/FileSave dialog - // will be set on message - // WM_INITDIALOG, before this - // value is undefined - HWND m_hwndFileOpenDlg; - HWND m_hwndFileOpenDlgChild; - - OPENFILENAME_ m_ofn; - - // we connect the instance with the dialog window using - // SetProp, with this function we can reconnect from - // callback functions to this instance - static CFileOpenDialog* SAL_CALL getCurrentInstance(HWND hwnd); - - void SAL_CALL centerPositionToParent() const; - -private: - // FileOpen or FileSaveDialog - bool m_bFileOpenDialog; - OUString m_dialogTitle; - OUString m_displayDirectory; - OUString m_defaultExtension; - - mutable OUStringBuffer m_filterBuffer; - mutable OUStringBuffer m_fileTitleBuffer; - mutable OUStringBuffer m_helperBuffer; - mutable OUStringBuffer m_fileNameBuffer; - - CGetFileNameWrapper m_GetFileNameWrapper; - - WNDPROC m_pfnBaseDlgProc; - - // callback function - static UINT_PTR CALLBACK ofnHookProc( - HWND hChildDlg, // handle to child dialog box - UINT uiMsg, // message identifier - WPARAM wParam, // message parameter - LPARAM lParam // message parameter - ); - - // we have to subclass the dialog in order - // to clean up the window property we are - // using to connect the window with a class - // instance in WM_NCDESTROY - static LRESULT CALLBACK BaseDlgProc( - HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam ); - -private: - // avoid copy and assignment - CFileOpenDialog(const CFileOpenDialog&); - CFileOpenDialog& operator=(const CFileOpenDialog&); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/FilePicker.cxx b/fpicker/source/win32/filepicker/FilePicker.cxx deleted file mode 100644 index 7b60b0bb1dd6..000000000000 --- a/fpicker/source/win32/filepicker/FilePicker.cxx +++ /dev/null @@ -1,555 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include <memory> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <cppuhelper/interfacecontainer.h> -#include <cppuhelper/supportsservice.hxx> -#include <osl/diagnose.h> - -#include "FilePicker.hxx" -#include "WinFileOpenImpl.hxx" - -#include "FPServiceInfo.hxx" -#include "../misc/WinImplHelper.hxx" -#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> -#include "filepickereventnotification.hxx" - -#include <comphelper/sequence.hxx> - -using namespace com::sun::star; -using namespace ::com::sun::star::ui::dialogs; -using namespace ::com::sun::star::ui::dialogs::TemplateDescription; - -#define FILE_PICKER_DLL_NAME L"fps.dll" - -namespace -{ - // controlling event notifications - const bool STARTUP_SUSPENDED = true; - - uno::Sequence<OUString> SAL_CALL FilePicker_getSupportedServiceNames() - { - uno::Sequence<OUString> aRet(2); - aRet[0] = "com.sun.star.ui.dialogs.FilePicker"; - aRet[1] = "com.sun.star.ui.dialogs.SystemFilePicker"; - return aRet; - } -} - -CFilePicker::CFilePicker( const uno::Reference<lang::XMultiServiceFactory>& xServiceMgr) : - CFilePicker_Base(m_rbHelperMtx), - m_xServiceMgr(xServiceMgr), - m_aAsyncEventNotifier(rBHelper) -{ - HINSTANCE hInstance = GetModuleHandleW(FILE_PICKER_DLL_NAME); - SAL_WARN_IF( !hInstance, "fpicker", "The name of the service dll must have changed" ); - - // create a default FileOpen dialog without any additional ui elements - m_pImpl = std::unique_ptr< CWinFileOpenImpl >( - new CWinFileOpenImpl( - this, - true, - 0, - 0, - hInstance ) ); -} - -// XFPEventListenerManager - -void SAL_CALL CFilePicker::addFilePickerListener(const uno::Reference<XFilePickerListener>& xListener) -{ - if ( rBHelper.bDisposed ) - throw lang::DisposedException( - "object is already disposed", - static_cast< XFilePicker2* >( this ) ); - - if ( !rBHelper.bInDispose && !rBHelper.bDisposed ) - rBHelper.aLC.addInterface(cppu::UnoType<decltype(xListener)>::get(), xListener ); -} - -void SAL_CALL CFilePicker::removeFilePickerListener(const uno::Reference<XFilePickerListener>& xListener ) -{ - if ( rBHelper.bDisposed ) - throw lang::DisposedException( - "object is already disposed", - static_cast< XFilePicker2* >( this ) ); - - rBHelper.aLC.removeInterface(cppu::UnoType<decltype(xListener)>::get(), xListener ); -} - -// XEventListener - -void SAL_CALL CFilePicker::disposing(const lang::EventObject& aEvent) -{ - uno::Reference<XFilePickerListener> xFilePickerListener(aEvent.Source, css::uno::UNO_QUERY); - - if (xFilePickerListener.is()) - removeFilePickerListener(xFilePickerListener); -} - -void SAL_CALL CFilePicker::fileSelectionChanged(FilePickerEvent aEvent) -{ - aEvent.Source.set(static_cast<XFilePickerNotifier*>(this)); - m_aAsyncEventNotifier.notifyEvent( - new CFilePickerParamEventNotification(&XFilePickerListener::fileSelectionChanged,aEvent)); -} - -void SAL_CALL CFilePicker::directoryChanged(FilePickerEvent aEvent) -{ - aEvent.Source.set(static_cast<XFilePickerNotifier*>(this)); - m_aAsyncEventNotifier.notifyEvent( - new CFilePickerParamEventNotification(&XFilePickerListener::directoryChanged,aEvent)); -} - -void SAL_CALL CFilePicker::controlStateChanged(FilePickerEvent aEvent) -{ - aEvent.Source.set(static_cast<XFilePickerNotifier*>(this)); - m_aAsyncEventNotifier.notifyEvent( - new CFilePickerParamEventNotification(&XFilePickerListener::controlStateChanged,aEvent)); -} - -void SAL_CALL CFilePicker::dialogSizeChanged() -{ - m_aAsyncEventNotifier.notifyEvent( - new CFilePickerEventNotification(&XFilePickerListener::dialogSizeChanged)); -} - -// If there are more than one listener the return value of the last one wins - -OUString SAL_CALL CFilePicker::helpRequested(FilePickerEvent aEvent) const -{ - OUString aHelpText; - - ::cppu::OInterfaceContainerHelper* pICHelper = - rBHelper.getContainer( cppu::UnoType<XFilePickerListener>::get()); - - if (pICHelper) - { - ::cppu::OInterfaceIteratorHelper iter(*pICHelper); - - while(iter.hasMoreElements()) - { - try - { - /* - if there are multiple listeners responding - to this notification the next response - overwrites the one before if it is not empty - */ - - OUString temp; - - uno::Reference<XFilePickerListener> xFPListener(iter.next(), uno::UNO_QUERY); - if (xFPListener.is()) - { - temp = xFPListener->helpRequested(aEvent); - if (temp.getLength()) - aHelpText = temp; - } - - } - catch(uno::RuntimeException&) - { - OSL_FAIL( "RuntimeException during event dispatching" ); - } - } - } - - return aHelpText; -} - -bool CFilePicker::startupEventNotification(bool bStartupSuspended) -{ - return m_aAsyncEventNotifier.startup(bStartupSuspended); -} - -void CFilePicker::shutdownEventNotification() -{ - m_aAsyncEventNotifier.shutdown(); -} - -void CFilePicker::suspendEventNotification() -{ - m_aAsyncEventNotifier.suspend(); -} - -void CFilePicker::resumeEventNotification() -{ - m_aAsyncEventNotifier.resume(); -} - -// XFilePicker - -void SAL_CALL CFilePicker::setMultiSelectionMode(sal_Bool bMode) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setMultiSelectionMode(bMode); -} - -void SAL_CALL CFilePicker::setTitle(const OUString& aTitle) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setTitle(aTitle); -} - -void SAL_CALL CFilePicker::appendFilter(const OUString& aTitle, const OUString& aFilter) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->appendFilter(aTitle, aFilter); -} - -void SAL_CALL CFilePicker::setCurrentFilter(const OUString& aTitle) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setCurrentFilter(aTitle); -} - -OUString SAL_CALL CFilePicker::getCurrentFilter() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getCurrentFilter(); -} - -void SAL_CALL CFilePicker::appendFilterGroup(const OUString& sGroupTitle, const uno::Sequence<beans::StringPair>& aFilters) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->appendFilterGroup(sGroupTitle, aFilters); -} - -void SAL_CALL CFilePicker::setDefaultName(const OUString& aName) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setDefaultName(aName); -} - -void SAL_CALL CFilePicker::setDisplayDirectory(const OUString& aDirectory) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setDisplayDirectory(aDirectory); -} - -OUString SAL_CALL CFilePicker::getDisplayDirectory() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getDisplayDirectory(); -} - -uno::Sequence<OUString> SAL_CALL CFilePicker::getFiles() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getFiles(); -} - -uno::Sequence< OUString > SAL_CALL CFilePicker::getSelectedFiles() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - osl::MutexGuard aGuard(m_aMutex); - - const uno::Sequence< OUString > lSource = m_pImpl->getFiles(); - const ::sal_Int32 c = lSource.getLength(); - if (c < 2) - return lSource; - - const OUString sPath = lSource[0]; - ::std::vector< OUString > lTarget; - ::sal_Int32 i = 1; - for (i=1; i<c; ++i) - { - const OUString sFile = lSource[i]; - if (sFile.indexOf ('/') > 0) - { - // a) file contains own path ! - lTarget.push_back(sFile); - } - else - { - // b) file is relative to given path - OUStringBuffer sFull(256); - - sFull.append (sPath); - sFull.append("/" ); - sFull.append (sFile); - - lTarget.push_back(sFull.makeStringAndClear()); - } - } - - return comphelper::containerToSequence(lTarget); -} - -sal_Int16 SAL_CALL CFilePicker::execute() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - sal_Int16 ret; - - if (startupEventNotification(STARTUP_SUSPENDED)) - { - // we should not block in this call else - // in the case of an event the client can't - // call another function an we run into a - // deadlock !!!!! - ret = m_pImpl->execute( ); - - shutdownEventNotification(); - } - else - { - OSL_FAIL("Could not start event notifier thread!"); - - throw uno::RuntimeException( - "Error executing dialog", - static_cast<XFilePicker2*>(this)); - } - - return ret; -} - -void SAL_CALL CFilePicker::setValue(sal_Int16 aControlId, sal_Int16 aControlAction, const uno::Any& aValue) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setValue(aControlId, aControlAction, aValue); -} - -uno::Any SAL_CALL CFilePicker::getValue(sal_Int16 aControlId, sal_Int16 aControlAction) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getValue(aControlId, aControlAction); -} - -void SAL_CALL CFilePicker::enableControl(sal_Int16 aControlId, sal_Bool bEnable) -{ - OSL_ASSERT( nullptr != m_pImpl.get( ) ); - - osl::MutexGuard aGuard( m_aMutex ); - m_pImpl->enableControl( aControlId, bEnable ); -} - -void SAL_CALL CFilePicker::setLabel(sal_Int16 aControlId, const OUString& aLabel) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setLabel(aControlId, aLabel); -} - -OUString SAL_CALL CFilePicker::getLabel(sal_Int16 aControlId) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getLabel(aControlId); -} - -uno::Sequence<sal_Int16> SAL_CALL CFilePicker::getSupportedImageFormats() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getSupportedImageFormats(); -} - -sal_Int32 SAL_CALL CFilePicker::getTargetColorDepth() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getTargetColorDepth(); -} - -sal_Int32 SAL_CALL CFilePicker::getAvailableWidth() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getAvailableWidth(); -} - -sal_Int32 SAL_CALL CFilePicker::getAvailableHeight() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getAvailableHeight(); -} - -void SAL_CALL CFilePicker::setImage(sal_Int16 aImageFormat, const uno::Any& aImage) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->setImage(aImageFormat, aImage); -} - -sal_Bool SAL_CALL CFilePicker::setShowState(sal_Bool bShowState) -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->setShowState(bShowState); -} - -sal_Bool SAL_CALL CFilePicker::getShowState() -{ - OSL_ASSERT(nullptr != m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - return m_pImpl->getShowState(); -} - -void SAL_CALL CFilePicker::initialize(const uno::Sequence<uno::Any>& aArguments) -{ - // parameter checking - uno::Any aAny; - if ( 0 == aArguments.getLength( ) ) - throw lang::IllegalArgumentException( - "no arguments", - static_cast<XFilePicker2*>(this), 1); - - aAny = aArguments[0]; - - if ( (aAny.getValueType() != ::cppu::UnoType<sal_Int16>::get()) && - (aAny.getValueType() != ::cppu::UnoType<sal_Int8>::get()) ) - throw lang::IllegalArgumentException( - "invalid argument type", - static_cast<XFilePicker2*>(this), 1); - - sal_Int16 templateId = -1; - aAny >>= templateId; - - bool bFileOpenDialog = true; - sal_uInt32 winResTemplateId = 0; - - switch ( templateId ) - { - case FILEOPEN_SIMPLE: - bFileOpenDialog = true; - break; - - case FILESAVE_SIMPLE: - bFileOpenDialog = false; - break; - - case FILESAVE_AUTOEXTENSION_PASSWORD: - bFileOpenDialog = false; - winResTemplateId = TMPL2000_FILESAVE_AUTOEXT_PASSWORD_BOX_ID; - break; - - case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS: - bFileOpenDialog = false; - winResTemplateId = TMPL2000_AUTOEXT_PASSWORD_FILTEROPTION_BOX; - break; - - case FILESAVE_AUTOEXTENSION_SELECTION: - bFileOpenDialog = false; - winResTemplateId = TMPL2000_AUTOEXT_SELECTION_BOX; - break; - - case FILESAVE_AUTOEXTENSION_TEMPLATE: - bFileOpenDialog = false; - winResTemplateId = TMPL2000_FILEOPEN_AUTOEXT_TEMPLATE_BOX_ID; - break; - - case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE: - winResTemplateId = TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_ID; - break; - - case FILEOPEN_PLAY: - case FILEOPEN_LINK_PLAY: //FIXME: FILEOPEN_LINK_PLAY needs an own template, no idea how to create one - winResTemplateId = TMPL2000_PLAY_PUSHBUTTON; - break; - - case FILEOPEN_READONLY_VERSION: - winResTemplateId = TMPL2000_FILEOPEN_READONLY_VERSION_BOX_ID; - break; - - case FILEOPEN_LINK_PREVIEW: - case FILEOPEN_PREVIEW: //FIXME: FILEOPEN_PREVIEW needs an own template, no idea how to create one - winResTemplateId = TMPL2000_FILEOPEN_LINK_PREVIEW_BOX_SIMPLE_ID; - break; - - case FILESAVE_AUTOEXTENSION: - bFileOpenDialog = false; - winResTemplateId = TMPL2000_FILESAVE_AUTOEXT; - break; - - default: - throw lang::IllegalArgumentException( - "Unknown template", - static_cast< XFilePicker2* >( this ), - 1 ); - } - - HINSTANCE hInstance = GetModuleHandle( FILE_PICKER_DLL_NAME ); - SAL_WARN_IF( !hInstance, "fpicker", "The name of the service dll must have changed" ); - - // create a new impl-class here based on the - // given string, if the given string is empty - // we do nothing - m_pImpl = std::unique_ptr< CWinFileOpenImpl >( - new CWinFileOpenImpl( - this, - bFileOpenDialog, - 0, - winResTemplateId, - hInstance ) ); -} - -void SAL_CALL CFilePicker::cancel() -{ - OSL_ASSERT(m_pImpl.get()); - - osl::MutexGuard aGuard(m_aMutex); - m_pImpl->cancel(); -} - -// XServiceInfo - -OUString SAL_CALL CFilePicker::getImplementationName() -{ - return OUString(FILE_PICKER_IMPL_NAME); -} - -sal_Bool SAL_CALL CFilePicker::supportsService(const OUString& ServiceName) -{ - return cppu::supportsService(this, ServiceName); -} - -uno::Sequence<OUString> SAL_CALL CFilePicker::getSupportedServiceNames() -{ - return FilePicker_getSupportedServiceNames(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/FilePicker.hxx b/fpicker/source/win32/filepicker/FilePicker.hxx deleted file mode 100644 index 23cddeafadd0..000000000000 --- a/fpicker/source/win32/filepicker/FilePicker.hxx +++ /dev/null @@ -1,179 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKER_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKER_HXX - -#include <cppuhelper/compbase.hxx> -#include <osl/mutex.hxx> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/ui/dialogs/XFilePicker3.hpp> -#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> -#include <com/sun/star/ui/dialogs/XFilePreview.hpp> -#include "asynceventnotifier.hxx" -#include "eventnotification.hxx" - -#include <memory> - -// Implementation class for the XFilePicker Interface - -class CWinFileOpenImpl; - -class CFilePickerDummy -{ -protected: - osl::Mutex m_aMutex; - osl::Mutex m_rbHelperMtx; -}; - -typedef ::cppu::WeakComponentImplHelper < - css::ui::dialogs::XFilePicker3, - css::ui::dialogs::XFilePickerControlAccess, - css::ui::dialogs::XFilePreview, - css::lang::XInitialization, - css::lang::XServiceInfo > CFilePicker_Base; - -class CFilePicker : - public CFilePickerDummy, - public CFilePicker_Base -{ -public: - - // ctor - explicit CFilePicker( const css::uno::Reference< css::lang::XMultiServiceFactory >& xServiceMgr ); - - // XFilePickerNotifier - - virtual void SAL_CALL addFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override; - virtual void SAL_CALL removeFilePickerListener( const css::uno::Reference< css::ui::dialogs::XFilePickerListener >& xListener ) override; - - // XExecutableDialog functions - - virtual void SAL_CALL setTitle( const OUString& aTitle ) override; - - virtual sal_Int16 SAL_CALL execute( ) override; - - // XFilePicker functions - - virtual void SAL_CALL setMultiSelectionMode( sal_Bool bMode ) override; - - virtual void SAL_CALL setDefaultName( const OUString& aName ) override; - - virtual void SAL_CALL setDisplayDirectory( const OUString& aDirectory ) override; - - virtual OUString SAL_CALL getDisplayDirectory( ) override; - - virtual css::uno::Sequence< OUString > SAL_CALL getFiles( ) override; - - // XFilePicker2 functions - - virtual css::uno::Sequence< OUString > SAL_CALL getSelectedFiles( ) override; - - // XFilterManager functions - - virtual void SAL_CALL appendFilter( const OUString& aTitle, const OUString& aFilter ) override; - - virtual void SAL_CALL setCurrentFilter( const OUString& aTitle ) override; - - virtual OUString SAL_CALL getCurrentFilter( ) override; - - // XFilterGroupManager functions - - virtual void SAL_CALL appendFilterGroup( const OUString& sGroupTitle, const css::uno::Sequence< css::beans::StringPair >& aFilters ) override; - - // XFilePickerControlAccess functions - - virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const css::uno::Any& aValue ) override; - - virtual css::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) override; - - virtual void SAL_CALL enableControl( sal_Int16 aControlId, sal_Bool bEnable ) override; - - virtual void SAL_CALL setLabel( sal_Int16 aControlId, const OUString& aLabel ) override; - - virtual OUString SAL_CALL getLabel( sal_Int16 aControlId ) override; - - // XFilePreview - - virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats( ) override; - - virtual sal_Int32 SAL_CALL getTargetColorDepth( ) override; - - virtual sal_Int32 SAL_CALL getAvailableWidth( ) override; - - virtual sal_Int32 SAL_CALL getAvailableHeight( ) override; - - virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const css::uno::Any& aImage ) override; - - virtual sal_Bool SAL_CALL setShowState( sal_Bool bShowState ) override; - - virtual sal_Bool SAL_CALL getShowState( ) override; - - // XInitialization - - virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; - - // XCancellable - - virtual void SAL_CALL cancel( ) override; - - // XEventListener - - /// @throws css::uno::RuntimeException - virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ); - - // XServiceInfo - - virtual OUString SAL_CALL getImplementationName( ) override; - - virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; - - virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; - - // FilePicker Event functions - - void SAL_CALL fileSelectionChanged( css::ui::dialogs::FilePickerEvent aEvent ); - void SAL_CALL directoryChanged( css::ui::dialogs::FilePickerEvent aEvent ); - OUString SAL_CALL helpRequested( css::ui::dialogs::FilePickerEvent aEvent ) const; - void SAL_CALL controlStateChanged( css::ui::dialogs::FilePickerEvent aEvent ); - void SAL_CALL dialogSizeChanged( ); - - bool startupEventNotification(bool bStartupSuspended); - void shutdownEventNotification(); - void suspendEventNotification(); - void resumeEventNotification(); - -private: - // prevent copy and assignment - CFilePicker( const CFilePicker& ); - CFilePicker& operator=( const CFilePicker& ); - - using WeakComponentImplHelperBase::disposing; - -private: - css::uno::Reference< css::lang::XMultiServiceFactory > m_xServiceMgr; // to instanciate own services - CAsyncEventNotifier m_aAsyncEventNotifier; - std::unique_ptr<CWinFileOpenImpl> m_pImpl; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/VistaFilePicker.cxx b/fpicker/source/win32/filepicker/VistaFilePicker.cxx index 05ba2266f103..ebe19f3b42b8 100644 --- a/fpicker/source/win32/filepicker/VistaFilePicker.cxx +++ b/fpicker/source/win32/filepicker/VistaFilePicker.cxx @@ -26,7 +26,6 @@ // Without IFileDialogCustomize we can't do much #ifdef __IFileDialogCustomize_INTERFACE_DEFINED__ -#include "WinFileOpenImpl.hxx" #include "../misc/WinImplHelper.hxx" #include "shared.hxx" diff --git a/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx b/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx deleted file mode 100644 index 30f20acfee94..000000000000 --- a/fpicker/source/win32/filepicker/WinFileOpenImpl.cxx +++ /dev/null @@ -1,830 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "shared.hxx" -#include "WinFileOpenImpl.hxx" -#include <osl/diagnose.h> -#include <osl/file.hxx> -#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> -#include <com/sun/star/ui/dialogs/FilePickerEvent.hpp> -#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> -#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> -#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> -#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> -#include "../misc/WinImplHelper.hxx" - -#include "FilePicker.hxx" -#include "controlaccess.hxx" -#include "customcontrolfactory.hxx" -#include <rtl/ustrbuf.hxx> -#include <rtl/string.hxx> -#include <osl/thread.hxx> -#include "filepickerstate.hxx" - -using namespace com::sun::star; - -using com::sun::star::ui::dialogs::FilePickerEvent; -using com::sun::star::lang::IllegalArgumentException; -using com::sun::star::ui::dialogs::XFilePicker2; - -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 -{ - INIT_CUSTOM_CONTROLS, - CACHE_CONTROL_VALUES -}; - -struct EnumParam -{ - ECW_ACTION_T m_action; - CWinFileOpenImpl* m_instance; - - EnumParam( ECW_ACTION_T action, CWinFileOpenImpl* instance ): - m_action( action ), - m_instance( instance ) - {} -}; - -CWinFileOpenImpl::CWinFileOpenImpl( - CFilePicker* aFilePicker, - bool bFileOpenDialog, - sal_uInt32 dwFlags, - sal_uInt32 dwTemplateId, - HINSTANCE hInstance) : - CFileOpenDialog(bFileOpenDialog, dwFlags, dwTemplateId, hInstance), - m_filterContainer(new CFilterContainer()), - m_Preview(new CPreviewAdapter(hInstance)), - m_CustomControls(CCustomControlFactory::CreateCustomControlContainer()), - m_FilePicker(aFilePicker), - m_bInitialSelChanged(true), - m_HelpPopupWindow(hInstance, m_hwndFileOpenDlg), - m_ExecuteFilePickerState(new CExecuteFilePickerState()), - m_NonExecuteFilePickerState(new CNonExecuteFilePickerState()) -{ - m_FilePickerState = m_NonExecuteFilePickerState; -} - -CWinFileOpenImpl::~CWinFileOpenImpl() -{ - delete m_ExecuteFilePickerState; - delete m_NonExecuteFilePickerState; -} - -// we expect the directory in URL format - -void CWinFileOpenImpl::setDisplayDirectory(const OUString& aDirectory) -{ - OUString aSysDirectory; - if( aDirectory.getLength() > 0) - { - if ( ::osl::FileBase::E_None != - ::osl::FileBase::getSystemPathFromFileURL(aDirectory,aSysDirectory)) - throw IllegalArgumentException( - "Invalid directory", - static_cast<XFilePicker2*>(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 - // hierarchy which is the desktop folder - if ( aSysDirectory.lastIndexOf(BACKSLASH) != (aSysDirectory.getLength() - 1)) - aSysDirectory += BACKSLASH; - } - - // call base class method - CFileOpenDialog::setDisplayDirectory(aSysDirectory); -} - -// we return the directory in URL format - -OUString CWinFileOpenImpl::getDisplayDirectory() -{ - return m_FilePickerState->getDisplayDirectory(this); -} - -void SAL_CALL CWinFileOpenImpl::setDefaultName(const OUString& aName) -{ - // 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 - -uno::Sequence<OUString> SAL_CALL CWinFileOpenImpl::getFiles() -{ - return m_FilePickerState->getFiles(this); -} - -// shows the FileOpen/FileSave dialog - -sal_Int16 SAL_CALL CWinFileOpenImpl::execute( ) -{ - sal_Int16 rc = CFileOpenDialog::doModal(); - - if (1 == rc) - rc = css::ui::dialogs::ExecutableDialogResults::OK; - else if (0 == rc) - rc = css::ui::dialogs::ExecutableDialogResults::CANCEL; - else - throw uno::RuntimeException( - "Error executing dialog", - static_cast<XFilePicker2*>(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) -{ - bool bRet = m_filterContainer->addFilter(aTitle, aFilter); - - if (!bRet) - throw IllegalArgumentException( - "filter already exists", - static_cast<XFilePicker2*>(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) -{ - sal_Int32 filterPos = m_filterContainer->getFilterPos(aTitle); - - if (filterPos < 0) - throw IllegalArgumentException( - "filter doesn't exist", - static_cast<XFilePicker2*>(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() -{ - sal_uInt32 nIndex = getSelectedFilterIndex(); - - OUString currentFilter; - if (nIndex > 0) - { - // filter index of the base class starts with 1 - if (!m_filterContainer->getFilter(nIndex - 1, currentFilter)) { - OSL_ASSERT(false); - } - } - - 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 uno::Sequence<beans::StringPair>& aFilters) -{ - (void) sGroupTitle; // avoid warning - 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 - -// #i90917: Due to a different feature set for the system-dependent file pickers -// it's possible that generic code (e.g. sfx2) provides control ids -// (see ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR) which are NOT -// available on all platforms. This filter function should filter out control ids -// which are only available on KDE/GTK file pickers. -static bool filterControlCommand( sal_Int16 nControlId ) -{ - if ( nControlId == LISTBOX_FILTER_SELECTOR ) - return true; - return false; -} - -void SAL_CALL CWinFileOpenImpl::setValue(sal_Int16 aControlId, sal_Int16 aControlAction, const uno::Any& aValue) -{ - OSL_ASSERT(m_FilePickerState); - if ( !filterControlCommand( aControlId )) - m_FilePickerState->setValue(aControlId, aControlAction, aValue); -} - -// returns the value of an custom template element -// we assume that there are only checkboxes or comboboxes - -uno::Any SAL_CALL CWinFileOpenImpl::getValue(sal_Int16 aControlId, sal_Int16 aControlAction) -{ - OSL_ASSERT(m_FilePickerState); - if ( !filterControlCommand( aControlId )) - return m_FilePickerState->getValue(aControlId, aControlAction); - else - return uno::Any(); -} - -// enables a custom template element - -void SAL_CALL CWinFileOpenImpl::enableControl(sal_Int16 ControlID, bool bEnable) -{ - OSL_ASSERT(m_FilePickerState); - if ( !filterControlCommand( ControlID )) - m_FilePickerState->enableControl(ControlID, bEnable); -} - -void SAL_CALL CWinFileOpenImpl::setLabel( sal_Int16 aControlId, const OUString& aLabel ) -{ - OSL_ASSERT(m_FilePickerState); - if ( !filterControlCommand( aControlId )) - m_FilePickerState->setLabel(aControlId, aLabel); -} - -OUString SAL_CALL CWinFileOpenImpl::getLabel( sal_Int16 aControlId ) -{ - OSL_ASSERT(m_FilePickerState); - if ( !filterControlCommand( aControlId )) - return m_FilePickerState->getLabel(aControlId); - else - return OUString(); -} - -uno::Sequence<sal_Int16> SAL_CALL CWinFileOpenImpl::getSupportedImageFormats() -{ - return CPreviewAdapter::getSupportedImageFormats(); -} - -sal_Int32 SAL_CALL CWinFileOpenImpl::getTargetColorDepth() -{ - return m_Preview->getTargetColorDepth(); -} - -sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableWidth() -{ - return m_Preview->getAvailableWidth(); -} - -sal_Int32 SAL_CALL CWinFileOpenImpl::getAvailableHeight() -{ - return m_Preview->getAvailableHeight(); -} - -void SAL_CALL CWinFileOpenImpl::setImage(sal_Int16 aImageFormat, const uno::Any& aImage) -{ - m_Preview->setImage(aImageFormat,aImage); -} - -bool SAL_CALL CWinFileOpenImpl::setShowState(bool bShowState) -{ - return m_Preview->setShowState(bShowState); -} - -bool SAL_CALL CWinFileOpenImpl::getShowState() -{ - return m_Preview->getShowState(); -} - -void SAL_CALL CWinFileOpenImpl::cancel() -{ - if (IsWindow(m_hwndFileOpenDlg)) - { - // simulate a mouse click to the - // cancel button - BOOL const ret = PostMessage( - m_hwndFileOpenDlg, - WM_COMMAND, - MAKEWPARAM(IDCANCEL,BN_CLICKED), - reinterpret_cast<LPARAM>(GetDlgItem(m_hwndFileOpenDlg, IDCANCEL))); - SAL_WARN_IF(0 == ret, "fpicker", "ERROR: PostMessage() failed!"); - } -} - -// returns the id of a custom template element - -sal_Int16 SAL_CALL CWinFileOpenImpl::getFocused() -{ - int 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) - nID = 0; - - return sal::static_int_cast< sal_Int16 >(nID); -} - -inline bool SAL_CALL CWinFileOpenImpl::IsCustomControlHelpRequested(LPHELPINFO lphi) -{ - 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 - -LRESULT CALLBACK CWinFileOpenImpl::SubClassFunc( - HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam) -{ - unsigned int lResult = 0; - - CWinFileOpenImpl* pImpl = dynamic_cast<CWinFileOpenImpl*>(getCurrentInstance(hWnd)); - - switch(wMessage) - { - case WM_HELP: - { - LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam); - - if (CWinFileOpenImpl::IsCustomControlHelpRequested(lphi)) - pImpl->onCustomControlHelpRequest(lphi); - else - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - } - break; - - case WM_SIZE: - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - - pImpl->onWMSize(); - break; - - case WM_WINDOWPOSCHANGED: - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - - pImpl->onWMWindowPosChanged(); - break; - - case WM_SHOWWINDOW: - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - - pImpl->onWMShow(bool(wParam)); - break; - - case WM_NCDESTROY: - // restore the old window proc - SetWindowLongPtr(hWnd, GWLP_WNDPROC, - reinterpret_cast<LONG_PTR>(pImpl->m_pfnOldDlgProc)); - - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - break; - - default: - lResult = CallWindowProc( - reinterpret_cast<WNDPROC>(pImpl->m_pfnOldDlgProc), - hWnd,wMessage,wParam,lParam); - break; - - } // switch - - return lResult; -} - -void SAL_CALL CWinFileOpenImpl::InitControlLabel(HWND hWnd) -{ - - // set the labels for all extended controls - - - sal_Int16 aCtrlId = sal::static_int_cast< sal_Int16 >(GetDlgCtrlID(hWnd)); - OUString aLabel = m_ResProvider.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/cmb13 (defined in MS platform sdk dlgs.h) -// and all push buttons will be left aligned with the standard -// "OK" button - -void SAL_CALL CWinFileOpenImpl::InitCustomControlContainer(HWND hCustomControl) -{ - m_CustomControls->AddControl( - CCustomControlFactory::CreateCustomControl(hCustomControl,m_hwndFileOpenDlg)); -} - -void SAL_CALL CWinFileOpenImpl::CacheControlState(HWND hWnd) -{ - OSL_ASSERT(m_FilePickerState && m_NonExecuteFilePickerState); - m_ExecuteFilePickerState->cacheControlState(hWnd, m_NonExecuteFilePickerState); -} - -BOOL CALLBACK CWinFileOpenImpl::EnumChildWndProc(HWND hWnd, LPARAM lParam) -{ - EnumParam* enumParam = reinterpret_cast<EnumParam*>(lParam); - CWinFileOpenImpl* pImpl = enumParam->m_instance; - - OSL_ASSERT(pImpl); - - bool bRet = true; - - switch(enumParam->m_action) - { - case INIT_CUSTOM_CONTROLS: - pImpl->InitControlLabel(hWnd); - pImpl->InitCustomControlContainer(hWnd); - break; - - case CACHE_CONTROL_VALUES: - pImpl->CacheControlState(hWnd); - break; - - default: - // should not end here - OSL_ASSERT(false); - } - - return bRet; -} - -sal_uInt32 SAL_CALL CWinFileOpenImpl::onFileOk() -{ - m_NonExecuteFilePickerState->reset(); - - EnumParam enumParam(CACHE_CONTROL_VALUES,this); - - EnumChildWindows( - m_hwndFileOpenDlgChild, - CWinFileOpenImpl::EnumChildWndProc, - reinterpret_cast<LPARAM>(&enumParam)); - - return 0; -} - -void SAL_CALL CWinFileOpenImpl::onSelChanged(HWND) -{ - // 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 - // remember that this is the first SelChanged message - // and set the default name here to overwrite the - // windows setting - InitialSetDefaultName(); - - FilePickerEvent evt; - m_FilePicker->fileSelectionChanged(evt); -} - -// #i40865# The size of the standard labels 'File name' -// and 'File type' is to short in some cases when the -// label will be changed (e.g. in the Brazil version). -// We just make sure that the labels are using the maximum -// available space. -void CWinFileOpenImpl::EnlargeStdControlLabels() const -{ - HWND hFilterBoxLabel = GetDlgItem(m_hwndFileOpenDlg, stc2); - HWND hFileNameBoxLabel = GetDlgItem(m_hwndFileOpenDlg, stc3); - HWND hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, cmb13); - if (!hFileNameBox) - hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, edt1); // since Win2k it is cmb13 or edt1 - - HWND hFilterBox = GetDlgItem(m_hwndFileOpenDlg, cmb1); - HWND hOkButton = GetDlgItem(m_hwndFileOpenDlg, IDOK); - - // Move filter and file name box nearer to OK and Cancel button - RECT rcOkButton; - GetWindowRect(hOkButton, &rcOkButton); - - const int MAX_GAP = 10; - const int OFFSET = 0; - - RECT rcFileNameBox; - GetWindowRect(hFileNameBox, &rcFileNameBox); - int w = rcFileNameBox.right - rcFileNameBox.left; - int h = rcFileNameBox.bottom - rcFileNameBox.top; - - int gap = rcOkButton.left - rcFileNameBox.right; - gap = (gap > MAX_GAP) ? gap - MAX_GAP : gap; - - ScreenToClient(m_hwndFileOpenDlg, reinterpret_cast<LPPOINT>(&rcFileNameBox)); - MoveWindow(hFileNameBox, rcFileNameBox.left + gap + OFFSET, rcFileNameBox.top, w - OFFSET, h, true); - - RECT rcFilterBox; - GetWindowRect(hFilterBox, &rcFilterBox); - w = rcFilterBox.right - rcFilterBox.left; - h = rcFilterBox.bottom - rcFilterBox.top; - ScreenToClient(m_hwndFileOpenDlg, reinterpret_cast<LPPOINT>(&rcFilterBox)); - MoveWindow(hFilterBox, rcFilterBox.left + gap + OFFSET, rcFilterBox.top, w - OFFSET, h, true); - - // get the new window rect - GetWindowRect(hFileNameBox, &rcFileNameBox); - - RECT rcFilterBoxLabel; - GetWindowRect(hFilterBoxLabel, &rcFilterBoxLabel); - int offset = rcFileNameBox.left - rcFilterBoxLabel.right - 1; - - w = rcFilterBoxLabel.right - rcFilterBoxLabel.left + offset; - h = rcFilterBoxLabel.bottom - rcFilterBoxLabel.top; - ScreenToClient(m_hwndFileOpenDlg, reinterpret_cast<LPPOINT>(&rcFilterBoxLabel)); - MoveWindow(hFilterBoxLabel, rcFilterBoxLabel.left, rcFilterBoxLabel.top, w, h, true); - - RECT rcFileNameBoxLabel; - GetWindowRect(hFileNameBoxLabel, &rcFileNameBoxLabel); - w = rcFileNameBoxLabel.right - rcFileNameBoxLabel.left + offset; - h = rcFileNameBoxLabel.bottom - rcFileNameBoxLabel.top; - ScreenToClient(m_hwndFileOpenDlg, reinterpret_cast<LPPOINT>(&rcFileNameBoxLabel)); - MoveWindow(hFileNameBoxLabel, rcFileNameBoxLabel.left, rcFileNameBoxLabel.top, w, h, true); -} - -void SAL_CALL CWinFileOpenImpl::onInitDone() -{ - m_Preview->setParent(m_hwndFileOpenDlg); - - // but now we have a valid parent handle - m_HelpPopupWindow.setParent(m_hwndFileOpenDlg); - - EnlargeStdControlLabels(); - - // #99826 - // Set the online filepicker state before initializing - // the control labels from the resource else we are - // overriding the offline settings - m_ExecuteFilePickerState->setHwnd(m_hwndFileOpenDlgChild); - - m_FilePickerState = m_ExecuteFilePickerState; - - // initialize controls from cache - - EnumParam enumParam(INIT_CUSTOM_CONTROLS,this); - - EnumChildWindows( - m_hwndFileOpenDlgChild, - CWinFileOpenImpl::EnumChildWndProc, - reinterpret_cast<LPARAM>(&enumParam)); - - m_ExecuteFilePickerState->initFilePickerControls( - m_NonExecuteFilePickerState->getControlCommand()); - - SetDefaultExtension(); - - m_CustomControls->Align(); - - m_CustomControls->SetFont( - reinterpret_cast<HFONT>(SendMessageW(m_hwndFileOpenDlg, WM_GETFONT, 0, 0))); - - // resume event notification that was - // defered in onInitDialog - m_FilePicker->resumeEventNotification(); - - //#105996 let vcl know that now a system window is active - BOOL const ret = PostMessage( - HWND_BROADCAST, - RegisterWindowMessageW(L"SYSTEM_WINDOW_ACTIVATED"), - 0, - 0); - SAL_WARN_IF(0 == ret, "fpicker", "ERROR: PostMessage() failed!"); - - // call the parent function to center the - // dialog to its parent - CFileOpenDialog::onInitDone(); -} - -void SAL_CALL CWinFileOpenImpl::onFolderChanged() -{ - FilePickerEvent evt; - m_FilePicker->directoryChanged(evt); -} - -void SAL_CALL CWinFileOpenImpl::onTypeChanged(sal_uInt32) -{ - SetDefaultExtension(); - - FilePickerEvent evt; - evt.ElementId = LISTBOX_FILTER; - m_FilePicker->controlStateChanged(evt); -} - -// onMessageCommand handler - -sal_uInt32 SAL_CALL CWinFileOpenImpl::onCtrlCommand( - HWND, sal_uInt16 ctrlId, sal_uInt16) -{ - SetDefaultExtension(); - - if (ctrlId < ctlFirst) - { - FilePickerEvent evt; - evt.ElementId = ctrlId; - m_FilePicker->controlStateChanged(evt); - } - - return 0; -} - -void CWinFileOpenImpl::onWMSize() -{ - m_Preview->notifyParentSizeChanged(); - m_CustomControls->Align(); - m_FilePicker->dialogSizeChanged(); -} - -void CWinFileOpenImpl::onWMShow(bool bShow) -{ - m_Preview->notifyParentShow(bShow); -} - -void CWinFileOpenImpl::onWMWindowPosChanged() -{ - m_Preview->notifyParentWindowPosChanged(); -} - -void CWinFileOpenImpl::onCustomControlHelpRequest(LPHELPINFO lphi) -{ - FilePickerEvent evt; - evt.ElementId = sal::static_int_cast< sal_Int16 >(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)); - } -} - -void SAL_CALL CWinFileOpenImpl::onInitDialog(HWND hwndDlg) -{ - // subclass the dialog window - m_pfnOldDlgProc = - reinterpret_cast<WNDPROC>( - SetWindowLongPtr( hwndDlg, GWLP_WNDPROC, - reinterpret_cast<LONG_PTR>(SubClassFunc))); -} - -// processing before showing the dialog - -bool SAL_CALL CWinFileOpenImpl::preModal() -{ - CFileOpenDialog::setFilter( - makeWinFilterBuffer(*m_filterContainer.get())); - - return true; -} - -// processing after showing the dialog - -void CWinFileOpenImpl::postModal(sal_Int16 nDialogResult) -{ - CFileOpenDialog::postModal(nDialogResult); - - // empty the container in order to get rid off - // invalid controls in case someone calls execute - // twice in sequence with the same instance - m_CustomControls->RemoveAllControls(); - - m_FilePickerState = m_NonExecuteFilePickerState; -} - -void SAL_CALL CWinFileOpenImpl::SetDefaultExtension() -{ - HWND hwndChkSaveWithExt = GetDlgItem(m_hwndFileOpenDlgChild, 100); - - if (hwndChkSaveWithExt) - { - uno::Any aAny = CheckboxGetState(hwndChkSaveWithExt); - bool bChecked = *static_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 - 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); - - SendMessageW(m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, reinterpret_cast<LPARAM>(FilterExt.getStr())); - } - } - } - else - { - SendMessageW(m_hwndFileOpenDlg, CDM_SETDEFEXT, 0, reinterpret_cast<LPARAM>(L"")); - } - } - - // !!! HACK !!! -} - -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()) - { - // under W2k by default 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. - // However, edt1 is still possible. See fdo#74295 - HWND hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, cmb13); - if (!hFileNameBox) - hFileNameBox = GetDlgItem(m_hwndFileOpenDlg, edt1); - SetWindowTextW(hFileNameBox, reinterpret_cast<PCWSTR>(m_defaultName.getStr())); - } - - m_bInitialSelChanged = false; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx b/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx deleted file mode 100644 index 634f2834fc58..000000000000 --- a/fpicker/source/win32/filepicker/WinFileOpenImpl.hxx +++ /dev/null @@ -1,201 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_WINFILEOPENIMPL_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_WINFILEOPENIMPL_HXX - -#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> -#include <com/sun/star/ui/dialogs/FilePickerEvent.hpp> -#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp> -#include "FilterContainer.hxx" -#include "FileOpenDlg.hxx" -#include "previewadapter.hxx" -#include "helppopupwindow.hxx" -#include "customcontrol.hxx" -#include "../misc/resourceprovider.hxx" - -#include <utility> -#include <memory> -#include <vector> -#include <osl/conditn.hxx> - -class CFilePicker; -class CFilePickerState; -class CExecuteFilePickerState; -class CNonExecuteFilePickerState; - -class CWinFileOpenImpl : public CFileOpenDialog -{ -public: - CWinFileOpenImpl( - CFilePicker* aFilePicker, - bool bFileOpenDialog = true, - sal_uInt32 dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, - sal_uInt32 dwTemplateId = 0, - HINSTANCE hInstance = nullptr ); - - virtual ~CWinFileOpenImpl( ) override; - - // XExecutableDialog - - /// @throws css::uno::RuntimeException - virtual sal_Int16 SAL_CALL execute( ); - - // XFilePicker - - virtual void SAL_CALL setDefaultName( const OUString& aName ) override; - - /// @throws css::uno::RuntimeException - virtual css::uno::Sequence< OUString > SAL_CALL getFiles( ); - - virtual void SAL_CALL setDisplayDirectory( const OUString& aDirectory ) override; - - /// @throws css::uno::RuntimeException - virtual OUString SAL_CALL getDisplayDirectory( ); - - // XFilterManager - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - virtual void SAL_CALL appendFilter( const OUString& aTitle, const OUString& aFilter ); - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - virtual void SAL_CALL setCurrentFilter( const OUString& aTitle ); - - /// @throws css::uno::RuntimeException - virtual OUString SAL_CALL getCurrentFilter( ); - - // XFilterGroupManager - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - virtual void SAL_CALL appendFilterGroup( const OUString& sGroupTitle, const css::uno::Sequence< css::beans::StringPair >& aFilters ); - - // XFilePickerControlAccess - - /// @throws css::uno::RuntimeException - virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const css::uno::Any& aValue ); - - /// @throws css::uno::RuntimeException - virtual css::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ); - - /// @throws css::uno::RuntimeException - virtual void SAL_CALL enableControl( sal_Int16 aControlId, bool bEnable ); - - /// @throws css::uno::RuntimeException - virtual void SAL_CALL setLabel( sal_Int16 aControlId, const OUString& aLabel ); - - /// @throws css::uno::RuntimeException - virtual OUString SAL_CALL getLabel( sal_Int16 aControlId ); - - // XFilePreview - - /// @throws css::uno::RuntimeException - virtual css::uno::Sequence< sal_Int16 > SAL_CALL getSupportedImageFormats( ); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getTargetColorDepth( ); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getAvailableWidth( ); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getAvailableHeight( ); - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const css::uno::Any& aImage ); - - /// @throws css::uno::RuntimeException - virtual bool SAL_CALL setShowState( bool bShowState ); - - /// @throws css::uno::RuntimeException - virtual bool SAL_CALL getShowState( ); - - // XCancelable - - virtual void SAL_CALL cancel( ); - - // Implementation details - -protected: - static sal_Int16 SAL_CALL getFocused( ); - - virtual bool SAL_CALL preModal( ) override; - virtual void SAL_CALL postModal( sal_Int16 nDialogResult ) override; - - virtual sal_uInt32 SAL_CALL onFileOk() override; - virtual void SAL_CALL onSelChanged( HWND hwndListBox ) override; - - // only called back if OFN_EXPLORER is set - virtual void SAL_CALL onInitDone() override; - virtual void SAL_CALL onFolderChanged() override; - virtual void SAL_CALL onTypeChanged( sal_uInt32 nFilterIndex ) override; - - // call base class method first when overriding - virtual void SAL_CALL onInitDialog( HWND hwndDlg ) override; - - virtual sal_uInt32 SAL_CALL onCtrlCommand( HWND hwndDlg, sal_uInt16 ctrlId, sal_uInt16 notifyCode ) override; - - void onWMSize(); - void onWMShow(bool bShow); - void onWMWindowPosChanged(); - void onCustomControlHelpRequest(LPHELPINFO lphi); - -private: - inline void SAL_CALL appendFilterGroupSeparator( ); - - static inline bool SAL_CALL IsCustomControlHelpRequested(LPHELPINFO lphi); - - void EnlargeStdControlLabels() 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); - - void SAL_CALL SetDefaultExtension(); - void SAL_CALL InitialSetDefaultName(); - - static LRESULT CALLBACK SubClassFunc(HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam); - - static BOOL CALLBACK EnumChildWndProc( HWND hWnd, LPARAM lParam ); - -private: - std::unique_ptr<CFilterContainer> m_filterContainer; - std::unique_ptr<CPreviewAdapter> m_Preview; - std::unique_ptr<CCustomControl> m_CustomControls; - CFilePicker* m_FilePicker; - WNDPROC m_pfnOldDlgProc; - OUString m_defaultName; - bool m_bInitialSelChanged; - CHelpPopupWindow m_HelpPopupWindow; - CFilePickerState* m_FilePickerState; - CExecuteFilePickerState* m_ExecuteFilePickerState; - CNonExecuteFilePickerState* m_NonExecuteFilePickerState; - CResourceProvider m_ResProvider; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/asynceventnotifier.cxx b/fpicker/source/win32/filepicker/asynceventnotifier.cxx deleted file mode 100644 index c30de36759a0..000000000000 --- a/fpicker/source/win32/filepicker/asynceventnotifier.cxx +++ /dev/null @@ -1,261 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include <osl/diagnose.h> -#include <osl/thread.h> -#include "asynceventnotifier.hxx" -#include <com/sun/star/uno/RuntimeException.hpp> -#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp> - -#include <process.h> -#include <memory> - -using namespace com::sun::star; -using ::com::sun::star::ui::dialogs::XFilePickerListener; - - -CAsyncEventNotifier::CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelper) : - m_hThread(nullptr), - m_bRun(false), - m_ThreadId(0), - m_rBroadcastHelper(rBroadcastHelper), - m_NotifyEvent(m_hEvents[0]), - m_ResumeNotifying(m_hEvents[1]) -{ - // m_NotifyEvent - m_hEvents[0] = CreateEvent(nullptr, /* no security */ - true, /* manual reset */ - false, /* initial state not signaled */ - nullptr); /* automatic name */ - - // m_ResumeNotifying - m_hEvents[1] = CreateEvent(nullptr, /* no security */ - true, /* manual reset */ - false, /* initial state not signaled */ - nullptr); /* automatic name */ -} - - -CAsyncEventNotifier::~CAsyncEventNotifier() -{ - OSL_ENSURE(nullptr == m_hThread,"Thread not stopped, destroying this instance leads to disaster"); - - CloseHandle(m_hEvents[0]); - CloseHandle(m_hEvents[1]); -} - - -void SAL_CALL CAsyncEventNotifier::addListener(const uno::Type& aType , - const uno::Reference< uno::XInterface >& xListener) -{ - if ( m_rBroadcastHelper.bDisposed ) - throw lang::DisposedException( "FilePicker is already disposed" ); - - if ( m_rBroadcastHelper.bInDispose ) - throw lang::DisposedException( "FilePicker will be disposed now." ); - - m_rBroadcastHelper.aLC.addInterface( aType, xListener ); -} - - -void SAL_CALL CAsyncEventNotifier::removeListener(const uno::Type& aType , - const uno::Reference< uno::XInterface >& xListener) -{ - if ( m_rBroadcastHelper.bDisposed ) - throw lang::DisposedException( "FilePicker is already disposed." ); - - m_rBroadcastHelper.aLC.removeInterface( aType, xListener ); -} - - -bool SAL_CALL CAsyncEventNotifier::startup(bool bCreateSuspended) -{ - osl::MutexGuard aGuard(m_Mutex); - - // m_bRun may already be false because of a - // call to stop but the thread did not yet - // terminate so m_hEventNotifierThread is - // yet a valid thread handle that should - // not be overwritten - if (!m_bRun) - { - if (!bCreateSuspended) - SetEvent(m_ResumeNotifying); - - m_hThread = reinterpret_cast<HANDLE>(_beginthreadex( - nullptr, 0, CAsyncEventNotifier::ThreadProc, this, 0, &m_ThreadId)); - - OSL_ASSERT(nullptr != m_hThread); - - if (m_hThread) - m_bRun = true; - } - - SAL_WARN_IF( !m_bRun, "fpicker", "Could not start event notifier!"); - - return m_bRun; -} - - -void SAL_CALL CAsyncEventNotifier::shutdown() -{ - OSL_PRECOND(GetCurrentThreadId() != m_ThreadId, - "Method called in wrong thread context!"); - - osl::ResettableMutexGuard aGuard(m_Mutex); - - OSL_PRECOND(m_bRun,"Event notifier does not run!"); - - m_bRun = false; - m_EventList.clear(); - - // awake the notifier thread - SetEvent(m_ResumeNotifying); - SetEvent(m_NotifyEvent); - - // release the mutex here because the event - // notifier thread may need it to finish - aGuard.clear(); - - // we are waiting infinite, so error will - // be better detected in form of deadlocks - if (WaitForSingleObject(m_hThread, INFINITE) == WAIT_FAILED) { - OSL_FAIL("Waiting for thread termination failed!"); - } - - // lock mutex again to reset m_hThread - // and prevent a race with start() - aGuard.reset(); - - CloseHandle(m_hThread); - m_hThread = nullptr; -} - - -void CAsyncEventNotifier::suspend() -{ - ResetEvent(m_ResumeNotifying); -} - - -void CAsyncEventNotifier::resume() -{ - SetEvent(m_ResumeNotifying); -} - - -void SAL_CALL CAsyncEventNotifier::notifyEvent(CEventNotification* EventNotification) -{ - osl::MutexGuard aGuard(m_Mutex); - - OSL_ENSURE(m_bRun,"Event notifier is not running!"); - - if (m_bRun) - { - m_EventList.push_back(EventNotification); - SetEvent(m_NotifyEvent); - } -} - - -size_t SAL_CALL CAsyncEventNotifier::getEventListSize() -{ - osl::MutexGuard aGuard(m_Mutex); - return m_EventList.size(); -} - - -void SAL_CALL CAsyncEventNotifier::resetNotifyEvent() -{ - osl::MutexGuard aGuard(m_Mutex); - if ( m_EventList.empty() ) - ResetEvent(m_NotifyEvent); -} - - -CEventNotification* SAL_CALL CAsyncEventNotifier::getNextEventRecord() -{ - osl::MutexGuard aGuard(m_Mutex); - return m_EventList.front(); -} - - -void SAL_CALL CAsyncEventNotifier::removeNextEventRecord() -{ - osl::MutexGuard aGuard(m_Mutex); - m_EventList.pop_front(); -} - - -void SAL_CALL CAsyncEventNotifier::run() -{ - while (m_bRun) - { - WaitForMultipleObjects(2, m_hEvents, true, INFINITE); - - if (m_bRun) - { - while (getEventListSize() > 0) - { - std::unique_ptr<CEventNotification> EventNotification(getNextEventRecord()); - removeNextEventRecord(); - - ::cppu::OInterfaceContainerHelper* pICHelper = - m_rBroadcastHelper.getContainer(cppu::UnoType<XFilePickerListener>::get()); - - if (pICHelper) - { - ::cppu::OInterfaceIteratorHelper iter(*pICHelper); - - while(iter.hasMoreElements()) - { - try - { - EventNotification->notifyEventListener(iter.next()); - } - catch(uno::RuntimeException&) - { - OSL_FAIL("RuntimeException during event dispatching"); - } - } - } - - } // while(getEventListSize() > 0) - - resetNotifyEvent(); - - } // if (m_bRun) - - } // while(m_bRun) -} - - -unsigned int WINAPI CAsyncEventNotifier::ThreadProc(LPVOID pParam) -{ - osl_setThreadName("fpicker CAsyncEventNotifier::run()"); - - CAsyncEventNotifier* pInst = static_cast< CAsyncEventNotifier* >(pParam); - OSL_ASSERT(pInst); - - pInst->run(); - - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/asynceventnotifier.hxx b/fpicker/source/win32/filepicker/asynceventnotifier.hxx deleted file mode 100644 index c394398baa84..000000000000 --- a/fpicker/source/win32/filepicker/asynceventnotifier.hxx +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCEVENTNOTIFIER_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_ASYNCEVENTNOTIFIER_HXX - -#include <osl/mutex.hxx> -#include <osl/conditn.hxx> -#include <cppuhelper/interfacecontainer.h> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - -#include <list> -#include <utility> -#include "eventnotification.hxx" - - -class CAsyncEventNotifier -{ -public: - explicit CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelper); - ~CAsyncEventNotifier(); - - bool SAL_CALL startup(bool bCreateSuspended = true); - void SAL_CALL shutdown(); - - // notifications may be added the event queue but will only - // be notified to the clients after resume was called - void suspend(); - - // resume notifying events - void resume(); - - // this class is responsible for the memory management of - // the CEventNotification instance - void SAL_CALL notifyEvent(CEventNotification* EventNotification); - - void SAL_CALL addListener (const css::uno::Type& aType , - const css::uno::Reference< css::uno::XInterface >& xListener); - void SAL_CALL removeListener(const css::uno::Type& aType , - const css::uno::Reference< css::uno::XInterface >& xListener); - -private: - size_t SAL_CALL getEventListSize(); - void SAL_CALL resetNotifyEvent(); - CEventNotification* SAL_CALL getNextEventRecord(); - void SAL_CALL removeNextEventRecord(); - - void SAL_CALL run( ); - - static unsigned int WINAPI ThreadProc(LPVOID pParam); - -private: - std::list<CEventNotification*> m_EventList; - HANDLE m_hThread; - bool m_bRun; - unsigned m_ThreadId; - ::cppu::OBroadcastHelper& m_rBroadcastHelper; - HANDLE m_hEvents[2]; - HANDLE& m_NotifyEvent; - HANDLE& m_ResumeNotifying; - osl::Mutex m_Mutex; - -// prevent copy and assignment -private: - CAsyncEventNotifier( const CAsyncEventNotifier& ); - CAsyncEventNotifier& operator=( const CAsyncEventNotifier& ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlaccess.cxx b/fpicker/source/win32/filepicker/controlaccess.cxx deleted file mode 100644 index 6b4de5b4f597..000000000000 --- a/fpicker/source/win32/filepicker/controlaccess.cxx +++ /dev/null @@ -1,203 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/macros.h> -#include "controlaccess.hxx" -#include "../misc/WinImplHelper.hxx" - -// we are using a table based algorithm to dispatch control -// actions there is one table containing one action table for -// each control class and one action table per control class -// which contains function pointer to control action functions - -namespace -{ - // table setup - - CTRL_SETVALUE_FUNCTION_T CheckboxSetValueFunctionTable[] = - { - CheckboxSetState - }; - const size_t SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE = - SAL_N_ELEMENTS( CheckboxSetValueFunctionTable ); - - CTRL_GETVALUE_FUNCTION_T CheckboxGetValueFunctionTable[] = - { - CheckboxGetState - }; - const size_t SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE = - SAL_N_ELEMENTS( CheckboxGetValueFunctionTable ); - - CTRL_SETVALUE_FUNCTION_T ListboxSetValueFunctionTable[] = - { - nullptr, - ListboxAddItem, - ListboxAddItems, - ListboxDeleteItem, - ListboxDeleteItems, - ListboxSetSelectedItem - }; - const size_t SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE = - SAL_N_ELEMENTS( ListboxSetValueFunctionTable ); - - CTRL_GETVALUE_FUNCTION_T ListboxGetValueFunctionTable[] = - { - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - ListboxGetItems, - ListboxGetSelectedItem, - ListboxGetSelectedItemIndex - }; - const size_t SIZE_LISTBOX_GETVALUE_ACTION_TABLE = - SAL_N_ELEMENTS( ListboxGetValueFunctionTable ); - - struct ENTRY - { - LPVOID lpFunctionTable; - size_t TableSize; - }; - - // an array of function tables, one for each control class - ENTRY CtrlClassSetValueFunctionTable[] = - { - { nullptr, 0 }, - { CheckboxSetValueFunctionTable, SIZE_CHECKBOX_SETVALUE_FUNCTION_TABLE }, - { ListboxSetValueFunctionTable, SIZE_LISTBOX_SETVALUE_FUNCTION_TABLE }, - { nullptr, 0 } - }; - - // an array of function tables, one for each control class - ENTRY CtrlClassGetValueFunctionTable[] = - { - { nullptr, 0 }, - { CheckboxGetValueFunctionTable, SIZE_CHECKBOX_GETVALUE_FUNCTION_TABLE }, - { ListboxGetValueFunctionTable, SIZE_LISTBOX_GETVALUE_ACTION_TABLE }, - { nullptr, 0 } - }; - - CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( - CTRL_SETVALUE_FUNCTION_T* aCtrlSetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction ) - { - if ( !aCtrlSetValueFunctionTable || - aCtrlAction < 0 - || sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize ) - return nullptr; - - return aCtrlSetValueFunctionTable[aCtrlAction]; - } - - CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( - CTRL_GETVALUE_FUNCTION_T* aCtrlGetValueFunctionTable, size_t aTableSize, sal_Int16 aCtrlAction ) - { - if ( !aCtrlGetValueFunctionTable || - aCtrlAction < 0 || - sal::static_int_cast< sal_uInt16 >(aCtrlAction) >= aTableSize ) - return nullptr; - - return aCtrlGetValueFunctionTable[aCtrlAction]; - } - - inline - ENTRY SAL_CALL GetCtrlClassSetValueFunctionTable( CTRL_CLASS aCtrlClass ) - { - return CtrlClassSetValueFunctionTable[aCtrlClass]; - } - - inline - ENTRY SAL_CALL GetCtrlClassGetValueFunctionTable( CTRL_CLASS aCtrlClass ) - { - return CtrlClassGetValueFunctionTable[aCtrlClass]; - } - - const int WindowsFileOpenCtrlIds[] = - { - 0, - IDOK, // PUSHBUTTON_OK - IDCANCEL, // PUSHBUTTON_CANCEL - cmb1, // LISTBOX_FILTER - 0, // CONTROL_FILEVIEW - 0, // not available in system file picker - stc2, // LISTBOX_FILTER_LABEL - stc3 // LISTBOX_FILE_NAME_LABEL - }; - const int SIZE_WINDOWS_FILEOPEN_CTRL_IDS = SAL_N_ELEMENTS(WindowsFileOpenCtrlIds); - -}; // end namespace - -CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction ) -{ - ENTRY aEntry = - GetCtrlClassSetValueFunctionTable( aCtrlClass ); - - return GetCtrlSetValueFunction( - static_cast< CTRL_SETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ), - aEntry.TableSize, - aCtrlAction ); -} - -CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction ) -{ - ENTRY aEntry = - GetCtrlClassGetValueFunctionTable( aCtrlClass ); - - return GetCtrlGetValueFunction( - static_cast< CTRL_GETVALUE_FUNCTION_T* >( aEntry.lpFunctionTable ), - aEntry.TableSize, - aCtrlAction ); -} - -CTRL_CLASS SAL_CALL GetCtrlClass( HWND hwndCtrl ) -{ - CTRL_CLASS aCtrlClass = UNKNOWN; - WCHAR aClassName[256]; - - int nRet = GetClassNameW(hwndCtrl,aClassName,SAL_N_ELEMENTS(aClassName)); - if (nRet) - { - if (0 == _wcsicmp(aClassName,L"button")) - { - // button means many things so we have - // to find out what button it is - LONG lBtnStyle = GetWindowLong(hwndCtrl,GWL_STYLE); - if (lBtnStyle & BS_CHECKBOX) - aCtrlClass = CHECKBOX; - else if (((lBtnStyle & BS_PUSHBUTTON) == 0) || (lBtnStyle & BS_DEFPUSHBUTTON)) - aCtrlClass = PUSHBUTTON; - } - else if (0 == _wcsicmp(aClassName,L"listbox") || - 0 == _wcsicmp(aClassName,L"combobox")) - aCtrlClass = LISTBOX; - } - - return aCtrlClass; -} - -int SAL_CALL CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId ) -{ - if ( aControlId < 0 || aControlId > SIZE_WINDOWS_FILEOPEN_CTRL_IDS ) - return aControlId; - - return WindowsFileOpenCtrlIds[aControlId]; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlaccess.hxx b/fpicker/source/win32/filepicker/controlaccess.hxx deleted file mode 100644 index 55544e3e42c8..000000000000 --- a/fpicker/source/win32/filepicker/controlaccess.hxx +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLACCESS_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLACCESS_HXX - -#include <sal/types.h> -#include <rtl/ustring.hxx> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif -#include <com/sun/star/uno/Any.hxx> - -typedef void ( SAL_CALL *CTRL_SETVALUE_FUNCTION_T)( HWND, const css::uno::Any&, const css::uno::Reference< css::uno::XInterface >&, sal_Int16 ); -typedef css::uno::Any ( SAL_CALL *CTRL_GETVALUE_FUNCTION_T )( HWND ); - -// the currently supported control classes -enum CTRL_CLASS -{ - UNKNOWN = 0, - CHECKBOX, - LISTBOX, - PUSHBUTTON -}; - -// returns the class of a control -CTRL_CLASS SAL_CALL GetCtrlClass( HWND hwndCtrl ); - -// returns a pointer to a setValue function based on the control class -// and the control action, if no function was found NULL will be returned -CTRL_SETVALUE_FUNCTION_T SAL_CALL GetCtrlSetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction ); - -// returns a pointer to a getValue function based on the control class -// and the control action, if no function was found NULL will be returned -CTRL_GETVALUE_FUNCTION_T SAL_CALL GetCtrlGetValueFunction( CTRL_CLASS aCtrlClass, sal_Int16 aCtrlAction ); - -// translates a CommonFilePickerElementId as defined in CommonFilePickerElementIds.idl -// to a control id that is valid for the FileOpen dialog under windows as defined -// in dlgs.h in the Windows Platform SDK -int SAL_CALL CommonFilePickerCtrlIdToWinFileOpenCtrlId( sal_Int16 aControlId ); - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlcommand.cxx b/fpicker/source/win32/filepicker/controlcommand.cxx deleted file mode 100644 index 5296e487a521..000000000000 --- a/fpicker/source/win32/filepicker/controlcommand.cxx +++ /dev/null @@ -1,219 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "controlcommand.hxx" -#include "controlcommandrequest.hxx" -#include "controlcommandresult.hxx" -#include "filepickerstate.hxx" - -#include <osl/diagnose.h> - - -CControlCommand::CControlCommand( sal_Int16 aControlId ) : - m_NextCommand( nullptr ), - m_aControlId( aControlId ) -{ -} - - -CControlCommand::~CControlCommand( ) -{ -} - - -CControlCommandResult* SAL_CALL CControlCommand::handleRequest( CControlCommandRequest* pRequest ) -{ - // if the command does not support handleRequest, it should at least - // redirect the request to the next element - // so the base class implementation has to do it - - OSL_ENSURE( pRequest, "invalid parameter" ); - - CControlCommandResult* result; - CControlCommand* nextCommand; - - nextCommand = getNextCommand( ); - if ( nextCommand ) - { - result = nextCommand->handleRequest( pRequest ); - } - else - { - result = new CControlCommandResult(); - } - - return result; -} - - -CControlCommand* SAL_CALL CControlCommand::getNextCommand( ) const -{ - return m_NextCommand; -} - - -void SAL_CALL CControlCommand::setNextCommand( CControlCommand* nextCommand ) -{ - m_NextCommand = nextCommand; -} - - -sal_Int16 SAL_CALL CControlCommand::getControlId( ) const -{ - return m_aControlId; -} - - -CValueControlCommand::CValueControlCommand( - sal_Int16 aControlId, - sal_Int16 aControlAction, - const css::uno::Any& aValue ) : - CControlCommand( aControlId ), - m_aControlAction( aControlAction ), - m_aValue( aValue ) -{ -} - - -void SAL_CALL CValueControlCommand::exec( CFilePickerState* aFilePickerState ) -{ - OSL_ENSURE( aFilePickerState, "empty reference" ); - - aFilePickerState->setValue( - getControlId( ), - m_aControlAction, - m_aValue ); -} - - -CControlCommandResult* SAL_CALL CValueControlCommand::handleRequest( CControlCommandRequest* aRequest ) -{ - CValueControlCommandRequest* value_request = - dynamic_cast< CValueControlCommandRequest* >( aRequest ); - - CControlCommandResult* result; - CControlCommand* nextCommand; - - if ( value_request && - (value_request->getControlId( ) == getControlId( )) && - (value_request->getControlAction( ) == m_aControlAction) ) - { - result = new CValueCommandResult( true, m_aValue ); - } - else - { - nextCommand = getNextCommand( ); - if ( nextCommand ) - { - result = nextCommand->handleRequest( aRequest ); - } - else - { - result = new CControlCommandResult( ); - } - } - - return result; -} - - -sal_Int16 SAL_CALL CValueControlCommand::getControlAction( ) const -{ - return m_aControlAction; -} - - -css::uno::Any SAL_CALL CValueControlCommand::getValue( ) const -{ - return m_aValue; -} - - -CLabelControlCommand::CLabelControlCommand( - sal_Int16 aControlId, - const OUString& aLabel ) : - CControlCommand( aControlId ), - m_aLabel( aLabel ) -{ -} - - -void SAL_CALL CLabelControlCommand::exec( CFilePickerState* aFilePickerState ) -{ - OSL_ENSURE( aFilePickerState, "empty reference" ); - - aFilePickerState->setLabel( getControlId( ), m_aLabel ); -} - - -CControlCommandResult* SAL_CALL CLabelControlCommand::handleRequest( CControlCommandRequest* aRequest ) -{ - OSL_ENSURE( aRequest, "invalid parameter" ); - - CControlCommandResult* result; - CControlCommand* nextCommand; - - CValueControlCommandRequest* value_request = - dynamic_cast< CValueControlCommandRequest* >( aRequest ); - - if ( !value_request && - (aRequest->getControlId( ) == getControlId( )) ) - { - result = new CLabelCommandResult( true, m_aLabel ); - } - else - { - nextCommand = getNextCommand( ); - if ( nextCommand ) - { - result = nextCommand->handleRequest( aRequest ); - } - else - { - result = new CControlCommandResult( ); - } - } - - return result; -} - - -OUString SAL_CALL CLabelControlCommand::getLabel( ) const -{ - return m_aLabel; -} - - -CEnableControlCommand::CEnableControlCommand( - sal_Int16 aControlId, - bool bEnable ) : - CControlCommand( aControlId ), - m_bEnable( bEnable ) -{ -} - - -void SAL_CALL CEnableControlCommand::exec( CFilePickerState* aFilePickerState ) -{ - OSL_ENSURE( aFilePickerState, "empty reference" ); - - aFilePickerState->enableControl( getControlId( ), m_bEnable ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlcommand.hxx b/fpicker/source/win32/filepicker/controlcommand.hxx deleted file mode 100644 index 6e687661afe9..000000000000 --- a/fpicker/source/win32/filepicker/controlcommand.hxx +++ /dev/null @@ -1,118 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMAND_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMAND_HXX - -#include <memory> -#include <sal/types.h> -#include <com/sun/star/uno/Any.hxx> -#include <rtl/ustring.hxx> - - -class CFilePickerState; -class CControlCommandRequest; -class CControlCommandResult; - -class CControlCommand -{ -public: - explicit CControlCommand( sal_Int16 aControlId ); - virtual ~CControlCommand( ); - - virtual void SAL_CALL exec( CFilePickerState* aFilePickerState ) = 0; - - // the client inherits the ownership of the returned - // CControlCommandResult and has to delete it or he may - // use the unique_ptr template for automatic deletion - virtual CControlCommandResult* SAL_CALL handleRequest( CControlCommandRequest* aRequest ); - - // clients of this method should use the returned - // pointer only temporary because it's not ref-counted - // and the ownerhsip belongs to this instance - CControlCommand* SAL_CALL getNextCommand( ) const; - - // transfers the ownership to this class - void SAL_CALL setNextCommand( CControlCommand* nextCommand ); - -protected: - sal_Int16 SAL_CALL getControlId( ) const; - -private: - CControlCommand* m_NextCommand; - sal_Int16 m_aControlId; -}; - - -class CValueControlCommand : public CControlCommand -{ -public: - CValueControlCommand( - sal_Int16 aControlId, - sal_Int16 aControlAction, - const css::uno::Any& aValue ); - - virtual void SAL_CALL exec( CFilePickerState* aFilePickerState ) override; - - virtual CControlCommandResult* SAL_CALL handleRequest( CControlCommandRequest* aRequest ) override; - - sal_Int16 SAL_CALL getControlAction( ) const; - - css::uno::Any SAL_CALL getValue( ) const; - -private: - sal_Int16 m_aControlAction; - css::uno::Any m_aValue; -}; - - -class CLabelControlCommand : public CControlCommand -{ -public: - CLabelControlCommand( - sal_Int16 aControlId, - const OUString& aLabel ); - - virtual void SAL_CALL exec( CFilePickerState* aFilePickerState ) override; - - virtual CControlCommandResult* SAL_CALL handleRequest( CControlCommandRequest* aRequest ) override; - - OUString SAL_CALL getLabel( ) const; - -private: - OUString m_aLabel; -}; - - -class CEnableControlCommand : public CControlCommand -{ -public: - CEnableControlCommand( - sal_Int16 controlId, - bool bEnable ); - - virtual void SAL_CALL exec( CFilePickerState* aFilePickerState ) override; - -private: - bool m_bEnable; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlcommandrequest.hxx b/fpicker/source/win32/filepicker/controlcommandrequest.hxx deleted file mode 100644 index 5a7f350061e8..000000000000 --- a/fpicker/source/win32/filepicker/controlcommandrequest.hxx +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMANDREQUEST_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMANDREQUEST_HXX - -#include <sal/types.h> - - -// declaration - - -class CControlCommandRequest -{ -public: - explicit CControlCommandRequest( sal_Int16 aControlId ) : - m_aControlId( aControlId ) - { - } - - virtual ~CControlCommandRequest( ) - { - } - - sal_Int16 SAL_CALL getControlId( ) const - { - return m_aControlId; - } - -private: - sal_Int16 m_aControlId; -}; - - -class CValueControlCommandRequest : public CControlCommandRequest -{ -public: - CValueControlCommandRequest( - sal_Int16 aControlId, - sal_Int16 aControlAction ) : - CControlCommandRequest( aControlId ), - m_aControlAction( aControlAction ) - { - } - - sal_Int16 SAL_CALL getControlAction( ) const - { - return m_aControlAction; - } - -private: - sal_Int16 m_aControlAction; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/controlcommandresult.hxx b/fpicker/source/win32/filepicker/controlcommandresult.hxx deleted file mode 100644 index 998e5f1c13d3..000000000000 --- a/fpicker/source/win32/filepicker/controlcommandresult.hxx +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMANDRESULT_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CONTROLCOMMANDRESULT_HXX - -#include <sal/types.h> -#include <com/sun/star/uno/Any.hxx> -#include <rtl/ustring.hxx> - - -// declaration - - -class CControlCommandResult -{ -public: - explicit CControlCommandResult( bool bResult = false ) : - m_bResult( bResult ) - { - } - - virtual ~CControlCommandResult( ) - { - } - - bool SAL_CALL hasResult( ) const - { - return m_bResult; - } - -private: - bool m_bResult; -}; - - -class CValueCommandResult : public CControlCommandResult -{ -public: - CValueCommandResult( bool bResult, const css::uno::Any& aValue ) : - CControlCommandResult( bResult ), - m_aValue( aValue ) - { - } - - css::uno::Any SAL_CALL getValue( ) const - { - return m_aValue; - } - -private: - css::uno::Any m_aValue; -}; - - -class CLabelCommandResult : public CControlCommandResult -{ -public: - CLabelCommandResult( bool bResult, const OUString& aLabel ) : - CControlCommandResult( bResult ), - m_aLabel( aLabel ) - { - } - - OUString SAL_CALL getLabel( ) const - { - return m_aLabel; - } - -private: - OUString m_aLabel; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrol.cxx b/fpicker/source/win32/filepicker/customcontrol.cxx deleted file mode 100644 index 1e57e63d4b04..000000000000 --- a/fpicker/source/win32/filepicker/customcontrol.cxx +++ /dev/null @@ -1,46 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "customcontrol.hxx" - - -CCustomControl::~CCustomControl() -{ -} - - -void SAL_CALL CCustomControl::AddControl(CCustomControl*) -{ - // will be implemented by custom control containers -} - - -void SAL_CALL CCustomControl::RemoveControl(CCustomControl*) -{ - // will be implemented by custom control containers -} - - -void SAL_CALL CCustomControl::RemoveAllControls() -{ - // will be implemented by custom control containers -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrol.hxx b/fpicker/source/win32/filepicker/customcontrol.hxx deleted file mode 100644 index a85ab928c8d4..000000000000 --- a/fpicker/source/win32/filepicker/customcontrol.hxx +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROL_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROL_HXX - -#include <sal/types.h> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -class CCustomControl -{ -public: - virtual ~CCustomControl(); - - // align the control to a reference object/control - virtual void SAL_CALL Align() = 0; - - virtual void SAL_CALL SetFont(HFONT hFont) = 0; - - virtual void SAL_CALL AddControl(CCustomControl* aCustomControl); - virtual void SAL_CALL RemoveControl(CCustomControl* aCustomControl); - virtual void SAL_CALL RemoveAllControls(); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrolcontainer.cxx b/fpicker/source/win32/filepicker/customcontrolcontainer.cxx deleted file mode 100644 index c4b5fe340ff9..000000000000 --- a/fpicker/source/win32/filepicker/customcontrolcontainer.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "customcontrolcontainer.hxx" - -#include <algorithm> - - -CCustomControlContainer::~CCustomControlContainer() -{ - RemoveAllControls(); -} - - -void SAL_CALL CCustomControlContainer::Align() -{ - for (auto aCCustomControl : m_ControlContainer) - aCCustomControl->Align(); -} - - -void SAL_CALL CCustomControlContainer::SetFont(HFONT hFont) -{ - for (auto aCCustomControl : m_ControlContainer) - aCCustomControl->SetFont(hFont); -} - - -void SAL_CALL CCustomControlContainer::AddControl(CCustomControl* aCustomControl) -{ - m_ControlContainer.push_back(aCustomControl); -} - - -void SAL_CALL CCustomControlContainer::RemoveControl(CCustomControl* aCustomControl) -{ - ControlContainer_t::iterator iter_end = m_ControlContainer.end(); - - ControlContainer_t::iterator iter = - std::find(m_ControlContainer.begin(),iter_end,aCustomControl); - - if (iter != iter_end) - { - delete *iter; - m_ControlContainer.remove(aCustomControl); - } -} - - -void SAL_CALL CCustomControlContainer::RemoveAllControls() -{ - for (auto aCCustomControl : m_ControlContainer) - delete aCCustomControl; - - m_ControlContainer.clear(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrolcontainer.hxx b/fpicker/source/win32/filepicker/customcontrolcontainer.hxx deleted file mode 100644 index e5af47a37aab..000000000000 --- a/fpicker/source/win32/filepicker/customcontrolcontainer.hxx +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROLCONTAINER_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROLCONTAINER_HXX - -#include "customcontrol.hxx" - -#include <list> - - -// A container for custom controls -// the container is responsible for -// the destruction of the custom -// controls - - -class CCustomControlContainer : public CCustomControl -{ -public: - virtual ~CCustomControlContainer() override; - - virtual void SAL_CALL Align() override; - virtual void SAL_CALL SetFont(HFONT hFont) override; - - virtual void SAL_CALL AddControl(CCustomControl* aCustomControl) override; - virtual void SAL_CALL RemoveControl(CCustomControl* aCustomControl) override; - virtual void SAL_CALL RemoveAllControls() override; - -private: - typedef std::list<CCustomControl*> ControlContainer_t; - - ControlContainer_t m_ControlContainer; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrolfactory.cxx b/fpicker/source/win32/filepicker/customcontrolfactory.cxx deleted file mode 100644 index cfdb1d56c1f7..000000000000 --- a/fpicker/source/win32/filepicker/customcontrolfactory.cxx +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - - -#include "customcontrolfactory.hxx" -#include "customcontrolcontainer.hxx" -#include "dialogcustomcontrols.hxx" -#include <osl/diagnose.h> - - -CCustomControl* CCustomControlFactory::CreateCustomControl(HWND aControlHandle, HWND aParentHandle) -{ - OSL_PRECOND(IsWindow(aControlHandle),"Invalid control handle"); - OSL_PRECOND(IsWindow(aControlHandle),"Invalid parent handle"); - - // get window class - // if static text create static text control etc. - - WCHAR aClassName[256]; - ZeroMemory(aClassName,sizeof(aClassName)); - if (GetClassNameW(aControlHandle,aClassName,SAL_N_ELEMENTS(aClassName)) == 0) { - OSL_FAIL("Invalid window handle"); - } - - if (0 == _wcsicmp(aClassName,L"button")) - { - // button means many things so we have - // to find out what button it is - LONG lBtnStyle = GetWindowLong(aControlHandle,GWL_STYLE); - - if (lBtnStyle & BS_CHECKBOX) - return new CCheckboxCustomControl(aControlHandle,aParentHandle); - - if ( ((lBtnStyle & BS_PUSHBUTTON) == 0) || (lBtnStyle & BS_DEFPUSHBUTTON)) - return new CPushButtonCustomControl(aControlHandle,aParentHandle); - - return new CDummyCustomControl(aControlHandle,aParentHandle); - } - - if (0 == _wcsicmp(aClassName,L"listbox") || 0 == _wcsicmp(aClassName,L"combobox")) - return new CComboboxCustomControl(aControlHandle,aParentHandle); - - if (0 == _wcsicmp(aClassName,L"static")) - return new CStaticCustomControl(aControlHandle,aParentHandle); - - return new CDummyCustomControl(aControlHandle,aParentHandle); -} - - -CCustomControl* CCustomControlFactory::CreateCustomControlContainer() -{ - return new CCustomControlContainer; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/customcontrolfactory.hxx b/fpicker/source/win32/filepicker/customcontrolfactory.hxx deleted file mode 100644 index 46043b4cd745..000000000000 --- a/fpicker/source/win32/filepicker/customcontrolfactory.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROLFACTORY_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_CUSTOMCONTROLFACTORY_HXX - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - -class CCustomControl; - -namespace CCustomControlFactory -{ - // The CCustomControl instances will be created on the heap - // and the client is responsible for deleting this instances - // (he adopts ownership) - CCustomControl* CreateCustomControl(HWND aControlHandle, HWND aParentHandle); - - CCustomControl* CreateCustomControlContainer(); -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/dialogcustomcontrols.cxx b/fpicker/source/win32/filepicker/dialogcustomcontrols.cxx deleted file mode 100644 index e91854b0b8fb..000000000000 --- a/fpicker/source/win32/filepicker/dialogcustomcontrols.cxx +++ /dev/null @@ -1,154 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "dialogcustomcontrols.hxx" -#include <osl/diagnose.h> - - -CDialogCustomControlBase::CDialogCustomControlBase(HWND aControlHandle, HWND aParentHandle) : - m_CustomControlHandle(aControlHandle), - m_ParentHandle(aParentHandle) -{ -} - - -void SAL_CALL CDialogCustomControlBase::SetFont(HFONT hFont) -{ - SendMessageW( - m_CustomControlHandle, - WM_SETFONT, - reinterpret_cast<WPARAM>(hFont), - (LPARAM)true); -} - - -void SAL_CALL CDialogCustomControlBase::AlignToBuddy(HWND aBuddyHandle) -{ - OSL_PRECOND(IsWindow(aBuddyHandle),"Invalid buddy window handle"); - - RECT rcBuddy; - GetWindowRect(aBuddyHandle,&rcBuddy); - - POINT pt = {rcBuddy.left,rcBuddy.top}; - ScreenToClient(m_ParentHandle,&pt); - - int cx_new = rcBuddy.right - rcBuddy.left; - int cy_new = rcBuddy.bottom - rcBuddy.top; - - // keep the vertical position because - // the Windows dialog controller does - // this job - RECT rcMe; - GetWindowRect(m_CustomControlHandle,&rcMe); - - POINT ptMe = {rcMe.left,rcMe.top}; - ScreenToClient(m_ParentHandle,&ptMe); - - SetWindowPos( - m_CustomControlHandle, - HWND_TOP, - pt.x, - ptMe.y, - cx_new, - cy_new, - SWP_NOACTIVATE); -} - - -CDummyCustomControl::CDummyCustomControl(HWND, HWND) -{ -} - - -void SAL_CALL CDummyCustomControl::Align() -{ - // do nothing -} - - -void SAL_CALL CDummyCustomControl::SetFont(HFONT) -{ - // do nothing -} - - -CStaticCustomControl::CStaticCustomControl(HWND aControlHandle, HWND aParentHandle) : - CDialogCustomControlBase(aControlHandle,aParentHandle) -{ -} - - -// Align to the "File name" static -// text of the standard FileOpen dlg - - -void SAL_CALL CStaticCustomControl::Align() -{ - AlignToBuddy(GetDlgItem(m_ParentHandle,stc3)); -} - - -CPushButtonCustomControl::CPushButtonCustomControl(HWND aControlHandle, HWND aParentHandle) : - CDialogCustomControlBase(aControlHandle,aParentHandle) -{ -} - - -// Align to the "OK" button of the -// standard FileOpen dlg - - -void SAL_CALL CPushButtonCustomControl::Align() -{ - AlignToBuddy(GetDlgItem(m_ParentHandle,IDCANCEL)); -} - - -CComboboxCustomControl::CComboboxCustomControl(HWND aControlHandle, HWND aParentHandle) : - CDialogCustomControlBase(aControlHandle,aParentHandle) -{ -} - - -// Align to the "File name" combobox -// of the standard FileOpen dlg - - -void SAL_CALL CComboboxCustomControl::Align() -{ - AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1)); -} - - -CCheckboxCustomControl::CCheckboxCustomControl(HWND aControlHandle, HWND aParentHandle) : - CDialogCustomControlBase(aControlHandle,aParentHandle) -{ -} - - -// Align to the "File name" combobox -// of the standard FileOpen dlg - - -void SAL_CALL CCheckboxCustomControl::Align() -{ - AlignToBuddy(GetDlgItem(m_ParentHandle,cmb1)); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/dialogcustomcontrols.hxx b/fpicker/source/win32/filepicker/dialogcustomcontrols.hxx deleted file mode 100644 index b06a773b83f2..000000000000 --- a/fpicker/source/win32/filepicker/dialogcustomcontrols.hxx +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_DIALOGCUSTOMCONTROLS_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_DIALOGCUSTOMCONTROLS_HXX - -#include "customcontrol.hxx" - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -class CDummyCustomControl : public CCustomControl -{ -public: - CDummyCustomControl(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL Align() override; - virtual void SAL_CALL SetFont(HFONT hFont) override; -}; - - -class CDialogCustomControlBase : public CCustomControl -{ -protected: - CDialogCustomControlBase(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL SetFont(HFONT hFont) override; - - // aligns the specific control class to a reference - // buddy - - void SAL_CALL AlignToBuddy(HWND aBuddyHandle); - -protected: - HWND m_CustomControlHandle; - HWND m_ParentHandle; -}; - - -class CStaticCustomControl : public CDialogCustomControlBase -{ -public: - CStaticCustomControl(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL Align() override; -}; - - -class CPushButtonCustomControl : public CDialogCustomControlBase -{ -public: - CPushButtonCustomControl(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL Align() override; -}; - - -class CComboboxCustomControl : public CDialogCustomControlBase -{ -public: - CComboboxCustomControl(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL Align() override; -}; - - -class CCheckboxCustomControl : public CDialogCustomControlBase -{ -public: - CCheckboxCustomControl(HWND aControlHandle, HWND aParentHandle); - - virtual void SAL_CALL Align() override; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/dibpreview.cxx b/fpicker/source/win32/filepicker/dibpreview.cxx deleted file mode 100644 index 6db7df14a048..000000000000 --- a/fpicker/source/win32/filepicker/dibpreview.cxx +++ /dev/null @@ -1,387 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "dibpreview.hxx" -#include <osl/diagnose.h> - -#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> - -#include <rtl/ustring.hxx> - -#include <stdexcept> -#include <string> - - -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::RuntimeException; -using ::com::sun::star::uno::Any; -using ::com::sun::star::lang::IllegalArgumentException; - - -namespace /* private */ -{ - const PCWSTR CURRENT_INSTANCE = L"CurrInst"; -}; - -#define PREVIEWWND_CLASS_NAME L"DIBPreviewWnd###" - - -// static member initialization - - -osl::Mutex CDIBPreview::s_Mutex; -ATOM CDIBPreview::s_ClassAtom = 0; -sal_Int32 CDIBPreview::s_RegisterDibPreviewWndCount = 0; - - -CDIBPreview::CDIBPreview(HINSTANCE instance,HWND parent,bool bShowWindow) : - m_Instance(instance) -{ - 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, - nullptr, // for child windows this will - // be used as child window identifier - m_Instance, - this // pass a pointer to the current - // instance of this class - ); - - if (!IsWindow(m_Hwnd)) - { - SAL_WARN("fpicker","Could not create preview window"); - UnregisterDibPreviewWindowClass(); - throw std::runtime_error("Could not create preview window"); - } -} - - -CDIBPreview::~CDIBPreview( ) -{ - // remember: we don't have to destroy the - // preview window because it will be destroyed - // by its parent window (the FileOpen dialog) - // but we have to unregister the window class - //if ( m_bWndClassRegistered ) - UnregisterDibPreviewWindowClass(); -} - - -sal_Int32 SAL_CALL CDIBPreview::getTargetColorDepth() -{ - HDC hdc = GetDC(m_Hwnd); - int clrRes = 0; - - if (hdc) - clrRes = GetDeviceCaps(hdc, COLORRES); - - return clrRes; -} - - -sal_Int32 SAL_CALL CDIBPreview::getAvailableWidth() -{ - RECT rect; - bool bRet = GetClientRect(m_Hwnd,&rect); - - sal_Int32 cx = 0; - - if ( bRet ) - cx = rect.right; - - return cx; -} - - -sal_Int32 SAL_CALL CDIBPreview::getAvailableHeight() -{ - RECT rect; - bool bRet = GetClientRect(m_Hwnd,&rect); - - sal_Int32 cy = 0; - - if ( bRet ) - cy = rect.bottom; - - return cy; -} - - -void SAL_CALL CDIBPreview::setImage(sal_Int16 aImageFormat, const Any& aImage) -{ - PreviewBase::setImage(aImageFormat,aImage); - - // 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; - - aGuard.clear(); - - InvalidateRect(m_Hwnd,nullptr,false); - UpdateWindow(m_Hwnd); -} - - -bool SAL_CALL CDIBPreview::setShowState(bool bShowState) -{ - PreviewBase::setShowState(bShowState); - ShowWindow(m_Hwnd, m_bShowState ? SW_SHOW : SW_HIDE); - return true; -} - - -bool SAL_CALL CDIBPreview::getShowState() -{ - return bool(IsWindowVisible(m_Hwnd)); -} - - -HWND SAL_CALL CDIBPreview::getWindowHandle() const -{ - return m_Hwnd; -} - - -void SAL_CALL CDIBPreview::onPaint(HWND hWnd, HDC hDC) -{ - osl::MutexGuard aGuard(m_PaintLock); - - try - { - BITMAPFILEHEADER* pbmfh = reinterpret_cast<BITMAPFILEHEADER*>(m_Image.getArray()); - - if ( !IsBadReadPtr( pbmfh, sizeof(BITMAPFILEHEADER)) && - (pbmfh->bfType == ('B' | ('M' << 8))) ) - { - BITMAPINFO * pbmi = reinterpret_cast<BITMAPINFO*>((pbmfh + 1)); - sal_uInt8 * pBits = reinterpret_cast<sal_uInt8*>(pbmfh) + pbmfh->bfOffBits; - - int cxDib = pbmi->bmiHeader.biWidth; - int cyDib = abs (pbmi->bmiHeader.biHeight); - - 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, nX, nY, cxDib, cyDib, - 0, 0, cxDib, cyDib, pBits, pbmi, - DIB_RGB_COLORS, SRCCOPY); - - OSL_ASSERT(0 != 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,reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1)); - - // bottom - rc.left = 0; - rc.top = nHeight - nY - 1; - rc.right = nWidth; - rc.bottom = nHeight; - FillRect(hDC,&rc,reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1)); - } - - if (nX > 0) - { - // left - rc.left = 0; - rc.top = nY; - rc.right = nX; - rc.bottom = nHeight - nY; - FillRect(hDC,&rc,reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1)); - - // right - rc.left = nWidth - nX - 1; - rc.top = nY; - rc.right = nWidth; - rc.bottom = nHeight - nY; - FillRect(hDC,&rc,reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1)); - } - } - else // clear background - { - RECT rc; - GetClientRect(hWnd,&rc); - FillRect(hDC,&rc,reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1)); - } - } - catch(...) - { - OSL_ASSERT(false); - } -} - - -LRESULT CALLBACK CDIBPreview::WndProc( - HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - LRESULT lResult = 0; - - switch(uMsg) - { - - // we connect a pointer to the current instance - // with a window instance via SetProp - case WM_CREATE: - { - LPCREATESTRUCT lpcs = - reinterpret_cast< LPCREATESTRUCT >(lParam); - - OSL_ASSERT(lpcs->lpCreateParams); - - // connect the instance handle to the window - SetPropW(hWnd, CURRENT_INSTANCE, lpcs->lpCreateParams); - } - break; - - // we remove the window property which connects - // a class instance with a window class - case WM_NCDESTROY: - { - // RemoveProp returns the saved value on success - if (static_cast<CDIBPreview*>( - RemovePropW(hWnd, CURRENT_INSTANCE)) == nullptr) - { - OSL_ASSERT(false); - } - } - break; - - case WM_PAINT: - { - CDIBPreview* pImpl = static_cast<CDIBPreview*>( - GetPropW(hWnd, CURRENT_INSTANCE)); - - OSL_ASSERT(pImpl); - - HDC hDC; - PAINTSTRUCT ps; - - hDC = BeginPaint(hWnd,&ps); - pImpl->onPaint(hWnd,hDC); - EndPaint(hWnd,&ps); - } - break; - - // ignore this message in order to - // avoid flickering during paint - case WM_ERASEBKGND: - lResult = 1; - break; - - default: - return DefWindowProc(hWnd, uMsg, wParam, lParam); - } - - return lResult; -} - - -ATOM SAL_CALL CDIBPreview::RegisterDibPreviewWindowClass() -{ - osl::MutexGuard aGuard( s_Mutex ); - - if (0 == s_ClassAtom) - { - // register the preview window class - WNDCLASSEX wndClsEx; - ZeroMemory(&wndClsEx, sizeof(wndClsEx)); - - wndClsEx.cbSize = sizeof(wndClsEx); - wndClsEx.style = CS_HREDRAW | CS_VREDRAW; - wndClsEx.lpfnWndProc = CDIBPreview::WndProc; - wndClsEx.hInstance = m_Instance; - wndClsEx.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_INACTIVEBORDER + 1); - wndClsEx.lpszClassName = PREVIEWWND_CLASS_NAME; - - // register the preview window class - // !!! Win95 - the window class will be unregistered automatically - // if the dll is unloaded - // Win2000 - the window class must be unregistered manually - // if the dll is unloaded - s_ClassAtom = RegisterClassExW(&wndClsEx); - if (0 == s_ClassAtom) - { - SAL_WARN("fpicker", "Could not register preview window class"); - 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++; - - return s_ClassAtom; -} - - -void SAL_CALL CDIBPreview::UnregisterDibPreviewWindowClass() -{ - osl::MutexGuard aGuard( s_Mutex ); - - OSL_ASSERT( ( (0 != s_ClassAtom) && (s_RegisterDibPreviewWndCount > 0)) || - ( (0 == s_ClassAtom) && (0 == s_RegisterDibPreviewWndCount) ) ); - - // update the register class counter - // and unregister the window class if - // counter drops to zero - if (0 != s_ClassAtom) - { - s_RegisterDibPreviewWndCount--; - OSL_ASSERT(s_RegisterDibPreviewWndCount >= 0); - } - - if (0 == s_RegisterDibPreviewWndCount) - { - UnregisterClassW(reinterpret_cast<PCWSTR>((DWORD_PTR)MAKELONG(s_ClassAtom,0)),m_Instance); - s_ClassAtom = 0; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/dibpreview.hxx b/fpicker/source/win32/filepicker/dibpreview.hxx deleted file mode 100644 index fb34f911cbbf..000000000000 --- a/fpicker/source/win32/filepicker/dibpreview.hxx +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_DIBPREVIEW_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_DIBPREVIEW_HXX - -#include "previewbase.hxx" -#include <com/sun/star/uno/Sequence.hxx> -#include <osl/mutex.hxx> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -// A very simple wrapper for a window that does -// display DIBs. -// Maybe it would be better and more extensible -// to create another class that is responsible -// for rendering a specific image format into -// the area of the window, but for our purpose -// it's enough to go the simple way - KISS. - - -class CDIBPreview : public PreviewBase -{ -public: - - // ctor - CDIBPreview(HINSTANCE instance,HWND parent,bool bShowWindow = false); - - // dtor - virtual ~CDIBPreview( ) override; - - // preview interface implementation - - virtual sal_Int32 SAL_CALL getTargetColorDepth() override; - - virtual sal_Int32 SAL_CALL getAvailableWidth() override; - - virtual sal_Int32 SAL_CALL getAvailableHeight() override; - - virtual void SAL_CALL setImage(sal_Int16 aImageFormat, const css::uno::Any& aImage) override; - - virtual bool SAL_CALL setShowState(bool bShowState) override; - - virtual bool SAL_CALL getShowState() override; - - virtual HWND SAL_CALL getWindowHandle() const override; - -private: - virtual void SAL_CALL onPaint( HWND hWnd, HDC hDC ); - - ATOM SAL_CALL RegisterDibPreviewWindowClass( ); - void SAL_CALL UnregisterDibPreviewWindowClass( ); - - static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); - -private: - HINSTANCE m_Instance; - HWND m_Hwnd; - css::uno::Sequence<sal_Int8> m_Image; - osl::Mutex m_PaintLock; - - // the preview window class has to be registered only - // once per process, so multiple instance of this class - // share the registered window class - static ATOM s_ClassAtom; - static osl::Mutex s_Mutex; - static sal_Int32 s_RegisterDibPreviewWndCount; - -// prevent copy and assignment -private: - CDIBPreview(const CDIBPreview&); - CDIBPreview& operator=(const CDIBPreview&); -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/eventnotification.hxx b/fpicker/source/win32/filepicker/eventnotification.hxx deleted file mode 100644 index 5f99f761ddb0..000000000000 --- a/fpicker/source/win32/filepicker/eventnotification.hxx +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_EVENTNOTIFICATION_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_EVENTNOTIFICATION_HXX - -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/uno/Reference.hxx> - - -// encapsulate a filepicker event -// notification, because there are -// two types of filepicker notifications -// with and without parameter -// this is an application of the -// "command" pattern see GoF - - -class CEventNotification -{ -public: - virtual ~CEventNotification() { }; - - virtual void SAL_CALL notifyEventListener( css::uno::Reference< css::uno::XInterface > xListener ) = 0; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/filepickereventnotification.cxx b/fpicker/source/win32/filepicker/filepickereventnotification.cxx deleted file mode 100644 index 04d463758725..000000000000 --- a/fpicker/source/win32/filepicker/filepickereventnotification.cxx +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "filepickereventnotification.hxx" -#include <sal/types.h> - -using namespace com::sun::star::uno; -using namespace com::sun::star::ui::dialogs; - -// A FilePicker event without parameter - -CFilePickerEventNotification::CFilePickerEventNotification(EventListenerMethod_t EventListenerMethod) : - m_EventListenerMethod(EventListenerMethod) -{ -} - -void SAL_CALL CFilePickerEventNotification::notifyEventListener( Reference< XInterface > xListener ) -{ - Reference<XFilePickerListener> xFilePickerListener(xListener,UNO_QUERY); - if (xFilePickerListener.is()) - (xFilePickerListener.get()->*m_EventListenerMethod)(); -} - -// A FilePicker event with parameter - -CFilePickerParamEventNotification::CFilePickerParamEventNotification(EventListenerMethod_t EventListenerMethod, const FilePickerEvent& FilePickerEvent) : - m_EventListenerMethod(EventListenerMethod), - m_FilePickerEvent(FilePickerEvent) -{ -} - -// A FilePicker event with parameter - -void SAL_CALL CFilePickerParamEventNotification::notifyEventListener( Reference< XInterface > xListener ) -{ - Reference<XFilePickerListener> xFilePickerListener(xListener,UNO_QUERY); - if (xFilePickerListener.is()) - (xFilePickerListener.get()->*m_EventListenerMethod)(m_FilePickerEvent); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/filepickereventnotification.hxx b/fpicker/source/win32/filepicker/filepickereventnotification.hxx deleted file mode 100644 index bd42281fee5a..000000000000 --- a/fpicker/source/win32/filepicker/filepickereventnotification.hxx +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKEREVENTNOTIFICATION_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKEREVENTNOTIFICATION_HXX - -#include "eventnotification.hxx" -#include <com/sun/star/ui/dialogs/XFilePickerListener.hpp> -#include <com/sun/star/ui/dialogs/FilePickerEvent.hpp> - - -// A FilePicker event without -// parameter - - -class CFilePickerEventNotification : public CEventNotification -{ -public: - typedef void (SAL_CALL css::ui::dialogs::XFilePickerListener::*EventListenerMethod_t)(); - -public: - explicit CFilePickerEventNotification(EventListenerMethod_t EventListenerMethod); - - virtual void SAL_CALL notifyEventListener( css::uno::Reference< css::uno::XInterface > xListener ) override; - -private: - EventListenerMethod_t m_EventListenerMethod; -}; - - -// A FilePicker event with parameter - - -class CFilePickerParamEventNotification : public CEventNotification -{ -public: - typedef void (SAL_CALL css::ui::dialogs::XFilePickerListener::*EventListenerMethod_t)(const css::ui::dialogs::FilePickerEvent&); - - explicit CFilePickerParamEventNotification(EventListenerMethod_t EventListenerMethod, const css::ui::dialogs::FilePickerEvent& FilePickerEvent); - - virtual void SAL_CALL notifyEventListener( css::uno::Reference< css::uno::XInterface > xListener ) override; - -private: - EventListenerMethod_t m_EventListenerMethod; - css::ui::dialogs::FilePickerEvent m_FilePickerEvent; -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/filepickerstate.cxx b/fpicker/source/win32/filepicker/filepickerstate.cxx deleted file mode 100644 index 5974b9eb8eae..000000000000 --- a/fpicker/source/win32/filepicker/filepickerstate.cxx +++ /dev/null @@ -1,622 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "filepickerstate.hxx" -#include <osl/diagnose.h> -#include "controlaccess.hxx" -#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> -#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> -#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp> -#include <com/sun/star/ui/dialogs/ControlActions.hpp> -#include "controlcommandrequest.hxx" -#include "controlcommandresult.hxx" -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/uno/XInterface.hpp> -#include <osl/file.hxx> -#include "FileOpenDlg.hxx" -#include <memory> - -#include "../misc/WinImplHelper.hxx" - - -using com::sun::star::uno::Any; -using com::sun::star::uno::Sequence; -using com::sun::star::uno::Reference; -using com::sun::star::uno::XInterface; - -using namespace ::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds; -using namespace ::com::sun::star::ui::dialogs::CommonFilePickerElementIds; -using namespace ::com::sun::star::ui::dialogs::ListboxControlActions; - - -const sal_Int32 MAX_LABEL = 256; -const sal_Int16 LISTBOX_LABEL_OFFSET = 100; - - -// declaration - - -CFilePickerState::~CFilePickerState( ) -{ -} - - -CNonExecuteFilePickerState::CNonExecuteFilePickerState( ) : - m_FirstControlCommand( nullptr ) -{ -} - - -CNonExecuteFilePickerState::~CNonExecuteFilePickerState( ) -{ - reset( ); -} - - -void SAL_CALL CNonExecuteFilePickerState::setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const Any& aValue ) -{ - CValueControlCommand* value_command = new CValueControlCommand( - aControlId, aControlAction, aValue ); - - addControlCommand( value_command ); -} - - -Any SAL_CALL CNonExecuteFilePickerState::getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) -{ - CValueControlCommandRequest value_request( aControlId, aControlAction ); - Any aAny; - - if (m_FirstControlCommand) - { - // pass the request along the command-chain - std::unique_ptr< CControlCommandResult > result( m_FirstControlCommand->handleRequest( &value_request ) ); - - OSL_ENSURE( result.get(), "invalid getValue request" ); - - if ( result.get() ) - { - // #101753 must remove assertion else running into deadlock - // because getValue may be called asynchronously from main thread - // with locked SOLAR_MUTEX but we also need SOLAR_MUTEX in - // WinFileOpenDialog::onInitDone ... but we cannot dismiss the - // assertion dialog because at this point the FileOpen Dialog - // has already the focus but is not yet visible :-( - // The real cure is to remove the VCL/SOLAR_MUTEX dependency - // cause by the use of our resource manager and not being able to - // generate native windows resources - //OSL_ENSURE( result->hasResult( ), "invalid getValue request" ); - - if ( result->hasResult( ) ) - { - CValueCommandResult* value_result = dynamic_cast< CValueCommandResult* >( result.get( ) ); - OSL_ENSURE( value_result, "should have be a CValueCommandResult" ); - - aAny = value_result->getValue( ); - OSL_ENSURE( aAny.hasValue( ), "empty any" ); - } - } - } - - return aAny; -} - - -void SAL_CALL CNonExecuteFilePickerState::enableControl( sal_Int16 aControlId, bool bEnable ) -{ - CEnableControlCommand* enable_command = new CEnableControlCommand( - aControlId, bEnable ); - - addControlCommand( enable_command ); -} - - -void SAL_CALL CNonExecuteFilePickerState::setLabel( sal_Int16 aControlId, const OUString& aLabel ) -{ - CLabelControlCommand* label_command = new CLabelControlCommand( - aControlId, aLabel ); - - addControlCommand( label_command ); -} - - -OUString SAL_CALL CNonExecuteFilePickerState::getLabel( sal_Int16 aControlId ) -{ - CControlCommandRequest label_request( aControlId ); - - // pass the request along the command-chain - std::unique_ptr< CControlCommandResult > result( m_FirstControlCommand->handleRequest( &label_request ) ); - - OSL_ENSURE( result->hasResult( ), "invalid getValue request" ); - - OUString aLabel; - - if ( result->hasResult( ) ) - { - CLabelCommandResult* label_result = dynamic_cast< CLabelCommandResult* >( result.get( ) ); - OSL_ENSURE( label_result, "should have be a CLabelCommandResult" ); - - aLabel = label_result->getLabel( ); - } - - return aLabel; -} - -/* #i26224# - When typing file names with drive letter but without '\' - in the "File name" box of the FileOpen dialog the FileOpen - dialog makes strange paths out of them e.g. "d:.\test.sxw". - Such file names will not be accepted by sal so we fix these - somehow broken paths here. */ -OUString MatchFixBrokenPath(const OUString& path) -{ - OSL_ASSERT(path.getLength() >= 4); - - if (path[1] == ':' && path[2] == '.' && path[3] == '\\') - { - // skip the '.' - return OUString(path.getStr(), 2) + path.copy(3, path.getLength() - 3); - } - return path; -} - - -static OUString trimTrailingSpaces(const OUString& rString) -{ - OUString aResult(rString); - - sal_Int32 nIndex = rString.lastIndexOf(' '); - if (nIndex == rString.getLength()-1) - { - while (nIndex >= 0 && rString[nIndex] == ' ') - nIndex--; - if (nIndex >= 0) - aResult = rString.copy(0,nIndex+1); - else - aResult.clear(); - } - return aResult; -} - -Sequence< OUString > SAL_CALL CNonExecuteFilePickerState::getFiles( CFileOpenDialog* aFileOpenDialog ) -{ - OSL_PRECOND( aFileOpenDialog, "invalid parameter" ); - - Sequence< OUString > aFilePathList; - OUString aFilePathURL; - OUString aFilePath; - ::osl::FileBase::RC rc; - - aFilePath = aFileOpenDialog->getFullFileName( ); - - if ( aFilePath.getLength( ) ) - { - // tokenize the returned string and copy the - // sub-strings separately into a sequence - const sal_Unicode* pTemp = aFilePath.getStr(); - const sal_Unicode* pStrEnd = pTemp + aFilePath.getLength(); - sal_uInt32 lSubStr; - - while (pTemp < pStrEnd) - { - // detect the length of the next sub string - lSubStr = rtl_ustr_getLength(pTemp); - - aFilePathList.realloc(aFilePathList.getLength() + 1); - - aFilePathList[aFilePathList.getLength() - 1] = - MatchFixBrokenPath(OUString(pTemp, lSubStr)); - - pTemp += (lSubStr + 1); - } - - // change all entries to file URLs - sal_Int32 lenFileList = aFilePathList.getLength( ); - OSL_ASSERT( lenFileList >= 1 ); - - for ( sal_Int32 i = 0; i < lenFileList; i++ ) - { - aFilePath = trimTrailingSpaces(aFilePathList[i]); - rc = ::osl::FileBase::getFileURLFromSystemPath( - aFilePath, aFilePathURL ); - - // we do return all or nothing, that means - // in case of failures we destroy the sequence - // and return an empty sequence - if ( rc != ::osl::FileBase::E_None ) - { - aFilePathList.realloc( 0 ); - break; - } - - aFilePathList[i] = aFilePathURL; - } - } - - return aFilePathList; -} - - -OUString SAL_CALL CNonExecuteFilePickerState::getDisplayDirectory( CFileOpenDialog* aFileOpenDialog ) -{ - OSL_PRECOND( aFileOpenDialog, "invalid parameter" ); - - OUString pathURL; - OUString displayDir; - - displayDir = aFileOpenDialog->getLastDisplayDirectory( ); - - if ( displayDir.getLength( ) ) - ::osl::FileBase::getFileURLFromSystemPath( displayDir, pathURL ); - - return pathURL; -} - - -void SAL_CALL CNonExecuteFilePickerState::reset( ) -{ - CControlCommand* nextCommand; - CControlCommand* currentCommand = m_FirstControlCommand; - - while( currentCommand ) - { - nextCommand = currentCommand->getNextCommand( ); - delete currentCommand; - currentCommand = nextCommand; - } - - m_FirstControlCommand = nullptr; -} - - -CControlCommand* SAL_CALL CNonExecuteFilePickerState::getControlCommand( ) const -{ - return m_FirstControlCommand; -} - - -// we append new control commands to the end -// of the list so that we are sure the commands -// will be executed as the client issued it - - -void SAL_CALL CNonExecuteFilePickerState::addControlCommand( CControlCommand* aControlCommand ) -{ - OSL_ASSERT( aControlCommand ); - - if ( nullptr == m_FirstControlCommand ) - { - m_FirstControlCommand = aControlCommand; - } - else - { - CControlCommand* pNextControlCommand = m_FirstControlCommand; - - while ( pNextControlCommand->getNextCommand( ) != nullptr ) - pNextControlCommand = pNextControlCommand->getNextCommand( ); - - pNextControlCommand->setNextCommand( aControlCommand ); - } -} - - -CExecuteFilePickerState::CExecuteFilePickerState( HWND hwndDlg ) : - m_hwndDlg( hwndDlg ) -{ -} - - -void SAL_CALL CExecuteFilePickerState::setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const Any& aValue ) -{ - // we do not support SET_HELP_URL/GET_HELP_URL - if ( css::ui::dialogs::ControlActions::SET_HELP_URL == aControlAction ) - return; - - HWND hwndCtrl = GetHwndDlgItem( aControlId ); - - // the filter listbox can be manipulated via this - // method the caller should use XFilterManager - if ( !hwndCtrl || (aControlId == LISTBOX_FILTER) ) - { - OSL_FAIL( "invalid control id" ); - return; - } - - CTRL_CLASS aCtrlClass = GetCtrlClass( hwndCtrl ); - if ( UNKNOWN == aCtrlClass ) - { - OSL_FAIL( "unsupported control class" ); - return; - } - - CTRL_SETVALUE_FUNCTION_T lpfnSetValue = - GetCtrlSetValueFunction( aCtrlClass, aControlAction ); - - if ( !lpfnSetValue ) - { - OSL_FAIL( "unsupported control action" ); - return; - } - - // the function that we call should throw an IllegalArgumentException if - // the given value is invalid or empty, that's why we provide a Reference - // to an XInterface and a argument position - lpfnSetValue( hwndCtrl, aValue, Reference< XInterface >( ), 3 ); -} - - -Any SAL_CALL CExecuteFilePickerState::getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) -{ - // we do not support SET_HELP_URL/GET_HELP_URL - if ( css::ui::dialogs::ControlActions::GET_HELP_URL == aControlAction ) - return Any( ); - - HWND hwndCtrl = GetHwndDlgItem( aControlId ); - - // the filter listbox can be manipulated via this - // method the caller should use XFilterManager - if ( !hwndCtrl || (aControlId == LISTBOX_FILTER) ) - { - OSL_FAIL( "invalid control id" ); - return Any( ); - } - - CTRL_CLASS aCtrlClass = GetCtrlClass( hwndCtrl ); - if ( UNKNOWN == aCtrlClass ) - { - OSL_FAIL( "unsupported control class" ); - return Any( ); - } - - CTRL_GETVALUE_FUNCTION_T lpfnGetValue = - GetCtrlGetValueFunction( aCtrlClass, aControlAction ); - - if ( !lpfnGetValue ) - { - OSL_FAIL( "unsupported control action" ); - return Any( ); - } - - return lpfnGetValue( hwndCtrl ); -} - - -void SAL_CALL CExecuteFilePickerState::enableControl( sal_Int16 aControlId, bool bEnable ) -{ - HWND hwndCtrl = GetHwndDlgItem( aControlId ); - - OSL_ENSURE( IsWindow( hwndCtrl ), "invalid element id"); - - EnableWindow( hwndCtrl, bEnable ); -} - - -void SAL_CALL CExecuteFilePickerState::setLabel( sal_Int16 aControlId, const OUString& aLabel ) -{ - HWND hwndCtrl = GetHwndDlgItem( aControlId ); - - OSL_ENSURE( IsWindow( hwndCtrl ), "invalid element id"); - - if ( IsListboxControl( hwndCtrl ) ) - hwndCtrl = GetListboxLabelItem( aControlId ); - - OUString aWinLabel = SOfficeToWindowsLabel( aLabel ); - - // somewhat risky because we don't know if OUString - // has a terminating '\0' - SetWindowTextW( hwndCtrl, reinterpret_cast<PCWSTR>(aWinLabel.getStr( )) ); -} - - -OUString SAL_CALL CExecuteFilePickerState::getLabel( sal_Int16 aControlId ) -{ - HWND hwndCtrl = GetHwndDlgItem( aControlId ); - - OSL_ENSURE( IsWindow( hwndCtrl ), "invalid element id"); - - if ( IsListboxControl( hwndCtrl ) ) - hwndCtrl = GetListboxLabelItem( aControlId ); - - sal_Unicode aLabel[MAX_LABEL]; - int nRet = GetWindowTextW( hwndCtrl, reinterpret_cast<PWSTR>(aLabel), MAX_LABEL ); - - OUString ctrlLabel; - if ( nRet ) - { - ctrlLabel = WindowsToSOfficeLabel( aLabel ); - } - - return ctrlLabel; -} - - -Sequence< OUString > SAL_CALL CExecuteFilePickerState::getFiles( CFileOpenDialog* aFileOpenDialog ) -{ - SAL_WARN_IF( !aFileOpenDialog, "fpicker", "invalid parameter" ); - - Sequence< OUString > aFilePathList; - OUString aFilePathURL; - OUString aFilePath; - ::osl::FileBase::RC rc; - - // in execution mode getFullFileName doesn't - // return anything, so we must use another way - - // returns the currently selected file(s) - // including path information - aFilePath = aFileOpenDialog->getCurrentFilePath( ); - - // if multiple files are selected or the user - // typed anything that doesn't seem to be a valid - // file name getFileURLFromSystemPath fails - // and we return an empty file list - rc = ::osl::FileBase::getFileURLFromSystemPath( - aFilePath, aFilePathURL ); - - if ( ::osl::FileBase::E_None == rc ) - { - aFilePathList.realloc( 1 ); - aFilePathList[0] = aFilePathURL; - } - - return aFilePathList; -} - - -OUString SAL_CALL CExecuteFilePickerState::getDisplayDirectory( CFileOpenDialog* aFileOpenDialog ) -{ - SAL_WARN_IF( !aFileOpenDialog, "fpicker", "invalid parameter" ); - - OUString pathURL; - OUString displayDir; - - displayDir = aFileOpenDialog->getCurrentFolderPath( ); - - if ( displayDir.getLength( ) ) - ::osl::FileBase::getFileURLFromSystemPath( displayDir, pathURL ); - - return pathURL; -} - - -void SAL_CALL CExecuteFilePickerState::initFilePickerControls( CControlCommand* firstControlCommand ) -{ - CControlCommand* aControlCommand = firstControlCommand; - - while ( aControlCommand ) - { - aControlCommand->exec( this ); - aControlCommand = aControlCommand->getNextCommand( ); - } -} - - -void SAL_CALL CExecuteFilePickerState::cacheControlState( HWND hwndControl, CFilePickerState* aNonExecFilePickerState ) -{ - OSL_ENSURE( hwndControl && aNonExecFilePickerState, "invalid parameters" ); - - CTRL_CLASS aCtrlClass = GetCtrlClass( hwndControl ); - - sal_Int16 aControlAction; - CTRL_GETVALUE_FUNCTION_T lpfnGetValue; - - if ( CHECKBOX == aCtrlClass ) - { - aControlAction = 0; - - lpfnGetValue = GetCtrlGetValueFunction( aCtrlClass, aControlAction ); - - OSL_ASSERT( lpfnGetValue ); - - aNonExecFilePickerState->setValue( - sal::static_int_cast< sal_Int16 >( GetDlgCtrlID( hwndControl ) ), - aControlAction, - lpfnGetValue( hwndControl ) ); - - aNonExecFilePickerState->setLabel( - sal::static_int_cast< sal_Int16 >( GetDlgCtrlID( hwndControl ) ), - getLabel( - sal::static_int_cast< sal_Int16 >( - GetDlgCtrlID( hwndControl ) ) ) ); - } - else if ( LISTBOX == aCtrlClass ) - { - // for listboxes we save only the - // last selected item and the last - // selected item index - - aControlAction = GET_SELECTED_ITEM; - - lpfnGetValue = GetCtrlGetValueFunction( aCtrlClass, aControlAction ); - - aNonExecFilePickerState->setValue( - sal::static_int_cast< sal_Int16 >( GetDlgCtrlID( hwndControl ) ), - aControlAction, - lpfnGetValue( hwndControl ) ); - - aControlAction = css::ui::dialogs::ControlActions::GET_SELECTED_ITEM_INDEX; - - lpfnGetValue = GetCtrlGetValueFunction( aCtrlClass, aControlAction ); - - aNonExecFilePickerState->setValue( - sal::static_int_cast< sal_Int16 >( GetDlgCtrlID( hwndControl ) ), - aControlAction, - lpfnGetValue( hwndControl ) ); - } -} - - -void SAL_CALL CExecuteFilePickerState::setHwnd( HWND hwndDlg ) -{ - m_hwndDlg = hwndDlg; -} - - -inline bool SAL_CALL CExecuteFilePickerState::IsListboxControl( HWND hwndControl ) -{ - OSL_PRECOND( IsWindow( hwndControl ), "invalid parameter" ); - - CTRL_CLASS aCtrlClass = GetCtrlClass( hwndControl ); - return ( LISTBOX == aCtrlClass ); -} - - -// because listboxes (comboboxes) and their labels -// are separated we have to translate the listbox -// id to their corresponding label id -// the convention is that the label id of a listbox -// is the id of the listbox + 100 - - -inline sal_Int16 SAL_CALL CExecuteFilePickerState::ListboxIdToListboxLabelId( sal_Int16 aListboxId ) -{ - return ( aListboxId + LISTBOX_LABEL_OFFSET ); -} - - -inline HWND SAL_CALL CExecuteFilePickerState::GetListboxLabelItem( sal_Int16 aControlId ) const -{ - sal_Int16 aLabelId = ListboxIdToListboxLabelId( aControlId ); - HWND hwndCtrl = GetHwndDlgItem( aLabelId ); - - OSL_ASSERT( IsWindow( hwndCtrl ) ); - - return hwndCtrl; -} - - -HWND SAL_CALL CExecuteFilePickerState::GetHwndDlgItem( sal_Int16 aControlId, bool bIncludeStdCtrls ) const -{ - OSL_ENSURE( IsWindow( m_hwndDlg ), "no valid parent window set before" ); - - HWND hwndCtrl = GetDlgItem( m_hwndDlg, aControlId ); - - // maybe it's a control of the dialog itself for instance - // the ok and cancel button - if ( !hwndCtrl && bIncludeStdCtrls ) - { - hwndCtrl = GetDlgItem( - GetParent( m_hwndDlg ), - CommonFilePickerCtrlIdToWinFileOpenCtrlId( aControlId ) ); - } - - return hwndCtrl; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/filepickerstate.hxx b/fpicker/source/win32/filepicker/filepickerstate.hxx deleted file mode 100644 index c08ceb8a3f61..000000000000 --- a/fpicker/source/win32/filepicker/filepickerstate.hxx +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKERSTATE_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_FILEPICKERSTATE_HXX - -#include <sal/types.h> -#include "controlcommand.hxx" -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Sequence.hxx> -#include <rtl/ustring.hxx> - -#define WIN32_LEAN_AND_MEAN -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -class CControlCommand; -class CFileOpenDialog; - - -// declaration - - -class CFilePickerState -{ -public: - virtual ~CFilePickerState( ); - - virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const css::uno::Any& aValue ) = 0; - - virtual css::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) = 0; - - virtual void SAL_CALL enableControl( sal_Int16 aControlId, bool bEnable ) = 0; - - virtual void SAL_CALL setLabel( sal_Int16 aControlId, const OUString& aLabel ) = 0; - - virtual OUString SAL_CALL getLabel( sal_Int16 aControlId ) = 0; - - virtual css::uno::Sequence< OUString > SAL_CALL getFiles( CFileOpenDialog* aFileOpenDialog ) = 0; - - virtual OUString SAL_CALL getDisplayDirectory( CFileOpenDialog* aFileOpenDialog ) = 0; -}; - - -// this class is not thread-safe - - -class CNonExecuteFilePickerState : public CFilePickerState -{ -public: - CNonExecuteFilePickerState( ); - - virtual ~CNonExecuteFilePickerState( ) override; - - virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const css::uno::Any& aValue ) override; - - virtual css::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) override; - - virtual void SAL_CALL enableControl( sal_Int16 aControlId, bool bEnable ) override; - - virtual void SAL_CALL setLabel( sal_Int16 aControlId, const OUString& aLabel ) override; - - virtual OUString SAL_CALL getLabel( sal_Int16 aControlId ) override; - - virtual css::uno::Sequence< OUString > SAL_CALL getFiles( CFileOpenDialog* aFileOpenDialog ) override; - - virtual OUString SAL_CALL getDisplayDirectory( CFileOpenDialog* aFileOpenDialog ) override; - - void SAL_CALL reset( ); - - CControlCommand* SAL_CALL getControlCommand( ) const; - -protected: - void SAL_CALL addControlCommand( CControlCommand* aControlCommand ); - -private: - CControlCommand* m_FirstControlCommand; -}; - - -// this class is not thread-safe - - -class CExecuteFilePickerState : public CFilePickerState -{ -public: - explicit CExecuteFilePickerState( HWND hwndDlg = nullptr ); - - virtual void SAL_CALL setValue( sal_Int16 aControlId, sal_Int16 aControlAction, const css::uno::Any& aValue ) override; - - virtual css::uno::Any SAL_CALL getValue( sal_Int16 aControlId, sal_Int16 aControlAction ) override; - - virtual void SAL_CALL enableControl( sal_Int16 aControlId, bool bEnable ) override; - - virtual void SAL_CALL setLabel( sal_Int16 aControlId, const OUString& aLabel ) override; - - virtual OUString SAL_CALL getLabel( sal_Int16 aControlId ) override; - - virtual css::uno::Sequence< OUString > SAL_CALL getFiles( CFileOpenDialog* aFileOpenDialog ) override; - - virtual OUString SAL_CALL getDisplayDirectory( CFileOpenDialog* aFileOpenDialog ) override; - - void SAL_CALL initFilePickerControls( CControlCommand* firstControlCommand ); - - void SAL_CALL cacheControlState( HWND hwndControl, CFilePickerState* aFilePickerState ); - - void SAL_CALL setHwnd( HWND hwndDlg ); - -private: - - static inline bool SAL_CALL IsListboxControl( HWND hwndControl ); - - static inline sal_Int16 SAL_CALL ListboxIdToListboxLabelId( sal_Int16 aListboxId ); - - inline HWND SAL_CALL GetListboxLabelItem( sal_Int16 aControlId ) const; - - // returns a hwnd for a control if successful - // if bIncludeStdCtrls is false, the standard file dialog - // controls like OK button, etc. will not be considered - // the function return 0 on failure - HWND SAL_CALL GetHwndDlgItem( sal_Int16 aControlId, bool bIncludeStdCtrls = true ) const; - - HWND m_hwndDlg; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/getfilenamewrapper.cxx b/fpicker/source/win32/filepicker/getfilenamewrapper.cxx deleted file mode 100644 index a7a5a3d764e6..000000000000 --- a/fpicker/source/win32/filepicker/getfilenamewrapper.cxx +++ /dev/null @@ -1,260 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/config.h> - -#include <memory> -#include <stdio.h> -#include <osl/diagnose.h> -#include <osl/thread.h> -#include <sal/log.hxx> -#include "getfilenamewrapper.hxx" - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <objbase.h> -#include <process.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - -namespace /* private */ -{ - - - // This class prevents changing of the working - // directory. - - class CurDirGuard - { - bool m_bValid; - wchar_t* m_pBuffer; - DWORD m_nBufLen; - - public: - CurDirGuard() - : m_bValid( false ) - , m_pBuffer( nullptr ) - , m_nBufLen( 0 ) - { - m_nBufLen = GetCurrentDirectoryW( 0, nullptr ); - if ( m_nBufLen ) - { - m_pBuffer = new wchar_t[m_nBufLen]; - m_bValid = ( GetCurrentDirectoryW( m_nBufLen, m_pBuffer ) == ( m_nBufLen - 1 ) ); - } - } - - ~CurDirGuard() - { - bool bDirSet = false; - - if ( m_pBuffer ) - { - if ( m_bValid ) - { - if ( m_nBufLen - 1 > MAX_PATH ) - { - DWORD nNewLen = m_nBufLen + 8; - auto pNewBuffer = std::unique_ptr<wchar_t>(new wchar_t[nNewLen]); - if ( m_nBufLen > 3 && m_pBuffer[0] == (wchar_t)'\\' && m_pBuffer[1] == (wchar_t)'\\' ) - { - if ( m_pBuffer[2] == (wchar_t)'?' ) - _snwprintf( pNewBuffer.get(), nNewLen, L"%s", m_pBuffer ); - else - _snwprintf( pNewBuffer.get(), nNewLen, L"\\\\?\\UNC\\%s", m_pBuffer+2 ); - } - else - _snwprintf( pNewBuffer.get(), nNewLen, L"\\\\?\\%s", m_pBuffer ); - bDirSet = SetCurrentDirectoryW( pNewBuffer.get() ); - } - else - bDirSet = SetCurrentDirectoryW( m_pBuffer ); - } - - delete [] m_pBuffer; - m_pBuffer = nullptr; - } - - if ( !bDirSet ) - { - // the fallback solution - wchar_t pPath[MAX_PATH+1]; - if ( GetWindowsDirectoryW( pPath, MAX_PATH+1 ) <= MAX_PATH ) - { - SetCurrentDirectoryW( pPath ); - } - else - { - // the system path is also too long?!! - } - } - } - }; - - - struct GetFileNameParam - { - GetFileNameParam(bool bOpen, LPOPENFILENAME lpofn) : - m_bOpen(bOpen), - m_lpofn(lpofn), - m_bRet(false), - m_ExtErr(0) - {} - - bool m_bOpen; - LPOPENFILENAME m_lpofn; - bool m_bRet; - int m_ExtErr; - }; - - - unsigned __stdcall ThreadProc(void* pParam) - { - osl_setThreadName("fpicker GetOpenFileName"); - - CurDirGuard aGuard; - - GetFileNameParam* lpgfnp = - static_cast<GetFileNameParam*>(pParam); - - HRESULT hr = OleInitialize( nullptr ); - - if (lpgfnp->m_bOpen) - lpgfnp->m_bRet = GetOpenFileName(lpgfnp->m_lpofn); - else - lpgfnp->m_bRet = GetSaveFileName(lpgfnp->m_lpofn); - - lpgfnp->m_ExtErr = CommDlgExtendedError(); - - if ( SUCCEEDED( hr ) ) - OleUninitialize(); - - return 0; - } - - - // executes GetOpenFileName/GetSaveFileName in - // a separate thread - - - bool ThreadExecGetFileName(LPOPENFILENAME lpofn, bool bOpen, /*out*/ int& ExtErr) - { - GetFileNameParam gfnp(bOpen,lpofn); - unsigned id; - - HANDLE hThread = reinterpret_cast<HANDLE>( - _beginthreadex(nullptr, 0, ThreadProc, &gfnp, 0, &id)); - - SAL_WARN_IF( !hThread, "fpicker", "could not create STA thread"); - - WaitForSingleObject(hThread, INFINITE); - CloseHandle(hThread); - - ExtErr = gfnp.m_ExtErr; - - return gfnp.m_bRet; - } - - - // This function returns true if the calling - // thread belongs to a Multithreaded Apartment - // (MTA) - - - bool IsMTA() - { - HRESULT hr = CoInitialize(nullptr); - - if (RPC_E_CHANGED_MODE == hr) - return true; - - if(SUCCEEDED(hr)) - CoUninitialize(); - - return false; - } - -} // namespace private - - -CGetFileNameWrapper::CGetFileNameWrapper() : - m_ExtendedDialogError(0) -{ -} - - -bool CGetFileNameWrapper::getOpenFileName(LPOPENFILENAME lpofn) -{ - OSL_PRECOND(lpofn,"invalid parameter"); - - bool bRet = false; - - if (IsMTA()) - { - bRet = ThreadExecGetFileName( - lpofn, true, m_ExtendedDialogError); - } - else - { - CurDirGuard aGuard; - - HRESULT hr = OleInitialize( nullptr ); - - bRet = GetOpenFileName(lpofn); - m_ExtendedDialogError = CommDlgExtendedError(); - - if ( SUCCEEDED( hr ) ) - OleUninitialize(); - } - - return bRet; -} - - -bool CGetFileNameWrapper::getSaveFileName(LPOPENFILENAME lpofn) -{ - OSL_PRECOND(lpofn,"invalid parameter"); - - bool bRet = false; - - if (IsMTA()) - { - bRet = ThreadExecGetFileName( - lpofn, false, m_ExtendedDialogError); - } - else - { - CurDirGuard aGuard; - - bRet = GetSaveFileName(lpofn); - m_ExtendedDialogError = CommDlgExtendedError(); - } - - return bRet; -} - - -int CGetFileNameWrapper::commDlgExtendedError( ) -{ - return m_ExtendedDialogError; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/getfilenamewrapper.hxx b/fpicker/source/win32/filepicker/getfilenamewrapper.hxx deleted file mode 100644 index 2581cac00a14..000000000000 --- a/fpicker/source/win32/filepicker/getfilenamewrapper.hxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_GETFILENAMEWRAPPER_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_GETFILENAMEWRAPPER_HXX - -#include <sal/types.h> - -#define WIN32_LEAN_AND_MEAN -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#include <commdlg.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - -/* - A simple wrapper around the GetOpenFileName/GetSaveFileName API. - Because currently the Win32 API functions GetOpenFileName/GetSaveFileName - work only properly in an Single Threaded Apartment. -*/ - -class CGetFileNameWrapper -{ -public: - CGetFileNameWrapper(); - - bool getOpenFileName(LPOPENFILENAME lpofn); - bool getSaveFileName(LPOPENFILENAME lpofn); - int commDlgExtendedError(); - -private: - int m_ExtendedDialogError; -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/helppopupwindow.cxx b/fpicker/source/win32/filepicker/helppopupwindow.cxx deleted file mode 100644 index 3990e14f5628..000000000000 --- a/fpicker/source/win32/filepicker/helppopupwindow.cxx +++ /dev/null @@ -1,551 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "helppopupwindow.hxx" -#include <osl/diagnose.h> - - -using osl::Mutex; - - -namespace /* private */ -{ - - const PCWSTR CURRENT_INSTANCE = L"CurrInst"; - -}; - -#define HELPPOPUPWND_CLASS_NAME L"hlppopupwnd###" - -const sal_Int32 MAX_CHARS_PER_LINE = 55; - -const sal_Int32 SHADOW_WIDTH = 6; -const sal_Int32 SHADOW_HEIGHT = 6; -const sal_Int32 SHADOW_OFFSET = 6; -const sal_Int32 YOFFSET = 20; - -const DWORD OUTER_FRAME_COLOR = 0; // black -const sal_Int32 OUTER_FRAME_WIDTH = 1; // pixel - -// it's the standard windows color of an inactive window border -const DWORD INNER_FRAME_COLOR = 0xC8D0D4; -const sal_Int32 INNER_FRAME_WIDTH = 1; // pixel - - -// static member initialization - - -osl::Mutex CHelpPopupWindow::s_Mutex; -ATOM CHelpPopupWindow::s_ClassAtom = 0; -sal_Int32 CHelpPopupWindow::s_RegisterWndClassCount = 0; - - -CHelpPopupWindow::CHelpPopupWindow( - HINSTANCE hInstance, - HWND hwndParent ) : - m_hMargins( 0 ), - m_vMargins( 0 ), - m_avCharWidth( 0 ), - m_avCharHeight( 0 ), - m_hwnd( nullptr ), - m_hwndParent( hwndParent ), - m_hInstance( hInstance ), - m_hBitmapShadow( nullptr ), - m_hBrushShadow( nullptr ) -{ - m_bWndClassRegistered = RegisterWindowClass( ); - - // create a pattern brush for the window shadow - WORD aPattern[] = { 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55 }; - - m_hBitmapShadow = CreateBitmap( 8, 8, 1, 1, aPattern ); - m_hBrushShadow = CreatePatternBrush( m_hBitmapShadow ); -} - - -CHelpPopupWindow::~CHelpPopupWindow( ) -{ - // remember: we don't have to destroy the - // preview window because it will be destroyed - // by its parent window (the FileOpen dialog) - // but we have to unregister the window class - if ( m_bWndClassRegistered ) - UnregisterWindowClass( ); - - DeleteObject( m_hBitmapShadow ); - DeleteObject( m_hBrushShadow ); -} - - -void SAL_CALL CHelpPopupWindow::setText( const OUString& aHelpText ) -{ - m_HelpText = aHelpText; -} - - -void SAL_CALL CHelpPopupWindow::show( sal_Int32 x, sal_Int32 y ) -{ - OSL_ENSURE( nullptr == m_hwnd, "method should not be called twice in sequence" ); - - // we create a window with length and height of 0 - // first in order to get a device context of this - // window, then we calculate the upper left corner - // and the dimensions and resize the window - - m_hwnd = CreateWindowExW( - 0, - HELPPOPUPWND_CLASS_NAME, - nullptr, - WS_POPUP, - 0, - 0, - 0, - 0, - m_hwndParent, - nullptr, - m_hInstance, - this ); - - OSL_ENSURE( m_hwnd, "creating help popup window failed" ); - - sal_Int32 cx_new; - sal_Int32 cy_new; - - adjustWindowSize( &cx_new, &cy_new ); - adjustWindowPos( x, y, cx_new, cy_new ); - - UpdateWindow( m_hwnd ); - ShowWindow( m_hwnd, SW_SHOW ); -} - - -HWND SAL_CALL CHelpPopupWindow::setParent( HWND hwndNewParent ) -{ - HWND oldParent = m_hwndParent; - - m_hwndParent = hwndNewParent; - - return oldParent; -} - - -// calculates the necessary dimensions of the popup -// window including the margins etc. - - -void SAL_CALL CHelpPopupWindow::calcWindowRect( LPRECT lprect ) -{ - OSL_ASSERT( m_hwnd && lprect ); - - SetRect( lprect, 0, 0, MAX_CHARS_PER_LINE * m_avCharWidth, 0 ); - - HDC hdc = GetDC( m_hwnd ); - - // set the font we are using later - HGDIOBJ oldFont = SelectObject( - hdc, GetStockObject( DEFAULT_GUI_FONT ) ); - - UINT nFormat = DT_WORDBREAK | DT_CALCRECT | DT_EXTERNALLEADING | DT_LEFT; - - if ( m_HelpText.getLength( ) <= MAX_CHARS_PER_LINE ) - nFormat |= DT_SINGLELINE; - - DrawTextW( - hdc, - reinterpret_cast<PCWSTR>(m_HelpText.getStr( )), - m_HelpText.getLength( ), - lprect, - nFormat ); - - // add the necessary space for the frames - // and margins - - lprect->bottom += - m_vMargins + - SHADOW_HEIGHT + - OUTER_FRAME_WIDTH * 2 + - INNER_FRAME_WIDTH * 2; - - lprect->right += - SHADOW_WIDTH + - 2 * m_avCharWidth + - OUTER_FRAME_WIDTH * 2 + - INNER_FRAME_WIDTH * 2; - - SelectObject( hdc, oldFont ); - - ReleaseDC( m_hwnd, hdc ); -} - - -void SAL_CALL CHelpPopupWindow::adjustWindowSize( sal_Int32* cx_new, sal_Int32* cy_new ) -{ - OSL_ASSERT( cx_new && cy_new ); - - RECT rect; - calcWindowRect( &rect ); - - // adjust the window size - SetWindowPos( - m_hwnd, - nullptr, - 0, - 0, - rect.right, - rect.bottom, - SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); - - *cx_new = rect.right; - *cy_new = rect.bottom; -} - - -void SAL_CALL CHelpPopupWindow::adjustWindowPos( - sal_Int32 x, sal_Int32 y, sal_Int32 cx, sal_Int32 cy ) -{ - int popX; - int popY; - int popWidth; - int popHeight; - - OSL_ASSERT( m_hwnd ); - - HDC hdc = GetDC( m_hwnd ); - - // assuming these are screen coordinates - popWidth = cx; - popHeight = cy; - popX = x - ( popWidth / 2 ); - popY = y - YOFFSET; - - int xScreen = GetDeviceCaps( hdc, HORZRES ); - int yScreen = GetDeviceCaps( hdc, VERTRES ); - - if (popX < 0) - popX = 0; - - if (popY < 0) - popY = 0; - - if ((popX + popWidth) > xScreen) - popX = xScreen - popWidth; - - if ((popY + popHeight) > yScreen) - popY = yScreen - popHeight; - - SetWindowPos( - m_hwnd, - nullptr, - popX, - popY, - 0, - 0, - SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE ); - - ReleaseDC( m_hwnd, hdc ); -} - - -void SAL_CALL CHelpPopupWindow::onPaint( HWND hWnd, HDC hdc ) -{ - RECT rc; - RECT rect; - HGDIOBJ hpen, hpenOld; - HGDIOBJ hbrOld; - COLORREF oldBkColor; - COLORREF oldTextColor; - HGDIOBJ oldFont; - HGDIOBJ oldBrush; - HGDIOBJ hBrush; - - GetClientRect( hWnd, &rc ); - - // draw the black border - - hBrush = CreateSolidBrush( GetSysColor( COLOR_INFOBK ) ); - oldBrush = SelectObject( hdc, hBrush ); - - hpen = CreatePen( PS_SOLID, 0, OUTER_FRAME_COLOR ); - hpenOld = SelectObject( hdc, hpen ); - - Rectangle( hdc, - rc.left + OUTER_FRAME_WIDTH, - rc.top + OUTER_FRAME_WIDTH, - rc.right - SHADOW_WIDTH, - rc.bottom - SHADOW_HEIGHT); - - SelectObject( hdc, oldBrush ); - SelectObject( hdc, hpenOld ); - - DeleteObject( hBrush ); - DeleteObject( hpen ); - - // draw a light gray border - - hBrush = CreateSolidBrush( GetSysColor( COLOR_INFOBK ) ); - oldBrush = SelectObject( hdc, hBrush ); - - hpen = CreatePen( PS_SOLID, 0, INNER_FRAME_COLOR ); - hpenOld = SelectObject( hdc, hpen ); - - Rectangle( hdc, - rc.left + OUTER_FRAME_WIDTH + 1, - rc.top + OUTER_FRAME_WIDTH + 1, - rc.right - SHADOW_WIDTH - OUTER_FRAME_WIDTH, - rc.bottom - SHADOW_HEIGHT - OUTER_FRAME_WIDTH ); - - SelectObject( hdc, oldBrush ); - SelectObject( hdc, hpenOld ); - - DeleteObject( hBrush ); - DeleteObject( hpen ); - - // Write some text to this window - - rect.left = rc.left + OUTER_FRAME_WIDTH + INNER_FRAME_WIDTH + 1 + m_hMargins; - rect.top = rc.top + OUTER_FRAME_WIDTH + INNER_FRAME_WIDTH + 1 + m_vMargins / 2; - rect.right = rc.right - SHADOW_WIDTH - OUTER_FRAME_WIDTH - INNER_FRAME_WIDTH - m_hMargins; - rect.bottom = rc.bottom - SHADOW_HEIGHT - OUTER_FRAME_WIDTH - INNER_FRAME_WIDTH - m_vMargins / 2; - - oldBkColor = SetBkColor( hdc, GetSysColor( COLOR_INFOBK ) ); - oldTextColor = SetTextColor( hdc, COLOR_INFOTEXT ); - - oldFont = SelectObject( hdc, GetStockObject( DEFAULT_GUI_FONT ) ); - - UINT nFormat = DT_WORDBREAK | DT_EXTERNALLEADING | DT_LEFT; - - if ( m_HelpText.getLength( ) <= MAX_CHARS_PER_LINE ) - nFormat |= DT_SINGLELINE; - - DrawTextW( - hdc, - reinterpret_cast<wchar_t const *>(m_HelpText.getStr( )), - m_HelpText.getLength( ), - &rect, - nFormat ); - - SelectObject( hdc, oldFont ); - SetTextColor( hdc, oldTextColor ); - SetBkColor( hdc, oldBkColor ); - - // set text color and text background color - // see MSDN PatBlt - - oldBkColor = SetBkColor( hdc, RGB( 0, 0, 0 ) ); - oldTextColor = SetTextColor( hdc, RGB( 255, 255, 255 ) ); - - // Get our brush for the shadow - - UnrealizeObject( m_hBrushShadow ); - hbrOld = SelectObject( hdc, m_hBrushShadow ); - - // bottom shadow - - PatBlt(hdc, - rc.left + SHADOW_OFFSET, - rc.bottom - SHADOW_HEIGHT, - rc.right - SHADOW_OFFSET - SHADOW_WIDTH, - SHADOW_HEIGHT, - 0xA000C9); - - // right-side shadow - - PatBlt(hdc, - rc.right - SHADOW_WIDTH, - rc.top + SHADOW_OFFSET, - SHADOW_WIDTH, - rc.bottom - SHADOW_OFFSET, - 0xA000C9); - - SelectObject(hdc, hbrOld); - SetTextColor( hdc, oldTextColor ); - SetBkColor( hdc, oldBkColor ); -} - - -void SAL_CALL CHelpPopupWindow::onNcDestroy() -{ - m_hwnd = nullptr; -} - - -void SAL_CALL CHelpPopupWindow::onCreate( HWND hwnd ) -{ - m_hwnd = hwnd; - - HDC hdc = GetDC( m_hwnd ); - - HGDIOBJ oldFont = SelectObject( - hdc, GetStockObject( DEFAULT_GUI_FONT ) ); - - TEXTMETRIC tm; - GetTextMetrics( hdc, &tm ); - - m_avCharWidth = tm.tmAveCharWidth; - m_avCharHeight = tm.tmHeight; - - if ( 0 == m_hMargins ) - m_hMargins = m_avCharWidth; - - if ( 0 == m_vMargins ) - m_vMargins = m_avCharHeight; - - SelectObject( hdc, oldFont ); - - ReleaseDC( m_hwnd, hdc ); -} - - -LRESULT CALLBACK CHelpPopupWindow::WndProc( - HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) -{ - LRESULT lResult = 0; - - switch ( uMsg ) - { - case WM_CREATE: - { - LPCREATESTRUCT lpcs = - reinterpret_cast< LPCREATESTRUCT >( lParam ); - - OSL_ASSERT( lpcs->lpCreateParams ); - - CHelpPopupWindow* pImpl = static_cast< CHelpPopupWindow* >( - lpcs->lpCreateParams ); - - // connect the instance handle to the window - SetPropW( hWnd, CURRENT_INSTANCE, pImpl ); - - pImpl->onCreate( hWnd ); - - // capture mouse and keybord events - SetCapture( hWnd ); - } - break; - - case WM_PAINT: - { - CHelpPopupWindow* pImpl = static_cast< CHelpPopupWindow* >( - GetPropW( hWnd, CURRENT_INSTANCE ) ); - - OSL_ASSERT( pImpl ); - - PAINTSTRUCT ps; - - BeginPaint(hWnd, &ps); - pImpl->onPaint( hWnd, ps.hdc ); - EndPaint(hWnd, &ps); - } - break; - - case WM_NCDESTROY: - { - // RemoveProp returns the saved value on success - CHelpPopupWindow* pImpl = static_cast< CHelpPopupWindow* >( - RemovePropW( hWnd, CURRENT_INSTANCE ) ); - - OSL_ASSERT( pImpl ); - - pImpl->onNcDestroy(); - } - break; - - case WM_LBUTTONDOWN: - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - case WM_MBUTTONDOWN: - case WM_RBUTTONDOWN: - ReleaseCapture(); - DestroyWindow(hWnd); - break; - - default: - return DefWindowProc(hWnd, uMsg, wParam, lParam); - } - - return lResult; -} - - -ATOM SAL_CALL CHelpPopupWindow::RegisterWindowClass( ) -{ - osl::MutexGuard aGuard( s_Mutex ); - - if ( 0 == s_ClassAtom ) - { - // register the window class - WNDCLASSEX wndClsEx; - - ZeroMemory(&wndClsEx, sizeof(wndClsEx)); - - wndClsEx.cbSize = sizeof(wndClsEx); - wndClsEx.lpfnWndProc = CHelpPopupWindow::WndProc; - wndClsEx.hInstance = m_hInstance; - wndClsEx.hCursor = LoadCursor(nullptr, IDC_ARROW); - wndClsEx.hbrBackground = static_cast<HBRUSH>(GetStockObject( NULL_BRUSH )); - wndClsEx.lpszClassName = HELPPOPUPWND_CLASS_NAME; - - // register the preview window class - // !!! Win95 - the window class will be unregistered automatically - // 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); - } - - // increment the register class counter - // so that we keep track of the number - // of class registrations - if (0 != s_ClassAtom) - s_RegisterWndClassCount++; - - return s_ClassAtom; -} - - -void SAL_CALL CHelpPopupWindow::UnregisterWindowClass( ) -{ - osl::MutexGuard aGuard( s_Mutex ); - - OSL_ASSERT( ( (0 != s_ClassAtom) && (s_RegisterWndClassCount > 0)) || - ( (0 == s_ClassAtom) && (0 == s_RegisterWndClassCount) ) ); - - // update the register class counter - // and unregister the window class if - // counter drops to zero - if ( 0 != s_ClassAtom ) - { - s_RegisterWndClassCount--; - OSL_ASSERT( s_RegisterWndClassCount >= 0 ); - } - - if ( 0 == s_RegisterWndClassCount ) - { - if ( !UnregisterClassW( - reinterpret_cast<PCWSTR>((DWORD_PTR)MAKELONG( s_ClassAtom, 0 )), m_hInstance ) ) - { - OSL_FAIL( "unregister window class failed" ); - } - - s_ClassAtom = 0; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/helppopupwindow.hxx b/fpicker/source/win32/filepicker/helppopupwindow.hxx deleted file mode 100644 index d63230238f75..000000000000 --- a/fpicker/source/win32/filepicker/helppopupwindow.hxx +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_HELPPOPUPWINDOW_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_HELPPOPUPWINDOW_HXX - -#include <sal/types.h> -#include <rtl/ustring.hxx> -#include <osl/mutex.hxx> - -#define WIN32_LEAN_AND_MEAN -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -// declaration - - -/* - A simple popup window similarly to the one the - windows help (using WinHelp) creates when called - with the option HELP_CONTEXTPOPUP. - - The interface is very simple but necessary for our - needs. - The window automatically calculates the necessary - dimensions of the window and a appropriate show - position based on the position the client provides. - When the user click any mouse button or hits any key - the window closes itself and disappears. -*/ - -class CHelpPopupWindow -{ -public: - - /* - The client may set some parameter of the window. - When the client omits to set one or more values - a default value will be taken. - The values are in pixel. - */ - CHelpPopupWindow( - HINSTANCE hInstance, - HWND hwndParent ); - - /* - dtor - */ - ~CHelpPopupWindow( ); - - /* - The client may set the text the window is showing - on next activation. - */ - void SAL_CALL setText( const OUString& aHelpText ); - - /* - Shows the window with the text that was last set. - The position is the preferred position. The window - may itself show at a slightly different position - if it fits not at the preferred position. - */ - void SAL_CALL show( sal_Int32 x, sal_Int32 y ); - - HWND SAL_CALL setParent( HWND hwndNewParent ); - -private: - void SAL_CALL onPaint( HWND, HDC ); - void SAL_CALL onNcDestroy(); - void SAL_CALL onCreate( HWND ); - - POINT SAL_CALL calcUpperLeftCorner( ); - void SAL_CALL calcWindowRect( LPRECT lprect ); - - void SAL_CALL adjustWindowSize( sal_Int32*, sal_Int32* ); - void SAL_CALL adjustWindowPos( sal_Int32 x, sal_Int32 y, sal_Int32 cx, sal_Int32 cy ); - - ATOM SAL_CALL RegisterWindowClass( ); - void SAL_CALL UnregisterWindowClass( ); - - static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); - -private: - sal_Int32 m_hMargins; - sal_Int32 m_vMargins; - sal_Int32 m_avCharWidth; - sal_Int32 m_avCharHeight; - HWND m_hwnd; - HWND m_hwndParent; - HINSTANCE m_hInstance; - bool m_bWndClassRegistered; - OUString m_HelpText; - HBITMAP m_hBitmapShadow; - HBRUSH m_hBrushShadow; - - // the window class has to be registered only - // once per process, so multiple instance of this class - // share the registered window class - static ATOM s_ClassAtom; - static osl::Mutex s_Mutex; - static sal_Int32 s_RegisterWndClassCount; - -// prevent copy and assignment -private: - CHelpPopupWindow( const CHelpPopupWindow& ); - CHelpPopupWindow& operator=( const CHelpPopupWindow& ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/platform_xp.h b/fpicker/source/win32/filepicker/platform_xp.h deleted file mode 100644 index 4d4792a29dff..000000000000 --- a/fpicker/source/win32/filepicker/platform_xp.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PLATFORM_XP_H -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PLATFORM_XP_H - -#pragma once - -// Change these values to use different versions -#undef WINVER -#undef _WIN32_WINNT -#undef _WIN32_IE -#undef _WTL_NO_CSTRING - -#define WINVER 0x0502 -#define _WIN32_WINNT 0x0502 -#define _WIN32_IE 0x0700 -#define _WTL_NO_CSTRING - -#if defined _MSC_VER - #pragma warning(push, 1) -#endif - -#include <windows.h> - -#if defined _MSC_VER - #pragma warning(pop) -#endif - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/previewadapter.cxx b/fpicker/source/win32/filepicker/previewadapter.cxx deleted file mode 100644 index 2eeb61da15b8..000000000000 --- a/fpicker/source/win32/filepicker/previewadapter.cxx +++ /dev/null @@ -1,455 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - - -#include "previewadapter.hxx" - -#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> -#include <osl/diagnose.h> -#include "dibpreview.hxx" -#include "../misc/WinImplHelper.hxx" - -#include <memory> -#include <stdexcept> - - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; - - -// An impl class to hide implementation details -// from clients - - -class CPreviewAdapterImpl -{ -public: - explicit CPreviewAdapterImpl(HINSTANCE instance); - - virtual ~CPreviewAdapterImpl(); - - virtual sal_Int32 SAL_CALL getTargetColorDepth(); - - virtual sal_Int32 SAL_CALL getAvailableWidth(); - - virtual sal_Int32 SAL_CALL getAvailableHeight(); - - /// @throws IllegalArgumentException - /// @throws RuntimeException - virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const Any& aImage ); - - virtual bool SAL_CALL setShowState(bool bShowState); - - virtual bool SAL_CALL getShowState(); - - virtual void SAL_CALL setParent(HWND parent); - - virtual HWND SAL_CALL getParent(); - - - // parent notification handler - - - virtual void SAL_CALL notifyParentShow(bool bShow); - - virtual void SAL_CALL notifyParentSizeChanged(); - - virtual void SAL_CALL notifyParentWindowPosChanged(); - -protected: - virtual void SAL_CALL calcRightMargin(); - - virtual void SAL_CALL rearrangeLayout(); - - /// @throws std::runtime_error - void SAL_CALL initializeActivePreview(); - - HWND SAL_CALL findFileListbox() const; - -// member -protected: - HINSTANCE m_Instance; - std::unique_ptr<PreviewBase> m_Preview; - HWND m_FileDialog; - int m_RightMargin; - -//prevent copy/assignment -private: - CPreviewAdapterImpl(const CPreviewAdapterImpl&) = delete; - CPreviewAdapterImpl& operator=(const CPreviewAdapterImpl&) = delete; -}; - - -CPreviewAdapterImpl::CPreviewAdapterImpl(HINSTANCE instance) : - m_Instance(instance), - m_Preview(new PreviewBase()), // create dummy preview (NULL-Object pattern) - m_FileDialog(nullptr), - m_RightMargin(0) -{ -} - - -CPreviewAdapterImpl::~CPreviewAdapterImpl() -{ -} - - -sal_Int32 SAL_CALL CPreviewAdapterImpl::getTargetColorDepth() -{ - return m_Preview->getTargetColorDepth(); -} - - -sal_Int32 SAL_CALL CPreviewAdapterImpl::getAvailableWidth() -{ - return m_Preview->getAvailableWidth(); -} - - -sal_Int32 SAL_CALL CPreviewAdapterImpl::getAvailableHeight() -{ - return m_Preview->getAvailableHeight(); -} - - -void SAL_CALL CPreviewAdapterImpl::setImage( sal_Int16 aImageFormat, const Any& aImage ) -{ - m_Preview->setImage(aImageFormat,aImage); -} - - -bool SAL_CALL CPreviewAdapterImpl::setShowState( bool bShowState ) -{ - bool bRet = m_Preview->setShowState(bShowState); - rearrangeLayout(); - return bRet; -} - - -bool SAL_CALL CPreviewAdapterImpl::getShowState() -{ - return m_Preview->getShowState(); -} - - -void SAL_CALL CPreviewAdapterImpl::setParent(HWND parent) -{ - OSL_PRECOND(IsWindow(parent),"Invalid FileDialog handle"); - - m_FileDialog = parent; - calcRightMargin(); -} - - -HWND SAL_CALL CPreviewAdapterImpl::getParent() -{ - return m_FileDialog; -} - - -void SAL_CALL CPreviewAdapterImpl::calcRightMargin() -{ - // Calculate the right reference margin - - // Assumption: - // 1. This method will be called before the dialog becomes - // visible - // 2. There exist a FileListbox with the id lst1 even - // if it is not visible like under Win2000/XP - // 3. Initially this FileListbox has the appropriate size - // to fit within the FileListbox - // 4. The margin between the right edge of the FileListbox - // and the right edge of the FileDialog will be constant - // even if the size of the dialog changes - - HWND flb = GetDlgItem(m_FileDialog,lst1); - - OSL_ENSURE(IsWindow(flb),"Filelistbox not found"); - - RECT rcFlb; - GetWindowRect(flb,&rcFlb); - - RECT rcFileDlg; - GetWindowRect(m_FileDialog,&rcFileDlg); - - m_RightMargin = rcFileDlg.right - rcFlb.right; -} - - -void SAL_CALL CPreviewAdapterImpl::notifyParentShow(bool) -{ -} - - -void SAL_CALL CPreviewAdapterImpl::notifyParentSizeChanged() -{ - rearrangeLayout(); -} - - -void SAL_CALL CPreviewAdapterImpl::notifyParentWindowPosChanged() -{ -} - - -void SAL_CALL CPreviewAdapterImpl::rearrangeLayout() -{ - // try to get a handle to the filelistbox - // if there is no new-style filelistbox like - // in Win2000/XP there should be at least the - // old listbox, so we take this one - // lst1 - identifies the old-style filelistbox - // lst2 - identifies the new-style filelistbox - // see dlgs.h - HWND flb_new = findFileListbox(); - - // under Windows NT 4.0 the size of the old - // filelistbox will be used as reference for - // sizing the new filelistbox, so we have - // to change the size of it too - HWND flb_old = GetDlgItem(m_FileDialog,lst1); - - RECT rcFlbNew; - GetWindowRect(flb_new,&rcFlbNew); - - RECT rcFileDlg; - GetWindowRect(m_FileDialog,&rcFileDlg); - rcFileDlg.right -= m_RightMargin; - - // the available area for the filelistbox should be - // the left edge of the filelistbox and the right - // edge of the OK button, we take this as reference - int height = rcFlbNew.bottom - rcFlbNew.top; - int width = rcFileDlg.right - rcFlbNew.left; - - HWND prvwnd = m_Preview->getWindowHandle(); - - // we use GetWindowLong to ask for the visibility - // of the preview window because IsWindowVisible - // only returns true the specified window including - // its parent windows are visible - // this is not the case when we are called in response - // to the WM_SHOWWINDOW message, somehow the WS_VISIBLE - // style bit of the FileOpen dialog must be set after that - // message - LONG lStyle = GetWindowLong(prvwnd,GWL_STYLE); - bool bIsVisible = ((lStyle & WS_VISIBLE) != 0); - - int cx = 0; - - if (IsWindow(prvwnd) && bIsVisible) - { - cx = width/2; - - // resize the filelistbox to the half of the - // available space - SetWindowPos(flb_new, - nullptr, 0, 0, cx, height, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); - - SetWindowPos(flb_old, - nullptr, 0, 0, cx, height, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); - - // get the new dimensions of the filelistbox after - // resizing and take the right,top corner as starting - // point for the preview window - GetWindowRect(flb_new,&rcFlbNew); - POINT pt = { rcFlbNew.right, rcFlbNew.top }; - ScreenToClient(m_FileDialog,&pt); - - // resize the preview window to fit within - // the available space and set the window - // to the top of the z-order else it will - // be invisible - SetWindowPos(prvwnd, - HWND_TOP, pt.x, pt.y, cx, height, SWP_NOACTIVATE); - } - else - { - // resize the filelistbox to the maximum available - // space - cx = rcFileDlg.right - rcFlbNew.left; - - // resize the old filelistbox - SetWindowPos(flb_old, - nullptr, 0, 0, cx, height, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); - - // resize the new filelistbox - SetWindowPos(flb_new, - nullptr, 0, 0, cx, height, - SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE ); - } -} - - -void SAL_CALL CPreviewAdapterImpl::initializeActivePreview() -{ - bool bShowState = m_Preview->getImaginaryShowState(); - - sal_Int16 aImgFrmt; - Any aImg; - m_Preview->getImage(aImgFrmt,aImg); - - HWND flb = findFileListbox(); - - PreviewBase* prv = new CDIBPreview( - m_Instance, GetParent(flb), bShowState); - - m_Preview.reset(prv); - - m_Preview->setImage(aImgFrmt,aImg); -} - - -HWND SAL_CALL CPreviewAdapterImpl::findFileListbox() const -{ - // try to get a handle to the filelistbox - // if there is no new-style filelistbox like - // in Win2000/XP there should be at least the - // old listbox, so we take this one - // lst1 - identifies the old-style filelistbox - // lst2 - identifies the new-style filelistbox - // see dlgs.h - HWND flb = GetDlgItem(m_FileDialog,lst2); - if (!IsWindow(flb)) - flb = GetDlgItem(m_FileDialog,lst1); - - return flb; -} - - -// Implementation for Windows 95/NT/ME/2000/XP -// because: - - -class CWin95NTPreviewAdapterImpl : public CPreviewAdapterImpl -{ -public: - explicit CWin95NTPreviewAdapterImpl(HINSTANCE instance); - - virtual void SAL_CALL notifyParentShow(bool bShow) override; -}; - - -CWin95NTPreviewAdapterImpl::CWin95NTPreviewAdapterImpl(HINSTANCE instance) : - CPreviewAdapterImpl(instance) -{ -} - - -void SAL_CALL CWin95NTPreviewAdapterImpl::notifyParentShow(bool bShow) -{ - try - { - if (bShow) - { - initializeActivePreview(); - rearrangeLayout(); - } - } - catch(std::runtime_error&) - { - } -} - - -// ctor - - -CPreviewAdapter::CPreviewAdapter(HINSTANCE instance) -{ - m_pImpl.reset(new CWin95NTPreviewAdapterImpl(instance)); -} - - -CPreviewAdapter::~CPreviewAdapter() -{ -} - - -Sequence<sal_Int16> SAL_CALL CPreviewAdapter::getSupportedImageFormats() -{ - css::uno::Sequence<sal_Int16> imgFormats(1); - imgFormats[0] = css::ui::dialogs::FilePreviewImageFormats::BITMAP; - return imgFormats; -} - - -sal_Int32 SAL_CALL CPreviewAdapter::getTargetColorDepth() -{ - return m_pImpl->getTargetColorDepth(); -} - - -sal_Int32 SAL_CALL CPreviewAdapter::getAvailableWidth() -{ - return m_pImpl->getAvailableWidth(); -} - - -sal_Int32 SAL_CALL CPreviewAdapter::getAvailableHeight() -{ - return m_pImpl->getAvailableHeight(); -} - - -void SAL_CALL CPreviewAdapter::setImage( sal_Int16 aImageFormat, const Any& aImage ) -{ - m_pImpl->setImage(aImageFormat,aImage); -} - - -bool SAL_CALL CPreviewAdapter::setShowState( bool bShowState ) -{ - return m_pImpl->setShowState(bShowState); -} - - -bool SAL_CALL CPreviewAdapter::getShowState() -{ - return m_pImpl->getShowState(); -} - - -void SAL_CALL CPreviewAdapter::setParent(HWND parent) -{ - m_pImpl->setParent(parent); -} - - -void SAL_CALL CPreviewAdapter::notifyParentShow(bool bShow) -{ - m_pImpl->notifyParentShow(bShow); -} - - -void SAL_CALL CPreviewAdapter::notifyParentSizeChanged() -{ - m_pImpl->notifyParentSizeChanged(); -} - - -void SAL_CALL CPreviewAdapter::notifyParentWindowPosChanged() -{ - m_pImpl->notifyParentWindowPosChanged(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/previewadapter.hxx b/fpicker/source/win32/filepicker/previewadapter.hxx deleted file mode 100644 index 1f14098ae849..000000000000 --- a/fpicker/source/win32/filepicker/previewadapter.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PREVIEWADAPTER_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PREVIEWADAPTER_HXX - -#include <sal/types.h> -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/uno/RuntimeException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/uno/Any.hxx> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif -#include <memory> - -class CPreviewAdapterImpl; - -// A kind of a facade for the preview class. -// We want to hide the fact that the preview -// window may only become visible if there is -// a valid parent window (means, the FilePicker) -// is in execution mode. So unless someone sets -// the preview active with a valid parent -// window the preview may not be visible - -class CPreviewAdapter -{ -public: - - // ctor - explicit CPreviewAdapter(HINSTANCE instance); - - ~CPreviewAdapter(); - - static css::uno::Sequence<sal_Int16> SAL_CALL getSupportedImageFormats(); - - sal_Int32 SAL_CALL getTargetColorDepth(); - - sal_Int32 SAL_CALL getAvailableWidth(); - - sal_Int32 SAL_CALL getAvailableHeight(); - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - void SAL_CALL setImage(sal_Int16 aImageFormat, const css::uno::Any& aImage); - - bool SAL_CALL setShowState(bool bShowState); - - bool SAL_CALL getShowState(); - - void SAL_CALL setParent(HWND parent); - - - // notification from parent - - - void SAL_CALL notifyParentShow(bool bShow); - - void SAL_CALL notifyParentSizeChanged(); - - void SAL_CALL notifyParentWindowPosChanged(); - -private: - // hide implementation details using the - // bridge pattern - std::unique_ptr<CPreviewAdapterImpl> m_pImpl; - -// prevent copy and assignment -private: - CPreviewAdapter(const CPreviewAdapter&); - CPreviewAdapter& operator=(const CPreviewAdapter&); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/previewbase.cxx b/fpicker/source/win32/filepicker/previewbase.cxx deleted file mode 100644 index ade90668d016..000000000000 --- a/fpicker/source/win32/filepicker/previewbase.cxx +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#include "previewbase.hxx" - -#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp> -#include <com/sun/star/uno/Sequence.hxx> - -using namespace com::sun::star::uno; -using namespace com::sun::star::lang; - - -PreviewBase::PreviewBase() : - m_ImageFormat(css::ui::dialogs::FilePreviewImageFormats::BITMAP), - m_bShowState(false) -{ -} - - -PreviewBase::~PreviewBase() -{ -} - - -sal_Int32 SAL_CALL PreviewBase::getTargetColorDepth() -{ - return 0; -} - - -sal_Int32 SAL_CALL PreviewBase::getAvailableWidth() -{ - return 0; -} - - -sal_Int32 SAL_CALL PreviewBase::getAvailableHeight() -{ - return 0; -} - - -void SAL_CALL PreviewBase::setImage( sal_Int16 aImageFormat, const css::uno::Any& aImage ) -{ - if (aImageFormat != css::ui::dialogs::FilePreviewImageFormats::BITMAP) - throw IllegalArgumentException( - "unsupported image format", nullptr, 1); - - if (aImage.hasValue() && (aImage.getValueType() != cppu::UnoType<Sequence<sal_Int8>>::get())) - throw IllegalArgumentException( - "invalid image data", nullptr, 2); - - // save the new image data and force a redraw - m_ImageData = aImage; - m_ImageFormat = aImageFormat; -} - - -void SAL_CALL PreviewBase::getImage(sal_Int16& aImageFormat,css::uno::Any& aImage) -{ - aImageFormat = m_ImageFormat; - aImage = m_ImageData; -} - - -bool SAL_CALL PreviewBase::setShowState( bool bShowState ) -{ - m_bShowState = bShowState; - return true; -} - - -bool SAL_CALL PreviewBase::getShowState() -{ - return false; -} - - -bool SAL_CALL PreviewBase::getImaginaryShowState() const -{ - return m_bShowState; -} - - -HWND SAL_CALL PreviewBase::getWindowHandle() const -{ - return nullptr; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/fpicker/source/win32/filepicker/previewbase.hxx b/fpicker/source/win32/filepicker/previewbase.hxx deleted file mode 100644 index 503b541457f5..000000000000 --- a/fpicker/source/win32/filepicker/previewbase.hxx +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PREVIEWBASE_HXX -#define INCLUDED_FPICKER_SOURCE_WIN32_FILEPICKER_PREVIEWBASE_HXX - -#include <sal/types.h> -#include <com/sun/star/uno/RuntimeException.hpp> -#include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <com/sun/star/uno/Any.hxx> - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif - - -// Common interface for previews - - -class PreviewBase -{ -public: - PreviewBase(); - - // dtor - virtual ~PreviewBase(); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getTargetColorDepth(); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getAvailableWidth(); - - /// @throws css::uno::RuntimeException - virtual sal_Int32 SAL_CALL getAvailableHeight(); - - /// @throws css::lang::IllegalArgumentException - /// @throws css::uno::RuntimeException - virtual void SAL_CALL setImage( sal_Int16 aImageFormat, const css::uno::Any& aImage ); - - /// @throws css::uno::RuntimeException - virtual bool SAL_CALL setShowState( bool bShowState ); - - /// @throws css::uno::RuntimeException - virtual bool SAL_CALL getShowState(); - - virtual void SAL_CALL getImage(sal_Int16& aImageFormat,css::uno::Any& aImage); - - bool SAL_CALL getImaginaryShowState() const; - - virtual HWND SAL_CALL getWindowHandle() const; - -protected: - css::uno::Any m_ImageData; - sal_Int16 m_ImageFormat; - bool m_bShowState; -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |