diff options
Diffstat (limited to '')
29 files changed, 2535 insertions, 0 deletions
diff --git a/vcl/inc/qt5/Qt5AccessibleEventListener.hxx b/vcl/inc/qt5/Qt5AccessibleEventListener.hxx new file mode 100644 index 000000000..0fd3783ee --- /dev/null +++ b/vcl/inc/qt5/Qt5AccessibleEventListener.hxx @@ -0,0 +1,38 @@ +/* -*- 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/. + */ + +#pragma once + +#include <com/sun/star/accessibility/XAccessible.hpp> +#include <com/sun/star/accessibility/XAccessibleEventListener.hpp> +#include <com/sun/star/lang/EventObject.hpp> + +#include "Qt5AccessibleWidget.hxx" + +#include <cppuhelper/implbase.hxx> + +class Qt5AccessibleEventListener final + : public cppu::WeakImplHelper<css::accessibility::XAccessibleEventListener> +{ +public: + Qt5AccessibleEventListener( + const css::uno::Reference<css::accessibility::XAccessible> xAccessible, + Qt5AccessibleWidget* pAccessibleWidget); + + virtual void SAL_CALL + notifyEvent(const css::accessibility::AccessibleEventObject& aEvent) override; + + virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override; + +private: + css::uno::Reference<css::accessibility::XAccessible> m_xAccessible; + Qt5AccessibleWidget* m_pAccessibleWidget; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5AccessibleWidget.hxx b/vcl/inc/qt5/Qt5AccessibleWidget.hxx new file mode 100644 index 000000000..aacaba9a8 --- /dev/null +++ b/vcl/inc/qt5/Qt5AccessibleWidget.hxx @@ -0,0 +1,144 @@ +/* -*- 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/. + */ + +#pragma once + +#include <vclpluginapi.h> + +#include <QtCore/QObject> +#include <QtCore/QPair> +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QVector> +#include <QtGui/QAccessible> +#include <QtGui/QAccessibleActionInterface> +#include <QtGui/QAccessibleInterface> +#include <QtGui/QAccessibleTableInterface> +#include <QtGui/QAccessibleTextInterface> +#include <QtGui/QAccessibleValueInterface> +#include <QtGui/QColor> +#include <QtGui/QWindow> + +#include <com/sun/star/accessibility/XAccessible.hpp> + +class Qt5Frame; +class Qt5Widget; + +class Qt5AccessibleWidget final : public QObject, + public QAccessibleInterface, + public QAccessibleActionInterface, + public QAccessibleTextInterface, + public QAccessibleEditableTextInterface, + public QAccessibleTableInterface, + public QAccessibleValueInterface +{ + Q_OBJECT + +public: + Qt5AccessibleWidget(const css::uno::Reference<css::accessibility::XAccessible> xAccessible, + QObject* pObject); + QWindow* window() const override; + int childCount() const override; + int indexOfChild(const QAccessibleInterface* child) const override; + QVector<QPair<QAccessibleInterface*, QAccessible::Relation>> + relations(QAccessible::Relation match = QAccessible::AllRelations) const override; + QAccessibleInterface* focusChild() const override; + + QRect rect() const override; + + QAccessibleInterface* parent() const override; + QAccessibleInterface* child(int index) const override; + + QString text(QAccessible::Text t) const override; + QAccessible::Role role() const override; + QAccessible::State state() const override; + + QColor foregroundColor() const override; + QColor backgroundColor() const override; + + bool isValid() const override; + QObject* object() const override; + void setText(QAccessible::Text t, const QString& text) override; + QAccessibleInterface* childAt(int x, int y) const override; + + void* interface_cast(QAccessible::InterfaceType t) override; + + // QAccessibleActionInterface + QStringList actionNames() const override; + void doAction(const QString& actionName) override; + QStringList keyBindingsForAction(const QString& actionName) const override; + + static QAccessibleValueInterface* valueInterface(); + static QAccessibleTextInterface* textInterface(); + + // QAccessibleTextInterface + void addSelection(int startOffset, int endOffset) override; + QString attributes(int offset, int* startOffset, int* endOffset) const override; + int characterCount() const override; + QRect characterRect(int offset) const override; + int cursorPosition() const override; + int offsetAtPoint(const QPoint& point) const override; + void removeSelection(int selectionIndex) override; + void scrollToSubstring(int startIndex, int endIndex) override; + void selection(int selectionIndex, int* startOffset, int* endOffset) const override; + int selectionCount() const override; + void setCursorPosition(int position) override; + void setSelection(int selectionIndex, int startOffset, int endOffset) override; + QString text(int startOffset, int endOffset) const override; + QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int* startOffset, int* endOffset) const override; + QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, int* startOffset, + int* endOffset) const override; + QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, + int* startOffset, int* endOffset) const override; + + // QAccessibleEditableTextInterface + virtual void deleteText(int startOffset, int endOffset) override; + virtual void insertText(int offset, const QString& text) override; + virtual void replaceText(int startOffset, int endOffset, const QString& text) override; + + // QAccessibleValueInterface + QVariant currentValue() const override; + QVariant maximumValue() const override; + QVariant minimumStepSize() const override; + QVariant minimumValue() const override; + void setCurrentValue(const QVariant& value) override; + + // QAccessibleTableInterface + virtual QAccessibleInterface* caption() const override; + virtual QAccessibleInterface* cellAt(int row, int column) const override; + virtual int columnCount() const override; + virtual QString columnDescription(int column) const override; + virtual bool isColumnSelected(int column) const override; + virtual bool isRowSelected(int row) const override; + virtual void modelChange(QAccessibleTableModelChangeEvent* event) override; + virtual int rowCount() const override; + virtual QString rowDescription(int row) const override; + virtual bool selectColumn(int column) override; + virtual bool selectRow(int row) override; + virtual int selectedCellCount() const override; + virtual QList<QAccessibleInterface*> selectedCells() const override; + virtual int selectedColumnCount() const override; + virtual QList<int> selectedColumns() const override; + virtual int selectedRowCount() const override; + virtual QList<int> selectedRows() const override; + virtual QAccessibleInterface* summary() const override; + virtual bool unselectColumn(int column) override; + virtual bool unselectRow(int row) override; + + // Factory + static QAccessibleInterface* customFactory(const QString& classname, QObject* object); + +private: + css::uno::Reference<css::accessibility::XAccessible> m_xAccessible; + css::uno::Reference<css::accessibility::XAccessibleContext> getAccessibleContextImpl() const; + QObject* m_pObject; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Bitmap.hxx b/vcl/inc/qt5/Qt5Bitmap.hxx new file mode 100644 index 000000000..8ff4297e4 --- /dev/null +++ b/vcl/inc/qt5/Qt5Bitmap.hxx @@ -0,0 +1,66 @@ +/* -*- 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 . + */ + +#pragma once + +#include <salbmp.hxx> + +#include <memory> + +class QImage; + +class Qt5Bitmap final : public SalBitmap +{ + std::unique_ptr<QImage> m_pImage; + BitmapPalette m_aPalette; + + // for 4bit support + std::unique_ptr<sal_uInt8[]> m_pBuffer; + Size m_aSize; + sal_uInt32 m_nScanline; + +public: + Qt5Bitmap(); + Qt5Bitmap(const QImage& rQImage); + + const QImage* GetQImage() const { return m_pImage.get(); } + + virtual bool Create(const Size& rSize, sal_uInt16 nBitCount, + const BitmapPalette& rPal) override; + virtual bool Create(const SalBitmap& rSalBmp) override; + virtual bool Create(const SalBitmap& rSalBmp, SalGraphics* pGraphics) override; + virtual bool Create(const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount) override; + virtual bool Create(const css::uno::Reference<css::rendering::XBitmapCanvas>& rBitmapCanvas, + Size& rSize, bool bMask = false) override; + virtual void Destroy() final override; + virtual Size GetSize() const override; + virtual sal_uInt16 GetBitCount() const override; + + virtual BitmapBuffer* AcquireBuffer(BitmapAccessMode nMode) override; + virtual void ReleaseBuffer(BitmapBuffer* pBuffer, BitmapAccessMode nMode) override; + virtual bool GetSystemData(BitmapSystemData& rData) override; + + virtual bool ScalingSupported() const override; + virtual bool Scale(const double& rScaleX, const double& rScaleY, + BmpScaleFlag nScaleFlag) override; + virtual bool Replace(const Color& rSearchColor, const Color& rReplaceColor, + sal_uInt8 nTol) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Clipboard.hxx b/vcl/inc/qt5/Qt5Clipboard.hxx new file mode 100644 index 000000000..b99534f59 --- /dev/null +++ b/vcl/inc/qt5/Qt5Clipboard.hxx @@ -0,0 +1,97 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/datatransfer/XTransferable.hpp> +#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp> +#include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp> +#include <com/sun/star/datatransfer/clipboard/XClipboardListener.hpp> +#include <cppuhelper/compbase.hxx> + +#include <QtGui/QClipboard> + +/** + * This implementation has two main functions, which handle the clipboard content: + * the XClipboard::setContent function and the QClipboard::change signal handler. + * + * The first just sets the respective clipboard to the expected content from LO, + * the latter will handle any reported changes. + **/ +class Qt5Clipboard final + : public QObject, + public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, + css::datatransfer::clipboard::XFlushableClipboard, + css::lang::XServiceInfo> +{ + Q_OBJECT + + osl::Mutex m_aMutex; + const OUString m_aClipboardName; + const QClipboard::Mode m_aClipboardMode; + // has to be set, if LO changes the QClipboard itself, so it won't instantly lose + // ownership by it's self-triggered QClipboard::changed handler + bool m_bOwnClipboardChange; + // true, if LO really wants to give up clipboard ownership + bool m_bDoClear; + + // if not empty, this holds the setContents provided XTransferable or a Qt5ClipboardTransferable + css::uno::Reference<css::datatransfer::XTransferable> m_aContents; + // the owner of the current contents, which must be informed on content change + css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner; + std::vector<css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>> m_aListeners; + + static bool isOwner(const QClipboard::Mode aMode); + static bool isSupported(const QClipboard::Mode aMode); + + explicit Qt5Clipboard(const OUString& aModeString, const QClipboard::Mode aMode); + +private Q_SLOTS: + void handleChanged(QClipboard::Mode mode); + void handleClearClipboard(); + +signals: + void clearClipboard(); + +public: + // factory function to construct only valid Qt5Clipboard objects by name + static css::uno::Reference<css::uno::XInterface> create(const OUString& aModeString); + + // 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; + + // XClipboard + virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getContents() override; + virtual void SAL_CALL setContents( + const css::uno::Reference<css::datatransfer::XTransferable>& xTrans, + const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner) + override; + virtual OUString SAL_CALL getName() override; + + // XClipboardEx + virtual sal_Int8 SAL_CALL getRenderingCapabilities() override; + + // XFlushableClipboard + virtual void SAL_CALL flushClipboard() override; + + // XClipboardNotifier + virtual void SAL_CALL addClipboardListener( + const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener) + override; + virtual void SAL_CALL removeClipboardListener( + const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener) + override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Data.hxx b/vcl/inc/qt5/Qt5Data.hxx new file mode 100644 index 000000000..1834835d3 --- /dev/null +++ b/vcl/inc/qt5/Qt5Data.hxx @@ -0,0 +1,47 @@ +/* -*- 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 . + */ + +#pragma once + +#include <unx/gendata.hxx> + +#include <o3tl/enumarray.hxx> +#include <vcl/ptrstyle.hxx> +#include <memory> +#include <vclpluginapi.h> + +class QCursor; + +class VCLPLUG_QT5_PUBLIC Qt5Data final : public GenericUnixSalData +{ + o3tl::enumarray<PointerStyle, std::unique_ptr<QCursor>> m_aCursors; + +public: + explicit Qt5Data(SalInstance* pInstance); + virtual ~Qt5Data() override; + + virtual void ErrorTrapPush() override; + virtual bool ErrorTrapPop(bool bIgnoreError = true) override; + + QCursor& getCursor(PointerStyle ePointerStyle); + + static bool noNativeControls(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5DragAndDrop.hxx b/vcl/inc/qt5/Qt5DragAndDrop.hxx new file mode 100644 index 000000000..c88465ab3 --- /dev/null +++ b/vcl/inc/qt5/Qt5DragAndDrop.hxx @@ -0,0 +1,115 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <com/sun/star/datatransfer/dnd/XDragSource.hpp> +#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <cppuhelper/compbase.hxx> + +class Qt5Frame; + +class Qt5DragSource final + : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDragSource, + css::lang::XInitialization, css::lang::XServiceInfo> +{ + osl::Mutex m_aMutex; + Qt5Frame* m_pFrame; + css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener; + +public: + Qt5DragSource() + : WeakComponentImplHelper(m_aMutex) + , m_pFrame(nullptr) + { + } + + virtual ~Qt5DragSource() override; + + // XDragSource + virtual sal_Bool SAL_CALL isDragImageSupported() override; + virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) override; + virtual void SAL_CALL startDrag( + const css::datatransfer::dnd::DragGestureEvent& trigger, sal_Int8 sourceActions, + sal_Int32 cursor, sal_Int32 image, + const css::uno::Reference<css::datatransfer::XTransferable>& transferable, + const css::uno::Reference<css::datatransfer::dnd::XDragSourceListener>& listener) override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; + void deinitialize(); + + OUString SAL_CALL getImplementationName() override; + + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + void fire_dragEnd(sal_Int8 nAction, bool bSuccessful); +}; + +class Qt5DropTarget final + : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget, + css::datatransfer::dnd::XDropTargetDragContext, + css::datatransfer::dnd::XDropTargetDropContext, + css::lang::XInitialization, css::lang::XServiceInfo> +{ + osl::Mutex m_aMutex; + Qt5Frame* m_pFrame; + sal_Int8 m_nDropAction; + bool m_bActive; + sal_Int8 m_nDefaultActions; + std::vector<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners; + bool m_bDropSuccessful; + +public: + Qt5DropTarget(); + virtual ~Qt5DropTarget() override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArgs) override; + void deinitialize(); + + // XDropTarget + virtual void SAL_CALL addDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override; + virtual void SAL_CALL removeDropTargetListener( + const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override; + virtual sal_Bool SAL_CALL isActive() override; + virtual void SAL_CALL setActive(sal_Bool active) override; + virtual sal_Int8 SAL_CALL getDefaultActions() override; + virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override; + + // XDropTargetDragContext + virtual void SAL_CALL acceptDrag(sal_Int8 dragOperation) override; + virtual void SAL_CALL rejectDrag() override; + + // XDropTargetDropContext + virtual void SAL_CALL acceptDrop(sal_Int8 dropOperation) override; + virtual void SAL_CALL rejectDrop() override; + virtual void SAL_CALL dropComplete(sal_Bool success) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde); + void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte); + void fire_dragOver(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtde); + void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde); + + sal_Int8 proposedDropAction() const { return m_nDropAction; } + bool dropSuccessful() const { return m_bDropSuccessful; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5FilePicker.hxx b/vcl/inc/qt5/Qt5FilePicker.hxx new file mode 100644 index 000000000..5fef2aaea --- /dev/null +++ b/vcl/inc/qt5/Qt5FilePicker.hxx @@ -0,0 +1,175 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vclpluginapi.h> + +#include <cppuhelper/compbase.hxx> + +#include <com/sun/star/frame/XTerminateListener.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ui/dialogs/XFilePicker3.hpp> +#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> +#include <com/sun/star/ui/dialogs/XFolderPicker2.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <osl/conditn.hxx> +#include <osl/mutex.hxx> + +#include <QtCore/QObject> +#include <QtCore/QString> +#include <QtCore/QStringList> +#include <QtCore/QHash> +#include <QtWidgets/QFileDialog> + +#include <memory> + +class QComboBox; +class QGridLayout; +class QLabel; +class QWidget; + +typedef ::cppu::WeakComponentImplHelper<css::frame::XTerminateListener, css::lang::XInitialization, + css::lang::XServiceInfo, css::ui::dialogs::XFilePicker3, + css::ui::dialogs::XFilePickerControlAccess, + css::ui::dialogs::XFolderPicker2> + Qt5FilePicker_Base; + +class VCLPLUG_QT5_PUBLIC Qt5FilePicker : public QObject, public Qt5FilePicker_Base +{ + Q_OBJECT + +private: + css::uno::Reference<css::uno::XComponentContext> m_context; + + css::uno::Reference<css::ui::dialogs::XFilePickerListener> m_xListener; + + osl::Mutex m_aHelperMutex; ///< mutex used by the WeakComponentImplHelper + + QStringList m_aNamedFilterList; ///< to keep the original sequence + QHash<QString, QString> m_aTitleToFilterMap; + // to retrieve the filename extension for a given filter + QHash<QString, QString> m_aNamedFilterToExtensionMap; + QString m_aCurrentFilter; + + QGridLayout* m_pLayout; ///< layout for extra custom controls + QHash<sal_Int16, QWidget*> m_aCustomWidgetsMap; ///< map of SAL control ID's to widget + + const bool m_bIsFolderPicker; + + QWidget* m_pParentWidget; + +protected: + std::unique_ptr<QFileDialog> m_pFileDialog; ///< the file picker dialog + QWidget* m_pExtraControls; ///< widget to contain extra custom controls + +public: + // use non-native file dialog by default; there's no easy way to add custom widgets + // in a generic way in the native one + explicit Qt5FilePicker(css::uno::Reference<css::uno::XComponentContext> const& context, + QFileDialog::FileMode, bool bUseNative = false); + virtual ~Qt5FilePicker() override; + + // 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; + + // XFilterManager functions + virtual void SAL_CALL appendFilter(const OUString& rTitle, const OUString& rFilter) override; + virtual void SAL_CALL setCurrentFilter(const OUString& rTitle) override; + virtual OUString SAL_CALL getCurrentFilter() override; + + // XFilterGroupManager functions + virtual void SAL_CALL + appendFilterGroup(const OUString& rGroupTitle, + const css::uno::Sequence<css::beans::StringPair>& rFilters) override; + + // XCancellable + virtual void SAL_CALL cancel() override; + + // XExecutableDialog functions + virtual void SAL_CALL setTitle(const OUString& rTitle) 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& rName) override; + virtual void SAL_CALL setDisplayDirectory(const OUString& rDirectory) override; + virtual OUString SAL_CALL getDisplayDirectory() override; + virtual css::uno::Sequence<OUString> SAL_CALL getFiles() override; + + // XFilePickerControlAccess functions + virtual void SAL_CALL setValue(sal_Int16 nControlId, sal_Int16 nControlAction, + const css::uno::Any& rValue) override; + virtual css::uno::Any SAL_CALL getValue(sal_Int16 nControlId, + sal_Int16 nControlAction) override; + virtual void SAL_CALL enableControl(sal_Int16 nControlId, sal_Bool bEnable) override; + virtual void SAL_CALL setLabel(sal_Int16 nControlId, const OUString& rLabel) override; + virtual OUString SAL_CALL getLabel(sal_Int16 nControlId) override; + + // XFilePicker2 functions + virtual css::uno::Sequence<OUString> SAL_CALL getSelectedFiles() override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; + + // XEventListener + void SAL_CALL disposing(const css::lang::EventObject& rEvent) override; + using cppu::WeakComponentImplHelperBase::disposing; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + // XFolderPicker functions + virtual OUString SAL_CALL getDirectory() override; + virtual void SAL_CALL setDescription(const OUString& rDescription) override; + + // XTerminateListener + void SAL_CALL queryTermination(const css::lang::EventObject& aEvent) override; + void SAL_CALL notifyTermination(const css::lang::EventObject& aEvent) override; + +protected: + virtual void addCustomControl(sal_Int16 controlId); + void setCustomControlWidgetLayout(QGridLayout* pLayout) { m_pLayout = pLayout; } + +private: + Qt5FilePicker(const Qt5FilePicker&) = delete; + Qt5FilePicker& operator=(const Qt5FilePicker&) = delete; + + static QString getResString(const char* pRedId); + static css::uno::Any handleGetListValue(const QComboBox* pWidget, sal_Int16 nControlAction); + static void handleSetListValue(QComboBox* pQComboBox, sal_Int16 nAction, + const css::uno::Any& rValue); + +private Q_SLOTS: + // emit XFilePickerListener controlStateChanged event + void filterSelected(const QString&); + // emit XFilePickerListener fileSelectionChanged event + void currentChanged(const QString&); + // (un)set automatic file extension + virtual void updateAutomaticFileExtension(); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Font.hxx b/vcl/inc/qt5/Qt5Font.hxx new file mode 100644 index 000000000..0720be931 --- /dev/null +++ b/vcl/inc/qt5/Qt5Font.hxx @@ -0,0 +1,41 @@ +/* -*- 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 . + */ + +#pragma once + +#include <fontinstance.hxx> + +#include <QtGui/QFont> + +#include "Qt5FontFace.hxx" + +class Qt5Font final : public QFont, public LogicalFontInstance +{ + friend rtl::Reference<LogicalFontInstance> + Qt5FontFace::CreateFontInstance(const FontSelectPattern&) const; + + bool GetGlyphOutline(sal_GlyphId, basegfx::B2DPolyPolygon&, bool) const override; + bool ImplGetGlyphBoundRect(sal_GlyphId, tools::Rectangle&, bool) const override; + + virtual hb_font_t* ImplInitHbFont() override; + + explicit Qt5Font(const PhysicalFontFace&, const FontSelectPattern&); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5FontFace.hxx b/vcl/inc/qt5/Qt5FontFace.hxx new file mode 100644 index 000000000..585f4aaa8 --- /dev/null +++ b/vcl/inc/qt5/Qt5FontFace.hxx @@ -0,0 +1,67 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vclpluginapi.h> +#include <PhysicalFontFace.hxx> + +#include <tools/ref.hxx> +#include <vcl/fontcapabilities.hxx> +#include <vcl/fontcharmap.hxx> + +#include <QtCore/QString> +#include <QtGui/QFont> + +class FontAttributes; +class FontSelectPattern; + +class Qt5FontFace final : public PhysicalFontFace +{ +public: + static Qt5FontFace* fromQFont(const QFont& rFont); + static Qt5FontFace* fromQFontDatabase(const QString& aFamily, const QString& aStyle); + static void fillAttributesFromQFont(const QFont& rFont, FontAttributes& rFA); + + VCLPLUG_QT5_PUBLIC static FontWeight toFontWeight(const int nWeight); + VCLPLUG_QT5_PUBLIC static FontWidth toFontWidth(const int nStretch); + VCLPLUG_QT5_PUBLIC static FontItalic toFontItalic(const QFont::Style eStyle); + + sal_IntPtr GetFontId() const override; + + int GetFontTable(const char pTagName[5], unsigned char*) const; + + const FontCharMapRef& GetFontCharMap() const; + bool GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const; + bool HasChar(sal_uInt32 cChar) const; + + rtl::Reference<LogicalFontInstance> + CreateFontInstance(const FontSelectPattern& rFSD) const override; + +private: + Qt5FontFace(const Qt5FontFace&); + Qt5FontFace(const FontAttributes& rFA, const QString& rFontID); + + const QString m_aFontId; + mutable FontCharMapRef m_xCharMap; + mutable vcl::FontCapabilities m_aFontCapabilities; + mutable bool m_bFontCapabilitiesRead; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx new file mode 100644 index 000000000..0caf1bc3e --- /dev/null +++ b/vcl/inc/qt5/Qt5Frame.hxx @@ -0,0 +1,225 @@ +/* -*- 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 . + */ + +#pragma once + +#include <config_vclplug.h> + +#include <salframe.hxx> +#include <vclpluginapi.h> + +#include "Qt5Tools.hxx" + +#include <headless/svpgdi.hxx> +#include <vcl/svapp.hxx> +#include <vcl/sysdata.hxx> + +#include <QtCore/QObject> + +#if QT5_USING_X11 +#include <unx/screensaverinhibitor.hxx> +// any better way to get rid of the X11 / Qt type clashes? +#undef Bool +#undef CursorShape +#undef Expose +#undef KeyPress +#undef KeyRelease +#undef FocusIn +#undef FocusOut +#undef FontChange +#undef None +#undef Status +#undef Unsorted +#endif + +class Qt5DragSource; +class Qt5DropTarget; +class Qt5Graphics; +class Qt5Instance; +class Qt5MainWindow; +class Qt5Menu; +class Qt5SvpGraphics; + +class QDragMoveEvent; +class QDropEvent; +class QImage; +class QMimeData; +class QPaintDevice; +class QScreen; +class QWidget; + +class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame +{ + Q_OBJECT + + friend class Qt5Widget; + + QWidget* m_pQWidget; + Qt5MainWindow* m_pTopLevel; + + const bool m_bUseCairo; + std::unique_ptr<QImage> m_pQImage; + std::unique_ptr<Qt5Graphics> m_pQt5Graphics; + UniqueCairoSurface m_pSurface; + std::unique_ptr<Qt5SvpGraphics> m_pOurSvpGraphics; + // in base class, this ptr is the same as m_pOurSvpGraphic + // in derived class, it can point to a derivative + // of Qt5SvpGraphics (which the derived class then owns) + Qt5SvpGraphics* m_pSvpGraphics; + DamageHandler m_aDamageHandler; + QRegion m_aRegion; + bool m_bNullRegion; + + bool m_bGraphicsInUse; + bool m_bGraphicsInvalid; + SalFrameStyleFlags m_nStyle; + Qt5Frame* m_pParent; + PointerStyle m_ePointerStyle; + + SystemEnvData m_aSystemData; + + Qt5Menu* m_pSalMenu; + + Qt5DragSource* m_pDragSource; + Qt5DropTarget* m_pDropTarget; + bool m_bInDrag; + + bool m_bDefaultSize; + bool m_bDefaultPos; + bool m_bFullScreen; + bool m_bFullScreenSpanAll; + sal_uInt32 m_nRestoreScreen; + QRect m_aRestoreGeometry; + +#if QT5_USING_X11 + ScreenSaverInhibitor m_ScreenSaverInhibitor; +#endif + + void SetDefaultPos(); + Size CalcDefaultSize(); + void SetDefaultSize(); + + bool isChild(bool bPlug = true, bool bSysChild = true) const + { + SalFrameStyleFlags nMask = SalFrameStyleFlags::NONE; + if (bPlug) + nMask |= SalFrameStyleFlags::PLUG; + if (bSysChild) + nMask |= SalFrameStyleFlags::SYSTEMCHILD; + return bool(m_nStyle & nMask); + } + + bool isWindow() const; + QWindow* windowHandle() const; + QScreen* screen() const; + bool isMinimized() const; + bool isMaximized() const; + void SetWindowStateImpl(Qt::WindowStates eState); + + void fixICCCMwindowGroup(); + +public: + Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nSalFrameStyle, bool bUseCairo); + virtual ~Qt5Frame() override; + + QWidget* GetQWidget() const { return m_pQWidget; } + Qt5MainWindow* GetTopLevelWindow() const { return m_pTopLevel; } + QWidget* asChild() const; + qreal devicePixelRatioF() const; + + void Damage(sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 nExtentsWidth, + sal_Int32 nExtentsHeight) const; + + void InitQt5SvpGraphics(Qt5SvpGraphics* pQt5SvpGraphics); + virtual SalGraphics* AcquireGraphics() override; + virtual void ReleaseGraphics(SalGraphics* pGraphics) override; + + virtual bool PostEvent(std::unique_ptr<ImplSVEvent> pData) override; + + virtual void SetTitle(const OUString& rTitle) override; + virtual void SetIcon(sal_uInt16 nIcon) override; + virtual void SetMenu(SalMenu* pMenu) override; + virtual void DrawMenuBar() override; + + virtual void registerDragSource(Qt5DragSource* pDragSource); + virtual void deregisterDragSource(Qt5DragSource const* pDragSource); + virtual void registerDropTarget(Qt5DropTarget* pDropTarget); + virtual void deregisterDropTarget(Qt5DropTarget const* pDropTarget); + + void handleDragLeave(); + void handleDragMove(QDragMoveEvent* pEvent); + void handleDrop(QDropEvent* pEvent); + + virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override; + virtual void Show(bool bVisible, bool bNoActivate = false) override; + virtual void SetMinClientSize(long nWidth, long nHeight) override; + virtual void SetMaxClientSize(long nWidth, long nHeight) override; + virtual void SetPosSize(long nX, long nY, long nWidth, long nHeight, + sal_uInt16 nFlags) override; + virtual void GetClientSize(long& rWidth, long& rHeight) override; + virtual void GetWorkArea(tools::Rectangle& rRect) override; + virtual SalFrame* GetParent() const override; + virtual void SetModal(bool bModal) override; + virtual bool GetModal() const override; + virtual void SetWindowState(const SalFrameState* pState) override; + virtual bool GetWindowState(SalFrameState* pState) override; + virtual void ShowFullScreen(bool bFullScreen, sal_Int32 nDisplay) override; + virtual void StartPresentation(bool bStart) override; + virtual void SetAlwaysOnTop(bool bOnTop) override; + virtual void ToTop(SalFrameToTop nFlags) override; + virtual void SetPointer(PointerStyle ePointerStyle) override; + virtual void CaptureMouse(bool bMouse) override; + virtual void SetPointerPos(long nX, long nY) override; + virtual bool ShowTooltip(const OUString& rText, const tools::Rectangle& rHelpArea) override; + using SalFrame::Flush; + virtual void Flush() override; + virtual void SetInputContext(SalInputContext* pContext) override; + virtual void EndExtTextInput(EndExtTextInputFlags nFlags) override; + virtual OUString GetKeyName(sal_uInt16 nKeyCode) override; + virtual bool MapUnicodeToKeyCode(sal_Unicode aUnicode, LanguageType aLangType, + vcl::KeyCode& rKeyCode) override; + virtual LanguageType GetInputLanguage() override; + virtual void UpdateSettings(AllSettings& rSettings) override; + virtual void Beep() override; + virtual const SystemEnvData* GetSystemData() const override { return &m_aSystemData; } + virtual SalPointerState GetPointerState() override; + virtual KeyIndicatorState GetIndicatorState() override; + virtual void SimulateKeyPress(sal_uInt16 nKeyCode) override; + virtual void SetParent(SalFrame* pNewParent) override; + virtual bool SetPluginParent(SystemParentData* pNewParent) override; + virtual void ResetClipRegion() override; + virtual void BeginSetClipRegion(sal_uInt32 nRects) override; + virtual void UnionClipRegion(long nX, long nY, long nWidth, long nHeight) override; + virtual void EndSetClipRegion() override; + + virtual void SetScreenNumber(unsigned int) override; + virtual void SetApplicationID(const OUString&) override; + + inline bool CallCallback(SalEvent nEvent, const void* pEvent) const; + + cairo_t* getCairoContext() const; +}; + +inline bool Qt5Frame::CallCallback(SalEvent nEvent, const void* pEvent) const +{ + SolarMutexGuard aGuard; + return SalFrame::CallCallback(nEvent, pEvent); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Graphics.hxx b/vcl/inc/qt5/Qt5Graphics.hxx new file mode 100644 index 000000000..bc4870ee7 --- /dev/null +++ b/vcl/inc/qt5/Qt5Graphics.hxx @@ -0,0 +1,202 @@ +/* -*- 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 . + */ + +#pragma once + +#include <salgdi.hxx> + +#include <memory> + +#include <QtGui/QPainter> +#include <QtGui/QPainterPath> +#include <QtGui/QRegion> + +#include "Qt5GraphicsBase.hxx" + +class PhysicalFontCollection; +class QImage; +class QPushButton; +class Qt5Font; +class Qt5FontFace; +class Qt5Frame; +class Qt5Painter; + +class Qt5Graphics final : public SalGraphics, public Qt5GraphicsBase +{ + friend class Qt5Bitmap; + friend class Qt5Painter; + + Qt5Frame* m_pFrame; + QImage* m_pQImage; + QRegion m_aClipRegion; + QPainterPath m_aClipPath; + Color m_aLineColor; + Color m_aFillColor; + QPainter::CompositionMode m_eCompositionMode; + + PhysicalFontCollection* m_pFontCollection; + rtl::Reference<Qt5Font> m_pTextStyle[MAX_FALLBACK]; + Color m_aTextColor; + std::unique_ptr<QPushButton> m_focusedButton; + std::unique_ptr<QImage> m_image; + QRect m_lastPopupRect; + + Qt5Graphics(Qt5Frame* pFrame, QImage* pQImage); + + void drawScaledImage(const SalTwoRect& rPosAry, const QImage& rImage); + + void handleDamage(const tools::Rectangle&) override; + +public: + Qt5Graphics(Qt5Frame* pFrame) + : Qt5Graphics(pFrame, nullptr) + { + } + Qt5Graphics(QImage* pQImage) + : Qt5Graphics(nullptr, pQImage) + { + } + virtual ~Qt5Graphics() override; + + void ChangeQImage(QImage* pImage); + + virtual SalGraphicsImpl* GetImpl() const override; + virtual SystemGraphicsData GetGraphicsData() const override; + virtual bool supportsOperation(OutDevSupportType) const override; + virtual OUString getRenderBackendName() const override { return "qt5"; } + +#if ENABLE_CAIRO_CANVAS + virtual bool SupportsCairo() const override; + virtual cairo::SurfaceSharedPtr + CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override; + virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, + int width, int height) const override; + virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, + const BitmapSystemData& rData, + const Size& rSize) const override; + virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, + const basegfx::B2ISize& rSize) const override; + virtual SystemFontData GetSysFontData(int nFallbacklevel) const override; +#endif // ENABLE_CAIRO_CANVAS + + // GDI + + virtual bool setClipRegion(const vcl::Region&) override; + virtual void ResetClipRegion() override; + + virtual void drawPixel(long nX, long nY) override; + virtual void drawPixel(long nX, long nY, Color nColor) override; + virtual void drawLine(long nX1, long nY1, long nX2, long nY2) override; + virtual void drawRect(long nX, long nY, long nWidth, long nHeight) override; + virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint* pPtAry) override; + virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint* pPtAry) override; + virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, + PCONSTSALPOINT* pPtAry) override; + virtual bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolyPolygon&, double fTransparency) override; + virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint* pPtAry, + const PolyFlags* pFlgAry) override; + virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint* pPtAry, + const PolyFlags* pFlgAry) override; + virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32* pPoints, + const SalPoint* const* pPtAry, + const PolyFlags* const* pFlgAry) override; + virtual bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice, + const basegfx::B2DPolygon&, double fTransparency, double fLineWidths, + const std::vector<double>* pStroke, // MM01 + basegfx::B2DLineJoin, css::drawing::LineCap eLineCap, + double fMiterMinimumAngle, bool bPixelSnapHairline) override; + virtual bool drawGradient(const tools::PolyPolygon&, const Gradient&) override; + + virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, + long nSrcHeight, bool bWindowInvalidate) override; + + virtual void copyBits(const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics) override; + virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) override; + virtual void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + const SalBitmap& rTransparentBitmap) override; + virtual void drawMask(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, + Color nMaskColor) override; + + virtual std::shared_ptr<SalBitmap> getBitmap(long nX, long nY, long nWidth, + long nHeight) override; + virtual Color getPixel(long nX, long nY) override; + + virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override; + virtual void invert(sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags) override; + + virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void* pPtr, + sal_uInt32 nSize) override; + + virtual bool blendBitmap(const SalTwoRect&, const SalBitmap& rBitmap) override; + + virtual bool blendAlphaBitmap(const SalTwoRect&, const SalBitmap& rSrcBitmap, + const SalBitmap& rMaskBitmap, + const SalBitmap& rAlphaBitmap) override; + + virtual bool drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap, + const SalBitmap& rAlphaBitmap) override; + + bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap) override; + + virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, + sal_uInt8 nTransparency) override; + + virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override; + virtual sal_uInt16 GetBitCount() const override; + virtual long GetGraphicsWidth() const override; + + virtual void SetLineColor() override; + virtual void SetLineColor(Color nColor) override; + virtual void SetFillColor() override; + virtual void SetFillColor(Color nColor) override; + virtual void SetXORMode(bool bSet, bool bInvertOnly) override; + virtual void SetROPLineColor(SalROPColor nROPColor) override; + virtual void SetROPFillColor(SalROPColor nROPColor) override; + + // Text rendering + font support + + virtual void SetTextColor(Color nColor) override; + virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override; + virtual void GetFontMetric(ImplFontMetricDataRef&, int nFallbackLevel) override; + virtual FontCharMapRef GetFontCharMap() const override; + virtual bool GetFontCapabilities(vcl::FontCapabilities& rFontCapabilities) const override; + virtual void GetDevFontList(PhysicalFontCollection*) override; + virtual void ClearDevFontCache() override; + virtual bool AddTempDevFont(PhysicalFontCollection*, const OUString& rFileURL, + const OUString& rFontName) override; + virtual bool CreateFontSubset(const OUString& rToFile, const PhysicalFontFace* pFont, + const sal_GlyphId* pGlyphIds, const sal_uInt8* pEncoding, + sal_Int32* pWidths, int nGlyphs, + FontSubsetInfo& rInfo // out parameter + ) override; + + virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override; + virtual void FreeEmbedFontData(const void* pData, long nDataLen) override; + + virtual void GetGlyphWidths(const PhysicalFontFace*, bool bVertical, + std::vector<sal_Int32>& rWidths, Ucs2UIntMap& rUnicodeEnc) override; + + virtual std::unique_ptr<GenericSalLayout> GetTextLayout(int nFallbackLevel) override; + virtual void DrawTextLayout(const GenericSalLayout&) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5GraphicsBase.hxx b/vcl/inc/qt5/Qt5GraphicsBase.hxx new file mode 100644 index 000000000..ef7955186 --- /dev/null +++ b/vcl/inc/qt5/Qt5GraphicsBase.hxx @@ -0,0 +1,30 @@ +/* -*- 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/. + */ + +#pragma once + +#include <QtWidgets/QApplication> + +class Qt5GraphicsBase +{ + qreal m_fDPR; + +protected: + Qt5GraphicsBase() + : m_fDPR(qApp ? qApp->devicePixelRatio() : 1.0) + { + } + + void setDevicePixelRatioF(qreal fDPR) { m_fDPR = fDPR; } + +public: + qreal devicePixelRatioF() const { return m_fDPR; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Graphics_Controls.hxx b/vcl/inc/qt5/Qt5Graphics_Controls.hxx new file mode 100644 index 000000000..325e5c351 --- /dev/null +++ b/vcl/inc/qt5/Qt5Graphics_Controls.hxx @@ -0,0 +1,97 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vclpluginapi.h> +#include <WidgetDrawInterface.hxx> + +#include <memory> + +#include <QtGui/QImage> +#include <QtGui/QPainter> +#include <QtGui/QRegion> +#include <QtWidgets/QPushButton> +#include <QtWidgets/QStyle> +#include <QtWidgets/QStyleOption> + +class Qt5GraphicsBase; + +class Qt5Graphics_Controls final : public vcl::WidgetDrawInterface +{ + std::unique_ptr<QImage> m_image; + QRect m_lastPopupRect; + Qt5GraphicsBase const& m_rGraphics; + +public: + Qt5Graphics_Controls(const Qt5GraphicsBase& rGraphics); + + QImage* getImage() { return m_image.get(); } + + bool isNativeControlSupported(ControlType nType, ControlPart nPart) override; + bool hitTestNativeControl(ControlType nType, ControlPart nPart, + const tools::Rectangle& rControlRegion, const Point& aPos, + bool& rIsInside) override; + bool drawNativeControl(ControlType nType, ControlPart nPart, + const tools::Rectangle& rControlRegion, ControlState nState, + const ImplControlValue& aValue, const OUString& aCaption, + const Color& rBackgroundColor) override; + bool getNativeControlRegion(ControlType nType, ControlPart nPart, + const tools::Rectangle& rControlRegion, ControlState nState, + const ImplControlValue& aValue, const OUString& aCaption, + tools::Rectangle& rNativeBoundingRegion, + tools::Rectangle& rNativeContentRegion) override; + +private: + static int pixelMetric(QStyle::PixelMetric metric, const QStyleOption* option = nullptr); + static QSize sizeFromContents(QStyle::ContentsType type, const QStyleOption* option, + const QSize& contentsSize); + static QRect subControlRect(QStyle::ComplexControl control, const QStyleOptionComplex* option, + QStyle::SubControl subControl); + static QRect subElementRect(QStyle::SubElement element, const QStyleOption* option); + + void draw(QStyle::ControlElement element, QStyleOption* option, QImage* image, + QStyle::State const state = QStyle::State_None, QRect rect = QRect()); + void draw(QStyle::PrimitiveElement element, QStyleOption* option, QImage* image, + QStyle::State const state = QStyle::State_None, QRect rect = QRect()); + void draw(QStyle::ComplexControl element, QStyleOptionComplex* option, QImage* image, + QStyle::State const state = QStyle::State_None); + void drawFrame(QStyle::PrimitiveElement element, QImage* image, QStyle::State const& state, + bool bClip = true, + QStyle::PixelMetric eLineMetric = QStyle::PM_DefaultFrameWidth); + + static void fillQStyleOptionTab(const ImplControlValue& value, QStyleOptionTab& sot); + void fullQStyleOptionTabWidgetFrame(QStyleOptionTabWidgetFrame& option, bool bDownscale); + + enum class Round + { + Floor, + Ceil, + }; + + int downscale(int value, Round eRound); + int upscale(int value, Round eRound); + QRect downscale(const QRect& rect); + QRect upscale(const QRect& rect); + QSize downscale(const QSize& size, Round eRound); + QSize upscale(const QSize& size, Round eRound); + QPoint upscale(const QPoint& point, Round eRound); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx new file mode 100644 index 000000000..361eca0fc --- /dev/null +++ b/vcl/inc/qt5/Qt5Instance.hxx @@ -0,0 +1,161 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vclpluginapi.h> +#include <unx/geninst.h> +#include <salusereventlist.hxx> +#include <vcl/timer.hxx> + +#include <osl/conditn.hxx> + +#include <QtCore/QObject> + +#include <cstdlib> +#include <functional> +#include <memory> +#include <vector> + +#include "Qt5FilePicker.hxx" + +class QApplication; +class SalYieldMutex; +class SalFrame; + +struct StdFreeCStr +{ + void operator()(char* arg) const noexcept { std::free(arg); } +}; +using FreeableCStr = std::unique_ptr<char[], StdFreeCStr>; + +class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject, + public SalGenericInstance, + public SalUserEventList +{ + Q_OBJECT + + osl::Condition m_aWaitingYieldCond; + int m_postUserEventId; + const bool m_bUseCairo; + std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards; + + std::unique_ptr<QApplication> m_pQApplication; + std::vector<FreeableCStr> m_pFakeArgvFreeable; + std::unique_ptr<char* []> m_pFakeArgv; + std::unique_ptr<int> m_pFakeArgc; + + Timer m_aUpdateStyleTimer; + bool m_bUpdateFonts; + + DECL_LINK(updateStyleHdl, Timer*, void); + void AfterAppInit() override; + +private Q_SLOTS: + bool ImplYield(bool bWait, bool bHandleAllCurrentEvents); + void ImplRunInMain(); + static void deleteObjectLater(QObject* pObject); + +Q_SIGNALS: + bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents); + void ImplRunInMainSignal(); + void deleteObjectLaterSignal(QObject* pObject); + +protected: + virtual Qt5FilePicker* + createPicker(css::uno::Reference<css::uno::XComponentContext> const& context, + QFileDialog::FileMode); + +public: + explicit Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo = false); + virtual ~Qt5Instance() override; + + // handle common SalInstance setup + static void AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, + std::unique_ptr<int>& rFakeArgc, + std::vector<FreeableCStr>& rFakeArgvFreeable); + void MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, std::unique_ptr<int>& rFakeArgc, + std::vector<FreeableCStr>& rFakeArgvFreeable); + static std::unique_ptr<QApplication> CreateQApplication(int& nArgc, char** pArgv); + + void RunInMainThread(std::function<void()> func); + + virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override; + virtual SalFrame* CreateChildFrame(SystemParentData* pParent, + SalFrameStyleFlags nStyle) override; + virtual void DestroyFrame(SalFrame* pFrame) override; + + virtual SalObject* CreateObject(SalFrame* pParent, SystemWindowData* pWindowData, + bool bShow) override; + virtual void DestroyObject(SalObject* pObject) override; + + virtual std::unique_ptr<SalVirtualDevice> + CreateVirtualDevice(SalGraphics* pGraphics, long& nDX, long& nDY, DeviceFormat eFormat, + const SystemGraphicsData* pData = nullptr) override; + + virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo, + ImplJobSetup* pSetupData) override; + virtual void DestroyInfoPrinter(SalInfoPrinter* pPrinter) override; + virtual std::unique_ptr<SalPrinter> CreatePrinter(SalInfoPrinter* pInfoPrinter) override; + virtual void GetPrinterQueueInfo(ImplPrnQueueList* pList) override; + virtual void GetPrinterQueueState(SalPrinterQueueInfo* pInfo) override; + virtual OUString GetDefaultPrinter() override; + virtual void PostPrintersChanged() override; + + virtual std::unique_ptr<SalMenu> CreateMenu(bool, Menu*) override; + virtual std::unique_ptr<SalMenuItem> CreateMenuItem(const SalItemParams&) override; + + virtual SalTimer* CreateSalTimer() override; + virtual SalSystem* CreateSalSystem() override; + virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override; + + virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override; + virtual bool AnyInput(VclInputFlags nType) override; + + virtual OpenGLContext* CreateOpenGLContext() override; + + virtual OUString GetConnectionIdentifier() override; + + virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, + const OUString& rDocumentService) override; + + virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override; + + virtual bool IsMainThread() const override; + + virtual void TriggerUserEventProcessing() override; + virtual void ProcessEvent(SalUserEvent aEvent) override; + + bool hasNativeFileSelection() const override { return true; } + css::uno::Reference<css::ui::dialogs::XFilePicker2> + createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override; + css::uno::Reference<css::ui::dialogs::XFolderPicker2> + createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override; + + virtual css::uno::Reference<css::uno::XInterface> + CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override; + virtual css::uno::Reference<css::uno::XInterface> CreateDragSource() override; + virtual css::uno::Reference<css::uno::XInterface> CreateDropTarget() override; + + void UpdateStyle(bool bFontsChanged); + + void* CreateGStreamerSink(const SystemChildWindow*) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5MainWindow.hxx b/vcl/inc/qt5/Qt5MainWindow.hxx new file mode 100644 index 000000000..f1e91b489 --- /dev/null +++ b/vcl/inc/qt5/Qt5MainWindow.hxx @@ -0,0 +1,40 @@ +/* -*- 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 . + */ + +#pragma once + +#include <QtWidgets/QWidget> +#include <QtWidgets/QMainWindow> + +#include "Qt5Frame.hxx" + +class Qt5MainWindow : public QMainWindow +{ + Q_OBJECT + + Qt5Frame& m_rFrame; + + virtual void closeEvent(QCloseEvent* pEvent) override; + void moveEvent(QMoveEvent*) override; + +public: + Qt5MainWindow(Qt5Frame& rFrame, Qt::WindowFlags f = Qt::WindowFlags()); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Menu.hxx b/vcl/inc/qt5/Qt5Menu.hxx new file mode 100644 index 000000000..2e5434f4d --- /dev/null +++ b/vcl/inc/qt5/Qt5Menu.hxx @@ -0,0 +1,122 @@ +/* -*- 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/. + */ + +#pragma once + +#include <salmenu.hxx> + +#include <QtCore/QObject> + +#include <memory> + +class MenuItemList; +class QAction; +class QActionGroup; +class QPushButton; +class QMenu; +class QMenuBar; +class Qt5MenuItem; +class Qt5Frame; + +/* + * Qt5Menu can represent + * (1) the top-level menu of a menubar, in which case 'mbMenuBar' is true and + * 'mpQMenuBar' refers to the corresponding QMenuBar + * (2) another kind of menu (like a PopupMenu), in which case the corresponding QMenu + * object is instantiated and owned by this Qt5Menu (held in 'mpOwnedQMenu'). + * (3) a "submenu" in an existing menu (like (1)), in which case the corresponding + * QMenu object is owned by the corresponding Qt5MenuItem. + * + * For (2) and (3), member 'mpQMenu' points to the corresponding QMenu object. + */ +class Qt5Menu : public QObject, public SalMenu +{ + Q_OBJECT +private: + std::vector<Qt5MenuItem*> maItems; + VclPtr<Menu> mpVCLMenu; + Qt5Menu* mpParentSalMenu; + Qt5Frame* mpFrame; + bool mbMenuBar; + QMenuBar* mpQMenuBar; + // self-created QMenu that this Qt5Menu represents, if applicable (s. comment for class) + std::unique_ptr<QMenu> mpOwnedQMenu; + // pointer to QMenu owned by the corresponding Qt5MenuItem or self (-> mpOwnedQMenu) + QMenu* mpQMenu; + QPushButton* mpCloseButton; + QMetaObject::Connection maCloseButtonConnection; + + void DoFullMenuUpdate(Menu* pMenuBar); + static void NativeItemText(OUString& rItemText); + + void InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos); + + void ReinitializeActionGroup(unsigned nPos); + void ResetAllActionGroups(); + void UpdateActionGroupItem(const Qt5MenuItem* pSalMenuItem); + +public: + Qt5Menu(bool bMenuBar); + + virtual bool VisibleMenuBar() override; // must return TRUE to actually DISPLAY native menu bars + + virtual void InsertItem(SalMenuItem* pSalMenuItem, unsigned nPos) override; + virtual void RemoveItem(unsigned nPos) override; + virtual void SetSubMenu(SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsigned nPos) override; + virtual void SetFrame(const SalFrame* pFrame) override; + const Qt5Frame* GetFrame() const; + virtual void ShowMenuBar(bool bVisible) override; + virtual bool ShowNativePopupMenu(FloatingWindow* pWin, const tools::Rectangle& rRect, + FloatWinPopupFlags nFlags) override; + Qt5Menu* GetTopLevel(); + virtual void SetItemBits(unsigned nPos, MenuItemBits nBits) override; + virtual void CheckItem(unsigned nPos, bool bCheck) override; + virtual void EnableItem(unsigned nPos, bool bEnable) override; + virtual void ShowItem(unsigned nPos, bool bShow) override; + virtual void SetItemText(unsigned nPos, SalMenuItem* pSalMenuItem, + const OUString& rText) override; + virtual void SetItemImage(unsigned nPos, SalMenuItem* pSalMenuItem, + const Image& rImage) override; + virtual void SetAccelerator(unsigned nPos, SalMenuItem* pSalMenuItem, + const vcl::KeyCode& rKeyCode, const OUString& rKeyName) override; + virtual void GetSystemMenuData(SystemMenuData* pData) override; + virtual void ShowCloseButton(bool bShow) override; + + void SetMenu(Menu* pMenu) { mpVCLMenu = pMenu; } + Menu* GetMenu() { return mpVCLMenu; } + unsigned GetItemCount() const { return maItems.size(); } + Qt5MenuItem* GetItemAtPos(unsigned nPos) { return maItems[nPos]; } + +private slots: + static void slotMenuTriggered(Qt5MenuItem* pQItem); + static void slotMenuAboutToShow(Qt5MenuItem* pQItem); + static void slotMenuAboutToHide(Qt5MenuItem* pQItem); + void slotCloseDocument(); +}; + +class Qt5MenuItem : public SalMenuItem +{ +public: + Qt5MenuItem(const SalItemParams*); + + QAction* getAction() const; + + Qt5Menu* mpParentMenu; // The menu into which this menu item is inserted + Qt5Menu* mpSubMenu; // Submenu of this item (if defined) + std::unique_ptr<QAction> mpAction; // action corresponding to this item + std::unique_ptr<QMenu> mpMenu; // menu corresponding to this item + std::shared_ptr<QActionGroup> mpActionGroup; // empty if it's a separator element + sal_uInt16 mnId; // Item ID + MenuItemType mnType; // Item type + bool mbVisible; // Item visibility. + bool mbEnabled; // Item active. + Image maImage; // Item image +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Object.hxx b/vcl/inc/qt5/Qt5Object.hxx new file mode 100644 index 000000000..0479db2d6 --- /dev/null +++ b/vcl/inc/qt5/Qt5Object.hxx @@ -0,0 +1,79 @@ +/* -*- 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 . + */ + +#pragma once + +#include <salobj.hxx> +#include <vcl/sysdata.hxx> + +#include <QtCore/QObject> +#include <QtGui/QRegion> +#include <QtGui/QWindow> + +class Qt5Frame; +class QWidget; + +class Qt5Object final : public QObject, public SalObject +{ + Q_OBJECT + + SystemEnvData m_aSystemData; + Qt5Frame* m_pParent; + QWidget* m_pQWidget; // main widget, container + QWindow* m_pQWindow; // contained window, used for opengl rendering + QRegion m_pRegion; + +public: + Qt5Object(Qt5Frame* pParent, bool bShow); + ~Qt5Object() override; + + Qt5Frame* frame() const { return m_pParent; } + QWidget* widget() const { return m_pQWidget; } + QWindow* windowHandle() const { return m_pQWindow; } + + virtual void ResetClipRegion() override; + virtual void BeginSetClipRegion(sal_uInt32 nRects) override; + virtual void UnionClipRegion(long nX, long nY, long nWidth, long nHeight) override; + virtual void EndSetClipRegion() override; + + virtual void SetPosSize(long nX, long nY, long nWidth, long nHeight) override; + virtual void Show(bool bVisible) override; + + virtual void SetForwardKey(bool bEnable) override; + + virtual const SystemEnvData* GetSystemData() const override { return &m_aSystemData; } +}; + +class Qt5ObjectWindow final : public QWindow +{ + Qt5Object& m_rParent; + + bool event(QEvent*) override; + void focusInEvent(QFocusEvent*) override; + void focusOutEvent(QFocusEvent*) override; + void mousePressEvent(QMouseEvent*) override; + void mouseReleaseEvent(QMouseEvent*) override; + // keyPressEvent(QKeyEvent*) is handled via event(QEvent*); see comment in Qt5Widget::event + void keyReleaseEvent(QKeyEvent*) override; + +public: + explicit Qt5ObjectWindow(Qt5Object& rParent); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5OpenGLContext.hxx b/vcl/inc/qt5/Qt5OpenGLContext.hxx new file mode 100644 index 000000000..df5424620 --- /dev/null +++ b/vcl/inc/qt5/Qt5OpenGLContext.hxx @@ -0,0 +1,50 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vcl/opengl/OpenGLContext.hxx> + +class QWindow; +class QOpenGLContext; + +class Qt5OpenGLContext final : public OpenGLContext +{ +public: + virtual void initWindow() override; + +private: + virtual const GLWindow& getOpenGLWindow() const override { return m_aGLWin; } + virtual GLWindow& getModifiableOpenGLWindow() override { return m_aGLWin; } + virtual bool ImplInit() override; + + virtual void makeCurrent() override; + virtual void destroyCurrentContext() override; + virtual bool isCurrent() override; + virtual bool isAnyCurrent() override; + virtual void resetCurrent() override; + virtual void swapBuffers() override; + + static bool g_bAnyCurrent; + + GLWindow m_aGLWin; + + QWindow* m_pWindow; + QOpenGLContext* m_pContext; +}; diff --git a/vcl/inc/qt5/Qt5Painter.hxx b/vcl/inc/qt5/Qt5Painter.hxx new file mode 100644 index 000000000..51ddc3d69 --- /dev/null +++ b/vcl/inc/qt5/Qt5Painter.hxx @@ -0,0 +1,67 @@ +/* -*- 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 . + */ + +#pragma once + +#include <QtCore/QRectF> +#include <QtGui/QPainter> +#include <QtWidgets/QWidget> + +#include "Qt5Frame.hxx" +#include "Qt5Graphics.hxx" + +class Qt5Painter final : public QPainter +{ + Qt5Graphics& m_rGraphics; + QRegion m_aRegion; + +public: + Qt5Painter(Qt5Graphics& rGraphics, bool bPrepareBrush = false, sal_uInt8 nTransparency = 255); + ~Qt5Painter() + { + if (m_rGraphics.m_pFrame && !m_aRegion.isEmpty()) + m_rGraphics.m_pFrame->GetQWidget()->update(m_aRegion); + } + + void update(int nx, int ny, int nw, int nh) + { + if (m_rGraphics.m_pFrame) + m_aRegion += scaledQRect({ nx, ny, nw, nh }, 1 / m_rGraphics.devicePixelRatioF()); + } + + void update(const QRect& rRect) + { + if (m_rGraphics.m_pFrame) + m_aRegion += scaledQRect(rRect, 1 / m_rGraphics.devicePixelRatioF()); + } + + void update(const QRectF& rRectF) + { + if (m_rGraphics.m_pFrame) + update(scaledQRect(rRectF.toAlignedRect(), 1 / m_rGraphics.devicePixelRatioF())); + } + + void update() + { + if (m_rGraphics.m_pFrame) + m_aRegion += m_rGraphics.m_pFrame->GetQWidget()->rect(); + } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Printer.hxx b/vcl/inc/qt5/Qt5Printer.hxx new file mode 100644 index 000000000..23f5428ca --- /dev/null +++ b/vcl/inc/qt5/Qt5Printer.hxx @@ -0,0 +1,32 @@ +/* -*- 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 . + */ + +#pragma once + +#include <unx/genprn.h> + +class SalFrame; + +class Qt5Printer final : public PspSalPrinter +{ +public: + Qt5Printer(SalInfoPrinter* pInfoPrinter); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5SvpGraphics.hxx b/vcl/inc/qt5/Qt5SvpGraphics.hxx new file mode 100644 index 000000000..2ea5e6ad9 --- /dev/null +++ b/vcl/inc/qt5/Qt5SvpGraphics.hxx @@ -0,0 +1,55 @@ +/* -*- 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 . + */ + +#pragma once + +#include <vclpluginapi.h> +#include <headless/svpgdi.hxx> + +#include "Qt5GraphicsBase.hxx" + +class Qt5Frame; + +class VCLPLUG_QT5_PUBLIC Qt5SvpGraphics : public SvpSalGraphics, public Qt5GraphicsBase +{ + Qt5Frame* const m_pFrame; + +protected: + void handleDamage(const tools::Rectangle&) override; + +public: + Qt5SvpGraphics(Qt5Frame* pFrame); + ~Qt5SvpGraphics() override; + + void updateQWidget() const; + +#if ENABLE_CAIRO_CANVAS + bool SupportsCairo() const override; + cairo::SurfaceSharedPtr + CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override; + cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, + int height) const override; +#endif // ENABLE_CAIRO_CANVAS + + virtual void GetResolution(sal_Int32& rDPIX, sal_Int32& rDPIY) override; + + virtual OUString getRenderBackendName() const override { return "qt5svp"; } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5SvpSurface.hxx b/vcl/inc/qt5/Qt5SvpSurface.hxx new file mode 100644 index 000000000..0e4da4877 --- /dev/null +++ b/vcl/inc/qt5/Qt5SvpSurface.hxx @@ -0,0 +1,44 @@ +/* -*- 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/. + */ + +#pragma once + +#include <sal/config.h> + +#include <vcl/cairo.hxx> + +class Qt5SvpGraphics; +class OutputDevice; + +namespace cairo +{ +class Qt5SvpSurface final : public Surface +{ + const Qt5SvpGraphics* m_pGraphics; + cairo_t* const m_pCairoContext; + CairoSurfaceSharedPtr m_pSurface; + +public: + /// takes over ownership of passed cairo_surface + explicit Qt5SvpSurface(const CairoSurfaceSharedPtr& pSurface); + /// create surface on subarea of given drawable + explicit Qt5SvpSurface(const Qt5SvpGraphics* pGraphics, int x, int y, int width, int height); + ~Qt5SvpSurface() override; + + // Surface interface + CairoSharedPtr getCairo() const override; + CairoSurfaceSharedPtr getCairoSurface() const override { return m_pSurface; } + SurfaceSharedPtr getSimilar(int nContentType, int width, int height) const override; + + VclPtr<VirtualDevice> createVirtualDevice() const override; + void flush() const override; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5System.hxx b/vcl/inc/qt5/Qt5System.hxx new file mode 100644 index 000000000..63a7e9bde --- /dev/null +++ b/vcl/inc/qt5/Qt5System.hxx @@ -0,0 +1,23 @@ +/* -*- 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/. + */ + +#pragma once + +#include <unx/gensys.h> + +class Qt5System final : public SalGenericSystem +{ +public: + virtual unsigned int GetDisplayScreenCount() override; + virtual tools::Rectangle GetDisplayScreenPosSizePixel(unsigned int nScreen) override; + virtual int ShowNativeDialog(const OUString& rTitle, const OUString& rMessage, + const std::vector<OUString>& rButtons) override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Timer.hxx b/vcl/inc/qt5/Qt5Timer.hxx new file mode 100644 index 000000000..20b2a4c70 --- /dev/null +++ b/vcl/inc/qt5/Qt5Timer.hxx @@ -0,0 +1,47 @@ +/* -*- 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 . + */ + +#pragma once + +#include <saltimer.hxx> +#include <QtCore/QTimer> + +class Qt5Timer final : public QObject, public SalTimer +{ + Q_OBJECT + + QTimer m_aTimer; + +private Q_SLOTS: + void timeoutActivated(); + void startTimer(int); + void stopTimer(); + +Q_SIGNALS: + void startTimerSignal(int); + void stopTimerSignal(); + +public: + Qt5Timer(); + + virtual void Start(sal_uInt64 nMS) override; + virtual void Stop() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Tools.hxx b/vcl/inc/qt5/Qt5Tools.hxx new file mode 100644 index 000000000..1b58750ec --- /dev/null +++ b/vcl/inc/qt5/Qt5Tools.hxx @@ -0,0 +1,154 @@ +/* -*- 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 . + */ + +#pragma once + +#include <QtCore/QPoint> +#include <QtCore/QRect> +#include <QtCore/QSize> +#include <QtCore/QString> +#include <QtGui/QImage> + +#include <rtl/string.hxx> +#include <rtl/ustring.hxx> +#include <tools/color.hxx> +#include <tools/gen.hxx> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp> + +#include <memory> + +class Image; +class QImage; + +inline OUString toOUString(const QString& s) +{ + // QString stores UTF16, just like OUString + return OUString(reinterpret_cast<const sal_Unicode*>(s.data()), s.length()); +} + +inline QString toQString(const OUString& s) +{ + return QString::fromUtf16(reinterpret_cast<ushort const*>(s.getStr()), s.getLength()); +} + +inline QRect toQRect(const tools::Rectangle& rRect) +{ + return QRect(rRect.Left(), rRect.Top(), rRect.GetWidth(), rRect.GetHeight()); +} + +inline QRect toQRect(const tools::Rectangle& rRect, const qreal fScale) +{ + return QRect(floor(rRect.Left() * fScale), floor(rRect.Top() * fScale), + ceil(rRect.GetWidth() * fScale), ceil(rRect.GetHeight() * fScale)); +} + +inline QRect scaledQRect(const QRect& rRect, const qreal fScale) +{ + return QRect(floor(rRect.x() * fScale), floor(rRect.y() * fScale), ceil(rRect.width() * fScale), + ceil(rRect.height() * fScale)); +} + +inline tools::Rectangle toRectangle(const QRect& rRect) +{ + return tools::Rectangle(rRect.left(), rRect.top(), rRect.right(), rRect.bottom()); +} + +inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Height()); } + +inline Size toSize(const QSize& rSize) { return Size(rSize.width(), rSize.height()); } + +inline Point toPoint(const QPoint& rPoint) { return Point(rPoint.x(), rPoint.y()); } + +inline QColor toQColor(const Color& rColor) +{ + return QColor(rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(), + 255 - rColor.GetTransparency()); +} + +Qt::DropActions toQtDropActions(sal_Int8 dragOperation); +sal_Int8 toVclDropActions(Qt::DropActions dragOperation); +sal_Int8 toVclDropAction(Qt::DropAction dragOperation); +Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation); + +inline QList<int> toQList(const css::uno::Sequence<sal_Int32>& aSequence) +{ + QList<int> aList; + for (sal_Int32 i : aSequence) + { + aList.append(i); + } + return aList; +} + +static constexpr QImage::Format Qt5_DefaultFormat32 = QImage::Format_ARGB32; + +inline QImage::Format getBitFormat(sal_uInt16 nBitCount) +{ + switch (nBitCount) + { + case 1: + return QImage::Format_Mono; + case 8: + return QImage::Format_Indexed8; + case 24: + return QImage::Format_RGB888; + case 32: + return Qt5_DefaultFormat32; + default: + std::abort(); + break; + } + return QImage::Format_Invalid; +} + +inline sal_uInt16 getFormatBits(QImage::Format eFormat) +{ + switch (eFormat) + { + case QImage::Format_Mono: + return 1; + case QImage::Format_Indexed8: + return 8; + case QImage::Format_RGB888: + return 24; + case Qt5_DefaultFormat32: + case QImage::Format_ARGB32_Premultiplied: + return 32; + default: + std::abort(); + return 0; + } +} + +typedef struct _cairo_surface cairo_surface_t; +struct CairoDeleter +{ + void operator()(cairo_surface_t* pSurface) const; +}; + +typedef std::unique_ptr<cairo_surface_t, CairoDeleter> UniqueCairoSurface; + +sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers); +sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons); + +QImage toQImage(const Image& rImage); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Transferable.hxx b/vcl/inc/qt5/Qt5Transferable.hxx new file mode 100644 index 000000000..0d1cc7050 --- /dev/null +++ b/vcl/inc/qt5/Qt5Transferable.hxx @@ -0,0 +1,124 @@ +/* -*- 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/. + * + */ + +#pragma once + +#include <cppuhelper/compbase.hxx> +#include <com/sun/star/datatransfer/XTransferable.hpp> + +#include <QtCore/QMimeData> +#include <QtCore/QStringList> +#include <QtGui/QClipboard> + +/** + * Qt5Transferable classes are used to read QMimeData via the XTransferable + * interface. All the functionality is already implemented in the Qt5Transferable. + * + * The specialisations map to the two users, which provide QMimeData: the Clipboard + * and the Drag'n'Drop functionality. + * + * LO itself seem to just accept "text/plain;charset=utf-16", so it relies on the + * backend to convert to this charset, but still offers "text/plain" itself. + * + * It's the "mirror" interface of the Qt5MimeData, which is defined below. + **/ +class Qt5Transferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable> +{ + Qt5Transferable(const Qt5Transferable&) = delete; + + const QMimeData* m_pMimeData; + osl::Mutex m_aMutex; + bool m_bConvertFromLocale; + css::uno::Sequence<css::datatransfer::DataFlavor> m_aMimeTypeSeq; + +public: + Qt5Transferable(const QMimeData* pMimeData); + const QMimeData* mimeData() const { return m_pMimeData; } + + css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override; + sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override; + css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override; +}; + +/** + * The QClipboard's QMimeData is volatile. As written in the QClipboard::mimeData + * documentation, "the pointer returned might become invalidated when the contents + * of the clipboard changes". Therefore it can just be accessed reliably inside + * the QClipboard's object thread, which is the QApplication's thread, so all of + * the access has to go through RunInMainThread(). + * + * If we detect a QMimeData change, we simply drop reporting any content. In theory + * we can recover in the case where there hadn't been any calls of the XTransferable + * interface, but currently we don't. But we ensure to never report mixed content, + * so we'll just cease operation on QMimeData change. + **/ +class Qt5ClipboardTransferable final : public Qt5Transferable +{ + // to detect in-flight QMimeData changes + const QClipboard::Mode m_aMode; + + bool hasInFlightChanged() const; + +public: + explicit Qt5ClipboardTransferable(const QClipboard::Mode aMode, const QMimeData* pMimeData); + + // these are the same then Qt5Transferable, except they go through RunInMainThread + css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override; + sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override; + css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override; +}; + +/** + * Convenience typedef for better code readability + * + * This just uses the QMimeData provided by the QWidgets D'n'D events. + **/ +typedef Qt5Transferable Qt5DnDTransferable; + +/** + * A lazy loading QMimeData for XTransferable reads + * + * This is an interface class to make a XTransferable read accessible as a + * QMimeData. The mime data is just stored inside the XTransferable, never + * in the QMimeData itself! It's objects are just used for QClipboard to read + * the XTransferable data. + * + * Like XTransferable itself, this class should be considered an immutable + * container for mime data. There is no need to ever set any of its data. + * + * LO will offer at least UTF-16, if there is a viable text representation. + * If LO misses to offer a UTF-8 or a locale encoded string, these objects + * will offer them themselves and convert from UTF-16 on demand. + * + * It's the "mirror" interface of the Qt5Transferable. + **/ +class Qt5MimeData final : public QMimeData +{ + friend class Qt5ClipboardTransferable; + + const css::uno::Reference<css::datatransfer::XTransferable> m_aContents; + mutable bool m_bHaveNoCharset; // = uses the locale charset + mutable bool m_bHaveUTF8; + mutable QStringList m_aMimeTypeList; + + QVariant retrieveData(const QString& mimeType, QVariant::Type type) const override; + +public: + explicit Qt5MimeData(const css::uno::Reference<css::datatransfer::XTransferable>& aContents); + + bool hasFormat(const QString& mimeType) const override; + QStringList formats() const override; + + bool deepCopy(QMimeData** const) const; + + css::datatransfer::XTransferable* xTransferable() const { return m_aContents.get(); } +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5VirtualDevice.hxx b/vcl/inc/qt5/Qt5VirtualDevice.hxx new file mode 100644 index 000000000..89251c96d --- /dev/null +++ b/vcl/inc/qt5/Qt5VirtualDevice.hxx @@ -0,0 +1,56 @@ +/* -*- 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 . + */ + +#pragma once + +#include <salvd.hxx> + +#include <memory> +#include <list> + +#include <QtCore/QSize> + +class Qt5Graphics; +class QImage; +enum class DeviceFormat; + +class Qt5VirtualDevice final : public SalVirtualDevice +{ + std::list<Qt5Graphics*> m_aGraphics; + std::unique_ptr<QImage> m_pImage; + DeviceFormat m_eFormat; + QSize m_aFrameSize; + double m_fScale; + +public: + Qt5VirtualDevice(DeviceFormat eFormat, double fScale); + + // SalVirtualDevice + virtual SalGraphics* AcquireGraphics() override; + virtual void ReleaseGraphics(SalGraphics* pGraphics) override; + + virtual bool SetSize(long nNewDX, long nNewDY) override; + virtual bool SetSizeUsingBuffer(long nNewDX, long nNewDY, sal_uInt8* pBuffer) override; + + // SalGeometryProvider + virtual long GetWidth() const override; + virtual long GetHeight() const override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx new file mode 100644 index 000000000..159794b2d --- /dev/null +++ b/vcl/inc/qt5/Qt5Widget.hxx @@ -0,0 +1,103 @@ +/* -*- 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 . + */ + +#pragma once + +#include <QtWidgets/QWidget> +#include <rtl/ustring.hxx> + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/accessibility/XAccessibleEditableText.hpp> + +class Qt5Frame; +class Qt5Object; + +class Qt5Widget : public QWidget +{ + Q_OBJECT + + Qt5Frame& m_rFrame; + bool m_bNonEmptyIMPreeditSeen; + int m_nDeltaX; + int m_nDeltaY; + + enum class ButtonKeyState + { + Pressed, + Released + }; + + static void commitText(Qt5Frame&, const QString& aText); + static bool handleKeyEvent(Qt5Frame&, const QWidget&, QKeyEvent*, const ButtonKeyState); + static void handleMouseButtonEvent(const Qt5Frame&, const QMouseEvent*, const ButtonKeyState); + + virtual bool event(QEvent*) override; + + virtual void focusInEvent(QFocusEvent*) override; + virtual void focusOutEvent(QFocusEvent*) override; + // keyPressEvent(QKeyEvent*) is handled via event(QEvent*); see comment + virtual void keyReleaseEvent(QKeyEvent*) override; + virtual void mouseMoveEvent(QMouseEvent*) override; + virtual void mousePressEvent(QMouseEvent*) override; + virtual void mouseReleaseEvent(QMouseEvent*) override; + virtual void dragEnterEvent(QDragEnterEvent*) override; + virtual void dragLeaveEvent(QDragLeaveEvent*) override; + virtual void dragMoveEvent(QDragMoveEvent*) override; + virtual void dropEvent(QDropEvent*) override; + virtual void moveEvent(QMoveEvent*) override; + virtual void paintEvent(QPaintEvent*) override; + virtual void resizeEvent(QResizeEvent*) override; + virtual void showEvent(QShowEvent*) override; + virtual void wheelEvent(QWheelEvent*) override; + virtual void closeEvent(QCloseEvent*) override; + virtual void changeEvent(QEvent*) override; + + void inputMethodEvent(QInputMethodEvent*) override; + QVariant inputMethodQuery(Qt::InputMethodQuery) const override; + +public: + Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f = Qt::WindowFlags()); + + Qt5Frame& frame() const { return m_rFrame; } + void endExtTextInput(); + + static bool handleEvent(Qt5Frame&, const QWidget&, QEvent*); + // key events might be propagated further down => call base on false + static inline bool handleKeyReleaseEvent(Qt5Frame&, const QWidget&, QKeyEvent*); + // mouse events are always accepted + static inline void handleMousePressEvent(const Qt5Frame&, const QMouseEvent*); + static inline void handleMouseReleaseEvent(const Qt5Frame&, const QMouseEvent*); +}; + +bool Qt5Widget::handleKeyReleaseEvent(Qt5Frame& rFrame, const QWidget& rWidget, QKeyEvent* pEvent) +{ + return handleKeyEvent(rFrame, rWidget, pEvent, ButtonKeyState::Released); +} + +void Qt5Widget::handleMousePressEvent(const Qt5Frame& rFrame, const QMouseEvent* pEvent) +{ + handleMouseButtonEvent(rFrame, pEvent, ButtonKeyState::Pressed); +} + +void Qt5Widget::handleMouseReleaseEvent(const Qt5Frame& rFrame, const QMouseEvent* pEvent) +{ + handleMouseButtonEvent(rFrame, pEvent, ButtonKeyState::Released); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/inc/qt5/Qt5XAccessible.hxx b/vcl/inc/qt5/Qt5XAccessible.hxx new file mode 100644 index 000000000..fe8e424e4 --- /dev/null +++ b/vcl/inc/qt5/Qt5XAccessible.hxx @@ -0,0 +1,34 @@ +/* -*- 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/. + */ + +#pragma once + +#include <vclpluginapi.h> + +#include <QtCore/QObject> + +#include <com/sun/star/accessibility/XAccessible.hpp> + +#include <vcl/window.hxx> + +class Qt5Frame; +class Qt5Widget; + +// Wrapper class to hold a css::accessibility::XAccessible object +// while being able to pass it as a QObject +class Qt5XAccessible : public QObject +{ + Q_OBJECT + +public: + Qt5XAccessible(css::uno::Reference<css::accessibility::XAccessible> xAccessible); + css::uno::Reference<css::accessibility::XAccessible> m_xAccessible; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |